Skip to content

Commit

Permalink
Fix coarsen DM
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrubeck committed Oct 21, 2024
1 parent e27b702 commit f4fdbb8
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions firedrake/mg/ufl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,23 @@ def coarsen_snescontext(context, self, coefficient_mapping=None):
coarse._fine = context
context._coarse = coarse

# Now that we have the coarse snescontext, push it to the coarsened DMs
# Otherwise they won't have the right transfer manager when they are
# coarsened in turn
for val in chain(coefficient_mapping.values(), (bc.function_arg for bc in problem.bcs)):
if isinstance(val, (firedrake.Function, firedrake.Cofunction)):
V = val.function_space()
coarseneddm = V.dm
parentdm = get_parent(context._problem.u.function_space().dm)

# Now attach the hook to the parent DM
if get_appctx(coarseneddm) is None:
push_appctx(coarseneddm, coarse)
teardown = partial(pop_appctx, coarseneddm, coarse)
add_hook(parentdm, teardown=teardown)
solution = context._problem.u
solutiondm = solution.function_space().dm
parentdm = get_parent(solutiondm)
if parentdm != solutiondm:
# Now that we have the coarse snescontext, push it to the coarsened DMs
# Otherwise they won't have the right transfer manager when they are
# coarsened in turn
for val in chain(coefficient_mapping.values(), (bc.function_arg for bc in problem.bcs)):
if isinstance(val, (firedrake.Function, firedrake.Cofunction)):
V = val.function_space()
coarseneddm = V.dm

# Now attach the hook to the parent DM
if get_appctx(coarseneddm) is None:
push_appctx(coarseneddm, coarse)
teardown = partial(pop_appctx, coarseneddm, coarse)
add_hook(parentdm, teardown=teardown)

ises = problem.J.arguments()[0].function_space()._ises
coarse._nullspace = self(context._nullspace, self, coefficient_mapping=coefficient_mapping)
Expand Down Expand Up @@ -384,7 +387,8 @@ def create_interpolation(dmc, dmf):
mat.setType(mat.Type.PYTHON)
mat.setPythonContext(ctx)
mat.setUp()
return mat, None
rscale = mat.createVecLeft() if row_size == col_size else None
return mat, rscale


def create_injection(dmc, dmf):
Expand Down

0 comments on commit f4fdbb8

Please sign in to comment.