SpECTRE
v2025.03.17
|
Produce a std::vector<T> over all blocks of the domain. More...
#include <ExpandOverBlocks.hpp>
Public Member Functions | |
ExpandOverBlocks (size_t num_blocks) | |
ExpandOverBlocks (std::vector< std::string > block_names, std::unordered_map< std::string, std::unordered_set< std::string > > block_groups={}) | |
std::vector< T > | operator() (const T &value) const |
Repeat over all blocks (homogeneous) | |
std::vector< T > | operator() (const std::vector< T > &value) const |
Only check if the size matches the number of blocks, throwing a std::length_error if it doesn't. | |
std::vector< T > | operator() (const std::unordered_map< std::string, T > &value) const |
Map block names, or names of block groups, to values. The map must cover all blocks once the groups are expanded. To use this option you must pass the list of block names and groups to the constructor. Here's an example: More... | |
template<typename U , Requires< ExpandOverBlocks_detail::is_value_type< T, U >::value > = nullptr> | |
std::vector< T > | operator() (const U &value) const |
Repeat over all blocks and dimensions (isotropic and homogeneous) | |
Produce a std::vector<T> over all blocks of the domain.
This class is useful to option-create values for e.g. the initial refinement level or initial number of grid points for domain creators. It can be used with std::visit
and a std::variant
with (a subset of) these types:
T
: Repeat the given value over all blocks (homogeneous).std::vector<T>
: Only check if the size matches the number of blocks, throwing a std::length_error
if it doesn't.std::unordered_map<std::string, T>
: Map block names, or names of block groups, to values. The map must cover all blocks once the groups are expanded. To use this option you must pass the list of block names and groups to the constructor.T::value_type
: Repeat the given value over all blocks and dimensions (isotropic and homogeneous). Only works if T
is a std::array
. For example, if T
is std::array<size_t, 3>
, this will produce a std::vector<std::array<size_t, 3>>
with the same value repeated num_blocks x 3
times.If T
is a std::unique_ptr
, the class will clone the value for each block using T::get_clone()
.
Note that the call-operators throw
when they encounter errors, such as mismatches in the number of blocks. The exceptions can be used to output user-facing error messages in an option-parsing context.
Here's an example for using this class:
Here's an example using block names and groups:
T | The type distributed over the domain |
std::vector< T > domain::ExpandOverBlocks< T >::operator() | ( | const std::unordered_map< std::string, T > & | value | ) | const |
Map block names, or names of block groups, to values. The map must cover all blocks once the groups are expanded. To use this option you must pass the list of block names and groups to the constructor. Here's an example: