1 #ifndef UTOPIA_CORE_SPACE_HH
2 #define UTOPIA_CORE_SPACE_HH
7 #include <spdlog/spdlog.h>
9 #include "../data_io/cfg_utils.hh"
26 template<std::
size_t num_dims>
30 static constexpr std::size_t
dim = num_dims;
52 static_assert(
dim > 0,
"Space::dim needs to be >= 1");
64 static_assert(
dim > 0,
"Space::dim needs to be >= 1");
81 template<
bool include_high_value_boundary=true>
84 const auto rel_pos = pos /
extent;
87 if constexpr (include_high_value_boundary) {
88 return arma::all(rel_pos >= 0. and rel_pos <= 1.);
91 return arma::all(rel_pos >= 0. and rel_pos < 1.);
106 if (contains<false>(pos)) {
149 template<
class NormType=std::
size_t>
151 const NormType p=2)
const
161 if (not cfg[
"periodic"]) {
162 throw std::invalid_argument(
"Missing config entry `periodic` to "
163 "set up a Space object!");
165 return get_as<bool>(
"periodic", cfg);
186 if (cfg[
"extent"].IsScalar()) {
187 ext.fill(get_as<double>(
"extent", cfg));
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
197 ext = get_as_SpaceVec<dim>(
"extent", cfg);
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."
DataIO::Config Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:80
arma::Col< double >::fixed< dim > SpaceVecType
Type for vector-like data that is associated with a physical space.
Definition: types.hh:61
The Space bundles properties about the physical space a model resides in.
Definition: space.hh:27
SpaceVec map_into_space(const SpaceVec &pos) const
Map a position (potentially outside space's extent) back into space.
Definition: space.hh:103
SpaceVecType< dim > SpaceVec
The type for vectors relating to physical space.
Definition: space.hh:33
Space()
Default constructor i.e. constructing a space with default parameters.
Definition: space.hh:59
SpaceVec setup_extent(const Config &cfg) const
Construct a space extent vector from a config node.
Definition: space.hh:182
auto distance(const SpaceVec &pos_0, const SpaceVec &pos_1, const NormType p=2) const
The distance of two coordinates in space.
Definition: space.hh:150
SpaceVec displacement(const SpaceVec &pos_0, const SpaceVec &pos_1) const
Compute the displacement vector between two coordinates.
Definition: space.hh:124
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
bool contains(const SpaceVec &pos) const
Whether this space contains the given coordinate (without mapping it)
Definition: space.hh:82
const SpaceVec extent
The physical (euclidean) extent of the space.
Definition: space.hh:39
Space(const Config &cfg)
Construct a Space using information from a config node.
Definition: space.hh:47
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