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

Generated by: LCOV version 1.14