Skip to content

Commit 66f2128

Browse files
nilsdeppeclaude
andcommitted
Add PPM reconstruction to GhValenciaDivClean GRMHD
Adds PpmPrim, a piecewise parabolic method (PPM) reconstructor for the GRMHD GhValenciaDivClean system, following the same structure as MonotonisedCentralPrim. PPM uses a 3-point stencil with the Colella & Woodward monotonicity limiter (ghost_zone_size = 2, no adaptive order). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7512086 commit 66f2128

7 files changed

Lines changed: 570 additions & 1 deletion

File tree

src/Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ spectre_target_sources(
99
Filters.cpp
1010
MonotonisedCentral.cpp
1111
PositivityPreservingAdaptiveOrder.cpp
12+
Ppm.cpp
1213
Reconstructor.cpp
1314
RegisterDerivedWithCharm.cpp
1415
Wcns5z.cpp
@@ -27,6 +28,7 @@ spectre_target_headers(
2728
FiniteDifference.hpp
2829
MonotonisedCentral.hpp
2930
PositivityPreservingAdaptiveOrder.hpp
31+
Ppm.hpp
3032
ReconstructWork.hpp
3133
ReconstructWork.tpp
3234
Reconstructor.hpp

src/Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/Factory.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/MonotonisedCentral.hpp"
77
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/PositivityPreservingAdaptiveOrder.hpp"
8+
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/Ppm.hpp"
89
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/Reconstructor.hpp"
910
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/Wcns5z.hpp"

src/Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/Ppm.cpp

Lines changed: 337 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// Distributed under the MIT License.
2+
// See LICENSE.txt for details.
3+
4+
#pragma once
5+
6+
#include <array>
7+
#include <cstddef>
8+
#include <memory>
9+
#include <utility>
10+
#include <vector>
11+
12+
#include "DataStructures/DataBox/PrefixHelpers.hpp"
13+
#include "DataStructures/DataBox/Prefixes.hpp"
14+
#include "DataStructures/Tensor/TypeAliases.hpp"
15+
#include "DataStructures/Variables.hpp"
16+
#include "DataStructures/VariablesTag.hpp"
17+
#include "Domain/Structure/DirectionalIdMap.hpp"
18+
#include "Domain/Tags.hpp"
19+
#include "Evolution/DgSubcell/Tags/GhostDataForReconstruction.hpp"
20+
#include "Evolution/DgSubcell/Tags/Mesh.hpp"
21+
#include "Evolution/Systems/GeneralizedHarmonic/Tags.hpp"
22+
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/Reconstructor.hpp"
23+
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/System.hpp"
24+
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/Tags.hpp"
25+
#include "Evolution/Systems/GrMhd/ValenciaDivClean/Tags.hpp"
26+
#include "Evolution/VariableFixing/FixToAtmosphere.hpp"
27+
#include "Evolution/VariableFixing/Tags.hpp"
28+
#include "Options/String.hpp"
29+
#include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
30+
#include "PointwiseFunctions/Hydro/Tags.hpp"
31+
#include "Utilities/Serialization/CharmPupable.hpp"
32+
#include "Utilities/TMPL.hpp"
33+
34+
/// \cond
35+
class DataVector;
36+
template <size_t Dim>
37+
class Direction;
38+
template <size_t Dim>
39+
class Element;
40+
template <size_t Dim>
41+
class ElementId;
42+
namespace EquationsOfState {
43+
template <bool IsRelativistic, size_t ThermodynamicDim>
44+
class EquationOfState;
45+
} // namespace EquationsOfState
46+
template <size_t Dim>
47+
class Mesh;
48+
namespace gsl {
49+
template <typename T>
50+
class not_null;
51+
} // namespace gsl
52+
namespace PUP {
53+
class er;
54+
} // namespace PUP
55+
namespace evolution::dg::subcell {
56+
class GhostData;
57+
} // namespace evolution::dg::subcell
58+
/// \endcond
59+
60+
namespace grmhd::GhValenciaDivClean::fd {
61+
/*!
62+
* \brief PPM (Piecewise Parabolic Method) reconstruction on the GRMHD
63+
* primitive variables (see ::fd::reconstruction::ppm() for details) and
64+
* unlimited 3rd order (degree 2 polynomial) reconstruction on the metric
65+
* variables.
66+
*
67+
* Only the spacetime metric is reconstructed when we and the neighboring
68+
* element in the direction are doing FD. If we are doing DG and a neighboring
69+
* element is doing FD, then the spacetime metric, \f$\Phi_{iab}\f$, and
70+
* \f$\Pi_{ab}\f$ are all reconstructed since the Riemann solver on the DG
71+
* element also needs to solve for the metric variables.
72+
*/
73+
template <typename System>
74+
class PpmPrim : public Reconstructor<System> {
75+
public:
76+
static constexpr size_t dim = 3;
77+
78+
struct AtmosphereTreatment {
79+
using type = ::VariableFixing::FixReconstructedStateToAtmosphere;
80+
static constexpr Options::String help = {
81+
"What reconstructed states to fix to their atmosphere values."};
82+
};
83+
struct ReconstructRhoTimesTemperature {
84+
using type = bool;
85+
static constexpr Options::String help = {
86+
"If 'true' then we reconstruct the rho*T, if 'false' we reconstruct "
87+
"T."};
88+
};
89+
90+
using options =
91+
tmpl::list<AtmosphereTreatment, ReconstructRhoTimesTemperature>;
92+
static constexpr Options::String help{
93+
"PPM (Piecewise Parabolic Method) reconstruction scheme using primitive "
94+
"variables and the metric variables."};
95+
96+
PpmPrim(::VariableFixing::FixReconstructedStateToAtmosphere
97+
fix_reconstructed_state_to_atmosphere,
98+
bool reconstruct_rho_times_temperature);
99+
100+
PpmPrim() = default;
101+
PpmPrim(PpmPrim&&) = default;
102+
PpmPrim& operator=(PpmPrim&&) = default;
103+
PpmPrim(const PpmPrim&) = default;
104+
PpmPrim& operator=(const PpmPrim&) = default;
105+
~PpmPrim() override = default;
106+
107+
explicit PpmPrim(CkMigrateMessage* msg);
108+
109+
WRAPPED_PUPable_decl_base_template(Reconstructor<System>, PpmPrim);
110+
111+
auto get_clone() const -> std::unique_ptr<Reconstructor<System>> override;
112+
113+
static constexpr bool use_adaptive_order = false;
114+
115+
void pup(PUP::er& p) override;
116+
117+
size_t ghost_zone_size() const override { return 2; }
118+
119+
using reconstruction_argument_tags =
120+
tmpl::list<::Tags::Variables<hydro::grmhd_tags<DataVector>>,
121+
typename System::variables_tag,
122+
hydro::Tags::GrmhdEquationOfState, domain::Tags::Element<dim>,
123+
evolution::dg::subcell::Tags::GhostDataForReconstruction<dim>,
124+
evolution::dg::subcell::Tags::Mesh<dim>,
125+
::Tags::VariableFixer<VariableFixing::FixToAtmosphere<dim>>>;
126+
127+
template <size_t ThermodynamicDim, typename TagsList>
128+
void reconstruct(
129+
gsl::not_null<std::array<Variables<TagsList>, dim>*> vars_on_lower_face,
130+
gsl::not_null<std::array<Variables<TagsList>, dim>*> vars_on_upper_face,
131+
const Variables<hydro::grmhd_tags<DataVector>>& volume_prims,
132+
const Variables<typename System::variables_tag::type::tags_list>&
133+
volume_spacetime_and_cons_vars,
134+
const EquationsOfState::EquationOfState<true, ThermodynamicDim>& eos,
135+
const Element<dim>& element,
136+
const DirectionalIdMap<dim, evolution::dg::subcell::GhostData>&
137+
ghost_data,
138+
const Mesh<dim>& subcell_mesh,
139+
const VariableFixing::FixToAtmosphere<dim>& fix_to_atmosphere) const;
140+
141+
/// Called by an element doing DG when the neighbor is doing subcell.
142+
template <size_t ThermodynamicDim, typename TagsList>
143+
void reconstruct_fd_neighbor(
144+
gsl::not_null<Variables<TagsList>*> vars_on_face,
145+
const Variables<hydro::grmhd_tags<DataVector>>& subcell_volume_prims,
146+
const Variables<
147+
grmhd::GhValenciaDivClean::Tags::spacetime_reconstruction_tags>&
148+
subcell_volume_spacetime_metric,
149+
const EquationsOfState::EquationOfState<true, ThermodynamicDim>& eos,
150+
const Element<dim>& element,
151+
const DirectionalIdMap<dim, evolution::dg::subcell::GhostData>&
152+
ghost_data,
153+
const Mesh<dim>& subcell_mesh,
154+
const VariableFixing::FixToAtmosphere<dim>& fix_to_atmosphere,
155+
Direction<dim> direction_to_reconstruct) const;
156+
157+
bool reconstruct_rho_times_temperature() const override;
158+
159+
private:
160+
template <typename LocalSystem>
161+
friend bool operator==(const PpmPrim<LocalSystem>& lhs,
162+
const PpmPrim<LocalSystem>& rhs);
163+
template <typename LocalSystem>
164+
friend bool operator!=(const PpmPrim<LocalSystem>& lhs,
165+
const PpmPrim<LocalSystem>& rhs);
166+
167+
::VariableFixing::FixReconstructedStateToAtmosphere
168+
fix_reconstructed_state_to_atmosphere_{
169+
::VariableFixing::FixReconstructedStateToAtmosphere::Never};
170+
bool reconstruct_rho_times_temperature_{false};
171+
};
172+
} // namespace grmhd::GhValenciaDivClean::fd

src/Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/Reconstructor.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class MonotonisedCentralPrim;
2222
template <typename System>
2323
class PositivityPreservingAdaptiveOrderPrim;
2424
template <typename System>
25+
class PpmPrim;
26+
template <typename System>
2527
class Wcns5zPrim;
2628
/// \endcond
2729

@@ -48,7 +50,7 @@ class Reconstructor : public PUP::able {
4850
using system = System;
4951
using creatable_classes =
5052
tmpl::list<MonotonisedCentralPrim<System>,
51-
PositivityPreservingAdaptiveOrderPrim<System>,
53+
PositivityPreservingAdaptiveOrderPrim<System>, PpmPrim<System>,
5254
Wcns5zPrim<System>>;
5355

5456
virtual std::unique_ptr<Reconstructor<System>> get_clone() const = 0;

tests/Unit/Evolution/Systems/GrMhd/GhValenciaDivClean/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(LIBRARY_SOURCES
1616
FiniteDifference/Test_Filters.cpp
1717
FiniteDifference/Test_MonotonisedCentral.cpp
1818
FiniteDifference/Test_PositivityPreservingAdaptiveOrder.cpp
19+
FiniteDifference/Test_Ppm.cpp
1920
FiniteDifference/Test_Wcns5z.cpp
2021
Subcell/Test_FixConservativesAndComputePrims.cpp
2122
Subcell/Test_NeighborPackagedData.cpp
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Distributed under the MIT License.
2+
// See LICENSE.txt for details.
3+
4+
#include "Framework/TestingFramework.hpp"
5+
6+
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/Factory.hpp"
7+
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/Ppm.hpp"
8+
#include "Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/Tag.hpp"
9+
#include "Evolution/Systems/RadiationTransport/NoNeutrinos/System.hpp"
10+
#include "Evolution/VariableFixing/FixToAtmosphere.hpp"
11+
#include "Framework/TestCreation.hpp"
12+
#include "Framework/TestHelpers.hpp"
13+
#include "Helpers/Evolution/Systems/GrMhd/GhValenciaDivClean/FiniteDifference/PrimReconstructor.hpp"
14+
15+
SPECTRE_TEST_CASE("Unit.Evolution.Systems.GrMhd.GhValenciaDivClean.Fd.PpmPrim",
16+
"[Unit][Evolution]") {
17+
namespace helpers = TestHelpers::grmhd::GhValenciaDivClean::fd;
18+
using NeutrinoTransportSystem = RadiationTransport::NoNeutrinos::System;
19+
using System = grmhd::GhValenciaDivClean::System<NeutrinoTransportSystem>;
20+
21+
PUPable_reg(SINGLE_ARG(grmhd::GhValenciaDivClean::fd::PpmPrim<System>));
22+
const auto ppm_from_options_base = TestHelpers::test_factory_creation<
23+
grmhd::GhValenciaDivClean::fd::Reconstructor<System>,
24+
grmhd::GhValenciaDivClean::fd::OptionTags::Reconstructor<System>>(
25+
"PpmPrim:\n"
26+
" AtmosphereTreatment: Never\n"
27+
" ReconstructRhoTimesTemperature: false\n");
28+
const auto ppm_deserialized =
29+
serialize_and_deserialize(ppm_from_options_base);
30+
auto* const ppm_from_options =
31+
dynamic_cast<const grmhd::GhValenciaDivClean::fd::PpmPrim<System>*>(
32+
ppm_deserialized.get());
33+
REQUIRE(ppm_from_options != nullptr);
34+
CHECK(
35+
grmhd::GhValenciaDivClean::fd::PpmPrim<System>{
36+
::VariableFixing::FixReconstructedStateToAtmosphere::Always, false} !=
37+
grmhd::GhValenciaDivClean::fd::PpmPrim<System>{
38+
::VariableFixing::FixReconstructedStateToAtmosphere::Never, false});
39+
CHECK(
40+
grmhd::GhValenciaDivClean::fd::PpmPrim<System>{
41+
::VariableFixing::FixReconstructedStateToAtmosphere::Always, false} !=
42+
grmhd::GhValenciaDivClean::fd::PpmPrim<System>{
43+
::VariableFixing::FixReconstructedStateToAtmosphere::Always, true});
44+
CHECK(*ppm_from_options ==
45+
grmhd::GhValenciaDivClean::fd::PpmPrim<System>{
46+
::VariableFixing::FixReconstructedStateToAtmosphere::Never, false});
47+
test_move_semantics(
48+
grmhd::GhValenciaDivClean::fd::PpmPrim<System>{
49+
::VariableFixing::FixReconstructedStateToAtmosphere::Never, false},
50+
grmhd::GhValenciaDivClean::fd::PpmPrim<System>{
51+
::VariableFixing::FixReconstructedStateToAtmosphere::Never, false});
52+
53+
helpers::test_prim_reconstructor(5, *ppm_from_options);
54+
}

0 commit comments

Comments
 (0)