InterpolationTargetSpecifiedPoints.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 <vector>
9 
10 #include "DataStructures/DataBox/Tag.hpp"
12 #include "NumericalAlgorithms/Interpolation/Tags.hpp"
13 #include "Options/Options.hpp"
14 #include "Utilities/Gsl.hpp"
15 #include "Utilities/TMPL.hpp"
16 
17 /// \cond
18 class DataVector;
19 namespace PUP {
20 class er;
21 } // namespace PUP
22 namespace db {
23 template <typename TagsList>
24 class DataBox;
25 } // namespace db
26 namespace intrp {
27 namespace Tags {
28 template <typename TemporalId>
29 struct TemporalIds;
30 } // namespace Tags
31 } // namespace intrp
32 /// \endcond
33 
34 namespace intrp {
35 
36 namespace OptionHolders {
37 /// A list of specified points to interpolate to.
38 ///
39 /// \note Input coordinates are interpreted in `Frame::Inertial`
40 template <size_t VolumeDim>
42  struct Points {
44  static constexpr Options::String help = {"Coordinates of each point"};
45  };
46  using options = tmpl::list<Points>;
47  static constexpr Options::String help = {"A list of specified points"};
48 
49  explicit SpecifiedPoints(
50  std::vector<std::array<double, VolumeDim>> points_in) noexcept;
51 
52  SpecifiedPoints() = default;
53  SpecifiedPoints(const SpecifiedPoints& /*rhs*/) = delete;
54  SpecifiedPoints& operator=(const SpecifiedPoints& /*rhs*/) = default;
55  SpecifiedPoints(SpecifiedPoints&& /*rhs*/) noexcept = default;
56  SpecifiedPoints& operator=(SpecifiedPoints&& /*rhs*/) noexcept = default;
57  ~SpecifiedPoints() = default;
58 
59  // clang-tidy non-const reference pointer.
60  void pup(PUP::er& p) noexcept; // NOLINT
61 
62  std::vector<std::array<double, VolumeDim>> points{};
63 };
64 
65 template <size_t VolumeDim>
66 bool operator==(const SpecifiedPoints<VolumeDim>& lhs,
67  const SpecifiedPoints<VolumeDim>& rhs) noexcept;
68 template <size_t VolumeDim>
69 bool operator!=(const SpecifiedPoints<VolumeDim>& lhs,
70  const SpecifiedPoints<VolumeDim>& rhs) noexcept;
71 
72 } // namespace OptionHolders
73 
74 namespace OptionTags {
75 template <typename InterpolationTargetTag, size_t VolumeDim>
78  static constexpr Options::String help{
79  "Options for interpolation onto a specified list of points."};
80  static std::string name() noexcept {
81  return Options::name<InterpolationTargetTag>();
82  }
84 };
85 } // namespace OptionTags
86 
87 namespace Tags {
88 template <typename InterpolationTargetTag, size_t VolumeDim>
91  using option_tags = tmpl::list<
93 
94  static constexpr bool pass_metavariables = false;
95  static type create_from_options(const type& option) noexcept {
96  return option;
97  }
98 };
99 } // namespace Tags
100 
101 namespace TargetPoints {
102 /// \brief Returns list of points as specified in input file.
103 ///
104 /// For requirements on InterpolationTargetTag, see InterpolationTarget
105 template <typename InterpolationTargetTag, size_t VolumeDim>
107  using const_global_cache_tags =
108  tmpl::list<Tags::SpecifiedPoints<InterpolationTargetTag, VolumeDim>>;
110  using frame = Frame::Inertial;
111 
112  template <typename Metavariables, typename DbTags>
113  static tnsr::I<DataVector, VolumeDim, Frame::Inertial> points(
114  const db::DataBox<DbTags>& box,
115  const tmpl::type_<Metavariables>& /*meta*/) noexcept {
116  const auto& options =
117  get<Tags::SpecifiedPoints<InterpolationTargetTag, VolumeDim>>(box);
118  tnsr::I<DataVector, VolumeDim, Frame::Inertial> target_points(
119  options.points.size());
120  for (size_t d = 0; d < VolumeDim; ++d) {
121  for (size_t i = 0; i < options.points.size(); ++i) {
122  target_points.get(d)[i] = gsl::at(options.points[i], d);
123  }
124  }
125  return target_points;
126  }
127 
128  template <typename Metavariables, typename DbTags, typename TemporalId>
129  static tnsr::I<DataVector, VolumeDim, Frame::Inertial> points(
130  const db::DataBox<DbTags>& box, const tmpl::type_<Metavariables>& meta,
131  const TemporalId& /*temporal_id*/) noexcept {
132  return points(box, meta);
133  }
134 };
135 
136 } // namespace TargetPoints
137 } // namespace intrp
gsl::at
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:125
std::false_type
intrp::OptionHolders::SpecifiedPoints
A list of specified points to interpolate to.
Definition: InterpolationTargetSpecifiedPoints.hpp:41
std::string
Frame::Inertial
Definition: IndexType.hpp:44
Options.hpp
intrp::Tags::SpecifiedPoints
Definition: InterpolationTargetSpecifiedPoints.hpp:89
intrp
Contains classes and functions for interpolation.
Definition: ElementInitInterpPoints.hpp:23
vector
db::SimpleTag
Mark a struct as a simple tag by inheriting from this.
Definition: Tag.hpp:36
intrp::OptionTags::InterpolationTargets
Groups option tags for InterpolationTargets.
Definition: Tags.hpp:34
intrp::OptionTags::SpecifiedPoints
Definition: InterpolationTargetSpecifiedPoints.hpp:76
cstddef
array
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:46
intrp::OptionHolders::SpecifiedPoints::Points
Definition: InterpolationTargetSpecifiedPoints.hpp:42
intrp::TargetPoints::SpecifiedPoints
Returns list of points as specified in input file.
Definition: InterpolationTargetSpecifiedPoints.hpp:106
Gsl.hpp
TypeAliases.hpp
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
TMPL.hpp
db
Namespace for DataBox related things.
Definition: DataBox.hpp:44