Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | List of all members
Utopia::Space< num_dims > Struct Template Reference

The Space bundles properties about the physical space a model resides in. More...

#include <space.hh>

Public Types

using SpaceVec = SpaceVecType< dim >
 The type for vectors relating to physical space.
 

Public Member Functions

 Space (const Config &cfg)
 Construct a Space using information from a config node.
 
 Space ()
 Default constructor i.e. constructing a space with default parameters.
 
template<bool include_high_value_boundary = true>
bool contains (const SpaceVec &pos) const
 Whether this space contains the given coordinate (without mapping it)
 
SpaceVec map_into_space (const SpaceVec &pos) const
 Map a position (potentially outside space's extent) back into space.
 
SpaceVec displacement (const SpaceVec &pos_0, const SpaceVec &pos_1) const
 Compute the displacement vector between two coordinates.
 
template<class NormType = std::size_t>
auto distance (const SpaceVec &pos_0, const SpaceVec &pos_1, const NormType p=2) const
 The distance of two coordinates in space.
 

Public Attributes

const bool periodic
 Whether the space is to be assumed periodic.
 
const SpaceVec extent
 The physical (euclidean) extent of the space.
 

Static Public Attributes

static constexpr std::size_t dim = num_dims
 The dimensionality of the space.
 

Private Member Functions

bool setup_periodic (const Config &cfg) const
 Setup the member periodic from a config node.
 
SpaceVec setup_extent () const
 Construct a default space extent vector (valued 1 in each dimension)
 
SpaceVec setup_extent (const Config &cfg) const
 Construct a space extent vector from a config node.
 

Detailed Description

template<std::size_t num_dims>
struct Utopia::Space< num_dims >

The Space bundles properties about the physical space a model resides in.

It is, for example, used by the CellManager and its Grid discretization and by the AgentManager to properly map agent positions and movements within the spatial domain.

Template Parameters
num_dimsThe dimensionality of the space

Member Typedef Documentation

◆ SpaceVec

template<std::size_t num_dims>
using Utopia::Space< num_dims >::SpaceVec = SpaceVecType<dim>

The type for vectors relating to physical space.

Constructor & Destructor Documentation

◆ Space() [1/2]

template<std::size_t num_dims>
Utopia::Space< num_dims >::Space ( const Config cfg)
inline

Construct a Space using information from a config node.

Parameters
cfgThe config node to read the periodic and extent entries from.
48 :
51 {
52 static_assert(dim > 0, "Space::dim needs to be >= 1");
53 }
SpaceVec setup_extent() const
Construct a default space extent vector (valued 1 in each dimension)
Definition space.hh:169
bool setup_periodic(const Config &cfg) const
Setup the member periodic from a config node.
Definition space.hh:160
const SpaceVec extent
The physical (euclidean) extent of the space.
Definition space.hh:39
const bool periodic
Whether the space is to be assumed periodic.
Definition space.hh:36
static constexpr std::size_t dim
The dimensionality of the space.
Definition space.hh:30

◆ Space() [2/2]

template<std::size_t num_dims>
Utopia::Space< num_dims >::Space ( )
inline

Default constructor i.e. constructing a space with default parameters.

The default space is non-periodic and has default extent of 1. into each dimension.

60 :
61 periodic(false),
63 {
64 static_assert(dim > 0, "Space::dim needs to be >= 1");
65 }

Member Function Documentation

◆ contains()

template<std::size_t num_dims>
template<bool include_high_value_boundary = true>
bool Utopia::Space< num_dims >::contains ( const SpaceVec pos) const
inline

Whether this space contains the given coordinate (without mapping it)

Checks whether the given coordinate is within this space's extent by computing the relative position and checking whether it is within [0, 1] or [0, 1) for all elements.

Note
No distinction is made between periodic and non-periodic space.
Template Parameters
include_high_value_boundaryWhether to check the closed or the half-open interval. The latter case is useful when working with periodic grids, allowing to map values on the high-value boundary back to the low-value boundary.
82 {
83 // Calculate the relative position within the space
84 const auto rel_pos = pos / extent; // element-wise division
85
86 // Check that all relative positions are in the respective interval
87 if constexpr (include_high_value_boundary) {
88 return arma::all(rel_pos >= 0. and rel_pos <= 1.); // [0, 1]
89 }
90 else {
91 return arma::all(rel_pos >= 0. and rel_pos < 1.); // [0, 1)
92 }
93 }
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

◆ displacement()

template<std::size_t num_dims>
SpaceVec Utopia::Space< num_dims >::displacement ( const SpaceVec pos_0,
const SpaceVec pos_1 
) const
inline

Compute the displacement vector between two coordinates.

Calculates vector pointing from pos_0 to pos_1. In periodic space, it calculates the shorter displacement.

Warning
The displacement of two coordinates in periodic boundary can be maximum of half the domain size, i.e. moving away from a coordinate in a certain direction will decrease the displacement once reached half the domain size.
124 {
126
127 if (not periodic) {
128 return dx;
129 }
130 // else: Need to get shortest distance
131
132 return dx - arma::round(dx / extent) % extent;
133 }
SpaceVecType< dim > SpaceVec
The type for vectors relating to physical space.
Definition space.hh:33

◆ distance()

template<std::size_t num_dims>
template<class NormType = std::size_t>
auto Utopia::Space< num_dims >::distance ( const SpaceVec pos_0,
const SpaceVec pos_1,
const NormType  p = 2 
) const
inline

The distance of two coordinates in space.

Calculates the distance of two coordinates using the norm implemented within Armadillo. In periodic boundary it calculates the shorter distance.

Warning
The distance of two coordinates in periodic boundary can be maximum of half the domain size wrt every dimension, i.e. moving away from a coordinate in a certain direction will decrease the distance once reached half the domain size.
Parameters
pThe norm used to compute the distance, see arma::norm. Can be either an integer >= 1 or one of: "-inf", "inf", "fro"
152 {
153 return arma::norm(displacement(pos_0, pos_1), p);
154 }
SpaceVec displacement(const SpaceVec &pos_0, const SpaceVec &pos_1) const
Compute the displacement vector between two coordinates.
Definition space.hh:124

◆ map_into_space()

template<std::size_t num_dims>
SpaceVec Utopia::Space< num_dims >::map_into_space ( const SpaceVec pos) const
inline

Map a position (potentially outside space's extent) back into space.

This is intended for use with periodic space. It will also work with non-periodic space, but the input value should not have been permitted in the first place.

Note
The high-value boundary is is mapped back to the low-value boundary, such that all points are well-defined.
103 {
104 // If it is already within space, nothing to map
105 // Check whether it is contained (_excluding_ high value boundary)
106 if (contains<false>(pos)) {
107 return pos;
108 }
109 // else: Need to transform back into space
110
111 return pos - arma::floor(pos / extent) % extent;
112 }

◆ setup_extent() [1/2]

template<std::size_t num_dims>
SpaceVec Utopia::Space< num_dims >::setup_extent ( ) const
inlineprivate

Construct a default space extent vector (valued 1 in each dimension)

169 {
171 ext.fill(1.);
172 return ext;
173 }

◆ setup_extent() [2/2]

template<std::size_t num_dims>
SpaceVec Utopia::Space< num_dims >::setup_extent ( const Config cfg) const
inlineprivate

Construct a space extent vector from a config node.

Parameters
cfgThe config node to read the extent parameter from. If that entry is missing, the default extent (1) is used. If the entry is a scalar, space will be set up to have equal extent in all dimensions. Otherwise, it is expected to be a sequence node.
182 {
183 if (cfg["extent"]) {
185
186 if (cfg["extent"].IsScalar()) {
187 ext.fill(get_as<double>("extent", cfg));
188 }
189 else {
190 if (dim != cfg["extent"].size()) {
191 throw std::invalid_argument(fmt::format(
192 "Invalid size of `space.extent` sequence ({}) for "
193 "selected space dimensionality ({})!",
194 cfg["extent"].size(), dim
195 ));
196 }
197 ext = get_as_SpaceVec<dim>("extent", cfg);
198 }
199
200 if (ext.min() <= 0.) {
201 ext.print("Invalid `space.extent`:");
202 throw std::invalid_argument(
203 "The space extent needs to be strictly positive in "
204 "all entries, but it contained at least one element <= 0! "
205 "Check the `space.extent` config node to address this."
206 );
207 }
208
209 return ext;
210 }
211 else {
212 // Return the default extent, needs no check
213 return setup_extent();
214 }
215 }

◆ setup_periodic()

template<std::size_t num_dims>
bool Utopia::Space< num_dims >::setup_periodic ( const Config cfg) const
inlineprivate

Setup the member periodic from a config node.

160 {
161 if (not cfg["periodic"]) {
162 throw std::invalid_argument("Missing config entry `periodic` to "
163 "set up a Space object!");
164 }
165 return get_as<bool>("periodic", cfg);
166 }

Member Data Documentation

◆ dim

template<std::size_t num_dims>
constexpr std::size_t Utopia::Space< num_dims >::dim = num_dims
staticconstexpr

The dimensionality of the space.

◆ extent

template<std::size_t num_dims>
const SpaceVec Utopia::Space< num_dims >::extent

The physical (euclidean) extent of the space.

◆ periodic

template<std::size_t num_dims>
const bool Utopia::Space< num_dims >::periodic

Whether the space is to be assumed periodic.


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