Corentin Cadiou
PDRA @ Lund Sweden
Chargé de recherche @ IAP from February
Star formation rate is given by
\[\frac{\Delta M_\star}{\Delta t} = \epsilon_\mathrm{ff} \frac{m_\mathrm{g}} {t_\mathrm{ff}} \propto m_\mathrm{g}^{3/2},\]
where
SF is only allowed in cells with
\[n_\mathrm{H}>n_\mathrm{th} \quad\text{and}\quad T<T_\mathrm{th},\]
where \(n_\mathrm{th}\) and \(T_\mathrm{th}\) are user-defined density and temperature thresholds (typically \(\sim 10\,\mathrm{cm^{-3}}\) and \(\sim 500-1000\,\mathrm{K}\)).
Stellar particle has mass
\[M_\star=N\times m_\star,\quad \text{with}\quad m_\star = n_\mathrm{th}\Delta x_\mathrm{min}^3 \text{ and } N \sim \mathcal{P}\left(\frac{m_\star}{\Delta M_\star}\right).\]
Note: this is mini-ramses' implementation
Mass conservation:
\[\dot m_\mathrm{g}+Km_\mathrm{g}^{3/2}=0,\]
where \(K = \sqrt{\frac{\epsilon_\mathrm{ff}^2 G}{0.5427 V}}\), \(V=(10\,\mathrm{pc})^3\) and \(G\) the gravitational constant.
The solution to this equation is
\[m_\mathrm{g} = \frac{4}{(K t - b)^2},\]
with \(b = \sqrt{4 / m_\mathrm{g,i}}\). Given mass conservation, we get the total stellar mass
\[M_\star(t) = m_\mathrm{g,i}-\frac{4}{(K t - b)^2}.\]
// First pass, count number of cells elligible for SF
uint Nformation_sites = 0;
foreach_cell.reduce_cell( "star_formation_count", U.getShape(),
CELL_LAMBDA(const ForeachCell::CellIndex& iCell, uint32_t& count)
{
[...]
}, Nformation_sites);
// Create temporary views to store particle data
Kokkos::View<real_t*> mp("new_particle_mass", Nformation_sites);
Kokkos::View<real_t**> xp("new_particle_pos", Nformation_sites, 3);
Kokkos::View<real_t**> vp("new_particle_vel", Nformation_sites, 3);
// Second pass, effectively create particle properties
uint Npart_created = 0;
foreach_cell.reduce_cell( "star_formation_spawn", U.getShape(),
CELL_LAMBDA(const ForeachCell::CellIndex& iCell, uint32_t& count)
{
[...]
}, Npart_created);
// Increase the number of particles
uint32_t Npart_old = U.getParticleArray("particles").getNumParticles();
U.growParticleArray("particles", Npart_old + Npart_created);
// Copy the temporary views to the particle array
Kokkos::parallel_for("star_formation_create", Npart_created,
KOKKOS_LAMBDA(uint32_t iPart)
{
[...]
});
Shortcomings:
Theuns+98 implementation
\[\frac{\mathrm{d}u}{\mathrm{d}t} = \left(\frac{1-Y}{m_\mathrm{H}}\right)^2\rho({\color{red}\mathcal{H}}-{\color{blue}\mathcal{C}})\]
Test:
Note 1: \(T\) may be off by factors \(\mu\), \(\Lambda\) may be off by factor \(X\).
foreach_cell.foreach_cell("cooling", U.getShape(),
CELL_LAMBDA(const ForeachCell::CellIndex& iCell)
{
while (t_cool < dt * scale_t) {
// Get abundances (in eq or not)
real_t HI = interpolate( HI_table, iz, iT, inH);
[...]
real_t HeIII = interpolate(HeIII_table, iz, iT, inH);
real_t e = HII + HeII + 2 * HeIII;
// Compute heating/cooling terms [erg/s.cm**3]
real_t net_cooling, H, C;
C = cooling(T_over_mu, nH, z, e, HI, HII, HeI, HeII, HeIII);
H = heating(nH, z, HI, HeI, HeII);
// Compute cooling [K/s]
net_cooling = (C - H) * nH / threekB_over_twoX;
// Cooling timescale [s]
dt_cool = FMIN(
// do not allow more than 25% change in temperature
FABS(T_over_mu * 0.25 / net_cooling),
// do not overshoot the remaining time
dt * scale_t - t_cool
);
T_over_mu -= net_cooling * dt_cool;
// Update cooling time
t_cool += dt_cool;
Nstep++;
}
}};
Pros/cons:
The old RAMSES way
subroutine dummy_sfr
call units([...], scale_d, [...], aexp)
do icell = 1, ncell ! Loop over cells
rho = uold(icell, 1) / scale_d ! Convert to g/cm**3
rho = uold(icell, 1) * scale_d ! Which one is correct?
rho = rho / mp ! Convert to mp/cm**3
if (rho < rho_treshold) then ! Implicit: rhs is in mp/cm**3
! do stuff
end if
end do
end subroutine
Discussion points:
// In kernel:
// real → code units [comoving]
real_t rho = Uin.at(iCell, IRho);
// The RAMSES' way
real_t rho_cgs = rho * some_conversion_factor;
// BETTER?
if (rho < rho_treshold.toCode) {...}
if (rho < 10 * mp_per_cc.toCode) {...}
rho * mp_per_cc.fromCode;
Discussion points:
[star_formation]
rho_threshold = 10 mp/cm**3
// Read config file: Dyablo's initialization
auto config = readConfig();
// Get runtime params: plugin initialization
auto rho_threshold = config.get<…>("star_formation", "rho_threshold");
typedef Density = Unit<M=1, L=-3>;
typedef Temperature = Unit<Temp=1>;
// In plugins:
// -- init --------------------------------------------------!
Quantity<Density> rho_threshold = configMap.get<Density>("star_formation", "rho_threshold");
auto T_threshold = configMap.get<Temperature>("star_formation", "T_threshold");
// -- update ------------------------------------------------!
auto erg = Units::erg;
auto s = Units::s;
auto cm3 = Units::cm.pow<3>();
Unit<M=1, L=3, T=-3> erg_per_s_cc (erg / s * cm3, scalarData);
real_t rho_threshold = this->rho_threshold.toCode(scalarData);
foreach_cell.reduce_cell("do_stuff", U.getShape(),
CELL_LAMBDA(const ForeachCell::CellIndex& iCell) {
real_t rho = Uin.at(iCell, VarIndex_Cooling::Irho);
if (rho > rho_threshold) {...}
real_t cooling_rate = table(...) * erg_per_s_cc.toCode;
real_t … = cooling_rate * erg_per_s_cc.fromCode;
});
// config.ini
[star_formation]
rho_threshold = 10 mp/cm**3