Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <cstddef>
7 : #include <optional>
8 :
9 : #include "DataStructures/DataBox/DataBox.hpp"
10 : #include "DataStructures/DataVector.hpp"
11 : #include "DataStructures/Tensor/EagerMath/DotProduct.hpp"
12 : #include "DataStructures/Tensor/Tensor.hpp"
13 : #include "DataStructures/Variables.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) {
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... 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::Access& box, tmpl::list<VolumeTags...> /*meta*/,
79 : tmpl::list<ProjectedFieldTagsForCorrection...> /*meta*/) {
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 :
87 : // Used during the auxiliary pass for LDG schemes.
88 : template <typename System, typename BoundaryCorrection,
89 : typename... PackagedFieldTags, typename... ProjectedFieldTags,
90 : typename... ProjectedFieldTagsForCorrection, size_t Dim,
91 : typename... VolumeArgs>
92 : double dg_auxiliary_package_data(
93 : const gsl::not_null<Variables<tmpl::list<PackagedFieldTags...>>*>
94 : packaged_data,
95 : const BoundaryCorrection& boundary_correction,
96 : const Variables<tmpl::list<ProjectedFieldTags...>>& projected_fields,
97 : const tnsr::i<DataVector, Dim, Frame::Inertial>& unit_normal_covector,
98 : const std::optional<tnsr::I<DataVector, Dim, Frame::Inertial>>&
99 : mesh_velocity,
100 : tmpl::list<ProjectedFieldTagsForCorrection...> /*meta*/,
101 : const VolumeArgs&... volume_args) {
102 : std::optional<Scalar<DataVector>> normal_dot_mesh_velocity{};
103 : if (mesh_velocity.has_value()) {
104 : normal_dot_mesh_velocity =
105 : dot_product(*mesh_velocity, unit_normal_covector);
106 : }
107 :
108 : if constexpr (evolution::dg::Actions::detail::
109 : has_inverse_spatial_metric_tag_v<System>) {
110 : return boundary_correction.dg_auxiliary_package_data(
111 : make_not_null(&get<PackagedFieldTags>(*packaged_data))...,
112 : get<ProjectedFieldTagsForCorrection>(projected_fields)...,
113 : unit_normal_covector,
114 : get<evolution::dg::Actions::detail::NormalVector<Dim>>(
115 : projected_fields),
116 : mesh_velocity, normal_dot_mesh_velocity, volume_args...);
117 : } else {
118 : return boundary_correction.dg_auxiliary_package_data(
119 : make_not_null(&get<PackagedFieldTags>(*packaged_data))...,
120 : get<ProjectedFieldTagsForCorrection>(projected_fields)...,
121 : unit_normal_covector, mesh_velocity, normal_dot_mesh_velocity,
122 : volume_args...);
123 : }
124 : }
125 :
126 : template <typename System, typename BoundaryCorrection,
127 : typename... PackagedFieldTags, typename... ProjectedFieldTags,
128 : typename... ProjectedFieldTagsForCorrection, size_t Dim,
129 : typename... VolumeTags>
130 : double dg_auxiliary_package_data(
131 : const gsl::not_null<Variables<tmpl::list<PackagedFieldTags...>>*>
132 : packaged_data,
133 : const BoundaryCorrection& boundary_correction,
134 : const Variables<tmpl::list<ProjectedFieldTags...>>& projected_fields,
135 : const tnsr::i<DataVector, Dim, Frame::Inertial>& unit_normal_covector,
136 : const std::optional<tnsr::I<DataVector, Dim, Frame::Inertial>>&
137 : mesh_velocity,
138 : const db::Access& box, tmpl::list<VolumeTags...> /*meta*/,
139 : tmpl::list<ProjectedFieldTagsForCorrection...> /*meta*/) {
140 : return dg_auxiliary_package_data<System>(
141 : packaged_data, boundary_correction, projected_fields,
142 : unit_normal_covector, mesh_velocity,
143 : tmpl::list<ProjectedFieldTagsForCorrection...>{},
144 : db::get<VolumeTags>(box)...);
145 : }
146 : } // namespace evolution::dg::Actions::detail
|