ApplyFluxes.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <tuple>
8 
13 #include "Domain/IndexToSliceAt.hpp"
14 #include "NumericalAlgorithms/DiscontinuousGalerkin/FluxCommunicationTypes.hpp"
15 #include "NumericalAlgorithms/DiscontinuousGalerkin/MortarHelpers.hpp"
16 #include "NumericalAlgorithms/DiscontinuousGalerkin/Tags.hpp" // IWYU pragma: keep // for db::item_type<Tags::Mortars<...>>
17 #include "Utilities/Gsl.hpp"
19 
20 /// \cond
21 namespace Parallel {
22 template <typename Metavariables>
23 class ConstGlobalCache;
24 } // namespace Parallel
25 namespace Tags {
26 template <size_t VolumeDim>
27 struct Mesh;
28 } // namespace Tags
29 // IWYU pragma: no_forward_declare db::DataBox
30 /// \endcond
31 
32 namespace dg {
33 namespace Actions {
34 /*!
35  * \ingroup ActionsGroup
36  * \ingroup DiscontinuousGalerkinGroup
37  * \brief Compute element boundary contributions to the temporal step of the
38  * variables
39  *
40  * This action invokes the numerical flux operator for each mortar of the
41  * element, lifts the data to the volume and adds it to the temporal step
42  * variables. These would be the time derivatives `Tags::dt` of the system
43  * variables for an evolution system, for instance.
44  *
45  * With:
46  * - `flux_comm_types = dg::FluxCommunicationTypes<Metavariables>`
47  *
48  * Uses:
49  * - All items used by `flux_comm_types`
50  * - Metavariables:
51  * - `temporal_id::step_prefix`
52  * - System:
53  * - `volume_dim`
54  * - `variables_tag`
55  * - ConstGlobalCache:
56  * - `Metavariables::normal_dot_numerical_flux`
57  * - DataBox:
58  * - `Tags::Mesh<volume_dim>`
59  * - `Tags::Mortars<Tags::Mesh<volume_dim - 1>, volume_dim>`
60  * - `Tags::Mortars<Tags::MortarSize<volume_dim - 1>, volume_dim>`
61  *
62  * DataBox changes:
63  * - Modifies:
64  * - `db::add_tag_prefix<step_prefix, variables_tag>`
65  * - `flux_comm_types::mortar_data_tag`
66  */
67 struct ApplyFluxes {
68  template <typename DbTags, typename... InboxTags, typename Metavariables,
69  typename ArrayIndex, typename ActionList,
70  typename ParallelComponent>
73  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
75  const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
76  const ParallelComponent* const /*meta*/) noexcept {
77  using system = typename Metavariables::system;
78  constexpr size_t volume_dim = system::volume_dim;
79  using variables_tag = typename system::variables_tag;
80  using dt_variables_tag =
81  db::add_tag_prefix<Metavariables::temporal_id::template step_prefix,
82  variables_tag>;
83 
84  using flux_comm_types = FluxCommunicationTypes<Metavariables>;
85  using mortar_data_tag = typename flux_comm_types::simple_mortar_data_tag;
86  db::mutate<dt_variables_tag, mortar_data_tag>(
87  make_not_null(&box),
88  [&cache](
92  const db::item_type<Tags::Mortars<Tags::Mesh<volume_dim - 1>,
93  volume_dim>>& mortar_meshes,
94  const db::item_type<
95  Tags::Mortars<Tags::MortarSize<volume_dim - 1>, volume_dim>>&
96  mortar_sizes) noexcept {
97  const auto& normal_dot_numerical_flux_computer =
98  get<typename Metavariables::normal_dot_numerical_flux>(cache);
99 
100  for (auto& this_mortar_data : *mortar_data) {
101  const auto& mortar_id = this_mortar_data.first;
102  const auto& direction = mortar_id.first;
103  const size_t dimension = direction.dimension();
104 
105  auto data = this_mortar_data.second.extract();
106  auto& local_mortar_data = data.first;
107  const auto& remote_mortar_data = data.second;
108 
110  compute_boundary_flux_contribution<flux_comm_types>(
111  normal_dot_numerical_flux_computer,
112  std::move(local_mortar_data), remote_mortar_data,
113  mesh.slice_away(dimension), mortar_meshes.at(mortar_id),
114  mesh.extents(dimension), mortar_sizes.at(mortar_id)));
115 
116  add_slice_to_data(dt_vars, lifted_data, mesh.extents(), dimension,
117  index_to_slice_at(mesh.extents(), direction));
118  }
119  },
120  db::get<Tags::Mesh<volume_dim>>(box),
122  db::get<Tags::Mortars<Tags::MortarSize<volume_dim - 1>, volume_dim>>(
123  box));
124 
125  return std::forward_as_tuple(std::move(box));
126  }
127 };
128 } // namespace Actions
129 } // namespace dg
Prefix< DataBox_detail::dispatch_add_tag_prefix_impl< Prefix, Tag, Args... >, Args... > add_tag_prefix
Wrap Tag in Prefix<_, Args...>, also wrapping variables tags if Tag is a Tags::Variables.
Definition: DataBoxTag.hpp:533
size_t index_to_slice_at(const Index< Dim > &extents, const Direction< Dim > &direction) noexcept
Finds the index in the perpendicular dimension of an element boundary.
Definition: IndexToSliceAt.hpp:15
Defines class tuples::TaggedTuple.
Definition: InitializeElement.hpp:63
Holds the number of grid points, basis, and quadrature in each direction of the computational grid...
Definition: Mesh.hpp:49
Define prefixes for DataBox tags.
Contains functions that forward to Charm++ parallel functions.
Definition: Abort.hpp:13
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args)
Apply the function f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1595
Data on mortars, indexed by (Direction, ElementId) pairs.
Definition: Tags.hpp:34
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
Defines classes and functions used for manipulating DataBox&#39;s.
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Types related to flux communication.
Definition: FluxCommunicationTypes.hpp:37
Definition: DataBoxTag.hpp:29
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Size of a mortar, relative to the element face. That is, the part of the face that it covers...
Definition: Tags.hpp:46
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:1211
The Poisson equation formulated as a set of coupled first-order PDEs.
Definition: FirstOrderSystem.hpp:55
The computational grid of the Element in the DataBox.
Definition: Tags.hpp:75
typename DataBox_detail::item_type_impl< TagList, Tag >::type item_type
Get the type that is returned by the Tag. If it is a base tag then a TagList must be passed as a seco...
Definition: DataBoxTag.hpp:410
Defines functions and classes from the GSL.
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, but it may be necessary to perform the conversion explicitly when type deduction is desired.
Definition: Gsl.hpp:863
Compute element boundary contributions to the temporal step of the variables.
Definition: ApplyFluxes.hpp:67
Defines helper functions for use with Variables class.
Definition: SolvePoissonProblem.hpp:38
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
void add_slice_to_data(const gsl::not_null< Variables< TagsList > *> volume_vars, const Variables< TagsList > &vars_on_slice, const Index< VolumeDim > &extents, const size_t sliced_dim, const size_t fixed_index) noexcept
Adds data on a codimension 1 slice to a volume quantity. The slice has a constant logical coordinate ...
Definition: VariablesHelpers.hpp:156
Definition: ComputeTimeDerivative.hpp:28
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12