1313#include " DataStructures/Tensor/Tensor.hpp"
1414#include " DataStructures/Variables.hpp"
1515#include " Evolution/Systems/GrMhd/ValenciaDivClean/Tags.hpp"
16+ #include " NumericalAlgorithms/Spectral/Mesh.hpp"
17+ #include " NumericalAlgorithms/Spectral/Quadrature.hpp"
1618#include " PointwiseFunctions/GeneralRelativity/Christoffel.hpp"
1719#include " PointwiseFunctions/GeneralRelativity/Tags.hpp"
20+ #include " PointwiseFunctions/Hydro/ComovingMagneticField.hpp"
1821#include " PointwiseFunctions/Hydro/Tags.hpp"
22+ #include " PointwiseFunctions/Hydro/TransportVelocity.hpp"
1923#include " Utilities/ConstantExpressions.hpp"
2024#include " Utilities/Gsl.hpp"
2125
@@ -65,6 +69,9 @@ struct PressureStar : db::SimpleTag {
6569struct EnthalpyTimesDensityWSquaredPlusBSquared : db::SimpleTag {
6670 using type = Scalar<DataVector>;
6771};
72+ struct ComovingMagneticFieldOneForm : db::SimpleTag {
73+ using type = tnsr::a<DataVector, 3 , Frame::Inertial>;
74+ };
6875} // namespace
6976
7077namespace grmhd ::ValenciaDivClean {
@@ -165,6 +172,97 @@ void sources_impl(
165172 get (*source_tilde_phi) += tilde_b.get (m) * d_lapse.get (m);
166173 }
167174}
175+
176+ void cartoon_sources_impl (
177+ const gsl::not_null<tnsr::i<DataVector, 3 , Frame::Inertial>*>
178+ source_tilde_s,
179+ const gsl::not_null<tnsr::I<DataVector, 3 , Frame::Inertial>*>
180+ source_tilde_b,
181+
182+ const Scalar<DataVector>& pressure_star,
183+ const tnsr::i<DataVector, 3 , Frame::Inertial>& magnetic_field_one_form,
184+ const Scalar<DataVector>& magnetic_field_dot_spatial_velocity,
185+
186+ const tnsr::i<DataVector, 3 , Frame::Inertial>& tilde_s,
187+ const tnsr::I<DataVector, 3 , Frame::Inertial>& tilde_b,
188+ const Scalar<DataVector>& tilde_phi,
189+ const tnsr::I<DataVector, 3 , Frame::Inertial>& spatial_velocity,
190+ const Scalar<DataVector>& lorentz_factor, const Scalar<DataVector>& lapse,
191+ const tnsr::I<DataVector, 3 , Frame::Inertial>& shift,
192+ const tnsr::ii<DataVector, 3 , Frame::Inertial>& spatial_metric,
193+ const tnsr::II<DataVector, 3 , Frame::Inertial>& inv_spatial_metric,
194+ const Scalar<DataVector>& sqrt_det_spatial_metric,
195+ const tnsr::I<DataVector, 3 , Frame::Inertial>& inertial_coords,
196+ const Spectral::Quadrature cartoon_quadrature) {
197+ #ifdef SPECTRE_DEBUG
198+ for (size_t i = 0 ; i < get<0 >(inertial_coords).size (); ++i) {
199+ ASSERT (not equal_within_roundoff (
200+ 0.0 , get<0 >(inertial_coords)[i],
201+ std::numeric_limits<double >::epsilon () * 100.0 ,
202+ max (get<0 >(inertial_coords))),
203+ " Computing cartoon source terms with x=0 in domain, got "
204+ " inertial_coords = "
205+ << inertial_coords);
206+ }
207+ #endif // SPECTRE_DEBUG
208+ if (cartoon_quadrature == Spectral::Quadrature::SphericalSymmetry) {
209+ get<0 >(*source_tilde_s) += 2.0 * get (lapse) * get (sqrt_det_spatial_metric) *
210+ get (pressure_star) / get<0 >(inertial_coords);
211+ get<0 >(*source_tilde_b) +=
212+ get (lapse) *
213+ (get<1 , 1 >(inv_spatial_metric) + get<2 , 2 >(inv_spatial_metric)) *
214+ get (tilde_phi) / get<0 >(inertial_coords);
215+ } else {
216+ ASSERT (
217+ cartoon_quadrature == Spectral::Quadrature::AxialSymmetry,
218+ " Got unexpected quadrature for Cartoon basis: " << cartoon_quadrature);
219+
220+ Variables<tmpl::list<hydro::Tags::SpatialVelocityOneForm<DataVector, 3 >,
221+ ComovingMagneticFieldOneForm,
222+ hydro::Tags::TransportVelocity<DataVector, 3 >>>
223+ temp_tensors (get<0 >(inertial_coords).size ());
224+
225+ auto & spatial_velocity_one_form =
226+ get<hydro::Tags::SpatialVelocityOneForm<DataVector, 3 >>(temp_tensors);
227+ raise_or_lower_index (make_not_null (&spatial_velocity_one_form),
228+ spatial_velocity, spatial_metric);
229+
230+ auto & comoving_magnetic_field_one_form =
231+ get<ComovingMagneticFieldOneForm>(temp_tensors);
232+ hydro::comoving_magnetic_field_one_form (
233+ make_not_null (&comoving_magnetic_field_one_form),
234+ spatial_velocity_one_form, magnetic_field_one_form,
235+ magnetic_field_dot_spatial_velocity, lorentz_factor, shift, lapse);
236+
237+ auto & transport_velocity =
238+ get<hydro::Tags::TransportVelocity<DataVector, 3 >>(temp_tensors);
239+ hydro::transport_velocity (make_not_null (&transport_velocity),
240+ spatial_velocity, lapse, shift);
241+
242+ get<0 >(*source_tilde_s) +=
243+ (get (lapse) * get (sqrt_det_spatial_metric) * get (pressure_star) +
244+ get (lapse) * get<2 >(tilde_b) *
245+ (-get<3 >(comoving_magnetic_field_one_form)) / get (lorentz_factor) +
246+ (get<2 >(tilde_s)) * get<2 >(transport_velocity)) /
247+ get<0 >(inertial_coords);
248+ get<2 >(*source_tilde_s) +=
249+ (get (lapse) * get<2 >(tilde_b) *
250+ (get<1 >(comoving_magnetic_field_one_form)) / get (lorentz_factor) +
251+ (-get<0 >(tilde_s)) * get<2 >(transport_velocity)) /
252+ get<0 >(inertial_coords);
253+
254+ get<0 >(*source_tilde_b) +=
255+ (get (lapse) * (get<2 , 2 >(inv_spatial_metric)) * get (tilde_phi) +
256+ get (lapse) * (-get<2 >(spatial_velocity)) * get<2 >(tilde_b) +
257+ (get<2 >(tilde_b)) * get<2 >(transport_velocity)) /
258+ get<0 >(inertial_coords);
259+ get<2 >(*source_tilde_b) +=
260+ (get (lapse) * (-get<2 , 0 >(inv_spatial_metric)) * get (tilde_phi) +
261+ get (lapse) * (get<0 >(spatial_velocity)) * get<2 >(tilde_b) +
262+ (-get<0 >(tilde_b)) * get<2 >(transport_velocity)) /
263+ get<0 >(inertial_coords);
264+ }
265+ }
168266} // namespace detail
169267
170268void ComputeSources::apply (
@@ -186,14 +284,17 @@ void ComputeSources::apply(
186284 const Scalar<DataVector>& specific_internal_energy,
187285 const Scalar<DataVector>& lorentz_factor,
188286 const Scalar<DataVector>& pressure, const Scalar<DataVector>& lapse,
287+ const tnsr::I<DataVector, 3 , Frame::Inertial>& shift,
189288 const tnsr::i<DataVector, 3 , Frame::Inertial>& d_lapse,
190289 const tnsr::iJ<DataVector, 3 , Frame::Inertial>& d_shift,
191290 const tnsr::ii<DataVector, 3 , Frame::Inertial>& spatial_metric,
192291 const tnsr::ijj<DataVector, 3 , Frame::Inertial>& d_spatial_metric,
193292 const tnsr::II<DataVector, 3 , Frame::Inertial>& inv_spatial_metric,
194293 const Scalar<DataVector>& sqrt_det_spatial_metric,
195294 const tnsr::ii<DataVector, 3 , Frame::Inertial>& extrinsic_curvature,
196- const double constraint_damping_parameter) {
295+ const double constraint_damping_parameter,
296+ const tnsr::I<DataVector, 3 , Frame::Inertial>& inertial_coords,
297+ const Mesh<3 >& dg_mesh) {
197298 Variables<
198299 tmpl::list<TildeSUp, DensitizedStress, MagneticFieldOneForm,
199300 hydro::Tags::MagneticFieldDotSpatialVelocity<DataVector>,
@@ -260,5 +361,14 @@ void ComputeSources::apply(
260361
261362 rest_mass_density, electron_fraction, pressure, specific_internal_energy,
262363 extrinsic_curvature, constraint_damping_parameter);
364+
365+ if (dg_mesh.basis (2 ) == Spectral::Basis::Cartoon) {
366+ detail::cartoon_sources_impl (
367+ source_tilde_s, source_tilde_b, pressure_star, magnetic_field_oneform,
368+ magnetic_field_dot_spatial_velocity, tilde_s, tilde_b, tilde_phi,
369+ spatial_velocity, lorentz_factor, lapse, shift, spatial_metric,
370+ inv_spatial_metric, sqrt_det_spatial_metric, inertial_coords,
371+ dg_mesh.quadrature (2 ));
372+ }
263373}
264374} // namespace grmhd::ValenciaDivClean
0 commit comments