Line data Source code
1 0 : // 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"
11 : #include "DataStructures/Tensor/TypeAliases.hpp"
12 : #include "Options/String.hpp"
13 : #include "ParallelAlgorithms/Interpolation/Protocols/ComputeTargetPoints.hpp"
14 : #include "ParallelAlgorithms/Interpolation/Tags.hpp"
15 : #include "Utilities/Gsl.hpp"
16 : #include "Utilities/PrettyType.hpp"
17 : #include "Utilities/ProtocolHelpers.hpp"
18 : #include "Utilities/TMPL.hpp"
19 :
20 : /// \cond
21 : class DataVector;
22 : namespace PUP {
23 : class er;
24 : } // namespace PUP
25 : namespace db {
26 : template <typename TagsList>
27 : class DataBox;
28 : } // namespace db
29 : namespace intrp {
30 : namespace Tags {
31 : template <typename TemporalId>
32 : struct TemporalIds;
33 : } // namespace Tags
34 : } // namespace intrp
35 : /// \endcond
36 :
37 : namespace intrp {
38 :
39 : namespace OptionHolders {
40 : /// A list of specified points to interpolate to.
41 : ///
42 : /// \note Input coordinates are interpreted in `Frame::Inertial`
43 : template <size_t VolumeDim>
44 1 : struct SpecifiedPoints {
45 0 : struct Points {
46 0 : using type = std::vector<std::array<double, VolumeDim>>;
47 0 : static constexpr Options::String help = {"Coordinates of each point"};
48 : };
49 0 : using options = tmpl::list<Points>;
50 0 : static constexpr Options::String help = {"A list of specified points"};
51 :
52 0 : explicit SpecifiedPoints(
53 : std::vector<std::array<double, VolumeDim>> points_in);
54 :
55 0 : SpecifiedPoints() = default;
56 0 : SpecifiedPoints(const SpecifiedPoints& /*rhs*/) = default;
57 0 : SpecifiedPoints& operator=(const SpecifiedPoints& /*rhs*/) = default;
58 0 : SpecifiedPoints(SpecifiedPoints&& /*rhs*/) = default;
59 0 : SpecifiedPoints& operator=(SpecifiedPoints&& /*rhs*/) = default;
60 0 : ~SpecifiedPoints() = default;
61 :
62 : // NOLINTNEXTLINE(google-runtime-references)
63 0 : void pup(PUP::er& p);
64 :
65 0 : std::vector<std::array<double, VolumeDim>> points{};
66 : };
67 :
68 : template <size_t VolumeDim>
69 0 : bool operator==(const SpecifiedPoints<VolumeDim>& lhs,
70 : const SpecifiedPoints<VolumeDim>& rhs);
71 : template <size_t VolumeDim>
72 0 : bool operator!=(const SpecifiedPoints<VolumeDim>& lhs,
73 : const SpecifiedPoints<VolumeDim>& rhs);
74 :
75 : } // namespace OptionHolders
76 :
77 : namespace OptionTags {
78 : template <typename InterpolationTargetTag, size_t VolumeDim>
79 0 : struct SpecifiedPoints {
80 0 : using type = OptionHolders::SpecifiedPoints<VolumeDim>;
81 0 : static constexpr Options::String help{
82 : "Options for interpolation onto a specified list of points."};
83 0 : static std::string name() {
84 : return pretty_type::name<InterpolationTargetTag>();
85 : }
86 0 : using group = InterpolationTargets;
87 : };
88 : } // namespace OptionTags
89 :
90 : namespace Tags {
91 : template <typename InterpolationTargetTag, size_t VolumeDim>
92 0 : struct SpecifiedPoints : db::SimpleTag {
93 0 : using type = OptionHolders::SpecifiedPoints<VolumeDim>;
94 0 : using option_tags = tmpl::list<
95 : OptionTags::SpecifiedPoints<InterpolationTargetTag, VolumeDim>>;
96 :
97 0 : static constexpr bool pass_metavariables = false;
98 0 : static type create_from_options(const type& option) { return option; }
99 : };
100 : } // namespace Tags
101 :
102 : namespace TargetPoints {
103 : /// \brief Returns list of points as specified in input file.
104 : ///
105 : /// Conforms to the intrp::protocols::ComputeTargetPoints protocol
106 : ///
107 : /// For requirements on InterpolationTargetTag, see
108 : /// intrp::protocols::InterpolationTargetTag
109 : template <typename InterpolationTargetTag, size_t VolumeDim>
110 1 : struct SpecifiedPoints : tt::ConformsTo<intrp::protocols::ComputeTargetPoints> {
111 0 : using const_global_cache_tags =
112 : tmpl::list<Tags::SpecifiedPoints<InterpolationTargetTag, VolumeDim>>;
113 0 : using is_sequential = std::false_type;
114 0 : using frame = Frame::Inertial;
115 :
116 : template <typename Metavariables, typename DbTags>
117 0 : static tnsr::I<DataVector, VolumeDim, Frame::Inertial> points(
118 : const db::DataBox<DbTags>& box,
119 : const tmpl::type_<Metavariables>& /*meta*/) {
120 : const auto& options =
121 : get<Tags::SpecifiedPoints<InterpolationTargetTag, VolumeDim>>(box);
122 : tnsr::I<DataVector, VolumeDim, Frame::Inertial> target_points(
123 : options.points.size());
124 : for (size_t d = 0; d < VolumeDim; ++d) {
125 : for (size_t i = 0; i < options.points.size(); ++i) {
126 : target_points.get(d)[i] = gsl::at(options.points[i], d);
127 : }
128 : }
129 : return target_points;
130 : }
131 :
132 : template <typename Metavariables, typename DbTags, typename TemporalId>
133 0 : static tnsr::I<DataVector, VolumeDim, Frame::Inertial> points(
134 : const db::DataBox<DbTags>& box, const tmpl::type_<Metavariables>& meta,
135 : const TemporalId& /*temporal_id*/) {
136 : return points(box, meta);
137 : }
138 : };
139 :
140 : } // namespace TargetPoints
141 : } // namespace intrp
|