From 58995fcf143e3319cbf032d3e4a4612701eea5e7 Mon Sep 17 00:00:00 2001 From: Lawrence Kidder Date: Tue, 17 Dec 2024 12:31:26 -0500 Subject: [PATCH] Allow CellCenteredFlux to work for mixed systems Previously CellCenteredFlux assumed that the flux_variables were the same as the evolved variables. --- src/Evolution/DgSubcell/CellCenteredFlux.hpp | 5 +- .../GhValenciaDivCleanBase.hpp | 5 ++ .../DgSubcell/Test_CellCenteredFlux.cpp | 52 +++++++++++++------ 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/Evolution/DgSubcell/CellCenteredFlux.hpp b/src/Evolution/DgSubcell/CellCenteredFlux.hpp index 87aab3687425..87d5a7701db5 100644 --- a/src/Evolution/DgSubcell/CellCenteredFlux.hpp +++ b/src/Evolution/DgSubcell/CellCenteredFlux.hpp @@ -35,6 +35,7 @@ template struct CellCenteredFlux { using flux_variables = typename System::flux_variables; + using variables = typename System::variables_tag::tags_list; using return_tags = tmpl::list>; @@ -42,7 +43,7 @@ struct CellCenteredFlux { typename FluxMutator::argument_tags, subcell::Tags::SubcellOptions, subcell::Tags::Mesh, domain::Tags::Mesh, domain::Tags::MeshVelocity, - ::Tags::Variables, subcell::Tags::DidRollback>; + ::Tags::Variables, subcell::Tags::DidRollback>; template static void apply( @@ -51,7 +52,7 @@ struct CellCenteredFlux { const subcell::SubcellOptions& subcell_options, const Mesh& subcell_mesh, const Mesh& dg_mesh, const std::optional>& dg_mesh_velocity, - const ::Variables& cell_centered_flux_vars, + const ::Variables& cell_centered_flux_vars, const bool did_rollback, Args&&... args) { if (did_rollback or not ComputeOnlyOnRollback) { if (subcell_options.finite_difference_derivative_order() != diff --git a/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp b/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp index 46d4d3eefcd9..eff180d53947 100644 --- a/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp +++ b/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp @@ -35,6 +35,7 @@ #include "Evolution/DgSubcell/Actions/TciAndRollback.hpp" #include "Evolution/DgSubcell/Actions/TciAndSwitchToDg.hpp" #include "Evolution/DgSubcell/CartesianFluxDivergence.hpp" +#include "Evolution/DgSubcell/CellCenteredFlux.hpp" #include "Evolution/DgSubcell/ComputeBoundaryTerms.hpp" #include "Evolution/DgSubcell/CorrectPackagedData.hpp" #include "Evolution/DgSubcell/GetActiveTag.hpp" @@ -763,6 +764,8 @@ struct GhValenciaDivCleanTemplateBase< Actions::Goto, Actions::Label, + Actions::MutateApply>, evolution::dg::subcell::Actions::SendDataForReconstruction< volume_dim, grmhd::GhValenciaDivClean::subcell::PrimitiveGhostVariables, @@ -773,6 +776,8 @@ struct GhValenciaDivCleanTemplateBase< Actions::MutateApply< grmhd::GhValenciaDivClean::subcell::PrimsAfterRollback< ordered_list_of_primitive_recovery_schemes>>, + Actions::MutateApply>, evolution::dg::subcell::fd::Actions::TakeTimeStep< grmhd::GhValenciaDivClean::subcell::TimeDerivative>, Actions::RecordTimeStepperData, diff --git a/tests/Unit/Evolution/DgSubcell/Test_CellCenteredFlux.cpp b/tests/Unit/Evolution/DgSubcell/Test_CellCenteredFlux.cpp index 4984c91dc9e5..0013f0ca16e3 100644 --- a/tests/Unit/Evolution/DgSubcell/Test_CellCenteredFlux.cpp +++ b/tests/Unit/Evolution/DgSubcell/Test_CellCenteredFlux.cpp @@ -34,7 +34,17 @@ struct Var2 : db::SimpleTag { using type = Scalar; }; -struct TestSystem { +struct Var3 : db::SimpleTag { + using type = Scalar; +}; + +struct TestConservativeSystem { + using variables_tag = ::Tags::Variables>; + using flux_variables = tmpl::list; +}; + +struct TestMixedSystem { + using variables_tag = ::Tags::Variables>; using flux_variables = tmpl::list; }; @@ -56,12 +66,13 @@ struct Fluxes { } }; -template +template void test(const fd::DerivativeOrder derivative_order, const bool did_rollback) { CAPTURE(Dim); CAPTURE(ComputeOnlyOnRollback); CAPTURE(derivative_order); CAPTURE(did_rollback); + using variables = typename TestSystem::variables_tag::tags_list; using flux_variables = typename TestSystem::flux_variables; using CellCenteredFluxTag = evolution::dg::subcell::Tags::CellCenteredFlux; @@ -70,6 +81,9 @@ void test(const fd::DerivativeOrder derivative_order, const bool did_rollback) { const Mesh subcell_mesh{9, Spectral::Basis::FiniteDifference, Spectral::Quadrature::CellCentered}; const std::optional> dg_mesh_velocity{}; + Variables vars{subcell_mesh.number_of_grid_points()}; + get(get(vars)) = 1.0; + get(get(vars)) = 2.0; auto box = db::create, CellCenteredFluxTag, domain::Tags::Mesh, domain::Tags::MeshVelocity, - ::Tags::Variables>>( + ::Tags::Variables>>( did_rollback, evolution::dg::subcell::SubcellOptions{ 4.0, 1_st, 1.0e-3, 1.0e-4, false, @@ -85,7 +99,7 @@ void test(const fd::DerivativeOrder derivative_order, const bool did_rollback) { std::nullopt, derivative_order, 1, 1, 1}, subcell_mesh, typename CellCenteredFluxTag::type{}, dg_mesh, dg_mesh_velocity, - Variables{subcell_mesh.number_of_grid_points(), 1.0}); + Variables{subcell_mesh.number_of_grid_points(), 1.0}); db::mutate_apply, Dim, ComputeOnlyOnRollback>>( @@ -96,12 +110,12 @@ void test(const fd::DerivativeOrder derivative_order, const bool did_rollback) { Dim>>(box) .has_value()); const auto& [flux1, flux2] = get(box).value(); - const auto& [var1, var2] = get<::Tags::Variables>(box); + const auto& box_vars = get<::Tags::Variables>(box); for (size_t i = 0; i < Dim; ++i) { - CHECK(flux1.get(i) == - DataVector((1.0 + static_cast(i)) * get(var1))); - CHECK(flux2.get(i) == - DataVector(5.0 * (1.0 + static_cast(i)) * get(var2))); + CHECK(flux1.get(i) == DataVector((1.0 + static_cast(i)) * + get(get(box_vars)))); + CHECK(flux2.get(i) == DataVector(5.0 * (1.0 + static_cast(i)) * + get(get(box_vars)))); } } else { CHECK(not get(derivative_order, did_rollback); - test<2, false>(derivative_order, did_rollback); - test<3, false>(derivative_order, did_rollback); + test(derivative_order, did_rollback); + test(derivative_order, did_rollback); + test(derivative_order, did_rollback); + + test(derivative_order, did_rollback); + test(derivative_order, did_rollback); + test(derivative_order, did_rollback); + + test(derivative_order, did_rollback); + test(derivative_order, did_rollback); + test(derivative_order, did_rollback); - test<1, true>(derivative_order, did_rollback); - test<2, true>(derivative_order, did_rollback); - test<3, true>(derivative_order, did_rollback); + test(derivative_order, did_rollback); + test(derivative_order, did_rollback); + test(derivative_order, did_rollback); } } }