12#include "gadgetconfig.h"
22#include "../cooling_sfr/cooling.h"
23#include "../data/allvars.h"
24#include "../data/dtypes.h"
25#include "../logs/logs.h"
26#include "../system/system.h"
27#include "../time_integration/timestep.h"
43 for(
int bin = 0; bin <
TIMEBINS; bin++)
45 Sp->TimeBinSfr[bin] = 0;
49 gas_state gs = GasState;
50 do_cool_data dc = DoCoolData;
79 if(dens <
All.OverDensThresh)
84 Sp->
SphP[target].Sfr = 0;
85 cool_sph_particle(Sp, target, &gs, &dc);
94 double egyhot =
All.EgySpecSN / (1 + factorEVP) +
All.EgySpecCold;
96 double ne = Sp->
SphP[target].Ne;
98 double tcool = GetCoolingTime(egyhot, dens *
All.
cf_a3inv, &ne, &gs, &dc);
99 Sp->
SphP[target].Ne = ne;
101 double y = tsfr / tcool * egyhot / (
All.FactorSN *
All.EgySpecSN - (1 -
All.FactorSN) *
All.EgySpecCold);
103 double x = 1 + 1 / (2 * y) -
sqrt(1 / y + 1 / (4 * y * y));
105 double egyeff = egyhot * (1 - x) +
All.EgySpecCold * x;
107 double cloudmass = x * Sp->
P[target].
getMass();
117 double trelax = tsfr * (1 - x) / x / (
All.FactorSN * (1 + factorEVP));
118 double egycurrent = utherm;
121 if(egycurrent > egyeff)
123 double dtcool = dtime;
124 ne = Sp->
SphP[target].Ne;
126 unew = DoCooling(egycurrent, dens *
All.
cf_a3inv, dtcool, &ne, &gs, &dc);
134 unew = (egyeff + (egycurrent - egyeff) *
exp(-dtime / trelax));
136 double du = unew - utherm;
144#ifdef OUTPUT_COOLHEAT
146 Sp->
SphP[target].CoolHeat = du * Sp->
P[target].
getMass() / dtime;
152 if(utherm > 1.01 * egyeff)
153 Sp->
SphP[target].Sfr = 0;
157 Sp->
SphP[target].Sfr =
175void coolsfr::init_clouds(
void)
177 gas_state gs = GasState;
178 do_cool_data dc = DoCoolData;
180 if(
All.PhysDensThresh == 0)
182 double A0 =
All.FactorEVP;
184 double egyhot =
All.EgySpecSN / A0;
207 double tcool = GetCoolingTime(egyhot, dens, &ne, &gs, &dc);
209 double coolrate = egyhot / tcool / dens;
211 double x = (egyhot - u4) / (egyhot -
All.EgySpecCold);
214 x /
pow(1 - x, 2) * (
All.FactorSN *
All.EgySpecSN - (1 -
All.FactorSN) *
All.EgySpecCold) / (
All.MaxSfrTimescale * coolrate);
217 "\nA0= %g \nComputed: PhysDensThresh= %g (int units) %g h^2 cm^-3\nEXPECTED FRACTION OF COLD GAS AT THRESHOLD = "
218 "%g\n\ntcool=%g dens=%g egyhot=%g\n",
222 dens =
All.PhysDensThresh * 10;
227 double tsfr =
sqrt(
All.PhysDensThresh / (dens)) *
All.MaxSfrTimescale;
228 double factorEVP =
pow(dens /
All.PhysDensThresh, -0.8) *
All.FactorEVP;
229 egyhot =
All.EgySpecSN / (1 + factorEVP) +
All.EgySpecCold;
233 tcool = GetCoolingTime(egyhot, dens, &ne, &gs, &dc);
235 double y = tsfr / tcool * egyhot / (
All.FactorSN *
All.EgySpecSN - (1 -
All.FactorSN) *
All.EgySpecCold);
236 x = 1 + 1 / (2 * y) -
sqrt(1 / y + 1 / (4 * y * y));
237 double egyeff = egyhot * (1 - x) +
All.EgySpecCold * x;
241 double fac = 1 / (
log(dens * 1.025) -
log(dens));
244 neff = -
log(peff) * fac;
246 tsfr =
sqrt(
All.PhysDensThresh / (dens)) *
All.MaxSfrTimescale;
247 factorEVP =
pow(dens /
All.PhysDensThresh, -0.8) *
All.FactorEVP;
248 egyhot =
All.EgySpecSN / (1 + factorEVP) +
All.EgySpecCold;
252 tcool = GetCoolingTime(egyhot, dens, &ne, &gs, &dc);
254 y = tsfr / tcool * egyhot / (
All.FactorSN *
All.EgySpecSN - (1 -
All.FactorSN) *
All.EgySpecCold);
255 x = 1 + 1 / (2 * y) -
sqrt(1 / y + 1 / (4 * y * y));
256 egyeff = egyhot * (1 - x) +
All.EgySpecCold * x;
260 neff +=
log(peff) * fac;
262 while(neff > 4.0 / 3);
264 double thresholdStarburst = dens;
266 mpi_printf(
"Run-away sets in for dens=%g\nDynamic range for quiescent star formation= %g\n", thresholdStarburst,
267 thresholdStarburst /
All.PhysDensThresh);
273 double sigma = 10.0 /
All.
Hubble * 1.0e-10 /
pow(1.0e-3, 2);
275 printf(
"Isotherm sheet central density: %g z0=%g\n",
M_PI *
All.
G * sigma * sigma / (2 *
GAMMA_MINUS1) / u4,
300void coolsfr::integrate_sfr(
void)
305 gas_state gs = GasState;
306 do_cool_data dc = DoCoolData;
315 FILE *fd = (WriteMiscFiles && (ThisTask == 0)) ? fopen(
"eos.txt",
"w") : NULL;
317 for(
double rho =
All.PhysDensThresh; rho <= 1000 *
All.PhysDensThresh; rho *= 1.1)
319 double tsfr =
sqrt(
All.PhysDensThresh / rho) *
All.MaxSfrTimescale;
321 double factorEVP =
pow(rho /
All.PhysDensThresh, -0.8) *
All.FactorEVP;
323 double egyhot =
All.EgySpecSN / (1 + factorEVP) +
All.EgySpecCold;
327 double tcool = GetCoolingTime(egyhot, rho, &ne, &gs, &dc);
329 double y = tsfr / tcool * egyhot / (
All.FactorSN *
All.EgySpecSN - (1 -
All.FactorSN) *
All.EgySpecCold);
330 double x = 1 + 1 / (2 * y) -
sqrt(1 / y + 1 / (4 * y * y));
332 double egyeff = egyhot * (1 - x) +
All.EgySpecCold * x;
336 if(WriteMiscFiles && (ThisTask == 0))
338 fprintf(fd,
"%g %g\n", rho, P0);
342 if(WriteMiscFiles && (ThisTask == 0))
345 fd = fopen(
"sfrrate.txt",
"w");
348 for(
double rho0 =
All.PhysDensThresh; rho0 <= 10000 *
All.PhysDensThresh; rho0 *= 1.02)
354 double sigma = 0, sigmasfr = 0, sigma_u4 = 0, x = 0;
356 while(rho > 0.0001 * rho0)
358 double tsfr, P0, gam;
359 if(rho >
All.PhysDensThresh)
361 tsfr =
sqrt(
All.PhysDensThresh / rho) *
All.MaxSfrTimescale;
363 double factorEVP =
pow(rho /
All.PhysDensThresh, -0.8) *
All.FactorEVP;
365 double egyhot =
All.EgySpecSN / (1 + factorEVP) +
All.EgySpecCold;
369 double tcool = GetCoolingTime(egyhot, rho, &ne, &gs, &dc);
371 double y = tsfr / tcool * egyhot / (
All.FactorSN *
All.EgySpecSN - (1 -
All.FactorSN) *
All.EgySpecCold);
372 x = 1 + 1 / (2 * y) -
sqrt(1 / y + 1 / (4 * y * y));
374 double egyeff = egyhot * (1 - x) +
All.EgySpecCold * x;
379 double rho2 = 1.1 * rho;
380 double tsfr2 =
sqrt(
All.PhysDensThresh / rho2) *
All.MaxSfrTimescale;
381 double factorEVP2 =
pow(rho2 /
All.PhysDensThresh, -0.8) *
All.FactorEVP;
382 double egyhot2 =
All.EgySpecSN / (1 + factorEVP2) +
All.EgySpecCold;
384 double tcool2 = GetCoolingTime(egyhot2, rho2, &ne, &gs, &dc);
385 double y2 = tsfr2 / tcool2 * egyhot2 / (
All.FactorSN *
All.EgySpecSN - (1 -
All.FactorSN) *
All.EgySpecCold);
386 double x2 = 1 + 1 / (2 * y2) -
sqrt(1 / y2 + 1 / (4 * y2 * y2));
387 double egyeff2 = egyhot2 * (1 - x2) +
All.EgySpecCold * x2;
390 gam =
log(P2 / P1) /
log(rho2 / rho);
399 sigma_u4 += rho * dz;
403 double dq = -(gam - 2) / rho * q * q - 4 *
M_PI *
All.
G / (gam * P0) * rho * rho * rho;
408 sigmasfr += (1 -
All.FactorSN) * rho * x / tsfr * dz;
423 if(WriteMiscFiles && (ThisTask == 0))
425 fprintf(fd,
"%g %g %g %g\n", rho0, sigma, sigmasfr, sigma_u4);
436 if(WriteMiscFiles && (ThisTask == 0))
442void coolsfr::set_units_sfr(
void)
global_data_all_processes All
double get_utherm_from_entropy(int i)
void set_entropy_from_utherm(double utherm, int i)
TimeBinData TimeBinsHydro
int TimeBinSynchronized[TIMEBINS]
#define HYDROGEN_MASSFRAC
#define TIMER_START(counter)
Starts the timer counter.
#define TIMER_STOP(counter)
Stops the timer counter.
expr pow(half base, half exp)
double UnitDensity_in_cgs
int ComovingIntegrationOn
void set_cosmo_factors_for_current_time(void)
unsigned char getTimeBinHydro(void)
unsigned char getType(void)
void set_thermodynamic_variables(void)
void myflush(FILE *fstream)