Beispiel #1
0
    def grid(self,
             value: Field or Tensor or Number or Geometry or callable = 0.,
             type: type = CenteredGrid,
             extrapolation: math.Extrapolation = None) -> CenteredGrid or StaggeredGrid:
        """
        *Deprecated* due to inconsistent extrapolation selection. Use `scalar_grid()` or `vector_grid()` instead.

        Creates a grid matching the resolution and bounds of the domain.
        The grid is created from the given `value` which must be one of the following:
        
        * Number (int, float, complex or zero-dimensional tensor): all grid values will be equal to `value`. This has a near-zero memory footprint.
        * Field: the given value is resampled to the grid cells of this Domain.
        * Tensor with spatial dimensions matching the domain resolution: grid values will equal `value`.
        * Geometry: grid values are determined from the volume overlap between grid cells and geometry. Non-overlapping = 0, fully enclosed grid cell = 1.
        * function(location: Tensor) returning one of the above.

        Args:
          value: constant, Field, Tensor or function specifying the grid values
          type: type of Grid to create, must be either CenteredGrid or StaggeredGrid
          extrapolation: (optional) grid extrapolation, defaults to Domain.boundaries['scalar_extrapolation']

        Returns:
          Grid of specified type
        """
        warnings.warn("Domain.grid is deprecated. Use scalar_grid or vector_grid instead.", DeprecationWarning)
        extrapolation = extrapolation or self.boundaries['scalar_extrapolation']
        if type is CenteredGrid:
            return CenteredGrid.sample(value, self.resolution, self.bounds, extrapolation)
        elif type is StaggeredGrid:
            return StaggeredGrid.sample(value, self.resolution, self.bounds, extrapolation)
        else:
            raise ValueError('Unknown grid type: %s' % type)
Beispiel #2
0
    def vector_grid(
        self,
        value: Field or Tensor or Number or Geometry or callable = 0.,
        type: type = CenteredGrid,
        extrapolation: math.Extrapolation = None
    ) -> CenteredGrid or StaggeredGrid:
        """
        Creates a vector grid matching the resolution and bounds of the domain.
        The grid is created from the given `value` which must be one of the following:
        
        * Number (int, float, complex or zero-dimensional tensor): all grid values will be equal to `value`. This has a near-zero memory footprint.
        * Field: the given value is resampled to the grid cells of this Domain.
        * Tensor with spatial dimensions matcing the domain resolution: grid values will equal `value`.
        * Geometry: grid values are determined from the volume overlap between grid cells and geometry. Non-overlapping = 0, fully enclosed grid cell = 1.
        * function(location: Tensor) returning one of the above.
        
        The returned grid will have a vector dimension with size equal to the rank of the domain.

        Args:
          value: constant, Field, Tensor or function specifying the grid values
          type: class of Grid to create, must be either CenteredGrid or StaggeredGrid
          extrapolation: (optional) grid extrapolation, defaults to Domain.boundaries['vector_extrapolation']

        Returns:
          Grid of specified type

        """
        extrapolation = extrapolation or self.boundaries['vector_extrapolation']
        if type is CenteredGrid:
            grid = CenteredGrid.sample(value, self.resolution, self.bounds,
                                       extrapolation)
            if grid.shape.channel.rank == 0:
                grid = grid.with_(values=math.expand_channel(
                    grid.values, 'vector', dim_size=self.rank))
            else:
                assert grid.shape.channel.sizes[0] == self.rank
            return grid
        elif type is StaggeredGrid:
            return StaggeredGrid.sample(value, self.resolution, self.bounds,
                                        extrapolation)
        else:
            raise ValueError('Unknown grid type: %s' % type)