ObserveTimeSeriesOnSurface.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <cstddef>
8 #include <string>
9 #include <utility>
10 #include <vector>
11 
12 #include "IO/Observer/Helpers.hpp"
13 #include "IO/Observer/ObservationId.hpp"
15 #include "Parallel/Invoke.hpp"
16 #include "Parallel/Reduction.hpp"
17 #include "Utilities/Functional.hpp"
18 #include "Utilities/Gsl.hpp"
19 #include "Utilities/PrettyType.hpp"
20 #include "Utilities/TMPL.hpp"
21 
22 /// \cond
23 namespace db {
24 template <typename TagsList>
25 class DataBox;
26 } // namespace db
27 namespace observers {
28 namespace ThreadedActions {
29 struct WriteReductionData;
30 } // namespace ThreadedActions
31 template <class Metavariables>
32 struct ObserverWriter;
33 } // namespace observers
34 /// \endcond
35 
36 namespace intrp {
37 namespace callbacks {
38 
39 namespace detail {
40 
41 template <typename T>
42 struct reduction_data_type;
43 
44 template <typename... Ts>
45 struct reduction_data_type<tmpl::list<Ts...>> {
46  // We use ReductionData because that is what is expected by the
47  // ObserverWriter. We do a "reduction" that involves only one
48  // processing element (often equivalent to a core),
49  // so AssertEqual is used here as a no-op.
50 
51  // The first argument is for Time, the others are for
52  // the list of things being observed.
53  using type = Parallel::ReductionData<
57 };
58 
59 template <typename... Ts>
60 auto make_legend(tmpl::list<Ts...> /* meta */) {
61  return std::vector<std::string>{"Time", Ts::name()...};
62 }
63 
64 template <typename DbTags, typename... Ts>
65 auto make_reduction_data(const db::DataBox<DbTags>& box, double time,
66  tmpl::list<Ts...> /* meta */) {
67  using reduction_data = typename reduction_data_type<tmpl::list<Ts...>>::type;
68  return reduction_data(time, get<Ts>(box)...);
69 }
70 
71 } // namespace detail
72 
73 /// \brief post_interpolation_callback that outputs
74 /// a time series on a surface.
75 ///
76 /// Uses:
77 /// - Metavariables
78 /// - `temporal_id`
79 /// - DataBox:
80 /// - `TagsToObserve`
81 ///
82 /// This is an InterpolationTargetTag::post_interpolation_callback;
83 /// see InterpolationTarget for a description of InterpolationTargetTag.
84 template <typename TagsToObserve, typename InterpolationTargetTag>
86  using observed_reduction_data_tags = observers::make_reduction_data_tags<
87  tmpl::list<typename detail::reduction_data_type<TagsToObserve>::type>>;
88 
89  template <typename DbTags, typename Metavariables>
90  static void apply(
91  const db::DataBox<DbTags>& box,
93  const typename Metavariables::temporal_id::type& temporal_id) noexcept {
96 
97  // We call this on proxy[0] because the 0th element of a NodeGroup is
98  // always guaranteed to be present.
99  Parallel::threaded_action<observers::ThreadedActions::WriteReductionData>(
100  proxy[0], observers::ObservationId(temporal_id.time()),
101  std::string{"/" + pretty_type::short_name<InterpolationTargetTag>()},
102  detail::make_legend(TagsToObserve{}),
103  detail::make_reduction_data(box, temporal_id.time().value(),
104  TagsToObserve{}));
105  }
106 };
107 } // namespace callbacks
108 } // namespace intrp
Definition: Actions.hpp:20
Functional that asserts that the function object C applied to the first and second arguments are equa...
Definition: Functional.hpp:66
Definition: Digraph.hpp:11
Definition: AddTemporalIdsToInterpolationTarget.hpp:17
The nodegroup parallel component that is responsible for writing data to disk.
Definition: ObserverComponent.hpp:55
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args)
Apply the function f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1595
Definition: Determinant.hpp:11
post_interpolation_callback that outputs a time series on a surface.
Definition: ObserveTimeSeriesOnSurface.hpp:85
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Namespace for DataBox related things.
Definition: DataBox.hpp:33
Contains a pretty_type library to write types in a "pretty" format.
Wraps the template metaprogramming library used (brigand)
auto get_parallel_component(ConstGlobalCache< Metavariables > &cache) noexcept -> Parallel::proxy_from_parallel_component< ConstGlobalCache_detail::get_component_if_mocked< typename Metavariables::component_list, ParallelComponentTag >> &
Access the Charm++ proxy associated with a ParallelComponent.
Definition: ConstGlobalCache.hpp:163
Defines functions and classes from the GSL.
Identifies a step in the linear solver algorithm.
Definition: IterationId.hpp:25
A type-erased identifier that combines the identifier&#39;s type and hash used to uniquely identify an ob...
Definition: ObservationId.hpp:43
Defines class template ConstGlobalCache.
The data to be reduced, and invokables to be called whenever two reduction messages are combined and ...
Definition: Reduction.hpp:64