TakeTimeStep.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <optional>
7 #include <tuple>
8 #include <utility>
9 
11 #include "DataStructures/DataVector.hpp"
15 #include "Domain/CoordinateMaps/Tags.hpp"
16 #include "Domain/ElementMap.hpp"
17 #include "Domain/Tags.hpp"
18 #include "Evolution/DgSubcell/Tags/Coordinates.hpp"
19 #include "Evolution/DgSubcell/Tags/Jacobians.hpp"
20 #include "Evolution/DiscontinuousGalerkin/MortarData.hpp"
21 #include "Evolution/DiscontinuousGalerkin/MortarTags.hpp"
23 
24 /// \cond
25 namespace Parallel {
26 template <typename Metavariables>
27 class GlobalCache;
28 } // namespace Parallel
29 namespace tuples {
30 template <typename...>
31 class TaggedTuple;
32 } // namespace tuples
33 /// \endcond
34 
36 /*!
37  * \brief Take a finite-difference time step on the subcell grid.
38  *
39  * The template parameter `TimeDerivative` must have a `static apply` function
40  * that takes the `DataBox` by `gsl::not_null` as its first argument and the
41  * determinant of the inverse Jacobian from the logical to the grid frame as the
42  * second argument.
43  *
44  * GlobalCache: nothing
45  *
46  * DataBox:
47  * - Uses:
48  * - `subcell::fd::Tags::InverseJacobianLogicalToGrid<Dim>`
49  * - `subcell::fd::Tags::DetInverseJacobianLogicalToGrid`
50  * - `domain::Tags::ElementMap<Dim, Frame::Grid>`
51  * - `domain::CoordinateMaps::Tags::CoordinateMap<Dim, Grid, Inertial>`
52  * - `subcell::Tags::Coordinates<Dim, Frame::Logical>`
53  * - Anything that `Metavariables::SubcellOptions::TimeDerivative` uses
54  * - Adds: nothing
55  * - Removes: nothing
56  * - Modifies:
57  * - `subcell::fd::Tags::InverseJacobianLogicalToGrid<Dim>`
58  * - `subcell::fd::Tags::DetInverseJacobianLogicalToGrid`
59  * - Anything that `Metavariables::SubcellOptions::TimeDerivative` modifies
60  */
61 template <typename TimeDerivative>
62 struct TakeTimeStep {
63  template <typename DbTags, typename... InboxTags, typename Metavariables,
64  typename ArrayIndex, typename ActionList,
65  typename ParallelComponent, size_t Dim = Metavariables::volume_dim>
66  static std::tuple<db::DataBox<DbTags>&&> apply(
67  db::DataBox<DbTags>& box, tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
68  const Parallel::GlobalCache<Metavariables>& /*cache*/,
69  const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
70  const ParallelComponent* const /*meta*/) noexcept {
72  Dim, Frame::Grid, Frame::Inertial>>(box))
73  .is_identity(),
74  "Do not yet support moving mesh with DG-subcell.");
75  db::mutate<fd::Tags::InverseJacobianLogicalToGrid<Dim>,
77  make_not_null(&box),
78  [](const auto inv_jac_ptr, const auto det_inv_jac_ptr,
79  const auto& logical_to_grid_map,
80  const auto& logical_coords) noexcept {
81  if (not inv_jac_ptr->has_value()) {
82  *inv_jac_ptr = logical_to_grid_map.inv_jacobian(logical_coords);
83  *det_inv_jac_ptr = determinant(**inv_jac_ptr);
84  }
85  },
86  db::get<::domain::Tags::ElementMap<Dim, Frame::Grid>>(box),
88 
89  TimeDerivative::apply(
90  make_not_null(&box),
92  *db::get<fd::Tags::DetInverseJacobianLogicalToGrid>(box));
93 
94  db::mutate<evolution::dg::Tags::MortarData<Dim>>(
95  make_not_null(&box), [](const auto mortar_data_ptr) noexcept {
96  for (auto& data : *mortar_data_ptr) {
97  data.second = evolution::dg::MortarData<Dim>{};
98  }
99  });
100  return {std::move(box)};
101  }
102 };
103 } // namespace evolution::dg::subcell::fd::Actions
utility
Frame::Inertial
Definition: IndexType.hpp:44
evolution::dg::subcell::fd::Tags::InverseJacobianLogicalToGrid
The inverse Jacobian from the logical frame to the grid frame at the cell centers.
Definition: Jacobians.hpp:22
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
Frame::Grid
Definition: IndexType.hpp:43
Tags.hpp
tuple
db::get
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:791
CoordinateMap.hpp
determinant
void determinant(const gsl::not_null< Scalar< T > * > det_tensor, const Tensor< T, Symm, index_list< Index0, Index1 >> &tensor) noexcept
Computes the determinant of a rank-2 Tensor tensor.
Definition: Determinant.hpp:139
evolution::dg::subcell::fd::Actions
Actions specific to using a finite-difference subcell method.
Definition: Actions.hpp:13
evolution::dg::MortarData
Data on the mortar used to compute the boundary correction for the DG scheme.
Definition: MortarData.hpp:50
DataBox.hpp
evolution::dg::subcell::fd::Actions::TakeTimeStep
Take a finite-difference time step on the subcell grid.
Definition: TakeTimeStep.hpp:62
Assert.hpp
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
domain::CoordinateMaps::Tags::CoordinateMap
Definition: Tags.hpp:30
ASSERT
#define ASSERT(a, m)
Assert that an expression should be true.
Definition: Assert.hpp:49
Tensor.hpp
Determinant.hpp
optional
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
evolution::dg::subcell::fd::Tags::DetInverseJacobianLogicalToGrid
The determinant of the inverse Jacobian from the logical frame to the grid frame at the cell centers.
Definition: Jacobians.hpp:33
evolution::dg::subcell::Tags::Coordinates
The coordinates in a given frame.
Definition: Coordinates.hpp:27
Parallel
Functionality for parallelization.
Definition: ElementReceiveInterpPoints.hpp:13