Exemplo n.º 1
0
def make_c_evaluate(function, c_name="evaluate", ldargs=None, tolerance=None):
    """Generates, compiles and loads a C function to evaluate the
    given Firedrake :class:`Function`."""

    from os import path
    from firedrake.pointeval_utils import compile_element
    from pyop2 import compilation
    from pyop2.utils import get_petsc_dir
    from pyop2.base import build_itspace
    from pyop2.sequential import generate_cell_wrapper
    import firedrake.pointquery_utils as pq_utils

    mesh = function.ufl_domain()
    src = pq_utils.src_locate_cell(mesh, tolerance=tolerance)
    src += compile_element(function, mesh.coordinates)

    args = []

    arg = mesh.coordinates.dat(op2.READ, mesh.coordinates.cell_node_map())
    arg.position = 0
    args.append(arg)

    arg = function.dat(op2.READ, function.cell_node_map())
    arg.position = 1
    args.append(arg)

    src += generate_cell_wrapper(build_itspace(args, mesh.cell_set),
                                 args,
                                 forward_args=["double*", "double*"],
                                 kernel_name="evaluate_kernel",
                                 wrapper_name="wrap_evaluate")

    if ldargs is None:
        ldargs = []
    ldargs += [
        "-L%s/lib" % sys.prefix, "-lspatialindex_c",
        "-Wl,-rpath,%s/lib" % sys.prefix
    ]
    return compilation.load(
        src,
        "c",
        c_name,
        cppargs=["-I%s" % path.dirname(__file__),
                 "-I%s/include" % sys.prefix] +
        ["-I%s/include" % d for d in get_petsc_dir()],
        ldargs=ldargs,
        comm=function.comm)
Exemplo n.º 2
0
def make_wrapper(function, **kwargs):
    args = make_args(function)
    return generate_cell_wrapper(build_itspace(args, function.cell_set), args, **kwargs)
Exemplo n.º 3
0
def make_wrapper(function, **kwargs):
    args = make_args(function)
    return generate_cell_wrapper(build_itspace(args, function.cell_set), args,
                                 **kwargs)
Exemplo n.º 4
0
def make_wrapper(function, **kwargs):
    args = make_args(function)
    return generate_cell_wrapper(function.cell_set, args, **kwargs)
Exemplo n.º 5
0
    def make_wrapper(function, **kwargs):
        from pyop2.base import build_itspace
        from pyop2.sequential import generate_cell_wrapper

        args = make_args(function)
        return generate_cell_wrapper(build_itspace(args, function.cell_set), args, **kwargs)