Ejemplo n.º 1
0
def make_c_evaluate(function, c_name="evaluate", ldargs=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
    import firedrake.pointquery_utils as pq_utils

    function_space = function.function_space()

    src = pq_utils.src_locate_cell(function_space.mesh())
    src += compile_element(function_space.ufl_element(), function_space.dim)
    src += pq_utils.make_wrapper(function,
                                 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],
                            ldargs=ldargs,
                            comm=function.comm)
Ejemplo n.º 2
0
def make_c_evaluate(function, c_name="evaluate", ldargs=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
    import firedrake.pointquery_utils as pq_utils

    function_space = function.function_space()

    src = pq_utils.src_locate_cell(function_space.mesh())
    src += compile_element(function_space.ufl_element(), function_space.dim)
    src += pq_utils.make_wrapper(function,
                                 forward_args=["double*", "double*"],
                                 kernel_name="evaluate_kernel",
                                 wrapper_name="wrap_evaluate")

    if ldargs is None:
        ldargs = []
    ldargs += ["-lspatialindex"]
    return compilation.load(src,
                            "cpp",
                            c_name,
                            cppargs=["-I%s" % path.dirname(__file__)],
                            ldargs=ldargs)
Ejemplo n.º 3
0
def make_c_evaluate(function, c_name="evaluate", ldargs=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
    import firedrake.pointquery_utils as pq_utils

    function_space = function.function_space()

    src = pq_utils.src_locate_cell(function_space.mesh())
    src += compile_element(function_space.ufl_element(), function_space.dim)
    src += pq_utils.make_wrapper(function,
                                 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)
Ejemplo n.º 4
0
def make_c_evaluate(function, c_name="evaluate", ldargs=None, tolerance=None):
    r"""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.sequential import generate_single_cell_wrapper
    import firedrake.pointquery_utils as pq_utils

    mesh = function.ufl_domain()
    src = [pq_utils.src_locate_cell(mesh, tolerance=tolerance)]
    src.append(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)

    p_ScalarType_c = f"{utils.ScalarType_c}*"
    src.append(
        generate_single_cell_wrapper(
            mesh.cell_set,
            args,
            forward_args=[p_ScalarType_c, p_ScalarType_c],
            kernel_name="evaluate_kernel",
            wrapper_name="wrap_evaluate"))

    src = "\n".join(src)

    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)
Ejemplo n.º 5
0
def make_c_evaluate(function, c_name="evaluate", ldargs=None, tolerance=None):
    r"""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.sequential import generate_single_cell_wrapper
    import firedrake.pointquery_utils as pq_utils

    mesh = function.ufl_domain()
    src = [pq_utils.src_locate_cell(mesh, tolerance=tolerance)]
    src.append(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.append(generate_single_cell_wrapper(mesh.cell_set, args,
                                            forward_args=["double*", "double*"],
                                            kernel_name="evaluate_kernel",
                                            wrapper_name="wrap_evaluate"))

    src = "\n".join(src)

    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)