Utopia 2
Framework for studying models of complex & adaptive systems.
|
Manages a physical space, its grid discretization, and cells on that grid. More...
#include <cell_manager.hh>
Public Types | |
using | Self = CellManager< CellTraits, Model > |
The type of this CellManager. | |
using | Cell = Utopia::Cell< CellTraits > |
Type of the managed cells. | |
using | Entity = Cell |
Alias for entity type; part of the shared interface of entity managers. | |
using | CellState = typename CellTraits::State |
Type of the cell state. | |
using | Space = typename Model::Space |
The space type this cell manager maps to. | |
using | GridType = Grid< Space > |
Grid type; this refers to the base type of the stored (derived) object. | |
using | SpaceVec = SpaceVecType< dim > |
Type of vectors that represent a physical quantity. | |
using | MultiIndex = typename GridType::MultiIndex |
Type of multi-index like arrays. | |
using | RNG = typename Model::RNG |
Random number generator type. | |
using | Config = typename Model::Config |
Configuration node type. | |
using | NBFuncCell = std::function< CellContainer< Cell >(const Cell &)> |
Neighborhood function used in public interface (with cell as argument) | |
using | RuleFunc = typename std::function< CellState(const std::shared_ptr< Cell > &)> |
The type of a rule function acting on cells of this cell manager. | |
using | VoidRuleFunc = typename std::function< void(const std::shared_ptr< Cell > &)> |
The type of a void rule function acting on cells of this cell manager. | |
Public Member Functions | |
CellManager (const Model &model, const Config &custom_cfg={}) | |
Construct a cell manager. | |
CellManager (const Model &model, const CellState initial_state, const Config &custom_cfg={}) | |
Construct a cell manager explicitly passing an initial cell state. | |
const auto & | log () const |
const Config & | cfg () const |
Return the configuration used for building this cell manager. | |
const std::shared_ptr< RNG > & | rng () const |
Return a reference to the shared random number generator. | |
const std::shared_ptr< Space > & | space () const |
Return pointer to the space, for convenience. | |
const std::shared_ptr< GridType > & | grid () const |
Return const reference to the grid. | |
const CellContainer< Cell > & | cells () const |
Return const reference to the managed CA cells. | |
const CellContainer< Cell > & | entities () const |
Return const reference to the entities managed by this manager: cells. | |
MultiIndex | midx_of (const Cell &cell) const |
Returns the multi-index of the given cell. | |
MultiIndex | midx_of (const std::shared_ptr< Cell > &cell) const |
Returns the multi-index of the given cell. | |
SpaceVec | barycenter_of (const Cell &cell) const |
Returns the barycenter of the given cell. | |
SpaceVec | barycenter_of (const std::shared_ptr< Cell > &cell) const |
Returns the barycenter of the given cell. | |
SpaceVec | extent_of (const Cell &cell) const |
Returns the physical extent of the given cell. | |
SpaceVec | extent_of (const std::shared_ptr< Cell > &cell) const |
Returns the physical extent of the given cell. | |
std::vector< SpaceVec > | vertices_of (const Cell &cell) const |
Returns a container of vertices of the given cell. | |
std::vector< SpaceVec > | vertices_of (const std::shared_ptr< Cell > &cell) const |
Returns a container of vertices of the given cell. | |
const std::shared_ptr< Cell > & | cell_at (const SpaceVec &pos) const |
Return the cell covering the given point in physical space. | |
CellContainer< Cell > | boundary_cells (const std::string &select="all") const |
Retrieve a container of cells that are at a specified boundary. | |
template<SelectionMode mode, class... Args> | |
CellContainer< Cell > | select_cells (Args &&... args) const |
Select cells using the Utopia::select_entities interface. | |
CellContainer< Cell > | select_cells (const Config &sel_cfg) const |
Select entities according to parameters specified in a configuration. | |
template<class ElementT = double, class SetterFunc > | |
void | set_cell_states (const std::string &hdf5_file, const std::string &dset_path, const SetterFunc &setter_func) |
Set all cell states using information from a HDF5 file. | |
const NBMode & | nb_mode () const |
Return the currently selected neighborhood mode. | |
auto | nb_size () const |
Return the (maximum) size of the currently selected neighborhood. | |
CellContainer< Cell > | neighbors_of (const Cell &cell) const |
Retrieve the given cell's neighbors. | |
CellContainer< Cell > | neighbors_of (const std::shared_ptr< Cell > &cell) const |
Retrieve the given cell's neighbors. | |
void | select_neighborhood (const Config &nb_cfg) |
Select the neighborhood and all parameters fully from a config node. | |
void | select_neighborhood (const std::string &nb_mode, const bool compute_and_store=true, const Config &nb_params={}) |
Select the neighborhood mode using a string for the mode argument. | |
void | select_neighborhood (const NBMode &nb_mode, const bool compute_and_store=true, const Config &nb_params={}) |
Set the neighborhood mode. | |
void | compute_cell_neighbors () |
Compute (and store) all cells' neighbors. | |
template<class IndexContainer > | |
CellContainer< Cell > | entity_pointers_from_ids (IndexContainer &&ids) const |
Given a container IDs, convert it to container of entity pointers. | |
Public Attributes | |
bool | _empty_nb_warning_emitted = false |
Whether a warning about an empty neighbourhood was already emitted. | |
Static Public Attributes | |
static constexpr DimType | dim = Model::Space::dim |
Dimensionality of the space this cell manager is to discretize. | |
Private Member Functions | |
Config | setup_cfg (const Model &model, const Config &custom_cfg) const |
Set up the cell manager configuration member. | |
std::shared_ptr< GridType > | setup_grid () const |
Set up the grid discretization. | |
CellContainer< Cell > | setup_cells (const CellState &initial_state) const |
Set up the cells container using an explicitly passed initial state. | |
CellContainer< Cell > | setup_cells () const |
Set up cells container via config or default constructor. | |
void | setup_nb_funcs () |
Setup the neighborhood functions using config entries. | |
Private Attributes | |
const std::shared_ptr< spdlog::logger > | _log |
The logger (same as the model this manager resides in) | |
const Config | _cfg |
Cell manager configuration node. | |
const std::shared_ptr< RNG > | _rng |
The model's random number generator, used e.g. for cell construction. | |
const std::shared_ptr< Space > | _space |
The physical space the cells are to reside in. | |
const std::shared_ptr< GridType > | _grid |
The grid that discretely maps cells into space. | |
CellContainer< Cell > | _cells |
Storage container for cells. | |
std::vector< CellContainer< Cell > > | _cell_neighbors |
Storage container for pre-calculated (!) cell neighbors. | |
NBFuncCell | _nb_func |
The currently chosen neighborhood function (working directly on cells) | |
NBFuncCell | _nb_from_cache |
Return the pre-computed neighbors of the given cell. | |
NBFuncCell | _nb_compute_each_time |
Compute the neighbors for the given cell using the grid. | |
NBFuncCell | _nb_compute_each_time_empty |
Compute the neighbors for the given cell using the grid. | |
Manages a physical space, its grid discretization, and cells on that grid.
This class implements a common interface for working with cells as a representation of volumes of physical space. A typical use case is the cellular automaton.
To that end, a discretization of space is needed: the grid. This spatial discretization is handled by concrete classes derived from Utopia::Grid. The CellManager communicates with these objects solely via cell indices (which are the indices within the container of cells), making the grid implementation independent of the type of cells used.
CellTraits | Type traits of the cells used |
Model | Type of the model using this manager |
using Utopia::CellManager< CellTraits, Model >::Cell = Utopia::Cell<CellTraits> |
Type of the managed cells.
using Utopia::CellManager< CellTraits, Model >::CellState = typename CellTraits::State |
Type of the cell state.
using Utopia::CellManager< CellTraits, Model >::Config = typename Model::Config |
Configuration node type.
using Utopia::CellManager< CellTraits, Model >::Entity = Cell |
Alias for entity type; part of the shared interface of entity managers.
using Utopia::CellManager< CellTraits, Model >::GridType = Grid<Space> |
Grid type; this refers to the base type of the stored (derived) object.
using Utopia::CellManager< CellTraits, Model >::MultiIndex = typename GridType::MultiIndex |
Type of multi-index like arrays.
using Utopia::CellManager< CellTraits, Model >::NBFuncCell = std::function<CellContainer<Cell>(const Cell&)> |
Neighborhood function used in public interface (with cell as argument)
using Utopia::CellManager< CellTraits, Model >::RNG = typename Model::RNG |
Random number generator type.
using Utopia::CellManager< CellTraits, Model >::RuleFunc = typename std::function<CellState(const std::shared_ptr<Cell>&)> |
The type of a rule function acting on cells of this cell manager.
This is a convenience type def that models can use to easily have this type available.
using Utopia::CellManager< CellTraits, Model >::Self = CellManager<CellTraits, Model> |
The type of this CellManager.
using Utopia::CellManager< CellTraits, Model >::Space = typename Model::Space |
The space type this cell manager maps to.
using Utopia::CellManager< CellTraits, Model >::SpaceVec = SpaceVecType<dim> |
Type of vectors that represent a physical quantity.
using Utopia::CellManager< CellTraits, Model >::VoidRuleFunc = typename std::function<void(const std::shared_ptr<Cell>&)> |
The type of a void rule function acting on cells of this cell manager.
This is a convenience type def that models can use to easily have this type available. Void rule functions are only possible for asynchronous updates.
|
inline |
Construct a cell manager.
With the model available, the CellManager can extract the required information from the model without the need to pass it explicitly. Furthermore, this constructor differs to the one with the initial_state
parameter such that the way the initial state of the cells is determined can be controlled via the configuration.
model | The model this CellManager belongs to |
custom_cfg | A custom config node to use to use for grid and cell setup. If not given, the model's configuration is used to extract the required entries. |
|
inline |
Construct a cell manager explicitly passing an initial cell state.
model | The model this CellManager belongs to |
initial_state | The initial state of the cells |
custom_cfg | A custom config node to use to use for grid and cell setup. If not given, the model's configuration is used to extract the required entries. |
|
inline |
|
inline |
|
inline |
Retrieve a container of cells that are at a specified boundary.
Lets the grid compute the set of cell IDs at the boundary and then converts them into pointers to cells. As the set is sorted by cell IDs, the returned container is also sorted.
parblock Select which boundary to return the cell IDs of. If 'all', all boundary cells are returned. Other available values depend on the dimensionality of the grid:
|
inline |
Return 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.
|
inline |
Return const reference to the managed CA cells.
|
inline |
Return the configuration used for building this cell manager.
|
inline |
Compute (and store) all cells' neighbors.
After this function was called, the cell neighbors will be returned from the storage container rather than re-calculated for every access.
|
inline |
Return const reference to the entities managed by this manager: cells.
|
inline |
Given a container IDs, convert it to container of entity pointers.
|
inline |
|
inline |
|
inline |
Return const reference to the grid.
|
inline |
– Getters ---------------------------------------------------------— Return the CellManager logger
|
inline |
|
inline |
|
inline |
Return the currently selected neighborhood mode.
|
inline |
Return the (maximum) size of the currently selected neighborhood.
|
inline |
|
inline |
|
inline |
Return a reference to the shared random number generator.
|
inline |
Select cells using the Utopia::select_entities interface.
Returns a container of cells that were selected according to a certain selection mode. This is done via the Utopia::select_entities interface.
mode | The selection mode |
\args args Forwarded to Utopia::select_entities
|
inline |
Select entities according to parameters specified in a configuration.
Via the mode
key, one of the selection modes can be chosen; for available oens, see Utopia::SelectionMode.
Depending on that mode, the other parameters are extracted from the configuration. See Utopia::select_entities for more info.
sel_cfg | The configuration node containing the expected key-value pairs specifying the selection. |
|
inline |
Select the neighborhood and all parameters fully from a config node.
If this method is used to set up the neighborhood, the following keys will be read and parsed:
- ``mode`` (required): the neighborhood mode - ``compute_and_store`` (optional, default: ``true``): whether to directly compute all neighbors and henceforth use the buffer to get these neighbors.
Subsequently, these values are passed to the appropriate overload of the select_neighborhood function.
nb_cfg | The neighborhood configuration node. Apart from the keys that are parsed here, the full config node is passed along further. |
|
inline |
Set the neighborhood mode.
nb_mode | The name of the neighborhood to select |
compute_and_store | Whether to directly compute all neighbors and henceforth use the buffer to get these neighbors. Default: true . |
nb_params | Passed on to the Grid::select_neighborhood method, carrying additional parameters. |
|
inline |
Select the neighborhood mode using a string for the mode argument.
Resolves a string-type nb_mode
to NBmode, then invokes the appropriate overload.
nb_mode | The name of the neighborhood to select |
compute_and_store | Whether to directly compute all neighbors and henceforth use the buffer to get these neighbors. Default: true . |
nb_params | Passed on to the Grid::select_neighborhood method, carrying additional parameters. |
|
inline |
Set all cell states using information from a HDF5 file.
Using armadillo functionality, this loads the data from the given HDF5 file into an array of ElementT
. It then iterates over all cells, looks up the multi index, and passes it to the setter_func
, which has the responsibility of setting the cell state accordingly.
The setter_func
should accept as first argument a reference to the cell (more accurately: const std::shared_ptr<Cell>&
) and as second argument the value from the loaded dataset.
ElemenT | The type that armadillo should load the data as. Need be supported by armadillo. |
SetterFunc | Type of the setter function, e.g. std::function<…> |
hdf5_file | The hdf5 file to load the data from. Can be an absolute path or relative to the working directory. |
dset_path | The path within the HDF5 file that points to the dataset to load data from. |
setter_func | The void(cell, value) function that sets the cell state given the value from the loaded dataset corresponding to the cells' multi-index. |
|
inlineprivate |
Set up cells container via config or default constructor.
If no explicit initial state is given, this setup function is called. There are three modes: If the CellTraits are set such that the default constructor of the cell state is to be used, that constructor is required and is called for each cell.
Otherwise, the CellState needs to be constructible via a const Config&
argument, which gets passed the config entry cell_params
from the CellManager's configuration. If a constructor with the signature (const Config&, const std::shared_ptr<RNG>&)
is supported, that constructor is called instead.
|
inlineprivate |
Set up the cells container using an explicitly passed initial state.
|
inlineprivate |
Set up the cell manager configuration member.
This function determines whether to use a custom configuration or the one provided by the model this CellManager belongs to
|
inlineprivate |
Set up the grid discretization.
|
inlineprivate |
Setup the neighborhood functions using config entries.
|
inline |
Return pointer to the space, for convenience.
|
inline |
Returns a container of vertices of the given cell.
The vertices are the absolute coordinates that define the cell. For example, a 2D square cell is the surface of a polygon defined by four points.
|
inline |
|
private |
Storage container for pre-calculated (!) cell neighbors.
|
private |
Storage container for cells.
|
private |
Cell manager configuration node.
bool Utopia::CellManager< CellTraits, Model >::_empty_nb_warning_emitted = false |
Whether a warning about an empty neighbourhood was already emitted.
This is to prevent a gigantic amount of warnings being logged
|
private |
The grid that discretely maps cells into space.
|
private |
The logger (same as the model this manager resides in)
|
private |
Compute the neighbors for the given cell using the grid.
|
private |
Compute the neighbors for the given cell using the grid.
|
private |
Return the pre-computed neighbors of the given cell.
|
private |
The currently chosen neighborhood function (working directly on cells)
|
private |
The model's random number generator, used e.g. for cell construction.
|
private |
The physical space the cells are to reside in.
|
staticconstexpr |
Dimensionality of the space this cell manager is to discretize.