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>,
43  ::Jacobian<DataVector, Dim, Frame::Grid, 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>,
98  ::Jacobian<DataVector, Dim, Frame::Grid, 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>,
124  ::Jacobian<DataVector, Dim, Frame::Grid, 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>,
157  ::Jacobian<DataVector, Dim, Frame::Grid, 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
Computes the Inertial mesh velocity from CoordinatesVelocityAndJacobians
Definition: TagsTimeDependent.hpp:147
Definition: BlockId.hpp:16
Abstract base class for CoordinateMap.
Definition: CoordinateMap.hpp:46
Marks a DataBoxTag as being a compute item that executes a function.
Definition: Tag.hpp:109
Tags for the DataBox inherit from this type.
Definition: Tag.hpp:23
Tag for the current time as a double.
Definition: Tags.hpp:72
Computes the Logical to Inertial inverse Jacobian from CoordinatesVelocityAndJacobians ...
Definition: TagsTimeDependent.hpp:109
The coordinates in a given frame.
Definition: Tags.hpp:128
The Inertial coordinates, the inverse Jacobian from the Grid to the Inertial frame, the Jacobian from the Grid to the Inertial frame, and the Inertial mesh velocity.
Definition: TagsTimeDependent.hpp:39
Computes the Inertial coordinates from CoordinatesVelocityAndJacobians
Definition: TagsTimeDependent.hpp:86
The mesh velocity.
Definition: TagsTimeDependent.hpp:138
The inverse Jacobian from the source frame to the target frame.
Definition: Tags.hpp:158
Definition: DataBoxTag.hpp:27
Defines class CoordinateMap.
Defines classes for Tensor.
Declares function unnormalized_face_normal.
The divergence of the mesh velocity.
Definition: TagsTimeDependent.hpp:165
Computes the Inertial coordinates, the inverse Jacobian from the Grid to the Inertial frame...
Definition: TagsTimeDependent.hpp:51
Wraps the template metaprogramming library used (brigand)
Defines functions and classes from the GSL.
Defines tags related to domain quantities.
Require a pointer to not be a nullptr
Definition: Gsl.hpp:182
The functions of time.
Definition: Tags.hpp:37