diff --git a/firedrake/preconditioners/assembled.py b/firedrake/preconditioners/assembled.py index d0e225e813..a0234048d5 100644 --- a/firedrake/preconditioners/assembled.py +++ b/firedrake/preconditioners/assembled.py @@ -17,7 +17,6 @@ class AssembledPC(PCBase): _prefix = "assembled_" def initialize(self, pc): - from firedrake.assemble import get_assembler A, P = pc.getOperators() if pc.type != "python": @@ -45,7 +44,13 @@ def initialize(self, pc): (a, bcs) = self.form(pc, test, trial) - form_assembler = get_assembler(a, bcs=bcs, form_compiler_parameters=fcp, mat_type=mat_type, options_prefix=options_prefix) + self._ctx_ref = self.new_snes_ctx(opc, a, bcs, mat_type, + fcp=fcp, + sub_mat_type=sub_mat_type, + options_prefix=options_prefix) + + form_assembler = self._ctx_ref._assembler_jac + self.P = form_assembler.allocate() self._assemble_P = form_assembler.assemble self._assemble_P(tensor=self.P) @@ -62,11 +67,6 @@ def initialize(self, pc): # We set a DM and an appropriate SNESContext on the constructed PC so one # can do e.g. multigrid or patch solves. dm = opc.getDM() - self._ctx_ref = self.new_snes_ctx(opc, a, bcs, mat_type, - fcp=fcp, - sub_mat_type=sub_mat_type, - options_prefix=options_prefix) - pc.setDM(dm) pc.setOptionsPrefix(options_prefix) pc.setOperators(A, self.P.petscmat) diff --git a/firedrake/solving_utils.py b/firedrake/solving_utils.py index 5efecc2e20..b1090d1111 100644 --- a/firedrake/solving_utils.py +++ b/firedrake/solving_utils.py @@ -279,15 +279,21 @@ def __init__(self, problem, def reconstruct(self, problem=None, mat_type=None, pmat_type=None, **kwargs): """Reconstruct this _SNESContext instance with new arguments.""" - problem = problem or self.problem + problem = problem or self._problem mat_type = mat_type or self.mat_type pmat_type = pmat_type or self.pmat_type - kwargs.setdefault("sub_mat_type", self.sub_mat_type) - kwargs.setdefault("sub_pmat_type", self.sub_pmat_type) - kwargs.setdefault("appctx", self.appctx) - kwargs.setdefault("options_prefix", self.options_prefix) - kwargs.setdefault("transfer_manager", self.transfer_manager) - kwargs.setdefault("pre_apply_bcs", self.pre_apply_bcs) + + default_options = { + "sub_mat_type": self.sub_mat_type, + "sub_pmat_type": self.sub_pmat_type, + "appctx": self.appctx, + "options_prefix": self.options_prefix, + "transfer_manager": self.transfer_manager, + "pre_apply_bcs": self.pre_apply_bcs, + } + for k, v in default_options.items(): + if kwargs.get(k) is None: + kwargs[k] = v return _SNESContext(problem, mat_type, pmat_type, **kwargs) @property