Utopia  2
Framework for studying models of complex & adaptive systems.
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Utopia::Grid< Space > Class Template Referenceabstract

The base class for all grid discretizations used by the CellManager. More...

#include <base.hh>

Inheritance diagram for Utopia::Grid< Space >:
Inheritance graph
[legend]

Public Types

using Self = Grid< Space >
 Type of this class, i.e. the base grid class. More...
 
using SpaceVec = typename Space::SpaceVec
 The type of vectors that have a relation to physical space. More...
 
using MultiIndex = MultiIndexType< dim >
 The type of multi-index like arrays, e.g. the grid shape. More...
 
using Config = DataIO::Config
 The configuration type. More...
 

Public Member Functions

 Grid (std::shared_ptr< Space > space, const Config &cfg)
 Construct a grid discretization. More...
 
virtual ~Grid ()=default
 Virtual destructor to allow polymorphic destruction. More...
 
IndexContainer neighbors_of (const IndexType id) const
 Returns the indices of the neighbors of the cell with the given ID. More...
 
void select_neighborhood (NBMode nb_mode, const Config &nb_params={})
 
const NBModenb_mode () const
 Const reference to the currently selected neighborhood mode. More...
 
const Confignb_params () const
 The neighborhood parameters of the currently selected neighborhood. More...
 
auto nb_size () const
 Maximum size of the currently selected neighborhood. More...
 
virtual MultiIndex midx_of (const IndexType) const =0
 Returns the multi-index of the cell with the given ID. More...
 
virtual SpaceVec barycenter_of (const IndexType) const =0
 Returns the barycenter of the cell with the given ID. More...
 
virtual SpaceVec extent_of (const IndexType) const =0
 Returns the extent of the cell with the given ID. More...
 
virtual std::vector< SpaceVecvertices_of (const IndexType) const =0
 Returns the vertices of the cell with the given ID. More...
 
virtual IndexType cell_at (const SpaceVec &) const =0
 Return the ID of the cell covering the given point in physical space. More...
 
virtual std::set< IndexTypeboundary_cells (std::string={}) const =0
 Retrieve a set of cell indices that are at a specified boundary. More...
 
virtual IndexType num_cells () const =0
 Get number of cells. More...
 
auto resolution () const
 Get scalar resolution value of this grid. More...
 
virtual SpaceVec effective_resolution () const =0
 Returns the effective resolution into each dimension of the grid. More...
 
virtual MultiIndex shape () const =0
 Get the shape of the grid discretization. More...
 
virtual GridStructure structure () const =0
 Structure of the grid. More...
 
std::string structure_name () const
 Structure of the grid as std::string. More...
 
const std::shared_ptr< Space > & space () const
 Const reference to the space this grid maps to. More...
 
bool is_periodic () const
 Whether the space this grid maps to is periodic. More...
 

Static Public Attributes

static constexpr DimType dim = Space::dim
 The dimensionality of the space to be discretized (for easier access) More...
 

Protected Member Functions

virtual NBFuncID< Selfget_nb_func (NBMode, const Config &)=0
 Retrieve the neighborhood function depending on the mode. More...
 
virtual DistType expected_num_neighbors (const NBMode &, const Config &) const =0
 

Protected Attributes

const std::shared_ptr< Space_space
 The space that is to be discretized. More...
 
const DistType _resolution
 How many cells to place per length unit of space. More...
 
NBMode _nb_mode
 Neighborhood mode. More...
 
Config _nb_params
 Neighborhood parameters. More...
 
NBFuncID< Self_nb_func
 Neighborhood function (working on cell IDs) More...
 
NBFuncID< Self_nb_empty
 A neighborhood function for empty neighborhood. More...
 

Detailed Description

template<class Space>
class Utopia::Grid< Space >

The base class for all grid discretizations used by the CellManager.

Member Typedef Documentation

◆ Config

template<class Space >
using Utopia::Grid< Space >::Config = DataIO::Config

The configuration type.

◆ MultiIndex

template<class Space >
using Utopia::Grid< Space >::MultiIndex = MultiIndexType<dim>

The type of multi-index like arrays, e.g. the grid shape.

◆ Self

template<class Space >
using Utopia::Grid< Space >::Self = Grid<Space>

Type of this class, i.e. the base grid class.

◆ SpaceVec

template<class Space >
using Utopia::Grid< Space >::SpaceVec = typename Space::SpaceVec

The type of vectors that have a relation to physical space.

Constructor & Destructor Documentation

◆ Grid()

template<class Space >
Utopia::Grid< Space >::Grid ( std::shared_ptr< Space space,
const Config cfg 
)
inline

Construct a grid discretization.

Parameters
spaceThe space to construct the discretization for
cfgFurther configuration parameters

◆ ~Grid()

template<class Space >
virtual Utopia::Grid< Space >::~Grid ( )
virtualdefault

Virtual destructor to allow polymorphic destruction.

Member Function Documentation

◆ barycenter_of()

template<class Space >
virtual SpaceVec Utopia::Grid< Space >::barycenter_of ( const  IndexType) const
pure virtual

Returns the barycenter of the cell with the given ID.

Note
This method does not perform bounds checking of the given ID!

Implemented in Utopia::TriangularGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::HexagonalGrid< Space >.

◆ boundary_cells()

template<class Space >
virtual std::set<IndexType> Utopia::Grid< Space >::boundary_cells ( std::string  = {}) const
pure virtual

Retrieve a set of cell indices that are at a specified boundary.

Note
For a periodic space, an empty container is returned; no error or warning is emitted.
Parameters
selectWhich boundary to return the cell IDs of. If 'all', all boundary cells are returned. Other available values depend on the dimensionality of the grid: 1D: left, right 2D: bottom, top 3D: back, front

Implemented in Utopia::TriangularGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::HexagonalGrid< Space >.

◆ cell_at()

template<class Space >
virtual IndexType Utopia::Grid< Space >::cell_at ( const SpaceVec ) const
pure virtual

Return the ID of the cell covering the given point in physical space.

Cells are interpreted as covering half-open intervals in space, i.e., including their low-value edges and excluding their high-value edges. The special case of points on high-value edges for non-periodic space behaves such that these points are associated with the cells at the boundary.

Note
This function always returns IDs of cells that are inside physical space. For non-periodic space, a check is performed whether the given point is inside the physical space associated with this grid. For periodic space, the given position is mapped back into the physical space.

Implemented in Utopia::SquareGrid< Space >, Utopia::HexagonalGrid< Space >, and Utopia::TriangularGrid< Space >.

◆ effective_resolution()

template<class Space >
virtual SpaceVec Utopia::Grid< Space >::effective_resolution ( ) const
pure virtual

Returns the effective resolution into each dimension of the grid.

Depending on choice of resolution and extent of physical space, the resolution given at initialization might not represent the density of cells per unit of space fully accurately. The effective resolution accounts for the scaling that was required to map an integer number of cells onto the space.

Implemented in Utopia::TriangularGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::HexagonalGrid< Space >.

◆ expected_num_neighbors()

template<class Space >
virtual DistType Utopia::Grid< Space >::expected_num_neighbors ( const NBMode ,
const Config  
) const
protectedpure virtual

Computes the expected number of neighbors for a given neighborhood mode and a corresponding set of neighborhood parameters

Implemented in Utopia::SquareGrid< Space >, Utopia::TriangularGrid< Space >, and Utopia::HexagonalGrid< Space >.

◆ extent_of()

template<class Space >
virtual SpaceVec Utopia::Grid< Space >::extent_of ( const  IndexType) const
pure virtual

Returns the extent of the cell with the given ID.

Note
This method does not perform bounds checking of the given ID!

Implemented in Utopia::TriangularGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::HexagonalGrid< Space >.

◆ get_nb_func()

template<class Space >
virtual NBFuncID<Self> Utopia::Grid< Space >::get_nb_func ( NBMode  ,
const Config  
)
protectedpure virtual

Retrieve the neighborhood function depending on the mode.

The configuration node that is passed along can be used to specify the neighborhood parameter members.

Implemented in Utopia::SquareGrid< Space >, Utopia::HexagonalGrid< Space >, and Utopia::TriangularGrid< Space >.

◆ is_periodic()

template<class Space >
bool Utopia::Grid< Space >::is_periodic ( ) const
inline

Whether the space this grid maps to is periodic.

◆ midx_of()

template<class Space >
virtual MultiIndex Utopia::Grid< Space >::midx_of ( const  IndexType) const
pure virtual

Returns the multi-index of the cell with the given ID.

Note
This method does not perform bounds checking of the given ID!

Implemented in Utopia::TriangularGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::HexagonalGrid< Space >.

◆ nb_mode()

template<class Space >
const NBMode& Utopia::Grid< Space >::nb_mode ( ) const
inline

Const reference to the currently selected neighborhood mode.

◆ nb_params()

template<class Space >
const Config& Utopia::Grid< Space >::nb_params ( ) const
inline

The neighborhood parameters of the currently selected neighborhood.

◆ nb_size()

template<class Space >
auto Utopia::Grid< Space >::nb_size ( ) const
inline

Maximum size of the currently selected neighborhood.

◆ neighbors_of()

template<class Space >
IndexContainer Utopia::Grid< Space >::neighbors_of ( const IndexType  id) const
inline

Returns the indices of the neighbors of the cell with the given ID.

◆ num_cells()

template<class Space >
virtual IndexType Utopia::Grid< Space >::num_cells ( ) const
pure virtual

Get number of cells.

This information is used by the CellManager to populate the cell container with the returned number of cells

Implemented in Utopia::TriangularGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::HexagonalGrid< Space >.

◆ resolution()

template<class Space >
auto Utopia::Grid< Space >::resolution ( ) const
inline

Get scalar resolution value of this grid.

◆ select_neighborhood()

template<class Space >
void Utopia::Grid< Space >::select_neighborhood ( NBMode  nb_mode,
const Config nb_params = {} 
)
inline

◆ shape()

template<class Space >
virtual MultiIndex Utopia::Grid< Space >::shape ( ) const
pure virtual

Get the shape of the grid discretization.

Implemented in Utopia::TriangularGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::HexagonalGrid< Space >.

◆ space()

template<class Space >
const std::shared_ptr<Space>& Utopia::Grid< Space >::space ( ) const
inline

Const reference to the space this grid maps to.

◆ structure()

template<class Space >
virtual GridStructure Utopia::Grid< Space >::structure ( ) const
pure virtual

◆ structure_name()

template<class Space >
std::string Utopia::Grid< Space >::structure_name ( ) const
inline

Structure of the grid as std::string.

◆ vertices_of()

template<class Space >
virtual std::vector<SpaceVec> Utopia::Grid< Space >::vertices_of ( const  IndexType) const
pure virtual

Returns the vertices of the cell with the given ID.

Consult the derived class implementation's documentation on the order of the vertices in the returned container.

Note
This method does not perform bounds checking of the given ID!

Implemented in Utopia::TriangularGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::HexagonalGrid< Space >.

Member Data Documentation

◆ _nb_empty

template<class Space >
NBFuncID<Self> Utopia::Grid< Space >::_nb_empty
protected
Initial value:
= [](const IndexType) {
idcs.reserve(0);
return idcs;
}
std::vector< IndexType > IndexContainer
Type for container of indices.
Definition: types.hh:43
std::size_t IndexType
Type for indices, i.e. values used for container indexing, agent IDs, ...
Definition: types.hh:40

A neighborhood function for empty neighborhood.

◆ _nb_func

template<class Space >
NBFuncID<Self> Utopia::Grid< Space >::_nb_func
protected

Neighborhood function (working on cell IDs)

◆ _nb_mode

template<class Space >
NBMode Utopia::Grid< Space >::_nb_mode
protected

Neighborhood mode.

◆ _nb_params

template<class Space >
Config Utopia::Grid< Space >::_nb_params
protected

Neighborhood parameters.

◆ _resolution

template<class Space >
const DistType Utopia::Grid< Space >::_resolution
protected

How many cells to place per length unit of space.

Note
The effective resolution might differ from this number, depending on the choice of resolution value and the physical extent of the space in each dimension.

◆ _space

template<class Space >
const std::shared_ptr<Space> Utopia::Grid< Space >::_space
protected

The space that is to be discretized.

◆ dim

template<class Space >
constexpr DimType Utopia::Grid< Space >::dim = Space::dim
staticconstexpr

The dimensionality of the space to be discretized (for easier access)


The documentation for this class was generated from the following file: