def _constant_ctypes(self): # Retrieve data from Python object function_space = self.function_space() mesh = function_space.mesh() coordinates = mesh.coordinates coordinates_space = coordinates.function_space() # Store data into ``C struct'' c_function = _CFunction() c_function.n_cols = mesh.num_cells() if mesh.layers is not None: # TODO: assert constant layer. Can we do variable though? c_function.extruded = 1 c_function.n_layers = mesh.layers - 1 else: c_function.extruded = 0 c_function.n_layers = 1 c_function.coords = coordinates.dat.data.ctypes.data_as( POINTER(c_double)) c_function.coords_map = coordinates_space.cell_node_list.ctypes.data_as( POINTER(as_ctypes(IntType))) # FIXME: What about complex? c_function.f = self.dat.data.ctypes.data_as(POINTER(c_double)) c_function.f_map = function_space.cell_node_list.ctypes.data_as( POINTER(as_ctypes(IntType))) return c_function
class _CFunction(ctypes.Structure): """C struct collecting data from a :class:`Function`""" _fields_ = [("n_cols", c_int), ("n_layers", c_int), ("coords", POINTER(c_double)), ("coords_map", POINTER(as_ctypes(IntType))), # FIXME: what if f does not have type double? ("f", POINTER(c_double)), ("f_map", POINTER(as_ctypes(IntType))), ("sidx", c_void_p)]
def argtypes(kernel): args = [] for arg in kernel.args: if isinstance(arg, loopy.ValueArg): args.append(as_ctypes(arg.dtype)) elif isinstance(arg, loopy.ArrayArg): args.append(ctypes.c_voidp) else: raise ValueError("Unhandled arg type '%s'" % type(arg)) return args
def argtypes(kernel): args = [] for arg in kernel.args: if isinstance(arg, loopy.ValueArg): args.append(as_ctypes(arg.dtype)) elif isinstance(arg, loopy.ArrayArg): args.append(ctypes.c_voidp) else: raise ValueError("Unhandled arg type '%s'" % type(arg)) return args
def _constant_ctypes(self): # Retrieve data from Python object function_space = self.function_space() mesh = function_space.mesh() coordinates = mesh.coordinates coordinates_space = coordinates.function_space() # Store data into ``C struct'' c_function = _CFunction() c_function.n_cols = mesh.num_cells() if hasattr(mesh, '_layers'): c_function.n_layers = mesh.layers - 1 else: c_function.n_layers = 1 c_function.coords = coordinates.dat.data.ctypes.data_as( POINTER(c_double)) c_function.coords_map = coordinates_space.cell_node_list.ctypes.data_as( POINTER(as_ctypes(IntType))) # FIXME: What about complex? c_function.f = self.dat.data.ctypes.data_as(POINTER(c_double)) c_function.f_map = function_space.cell_node_list.ctypes.data_as( POINTER(as_ctypes(IntType))) return c_function
def argtypes(self): index_type = as_ctypes(IntType) argtypes = (index_type, index_type) argtypes += self._iterset._argtypes_ for arg in self._args: argtypes += arg._argtypes_ seen = set() for arg in self._args: maps = arg.map_tuple for map_ in maps: for k, t in zip(map_._kernel_args_, map_._argtypes_): if k in seen: continue argtypes += (t,) seen.add(k) return argtypes
def argtypes(self): index_type = as_ctypes(IntType) argtypes = (index_type, index_type) argtypes += self._iterset._argtypes_ for arg in self._args: argtypes += arg._argtypes_ seen = set() for arg in self._args: maps = arg.map_tuple for map_ in maps: for k, t in zip(map_._kernel_args_, map_._argtypes_): if k in seen: continue argtypes += (t, ) seen.add(k) return argtypes
def set_argtypes(self, iterset, *args): index_type = as_ctypes(IntType) argtypes = [index_type, index_type] if isinstance(iterset, Subset): argtypes.append(iterset._argtype) for arg in args: if arg._is_mat: argtypes.append(arg.data._argtype) else: for d in arg.data: argtypes.append(d._argtype) if arg._is_indirect or arg._is_mat: maps = as_tuple(arg.map, Map) for map in maps: if map is not None: for m in map: argtypes.append(m._argtype) if iterset._extruded: argtypes.append(index_type) argtypes.append(index_type) self._argtypes = argtypes
def _constant_ctypes(self): # Retrieve data from Python object function_space = self.function_space() mesh = function_space.mesh() coordinates = mesh.coordinates coordinates_space = coordinates.function_space() # Store data into ``C struct'' c_function = _CFunction() c_function.n_cols = mesh.num_cells() if mesh.layers is not None: # TODO: assert constant layer. Can we do variable though? c_function.extruded = 1 c_function.n_layers = mesh.layers - 1 else: c_function.extruded = 0 c_function.n_layers = 1 c_function.coords = coordinates.dat.data.ctypes.data_as(POINTER(c_double)) c_function.coords_map = coordinates_space.cell_node_list.ctypes.data_as(POINTER(as_ctypes(IntType))) # FIXME: What about complex? c_function.f = self.dat.data.ctypes.data_as(POINTER(c_double)) c_function.f_map = function_space.cell_node_list.ctypes.data_as(POINTER(as_ctypes(IntType))) return c_function