Interpolate.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 
10 #include "Domain/ElementId.hpp"
11 #include "Options/Options.hpp"
14 #include "Parallel/Invoke.hpp"
15 #include "ParallelAlgorithms/EventsAndTriggers/Event.hpp"
16 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
17 #include "Utilities/TMPL.hpp"
18 
19 /// \cond
20 class TimeStepId;
21 namespace Tags {
22 struct TimeStepId;
23 template <size_t VolumeDim>
24 struct Mesh;
25 template <typename TagsList>
26 struct Variables;
27 } // namespace Tags
28 template <size_t Dim> class Mesh;
29 template <size_t VolumeDim> class ElementIndex;
30 namespace intrp {
31 template <typename Metavariables>
32 struct Interpolator;
33 namespace Actions {
34 struct InterpolatorReceiveVolumeData;
35 } // namespace Actions
36 } // namespace intrp
37 /// \endcond
38 
39 namespace intrp {
40 namespace Events {
41 template <size_t VolumeDim, typename Tensors, typename EventRegistrars>
43 
44 namespace Registrars {
45 template <size_t VolumeDim, typename Tensors>
46 struct Interpolate {
47  template <typename RegistrarList>
49 };
50 } // namespace Registrars
51 
52 /// Does an interpolation by calling Actions on Interpolator.
53 template <size_t VolumeDim, typename Tensors,
54  typename EventRegistrars =
55  tmpl::list<Registrars::Interpolate<VolumeDim, Tensors>>>
56 class Interpolate; // IWYU pragma: keep
57 
58 template <size_t VolumeDim, typename... Tensors, typename EventRegistrars>
59 class Interpolate<VolumeDim, tmpl::list<Tensors...>, EventRegistrars>
60  : public Event<EventRegistrars> {
61  /// \cond
62  explicit Interpolate(CkMigrateMessage* /*unused*/) noexcept {}
63  using PUP::able::register_constructor;
65  /// \endcond
66 
67  using options = tmpl::list<>;
68  static constexpr OptionString help =
69  "Starts interpolation by sending data to the Interpolator.";
70 
71  Interpolate() = default;
72 
73  using argument_tags =
74  tmpl::list<::Tags::TimeStepId, ::Tags::Mesh<VolumeDim>, Tensors...>;
75 
76  template <typename Metavariables, typename ParallelComponent>
77  void operator()(const TimeStepId& time_id, const Mesh<VolumeDim>& mesh,
78  const db::const_item_type<Tensors>&... tensors,
80  const ElementIndex<VolumeDim>& array_index,
81  const ParallelComponent* const /*meta*/) const noexcept {
82  Variables<tmpl::list<Tensors...>> interp_vars(mesh.number_of_grid_points());
83  const auto copy_to_variables = [&interp_vars](const auto tensor_tag_v,
84  const auto& tensor) noexcept {
85  using tensor_tag = tmpl::type_from<decltype(tensor_tag_v)>;
86  get<tensor_tag>(interp_vars) = tensor;
87  return 0;
88  };
89  expand_pack(copy_to_variables(tmpl::type_<Tensors>{}, tensors)...);
90 
91  // Send volume data to the Interpolator, to trigger interpolation.
92  auto& interpolator =
93  *::Parallel::get_parallel_component<Interpolator<Metavariables>>(cache)
94  .ckLocalBranch();
95  Parallel::simple_action<Actions::InterpolatorReceiveVolumeData>(
96  interpolator, time_id, ElementId<VolumeDim>(array_index), mesh,
97  interp_vars);
98  }
99 };
100 
101 /// \cond
102 template <size_t VolumeDim, typename... Tensors, typename EventRegistrars>
103 PUP::able::PUP_ID Interpolate<VolumeDim, tmpl::list<Tensors...>,
104  EventRegistrars>::my_PUP_ID = 0; // NOLINT
105 /// \endcond
106 
107 } // namespace Events
108 } // namespace intrp
Definition: Digraph.hpp:11
Definition: AddTemporalIdsToInterpolationTarget.hpp:17
An ElementId uniquely labels an Element. It is constructed from the BlockId of the Block to which the...
Definition: ElementId.hpp:36
Holds the number of grid points, basis, and quadrature in each direction of the computational grid...
Definition: Mesh.hpp:49
Defines classes and functions for making classes creatable from input files.
Defines macros to allow serialization of abstract template base classes.
Definition: Completion.hpp:13
Defines class ElementId.
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
size_t number_of_grid_points() const noexcept
The total number of grid points in all dimensions.
Definition: Mesh.hpp:124
A unique identifier for the temporal state of an integrated system.
Definition: TimeStepId.hpp:25
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:29
Definition: DataBoxTag.hpp:29
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:135
Does an interpolation by calling Actions on Interpolator.
Definition: Interpolate.hpp:42
Wraps the template metaprogramming library used (brigand)
Base class for something that can happen during a simulation (such as an observation).
Definition: Event.hpp:30
A class for indexing a Charm array by Element.
Definition: ElementIndex.hpp:53
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Defines class template ConstGlobalCache.
Definition: ComputeTimeDerivative.hpp:28
Definition: Interpolate.hpp:46
constexpr void expand_pack(Ts &&...) noexcept
Allows zero-cost unordered expansion of a parameter.
Definition: TMPL.hpp:546