Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
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.
 
using SpaceVec = typename Space::SpaceVec
 The type of vectors that have a relation to physical space.
 
using MultiIndex = MultiIndexType< dim >
 The type of multi-index like arrays, e.g. the grid shape.
 
using Config = DataIO::Config
 The configuration type.
 

Public Member Functions

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

Static Public Attributes

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

Protected Member Functions

virtual NBFuncID< Selfget_nb_func (NBMode, const Config &)=0
 Retrieve the neighborhood function depending on the mode.
 
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.
 
const DistType _resolution
 How many cells to place per length unit of space.
 
NBMode _nb_mode
 Neighborhood mode.
 
Config _nb_params
 Neighborhood parameters.
 
NBFuncID< Self_nb_func
 Neighborhood function (working on cell IDs)
 
NBFuncID< Self_nb_empty
 A neighborhood function for empty neighborhood.
 

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

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
146 :
147 _space(space),
148 _resolution([&cfg](){
149 if (not cfg["resolution"]) {
150 throw std::invalid_argument("Missing grid configuration "
151 "parameter 'resolution'! Please supply an integer >= 1.");
152 }
153
154 // Read in as signed int (allows throwing error for negative value)
155 const auto res = get_as<long long>("resolution", cfg);
156
157 if (res < 1) {
158 throw std::invalid_argument("Grid resolution needs to be a "
159 "positive integer, was < 1!");
160 }
161 return res;
162 }()),
164 _nb_params()
165 {
166 // Set the neighborhood function to not return anything
168 }
const DistType _resolution
How many cells to place per length unit of space.
Definition base.hh:127
NBFuncID< Self > _nb_func
Neighborhood function (working on cell IDs)
Definition base.hh:136
const std::shared_ptr< Space > _space
The space that is to be discretized.
Definition base.hh:120
NBMode _nb_mode
Neighborhood mode.
Definition base.hh:130
NBFuncID< Self > _nb_empty
A neighborhood function for empty neighborhood.
Definition base.hh:323
const std::shared_ptr< Space > & space() const
Const reference to the space this grid maps to.
Definition base.hh:299
Config _nb_params
Neighborhood parameters.
Definition base.hh:133
@ empty
Every entity is utterly alone in the world.
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

◆ ~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::HexagonalGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::TriangularGrid< 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::HexagonalGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::TriangularGrid< 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::TriangularGrid< Space >, Utopia::HexagonalGrid< Space >, and Utopia::SquareGrid< 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::HexagonalGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::TriangularGrid< 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::HexagonalGrid< Space >, Utopia::TriangularGrid< Space >, and Utopia::SquareGrid< 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::HexagonalGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::TriangularGrid< 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::TriangularGrid< Space >, Utopia::HexagonalGrid< Space >, and Utopia::SquareGrid< Space >.

◆ is_periodic()

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

Whether the space this grid maps to is periodic.

304 {
305 return _space->periodic;
306 }

◆ 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::HexagonalGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::TriangularGrid< Space >.

◆ nb_mode()

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

Const reference to the currently selected neighborhood mode.

198 {
199 return _nb_mode;
200 }

◆ nb_params()

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

The neighborhood parameters of the currently selected neighborhood.

203 {
204 return _nb_params;
205 }

◆ nb_size()

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

Maximum size of the currently selected neighborhood.

208 {
210 }
virtual DistType expected_num_neighbors(const NBMode &, const Config &) const =0

◆ 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.

178 {
179 return _nb_func(id);
180 }

◆ 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::HexagonalGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::TriangularGrid< Space >.

◆ resolution()

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

Get scalar resolution value of this grid.

274 {
275 return _resolution;
276 }

◆ select_neighborhood()

template<class Space >
void Utopia::Grid< Space >::select_neighborhood ( NBMode  nb_mode,
const Config nb_params = {} 
)
inline
183 {})
184 {
185 try {
187 }
188 catch (std::exception& e) {
189 throw std::invalid_argument("Failed to select neighborhood: "
190 + ((std::string) e.what()));
191 }
192
195 }
virtual NBFuncID< Self > get_nb_func(NBMode, const Config &)=0
Retrieve the neighborhood function depending on the mode.
const NBMode & nb_mode() const
Const reference to the currently selected neighborhood mode.
Definition base.hh:198
const Config & nb_params() const
The neighborhood parameters of the currently selected neighborhood.
Definition base.hh:203

◆ shape()

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

Get the shape of the grid discretization.

Implemented in Utopia::HexagonalGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::TriangularGrid< 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.

299 {
300 return _space;
301 }

◆ 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.

294 {
296 }
virtual GridStructure structure() const =0
Structure of the grid.
std::string grid_structure_to_string(const GridStructure &structure)
Given an GridStructure enum value, return the corresponding string key.
Definition base.hh:35

◆ 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::HexagonalGrid< Space >, Utopia::SquareGrid< Space >, and Utopia::TriangularGrid< 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.

323 {
325 idcs.reserve(0);
326 return idcs;
327 };

◆ _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: