Skip to content

Commit 7ce9bd4

Browse files
committed
tests/compiler: Add unique options prefixes to tests and modify CoupledCallbackBuilder to generalise to support constraining bcs for mixed problems
1 parent 624d2bc commit 7ce9bd4

3 files changed

Lines changed: 47 additions & 24 deletions

File tree

devito/petsc/iet/callbacks.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,17 +1128,43 @@ def _submat_callback_body(self):
11281128

11291129
dm_get_info = petsc_call(
11301130
'DMDAGetInfo', [
1131-
sobjs['callbackdm'], Null, Byref(sobjs['M']), Byref(sobjs['N']),
1131+
sobjs['callbackdm'], Null, Null, Null,
11321132
Null, Null, Null, Null, Byref(objs['dof']), Null, Null, Null, Null, Null
11331133
]
11341134
)
1135-
subblock_rows = DummyExpr(objs['subblockrows'], Mul(sobjs['M'], sobjs['N']))
1136-
subblock_cols = DummyExpr(objs['subblockcols'], Mul(sobjs['M'], sobjs['N']))
11371135

11381136
ptr = DummyExpr(
11391137
objs['submat_arr']._C_symbol, Deref(objs['Submats']._C_symbol), init=True
11401138
)
11411139

1140+
i = Dimension(name='i')
1141+
tmpvec = sobjs['tmpvec']
1142+
1143+
row_idx = DummyExpr(objs['rowidx'], IntDiv(i, objs['dof']))
1144+
col_idx = DummyExpr(objs['colidx'], Mod(i, objs['dof']))
1145+
1146+
# Query constrained global size from each sub-DM via a temporary Vec.
1147+
# For unconstrained sub-DMs this is equivalent to M*N; for constrained
1148+
# (BC-excluded) sub-DMs it returns the reduced size automatically.
1149+
get_row_vec = petsc_call(
1150+
'DMGetGlobalVector', [objs['Subdms'].indexed[objs['rowidx']], Byref(tmpvec)]
1151+
)
1152+
get_row_size = petsc_call(
1153+
'VecGetSize', [tmpvec, Byref(objs['subblockrows'])]
1154+
)
1155+
restore_row_vec = petsc_call(
1156+
'DMRestoreGlobalVector', [objs['Subdms'].indexed[objs['rowidx']], Byref(tmpvec)]
1157+
)
1158+
get_col_vec = petsc_call(
1159+
'DMGetGlobalVector', [objs['Subdms'].indexed[objs['colidx']], Byref(tmpvec)]
1160+
)
1161+
get_col_size = petsc_call(
1162+
'VecGetSize', [tmpvec, Byref(objs['subblockcols'])]
1163+
)
1164+
restore_col_vec = petsc_call(
1165+
'DMRestoreGlobalVector', [objs['Subdms'].indexed[objs['colidx']], Byref(tmpvec)]
1166+
)
1167+
11421168
mat_create = petsc_call('MatCreate', [sobjs['comm'], Byref(objs['block'])])
11431169

11441170
mat_set_sizes = petsc_call(
@@ -1151,10 +1177,6 @@ def _submat_callback_body(self):
11511177
mat_set_type = petsc_call('MatSetType', [objs['block'], 'MATSHELL'])
11521178

11531179
malloc = petsc_call('PetscMalloc1', [1, Byref(objs['subctx'])])
1154-
i = Dimension(name='i')
1155-
1156-
row_idx = DummyExpr(objs['rowidx'], IntDiv(i, objs['dof']))
1157-
col_idx = DummyExpr(objs['colidx'], Mod(i, objs['dof']))
11581180

11591181
deref_subdm = Dereference(objs['Subdms'], objs['ljacctx'])
11601182

@@ -1193,12 +1215,18 @@ def _submat_callback_body(self):
11931215
assign_block = DummyExpr(objs['submat_arr'].indexed[i], objs['block'])
11941216

11951217
iter_body = (
1218+
row_idx,
1219+
col_idx,
1220+
get_row_vec,
1221+
get_row_size,
1222+
restore_row_vec,
1223+
get_col_vec,
1224+
get_col_size,
1225+
restore_col_vec,
11961226
mat_create,
11971227
mat_set_sizes,
11981228
mat_set_type,
11991229
malloc,
1200-
row_idx,
1201-
col_idx,
12021230
set_rows,
12031231
set_cols,
12041232
dm_set_ctx,
@@ -1233,8 +1261,6 @@ def _submat_callback_body(self):
12331261
mat_get_dm,
12341262
dm_get_app,
12351263
dm_get_info,
1236-
subblock_rows,
1237-
subblock_cols,
12381264
ptr,
12391265
BlankLine,
12401266
iteration,

devito/petsc/iet/type_builder.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ def _extend_build(self, base_dict):
108108
)
109109
base_dict['nfields'] = PetscInt(sreg.make_name(prefix='nfields'))
110110

111-
space_dims = len(self.field_data.grid.dimensions)
112-
113-
dim_labels = ["M", "N", "P"]
114-
base_dict.update({
115-
dim_labels[i]: PetscInt(dim_labels[i]) for i in range(space_dims)
116-
})
117-
118111
submatrices = self.field_data.jacobian.nonzero_submatrices
119112

120113
base_dict['jacctx'] = JacobianStruct(
@@ -133,6 +126,10 @@ def _extend_build(self, base_dict):
133126
base_dict[f'{name}Y'] = Vec(f'{name}Y', destroy=False)
134127
base_dict[f'{name}F'] = Vec(f'{name}F', destroy=False)
135128

129+
# Temporary Vec used in MatCreateSubMatrices to query constrained
130+
# global sizes from sub-DMs (works for both constrained and unconstrained).
131+
base_dict['tmpvec'] = Vec('tmpvec', destroy=False)
132+
136133
# Bundle objects/metadata required by the coupled residual callback
137134
f_components, x_components = [], []
138135
bundle_mapper = {}

tests/test_petsc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ def test_petsc_cast():
229229
eqn2 = Eq(f2.laplace, 10)
230230
eqn3 = Eq(f3.laplace, 10)
231231

232-
petsc1 = petscsolve(eqn1, f1)
233-
petsc2 = petscsolve(eqn2, f2)
234-
petsc3 = petscsolve(eqn3, f3)
232+
petsc1 = petscsolve(eqn1, f1, options_prefix='cast1d')
233+
petsc2 = petscsolve(eqn2, f2, options_prefix='cast2d')
234+
petsc3 = petscsolve(eqn3, f3, options_prefix='cast3d')
235235

236236
with switchconfig(language='petsc'):
237237
op1 = Operator(petsc1)
@@ -261,9 +261,9 @@ def test_dmda_create():
261261
eqn2 = Eq(f2.laplace, 10)
262262
eqn3 = Eq(f3.laplace, 10)
263263

264-
petsc1 = petscsolve(eqn1, f1)
265-
petsc2 = petscsolve(eqn2, f2)
266-
petsc3 = petscsolve(eqn3, f3)
264+
petsc1 = petscsolve(eqn1, f1, options_prefix='dmda1d')
265+
petsc2 = petscsolve(eqn2, f2, options_prefix='dmda2d')
266+
petsc3 = petscsolve(eqn3, f3, options_prefix='dmda3d')
267267

268268
with switchconfig(language='petsc'):
269269
op1 = Operator(petsc1, opt='noop')

0 commit comments

Comments
 (0)