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 __indices_setup__(cls, **kwargs): dimensions = kwargs.get('dimensions') if dimensions is not None: return dimensions, dimensions else: dimensions = (Dimension(name='p_%s' % kwargs["name"]), ) return dimensions, dimensions
def __indices_setup__(cls, **kwargs): dimensions = kwargs.get('dimensions') if dimensions is not None: return dimensions else: return (kwargs['grid'].time_dim, Dimension(name='p_%s' % kwargs["name"]))
def __init__(self, **kwargs): super(SubDomainSet, self).__init__() if self.implicit_dimension is None: n = Dimension(name='n') self.implicit_dimension = n self._n_domains = kwargs.get('N', 1) self._bounds = kwargs.get('bounds', None)
def __init__(self, **kwargs): super().__init__() if self.implicit_dimension is None: self.implicit_dimension = Dimension(name='n') self._n_domains = kwargs.get('N', 1) self._global_bounds = kwargs.get('bounds', None)
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.")
def __indices_setup__(cls, **kwargs): dimensions = as_tuple(kwargs.get('dimensions')) if not dimensions: dimensions = (Dimension(name='p_%s' % kwargs["name"]), ) return dimensions, dimensions