SpECTRE Documentation Coverage Report
Current view: top level - Evolution/Systems/GrMhd/ValenciaDivClean/Subcell - TimeDerivative.hpp Hit Total Coverage
Commit: 923cd4a8ea30f5a5589baa60b0a93e358ca9f8e8 Lines: 1 4 25.0 %
Date: 2025-11-07 19:37:56
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #pragma once
       5             : 
       6             : #include <array>
       7             : #include <cstddef>
       8             : #include <cstdint>
       9             : #include <optional>
      10             : #include <type_traits>
      11             : 
      12             : #include "DataStructures/DataBox/AsAccess.hpp"
      13             : #include "DataStructures/DataBox/DataBox.hpp"
      14             : #include "DataStructures/DataBox/MetavariablesTag.hpp"
      15             : #include "DataStructures/DataBox/PrefixHelpers.hpp"
      16             : #include "DataStructures/DataBox/Prefixes.hpp"
      17             : #include "DataStructures/DataVector.hpp"
      18             : #include "DataStructures/TaggedContainers.hpp"
      19             : #include "DataStructures/Tensor/Tensor.hpp"
      20             : #include "DataStructures/Variables.hpp"
      21             : #include "Domain/Structure/Element.hpp"
      22             : #include "Domain/Tags.hpp"
      23             : #include "Evolution/BoundaryCorrection.hpp"
      24             : #include "Evolution/BoundaryCorrectionTags.hpp"
      25             : #include "Evolution/DgSubcell/CartesianFluxDivergence.hpp"
      26             : #include "Evolution/DgSubcell/ComputeBoundaryTerms.hpp"
      27             : #include "Evolution/DgSubcell/CorrectPackagedData.hpp"
      28             : #include "Evolution/DgSubcell/Projection.hpp"
      29             : #include "Evolution/DgSubcell/ReconstructionOrder.hpp"
      30             : #include "Evolution/DgSubcell/SubcellOptions.hpp"
      31             : #include "Evolution/DgSubcell/Tags/CellCenteredFlux.hpp"
      32             : #include "Evolution/DgSubcell/Tags/Coordinates.hpp"
      33             : #include "Evolution/DgSubcell/Tags/Jacobians.hpp"
      34             : #include "Evolution/DgSubcell/Tags/Mesh.hpp"
      35             : #include "Evolution/DgSubcell/Tags/OnSubcellFaces.hpp"
      36             : #include "Evolution/DgSubcell/Tags/SubcellOptions.hpp"
      37             : #include "Evolution/DiscontinuousGalerkin/Actions/NormalCovectorAndMagnitude.hpp"
      38             : #include "Evolution/DiscontinuousGalerkin/Actions/PackageDataImpl.hpp"
      39             : #include "Evolution/DiscontinuousGalerkin/MortarTags.hpp"
      40             : #include "Evolution/Systems/GrMhd/ValenciaDivClean/FiniteDifference/BoundaryConditionGhostData.hpp"
      41             : #include "Evolution/Systems/GrMhd/ValenciaDivClean/FiniteDifference/Reconstructor.hpp"
      42             : #include "Evolution/Systems/GrMhd/ValenciaDivClean/FiniteDifference/Tag.hpp"
      43             : #include "Evolution/Systems/GrMhd/ValenciaDivClean/Fluxes.hpp"
      44             : #include "Evolution/Systems/GrMhd/ValenciaDivClean/Sources.hpp"
      45             : #include "Evolution/Systems/GrMhd/ValenciaDivClean/Subcell/ComputeFluxes.hpp"
      46             : #include "Evolution/Systems/GrMhd/ValenciaDivClean/System.hpp"
      47             : #include "NumericalAlgorithms/FiniteDifference/DerivativeOrder.hpp"
      48             : #include "NumericalAlgorithms/FiniteDifference/HighOrderFluxCorrection.hpp"
      49             : #include "NumericalAlgorithms/Spectral/Mesh.hpp"
      50             : #include "PointwiseFunctions/Hydro/Tags.hpp"
      51             : #include "Utilities/CallWithDynamicType.hpp"
      52             : #include "Utilities/ErrorHandling/Assert.hpp"
      53             : #include "Utilities/Gsl.hpp"
      54             : #include "Utilities/TMPL.hpp"
      55             : 
      56             : namespace grmhd::ValenciaDivClean::subcell {
      57             : /*!
      58             :  * \brief Compute the time derivative on the subcell grid using FD
      59             :  * reconstruction.
      60             :  */
      61           1 : struct TimeDerivative {
      62             :   template <typename DbTagsList>
      63           0 :   static void apply(const gsl::not_null<db::DataBox<DbTagsList>*> box) {
      64             :     using metavariables =
      65             :         typename std::decay_t<decltype(db::get<Parallel::Tags::Metavariables>(
      66             :             *box))>;
      67             :     using evolved_vars_tag = typename System::variables_tag;
      68             :     using evolved_vars_tags = typename evolved_vars_tag::tags_list;
      69             :     using prim_tags = typename System::primitive_variables_tag::tags_list;
      70             :     using recons_prim_tags = tmpl::push_back<
      71             :         prim_tags,
      72             :         hydro::Tags::LorentzFactorTimesSpatialVelocity<DataVector, 3>>;
      73             :     using fluxes_tags = db::wrap_tags_in<::Tags::Flux, evolved_vars_tags,
      74             :                                          tmpl::size_t<3>, Frame::Inertial>;
      75             : 
      76             :     ASSERT(
      77             :         (db::get<::domain::CoordinateMaps::Tags::CoordinateMap<
      78             :              3, Frame::Grid, Frame::Inertial>>(*box))
      79             :             .is_identity(),
      80             :         "Moving mesh is only partly implemented in ValenciaDivClean. If you "
      81             :         "need this look at the complete implementation in GhValenciaDivClean. "
      82             :         "You will at least need to update the high-order boundary correction "
      83             :         "code to include the right normal vectors/Jacobians.");
      84             : 
      85             :     const Mesh<3>& subcell_mesh =
      86             :         db::get<evolution::dg::subcell::Tags::Mesh<3>>(*box);
      87             :     const Mesh<3>& dg_mesh = db::get<domain::Tags::Mesh<3>>(*box);
      88             :     ASSERT(
      89             :         is_isotropic(subcell_mesh),
      90             :         "The subcell/FD mesh must be isotropic for the FD time derivative but "
      91             :         "got "
      92             :             << subcell_mesh);
      93             :     const size_t reconstructed_num_pts =
      94             :         (subcell_mesh.extents(0) + 1) *
      95             :         subcell_mesh.extents().slice_away(0).product();
      96             : 
      97             :     const tnsr::I<DataVector, 3, Frame::ElementLogical>&
      98             :         cell_centered_logical_coords =
      99             :             db::get<evolution::dg::subcell::Tags::Coordinates<
     100             :                 3, Frame::ElementLogical>>(*box);
     101             :     std::array<double, 3> one_over_delta_xi{};
     102             :     for (size_t i = 0; i < 3; ++i) {
     103             :       // Note: assumes isotropic extents
     104             :       gsl::at(one_over_delta_xi, i) =
     105             :           1.0 / (get<0>(cell_centered_logical_coords)[1] -
     106             :                  get<0>(cell_centered_logical_coords)[0]);
     107             :     }
     108             : 
     109             :     // Inverse jacobian, to be projected on faces
     110             :     const auto& inv_jacobian_dg =
     111             :         db::get<domain::Tags::InverseJacobian<3, Frame::ElementLogical,
     112             :                                               Frame::Inertial>>(*box);
     113             :     const auto& det_inv_jacobian_dg = db::get<
     114             :         domain::Tags::DetInvJacobian<Frame::ElementLogical, Frame::Inertial>>(
     115             :         *box);
     116             : 
     117             :     // Velocity of the moving mesh on the DG grid, if applicable.
     118             :     const std::optional<tnsr::I<DataVector, 3, Frame::Inertial>>&
     119             :         mesh_velocity_dg = db::get<domain::Tags::MeshVelocity<3>>(*box);
     120             :     const std::optional<Scalar<DataVector>>& div_mesh_velocity =
     121             :         db::get<domain::Tags::DivMeshVelocity>(*box);
     122             : 
     123             :     const grmhd::ValenciaDivClean::fd::Reconstructor& recons =
     124             :         db::get<grmhd::ValenciaDivClean::fd::Tags::Reconstructor>(*box);
     125             : 
     126             :     const Element<3>& element = db::get<domain::Tags::Element<3>>(*box);
     127             :     const auto fd_derivative_order =
     128             :         db::get<evolution::dg::subcell::Tags::SubcellOptions<3>>(*box)
     129             :             .finite_difference_derivative_order();
     130             :     std::optional<std::array<std::vector<std::uint8_t>, 3>>
     131             :         reconstruction_order_data{};
     132             :     std::optional<std::array<gsl::span<std::uint8_t>, 3>>
     133             :         reconstruction_order{};
     134             :     if (static_cast<int>(fd_derivative_order) < 0) {
     135             :       reconstruction_order_data = make_array<3>(std::vector<std::uint8_t>(
     136             :           (subcell_mesh.extents(0) + 2) * subcell_mesh.extents(1) *
     137             :               subcell_mesh.extents(2),
     138             :           std::numeric_limits<std::uint8_t>::max()));
     139             :       reconstruction_order = std::array<gsl::span<std::uint8_t>, 3>{};
     140             :       for (size_t i = 0; i < 3; ++i) {
     141             :         gsl::at(reconstruction_order.value(), i) = gsl::make_span(
     142             :             gsl::at(reconstruction_order_data.value(), i).data(),
     143             :             gsl::at(reconstruction_order_data.value(), i).size());
     144             :       }
     145             :     }
     146             : 
     147             :     const bool element_is_interior = element.external_boundaries().empty();
     148             :     constexpr bool subcell_enabled_at_external_boundary =
     149             :         metavariables::SubcellOptions::subcell_enabled_at_external_boundary;
     150             : 
     151             :     ASSERT(element_is_interior or subcell_enabled_at_external_boundary,
     152             :            "Subcell time derivative is called at a boundary element while "
     153             :            "using subcell is disabled at external boundaries."
     154             :            "ElementID "
     155             :                << element.id());
     156             : 
     157             :     // Now package the data and compute the correction
     158             :     const auto& boundary_correction =
     159             :         db::get<evolution::Tags::BoundaryCorrection>(*box);
     160             :     using derived_boundary_corrections =
     161             :         tmpl::at<typename metavariables::factory_creation::factory_classes,
     162             :                  evolution::BoundaryCorrection>;
     163             :     std::array<Variables<evolved_vars_tags>, 3> boundary_corrections{};
     164             : 
     165             :     // If the element has external boundaries and subcell is enabled for
     166             :     // boundary elements, compute FD ghost data with a given boundary condition.
     167             :     if constexpr (subcell_enabled_at_external_boundary) {
     168             :       if (not element.external_boundaries().empty()) {
     169             :         fd::BoundaryConditionGhostData::apply(box, element, recons);
     170             :       }
     171             :     }
     172             : 
     173             :     call_with_dynamic_type<void, derived_boundary_corrections>(
     174             :         &boundary_correction, [&](const auto* derived_correction) {
     175             :           using DerivedCorrection = std::decay_t<decltype(*derived_correction)>;
     176             :           using dg_package_data_temporary_tags =
     177             :               typename DerivedCorrection::dg_package_data_temporary_tags;
     178             :           using dg_package_data_argument_tags = tmpl::append<
     179             :               evolved_vars_tags, recons_prim_tags, fluxes_tags,
     180             :               tmpl::remove_duplicates<tmpl::push_back<
     181             :                   dg_package_data_temporary_tags,
     182             :                   gr::Tags::SpatialMetric<DataVector, 3>,
     183             :                   gr::Tags::SqrtDetSpatialMetric<DataVector>,
     184             :                   gr::Tags::InverseSpatialMetric<DataVector, 3>,
     185             :                   evolution::dg::Actions::detail::NormalVector<3>>>>;
     186             :           // Computed prims and cons on face via reconstruction
     187             :           auto package_data_argvars_lower_face = make_array<3>(
     188             :               Variables<dg_package_data_argument_tags>(reconstructed_num_pts));
     189             :           auto package_data_argvars_upper_face = make_array<3>(
     190             :               Variables<dg_package_data_argument_tags>(reconstructed_num_pts));
     191             :           // Copy over the face values of the metric quantities.
     192             :           using spacetime_vars_to_copy =
     193             :               tmpl::list<gr::Tags::Lapse<DataVector>,
     194             :                          gr::Tags::Shift<DataVector, 3>,
     195             :                          gr::Tags::SpatialMetric<DataVector, 3>,
     196             :                          gr::Tags::SqrtDetSpatialMetric<DataVector>,
     197             :                          gr::Tags::InverseSpatialMetric<DataVector, 3>>;
     198             :           tmpl::for_each<spacetime_vars_to_copy>(
     199             :               [&package_data_argvars_lower_face,
     200             :                &package_data_argvars_upper_face,
     201             :                &spacetime_vars_on_face =
     202             :                    db::get<evolution::dg::subcell::Tags::OnSubcellFaces<
     203             :                        typename System::flux_spacetime_variables_tag, 3>>(
     204             :                        *box)](auto tag_v) {
     205             :                 using tag = tmpl::type_from<decltype(tag_v)>;
     206             :                 for (size_t d = 0; d < 3; ++d) {
     207             :                   get<tag>(gsl::at(package_data_argvars_lower_face, d)) =
     208             :                       get<tag>(gsl::at(spacetime_vars_on_face, d));
     209             :                   get<tag>(gsl::at(package_data_argvars_upper_face, d)) =
     210             :                       get<tag>(gsl::at(spacetime_vars_on_face, d));
     211             :                 }
     212             :               });
     213             : 
     214             :           // Reconstruct data to the face
     215             :           call_with_dynamic_type<void, typename grmhd::ValenciaDivClean::fd::
     216             :                                            Reconstructor::creatable_classes>(
     217             :               &recons, [&box, &package_data_argvars_lower_face,
     218             :                         &package_data_argvars_upper_face,
     219             :                         &reconstruction_order](const auto& reconstructor) {
     220             :                 using ReconstructorType =
     221             :                     std::decay_t<decltype(*reconstructor)>;
     222             :                 db::apply<
     223             :                     typename ReconstructorType::reconstruction_argument_tags>(
     224             :                     [&package_data_argvars_lower_face,
     225             :                      &package_data_argvars_upper_face, &reconstructor,
     226             :                      &reconstruction_order](const auto&... args) {
     227             :                       if constexpr (ReconstructorType::use_adaptive_order) {
     228             :                         reconstructor->reconstruct(
     229             :                             make_not_null(&package_data_argvars_lower_face),
     230             :                             make_not_null(&package_data_argvars_upper_face),
     231             :                             make_not_null(&reconstruction_order), args...);
     232             :                       } else {
     233             :                         (void)reconstruction_order;
     234             :                         reconstructor->reconstruct(
     235             :                             make_not_null(&package_data_argvars_lower_face),
     236             :                             make_not_null(&package_data_argvars_upper_face),
     237             :                             args...);
     238             :                       }
     239             :                     },
     240             :                     *box);
     241             :               });
     242             : 
     243             :           using dg_package_field_tags =
     244             :               typename DerivedCorrection::dg_package_field_tags;
     245             :           // Allocated outside for loop to reduce allocations
     246             :           Variables<dg_package_field_tags> upper_packaged_data{
     247             :               reconstructed_num_pts};
     248             :           Variables<dg_package_field_tags> lower_packaged_data{
     249             :               reconstructed_num_pts};
     250             : 
     251             :           // Compute fluxes on faces
     252             :           for (size_t i = 0; i < 3; ++i) {
     253             :             // Build extents of mesh shifted by half a grid cell in direction i
     254             :             const unsigned long& num_subcells_1d = subcell_mesh.extents(0);
     255             :             Index<3> face_mesh_extents(std::array<size_t, 3>{
     256             :                 num_subcells_1d, num_subcells_1d, num_subcells_1d});
     257             :             face_mesh_extents[i] = num_subcells_1d + 1;
     258             : 
     259             :             auto& vars_upper_face = gsl::at(package_data_argvars_upper_face, i);
     260             :             auto& vars_lower_face = gsl::at(package_data_argvars_lower_face, i);
     261             :             grmhd::ValenciaDivClean::subcell::compute_fluxes(
     262             :                 make_not_null(&vars_upper_face));
     263             :             grmhd::ValenciaDivClean::subcell::compute_fluxes(
     264             :                 make_not_null(&vars_lower_face));
     265             : 
     266             :             // Add moving mesh corrections to the fluxes, if needed
     267             :             std::optional<tnsr::I<DataVector, 3, Frame::Inertial>>
     268             :                 mesh_velocity_on_face = {};
     269             :             if (mesh_velocity_dg.has_value()) {
     270             :               // Project mesh velocity on face mesh.
     271             :               // Can we get away with only doing the normal component? It
     272             :               // is also used in the packaged data...
     273             :               mesh_velocity_on_face = tnsr::I<DataVector, 3, Frame::Inertial>{
     274             :                   reconstructed_num_pts};
     275             :               for (size_t j = 0; j < 3; j++) {
     276             :                 // j^th component of the velocity on the i^th directed face
     277             :                 mesh_velocity_on_face.value().get(j) =
     278             :                     evolution::dg::subcell::fd::project_to_faces(
     279             :                         mesh_velocity_dg.value().get(j), dg_mesh,
     280             :                         face_mesh_extents, i);
     281             :               }
     282             :               tmpl::for_each<evolved_vars_tags>([&vars_upper_face,
     283             :                                                  &vars_lower_face,
     284             :                                                  &mesh_velocity_on_face](
     285             :                                                     auto tag_v) {
     286             :                 using tag = tmpl::type_from<decltype(tag_v)>;
     287             :                 using flux_tag =
     288             :                     ::Tags::Flux<tag, tmpl::size_t<3>, Frame::Inertial>;
     289             :                 using FluxTensor = typename flux_tag::type;
     290             :                 const auto& var_upper = get<tag>(vars_upper_face);
     291             :                 const auto& var_lower = get<tag>(vars_lower_face);
     292             :                 auto& flux_upper = get<flux_tag>(vars_upper_face);
     293             :                 auto& flux_lower = get<flux_tag>(vars_lower_face);
     294             :                 for (size_t storage_index = 0; storage_index < var_upper.size();
     295             :                      ++storage_index) {
     296             :                   const auto tensor_index =
     297             :                       var_upper.get_tensor_index(storage_index);
     298             :                   for (size_t j = 0; j < 3; j++) {
     299             :                     const auto flux_storage_index =
     300             :                         FluxTensor::get_storage_index(prepend(tensor_index, j));
     301             :                     flux_upper[flux_storage_index] -=
     302             :                         mesh_velocity_on_face.value().get(j) *
     303             :                         var_upper[storage_index];
     304             :                     flux_lower[flux_storage_index] -=
     305             :                         mesh_velocity_on_face.value().get(j) *
     306             :                         var_lower[storage_index];
     307             :                   }
     308             :                 }
     309             :               });
     310             :             }
     311             : 
     312             :             // Normal vectors in curved spacetime normalized by inverse
     313             :             // spatial metric. Note that we use the sign convention on
     314             :             // the normal vectors to be compatible with DG.
     315             :             //
     316             :             // Note that these normal vectors are on all faces inside the DG
     317             :             // element since there are a bunch of subcells. We don't use the
     318             :             // NormalCovectorAndMagnitude tag in the DataBox right now to avoid
     319             :             // conflicts with the DG solver. We can explore in the future if
     320             :             // it's possible to reuse that allocation.
     321             :             //
     322             :             // The unnormalized normal vector is
     323             :             // n_j = d \xi^{\hat i}/dx^j
     324             :             // with "i" the current face.
     325             :             tnsr::i<DataVector, 3, Frame::Inertial> lower_outward_conormal{
     326             :                 reconstructed_num_pts, 0.0};
     327             :             for (size_t j = 0; j < 3; j++) {
     328             :               lower_outward_conormal.get(j) =
     329             :                   evolution::dg::subcell::fd::project_to_faces(
     330             :                       inv_jacobian_dg.get(i, j), dg_mesh, face_mesh_extents, i);
     331             :             }
     332             :             const auto det_inv_jacobian_face =
     333             :                 evolution::dg::subcell::fd::project_to_faces(
     334             :                     get(det_inv_jacobian_dg), dg_mesh, face_mesh_extents, i);
     335             : 
     336             :             const Scalar<DataVector> normalization{sqrt(get(
     337             :                 dot_product(lower_outward_conormal, lower_outward_conormal,
     338             :                             get<gr::Tags::InverseSpatialMetric<DataVector, 3>>(
     339             :                                 vars_upper_face))))};
     340             :             for (size_t j = 0; j < 3; j++) {
     341             :               lower_outward_conormal.get(j) =
     342             :                   lower_outward_conormal.get(j) / get(normalization);
     343             :             }
     344             : 
     345             :             tnsr::i<DataVector, 3, Frame::Inertial> upper_outward_conormal{
     346             :                 reconstructed_num_pts, 0.0};
     347             :             for (size_t j = 0; j < 3; j++) {
     348             :               upper_outward_conormal.get(j) = -lower_outward_conormal.get(j);
     349             :             }
     350             :             // Note: we probably should compute the normal vector in addition to
     351             :             // the co-vector. Not a huge issue since we'll get an FPE right now
     352             :             // if it's used by a Riemann solver.
     353             : 
     354             :             // Compute the packaged data
     355             :             using dg_package_data_projected_tags = tmpl::append<
     356             :                 evolved_vars_tags, fluxes_tags, dg_package_data_temporary_tags,
     357             :                 typename DerivedCorrection::dg_package_data_primitive_tags>;
     358             :             evolution::dg::Actions::detail::dg_package_data<System>(
     359             :                 make_not_null(&upper_packaged_data), *derived_correction,
     360             :                 vars_upper_face, upper_outward_conormal, mesh_velocity_on_face,
     361             :                 *box, typename DerivedCorrection::dg_package_data_volume_tags{},
     362             :                 dg_package_data_projected_tags{});
     363             : 
     364             :             evolution::dg::Actions::detail::dg_package_data<System>(
     365             :                 make_not_null(&lower_packaged_data), *derived_correction,
     366             :                 vars_lower_face, lower_outward_conormal, mesh_velocity_on_face,
     367             :                 *box, typename DerivedCorrection::dg_package_data_volume_tags{},
     368             :                 dg_package_data_projected_tags{});
     369             : 
     370             :             // Now need to check if any of our neighbors are doing DG,
     371             :             // because if so then we need to use whatever boundary data
     372             :             // they sent instead of what we computed locally.
     373             :             //
     374             :             // Note: We could check this beforehand to avoid the extra
     375             :             // work of reconstruction and flux computations at the
     376             :             // boundaries.
     377             :             evolution::dg::subcell::correct_package_data<true>(
     378             :                 make_not_null(&lower_packaged_data),
     379             :                 make_not_null(&upper_packaged_data), i, element, subcell_mesh,
     380             :                 db::get<evolution::dg::Tags::MortarData<3>>(*box), 0);
     381             : 
     382             :             // Compute the corrections on the faces. We only need to
     383             :             // compute this once because we can just flip the normal
     384             :             // vectors then
     385             :             gsl::at(boundary_corrections, i).initialize(reconstructed_num_pts);
     386             :             evolution::dg::subcell::compute_boundary_terms(
     387             :                 make_not_null(&gsl::at(boundary_corrections, i)),
     388             :                 *derived_correction, upper_packaged_data, lower_packaged_data,
     389             :                 db::as_access(*box),
     390             :                 typename DerivedCorrection::dg_boundary_terms_volume_tags{});
     391             :             // We need to multiply by the normal vector normalization
     392             :             gsl::at(boundary_corrections, i) *= get(normalization);
     393             :             // Also multiply by determinant of Jacobian, following Eq.(34)
     394             :             // of 2109.11645
     395             :             gsl::at(boundary_corrections, i) *= 1.0 / det_inv_jacobian_face;
     396             :           }
     397             :         });
     398             : 
     399             :     // Now compute the actual time derivatives.
     400             :     using variables_tag = typename System::variables_tag;
     401             :     using dt_variables_tag = db::add_tag_prefix<::Tags::dt, variables_tag>;
     402             :     const gsl::not_null<typename dt_variables_tag::type*> dt_vars_ptr =
     403             :         db::mutate<dt_variables_tag>(
     404             :             [](const auto local_dt_vars_ptr) { return local_dt_vars_ptr; },
     405             :             box);
     406             :     dt_vars_ptr->initialize(subcell_mesh.number_of_grid_points());
     407             : 
     408             :     using grmhd_source_tags =
     409             :         tmpl::transform<ValenciaDivClean::ComputeSources::return_tags,
     410             :                         tmpl::bind<db::remove_tag_prefix, tmpl::_1>>;
     411             :     sources_impl(
     412             :         dt_vars_ptr, *box, grmhd_source_tags{},
     413             :         typename grmhd::ValenciaDivClean::ComputeSources::argument_tags{});
     414             : 
     415             :     // Zero GRMHD tags that don't have sources.
     416             :     tmpl::for_each<typename variables_tag::tags_list>(
     417             :         [&dt_vars_ptr](auto evolved_var_tag_v) {
     418             :           using evolved_var_tag = tmpl::type_from<decltype(evolved_var_tag_v)>;
     419             :           using dt_tag = ::Tags::dt<evolved_var_tag>;
     420             :           auto& dt_var = get<dt_tag>(*dt_vars_ptr);
     421             :           for (size_t i = 0; i < dt_var.size(); ++i) {
     422             :             if constexpr (not tmpl::list_contains_v<grmhd_source_tags,
     423             :                                                     evolved_var_tag>) {
     424             :               dt_var[i] = 0.0;
     425             :             }
     426             :           }
     427             :         });
     428             : 
     429             :     // Correction to source terms due to moving mesh
     430             :     if (div_mesh_velocity.has_value()) {
     431             :       const DataVector div_mesh_velocity_subcell =
     432             :           evolution::dg::subcell::fd::project(div_mesh_velocity.value().get(),
     433             :                                               dg_mesh, subcell_mesh.extents());
     434             :       const auto& evolved_vars = db::get<evolved_vars_tag>(*box);
     435             : 
     436             :       tmpl::for_each<typename variables_tag::tags_list>(
     437             :           [&dt_vars_ptr, &div_mesh_velocity_subcell,
     438             :            &evolved_vars](auto evolved_var_tag_v) {
     439             :             using evolved_var_tag =
     440             :                 tmpl::type_from<decltype(evolved_var_tag_v)>;
     441             :             using dt_tag = ::Tags::dt<evolved_var_tag>;
     442             :             auto& dt_var = get<dt_tag>(*dt_vars_ptr);
     443             :             const auto& evolved_var = get<evolved_var_tag>(evolved_vars);
     444             :             for (size_t i = 0; i < dt_var.size(); ++i) {
     445             :               dt_var[i] -= div_mesh_velocity_subcell * evolved_var[i];
     446             :             }
     447             :           });
     448             :     }
     449             : 
     450             :     if (UNLIKELY(fd_derivative_order != ::fd::DerivativeOrder::Two)) {
     451             :       ERROR(
     452             :           "We don't yet have high-order flux corrections for curved/moving "
     453             :           "meshes and the implementation assumes curved/moving meshes. We need "
     454             :           "to dot the Cartesian fluxes into the cell-centered "
     455             :           "J inv(J)^{hat{i}}_j to get JF^{hat{i}} = J inv(J)^{hat{i}}_j F^j."
     456             :           " Some care needs to be taken since we also get F^j from our "
     457             :           "neighbors, which leaves the question as to whether to interpolate "
     458             :           "the _inertial fluxes_ and then transform or whether to transform "
     459             :           "and then interpolate the _densitized logical fluxes_.");
     460             :     }
     461             :     std::optional<std::array<Variables<evolved_vars_tags>, 3>>
     462             :         high_order_corrections{};
     463             :     ::fd::cartesian_high_order_flux_corrections(
     464             :         make_not_null(&high_order_corrections),
     465             : 
     466             :         db::get<evolution::dg::subcell::Tags::CellCenteredFlux<
     467             :             evolved_vars_tags, 3>>(*box),
     468             :         boundary_corrections, fd_derivative_order,
     469             :         db::get<evolution::dg::subcell::Tags::GhostDataForReconstruction<3>>(
     470             :             *box),
     471             :         subcell_mesh, recons.ghost_zone_size(),
     472             :         reconstruction_order.value_or(
     473             :             std::array<gsl::span<std::uint8_t>, 3>{}));
     474             : 
     475             :     const auto& cell_centered_det_inv_jacobian = db::get<
     476             :         evolution::dg::subcell::fd::Tags::DetInverseJacobianLogicalToInertial>(
     477             :         *box);
     478             :     for (size_t dim = 0; dim < 3; ++dim) {
     479             :       const auto& boundary_correction_in_axis =
     480             :           high_order_corrections.has_value()
     481             :               ? gsl::at(high_order_corrections.value(), dim)
     482             :               : gsl::at(boundary_corrections, dim);
     483             :       const double inverse_delta = gsl::at(one_over_delta_xi, dim);
     484             :       tmpl::for_each<typename variables_tag::tags_list>(
     485             :           [&dt_vars_ptr, &boundary_correction_in_axis,
     486             :            &cell_centered_det_inv_jacobian, dim, inverse_delta,
     487             :            &subcell_mesh](auto evolved_var_tag_v) {
     488             :             using evolved_var_tag =
     489             :                 tmpl::type_from<decltype(evolved_var_tag_v)>;
     490             :             using dt_tag = ::Tags::dt<evolved_var_tag>;
     491             :             auto& dt_var = get<dt_tag>(*dt_vars_ptr);
     492             :             const auto& var_correction =
     493             :                 get<evolved_var_tag>(boundary_correction_in_axis);
     494             :             for (size_t i = 0; i < dt_var.size(); ++i) {
     495             :               evolution::dg::subcell::add_cartesian_flux_divergence(
     496             :                   make_not_null(&dt_var[i]), inverse_delta,
     497             :                   get(cell_centered_det_inv_jacobian), var_correction[i],
     498             :                   subcell_mesh.extents(), dim);
     499             :             }
     500             :           });
     501             :     }
     502             : 
     503             :     evolution::dg::subcell::store_reconstruction_order_in_databox(
     504             :         box, reconstruction_order);
     505             :   }
     506             : 
     507             :  private:
     508             :   template <typename DtVarsList, typename DbTagsList, typename... SourcedTags,
     509             :             typename... ArgsTags>
     510           0 :   static void sources_impl(
     511             :       const gsl::not_null<Variables<DtVarsList>*> dt_vars_ptr,
     512             :       const db::DataBox<DbTagsList>& box, tmpl::list<SourcedTags...> /*meta*/,
     513             :       tmpl::list<ArgsTags...> /*meta*/) {
     514             :     grmhd::ValenciaDivClean::ComputeSources::apply(
     515             :         get<::Tags::dt<SourcedTags>>(dt_vars_ptr)..., get<ArgsTags>(box)...);
     516             :   }
     517             : };
     518             : }  // namespace grmhd::ValenciaDivClean::subcell

Generated by: LCOV version 1.14