1 #ifndef UTOPIA_CORE_GRIDS_BASE_HH
2 #define UTOPIA_CORE_GRIDS_BASE_HH
37 if (m.second == structure) {
43 throw std::invalid_argument(
44 "The given grid structure was not available in the "
45 "grid_structure_map! Are all GridStructure enum values represented "
80 if (m.second == nb_mode) {
86 throw std::invalid_argument(
"The given nb_mode was not available in the "
87 "nb_mode_map! Are all NBMode enum values represented in the map?");
149 if (not cfg[
"resolution"]) {
150 throw std::invalid_argument(
"Missing grid configuration "
151 "parameter 'resolution'! Please supply an integer >= 1.");
155 const auto res = get_as<long long>(
"resolution", cfg);
158 throw std::invalid_argument(
"Grid resolution needs to be a "
159 "positive integer, was < 1!");
188 catch (std::exception& e) {
189 throw std::invalid_argument(
"Failed to select neighborhood: "
190 + ((std::string) e.what()));
299 const std::shared_ptr<Space>&
space()
const {
The base class for all grid discretizations used by the CellManager.
Definition: base.hh:99
const DistType _resolution
How many cells to place per length unit of space.
Definition: base.hh:127
bool is_periodic() const
Whether the space this grid maps to is periodic.
Definition: base.hh:304
const NBMode & nb_mode() const
Const reference to the currently selected neighborhood mode.
Definition: base.hh:198
virtual ~Grid()=default
Virtual destructor to allow polymorphic destruction.
MultiIndexType< dim > MultiIndex
The type of multi-index like arrays, e.g. the grid shape.
Definition: base.hh:111
NBFuncID< Self > _nb_func
Neighborhood function (working on cell IDs)
Definition: base.hh:136
static constexpr DimType dim
The dimensionality of the space to be discretized (for easier access)
Definition: base.hh:105
virtual GridStructure structure() const =0
Structure of the grid.
virtual std::set< IndexType > boundary_cells(std::string={}) const =0
Retrieve a set of cell indices that are at a specified boundary.
const std::shared_ptr< Space > _space
The space that is to be discretized.
Definition: base.hh:120
Grid(std::shared_ptr< Space > space, const Config &cfg)
Construct a grid discretization.
Definition: base.hh:145
NBMode _nb_mode
Neighborhood mode.
Definition: base.hh:130
std::string structure_name() const
Structure of the grid as std::string.
Definition: base.hh:294
virtual IndexType num_cells() const =0
Get number of cells.
virtual SpaceVec extent_of(const IndexType) const =0
Returns the extent of the cell with the given ID.
const Config & nb_params() const
The neighborhood parameters of the currently selected neighborhood.
Definition: base.hh:203
NBFuncID< Self > _nb_empty
A neighborhood function for empty neighborhood.
Definition: base.hh:323
virtual SpaceVec barycenter_of(const IndexType) const =0
Returns the barycenter of the cell with the given ID.
virtual MultiIndex shape() const =0
Get the shape of the grid discretization.
virtual SpaceVec effective_resolution() const =0
Returns the effective resolution into each dimension of the grid.
IndexContainer neighbors_of(const IndexType id) const
Returns the indices of the neighbors of the cell with the given ID.
Definition: base.hh:178
virtual MultiIndex midx_of(const IndexType) const =0
Returns the multi-index 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.
const std::shared_ptr< Space > & space() const
Const reference to the space this grid maps to.
Definition: base.hh:299
auto resolution() const
Get scalar resolution value of this grid.
Definition: base.hh:274
virtual NBFuncID< Self > get_nb_func(NBMode, const Config &)=0
Retrieve the neighborhood function depending on the mode.
Config _nb_params
Neighborhood parameters.
Definition: base.hh:133
void select_neighborhood(NBMode nb_mode, const Config &nb_params={})
Definition: base.hh:182
virtual DistType expected_num_neighbors(const NBMode &, const Config &) const =0
virtual std::vector< SpaceVec > vertices_of(const IndexType) const =0
Returns the vertices of the cell with the given ID.
auto nb_size() const
Maximum size of the currently selected neighborhood.
Definition: base.hh:208
typename Space::SpaceVec SpaceVec
The type of vectors that have a relation to physical space.
Definition: base.hh:108
DataIO::Config Config
The configuration type.
Definition: base.hh:114
std::string grid_structure_to_string(const GridStructure &structure)
Given an GridStructure enum value, return the corresponding string key.
Definition: base.hh:35
NBMode
Possible neighborhood types; availability depends on choice of grid.
Definition: base.hh:52
const std::map< std::string, GridStructure > grid_structure_map
A map from strings to grid structure enum values.
Definition: base.hh:25
const std::map< std::string, NBMode > nb_mode_map
A map from strings to neighborhood enum values.
Definition: base.hh:67
std::string nb_mode_to_string(const NBMode &nb_mode)
Given an NBMode enum value, return the corresponding string key.
Definition: base.hh:78
GridStructure
Available grid implementations.
Definition: base.hh:13
std::function< IndexContainer(const IndexType)> NBFuncID
Type of the neighborhood calculating function.
Definition: base.hh:92
@ vonNeumann
The vonNeumann neighborhood, i.e. only nearest neighbors.
@ hexagonal
The hexagonal neighbourhood, i.e. the neighbourhood on a hexagonal grid.
@ Moore
The Moore neighborhood, i.e. nearest and next nearest neighbors.
@ empty
Every entity is utterly alone in the world.
@ hexagonal
A hexagonal lattice grid.
@ square
A square lattice grid.
@ triangular
A triangular lattice grid.
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:71
arma::Col< IndexType >::fixed< dim > MultiIndexType
Type for index type vectors that are associated with a physical space.
Definition: types.hh:53
std::vector< IndexType > IndexContainer
Type for container of indices.
Definition: types.hh:43
unsigned short DimType
Type for dimensions, i.e. very small unsigned integers.
Definition: types.hh:34
unsigned int DistType
Type for distancens, i.e. intermediately long unsigned integers.
Definition: types.hh:37
std::size_t IndexType
Type for indices, i.e. values used for container indexing, agent IDs, ...
Definition: types.hh:40
SpaceVecType< dim > SpaceVec
The type for vectors relating to physical space.
Definition: space.hh:33
static constexpr std::size_t dim
The dimensionality of the space.
Definition: space.hh:30