InterpolationTargetLineSegment.hpp
2 // See LICENSE.txt for details.
3
4 #pragma once
5
6 #include <array>
7 #include <cstddef>
8
10 #include "NumericalAlgorithms/Interpolation/SendPointsToInterpolator.hpp"
11 #include "Options/Options.hpp"
13 #include "Utilities/Gsl.hpp"
14 #include "Utilities/Requires.hpp"
15 #include "Utilities/TMPL.hpp"
17
18 /// \cond
19 class DataVector;
20 namespace PUP {
21 class er;
22 } // namespace PUP
23 namespace db {
24 template <typename TagsList>
25 class DataBox;
26 } // namespace db
27 namespace intrp {
28 namespace Tags {
29 template <typename Metavariables>
30 struct TemporalIds;
31 } // namespace Tags
32 } // namespace intrp
33 /// \endcond
34
35 namespace intrp {
36
37 namespace OptionHolders {
38 /// A line segment extending from Begin to End,
39 /// containing NumberOfPoints uniformly-spaced points including the endpoints.
40 ///
41 /// \note Input coordinates are interpreted in the frame given by
42 /// Metavariables::domain_frame
43 template <size_t VolumeDim>
44 struct LineSegment {
45  struct Begin {
47  static constexpr OptionString help = {"Beginning endpoint"};
48  };
49  struct End {
51  static constexpr OptionString help = {"Ending endpoint"};
52  };
53  struct NumberOfPoints {
54  using type = size_t;
55  static constexpr OptionString help = {
56  "Number of points including endpoints"};
57  static type lower_bound() noexcept { return 2; }
58  };
59  using options = tmpl::list<Begin, End, NumberOfPoints>;
60  static constexpr OptionString help = {
61  "A line segment extending from Begin to End, containing NumberOfPoints"
62  " uniformly-spaced points including the endpoints."};
63
66  size_t number_of_points_in) noexcept;
67
68  LineSegment() = default;
69  LineSegment(const LineSegment& /*rhs*/) = delete;
70  LineSegment& operator=(const LineSegment& /*rhs*/) = delete;
71  LineSegment(LineSegment&& /*rhs*/) noexcept = default;
72  LineSegment& operator=(LineSegment&& /*rhs*/) noexcept = default;
73  ~LineSegment() = default;
74
75  // clang-tidy non-const reference pointer.
76  void pup(PUP::er& p) noexcept; // NOLINT
77
80  size_t number_of_points{};
81 };
82
83 template <size_t VolumeDim>
84 bool operator==(const LineSegment<VolumeDim>& lhs,
85  const LineSegment<VolumeDim>& rhs) noexcept;
86 template <size_t VolumeDim>
87 bool operator!=(const LineSegment<VolumeDim>& lhs,
88  const LineSegment<VolumeDim>& rhs) noexcept;
89
90 } // namespace OptionHolders
91
92 namespace Actions {
93 /// \ingroup ActionsGroup
94 /// \brief Sends points on a line segment to an Interpolator.
95 ///
96 /// Uses:
97 /// - DataBox:
98 /// - ::Tags::Domain<VolumeDim, Frame>
99 /// - ::Tags::Variables<typename
100 /// InterpolationTargetTag::vars_to_interpolate_to_target>
101 ///
102 /// DataBox changes:
104 /// - Removes: nothing
105 /// - Modifies:
106 /// - Tags::IndicesOfFilledInterpPoints
107 /// - ::Tags::Variables<typename
108 /// InterpolationTargetTag::vars_to_interpolate_to_target>
109 ///
110 /// For requirements on InterpolationTargetTag, see InterpolationTarget
111 template <typename InterpolationTargetTag, size_t VolumeDim>
112 struct LineSegment {
114  using const_global_cache_tags = tmpl::list<InterpolationTargetTag>;
115  template <typename DbTags, typename... InboxTags, typename Metavariables,
116  typename ArrayIndex, typename ActionList,
117  typename ParallelComponent,
118  Requires<tmpl::list_contains_v<
119  DbTags, typename Tags::TemporalIds<Metavariables>>> = nullptr>
120  static void apply(
121  db::DataBox<DbTags>& box,
122  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
124  const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
125  const ParallelComponent* const /*meta*/,
126  const typename Metavariables::temporal_id::type& temporal_id) noexcept {
127  const auto& options = Parallel::get<InterpolationTargetTag>(cache);
128
129  // Fill points on a line segment
130  const double fractional_distance = 1.0 / (options.number_of_points - 1);
131  tnsr::I<DataVector, VolumeDim, typename Metavariables::domain_frame>
132  target_points(options.number_of_points);
133  for (size_t n = 0; n < options.number_of_points; ++n) {
134  for (size_t d = 0; d < VolumeDim; ++d) {
135  target_points.get(d)[n] =
136  gsl::at(options.begin, d) +
137  n * fractional_distance *
138  (gsl::at(options.end, d) - gsl::at(options.begin, d));
139  }
140  }
141
142  send_points_to_interpolator<InterpolationTargetTag>(
143  box, cache, target_points, temporal_id);
144  }
145 };
146
147 } // namespace Actions
148 } // namespace intrp
Definition: Strahlkorper.hpp:14
Defines class tuples::TaggedTuple.
Sends points on a line segment to an Interpolator.
Definition: InterpolationTargetLineSegment.hpp:112
Defines classes and functions for making classes creatable from input files.
Defines the type alias Requires.
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
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:26
temporal_ids on which to interpolate.
Definition: InterpolationTargetWedgeSectionTorus.hpp:29
Definition: InterpolationTargetLineSegment.hpp:49
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Definition: InterpolationTargetLineSegment.hpp:45
Definition: DataBoxTag.hpp:29
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Defines a list of useful type aliases for tensors.
Namespace for DataBox related things.
Definition: DataBox.hpp:33
Stores a collection of function values.
Definition: DataVector.hpp:46
Wraps the template metaprogramming library used (brigand)
Defines functions and classes from the GSL.
A line segment extending from Begin to End, containing NumberOfPoints uniformly-spaced points includi...
Definition: InterpolationTargetLineSegment.hpp:44
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t ...
Definition: Requires.hpp:67
Identifies a step in the linear solver algorithm.
Definition: IterationId.hpp:25
Definition: SolvePoissonProblem.hpp:38
Defines class template ConstGlobalCache.
Definition: InterpolationTargetLineSegment.hpp:53
Definition: ComputeTimeDerivative.hpp:28
constexpr T & at(std::array< T, N > &arr, Size index)
Retrieve a entry from a container, with checks in Debug mode that the index being retrieved is valid...
Definition: Gsl.hpp:124