Skip to content

Commit 82600a7

Browse files
committed
Enable floor reporting
1 parent ff5576c commit 82600a7

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

src/eos/adiabatic_hydro.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,29 @@ void AdiabaticHydroEOS::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

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

src/eos/adiabatic_hydro.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ class AdiabaticHydroEOS : public EquationOfState {
4949
// int& j, const int& i) \brief Fills an array of primitives given an array of
5050
// conserveds, potentially updating the conserved with floors
5151
template <typename View4D>
52-
KOKKOS_INLINE_FUNCTION void ConsToPrim(View4D cons, View4D prim, const int &nhydro,
53-
const int &nscalars, const int &k, const int &j,
54-
const int &i) const {
52+
KOKKOS_INLINE_FUNCTION int ConsToPrim(View4D cons, View4D prim, const int &nhydro,
53+
const int &nscalars, const int &k, const int &j,
54+
const int &i) const {
55+
int floors_used = 0;
5556
Real gm1 = GetGamma() - 1.0;
5657
auto density_floor_ = GetDensityFloor();
5758
auto pressure_floor_ = GetPressureFloor();
@@ -72,13 +73,19 @@ class AdiabaticHydroEOS : public EquationOfState {
7273
Real &w_vz = prim(IV3, k, j, i);
7374
Real &w_p = prim(IPR, k, j, i);
7475

76+
PARTHENON_REQUIRE(u_d != 0.0,
77+
"Densities should never be exactly 0! This points to working with "
78+
"some default initialized and/or uninitialized data.");
7579
// Let's apply floors explicitly, i.e., by default floor will be disabled (<=0)
7680
// and the code will fail if a negative density is encountered.
7781
PARTHENON_REQUIRE(u_d > 0.0 || density_floor_ > 0.0,
7882
"Got negative density. Consider enabling first-order flux "
7983
"correction or setting a reasonble density floor.");
8084
// apply density floor, without changing momentum or energy
81-
u_d = (u_d > density_floor_) ? u_d : density_floor_;
85+
if (u_d < density_floor_) {
86+
u_d = density_floor_;
87+
floors_used = floors_used | 1; // set density floor flag
88+
}
8289
w_d = u_d;
8390

8491
Real di = 1.0 / u_d;
@@ -117,6 +124,7 @@ class AdiabaticHydroEOS : public EquationOfState {
117124
// apply pressure floor, correct total energy
118125
u_e = (pressure_floor_ / gm1) + e_k;
119126
w_p = pressure_floor_;
127+
floors_used = floors_used | 2; // set pressure floor flag
120128
}
121129

122130
// temperature (internal energy) based pressure floor
@@ -125,6 +133,7 @@ class AdiabaticHydroEOS : public EquationOfState {
125133
// apply temperature floor, correct total energy
126134
u_e = (u_d * e_floor_) + e_k;
127135
w_p = eff_pressure_floor;
136+
floors_used = floors_used | 4; // set temperture floor flag
128137
}
129138

130139
// temperature (internal energy) based pressure ceiling
@@ -139,6 +148,7 @@ class AdiabaticHydroEOS : public EquationOfState {
139148
for (auto n = nhydro; n < nhydro + nscalars; ++n) {
140149
prim(n, k, j, i) = cons(n, k, j, i) * di;
141150
}
151+
return floors_used;
142152
}
143153

144154
private:

src/hydro/hydro.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
522522
auto mbar_over_kb = pkg->Param<Real>("mbar_over_kb");
523523
efloor = Tfloor / mbar_over_kb / (gamma - 1.0);
524524
}
525+
pkg->AddParam<>("dfloor", dfloor);
526+
pkg->AddParam<>("pfloor", pfloor);
527+
pkg->AddParam<>("Tfloor", Tfloor);
525528

526529
// By default disable ceilings by setting to infinity
527530
Real vceil =

src/hydro/hydro_driver.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,25 @@ TaskCollection HydroDriver::MakeTaskCollection(BlockList_t &blocks, int stage) {
591591
if (hydro_pkg->Param<bool>("first_order_flux_correct")) {
592592
msg << hydro_pkg->Param<std::int64_t>("fixed_num_cells_fofc") << " FOFC. ";
593593
}
594+
if (hydro_pkg->Param<Real>("dfloor") > 0.0) {
595+
msg << hydro_pkg->Param<std::int64_t>("fixed_num_cells_floor_rho")
596+
<< " dfloor. ";
597+
}
598+
if (hydro_pkg->Param<Real>("pfloor") > 0.0) {
599+
msg << hydro_pkg->Param<std::int64_t>("fixed_num_cells_floor_pres")
600+
<< " pfloor. ";
601+
}
602+
if (hydro_pkg->Param<Real>("Tfloor") > 0.0) {
603+
msg << hydro_pkg->Param<std::int64_t>("fixed_num_cells_floor_temp")
604+
<< " Tfloor. ";
605+
}
594606
std::cout << msg.str() << "\n";
595607
}
596608

597609
// reset counter for next stage
610+
hydro_pkg->UpdateParam<std::int64_t>("fixed_num_cells_floor_rho", 0);
611+
hydro_pkg->UpdateParam<std::int64_t>("fixed_num_cells_floor_pres", 0);
612+
hydro_pkg->UpdateParam<std::int64_t>("fixed_num_cells_floor_temp", 0);
598613
hydro_pkg->UpdateParam<std::int64_t>("fixed_num_cells_fofc", 0);
599614
return TaskStatus::complete;
600615
},

0 commit comments

Comments
 (0)