TagsTimeDependent.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <boost/optional.hpp>
7 #include <cstddef>
8 #include <memory>
9 #include <string>
10 #include <tuple>
11 #include <unordered_map>
12 
13 #include "DataStructures/DataBox/Tag.hpp"
14 #include "DataStructures/DataVector.hpp"
15 #include "DataStructures/Tensor/EagerMath/Magnitude.hpp" // For Tags::Normalized
18 #include "Domain/FaceNormal.hpp"
19 #include "Domain/FunctionsOfTime/FunctionOfTime.hpp"
20 #include "Domain/FunctionsOfTime/Tags.hpp"
21 #include "Domain/Tags.hpp"
22 #include "Time/Tags.hpp"
23 #include "Utilities/Gsl.hpp"
24 #include "Utilities/TMPL.hpp"
25 
26 namespace domain {
27 /// \ingroup ComputationalDomainGroup
28 /// \brief %Tags for the domain.
29 namespace Tags {
30 /// The Inertial coordinates, the inverse Jacobian from the Grid to the Inertial
31 /// frame, the Jacobian from the Grid to the Inertial frame, and the Inertial
32 /// mesh velocity.
33 ///
34 /// The type is a `boost::optional`, which, when is not valid, signals that the
35 /// mesh is not moving. Thus,
36 /// `static_cast<bool>(coordinates_velocity_and_jacobian)` can be used to check
37 /// if the mesh is moving.
38 template <size_t Dim>
40  using type = boost::optional<std::tuple<
41  tnsr::I<DataVector, Dim, Frame::Inertial>,
44  tnsr::I<DataVector, Dim, Frame::Inertial>>>;
45 };
46 
47 /// Computes the Inertial coordinates, the inverse Jacobian from the Grid to the
48 /// Inertial frame, the Jacobian from the Grid to the Inertial frame, and the
49 /// Inertial mesh velocity.
50 template <typename MapTagGridToInertial>
52  : CoordinatesMeshVelocityAndJacobians<MapTagGridToInertial::dim>,
54  static constexpr size_t dim = MapTagGridToInertial::dim;
56 
57  using return_type = typename base::type;
58 
59  static void function(
60  const gsl::not_null<return_type*> result,
62  grid_to_inertial_map,
63  const tnsr::I<DataVector, dim, Frame::Grid>& source_coords,
64  const double time,
65  const std::unordered_map<
68  functions_of_time) noexcept {
69  // Use identity to signal time-independent
70  if (not grid_to_inertial_map.is_identity()) {
71  *result = grid_to_inertial_map.coords_frame_velocity_jacobians(
72  source_coords, time, functions_of_time);
73  } else {
74  *result = boost::none;
75  }
76  }
77 
78  using argument_tags =
79  tmpl::list<MapTagGridToInertial, Tags::Coordinates<dim, Frame::Grid>,
81 };
82 
83 /// Computes the Inertial coordinates from
84 /// `CoordinatesVelocityAndJacobians`
85 template <size_t Dim>
87  : Tags::Coordinates<Dim, Frame::Inertial>,
90  using return_type = typename base::type;
91 
92  static void function(
94  const tnsr::I<DataVector, Dim, Frame::Grid>& source_coords,
95  const boost::optional<std::tuple<
96  tnsr::I<DataVector, Dim, Frame::Inertial>,
99  tnsr::I<DataVector, Dim, Frame::Inertial>>>&
100  grid_to_inertial_quantities) noexcept;
101 
102  using argument_tags = tmpl::list<Tags::Coordinates<Dim, Frame::Grid>,
104 };
105 
106 /// Computes the Logical to Inertial inverse Jacobian from
107 /// `CoordinatesVelocityAndJacobians`
108 template <size_t Dim>
110  : Tags::InverseJacobian<Dim, Frame::Logical, Frame::Inertial>,
113  using return_type = typename base::type;
114 
115  static void function(
118  inv_jac_logical_to_inertial,
119  const ::InverseJacobian<DataVector, Dim, Frame::Logical, Frame::Grid>&
120  inv_jac_logical_to_grid,
121  const boost::optional<std::tuple<
122  tnsr::I<DataVector, Dim, Frame::Inertial>,
125  tnsr::I<DataVector, Dim, Frame::Inertial>>>&
126  grid_to_inertial_quantities) noexcept;
127 
128  using argument_tags =
129  tmpl::list<Tags::InverseJacobian<Dim, Frame::Logical, Frame::Grid>,
131 };
132 
133 /// The mesh velocity
134 ///
135 /// The type is a `boost::optional`, which when it is not set indicates that the
136 /// mesh is not moving.
137 template <size_t Dim, typename Frame = ::Frame::Inertial>
139  using type = boost::optional<tnsr::I<DataVector, Dim, Frame>>;
140 };
141 
142 /// Computes the Inertial mesh velocity from `CoordinatesVelocityAndJacobians`
143 ///
144 /// The type is a `boost::optional`, which when it is not set indicates that the
145 /// mesh is not moving.
146 template <size_t Dim>
147 struct InertialMeshVelocityCompute : MeshVelocity<Dim, Frame::Inertial>,
150  using return_type = typename base::type;
151 
152  static void function(
153  gsl::not_null<return_type*> mesh_velocity,
154  const boost::optional<std::tuple<
155  tnsr::I<DataVector, Dim, Frame::Inertial>,
158  tnsr::I<DataVector, Dim, Frame::Inertial>>>&
159  grid_to_inertial_quantities) noexcept;
160 
161  using argument_tags = tmpl::list<CoordinatesMeshVelocityAndJacobians<Dim>>;
162 };
163 
164 /// The divergence of the mesh velocity
166  using type = boost::optional<Scalar<DataVector>>;
167  static std::string name() noexcept { return "div(MeshVelocity)"; }
168 };
169 } // namespace Tags
170 } // namespace domain
domain::Tags::CoordinatesMeshVelocityAndJacobians
The Inertial coordinates, the inverse Jacobian from the Grid to the Inertial frame,...
Definition: TagsTimeDependent.hpp:39
db::ComputeTag
Mark a struct as a compute tag by inheriting from this.
Definition: Tag.hpp:157
std::string
domain::CoordinateMapBase
Abstract base class for CoordinateMap.
Definition: CoordinateMap.hpp:45
domain::Tags::FunctionsOfTime
The functions of time.
Definition: Tags.hpp:37
domain::Tags::Coordinates
Definition: Tags.hpp:130
domain::Tags::Jacobian
The Jacobian from the source frame to the target frame.
Definition: Tags.hpp:203
FaceNormal.hpp
Tags.hpp
domain::Tags::MeshVelocity
The mesh velocity.
Definition: TagsTimeDependent.hpp:138
domain::Tags::CoordinatesMeshVelocityAndJacobiansCompute
Computes the Inertial coordinates, the inverse Jacobian from the Grid to the Inertial frame,...
Definition: TagsTimeDependent.hpp:51
domain::Tags::ElementToInertialInverseJacobian
Computes the Logical to Inertial inverse Jacobian from CoordinatesVelocityAndJacobians
Definition: TagsTimeDependent.hpp:109
tuple
db::SimpleTag
Mark a struct as a simple tag by inheriting from this.
Definition: Tag.hpp:36
CoordinateMap.hpp
cstddef
domain::Tags::InverseJacobian
The inverse Jacobian from the source frame to the target frame.
Definition: Tags.hpp:164
domain::Tags::InertialFromGridCoordinatesCompute
Computes the Inertial coordinates from CoordinatesVelocityAndJacobians
Definition: TagsTimeDependent.hpp:86
Tags::Time
Tag for the current time as a double.
Definition: Tags.hpp:73
memory
domain::Tags::InertialMeshVelocityCompute
Computes the Inertial mesh velocity from CoordinatesVelocityAndJacobians
Definition: TagsTimeDependent.hpp:147
domain::Tags::DivMeshVelocity
The divergence of the mesh velocity.
Definition: TagsTimeDependent.hpp:165
Gsl.hpp
Tensor.hpp
std::unique_ptr
unordered_map
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183
string