Skip to content

Commit 4bd4f8e

Browse files
committed
tests: Start tests for petscsection constraining bcs in 1d
1 parent 9f68bb2 commit 4bd4f8e

4 files changed

Lines changed: 407 additions & 7 deletions

File tree

devito/petsc/equations.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def constrain_essential_bcs(expressions, **kwargs):
3535

3636
# obvs shouldn't be obtained from indexeds[0], but how should it be obtained?
3737
# USE e.lhs function -> the one that the BC is being applied to
38+
# from IPython import embed; embed()
39+
# f._size_nodomain.left
3840
halo_size_left = indexeds[0].function._size_halo[d].left
3941
halo_size_right = indexeds[0].function._size_halo[d].right
4042

@@ -45,11 +47,11 @@ def constrain_essential_bcs(expressions, **kwargs):
4547

4648
# in theory this class shoulod just take in d
4749
# TODO: use unique name
48-
subdim_max = SubDimMax(d.name + '_max', subdim=d, thickness=d.thickness)
49-
subdim_min = SubDimMin(d.name + '_min', subdim=d, thickness=d.thickness)
50+
sregistry = kwargs.get('sregistry')
51+
subdim_max = SubDimMax(sregistry.make_name(prefix=d.name + '_max'), subdim=d, thickness=d.thickness)
52+
subdim_min = SubDimMin(sregistry.make_name(prefix=d.name + '_min'), subdim=d, thickness=d.thickness)
5053

5154
# from IPython import embed; embed()
52-
5355
new_dim = CustomBoundSubDimension(
5456
name=d.name,
5557
parent=d.parent,

devito/petsc/iet/callbacks.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _make_core(self):
126126
if self.field_data.initial_guess.exprs:
127127
self._make_initial_guess()
128128
# Make the callback used to constrain boundary nodes
129-
if self.field_data.constrain_bc.exprs:
129+
if self.field_data.constrain_bc:
130130
self._make_constrain_bc()
131131
self._make_user_struct_callback()
132132

@@ -658,7 +658,6 @@ def _make_constrain_bc(self):
658658
exprs, options={'mpi': False}, sregistry=self.sregistry,
659659
concretize_mapper=self.concretize_mapper
660660
)
661-
# from IPython import embed; embed()
662661
body = self._create_constrain_bc_body(
663662
List(body=irs.uiet.body)
664663
)
@@ -669,7 +668,60 @@ def _make_constrain_bc(self):
669668
self._efuncs[cb.name] = cb
670669

671670
def _create_constrain_bc_body(self, body):
672-
return body
671+
linsolve_expr = self.inject_solve.expr.rhs
672+
objs = self.objs
673+
sobjs = self.solver_objs
674+
target = self.target
675+
676+
dmda = sobjs['callbackdm']
677+
ctx = objs['dummyctx']
678+
679+
x_arr = self.field_data.arrays[target]['x']
680+
681+
vec_get_array = petsc_call(
682+
'VecGetArray', [objs['xloc'], Byref(x_arr._C_symbol)]
683+
)
684+
685+
dm_get_local_info = petsc_call(
686+
'DMDAGetLocalInfo', [dmda, Byref(linsolve_expr.localinfo)]
687+
)
688+
689+
body = self.time_dependence.uxreplace_time(body)
690+
691+
fields = get_user_struct_fields(body)
692+
self._struct_params.extend(fields)
693+
694+
dm_get_app_context = petsc_call(
695+
'DMGetApplicationContext', [dmda, Byref(ctx._C_symbol)]
696+
)
697+
698+
vec_restore_array = petsc_call(
699+
'VecRestoreArray', [objs['xloc'], Byref(x_arr._C_symbol)]
700+
)
701+
702+
body = body._rebuild(body=body.body + (vec_restore_array,))
703+
704+
stacks = (
705+
vec_get_array,
706+
dm_get_local_info
707+
)
708+
709+
# Dereference function data in struct
710+
derefs = dereference_funcs(ctx, fields)
711+
712+
# Force the struct definition to appear at the very start, since
713+
# stacks, allocs etc may rely on its information
714+
struct_definition = [Definition(ctx), dm_get_app_context]
715+
716+
body = self._make_callable_body(
717+
body, standalones=struct_definition, stacks=stacks+derefs
718+
)
719+
720+
# Replace non-function data with pointer to data in struct
721+
subs = {i._C_symbol: FieldFromPointer(i._C_symbol, ctx) for
722+
i in fields if not isinstance(i.function, AbstractFunction)}
723+
724+
return Uxreplace(subs).visit(body)
673725

674726
def _make_user_struct_callback(self):
675727
"""

devito/petsc/types/metadata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,12 @@ class MultipleFieldData(FieldData):
210210
arrays : dict
211211
A dictionary mapping the `targets` to their corresponding PETScArrays.
212212
"""
213-
def __init__(self, targets, arrays, jacobian=None, residual=None):
213+
def __init__(self, targets, arrays, jacobian=None, residual=None, constrain_bc=None):
214214
self._targets = as_tuple(targets)
215215
self._arrays = arrays
216216
self._jacobian = jacobian
217217
self._residual = residual
218+
self._constrain_bc = constrain_bc
218219

219220
@cached_property
220221
def space_dimensions(self):

0 commit comments

Comments
 (0)