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)
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)
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)
def _c_locator(self): from pyop2 import compilation import firedrake.function as function import firedrake.pointquery_utils as pq_utils src = pq_utils.src_locate_cell(self) src += """ int locator(struct Function *f, double *x) { struct ReferenceCoords reference_coords; return locate_cell(f, x, %(geometric_dimension)d, &to_reference_coords, &reference_coords); } """ % dict(geometric_dimension=self.geometric_dimension()) locator = compilation.load(src, "c", "locator", cppargs=["-I%s" % os.path.dirname(__file__), "-I%s/include" % sys.prefix], ldargs=["-L%s/lib" % sys.prefix, "-lspatialindex_c", "-Wl,-rpath,%s/lib" % sys.prefix]) locator.argtypes = [ctypes.POINTER(function._CFunction), ctypes.POINTER(ctypes.c_double)] locator.restype = ctypes.c_int return locator
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)
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)
def _c_locator(self): from pyop2 import compilation import firedrake.function as function import firedrake.pointquery_utils as pq_utils src = pq_utils.src_locate_cell(self) src += """ extern "C" int locator(struct Function *f, double *x) { struct ReferenceCoords reference_coords; return locate_cell(f, x, %(geometric_dimension)d, &to_reference_coords, &reference_coords); } """ % dict(geometric_dimension=self.geometric_dimension()) locator = compilation.load(src, "cpp", "locator", cppargs=["-I%s" % os.path.dirname(__file__)], ldargs=["-lspatialindex"]) locator.argtypes = [ctypes.POINTER(function._CFunction), ctypes.POINTER(ctypes.c_double)] locator.restype = ctypes.c_int return locator