def __init__(self, *args, **kwargs): if not self._cached(): super(SparseFunction, self).__init__(*args, **kwargs) # Set up sparse point coordinates coordinates = kwargs.get('coordinates', kwargs.get('coordinates_data')) if isinstance(coordinates, Function): self._coordinates = coordinates else: dimensions = (self.indices[-1], Dimension(name='d')) # Only retain the local data region if coordinates is not None: coordinates = np.array(coordinates) self._coordinates = SubFunction(name='%s_coords' % self.name, parent=self, dtype=self.dtype, dimensions=dimensions, shape=(self.npoint, self.grid.dim), space_order=0, initializer=coordinates, distributor=self._distributor) if self.npoint == 0: # This is a corner case -- we might get here, for example, when # running with MPI and some processes get 0-size arrays after # domain decomposition. We "touch" the data anyway to avoid the # case ``self._data is None`` self.coordinates.data
def __init__(self, *args, **kwargs): if not self._cached(): super(PrecomputedSparseFunction, self).__init__(*args, **kwargs) # Grid points per sparse point (2 in the case of bilinear and trilinear) r = kwargs.get('r') if not isinstance(r, int): raise TypeError('Need `r` int argument') if r <= 0: raise ValueError('`r` must be > 0') self.r = r gridpoints = SubFunction(name="%s_gridpoints" % self.name, dtype=np.int32, dimensions=(self.indices[-1], Dimension(name='d')), shape=(self.npoint, self.grid.dim), space_order=0, parent=self) gridpoints_data = kwargs.get('gridpoints', None) assert(gridpoints_data is not None) gridpoints.data[:] = gridpoints_data[:] self._gridpoints = gridpoints interpolation_coeffs = SubFunction(name="%s_interpolation_coeffs" % self.name, dimensions=(self.indices[-1], Dimension(name='d'), Dimension(name='i')), shape=(self.npoint, self.grid.dim, self.r), dtype=self.dtype, space_order=0, parent=self) coefficients_data = kwargs.get('interpolation_coeffs', None) assert(coefficients_data is not None) interpolation_coeffs.data[:] = coefficients_data[:] self._interpolation_coeffs = interpolation_coeffs warning("Ensure that the provided interpolation coefficient and grid point " + "values are computed on the final grid that will be used for other " + "computations.")
def __init__(self, *args, **kwargs): if not self._cached(): super(PrecomputedSparseFunction, self).__init__(*args, **kwargs) # Grid points per sparse point (2 in the case of bilinear and trilinear) r = kwargs.get('r') if not isinstance(r, int): raise TypeError('Need `r` int argument') if r <= 0: raise ValueError('`r` must be > 0') self.r = r gridpoints = SubFunction(name="%s_gridpoints" % self.name, dtype=np.int32, dimensions=(self.indices[-1], Dimension(name='d')), shape=(self.npoint, self.grid.dim), space_order=0, parent=self) gridpoints_data = kwargs.get('gridpoints', None) assert (gridpoints_data is not None) gridpoints.data[:] = gridpoints_data[:] self._gridpoints = gridpoints interpolation_coeffs = SubFunction( name="%s_interpolation_coeffs" % self.name, dimensions=(self.indices[-1], Dimension(name='d'), Dimension(name='i')), shape=(self.npoint, self.grid.dim, self.r), dtype=self.dtype, space_order=0, parent=self) coefficients_data = kwargs.get('interpolation_coeffs', None) assert (coefficients_data is not None) interpolation_coeffs.data[:] = coefficients_data[:] self._interpolation_coeffs = interpolation_coeffs warning( "Ensure that the provided interpolation coefficient and grid point " + "values are computed on the final grid that will be used for other " + "computations.")
def __init__(self, obj, r, gridpoints_data, coefficients_data): if not isinstance(r, int): raise TypeError('Need `r` int argument') if r <= 0: raise ValueError('`r` must be > 0') self.r = r self.obj = obj self._npoint = obj._npoint gridpoints = SubFunction(name="%s_gridpoints" % self.obj.name, dtype=np.int32, dimensions=(self.obj.indices[-1], Dimension(name='d')), shape=(self._npoint, self.obj.grid.dim), space_order=0, parent=self) assert (gridpoints_data is not None) gridpoints.data[:] = gridpoints_data[:] self.obj._gridpoints = gridpoints interpolation_coeffs = SubFunction( name="%s_interpolation_coeffs" % self.obj.name, dimensions=(self.obj.indices[-1], Dimension(name='d'), Dimension(name='i')), shape=(self.obj.npoint, self.obj.grid.dim, self.r), dtype=self.obj.dtype, space_order=0, parent=self) assert (coefficients_data is not None) interpolation_coeffs.data[:] = coefficients_data[:] self.obj._interpolation_coeffs = interpolation_coeffs warning( "Ensure that the provided interpolation coefficient and grid point " + "values are computed on the final grid that will be used for other " + "computations.")