|
4 | 4 | // Released under the MIT license. See LICENSE file included in the GitHub repo. |
5 | 5 | //============================================================================== |
6 | 6 | /// \file testRandomBlast.cpp |
7 | | -/// \brief Implements the random blast problem with radiative cooling. |
| 7 | +/// \brief Implements the random blast problem with particles, self-gravity, and Grackle cooling. |
8 | 8 | /// |
9 | | -#include "AMReX.H" |
10 | | -#include "AMReX_BLProfiler.H" |
11 | 9 | #include "AMReX_BLassert.H" |
12 | 10 | #include "AMReX_Geometry.H" |
13 | 11 | #include "AMReX_MultiFab.H" |
14 | | -#include "AMReX_ParallelDescriptor.H" |
15 | | -#include "AMReX_REAL.H" |
16 | 12 | #include <fmt/format.h> |
17 | 13 |
|
18 | 14 | #include "QuokkaSimulation.hpp" |
19 | 15 | #include "fundamental_constants.H" |
20 | 16 | #include "hydro/hydro_system.hpp" |
21 | 17 | #include "physics_info.hpp" |
22 | | -#include "util/BC.hpp" |
23 | | - |
24 | | -using amrex::Real; |
25 | 18 |
|
26 | 19 | struct RandomBlast { |
27 | 20 | }; // dummy type to allow compile-type polymorphism via template specialization |
28 | 21 |
|
29 | | -constexpr double seconds_in_year = 3.1536e7; |
30 | | -constexpr double parsec_in_cm = C::parsec; // cm == 1 pc |
31 | 22 | constexpr double m_H = C::m_p + C::m_e; // mass of hydrogen atom |
32 | 23 |
|
33 | 24 | template <> struct Physics_Traits<RandomBlast> { |
@@ -58,14 +49,10 @@ constexpr Real cloudy_H_mass_fraction = 1.0 / (1.0 + 0.1 * 3.971); |
58 | 49 | constexpr Real rho0 = nH0 * (m_H / cloudy_H_mass_fraction); // g cm^-3 |
59 | 50 |
|
60 | 51 | template <> struct SimulationData<RandomBlast> { |
61 | | - int SN_counter_cumulative = 0; // Track total number of SNe |
62 | | - |
63 | | - Real SN_rate_per_vol = NAN; // rate per unit time per unit volume |
64 | | - Real E_blast = 1.0e51; // ergs |
65 | | - Real M_ejecta = 0; // 10.0 * Msun; // g |
| 52 | + int SN_counter_cumulative = 0; // Track cumulative number of SNe at current time |
| 53 | + std::vector<int> SN_counter_arr; // Track cumulative number of SNe at all time |
66 | 54 |
|
67 | 55 | Real refine_threshold = 1.0; // gradient refinement threshold |
68 | | - int use_periodic_bc = 1; // default is periodic |
69 | 56 | }; |
70 | 57 |
|
71 | 58 | template <> void QuokkaSimulation<RandomBlast>::setInitialConditionsOnGrid(quokka::grid const &grid_elem) |
@@ -121,29 +108,11 @@ template <> void QuokkaSimulation<RandomBlast>::createInitialStochasticStellarPo |
121 | 108 | } |
122 | 109 | } |
123 | 110 |
|
124 | | -template <> void QuokkaSimulation<RandomBlast>::computeBeforeTimestep() |
125 | | -{ |
126 | | - // compute how many SNe will go off on this coarse timestep |
127 | | - // sample from Poisson distribution |
128 | | - const Real dt_coarse = dt_[0]; |
129 | | - const Real domain_vol = geom[0].ProbSize(); |
130 | | - const Real expectation_value = userData_.SN_rate_per_vol * domain_vol * dt_coarse; |
131 | | - |
132 | | - const int count = static_cast<int>(amrex::RandomPoisson(expectation_value)); |
133 | | - if (count > 0) { |
134 | | - amrex::Print() << "\t" << count << " SNe to be exploded.\n"; |
135 | | - } |
136 | | - |
137 | | - userData_.SN_counter_cumulative += count; |
138 | | - |
139 | | - // SN feedback is handled automatically by the StochasticStellarPop particles |
140 | | - // TODO(ben): need to force refinement to highest level for cells near particles |
141 | | -} |
142 | | - |
143 | 111 | template <> void QuokkaSimulation<RandomBlast>::computeAfterTimestep() |
144 | 112 | { |
145 | | - // With SN feedback, mass is not conserved due to mass injection |
146 | | - // Instead, we track the cumulative injected mass and energy in problem_main |
| 113 | + // Count how many SN went off in this timestep |
| 114 | + userData_.SN_counter_cumulative += sn_count_; |
| 115 | + userData_.SN_counter_arr.push_back(userData_.SN_counter_cumulative); |
147 | 116 | } |
148 | 117 |
|
149 | 118 | template <> void QuokkaSimulation<RandomBlast>::ComputeDerivedVar(int lev, std::string const &dname, amrex::MultiFab &mf, const int ncomp_cc_in) const |
@@ -212,50 +181,25 @@ auto problem_main() -> int |
212 | 181 | // This problem is only implemented in CGS units because the cooling tables are provided in CGS units. |
213 | 182 | static_assert(Physics_Traits<RandomBlast>::unit_system == UnitSystem::CGS); |
214 | 183 |
|
215 | | - // read parameters |
216 | | - amrex::ParmParse const pp; |
| 184 | + QuokkaSimulation<RandomBlast> sim; |
217 | 185 |
|
218 | | - // read in SN rate |
219 | | - Real SN_rate_per_vol = NAN; |
220 | | - pp.query("SN_rate_per_volume", SN_rate_per_vol); // yr^-1 kpc^-3 |
221 | | - SN_rate_per_vol /= seconds_in_year; |
222 | | - SN_rate_per_vol /= std::pow(1.0e3 * parsec_in_cm, 3); |
223 | | - AMREX_ALWAYS_ASSERT(!std::isnan(SN_rate_per_vol)); |
224 | | - |
225 | | - // read in refinement threshold (relative gradient in density) |
226 | | - Real refine_threshold = 0.1; |
227 | | - pp.query("refine_threshold", refine_threshold); // dimensionless |
228 | | - |
229 | | - // use periodic boundary conditions or not |
230 | | - int use_periodic_bc = 0; |
231 | | - pp.query("use_periodic_bc", use_periodic_bc); |
232 | | - |
233 | | - // Problem initialization |
234 | | - auto BCs_cc = (use_periodic_bc == 1) ? quokka::BC<RandomBlast>(quokka::BCType::int_dir) : quokka::BC<RandomBlast>(quokka::BCType::reflecting); |
235 | | - |
236 | | - QuokkaSimulation<RandomBlast> sim(BCs_cc); |
237 | | - sim.densityFloor_ = 1.0e-5 * rho0; // density floor (to prevent vacuum) |
238 | | - sim.userData_.SN_rate_per_vol = SN_rate_per_vol; |
239 | | - sim.userData_.refine_threshold = refine_threshold; |
240 | | - sim.userData_.use_periodic_bc = use_periodic_bc; |
| 186 | + // read parameters |
| 187 | + amrex::ParmParse const pp("problem"); |
| 188 | + pp.query("refine_threshold", sim.userData_.refine_threshold); // dimensionless |
241 | 189 |
|
242 | 190 | // Set initial conditions |
243 | 191 | sim.setInitialConditions(); |
244 | 192 |
|
245 | | - // set random state |
246 | | - const int seed = 42; |
247 | | - amrex::InitRandom(seed, 1); // all ranks should produce the same values |
248 | | - |
249 | 193 | // run simulation |
250 | 194 | sim.evolve(); |
251 | 195 |
|
252 | | - // print injected energy, injected mass |
253 | | - const Real E_in_cumulative = static_cast<Real>(sim.userData_.SN_counter_cumulative) * sim.userData_.E_blast; |
254 | | - const Real M_in_cumulative = static_cast<Real>(sim.userData_.SN_counter_cumulative) * sim.userData_.M_ejecta; |
255 | | - amrex::Print() << "Cumulative injected energy = " << E_in_cumulative << "\n"; |
256 | | - amrex::Print() << "Cumulative injected mass = " << M_in_cumulative << "\n"; |
| 196 | + if (amrex::ParallelDescriptor::IOProcessor()) { |
| 197 | + amrex::Print() << "\nCumulative N_sn = ["; |
| 198 | + for (auto const &i : sim.userData_.SN_counter_arr) { |
| 199 | + amrex::Print() << i << ", "; |
| 200 | + } |
| 201 | + amrex::Print() << "]\n"; |
| 202 | + } |
257 | 203 |
|
258 | | - // Cleanup and exit |
259 | | - const int status = 0; |
260 | | - return status; |
| 204 | + return 0; |
261 | 205 | } |
0 commit comments