Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <cstdint>
7 : #include <iosfwd>
8 : #include <optional>
9 : #include <string>
10 : #include <unordered_map>
11 : #include <unordered_set>
12 : #include <vector>
13 :
14 : /// \cond
15 : namespace Options {
16 : class Option;
17 : template <typename T>
18 : struct create_from_yaml;
19 : } // namespace Options
20 : /// \endcond
21 :
22 : namespace Events {
23 : /*!
24 : * \brief How reduction events like `Events::ObserveNorms` group elements into
25 : * reductions
26 : *
27 : * - `WholeDomain`: a single reduction over all observed elements.
28 : * - `ByBlock`: a separate reduction for each observed block.
29 : * - `ByBlockOrGroup`: a separate reduction for each entry of the
30 : * `BlocksToObserve` option, where a block group is reduced as a whole.
31 : *
32 : * See `Events::reduction_subfile_suffix` for how the reductions are named.
33 : */
34 0 : enum class ReductionScope : int8_t { WholeDomain, ByBlock, ByBlockOrGroup };
35 :
36 0 : std::ostream& operator<<(std::ostream& os, ReductionScope reduction_scope);
37 :
38 : /*!
39 : * \brief The suffix to append to the subfile path for an element in the block
40 : * \p block_name, or `std::nullopt` if the block is not observed.
41 : *
42 : * - `WholeDomain`: the suffix is empty, so all observed elements contribute to
43 : * the same subfile.
44 : * - `ByBlock`: the suffix is `/<BlockName>`. Block groups listed in
45 : * \p blocks_to_observe are expanded to their blocks.
46 : * - `ByBlockOrGroup`: the suffix is `/<BlockOrGroupName>`, the entry of
47 : * \p blocks_to_observe that contains the block. Since each element
48 : * contributes to only one reduction, it is an error if the block is
49 : * contained in more than one entry. When \p blocks_to_observe is
50 : * `std::nullopt` (i.e. all blocks) this is the same as `ByBlock`.
51 : *
52 : * \param reduction_scope How to group elements into reductions
53 : * \param blocks_to_observe The block or group names to observe, or
54 : * `std::nullopt` to observe all blocks
55 : * \param block_name The name of the block the element is in
56 : * \param all_block_names All block names in the domain
57 : * \param block_groups All block groups in the domain
58 : */
59 1 : std::optional<std::string> reduction_subfile_suffix(
60 : ReductionScope reduction_scope,
61 : const std::optional<std::vector<std::string>>& blocks_to_observe,
62 : const std::string& block_name,
63 : const std::vector<std::string>& all_block_names,
64 : const std::unordered_map<std::string, std::unordered_set<std::string>>&
65 : block_groups);
66 : } // namespace Events
67 :
68 : template <>
69 0 : struct Options::create_from_yaml<Events::ReductionScope> {
70 : template <typename Metavariables>
71 0 : static Events::ReductionScope create(const Options::Option& options) {
72 : return create<void>(options);
73 : }
74 : };
75 :
76 : template <>
77 0 : Events::ReductionScope
78 : Options::create_from_yaml<Events::ReductionScope>::create<void>(
79 : const Options::Option& options);
|