Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CellCenteredFlux to work for mixed systems #6418

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Evolution/DgSubcell/CellCenteredFlux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ template <typename System, typename FluxMutator, size_t Dim,
bool ComputeOnlyOnRollback, typename Fr = Frame::Inertial>
struct CellCenteredFlux {
using flux_variables = typename System::flux_variables;
using variables = typename System::variables_tag::tags_list;

using return_tags =
tmpl::list<subcell::Tags::CellCenteredFlux<flux_variables, Dim>>;
using argument_tags = tmpl::push_front<
typename FluxMutator::argument_tags, subcell::Tags::SubcellOptions<Dim>,
subcell::Tags::Mesh<Dim>, domain::Tags::Mesh<Dim>,
domain::Tags::MeshVelocity<Dim, Frame::Inertial>,
::Tags::Variables<flux_variables>, subcell::Tags::DidRollback>;
::Tags::Variables<variables>, subcell::Tags::DidRollback>;

template <typename... FluxTags, typename... Args>
static void apply(
Expand All @@ -51,7 +52,7 @@ struct CellCenteredFlux {
const subcell::SubcellOptions& subcell_options,
const Mesh<Dim>& subcell_mesh, const Mesh<Dim>& dg_mesh,
const std::optional<tnsr::I<DataVector, Dim>>& dg_mesh_velocity,
const ::Variables<flux_variables>& cell_centered_flux_vars,
const ::Variables<variables>& cell_centered_flux_vars,
const bool did_rollback, Args&&... args) {
if (did_rollback or not ComputeOnlyOnRollback) {
if (subcell_options.finite_difference_derivative_order() !=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -763,6 +764,8 @@ struct GhValenciaDivCleanTemplateBase<
Actions::Goto<evolution::dg::subcell::Actions::Labels::EndOfSolvers>,

Actions::Label<evolution::dg::subcell::Actions::Labels::BeginSubcell>,
Actions::MutateApply<evolution::dg::subcell::fd::CellCenteredFlux<
system, grmhd::ValenciaDivClean::ComputeFluxes, volume_dim, false>>,
evolution::dg::subcell::Actions::SendDataForReconstruction<
volume_dim,
grmhd::GhValenciaDivClean::subcell::PrimitiveGhostVariables,
Expand All @@ -773,6 +776,8 @@ struct GhValenciaDivCleanTemplateBase<
Actions::MutateApply<
grmhd::GhValenciaDivClean::subcell::PrimsAfterRollback<
ordered_list_of_primitive_recovery_schemes>>,
Actions::MutateApply<evolution::dg::subcell::fd::CellCenteredFlux<
system, grmhd::ValenciaDivClean::ComputeFluxes, volume_dim, true>>,
evolution::dg::subcell::fd::Actions::TakeTimeStep<
grmhd::GhValenciaDivClean::subcell::TimeDerivative>,
Actions::RecordTimeStepperData<system>,
Expand Down
52 changes: 37 additions & 15 deletions tests/Unit/Evolution/DgSubcell/Test_CellCenteredFlux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ struct Var2 : db::SimpleTag {
using type = Scalar<DataVector>;
};

struct TestSystem {
struct Var3 : db::SimpleTag {
using type = Scalar<DataVector>;
};

struct TestConservativeSystem {
using variables_tag = ::Tags::Variables<tmpl::list<Var1, Var2>>;
using flux_variables = tmpl::list<Var1, Var2>;
};

struct TestMixedSystem {
using variables_tag = ::Tags::Variables<tmpl::list<Var1, Var2, Var3>>;
using flux_variables = tmpl::list<Var1, Var2>;
};

Expand All @@ -56,12 +66,13 @@ struct Fluxes {
}
};

template <size_t Dim, bool ComputeOnlyOnRollback>
template <typename TestSystem, size_t Dim, bool ComputeOnlyOnRollback>
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<flux_variables, Dim>;
Expand All @@ -70,22 +81,25 @@ void test(const fd::DerivativeOrder derivative_order, const bool did_rollback) {
const Mesh<Dim> subcell_mesh{9, Spectral::Basis::FiniteDifference,
Spectral::Quadrature::CellCentered};
const std::optional<tnsr::I<DataVector, Dim>> dg_mesh_velocity{};
Variables<variables> vars{subcell_mesh.number_of_grid_points()};
get(get<Var1>(vars)) = 1.0;
get(get<Var2>(vars)) = 2.0;

auto box =
db::create<tmpl::list<evolution::dg::subcell::Tags::DidRollback,
evolution::dg::subcell::Tags::SubcellOptions<Dim>,
evolution::dg::subcell::Tags::Mesh<Dim>,
CellCenteredFluxTag, domain::Tags::Mesh<Dim>,
domain::Tags::MeshVelocity<Dim, Frame::Inertial>,
::Tags::Variables<flux_variables>>>(
::Tags::Variables<variables>>>(
did_rollback,
evolution::dg::subcell::SubcellOptions{
4.0, 1_st, 1.0e-3, 1.0e-4, false,
evolution::dg::subcell::fd::ReconstructionMethod::DimByDim, false,
std::nullopt, derivative_order, 1, 1, 1},
subcell_mesh, typename CellCenteredFluxTag::type{}, dg_mesh,
dg_mesh_velocity,
Variables<flux_variables>{subcell_mesh.number_of_grid_points(), 1.0});
Variables<variables>{subcell_mesh.number_of_grid_points(), 1.0});

db::mutate_apply<evolution::dg::subcell::fd::CellCenteredFlux<
TestSystem, Fluxes<Dim>, Dim, ComputeOnlyOnRollback>>(
Expand All @@ -96,12 +110,12 @@ void test(const fd::DerivativeOrder derivative_order, const bool did_rollback) {
Dim>>(box)
.has_value());
const auto& [flux1, flux2] = get<CellCenteredFluxTag>(box).value();
const auto& [var1, var2] = get<::Tags::Variables<flux_variables>>(box);
const auto& box_vars = get<::Tags::Variables<variables>>(box);
for (size_t i = 0; i < Dim; ++i) {
CHECK(flux1.get(i) ==
DataVector((1.0 + static_cast<double>(i)) * get(var1)));
CHECK(flux2.get(i) ==
DataVector(5.0 * (1.0 + static_cast<double>(i)) * get(var2)));
CHECK(flux1.get(i) == DataVector((1.0 + static_cast<double>(i)) *
get(get<Var1>(box_vars))));
CHECK(flux2.get(i) == DataVector(5.0 * (1.0 + static_cast<double>(i)) *
get(get<Var2>(box_vars))));
}
} else {
CHECK(not get<evolution::dg::subcell::Tags::CellCenteredFlux<flux_variables,
Expand All @@ -117,13 +131,21 @@ SPECTRE_TEST_CASE("Unit.Evolution.Subcell.CellCenteredFlux",
{DO::Two, DO::Four, DO::Six, DO::Eight, DO::Ten, DO::OneHigherThanRecons,
DO::OneHigherThanReconsButFiveToFour}) {
for (const bool did_rollback : {true, false}) {
test<1, false>(derivative_order, did_rollback);
test<2, false>(derivative_order, did_rollback);
test<3, false>(derivative_order, did_rollback);
test<TestConservativeSystem, 1, false>(derivative_order, did_rollback);
test<TestConservativeSystem, 2, false>(derivative_order, did_rollback);
test<TestConservativeSystem, 3, false>(derivative_order, did_rollback);

test<TestConservativeSystem, 1, true>(derivative_order, did_rollback);
test<TestConservativeSystem, 2, true>(derivative_order, did_rollback);
test<TestConservativeSystem, 3, true>(derivative_order, did_rollback);

test<TestMixedSystem, 1, false>(derivative_order, did_rollback);
test<TestMixedSystem, 2, false>(derivative_order, did_rollback);
test<TestMixedSystem, 3, false>(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<TestMixedSystem, 1, true>(derivative_order, did_rollback);
test<TestMixedSystem, 2, true>(derivative_order, did_rollback);
test<TestMixedSystem, 3, true>(derivative_order, did_rollback);
}
}
}
Expand Down
Loading