示例#1
0
def project_firedrake(v, V, **kwargs):

    annotate = kwargs.pop("annotate", None)

    to_annotate = utils.to_annotate(annotate)

    if isinstance(v, backend.Expression) and (annotate is not True):
        to_annotate = False

    if isinstance(v, backend.Constant) and (annotate is not True):
        to_annotate = False

    if isinstance(V, backend.functionspaceimpl.WithGeometry):
        result = utils.function_to_da_function(backend.Function(V, name=None))
    elif isinstance(V, backend.function.Function):
        result = utils.function_to_da_function(V)
    else:
        raise ValueError("Can't project into a '%r'" % V)

    name = kwargs.pop("name", None)
    if name is not None:
        result.adj_name = name
        result.rename(name, "a Function from dolfin-adjoint")
    with misc.annotations(to_annotate):
        result = backend.project(v, result, **kwargs)

    return result
示例#2
0
    def copy(self, *args, **kwargs):

        name = kwargs.pop("name", None)
        annotate = kwargs.pop("annotate", None)
        to_annotate = utils.to_annotate(annotate)

        with misc.annotations(False):
            copy = backend.Function.copy(self, *args, **kwargs)
            copy = utils.function_to_da_function(copy)

        if name is not None:
            copy.adj_name = name
            copy.rename(name, "a Function from dolfin-adjoint")
            adjglobals.function_names.add(name)

        if to_annotate:
            assignment.register_assign(copy, self)

        return copy
示例#3
0
def replay_dolfin(forget=False, tol=0.0, stop=False):

    with misc.annotations(False):
        if not backend.parameters["adjoint"]["record_all"]:
            info_red("Warning: your replay test will be much more effective with dolfin.parameters['adjoint']['record_all'] = True.")

        success = True
        for i in range(adjglobals.adjointer.equation_count):
            (fwd_var, output) = adjglobals.adjointer.get_forward_solution(i)
            storage = libadjoint.MemoryStorage(output)
            storage.set_compare(tol=tol)
            storage.set_overwrite(True)
            out = adjglobals.adjointer.record_variable(fwd_var, storage)
            success = success and out

            if forget:
                adjglobals.adjointer.forget_forward_equation(i)

            if not out and stop:
                break

    return success
示例#4
0
def hessian(J, m, warn=True):
    '''Choose which Hessian the user wants.'''
    with misc.annotations(False):
        H = BasicHessian(J, m, warn=warn)
    return H