SpECTRE Documentation Coverage Report
Current view: top level - Evolution/DgSubcell - CellCenteredFlux.hpp Hit Total Coverage
Commit: 37c384043430860f87787999aa7399d01bb3d213 Lines: 1 6 16.7 %
Date: 2024-04-20 02:24:02
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 <cstddef>
       7             : #include <optional>
       8             : #include <utility>
       9             : 
      10             : #include "DataStructures/DataBox/PrefixHelpers.hpp"
      11             : #include "DataStructures/DataBox/Prefixes.hpp"
      12             : #include "DataStructures/Variables.hpp"
      13             : #include "Domain/TagsTimeDependent.hpp"
      14             : #include "Evolution/DgSubcell/Projection.hpp"
      15             : #include "Evolution/DgSubcell/SubcellOptions.hpp"
      16             : #include "Evolution/DgSubcell/Tags/CellCenteredFlux.hpp"
      17             : #include "Evolution/DgSubcell/Tags/DidRollback.hpp"
      18             : #include "Evolution/DgSubcell/Tags/Mesh.hpp"
      19             : #include "Evolution/DgSubcell/Tags/SubcellOptions.hpp"
      20             : #include "NumericalAlgorithms/Spectral/Mesh.hpp"
      21             : #include "Utilities/Gsl.hpp"
      22             : #include "Utilities/TMPL.hpp"
      23             : 
      24             : namespace evolution::dg::subcell::fd {
      25             : /*!
      26             :  * \brief Mutator that wraps the system's `FluxMutator` to correctly set the
      27             :  * cell-centered fluxes on the subcell grid.
      28             :  *
      29             :  * Currently we only use high-order FD if the FD order was specified in the
      30             :  * input file. We will need to extend this to support adaptive-order in the
      31             :  * future. In that case we need to check if the FD reconstruction reports back
      32             :  * the order to use.
      33             :  */
      34             : template <typename System, typename FluxMutator, size_t Dim,
      35             :           bool ComputeOnlyOnRollback, typename Fr = Frame::Inertial>
      36           1 : struct CellCenteredFlux {
      37           0 :   using flux_variables = typename System::flux_variables;
      38             : 
      39           0 :   using return_tags =
      40             :       tmpl::list<subcell::Tags::CellCenteredFlux<flux_variables, Dim>>;
      41           0 :   using argument_tags = tmpl::push_front<
      42             :       typename FluxMutator::argument_tags, subcell::Tags::SubcellOptions<Dim>,
      43             :       subcell::Tags::Mesh<Dim>, domain::Tags::Mesh<Dim>,
      44             :       domain::Tags::MeshVelocity<Dim, Frame::Inertial>,
      45             :       ::Tags::Variables<flux_variables>, subcell::Tags::DidRollback>;
      46             : 
      47             :   template <typename... FluxTags, typename... Args>
      48           0 :   static void apply(
      49             :       const gsl::not_null<std::optional<Variables<tmpl::list<FluxTags...>>>*>
      50             :           cell_centered_fluxes,
      51             :       const subcell::SubcellOptions& subcell_options,
      52             :       const Mesh<Dim>& subcell_mesh, const Mesh<Dim>& dg_mesh,
      53             :       const std::optional<tnsr::I<DataVector, Dim>>& dg_mesh_velocity,
      54             :       const ::Variables<flux_variables>& cell_centered_flux_vars,
      55             :       const bool did_rollback, Args&&... args) {
      56             :     if (did_rollback or not ComputeOnlyOnRollback) {
      57             :       if (subcell_options.finite_difference_derivative_order() !=
      58             :           ::fd::DerivativeOrder::Two) {
      59             :         if (not cell_centered_fluxes->has_value()) {
      60             :           (*cell_centered_fluxes) =
      61             :               Variables<db::wrap_tags_in<::Tags::Flux, flux_variables,
      62             :                                          tmpl::size_t<Dim>, Fr>>{
      63             :                   subcell_mesh.number_of_grid_points()};
      64             :         }
      65             :         FluxMutator::apply(
      66             :             make_not_null(&get<FluxTags>((*cell_centered_fluxes).value()))...,
      67             :             std::forward<Args>(args)...);
      68             :         if (dg_mesh_velocity.has_value()) {
      69             :           for (size_t i = 0; i < Dim; i++) {
      70             :             //
      71             :             // Project mesh velocity on face mesh. We only need the component
      72             :             // orthogonal to the face.
      73             :             const DataVector& cell_centered_mesh_velocity =
      74             :                 evolution::dg::subcell::fd::project(
      75             :                     dg_mesh_velocity.value().get(i), dg_mesh,
      76             :                     subcell_mesh.extents());
      77             : 
      78             :             tmpl::for_each<flux_variables>(
      79             :                 [&cell_centered_flux_vars, &cell_centered_mesh_velocity,
      80             :                  &cell_centered_fluxes, &i](auto tag_v) {
      81             :                   using tag = tmpl::type_from<decltype(tag_v)>;
      82             :                   using flux_tag =
      83             :                       ::Tags::Flux<tag, tmpl::size_t<Dim>, Frame::Inertial>;
      84             :                   using FluxTensor = typename flux_tag::type;
      85             :                   const auto& var = get<tag>(cell_centered_flux_vars);
      86             :                   auto& flux = get<flux_tag>(cell_centered_fluxes->value());
      87             :                   for (size_t storage_index = 0; storage_index < var.size();
      88             :                        ++storage_index) {
      89             :                     const auto tensor_index =
      90             :                         var.get_tensor_index(storage_index);
      91             :                     const auto flux_storage_index =
      92             :                         FluxTensor::get_storage_index(prepend(tensor_index, i));
      93             :                     flux[flux_storage_index] -=
      94             :                         cell_centered_mesh_velocity * var[storage_index];
      95             :                   }
      96             :                 });
      97             :           }
      98             :         }
      99             :       }
     100             :     }
     101             :   }
     102             : };
     103             : }  // namespace evolution::dg::subcell::fd

Generated by: LCOV version 1.14