GrTagsForHydro.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 <memory>
9 #include <string>
10 #include <unordered_map>
11 #include <utility>
12 
16 #include "Domain/CoordinateMaps/Tags.hpp"
17 #include "Domain/ElementMap.hpp"
18 #include "Domain/FunctionsOfTime/FunctionOfTime.hpp"
19 #include "Domain/FunctionsOfTime/Tags.hpp"
20 #include "Domain/Tags.hpp"
21 #include "Evolution/DgSubcell/Tags/Coordinates.hpp"
22 #include "Evolution/DgSubcell/Tags/Inactive.hpp"
23 #include "Evolution/DgSubcell/Tags/Mesh.hpp"
24 #include "Evolution/DgSubcell/Tags/OnSubcellFaces.hpp"
25 #include "Evolution/Initialization/InitialData.hpp"
29 #include "Utilities/Gsl.hpp"
30 #include "Utilities/TMPL.hpp"
31 
32 /// \cond
33 namespace Initialization {
34 namespace Tags {
35 struct InitialTime;
36 } // namespace Tags
37 } // namespace Initialization
38 namespace Tags {
39 struct AnalyticSolutionOrData;
40 } // namespace Tags
41 namespace domain {
42 namespace Tags {
43 template <size_t Dim, typename Frame>
44 struct Coordinates;
45 template <size_t VolumeDim>
46 struct Mesh;
47 } // namespace Tags
48 } // namespace domain
49 // IWYU pragma: no_forward_declare db::DataBox
50 /// \endcond
51 
52 namespace Initialization {
53 /// Generic initialization actions and mutators for the subcell solver.
54 namespace subcell {
55 /*!
56  * \ingroup InitializationGroup
57  * \brief Allocate and set general relativity quantities needed for evolution
58  * of hydro systems when using a DG-subcell hybrid scheme.
59  *
60  * Uses:
61  * - DataBox:
62  * * `evolution::dg::subcell::Tags::Mesh<Dim>`
63  * * `domain::Tags::ElementMap<Dim, Frame::Grid>`
64  * * `Tags::CoordinateMap<Dim, Frame::Grid, Frame::Inertial>`
65  * * `domain::Tags::FunctionsOfTime`
66  * * `evolution::dg::subcell::Tags::Coordinates<Dim, Frame::Logical>`
67  * * `::Tags::AnalyticSolutionOrData`
68  *
69  * DataBox changes:
70  * - Adds:
71  * * `dg::subcell::Tags::Inactive<System::spacetime_variables_tag>`
72  * * `Tags::OnSubcellFaces<System::flux_spacetime_variables_tag, Dim>`
73  *
74  * - Removes: nothing
75  * - Modifies: nothing
76  *
77  * \note This action relies on the `SetupDataBox` aggregated initialization
78  * mechanism, so `Actions::SetupDataBox` must be present in the
79  * `Initialization` phase action list prior to this action.
80  */
81 template <typename System, size_t Dim>
83  using initialization_tags = tmpl::list<Initialization::Tags::InitialTime>;
84 
85  using gr_tag = typename System::spacetime_variables_tag;
88  typename System::flux_spacetime_variables_tag, Dim>;
89  using GrVars = typename gr_tag::type;
90  using SubcellGrVars = typename subcell_gr_tag::type;
91  using FaceGrVars = typename subcell_faces_gr_tag::type::value_type;
92 
93  using return_tags = tmpl::list<subcell_gr_tag, subcell_faces_gr_tag>;
94  using argument_tags =
103 
104  template <typename AnalyticDataOrSolution>
105  static void apply(
106  const gsl::not_null<SubcellGrVars*> cell_centered_gr_vars,
107  const gsl::not_null<std::array<FaceGrVars, Dim>*> face_centered_gr_vars,
108  const double initial_time, const Mesh<Dim>& subcell_mesh,
109  const ElementMap<Dim, Frame::Grid>& logical_to_grid_map,
111  grid_to_inertial_map,
112  const std::unordered_map<
113  std::string,
115  functions_of_time,
116  const tnsr::I<DataVector, Dim, Frame::Logical>&
117  subcell_logical_coordinates,
118  const AnalyticDataOrSolution& analytic_data_or_solution) noexcept {
119  const size_t num_grid_points = subcell_mesh.number_of_grid_points();
120  const auto cell_centered_inertial_coords =
121  grid_to_inertial_map(logical_to_grid_map(subcell_logical_coordinates),
122  initial_time, functions_of_time);
123 
124  // Set cell-centered vars. Need to first do without prefix then move into
125  // prefixed Variables.
126  GrVars no_prefix_cell_centered_gr_vars{num_grid_points};
127  no_prefix_cell_centered_gr_vars.assign_subset(evolution::initial_data(
128  analytic_data_or_solution, cell_centered_inertial_coords, initial_time,
129  typename GrVars::tags_list{}));
130  *cell_centered_gr_vars = std::move(no_prefix_cell_centered_gr_vars);
131 
132  // Set GR variables needed for computing the fluxes on the faces.
133  ASSERT(Mesh<Dim>(subcell_mesh.extents(0), subcell_mesh.basis(0),
134  subcell_mesh.quadrature(0)) == subcell_mesh,
135  "The subcell mesh must have isotropic basis, quadrature. and "
136  "extents but got "
137  << subcell_mesh);
138  for (size_t d = 0; d < Dim; ++d) {
139  const auto basis = make_array<Dim>(subcell_mesh.basis(0));
140  auto quadrature = make_array<Dim>(subcell_mesh.quadrature(0));
141  auto extents = make_array<Dim>(subcell_mesh.extents(0));
142  gsl::at(extents, d) = subcell_mesh.extents(0) + 1;
143  gsl::at(quadrature, d) = Spectral::Quadrature::FaceCentered;
144  const Mesh<Dim> face_centered_mesh{extents, basis, quadrature};
145  const auto face_centered_logical_coords =
146  logical_coordinates(face_centered_mesh);
147  const auto face_centered_inertial_coords = grid_to_inertial_map(
148  logical_to_grid_map(face_centered_logical_coords), initial_time,
149  functions_of_time);
150 
151  gsl::at(*face_centered_gr_vars, d)
152  .initialize(face_centered_mesh.number_of_grid_points());
153  gsl::at(*face_centered_gr_vars, d)
154  .assign_subset(evolution::initial_data(
155  analytic_data_or_solution, face_centered_inertial_coords,
156  initial_time, typename FaceGrVars::tags_list{}));
157  }
158  }
159 };
160 } // namespace subcell
161 } // namespace Initialization
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
Initialization::subcell::GrTagsForHydro
Allocate and set general relativity quantities needed for evolution of hydro systems when using a DG-...
Definition: GrTagsForHydro.hpp:82
std::string
utility
Frame::Inertial
Definition: IndexType.hpp:44
domain::CoordinateMapBase
Abstract base class for CoordinateMap.
Definition: CoordinateMap.hpp:45
domain::Tags::FunctionsOfTime
The FunctionsOfTime initialized from a DomainCreator or (if override_functions_of_time is true in the...
Definition: Tags.hpp:60
Frame::Grid
Definition: IndexType.hpp:43
Tags.hpp
Mesh::basis
const std::array< Spectral::Basis, Dim > & basis() const noexcept
The basis chosen in each dimension of the grid.
Definition: Mesh.hpp:182
CoordinateMap.hpp
Spectral.hpp
Initialization::Tags::InitialTime
Definition: Tags.hpp:18
evolution::initial_data
decltype(auto) initial_data(const SolutionOrData &solution_or_data, Coordinates &&coordinates, const double time, const tmpl::list< Tags... > tags) noexcept
Extract initial data either from analytic data or from an analytic solution at a specified time.
Definition: InitialData.hpp:17
cstddef
Assert.hpp
array
Mesh::number_of_grid_points
size_t number_of_grid_points() const noexcept
The total number of grid points in all dimensions.
Definition: Mesh.hpp:165
ElementMap
The CoordinateMap for the Element from the Logical frame to the TargetFrame
Definition: ElementMap.hpp:33
evolution::dg::subcell::Tags::OnSubcellFaces
Mark a tag as the being on the subcell faces.
Definition: OnSubcellFaces.hpp:20
Tags::AnalyticSolutionOrData
Definition: Tags.hpp:34
memory
evolution::dg::subcell::Tags::Mesh
The mesh on the subcells.
Definition: Mesh.hpp:19
domain::CoordinateMaps::Tags::CoordinateMap
Definition: Tags.hpp:30
ASSERT
#define ASSERT(a, m)
Assert that an expression should be true.
Definition: Assert.hpp:49
Variables.hpp
Mesh
Holds the number of grid points, basis, and quadrature in each direction of the computational grid.
Definition: Mesh.hpp:49
logical_coordinates
void logical_coordinates(gsl::not_null< tnsr::I< DataVector, VolumeDim, Frame::Logical > * > logical_coords, const Mesh< VolumeDim > &mesh) noexcept
Compute the logical coordinates in an Element.
Gsl.hpp
Tensor.hpp
Mesh::quadrature
const std::array< Spectral::Quadrature, Dim > & quadrature() const noexcept
The quadrature chosen in each dimension of the grid.
Definition: Mesh.hpp:196
evolution::dg::subcell::Tags::Inactive
Mark a tag as holding data for the inactive grid.
Definition: Inactive.hpp:23
Mesh::extents
const Index< Dim > & extents() const noexcept
The number of grid points in each dimension of the grid.
Definition: Mesh.hpp:148
evolution::dg::subcell::Tags::Coordinates
The coordinates in a given frame.
Definition: Coordinates.hpp:27
std::unique_ptr
unordered_map
TMPL.hpp
Mesh.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecPiecewisePolynomial.hpp:13
domain::Tags::ElementMap
Definition: Tags.hpp:115
string