1
- from pyop2 import op2
1
+ import pyop3 as op3
2
2
3
3
import firedrake
4
4
from firedrake import ufl_expr
@@ -81,13 +81,22 @@ def prolong(coarse, fine):
81
81
# Have to do this, because the node set core size is not right for
82
82
# this expanded stencil
83
83
for d in [coarse , coarse_coords ]:
84
- d .dat .global_to_local_begin (op2 .READ )
85
- d .dat .global_to_local_end (op2 .READ )
86
- op2 .par_loop (kernel , next .node_set ,
87
- next .dat (op2 .WRITE ),
88
- coarse .dat (op2 .READ , fine_to_coarse ),
89
- node_locations .dat (op2 .READ ),
90
- coarse_coords .dat (op2 .READ , fine_to_coarse_coords ))
84
+ d .dat .assemble ()
85
+
86
+ #op2.par_loop(kernel, next.node_set,
87
+ # next.dat(op2.WRITE),
88
+ # coarse.dat(op2.READ, fine_to_coarse),
89
+ # node_locations.dat(op2.READ),
90
+ # coarse_coords.dat(op2.READ, fine_to_coarse_coords))
91
+ op3 .do_loop (
92
+ n := Vf .nodes .index (),
93
+ kernel (
94
+ next .nodal_dat ()[n ],
95
+ coarse .nodal_dat ()[fine_to_coarse (n )],
96
+ node_locations .nodal_dat ()[n ],
97
+ coarse_coords .nodal_dat ()[fine_to_coarse_coords (n )],
98
+ ),
99
+ )
91
100
coarse = next
92
101
Vc = Vf
93
102
return fine
@@ -142,14 +151,22 @@ def restrict(fine_dual, coarse_dual):
142
151
# Have to do this, because the node set core size is not right for
143
152
# this expanded stencil
144
153
for d in [coarse_coords ]:
145
- d .dat .global_to_local_begin (op2 .READ )
146
- d .dat .global_to_local_end (op2 .READ )
154
+ d .dat .assemble ()
147
155
kernel = kernels .restrict_kernel (Vf , Vc )
148
- op2 .par_loop (kernel , fine_dual .node_set ,
149
- next .dat (op2 .INC , fine_to_coarse ),
150
- fine_dual .dat (op2 .READ ),
151
- node_locations .dat (op2 .READ ),
152
- coarse_coords .dat (op2 .READ , fine_to_coarse_coords ))
156
+ #op2.par_loop(kernel, fine_dual.node_set,
157
+ # next.dat(op2.INC, fine_to_coarse),
158
+ # fine_dual.dat(op2.READ),
159
+ # node_locations.dat(op2.READ),
160
+ # coarse_coords.dat(op2.READ, fine_to_coarse_coords))
161
+ op3 .do_loop (
162
+ n := Vf .nodes .index (),
163
+ kernel (
164
+ next .nodal_dat ()[fine_to_coarse (n )],
165
+ fine_dual .nodal_dat ()[n ],
166
+ node_locations .nodal_dat ()[n ],
167
+ coarse_coords .nodal_dat ()[fine_to_coarse_coords (n )],
168
+ ),
169
+ )
153
170
fine_dual = next
154
171
Vf = Vc
155
172
return coarse_dual
@@ -217,13 +234,21 @@ def inject(fine, coarse):
217
234
# Have to do this, because the node set core size is not right for
218
235
# this expanded stencil
219
236
for d in [fine , fine_coords ]:
220
- d .dat .global_to_local_begin (op2 .READ )
221
- d .dat .global_to_local_end (op2 .READ )
222
- op2 .par_loop (kernel , next .node_set ,
223
- next .dat (op2 .INC ),
224
- node_locations .dat (op2 .READ ),
225
- fine .dat (op2 .READ , coarse_node_to_fine_nodes ),
226
- fine_coords .dat (op2 .READ , coarse_node_to_fine_coords ))
237
+ d .dat .assemble ()
238
+ #op2.par_loop(kernel, next.node_set,
239
+ # next.dat(op2.INC),
240
+ # node_locations.dat(op2.READ),
241
+ # fine.dat(op2.READ, coarse_node_to_fine_nodes),
242
+ # fine_coords.dat(op2.READ, coarse_node_to_fine_coords))
243
+ op3 .do_loop (
244
+ n := Vc .nodes .index (),
245
+ kernel (
246
+ next .nodal_dat ()[n ],
247
+ node_locations .nodal_dat ()[n ],
248
+ fine .nodal_dat ()[coarse_node_to_fine_nodes (n )],
249
+ fine_coords .nodal_dat ()[coarse_node_to_fine_coords (n )],
250
+ ),
251
+ )
227
252
else :
228
253
coarse_coords = Vc .mesh ().coordinates
229
254
fine_coords = Vf .mesh ().coordinates
@@ -232,13 +257,22 @@ def inject(fine, coarse):
232
257
# Have to do this, because the node set core size is not right for
233
258
# this expanded stencil
234
259
for d in [fine , fine_coords ]:
235
- d .dat .global_to_local_begin (op2 .READ )
236
- d .dat .global_to_local_end (op2 .READ )
237
- op2 .par_loop (kernel , Vc .mesh ().cell_set ,
238
- next .dat (op2 .INC , next .cell_node_map ()),
239
- fine .dat (op2 .READ , coarse_cell_to_fine_nodes ),
240
- fine_coords .dat (op2 .READ , coarse_cell_to_fine_coords ),
241
- coarse_coords .dat (op2 .READ , coarse_coords .cell_node_map ()))
260
+ d .dat .assemble ()
261
+ #op2.par_loop(kernel, Vc.mesh().cell_set,
262
+ # next.dat(op2.INC, next.cell_node_map()),
263
+ # fine.dat(op2.READ, coarse_cell_to_fine_nodes),
264
+ # fine_coords.dat(op2.READ, coarse_cell_to_fine_coords),
265
+ # coarse_coords.dat(op2.READ, coarse_coords.cell_node_map()))
266
+ op3 .do_loop (
267
+ c := Vc .mesh ().cells .index (),
268
+ kernel (
269
+ next .dat [c ],
270
+ fine .nodal_dat ()[coarse_cell_to_fine_nodes (c )],
271
+ fine_coords .nodal_dat ()[coarse_cell_to_fine_coords (c )],
272
+ coarse_coords .nodal_dat ()[coarse_coords (c )],
273
+ ),
274
+ )
275
+
242
276
fine = next
243
277
Vf = Vc
244
278
return coarse
0 commit comments