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