ByBlock.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <pup.h>
8 #include <pup_stl.h> // IWYU pragma: keep
9 #include <utility>
10 #include <vector>
11 
12 #include "ErrorHandling/Error.hpp"
13 #include "Options/Options.hpp"
15 #include "Time/StepChoosers/StepChooser.hpp" // IWYU pragma: keep
16 #include "Utilities/TMPL.hpp"
17 
18 /// \cond
19 template <size_t VolumeDim>
20 class Element;
21 namespace Parallel {
22 template <typename Metavariables>
23 class ConstGlobalCache;
24 } // namespace Parallel
25 namespace Tags {
26 template <size_t VolumeDim>
27 struct Element;
28 } // namespace Tags
29 /// \endcond
30 
31 namespace StepChoosers {
32 template <size_t Dim, typename StepChooserRegistrars>
33 class ByBlock;
34 
35 namespace Registrars {
36 template <size_t Dim>
37 struct ByBlock {
38  template <typename StepChooserRegistrars>
40 };
41 } // namespace Registrars
42 
43 /// Suggests specified step sizes in each block
44 template <size_t Dim,
45  typename StepChooserRegistrars = tmpl::list<Registrars::ByBlock<Dim>>>
46 class ByBlock : public StepChooser<StepChooserRegistrars> {
47  public:
48  /// \cond
49  ByBlock() = default;
50  explicit ByBlock(CkMigrateMessage* /*unused*/) noexcept {}
51  using PUP::able::register_constructor;
53  /// \endcond
54 
55  struct Sizes {
56  using type = std::vector<double>;
57  static constexpr OptionString help{"Step sizes, indexed by block number"};
58  };
59 
60  static constexpr OptionString help{
61  "Suggests specified step sizes in each block"};
62  using options = tmpl::list<Sizes>;
63 
64  explicit ByBlock(std::vector<double> sizes) noexcept
65  : sizes_(std::move(sizes)) {}
66 
67  using argument_tags = tmpl::list<Tags::Element<Dim>>;
68 
69  template <typename Metavariables>
70  double operator()(const Element<Dim>& element,
72  const noexcept {
73  const size_t block = element.id().block_id();
74  if (block >= sizes_.size()) {
75  ERROR("Step size not specified for block " << block);
76  }
77  return sizes_[block];
78  }
79 
80  // NOLINTNEXTLINE(google-runtime-references)
81  void pup(PUP::er& p) noexcept override { p | sizes_; }
82 
83  private:
84  std::vector<double> sizes_;
85 };
86 
87 /// \cond
88 template <size_t Dim, typename StepChooserRegistrars>
89 PUP::able::PUP_ID ByBlock<Dim, StepChooserRegistrars>::my_PUP_ID = 0; // NOLINT
90 /// \endcond
91 } // namespace StepChoosers
const ElementId< VolumeDim > & id() const noexcept
A unique ID for the Element.
Definition: Element.hpp:57
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:35
Definition: ByBlock.hpp:55
Defines classes and functions for making classes creatable from input files.
Defines macros to allow serialization of abstract template base classes.
Contains functions that forward to Charm++ parallel functions.
Definition: Abort.hpp:13
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
StepChoosers suggest upper bounds on step sizes. Concrete StepChoosers should define operator() retur...
Definition: StepChooser.hpp:45
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:29
A spectral element with knowledge of its neighbors.
Definition: Element.hpp:29
Definition: DataBoxTag.hpp:29
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Wraps the template metaprogramming library used (brigand)
Definition: ByBlock.hpp:37
Defines macro ERROR.
Holds all the StepChoosers.
Definition: ByBlock.hpp:31
Suggests specified step sizes in each block.
Definition: ByBlock.hpp:33