Skip to content

Commit dc90720

Browse files
committed
udpate Blast.cpp
1 parent 390989c commit dc90720

2 files changed

Lines changed: 25 additions & 80 deletions

File tree

inputs/RandomBlast.in

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
# Problem size and geometry
33
# *****************************************************************
44
geometry.prob_lo = 0.0 0.0 0.0
5-
geometry.prob_hi = 3.086e20 3.086e20 3.086e20 # 100 x 100 x 100 pc
6-
geometry.is_periodic = 1 1 1
7-
use_periodic_bc = 1
5+
geometry.prob_hi = 3.086e19 3.086e19 3.086e19 # 10 x 10 x 10 pc
6+
quokka.bc = reflecting reflecting reflecting
87

98
# *****************************************************************
109
# VERBOSITY
@@ -20,7 +19,7 @@ amr.blocking_factor = 16 # grid size must be divisible by this
2019
amr.max_grid_size = 64
2120

2221
regrid_interval = 2
23-
refine_threshold = 0.1
22+
problem.refine_threshold = 0.1
2423
do_reflux = 1
2524
do_subcycle = 0
2625

@@ -35,9 +34,11 @@ max_timesteps = 20000
3534
dt_initial = 3.154e10 # 1000 yr
3635
stop_time = 3.154e13 # 1e6 yr
3736

38-
SN_rate_per_volume = 0.03 # yr^-1 kpc^-1
39-
4037
cooling.enabled = 1
4138
cooling.read_tables_even_if_disabled = 1
4239
cooling.cooling_table_type = resampled
4340
cooling.hdf5_data_file = "../extern/cooling/CloudyData_UVB=HM2012_resampled.h5"
41+
42+
tiny_profiler.enabled = 1
43+
44+
particles.verbose = 0

src/problems/RandomBlast/testRandomBlast.cpp

Lines changed: 18 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,21 @@
44
// Released under the MIT license. See LICENSE file included in the GitHub repo.
55
//==============================================================================
66
/// \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.
88
///
9-
#include "AMReX.H"
10-
#include "AMReX_BLProfiler.H"
119
#include "AMReX_BLassert.H"
1210
#include "AMReX_Geometry.H"
1311
#include "AMReX_MultiFab.H"
14-
#include "AMReX_ParallelDescriptor.H"
15-
#include "AMReX_REAL.H"
1612
#include <fmt/format.h>
1713

1814
#include "QuokkaSimulation.hpp"
1915
#include "fundamental_constants.H"
2016
#include "hydro/hydro_system.hpp"
2117
#include "physics_info.hpp"
22-
#include "util/BC.hpp"
23-
24-
using amrex::Real;
2518

2619
struct RandomBlast {
2720
}; // dummy type to allow compile-type polymorphism via template specialization
2821

29-
constexpr double seconds_in_year = 3.1536e7;
30-
constexpr double parsec_in_cm = C::parsec; // cm == 1 pc
3122
constexpr double m_H = C::m_p + C::m_e; // mass of hydrogen atom
3223

3324
template <> struct Physics_Traits<RandomBlast> {
@@ -58,14 +49,10 @@ constexpr Real cloudy_H_mass_fraction = 1.0 / (1.0 + 0.1 * 3.971);
5849
constexpr Real rho0 = nH0 * (m_H / cloudy_H_mass_fraction); // g cm^-3
5950

6051
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
6654

6755
Real refine_threshold = 1.0; // gradient refinement threshold
68-
int use_periodic_bc = 1; // default is periodic
6956
};
7057

7158
template <> void QuokkaSimulation<RandomBlast>::setInitialConditionsOnGrid(quokka::grid const &grid_elem)
@@ -121,29 +108,11 @@ template <> void QuokkaSimulation<RandomBlast>::createInitialStochasticStellarPo
121108
}
122109
}
123110

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-
143111
template <> void QuokkaSimulation<RandomBlast>::computeAfterTimestep()
144112
{
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);
147116
}
148117

149118
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
212181
// This problem is only implemented in CGS units because the cooling tables are provided in CGS units.
213182
static_assert(Physics_Traits<RandomBlast>::unit_system == UnitSystem::CGS);
214183

215-
// read parameters
216-
amrex::ParmParse const pp;
184+
QuokkaSimulation<RandomBlast> sim;
217185

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
241189

242190
// Set initial conditions
243191
sim.setInitialConditions();
244192

245-
// set random state
246-
const int seed = 42;
247-
amrex::InitRandom(seed, 1); // all ranks should produce the same values
248-
249193
// run simulation
250194
sim.evolve();
251195

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+
}
257203

258-
// Cleanup and exit
259-
const int status = 0;
260-
return status;
204+
return 0;
261205
}

0 commit comments

Comments
 (0)