Example #1
0
    def compute_operators(ksp, J, P):
        """Form the Jacobian for this problem

        :arg ksp: a PETSc KSP object
        :arg J: the Jacobian (a Mat)
        :arg P: the preconditioner matrix (a Mat)
        """
        from firedrake import inject
        dm = ksp.getDM()
        ctx = dmhooks.get_appctx(dm)
        problem = ctx._problem

        assert J.handle == ctx._jac.petscmat.handle
        if problem._constant_jacobian and ctx._jacobian_assembled:
            # Don't need to do any work with a constant jacobian
            # that's already assembled
            return
        ctx._jacobian_assembled = True

        fine = ctx._fine
        if fine is not None:
            inject(fine._x, ctx._x)
            for bc in ctx._problem.bcs:
                bc.apply(ctx._x)

        ctx._assemble_jac()
        ctx._jac.force_evaluation()
        if ctx.Jp is not None:
            assert P.handle == ctx._pjac.petscmat.handle
            ctx._assemble_pjac()
            ctx._pjac.force_evaluation()
Example #2
0
    def compute_operators(ksp, J, P):
        """Form the Jacobian for this problem

        :arg ksp: a PETSc KSP object
        :arg J: the Jacobian (a Mat)
        :arg P: the preconditioner matrix (a Mat)
        """
        from firedrake import inject
        dm = ksp.getDM()
        ctx = dmhooks.get_appctx(dm)
        problem = ctx._problem

        assert J.handle == ctx._jac.petscmat.handle
        if problem._constant_jacobian and ctx._jacobian_assembled:
            # Don't need to do any work with a constant jacobian
            # that's already assembled
            return
        ctx._jacobian_assembled = True

        fine = ctx._fine
        if fine is not None:
            inject(fine._x, ctx._x)
            for bc in ctx._problem.bcs:
                bc.apply(ctx._x)

        ctx._assemble_jac()
        ctx._jac.force_evaluation()
        if ctx.Jp is not None:
            assert P.handle == ctx._pjac.petscmat.handle
            ctx._assemble_pjac()
            ctx._pjac.force_evaluation()
Example #3
0
 def multTranspose(self, mat, x, y):
     with self.ffn.dat.vec as v:
         x.copy(v)
     firedrake.inject(self.ffn, self.cfn)
     for bc in self.cbcs:
         bc.apply(self.cfn)
     with self.cfn.dat.vec_ro as v:
         v.copy(y)
Example #4
0
 def multTranspose(self, mat, x, y):
     with self.ffn.dat.vec as v:
         x.copy(v)
     firedrake.inject(self.ffn, self.cfn)
     for bc in self.cbcs:
         bc.apply(self.cfn)
     with self.cfn.dat.vec_ro as v:
         v.copy(y)
Example #5
0
def coarsen_function(expr, coefficient_mapping=None):
    if coefficient_mapping is None:
        coefficient_mapping = {}
    new = coefficient_mapping.get(expr)
    if new is None:
        V = coarsen(expr.function_space())
        new = firedrake.Function(V)
        firedrake.inject(expr, new)
    return new
Example #6
0
def coarsen_function(expr, coefficient_mapping=None):
    if coefficient_mapping is None:
        coefficient_mapping = {}
    new = coefficient_mapping.get(expr)
    if new is None:
        V = coarsen(expr.function_space())
        new = firedrake.Function(V)
        firedrake.inject(expr, new)
    return new
Example #7
0
def coarsen_function(expr, self, coefficient_mapping=None):
    if coefficient_mapping is None:
        coefficient_mapping = {}
    new = coefficient_mapping.get(expr)
    if new is None:
        V = self(expr.function_space(), self)
        new = firedrake.Function(V, name="coarse_%s" % expr.name())
        firedrake.inject(expr, new)
    return new
Example #8
0
 def inject(f, c):
     return firedrake.inject(f, c)
Example #9
0
 def inject(f, c):
     return firedrake.inject(f, c)