Skip to content

Commit d3c882f

Browse files
committed
Add floor reporting for MHD
1 parent 411599d commit d3c882f

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/eos/adiabatic_glmmhd.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,30 @@ void AdiabaticGLMMHDEOS::ConservedToPrimitive(MeshData<Real> *md) const {
4343

4444
auto this_on_device = (*this);
4545

46-
parthenon::par_for(
46+
std::int64_t floor_rho, floor_pres, floor_temp;
47+
parthenon::par_reduce(
4748
DEFAULT_LOOP_PATTERN, "ConservedToPrimitive", parthenon::DevExecSpace(), 0,
4849
cons_pack.GetDim(5) - 1, kb.s, kb.e, jb.s, jb.e, ib.s, ib.e,
49-
KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
50+
KOKKOS_LAMBDA(const int b, const int k, const int j, const int i,
51+
std::int64_t &lfloor_rho, std::int64_t &lfloor_pres,
52+
std::int64_t &lfloor_temp) {
5053
const auto &cons = cons_pack(b);
5154
auto &prim = prim_pack(b);
5255
// auto &nu = entropy_pack(b);
5356

54-
return this_on_device.ConsToPrim(cons, prim, nhydro, nscalars, k, j, i);
55-
});
57+
auto floors_used =
58+
this_on_device.ConsToPrim(cons, prim, nhydro, nscalars, k, j, i);
59+
if (floors_used & 1) lfloor_rho += 1;
60+
if (floors_used & 2) lfloor_pres += 1;
61+
if (floors_used & 4) lfloor_temp += 1;
62+
},
63+
floor_rho, floor_pres, floor_temp);
64+
const auto floor_rho_pkg = pkg->Param<std::int64_t>("fixed_num_cells_floor_rho");
65+
pkg->UpdateParam<std::int64_t>("fixed_num_cells_floor_rho", floor_rho_pkg + floor_rho);
66+
const auto floor_pres_pkg = pkg->Param<std::int64_t>("fixed_num_cells_floor_pres");
67+
pkg->UpdateParam<std::int64_t>("fixed_num_cells_floor_pres",
68+
floor_pres_pkg + floor_pres);
69+
const auto floor_temp_pkg = pkg->Param<std::int64_t>("fixed_num_cells_floor_temp");
70+
pkg->UpdateParam<std::int64_t>("fixed_num_cells_floor_temp",
71+
floor_temp_pkg + floor_temp);
5672
}

src/eos/adiabatic_glmmhd.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ class AdiabaticGLMMHDEOS : public EquationOfState {
6363
// int& j, const int& i) \brief Fills an array of primitives given an array of
6464
// conserveds, potentially updating the conserved with floors
6565
template <typename View4D>
66-
KOKKOS_INLINE_FUNCTION void ConsToPrim(View4D cons, View4D prim, const int &nhydro,
67-
const int &nscalars, const int &k, const int &j,
68-
const int &i) const {
66+
KOKKOS_INLINE_FUNCTION int ConsToPrim(View4D cons, View4D prim, const int &nhydro,
67+
const int &nscalars, const int &k, const int &j,
68+
const int &i) const {
69+
int floors_used = 0;
6970
auto gam = GetGamma();
7071
auto gm1 = gam - 1.0;
7172
auto density_floor_ = GetDensityFloor();
@@ -95,13 +96,19 @@ class AdiabaticGLMMHDEOS : public EquationOfState {
9596
Real &w_Bz = prim(IB3, k, j, i);
9697
Real &w_psi = prim(IPS, k, j, i);
9798

99+
PARTHENON_REQUIRE(u_d != 0.0,
100+
"Densities should never be exactly 0! This points to working with "
101+
"some default initialized and/or uninitialized data.");
98102
// Let's apply floors explicitly, i.e., by default floor will be disabled (<=0)
99103
// and the code will fail if a negative density is encountered.
100104
PARTHENON_REQUIRE(u_d > 0.0 || density_floor_ > 0.0,
101105
"Got negative density. Consider enabling first-order flux "
102106
"correction or setting a reasonble density floor.");
103107
// apply density floor, without changing momentum or energy
104-
u_d = (u_d > density_floor_) ? u_d : density_floor_;
108+
if (u_d < density_floor_) {
109+
u_d = density_floor_;
110+
floors_used = floors_used | 1; // set density floor flag
111+
}
105112
w_d = u_d;
106113

107114
Real di = 1.0 / u_d;
@@ -146,6 +153,7 @@ class AdiabaticGLMMHDEOS : public EquationOfState {
146153
// apply pressure floor, correct total energy
147154
u_e = (pressure_floor_ / gm1) + e_k + e_B;
148155
w_p = pressure_floor_;
156+
floors_used = floors_used | 2; // set pressure floor flag
149157
}
150158

151159
// temperature (internal energy) based pressure floor
@@ -154,6 +162,7 @@ class AdiabaticGLMMHDEOS : public EquationOfState {
154162
// apply temperature floor, correct total energy
155163
u_e = (u_d * e_floor_) + e_k + e_B;
156164
w_p = eff_pressure_floor;
165+
floors_used = floors_used | 4; // set temperture floor flag
157166
}
158167

159168
// temperature (internal energy) based pressure ceiling
@@ -168,6 +177,7 @@ class AdiabaticGLMMHDEOS : public EquationOfState {
168177
for (auto n = nhydro; n < nhydro + nscalars; ++n) {
169178
prim(n, k, j, i) = cons(n, k, j, i) * di;
170179
}
180+
return floors_used;
171181
}
172182

173183
private:

src/eos/adiabatic_hydro.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ class AdiabaticHydroEOS : public EquationOfState {
187187
// apply density floor, without changing momentum or energy
188188
u_d = w_d;
189189

190-
Real di = 1.0 / u_d;
191190
u_m1 = w_d * w_vx;
192191
u_m2 = w_d * w_vy;
193192
u_m3 = w_d * w_vz;

0 commit comments

Comments
 (0)