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 <memory>
8 : #include <optional>
9 : #include <pup.h>
10 :
11 : #include "Evolution/Systems/CurvedScalarWave/BoundaryCorrections/Factory.hpp"
12 : #include "Evolution/Systems/CurvedScalarWave/System.hpp"
13 : #include "Evolution/Systems/CurvedScalarWave/Tags.hpp"
14 : #include "Evolution/Systems/GeneralizedHarmonic/BoundaryCorrections/Factory.hpp"
15 : #include "Evolution/Systems/GeneralizedHarmonic/System.hpp"
16 : #include "Evolution/Systems/ScalarTensor/BoundaryCorrections/BoundaryCorrection.hpp"
17 : #include "Evolution/Systems/ScalarTensor/Tags.hpp"
18 : #include "NumericalAlgorithms/DiscontinuousGalerkin/Formulation.hpp"
19 : #include "Options/String.hpp"
20 : #include "Utilities/Gsl.hpp"
21 : #include "Utilities/PrettyType.hpp"
22 : #include "Utilities/Serialization/CharmPupable.hpp"
23 : #include "Utilities/TMPL.hpp"
24 :
25 : /// \cond
26 : class DataVector;
27 : /// \endcond
28 :
29 : namespace ScalarTensor::BoundaryCorrections {
30 :
31 : /*!
32 : * \brief Apply a boundary condition to the combined Generalized Harmonic (::gh)
33 : * and scalar field (::CurvedScalarWave) system using boundary corrections
34 : * defined separately.
35 : * \see gh::BoundaryCorrections and CurvedScalarWave::BoundaryCorrections.
36 : */
37 : template <typename DerivedGhCorrection, typename DerivedScalarCorrection>
38 1 : class ProductOfCorrections final : public BoundaryCorrection {
39 : public:
40 0 : static constexpr size_t dim = 3;
41 0 : using dg_package_field_tags =
42 : tmpl::append<typename DerivedGhCorrection::dg_package_field_tags,
43 : typename DerivedScalarCorrection::dg_package_field_tags>;
44 :
45 0 : using dg_package_data_temporary_tags = tmpl::remove_duplicates<tmpl::append<
46 : typename DerivedGhCorrection::dg_package_data_temporary_tags,
47 : typename DerivedScalarCorrection::dg_package_data_temporary_tags>>;
48 :
49 0 : using dg_package_data_primitive_tags = tmpl::list<>;
50 :
51 0 : using dg_package_data_volume_tags = tmpl::append<
52 : typename DerivedGhCorrection::dg_package_data_volume_tags,
53 : typename DerivedScalarCorrection::dg_package_data_volume_tags>;
54 :
55 0 : using dg_boundary_terms_volume_tags = tmpl::append<
56 : typename DerivedGhCorrection::dg_boundary_terms_volume_tags,
57 : typename DerivedScalarCorrection::dg_boundary_terms_volume_tags>;
58 :
59 0 : static std::string name() {
60 : return "Product" + pretty_type::name<DerivedGhCorrection>() + "GH" + "And" +
61 : pretty_type::name<DerivedScalarCorrection>() + "Scalar";
62 : }
63 :
64 0 : struct GhCorrection {
65 0 : using type = DerivedGhCorrection;
66 0 : static std::string name() {
67 : // We change the default name of the boundary correction to avoid errors
68 : // during option parsing
69 : return pretty_type::name<DerivedGhCorrection>() + "GH";
70 : }
71 0 : static constexpr Options::String help{
72 : "The Generalized Harmonic part of the product boundary condition"};
73 : };
74 0 : struct ScalarCorrection {
75 0 : using type = DerivedScalarCorrection;
76 0 : static std::string name() {
77 : // We change the default name of the boundary correction to avoid errors
78 : // during option parsing
79 : return pretty_type::name<DerivedScalarCorrection>() + "Scalar";
80 : }
81 0 : static constexpr Options::String help{
82 : "The scalar part of the product boundary condition"};
83 : };
84 :
85 0 : using options = tmpl::list<GhCorrection, ScalarCorrection>;
86 :
87 0 : static constexpr Options::String help = {
88 : "Direct product of a GH and CurvedScalarWave boundary correction. "
89 : "See the documentation for the two individual boundary corrections for "
90 : "further details."};
91 :
92 0 : ProductOfCorrections() = default;
93 0 : ProductOfCorrections(DerivedGhCorrection gh_correction,
94 : DerivedScalarCorrection scalar_correction)
95 : : derived_gh_correction_{gh_correction},
96 : derived_scalar_correction_{scalar_correction} {}
97 0 : ProductOfCorrections(const ProductOfCorrections&) = default;
98 0 : ProductOfCorrections& operator=(const ProductOfCorrections&) = default;
99 0 : ProductOfCorrections(ProductOfCorrections&&) = default;
100 0 : ProductOfCorrections& operator=(ProductOfCorrections&&) = default;
101 0 : ~ProductOfCorrections() override = default;
102 :
103 : /// \cond
104 : explicit ProductOfCorrections(CkMigrateMessage* msg)
105 : : BoundaryCorrection(msg) {}
106 : using PUP::able::register_constructor;
107 : WRAPPED_PUPable_decl_template(ProductOfCorrections); // NOLINT
108 : /// \endcond
109 0 : void pup(PUP::er& p) override {
110 : BoundaryCorrection::pup(p);
111 : p | derived_gh_correction_;
112 : p | derived_scalar_correction_;
113 : }
114 :
115 0 : std::unique_ptr<BoundaryCorrection> get_clone() const override {
116 : return std::make_unique<ProductOfCorrections>(*this);
117 : }
118 :
119 0 : double dg_package_data(
120 : // GH packaged fields
121 : const gsl::not_null<tnsr::aa<DataVector, dim, Frame::Inertial>*>
122 : packaged_char_speed_v_spacetime_metric,
123 : const gsl::not_null<tnsr::iaa<DataVector, dim, Frame::Inertial>*>
124 : packaged_char_speed_v_zero,
125 : const gsl::not_null<tnsr::aa<DataVector, dim, Frame::Inertial>*>
126 : packaged_char_speed_v_plus,
127 : const gsl::not_null<tnsr::aa<DataVector, dim, Frame::Inertial>*>
128 : packaged_char_speed_v_minus,
129 : const gsl::not_null<tnsr::iaa<DataVector, dim, Frame::Inertial>*>
130 : packaged_char_speed_n_times_v_plus,
131 : const gsl::not_null<tnsr::iaa<DataVector, dim, Frame::Inertial>*>
132 : packaged_char_speed_n_times_v_minus,
133 : const gsl::not_null<tnsr::aa<DataVector, dim, Frame::Inertial>*>
134 : packaged_char_speed_gamma2_v_spacetime_metric,
135 : const gsl::not_null<tnsr::a<DataVector, dim, Frame::Inertial>*>
136 : packaged_char_speeds,
137 : // Scalar packaged fields
138 : const gsl::not_null<Scalar<DataVector>*> packaged_v_psi_scalar,
139 : const gsl::not_null<tnsr::i<DataVector, dim, Frame::Inertial>*>
140 : packaged_v_zero_scalar,
141 : const gsl::not_null<Scalar<DataVector>*> packaged_v_plus_scalar,
142 : const gsl::not_null<Scalar<DataVector>*> packaged_v_minus_scalar,
143 : const gsl::not_null<Scalar<DataVector>*> packaged_gamma2_scalar,
144 : const gsl::not_null<tnsr::i<DataVector, dim, Frame::Inertial>*>
145 : packaged_interface_unit_normal_scalar,
146 : const gsl::not_null<tnsr::a<DataVector, dim, Frame::Inertial>*>
147 : packaged_char_speeds_scalar,
148 : // GH variables
149 : const tnsr::aa<DataVector, dim, Frame::Inertial>& spacetime_metric,
150 : const tnsr::aa<DataVector, dim, Frame::Inertial>& pi,
151 : const tnsr::iaa<DataVector, dim, Frame::Inertial>& phi,
152 : // Scalar variables
153 : const Scalar<DataVector>& psi_scalar, const Scalar<DataVector>& pi_scalar,
154 : const tnsr::i<DataVector, dim, Frame::Inertial>& phi_scalar,
155 : // GH fluxes
156 : // Scalar fluxes
157 : // GH temporaries
158 : const Scalar<DataVector>& constraint_gamma1,
159 : const Scalar<DataVector>& constraint_gamma2,
160 : const Scalar<DataVector>& lapse,
161 : const tnsr::I<DataVector, dim, Frame::Inertial>& shift,
162 : // Scalar temporaries
163 :
164 : const Scalar<DataVector>& constraint_gamma1_scalar,
165 : const Scalar<DataVector>& constraint_gamma2_scalar,
166 : // Mesh variables
167 : const tnsr::i<DataVector, dim, Frame::Inertial>& normal_covector,
168 : const tnsr::I<DataVector, dim, Frame::Inertial>& normal_vector,
169 : const std::optional<tnsr::I<DataVector, dim, Frame::Inertial>>&
170 : mesh_velocity,
171 : const std::optional<Scalar<DataVector>>& normal_dot_mesh_velocity
172 : // GH volume quantities
173 : // Scalar volume quantities
174 : ) const {
175 : const double gh_correction_result = derived_gh_correction_.dg_package_data(
176 : // GH packaged variables
177 : packaged_char_speed_v_spacetime_metric, packaged_char_speed_v_zero,
178 : packaged_char_speed_v_plus, packaged_char_speed_v_minus,
179 : packaged_char_speed_n_times_v_plus, packaged_char_speed_n_times_v_minus,
180 : packaged_char_speed_gamma2_v_spacetime_metric, packaged_char_speeds,
181 : // GH variables
182 : spacetime_metric, pi, phi,
183 : // GH temporaries
184 : constraint_gamma1, constraint_gamma2, lapse, shift,
185 : // GH mesh variables
186 : normal_covector, normal_vector, mesh_velocity,
187 : normal_dot_mesh_velocity);
188 :
189 : const double scalar_correction_result =
190 : derived_scalar_correction_.dg_package_data(
191 : // Scalar packaged variables
192 : packaged_v_psi_scalar, packaged_v_zero_scalar,
193 : packaged_v_plus_scalar, packaged_v_minus_scalar,
194 : packaged_gamma2_scalar, packaged_interface_unit_normal_scalar,
195 : packaged_char_speeds_scalar,
196 : // Scalar variables
197 : psi_scalar, pi_scalar, phi_scalar,
198 : // Scalar temporaries
199 : lapse, shift, constraint_gamma1_scalar, constraint_gamma2_scalar,
200 : // Scalar mesh variables
201 : normal_covector, normal_vector, mesh_velocity,
202 : normal_dot_mesh_velocity);
203 : return std::max(gh_correction_result, scalar_correction_result);
204 : }
205 :
206 0 : void dg_boundary_terms(
207 : // GH boundary corrections
208 : const gsl::not_null<tnsr::aa<DataVector, dim, Frame::Inertial>*>
209 : boundary_correction_spacetime_metric,
210 : const gsl::not_null<tnsr::aa<DataVector, dim, Frame::Inertial>*>
211 : boundary_correction_pi,
212 : const gsl::not_null<tnsr::iaa<DataVector, dim, Frame::Inertial>*>
213 : boundary_correction_phi,
214 : // Scalar boundary corrections
215 : const gsl::not_null<Scalar<DataVector>*> psi_boundary_correction_scalar,
216 : const gsl::not_null<Scalar<DataVector>*> pi_boundary_correction_scalar,
217 : const gsl::not_null<tnsr::i<DataVector, dim, Frame::Inertial>*>
218 : phi_boundary_correction_scalar,
219 : // GH internal packages field tags
220 : const tnsr::aa<DataVector, dim, Frame::Inertial>&
221 : char_speed_v_spacetime_metric_int,
222 : const tnsr::iaa<DataVector, dim, Frame::Inertial>& char_speed_v_zero_int,
223 : const tnsr::aa<DataVector, dim, Frame::Inertial>& char_speed_v_plus_int,
224 : const tnsr::aa<DataVector, dim, Frame::Inertial>& char_speed_v_minus_int,
225 : const tnsr::iaa<DataVector, dim, Frame::Inertial>&
226 : char_speed_normal_times_v_plus_int,
227 : const tnsr::iaa<DataVector, dim, Frame::Inertial>&
228 : char_speed_normal_times_v_minus_int,
229 : const tnsr::aa<DataVector, dim, Frame::Inertial>&
230 : char_speed_constraint_gamma2_v_spacetime_metric_int,
231 : const tnsr::a<DataVector, dim, Frame::Inertial>& char_speeds_int,
232 : // Scalar internal packaged field tags
233 : const Scalar<DataVector>& v_psi_int_scalar,
234 : const tnsr::i<DataVector, dim, Frame::Inertial>& v_zero_int_scalar,
235 : const Scalar<DataVector>& v_plus_int_scalar,
236 : const Scalar<DataVector>& v_minus_int_scalar,
237 : const Scalar<DataVector>& gamma2_int_scalar,
238 : const tnsr::i<DataVector, dim, Frame::Inertial>&
239 : interface_unit_normal_int_scalar,
240 : const tnsr::a<DataVector, dim, Frame::Inertial>& char_speeds_int_scalar,
241 : // GH external packaged fields
242 : const tnsr::aa<DataVector, dim, Frame::Inertial>&
243 : char_speed_v_spacetime_metric_ext,
244 : const tnsr::iaa<DataVector, dim, Frame::Inertial>& char_speed_v_zero_ext,
245 : const tnsr::aa<DataVector, dim, Frame::Inertial>& char_speed_v_plus_ext,
246 : const tnsr::aa<DataVector, dim, Frame::Inertial>& char_speed_v_minus_ext,
247 : const tnsr::iaa<DataVector, dim, Frame::Inertial>&
248 : char_speed_normal_times_v_plus_ext,
249 : const tnsr::iaa<DataVector, dim, Frame::Inertial>&
250 : char_speed_normal_times_v_minus_ext,
251 : const tnsr::aa<DataVector, dim, Frame::Inertial>&
252 : char_speed_constraint_gamma2_v_spacetime_metric_ext,
253 : const tnsr::a<DataVector, dim, Frame::Inertial>& char_speeds_ext,
254 : // Scalar external packaged fields
255 : const Scalar<DataVector>& v_psi_ext_scalar,
256 : const tnsr::i<DataVector, dim, Frame::Inertial>& v_zero_ext_scalar,
257 : const Scalar<DataVector>& v_plus_ext_scalar,
258 : const Scalar<DataVector>& v_minus_ext_scalar,
259 : const Scalar<DataVector>& gamma2_ext_scalar,
260 : const tnsr::i<DataVector, dim, Frame::Inertial>&
261 : interface_unit_normal_ext_scalar,
262 : const tnsr::a<DataVector, dim, Frame::Inertial>& char_speeds_ext_scalar,
263 : // DG formulation
264 : const dg::Formulation dg_formulation) const {
265 : derived_gh_correction_.dg_boundary_terms(
266 : // GH boundary corrections
267 : boundary_correction_spacetime_metric, boundary_correction_pi,
268 : boundary_correction_phi,
269 : // GH internal packaged fields
270 : char_speed_v_spacetime_metric_int, char_speed_v_zero_int,
271 : char_speed_v_plus_int, char_speed_v_minus_int,
272 : char_speed_normal_times_v_plus_int, char_speed_normal_times_v_minus_int,
273 : char_speed_constraint_gamma2_v_spacetime_metric_int, char_speeds_int,
274 : // GH external packaged fields
275 : char_speed_v_spacetime_metric_ext, char_speed_v_zero_ext,
276 : char_speed_v_plus_ext, char_speed_v_minus_ext,
277 : char_speed_normal_times_v_plus_ext, char_speed_normal_times_v_minus_ext,
278 : char_speed_constraint_gamma2_v_spacetime_metric_ext, char_speeds_ext,
279 : dg_formulation);
280 :
281 : derived_scalar_correction_.dg_boundary_terms(
282 : // Scalar boundary corrections
283 : psi_boundary_correction_scalar, pi_boundary_correction_scalar,
284 : phi_boundary_correction_scalar,
285 : // Scalar internal packaged fields
286 : v_psi_int_scalar, v_zero_int_scalar, v_plus_int_scalar,
287 : v_minus_int_scalar, gamma2_int_scalar, interface_unit_normal_int_scalar,
288 : char_speeds_int_scalar,
289 : // Scalar external packaged fields
290 : v_psi_ext_scalar, v_zero_ext_scalar, v_plus_ext_scalar,
291 : v_minus_ext_scalar, gamma2_ext_scalar, interface_unit_normal_ext_scalar,
292 : char_speeds_ext_scalar, dg_formulation);
293 : }
294 :
295 0 : const DerivedGhCorrection& gh_correction() const {
296 : return derived_gh_correction_;
297 : }
298 :
299 0 : const DerivedScalarCorrection& scalar_correction() const {
300 : return derived_scalar_correction_;
301 : }
302 :
303 : private:
304 0 : DerivedGhCorrection derived_gh_correction_;
305 0 : DerivedScalarCorrection derived_scalar_correction_;
306 : };
307 :
308 : /// \cond
309 : template <typename DerivedGhCorrection, typename DerivedScalarCorrection>
310 : PUP::able::PUP_ID ProductOfCorrections<DerivedGhCorrection,
311 : DerivedScalarCorrection>::my_PUP_ID =
312 : 0; // NOLINT
313 : /// \endcond
314 : } // namespace ScalarTensor::BoundaryCorrections
|