PackageDataImpl.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <optional>
8 
10 #include "DataStructures/DataVector.hpp"
14 #include "Evolution/DiscontinuousGalerkin/Actions/ComputeTimeDerivativeHelpers.hpp"
15 #include "Evolution/DiscontinuousGalerkin/Actions/NormalCovectorAndMagnitude.hpp"
16 #include "Utilities/Gsl.hpp"
17 #include "Utilities/TMPL.hpp"
18 
19 namespace evolution::dg::Actions::detail {
20 // Helper function to get parameter packs so we can forward `Tensor`s instead
21 // of `Variables` to the boundary corrections. Returns the maximum absolute
22 // char speed on the face, which can be used for setting or monitoring the CFL
23 // without having to compute the speeds for each dimension in the volume.
24 // Whether using only the face speeds is accurate enough to guarantee
25 // stability is yet to be determined. However, if the CFL condition is
26 // violated on the boundaries we are definitely in trouble, so it can at least
27 // be used as a cheap diagnostic.
28 template <typename System, typename BoundaryCorrection,
29  typename... PackagedFieldTags, typename... ProjectedFieldTags,
30  typename... ProjectedFieldTagsForCorrection, size_t Dim,
31  typename... VolumeArgs>
32 double dg_package_data(
33  const gsl::not_null<Variables<tmpl::list<PackagedFieldTags...>>*>
34  packaged_data,
35  const BoundaryCorrection& boundary_correction,
36  const Variables<tmpl::list<ProjectedFieldTags...>>& projected_fields,
37  const tnsr::i<DataVector, Dim, Frame::Inertial>& unit_normal_covector,
38  const std::optional<tnsr::I<DataVector, Dim, Frame::Inertial>>&
39  mesh_velocity,
40  tmpl::list<ProjectedFieldTagsForCorrection...> /*meta*/,
41  const VolumeArgs&... volume_args) noexcept {
42  std::optional<Scalar<DataVector>> normal_dot_mesh_velocity{};
43  if (mesh_velocity.has_value()) {
44  normal_dot_mesh_velocity =
45  dot_product(*mesh_velocity, unit_normal_covector);
46  }
47 
48  if constexpr (evolution::dg::Actions::detail::
49  has_inverse_spatial_metric_tag_v<System>) {
50  return boundary_correction.dg_package_data(
51  make_not_null(&get<PackagedFieldTags>(*packaged_data))...,
52  get<ProjectedFieldTagsForCorrection>(projected_fields)...,
53  unit_normal_covector,
54  get<evolution::dg::Actions::detail::NormalVector<Dim>>(
55  projected_fields),
56  mesh_velocity, normal_dot_mesh_velocity, volume_args...);
57  } else {
58  return boundary_correction.dg_package_data(
59  make_not_null(&get<PackagedFieldTags>(*packaged_data))...,
60  get<ProjectedFieldTagsForCorrection>(projected_fields)...,
61  unit_normal_covector, mesh_velocity, normal_dot_mesh_velocity,
62  volume_args...);
63  }
64 }
65 
66 template <typename System, typename BoundaryCorrection,
67  typename... PackagedFieldTags, typename... ProjectedFieldTags,
68  typename... ProjectedFieldTagsForCorrection, size_t Dim,
69  typename DbTagsList, typename... VolumeTags>
70 double dg_package_data(
71  const gsl::not_null<Variables<tmpl::list<PackagedFieldTags...>>*>
72  packaged_data,
73  const BoundaryCorrection& boundary_correction,
74  const Variables<tmpl::list<ProjectedFieldTags...>>& projected_fields,
75  const tnsr::i<DataVector, Dim, Frame::Inertial>& unit_normal_covector,
76  const std::optional<tnsr::I<DataVector, Dim, Frame::Inertial>>&
77  mesh_velocity,
78  const db::DataBox<DbTagsList>& box, tmpl::list<VolumeTags...> /*meta*/,
79  tmpl::list<ProjectedFieldTagsForCorrection...> /*meta*/) noexcept {
80  return dg_package_data<System>(
81  packaged_data, boundary_correction, projected_fields,
82  unit_normal_covector, mesh_velocity,
83  tmpl::list<ProjectedFieldTagsForCorrection...>{},
84  db::get<VolumeTags>(box)...);
85 }
86 } // namespace evolution::dg::Actions::detail
get
constexpr Tag::type & get(Variables< TagList > &v) noexcept
Return Tag::type pointing into the contiguous array.
Definition: Variables.hpp:660
dot_product
void dot_product(const gsl::not_null< Scalar< DataType > * > dot_product, const Tensor< DataType, Symmetry< 1 >, index_list< Index >> &vector_a, const Tensor< DataType, Symmetry< 1 >, index_list< Index >> &vector_b) noexcept
Compute the Euclidean dot product of two vectors or one forms.
Definition: DotProduct.hpp:24
DotProduct.hpp
DataBox.hpp
cstddef
Variables.hpp
Gsl.hpp
Tensor.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
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecThirdOrderPiecewisePolynomial.hpp:13