Skip to content

Commit

Permalink
FixConservatives ignore magnetic field when zero
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsdeppe committed Nov 18, 2023
1 parent 527faaa commit 25015c5
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 83 deletions.
244 changes: 167 additions & 77 deletions src/Evolution/Systems/GrMhd/ValenciaDivClean/FixConservatives.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Options/Context.hpp"
#include "Options/String.hpp"
#include "PointwiseFunctions/GeneralRelativity/TagsDeclarations.hpp" // IWYU pragma: keep
#include "PointwiseFunctions/Hydro/MagneticFieldTreatment.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/TMPL.hpp"

Expand Down Expand Up @@ -160,11 +161,17 @@ class FixConservatives {
static constexpr Options::String help = {
"If true then the limiting is applied."};
};
/// How to treat the magnetic field
struct MagneticField {
using type = hydro::MagneticFieldTreatment;
static constexpr Options::String help = {
"How to treat the magnetic field."};
};

using options =
tmpl::list<MinimumValueOfD, CutoffD, MinimumValueOfYe, CutoffYe,
SafetyFactorForB, SafetyFactorForS, SafetyFactorForSCutoffD,
SafetyFactorForSSlope, Enable>;
SafetyFactorForSSlope, Enable, MagneticField>;
static constexpr Options::String help = {
"Variable fixing used in Foucart's thesis.\n"};

Expand All @@ -176,6 +183,7 @@ class FixConservatives {
double safety_factor_for_momentum_density,
double safety_factor_for_momentum_density_cutoff_d,
double safety_factor_for_momentum_density_slope, bool enable,
hydro::MagneticFieldTreatment magnetic_field_treatment,
const Options::Context& context = {});

FixConservatives() = default;
Expand Down Expand Up @@ -230,6 +238,8 @@ class FixConservatives {
double safety_factor_for_momentum_density_slope_{
std::numeric_limits<double>::signaling_NaN()};
bool enable_{true};
hydro::MagneticFieldTreatment magnetic_field_treatment_{
hydro::MagneticFieldTreatment::AssumeNonZero};
};

bool operator!=(const FixConservatives& lhs, const FixConservatives& rhs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ VariableFixing:
SafetyFactorForS: 1.0e-4
SafetyFactorForSCutoffD: 1.0e-8
SafetyFactorForSSlope: 0.0001
MagneticField: AssumeZero
FixToAtmosphere:
DensityOfAtmosphere: 1.0e-15
DensityCutoff: &AtmosphereDensityCutoff 1.1e-15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ VariableFixing:
SafetyFactorForS: 1.0e-12
SafetyFactorForSCutoffD: 1.0e-12
SafetyFactorForSSlope: 0.0
MagneticField: AssumeNonZero
FixToAtmosphere:
DensityOfAtmosphere: 1.0e-12
DensityCutoff: 1.0e-12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ VariableFixing:
SafetyFactorForS: 1.0e-12
SafetyFactorForSCutoffD: 1.0e-12
SafetyFactorForSSlope: 0.0
MagneticField: AssumeZero
FixToAtmosphere:
DensityOfAtmosphere: 1.0e-12
DensityCutoff: 1.0e-12
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/GrMhd/ValenciaDivClean/BlastWave.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ VariableFixing:
SafetyFactorForS: 1.0e-12
SafetyFactorForSCutoffD: 1.0e-12
SafetyFactorForSSlope: 0.0
MagneticField: AssumeNonZero
FixToAtmosphere:
DensityOfAtmosphere: 1.0e-12
DensityCutoff: 1.0e-12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ VariableFixing:
SafetyFactorForS: 1.0e-12
SafetyFactorForSCutoffD: 1.0e-12
SafetyFactorForSSlope: 0.0
MagneticField: AssumeNonZero
FixToAtmosphere:
DensityOfAtmosphere: 1.0e-12
DensityCutoff: 1.0e-12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "PointwiseFunctions/Hydro/EquationsOfState/Barotropic3D.hpp"
#include "PointwiseFunctions/Hydro/EquationsOfState/EquationOfState.hpp"
#include "PointwiseFunctions/Hydro/EquationsOfState/PolytropicFluid.hpp"
#include "PointwiseFunctions/Hydro/MagneticFieldTreatment.hpp"
#include "PointwiseFunctions/Hydro/Tags.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/TMPL.hpp"
Expand Down Expand Up @@ -51,7 +52,11 @@ void test(const EquationOfStateType& eos) {
sqrt(get(determinant(spatial_metric)))};

const grmhd::ValenciaDivClean::FixConservatives variable_fixer{
1.e-7, 1.0e-7, 1.0e-10, 1.0e-10, 0.0, 0.0, 1.e-7, 0.0, true};
1.e-7, 1.0e-7,
1.0e-10, 1.0e-10,
0.0, 0.0,
1.e-7, 0.0,
true, hydro::MagneticFieldTreatment::AssumeNonZero};
typename System::variables_tag::type cons_vars{num_pts, 0.0};
get(get<grmhd::ValenciaDivClean::Tags::TildeD>(cons_vars))[0] = 2.e-12;
get(get<grmhd::ValenciaDivClean::Tags::TildeYe>(cons_vars))[0] = 2.e-13;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
#include "PointwiseFunctions/Hydro/EquationsOfState/EquationOfState.hpp"
#include "PointwiseFunctions/Hydro/EquationsOfState/PolytropicFluid.hpp"
#include "PointwiseFunctions/Hydro/MagneticFieldTreatment.hpp"
#include "PointwiseFunctions/Hydro/Tags.hpp"

SPECTRE_TEST_CASE(
Expand All @@ -34,7 +35,11 @@ SPECTRE_TEST_CASE(
}
const Scalar<DataVector> sqrt_det_spatial_metric{num_pts, 1.0};
const grmhd::ValenciaDivClean::FixConservatives variable_fixer{
1.e-7, 1.0e-7, 1.0e-10, 1.0e-10, 0.0, 0.0, 1.e-7, 0.0, true};
1.e-7, 1.0e-7,
1.0e-10, 1.0e-10,
0.0, 0.0,
1.e-7, 0.0,
true, hydro::MagneticFieldTreatment::AssumeNonZero};
typename System::variables_tag::type cons_vars{num_pts, 0.0};
get(get<grmhd::ValenciaDivClean::Tags::TildeD>(cons_vars))[0] = 2.e-12;
get(get<grmhd::ValenciaDivClean::Tags::TildeYe>(cons_vars))[0] = 2.e-13;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Evolution/Systems/GrMhd/ValenciaDivClean/FixConservatives.hpp"
#include "Framework/TestCreation.hpp"
#include "Framework/TestHelpers.hpp"
#include "PointwiseFunctions/Hydro/MagneticFieldTreatment.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/MakeWithValue.hpp"

Expand Down Expand Up @@ -129,7 +130,11 @@ void run_benchmark(const bool enable) {
}

const grmhd::ValenciaDivClean::FixConservatives variable_fixer{
1.e-12, 1.0e-11, 1.0e-10, 1.0e-9, 0.0, 0.0, 1.0e-8, 0.0001, true};
1.e-12, 1.0e-11,
1.0e-10, 1.0e-9,
0.0, 0.0,
1.0e-8, 0.0001,
true, hydro::MagneticFieldTreatment::AssumeNonZero};

BENCHMARK("FixConservatives") {
// Note: Benchmarking and perf indicates that software prefetching is likely
Expand All @@ -144,7 +149,11 @@ SPECTRE_TEST_CASE("Unit.Evolution.GrMhd.ValenciaDivClean.FixConservatives",
"[VariableFixing][Unit]") {
for (const bool enable : {true, false}) {
grmhd::ValenciaDivClean::FixConservatives variable_fixer{
1.e-12, 1.0e-11, 1.0e-10, 1.0e-9, 0.0, 0.0, 1.e-12, 0.0, enable};
1.e-12, 1.0e-11,
1.0e-10, 1.0e-9,
0.0, 0.0,
1.e-12, 0.0,
enable, hydro::MagneticFieldTreatment::AssumeNonZero};
test_variable_fixer(serialize_and_deserialize(variable_fixer), enable);
test_serialization(variable_fixer);
}
Expand All @@ -159,7 +168,8 @@ SPECTRE_TEST_CASE("Unit.Evolution.GrMhd.ValenciaDivClean.FixConservatives",
"SafetyFactorForS: 0.0\n"
"SafetyFactorForSCutoffD: 1.0e-12\n"
"SafetyFactorForSSlope: 0.0\n"
"Enable: true\n");
"Enable: true\n"
"MagneticField: AssumeNonZero\n");
test_variable_fixer(fixer_from_options, true);

run_benchmark(false);
Expand Down

0 comments on commit 25015c5

Please sign in to comment.