MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Macros | Enumerations | Functions
sfr_eff.h File Reference
#include "forcetree.h"
#include "utils/paramset.h"
#include "timestep.h"
#include "partmanager.h"
#include "slotsmanager.h"
#include "physconst.h"
Include dependency graph for sfr_eff.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define METAL_YIELD   0.02
 

Enumerations

enum  StarformationCriterion {
  SFR_CRITERION_DENSITY = 1 , SFR_CRITERION_MOLECULAR_H2 = 3 , SFR_CRITERION_SELFGRAVITY = 5 , SFR_CRITERION_CONVERGENT_FLOW = 13 ,
  SFR_CRITERION_CONTINUOUS_CUTOFF = 21
}
 

Functions

void set_sfr_params (ParameterSet *ps)
 
void init_cooling_and_star_formation (int CoolingOn, int StarformationOn, Cosmology *CP, const double avg_baryon_mass, const double BoxSize, const struct UnitSystem units)
 
void cooling_and_starformation (ActiveParticles *act, double Time, double dloga, ForceTree *tree, const Cosmology *CP, MyFloat *GradRho, FILE *FdSfr)
 
double get_neutral_fraction_sfreff (double redshift, double hubble, struct particle_data *partdata, struct sph_particle_data *sphdata)
 
double get_helium_neutral_fraction_sfreff (int ion, double redshift, double hubble, struct particle_data *partdata, struct sph_particle_data *sphdata)
 
int sfr_need_to_compute_sph_grad_rho (void)
 
int get_generations (void)
 
int sfreff_on_eeqos (const struct sph_particle_data *sph, const double a3inv)
 
double get_MinEgySpec (void)
 

Macro Definition Documentation

◆ METAL_YIELD

#define METAL_YIELD   0.02

effective metal yield for star formation

Definition at line 11 of file sfr_eff.h.

Enumeration Type Documentation

◆ StarformationCriterion

Enumerator
SFR_CRITERION_DENSITY 
SFR_CRITERION_MOLECULAR_H2 
SFR_CRITERION_SELFGRAVITY 
SFR_CRITERION_CONVERGENT_FLOW 
SFR_CRITERION_CONTINUOUS_CUTOFF 

Definition at line 16 of file sfr_eff.h.

16  {
18  SFR_CRITERION_MOLECULAR_H2 = 3, /* 2 + 1 */
19  SFR_CRITERION_SELFGRAVITY = 5, /* 4 + 1 */
20  /* below are additional flags in SELFGRAVITY */
21  SFR_CRITERION_CONVERGENT_FLOW = 13, /* 8 + 4 + 1 */
22  SFR_CRITERION_CONTINUOUS_CUTOFF= 21, /* 16 + 4 + 1 */
23 };
@ SFR_CRITERION_MOLECULAR_H2
Definition: sfr_eff.h:18
@ SFR_CRITERION_CONVERGENT_FLOW
Definition: sfr_eff.h:21
@ SFR_CRITERION_CONTINUOUS_CUTOFF
Definition: sfr_eff.h:22
@ SFR_CRITERION_SELFGRAVITY
Definition: sfr_eff.h:19
@ SFR_CRITERION_DENSITY
Definition: sfr_eff.h:17

Function Documentation

◆ cooling_and_starformation()

void cooling_and_starformation ( ActiveParticles act,
double  Time,
double  dloga,
ForceTree tree,
const Cosmology CP,
MyFloat GradRho,
FILE *  FdSfr 
)

Definition at line 167 of file sfr_eff.c.

168 {
169  const int nthreads = omp_get_max_threads();
170  /*This is a queue for the new stars and their parents, so we can reallocate the slots after the main cooling loop.*/
171  int * NewStars = NULL;
172  int * NewParents = NULL;
173  int64_t NumNewStar = 0, NumMaybeWind = 0;
174  int * MaybeWind = NULL;
175  MyFloat * StellarMass = NULL;
176 
177  size_t *nqthrsfr = ta_malloc("nqthrsfr", size_t, nthreads);
178  int **thrqueuesfr = ta_malloc("thrqueuesfr", int *, nthreads);
179  int **thrqueueparent = ta_malloc("thrqueueparent", int *, nthreads);
180  size_t *nqthrwind = NULL;
181  int **thrqueuewind = NULL;
182 
183  /*Need to capture this so that when NumActiveParticle increases during the loop
184  * we don't add extra loop iterations on particles with invalid slots.*/
185  const int nactive = act->NumActiveParticle;
186  const double a3inv = 1./(Time * Time * Time);
187  const double hubble = hubble_function(CP, Time);
188 
190  NewStars = (int *) mymalloc("NewStars", nactive * sizeof(int) * nthreads);
191  gadget_setup_thread_arrays(NewStars, thrqueuesfr, nqthrsfr, nactive, nthreads);
192  NewParents = (int *) mymalloc2("NewParents", nactive * sizeof(int) * nthreads);
193  gadget_setup_thread_arrays(NewParents, thrqueueparent, nqthrsfr, nactive, nthreads);
194  }
195 
197  nqthrwind = ta_malloc("nqthrwind", size_t, nthreads);
198  thrqueuewind = ta_malloc("thrqueuewind", int *, nthreads);
199  StellarMass = (MyFloat *) mymalloc("StellarMass", SlotsManager->info[0].size * sizeof(MyFloat));
200  MaybeWind = (int *) mymalloc("MaybeWind", nactive * sizeof(int) * nthreads);
201  gadget_setup_thread_arrays(MaybeWind, thrqueuewind, nqthrwind, nactive, nthreads);
202  }
203 
204 
205  /* Get the global UVBG for this redshift. */
206  const double redshift = 1./Time - 1;
207  struct UVBG GlobalUVBG = get_global_UVBG(redshift);
208  double sum_sm = 0, sum_mass_stars = 0, localsfr = 0;
209 
210  /* First decide which stars are cooling and which starforming. If star forming we add them to a list.
211  * Note the dynamic scheduling: individual particles may have very different loop iteration lengths.
212  * Cooling is much slower than sfr. I tried splitting it into a separate loop instead, but this was faster.*/
213  #pragma omp parallel reduction(+:localsfr) reduction(+: sum_sm) reduction(+:sum_mass_stars)
214  {
215  int i;
216  const int tid = omp_get_thread_num();
217  #pragma omp for schedule(static)
218  for(i=0; i < nactive; i++)
219  {
220  /*Use raw particle number if active_set is null, otherwise use active_set*/
221  const int p_i = act->ActiveParticle ? act->ActiveParticle[i] : i;
222  /* Skip non-gas or garbage particles */
223  if(P[p_i].Type != 0 || P[p_i].IsGarbage || P[p_i].Mass <= 0)
224  continue;
225 
226  int shall_we_star_form = 0;
228  /*Reduce delaytime for wind particles.*/
229  winds_evolve(p_i, a3inv, hubble);
230  /* check whether we are star forming gas.*/
232  shall_we_star_form = quicklyastarformation(p_i, a3inv);
233  else
234  shall_we_star_form = sfreff_on_eeqos(&SPHP(p_i), a3inv);
235  }
236 
237  if(shall_we_star_form) {
238  int newstar = -1;
239  MyFloat sm = 0;
241  /*New star is always the same particle as the parent for quicklya*/
242  newstar = p_i;
243  sum_sm += P[p_i].Mass;
244  sm = P[p_i].Mass;
245  } else {
246  newstar = starformation(p_i, &localsfr, &sm, GradRho, redshift, a3inv, hubble, CP->GravInternal, &GlobalUVBG);
247  sum_sm += P[p_i].Mass * (1 - exp(-sm/P[p_i].Mass));
248  }
249  /*Add this particle to the stellar conversion queue if necessary.*/
250  if(newstar >= 0) {
251  thrqueuesfr[tid][nqthrsfr[tid]] = newstar;
252  thrqueueparent[tid][nqthrsfr[tid]] = p_i;
253  nqthrsfr[tid]++;
254  }
255  /* Add this particle to the queue for consideration to spawn a wind.
256  * Only for subgrid winds. */
257  if(nqthrwind && newstar < 0) {
258  thrqueuewind[tid][nqthrwind[tid]] = p_i;
259  StellarMass[P[p_i].PI] = sm;
260  nqthrwind[tid]++;
261  }
262  }
263  else
264  cooling_direct(p_i, redshift, a3inv, hubble, &GlobalUVBG);
265  }
266  }
267 
268  report_memory_usage("SFR");
269 
270  walltime_measure("/Cooling/Cooling");
271 
272  /* Do subgrid winds*/
274  NumMaybeWind = gadget_compact_thread_arrays(MaybeWind, thrqueuewind, nqthrwind, nthreads);
275  winds_subgrid(MaybeWind, NumMaybeWind, Time, hubble, tree, StellarMass);
276  myfree(MaybeWind);
277  myfree(StellarMass);
278  ta_free(thrqueuewind);
279  ta_free(nqthrwind);
280  }
281 
282  /*Merge step for the queue.*/
283  if(NewStars) {
284  NumNewStar = gadget_compact_thread_arrays(NewStars, thrqueuesfr, nqthrsfr, nthreads);
285  int64_t NumNewParent = gadget_compact_thread_arrays(NewParents, thrqueueparent, nqthrsfr, nthreads);
286  if(NumNewStar != NumNewParent)
287  endrun(3,"%lu new stars, but %lu new parents!\n",NumNewStar, NumNewParent);
288  /*Shrink star memory as we keep it for the wind model*/
289  NewStars = (int *) myrealloc(NewStars, sizeof(int) * NumNewStar);
290  }
291 
292  ta_free(thrqueueparent);
293  ta_free(thrqueuesfr);
294  ta_free(nqthrsfr);
295 
296 
298  return;
299 
300  /*Get some empty slots for the stars*/
301  int firststarslot = SlotsManager->info[4].size;
302  /* We ran out of slots! We must be forming a lot of stars.
303  * There are things in the way of extending the slot list, so we have to move them.
304  * The code in sfr_reserve_slots is not elegant, but I cannot think of a better way.*/
305  if(sfr_params.StarformationOn && (SlotsManager->info[4].size + NumNewStar >= SlotsManager->info[4].maxsize)) {
306  if(NewParents)
307  NewParents = (int *) myrealloc(NewParents, sizeof(int) * NumNewStar);
308  NewStars = sfr_reserve_slots(act, NewStars, NumNewStar, tree);
309  }
310  SlotsManager->info[4].size += NumNewStar;
311 
312  int stars_converted=0, stars_spawned=0;
313  int i;
314 
315  /*Now we turn the particles into stars*/
316  #pragma omp parallel for schedule(static) reduction(+:stars_converted) reduction(+:stars_spawned) reduction(+:sum_mass_stars)
317  for(i=0; i < NumNewStar; i++)
318  {
319  int child = NewStars[i];
320  int parent = NewParents[i];
321  make_particle_star(child, parent, firststarslot+i, Time);
322  sum_mass_stars += P[child].Mass;
323  if(child == parent)
324  stars_converted++;
325  else
326  stars_spawned++;
327  }
328 
329  /*Done with the parents*/
330  myfree(NewParents);
331 
332  int64_t tot_spawned=0, tot_converted=0;
333  sumup_large_ints(1, &stars_spawned, &tot_spawned);
334  sumup_large_ints(1, &stars_converted, &tot_converted);
335 
336  double total_sum_mass_stars, total_sm, totsfrrate;
337 
338  MPI_Reduce(&localsfr, &totsfrrate, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
339  MPI_Reduce(&sum_sm, &total_sm, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
340  MPI_Reduce(&sum_mass_stars, &total_sum_mass_stars, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
341  if(FdSfr)
342  {
343  double rate = 0;
344 
345  if(dloga > 0)
346  rate = total_sm / (dloga / hubble);
347 
348  /* convert to solar masses per yr */
349 
350  double rate_in_msunperyear = rate * sfr_params.UnitSfr_in_solar_per_year;
351 
352  /* Format:
353  * Time = current scale factor,
354  * total_sm = expected change in stellar mass this timestep,
355  * totsfrrate = current star formation rate in active particles in Msun/year,
356  * rate_in_msunperyear = expected stellar mass formation rate in Msun/year from total_sm,
357  * total_sum_mass_stars = actual mass of stars formed this timestep (discretized total_sm) */
358  fprintf(FdSfr, "%g %g %g %g %g\n", Time, total_sm, totsfrrate, rate_in_msunperyear,
359  total_sum_mass_stars);
360  fflush(FdSfr);
361  }
362 
363  MPIU_Barrier(MPI_COMM_WORLD);
364  if(tot_spawned || tot_converted)
365  message(0, "SFR: spawned %ld stars, converted %ld gas particles into stars\n", tot_spawned, tot_converted);
366 
367  walltime_measure("/Cooling/StarFormation");
368 
369  /* Now apply the wind model using the list of new stars.*/
371  winds_and_feedback(NewStars, NumNewStar, Time, hubble, tree);
372 
373  myfree(NewStars);
374 }
struct UVBG get_global_UVBG(double redshift)
double hubble_function(const Cosmology *CP, double a)
Definition: cosmology.c:58
void message(int where, const char *fmt,...)
Definition: endrun.c:175
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
static double dloga
Definition: lightcone.c:21
#define mymalloc(name, size)
Definition: mymalloc.h:15
#define ta_malloc(name, type, nele)
Definition: mymalloc.h:25
#define myrealloc(ptr, size)
Definition: mymalloc.h:18
#define ta_free(p)
Definition: mymalloc.h:28
#define mymalloc2(name, size)
Definition: mymalloc.h:16
#define myfree(x)
Definition: mymalloc.h:19
#define report_memory_usage(x)
Definition: mymalloc.h:30
#define P
Definition: partmanager.h:88
static Cosmology * CP
Definition: power.c:27
static struct SFRParams sfr_params
static int starformation(int i, double *localsfr, MyFloat *sm_out, MyFloat *GradRho, const double redshift, const double a3inv, const double hubble, const double GravInternal, const struct UVBG *const GlobalUVBG)
Definition: sfr_eff.c:666
int sfreff_on_eeqos(const struct sph_particle_data *sph, const double a3inv)
Definition: sfr_eff.c:486
static int make_particle_star(int child, int parent, int placement, double Time)
Definition: sfr_eff.c:578
static int * sfr_reserve_slots(ActiveParticles *act, int *NewStars, int NumNewStar, ForceTree *tt)
Definition: sfr_eff.c:380
static void cooling_direct(int i, const double redshift, const double a3inv, const double hubble, const struct UVBG *const GlobalUVBG)
Definition: sfr_eff.c:444
static int quicklyastarformation(int i, const double a3inv)
Definition: sfr_eff.c:641
struct slots_manager_type SlotsManager[1]
Definition: slotsmanager.c:7
#define SPHP(i)
Definition: slotsmanager.h:124
int * ActiveParticle
Definition: timestep.h:13
int64_t NumActiveParticle
Definition: timestep.h:12
double GravInternal
Definition: cosmology.h:32
int StarformationOn
Definition: sfr_eff.c:39
double UnitSfr_in_solar_per_year
Definition: sfr_eff.c:72
double QuickLymanAlphaProbability
Definition: sfr_eff.c:62
int WindOn
Definition: sfr_eff.c:41
Definition: cooling.h:8
int64_t maxsize
Definition: slotsmanager.h:11
int64_t size
Definition: slotsmanager.h:12
struct slot_info info[6]
Definition: slotsmanager.h:112
void gadget_setup_thread_arrays(int *dest, int *srcs[], size_t sizes[], size_t total_size, int narrays)
Definition: system.c:600
void sumup_large_ints(int n, int *src, int64_t *res)
Definition: system.c:192
size_t gadget_compact_thread_arrays(int *dest, int *srcs[], size_t sizes[], int narrays)
Definition: system.c:587
#define MPIU_Barrier(comm)
Definition: system.h:103
LOW_PRECISION MyFloat
Definition: types.h:19
#define walltime_measure(name)
Definition: walltime.h:8
void winds_evolve(int i, double a3inv, double hubble)
Definition: winds.c:403
void winds_subgrid(int *MaybeWind, int NumMaybeWind, const double Time, const double hubble, ForceTree *tree, MyFloat *StellarMasses)
Definition: winds.c:306
int winds_are_subgrid(void)
Definition: winds.c:115
void winds_and_feedback(int *NewStars, int NumNewStars, const double Time, const double hubble, ForceTree *tree)
Definition: winds.c:333

References ActiveParticles::ActiveParticle, cooling_direct(), CP, dloga, endrun(), gadget_compact_thread_arrays(), gadget_setup_thread_arrays(), get_global_UVBG(), Cosmology::GravInternal, hubble_function(), slots_manager_type::info, make_particle_star(), slot_info::maxsize, message(), MPIU_Barrier, myfree, mymalloc, mymalloc2, myrealloc, ActiveParticles::NumActiveParticle, P, quicklyastarformation(), SFRParams::QuickLymanAlphaProbability, report_memory_usage, sfr_params, sfr_reserve_slots(), sfreff_on_eeqos(), slot_info::size, SlotsManager, SPHP, starformation(), SFRParams::StarformationOn, sumup_large_ints(), ta_free, ta_malloc, SFRParams::UnitSfr_in_solar_per_year, walltime_measure, SFRParams::WindOn, winds_and_feedback(), winds_are_subgrid(), winds_evolve(), and winds_subgrid().

Referenced by run(), and runfof().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_generations()

int get_generations ( void  )

Definition at line 87 of file sfr_eff.c.

88 {
89  return sfr_params.Generations;
90 }
int Generations
Definition: sfr_eff.c:65

References SFRParams::Generations, and sfr_params.

Referenced by init(), and petaio_read_header_internal().

Here is the caller graph for this function:

◆ get_helium_neutral_fraction_sfreff()

double get_helium_neutral_fraction_sfreff ( int  ion,
double  redshift,
double  hubble,
struct particle_data partdata,
struct sph_particle_data sphdata 
)

Definition at line 548 of file sfr_eff.c.

549 {
550  const double a3inv = pow(1+redshift,3);
551  double helium;
552  struct UVBG GlobalUVBG = get_global_UVBG(redshift);
553  struct UVBG uvbg = get_local_UVBG(redshift, &GlobalUVBG, partdata->Pos, PartManager->CurrentParticleOffset);
554  double physdens = sphdata->Density * a3inv;
555 
556  if(sfr_params.QuickLymanAlphaProbability > 0 || !sfreff_on_eeqos(sphdata, a3inv)) {
557  /*This gets the neutral fraction for standard gas*/
558  double eomdensity = sphdata->Density;
559  double InternalEnergy = sphdata->Entropy / GAMMA_MINUS1 * pow(eomdensity * a3inv, GAMMA_MINUS1);
560  helium = GetHeliumIonFraction(ion, InternalEnergy, physdens, &uvbg, sphdata->Ne);
561  }
562  else {
563  /* This gets the neutral fraction for gas on the star-forming equation of state.
564  * This needs special handling because the cold clouds have a different neutral
565  * fraction than the hot gas*/
566  double dloga = get_dloga_for_bin(partdata->TimeBin, partdata->Ti_drift);
567  double dtime = dloga / hubble;
568  struct sfr_eeqos_data sfr_data = get_sfr_eeqos(partdata, sphdata, dtime, &uvbg, redshift, a3inv);
569  double nh0cold = GetHeliumIonFraction(ion, sfr_params.EgySpecCold, physdens, &uvbg, sfr_data.ne);
570  double nh0hot = GetHeliumIonFraction(ion, sfr_data.egyhot, physdens, &uvbg, sfr_data.ne);
571  helium = nh0cold * sfr_data.cloudfrac + (1-sfr_data.cloudfrac) * nh0hot;
572  }
573  return helium;
574 }
double GetHeliumIonFraction(int ion, double u_old, double rho, const struct UVBG *uvbg, double ne_init)
Definition: cooling.c:192
struct UVBG get_local_UVBG(double redshift, const struct UVBG *const GlobalUVBG, const double *const Pos, const double *const PosOffset)
struct part_manager_type PartManager[1]
Definition: partmanager.c:11
#define GAMMA_MINUS1
Definition: physconst.h:35
static struct sfr_eeqos_data get_sfr_eeqos(struct particle_data *part, struct sph_particle_data *sph, double dtime, struct UVBG *local_uvbg, const double redshift, const double a3inv)
Definition: sfr_eff.c:722
double EgySpecCold
Definition: sfr_eff.c:49
double CurrentParticleOffset[3]
Definition: partmanager.h:82
unsigned char TimeBin
Definition: partmanager.h:26
double Pos[3]
Definition: partmanager.h:12
inttime_t Ti_drift
Definition: partmanager.h:36
double cloudfrac
Definition: sfr_eff.c:104
double ne
Definition: sfr_eff.c:106
double egyhot
Definition: sfr_eff.c:100
double get_dloga_for_bin(int timebin, const inttime_t Ti_Current)
Definition: timebinmgr.c:279

References sfr_eeqos_data::cloudfrac, part_manager_type::CurrentParticleOffset, sph_particle_data::Density, dloga, sfr_eeqos_data::egyhot, SFRParams::EgySpecCold, sph_particle_data::Entropy, GAMMA_MINUS1, get_dloga_for_bin(), get_global_UVBG(), get_local_UVBG(), get_sfr_eeqos(), GetHeliumIonFraction(), sfr_eeqos_data::ne, sph_particle_data::Ne, PartManager, particle_data::Pos, SFRParams::QuickLymanAlphaProbability, sfr_params, sfreff_on_eeqos(), particle_data::Ti_drift, and particle_data::TimeBin.

Referenced by GTHeliumIFraction(), GTHeliumIIFraction(), and GTHeliumIIIFraction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_MinEgySpec()

double get_MinEgySpec ( void  )

Definition at line 797 of file sfr_eff.c.

798 {
799  /* mean molecular weight assuming ZERO ionization NEUTRAL GAS*/
800  const double meanweight = 4.0 / (1 + 3 * HYDROGEN_MASSFRAC);
801  /*Enforces a minimum internal energy in cooling. */
802  return sfr_params.temp_to_u / meanweight * sfr_params.MinGasTemp;
803 }
#define HYDROGEN_MASSFRAC
Definition: physconst.h:37
double temp_to_u
Definition: sfr_eff.c:70
double MinGasTemp
Definition: sfr_eff.c:57

References HYDROGEN_MASSFRAC, SFRParams::MinGasTemp, sfr_params, and SFRParams::temp_to_u.

Referenced by begrun(), run(), and runfof().

Here is the caller graph for this function:

◆ get_neutral_fraction_sfreff()

double get_neutral_fraction_sfreff ( double  redshift,
double  hubble,
struct particle_data partdata,
struct sph_particle_data sphdata 
)

Definition at line 520 of file sfr_eff.c.

521 {
522  double nh0;
523  const double a3inv = pow(1+redshift,3);
524  struct UVBG GlobalUVBG = get_global_UVBG(redshift);
525  struct UVBG uvbg = get_local_UVBG(redshift, &GlobalUVBG, partdata->Pos, PartManager->CurrentParticleOffset);
526  double physdens = sphdata->Density * a3inv;
527 
528  if(sfr_params.QuickLymanAlphaProbability > 0 || !sfreff_on_eeqos(sphdata, a3inv)) {
529  /*This gets the neutral fraction for standard gas*/
530  double eomdensity = sphdata->Density;
531  double InternalEnergy = sphdata->Entropy / GAMMA_MINUS1 * pow(eomdensity * a3inv, GAMMA_MINUS1);
532  nh0 = GetNeutralFraction(InternalEnergy, physdens, &uvbg, sphdata->Ne);
533  }
534  else {
535  /* This gets the neutral fraction for gas on the star-forming equation of state.
536  * This needs special handling because the cold clouds have a different neutral
537  * fraction than the hot gas*/
538  double dloga = get_dloga_for_bin(partdata->TimeBin, partdata->Ti_drift);
539  double dtime = dloga / hubble;
540  struct sfr_eeqos_data sfr_data = get_sfr_eeqos(partdata, sphdata, dtime, &uvbg, redshift, a3inv);
541  double nh0cold = GetNeutralFraction(sfr_params.EgySpecCold, physdens, &uvbg, sfr_data.ne);
542  double nh0hot = GetNeutralFraction(sfr_data.egyhot, physdens, &uvbg, sfr_data.ne);
543  nh0 = nh0cold * sfr_data.cloudfrac + (1-sfr_data.cloudfrac) * nh0hot;
544  }
545  return nh0;
546 }
double GetNeutralFraction(double u_old, double rho, const struct UVBG *uvbg, double ne_init)
Definition: cooling.c:181

References sfr_eeqos_data::cloudfrac, part_manager_type::CurrentParticleOffset, sph_particle_data::Density, dloga, sfr_eeqos_data::egyhot, SFRParams::EgySpecCold, sph_particle_data::Entropy, GAMMA_MINUS1, get_dloga_for_bin(), get_global_UVBG(), get_local_UVBG(), get_sfr_eeqos(), GetNeutralFraction(), sfr_eeqos_data::ne, sph_particle_data::Ne, PartManager, particle_data::Pos, SFRParams::QuickLymanAlphaProbability, sfr_params, sfreff_on_eeqos(), particle_data::Ti_drift, and particle_data::TimeBin.

Referenced by blackhole_accretion_ngbiter(), and GTNeutralHydrogenFraction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_cooling_and_star_formation()

void init_cooling_and_star_formation ( int  CoolingOn,
int  StarformationOn,
Cosmology CP,
const double  avg_baryon_mass,
const double  BoxSize,
const struct UnitSystem  units 
)

Definition at line 805 of file sfr_eff.c.

806 {
807  struct cooling_units coolunits;
812  /* Get mean cosmic baryon density for photoheating rate from long mean free path photons */
813  coolunits.rho_crit_baryon = 3 * pow(CP->HubbleParam * HUBBLE,2) * CP->OmegaBaryon / (8 * M_PI * GRAVITY);
814 
816 
818 
820 
821  if(!CoolingOn)
822  return;
823 
824  /*Initialize the uv fluctuation table*/
826 
827  sfr_params.StarformationOn = StarformationOn;
828 
829  if(!StarformationOn)
830  return;
831 
832  sfr_params.avg_baryon_mass = avg_baryon_mass;
833 
836  sfr_params.CritOverDensity * CP->OmegaBaryon * 3 * CP->Hubble * CP->Hubble / (8 * M_PI * CP->GravInternal);
837 
839 
840  /* mean molecular weight assuming ZERO ionization NEUTRAL GAS*/
841  double meanweight = 4.0 / (1 + 3 * HYDROGEN_MASSFRAC);
843 
844  /* mean molecular weight assuming FULL ionization */
845  meanweight = 4 / (8 - 5 * (1 - HYDROGEN_MASSFRAC));
847 
848  if(sfr_params.PhysDensThresh == 0)
849  {
850  double egyhot = sfr_params.EgySpecSN / sfr_params.FactorEVP;
851 
852  meanweight = 4 / (8 - 5 * (1 - HYDROGEN_MASSFRAC)); /* note: assuming FULL ionization */
853 
854  double u4 = sfr_params.temp_to_u/meanweight * 1.0e4;
855 
856  double dens = 1.0e6 * 3 * CP->Hubble * CP->Hubble / (8 * M_PI * CP->GravInternal);
857 
858  double ne = 1.0;
859 
860  struct UVBG uvbg = {0};
861  /*XXX: We set the threshold without metal cooling
862  * and with zero ionization at z=0.
863  * It probably make sense to set the parameters with
864  * a metalicity dependence.
865  * */
866  const double tcool = GetCoolingTime(0, egyhot, dens, &uvbg, &ne, 0.0);
867 
868  const double coolrate = egyhot / tcool / dens;
869 
870  const double x = (egyhot - u4) / (egyhot - sfr_params.EgySpecCold);
871 
873  x / pow(1 - x,
874  2) * (sfr_params.FactorSN * sfr_params.EgySpecSN - (1 -
876  (sfr_params.MaxSfrTimescale * coolrate);
877 
878  message(0, "A0= %g \n", sfr_params.FactorEVP);
879  message(0, "Computed: PhysDensThresh= %g (int units) %g h^2 cm^-3\n", sfr_params.PhysDensThresh,
881  message(0, "EXPECTED FRACTION OF COLD GAS AT THRESHOLD = %g\n", x);
882  message(0, "tcool=%g dens=%g egyhot=%g\n", tcool, dens, egyhot);
883 
884  dens = sfr_params.PhysDensThresh * 10;
885 
886  double neff;
887  do
888  {
889  double egyeff = get_egyeff(0, dens, &uvbg);
890 
891  double peff = GAMMA_MINUS1 * dens * egyeff;
892 
893  const double fac = 1 / (log(dens * 1.025) - log(dens));
894  neff = -log(peff) * fac;
895 
896  dens *= 1.025;
897  egyeff = get_egyeff(0, dens, &uvbg);
898  peff = GAMMA_MINUS1 * dens * egyeff;
899 
900  neff += log(peff) * fac;
901  }
902  while(neff > 4.0 / 3);
903 
904  message(0, "Run-away sets in for dens=%g\n", dens);
905  message(0, "Dynamic range for quiescent star formation= %g\n", dens / sfr_params.PhysDensThresh);
906 
907  const double sigma = 10.0 / CP->Hubble * 1.0e-10 / pow(1.0e-3, 2);
908 
909  message(0, "Isotherm sheet central density: %g z0=%g\n",
910  M_PI * CP->GravInternal * sigma * sigma / (2 * GAMMA_MINUS1) / u4,
911  GAMMA_MINUS1 * u4 / (2 * M_PI * CP->GravInternal * sigma));
912  }
913 
914  if(sfr_params.WindOn) {
916  }
917 
918 }
void init_cooling(const char *TreeCoolFile, const char *MetalCoolFile, char *reion_hist_file, struct cooling_units cu, Cosmology *CP)
Definition: cooling.c:36
double GetCoolingTime(double redshift, double u_old, double rho, struct UVBG *uvbg, double *ne_guess, double Z)
Definition: cooling.c:157
static struct cooling_units coolunits
Definition: cooling.c:33
void init_uvf_table(const char *UVFluctuationFile, const int UVFlucLen, const double BoxSize, const double UnitLength_in_cm)
double sigma[3]
Definition: densitykernel.c:97
#define HUBBLE
Definition: physconst.h:25
#define SOLAR_MASS
Definition: physconst.h:6
#define GRAVITY
Definition: physconst.h:5
#define PROTONMASS
Definition: physconst.h:21
#define SEC_PER_YEAR
Definition: physconst.h:32
#define BOLTZMANN
Definition: physconst.h:11
static double get_egyeff(double redshift, double dens, struct UVBG *uvbg)
Definition: sfr_eff.c:782
double HubbleParam
Definition: cosmology.h:20
double OmegaBaryon
Definition: cosmology.h:19
double Hubble
Definition: cosmology.h:21
double MaxSfrTimescale
Definition: sfr_eff.c:54
double TempSupernova
Definition: sfr_eff.c:52
double PhysDensThresh
Definition: sfr_eff.c:46
double CritOverDensity
Definition: sfr_eff.c:43
char UVFluctuationFile[100]
Definition: sfr_eff.c:82
char MetalCoolFile[100]
Definition: sfr_eff.c:81
char ReionHistFile[100]
Definition: sfr_eff.c:84
double OverDensThresh
Definition: sfr_eff.c:45
double tau_fmol_unit
Definition: sfr_eff.c:60
double FactorEVP
Definition: sfr_eff.c:50
double TempClouds
Definition: sfr_eff.c:53
double EgySpecSN
Definition: sfr_eff.c:47
double FactorSN
Definition: sfr_eff.c:48
char TreeCoolFile[100]
Definition: sfr_eff.c:80
double avg_baryon_mass
Definition: sfr_eff.c:67
double CritPhysDensity
Definition: sfr_eff.c:44
double UnitMass_in_g
Definition: unitsystem.h:8
double UnitInternalEnergy_in_cgs
Definition: unitsystem.h:14
double UnitTime_in_s
Definition: unitsystem.h:11
double UnitLength_in_cm
Definition: unitsystem.h:10
double UnitDensity_in_cgs
Definition: unitsystem.h:12
double rho_crit_baryon
Definition: cooling.h:31
int CoolingOn
Definition: cooling.h:23
double density_in_phys_cgs
Definition: cooling.h:25
double tt_in_s
Definition: cooling.h:29
double uu_in_cgs
Definition: cooling.h:27
void init_winds(double FactorSN, double EgySpecSN, double PhysDensThresh, double UnitTime_in_s)
Definition: winds.c:97

References SFRParams::avg_baryon_mass, BOLTZMANN, cooling_units::CoolingOn, coolunits, CP, SFRParams::CritOverDensity, SFRParams::CritPhysDensity, cooling_units::density_in_phys_cgs, SFRParams::EgySpecCold, SFRParams::EgySpecSN, SFRParams::FactorEVP, SFRParams::FactorSN, GAMMA_MINUS1, get_egyeff(), GetCoolingTime(), Cosmology::GravInternal, GRAVITY, Cosmology::Hubble, HUBBLE, Cosmology::HubbleParam, HYDROGEN_MASSFRAC, init_cooling(), init_uvf_table(), init_winds(), SFRParams::MaxSfrTimescale, message(), SFRParams::MetalCoolFile, Cosmology::OmegaBaryon, SFRParams::OverDensThresh, SFRParams::PhysDensThresh, PROTONMASS, SFRParams::ReionHistFile, cooling_units::rho_crit_baryon, SEC_PER_YEAR, sfr_params, sigma, SOLAR_MASS, SFRParams::StarformationOn, SFRParams::tau_fmol_unit, SFRParams::temp_to_u, SFRParams::TempClouds, SFRParams::TempSupernova, SFRParams::TreeCoolFile, cooling_units::tt_in_s, UnitSystem::UnitDensity_in_cgs, UnitSystem::UnitInternalEnergy_in_cgs, UnitSystem::UnitLength_in_cm, UnitSystem::UnitMass_in_g, SFRParams::UnitSfr_in_solar_per_year, UnitSystem::UnitTime_in_s, cooling_units::uu_in_cgs, SFRParams::UVFluctuationFile, and SFRParams::WindOn.

Referenced by begrun().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_sfr_params()

void set_sfr_params ( ParameterSet ps)

Definition at line 129 of file sfr_eff.c.

130 {
131  int ThisTask;
132  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
133  if(ThisTask == 0) {
134  /*Star formation parameters*/
135  sfr_params.StarformationCriterion = (enum StarformationCriterion) param_get_enum(ps, "StarformationCriterion");
136  sfr_params.CritOverDensity = param_get_double(ps, "CritOverDensity");
137  sfr_params.CritPhysDensity = param_get_double(ps, "CritPhysDensity");
138  sfr_params.WindOn = param_get_int(ps, "WindOn");
139 
140  sfr_params.FactorSN = param_get_double(ps, "FactorSN");
141  sfr_params.FactorEVP = param_get_double(ps, "FactorEVP");
142  sfr_params.TempSupernova = param_get_double(ps, "TempSupernova");
143  sfr_params.TempClouds = param_get_double(ps, "TempClouds");
144  sfr_params.MaxSfrTimescale = param_get_double(ps, "MaxSfrTimescale");
145  sfr_params.Generations = param_get_int(ps, "Generations");
146  sfr_params.MinGasTemp = param_get_double(ps, "MinGasTemp");
147  sfr_params.BHFeedbackUseTcool = param_get_int(ps, "BHFeedbackUseTcool");
149  endrun(0, "BHFeedbackUseTcool mode %d not supported\n", sfr_params.BHFeedbackUseTcool);
150  /*Lyman-alpha forest parameters*/
151  sfr_params.QuickLymanAlphaProbability = param_get_double(ps, "QuickLymanAlphaProbability");
152  sfr_params.QuickLymanAlphaTempThresh = param_get_double(ps, "QuickLymanAlphaTempThresh");
153  sfr_params.HIReionTemp = param_get_double(ps, "HIReionTemp");
154 
155  /* File names*/
156  param_get_string2(ps, "TreeCoolFile", sfr_params.TreeCoolFile, sizeof(sfr_params.TreeCoolFile));
158  param_get_string2(ps, "MetalCoolFile", sfr_params.MetalCoolFile, sizeof(sfr_params.MetalCoolFile));
159  param_get_string2(ps, "ReionHistFile", sfr_params.ReionHistFile, sizeof(sfr_params.ReionHistFile));
160  }
161  MPI_Bcast(&sfr_params, sizeof(struct SFRParams), MPI_BYTE, 0, MPI_COMM_WORLD);
162 }
double param_get_double(ParameterSet *ps, const char *name)
Definition: paramset.c:336
void param_get_string2(ParameterSet *ps, const char *name, char *dst, size_t len)
Definition: paramset.c:355
int param_get_int(ParameterSet *ps, const char *name)
Definition: paramset.c:368
int param_get_enum(ParameterSet *ps, const char *name)
Definition: paramset.c:378
StarformationCriterion
Definition: sfr_eff.h:16
double QuickLymanAlphaTempThresh
Definition: sfr_eff.c:63
int BHFeedbackUseTcool
Definition: sfr_eff.c:55
enum StarformationCriterion StarformationCriterion
Definition: sfr_eff.c:40
double HIReionTemp
Definition: sfr_eff.c:78
int ThisTask
Definition: test_exchange.c:23

References SFRParams::BHFeedbackUseTcool, SFRParams::CritOverDensity, SFRParams::CritPhysDensity, endrun(), SFRParams::FactorEVP, SFRParams::FactorSN, SFRParams::Generations, SFRParams::HIReionTemp, SFRParams::MaxSfrTimescale, SFRParams::MetalCoolFile, SFRParams::MinGasTemp, param_get_double(), param_get_enum(), param_get_int(), param_get_string2(), SFRParams::QuickLymanAlphaProbability, SFRParams::QuickLymanAlphaTempThresh, SFRParams::ReionHistFile, sfr_params, SFRParams::StarformationCriterion, SFRParams::TempClouds, SFRParams::TempSupernova, ThisTask, SFRParams::TreeCoolFile, SFRParams::UVFluctuationFile, and SFRParams::WindOn.

Referenced by read_parameter_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sfr_need_to_compute_sph_grad_rho()

int sfr_need_to_compute_sph_grad_rho ( void  )

Definition at line 952 of file sfr_eff.c.

953 {
955  return 1;
956  }
957  return 0;
958 }
#define HAS(val, flag)
Definition: types.h:22

References HAS, SFR_CRITERION_MOLECULAR_H2, sfr_params, and SFRParams::StarformationCriterion.

Referenced by run(), and runfof().

Here is the caller graph for this function:

◆ sfreff_on_eeqos()

int sfreff_on_eeqos ( const struct sph_particle_data sph,
const double  a3inv 
)

Definition at line 486 of file sfr_eff.c.

487 {
488  int flag = 0;
489  /* no sfr: normal cooling*/
491  return 0;
492  }
493 
494  if(sph->Density * a3inv >= sfr_params.PhysDensThresh)
495  flag = 1;
496 
498  flag = 0;
499 
500  if(sph->DelayTime > 0)
501  flag = 0; /* only normal cooling for particles in the wind */
502 
503  /* The model from 0904.2572 makes gas not star forming if more than 0.5 dex above
504  * the effective equation of state (at z=0). This in practice means black hole heated.*/
505  if(flag == 1 && sfr_params.BHFeedbackUseTcool == 2) {
506  //Redshift is the argument
507  double redshift = pow(a3inv, 1./3.)-1;
508  struct UVBG uvbg = get_global_UVBG(redshift);
509  double egyeff = get_egyeff(redshift, sph->Density, &uvbg);
510  const double enttou = pow(sph->Density * a3inv, GAMMA_MINUS1) / GAMMA_MINUS1;
511  double unew = sph->Entropy * enttou;
512  /* 0.5 dex = 10^0.5 = 3.2 */
513  if(unew >= egyeff * 3.2)
514  flag = 0;
515  }
516  return flag;
517 }

References SFRParams::BHFeedbackUseTcool, sph_particle_data::DelayTime, sph_particle_data::Density, sph_particle_data::Entropy, GAMMA_MINUS1, get_egyeff(), get_global_UVBG(), SFRParams::OverDensThresh, SFRParams::PhysDensThresh, sfr_params, and SFRParams::StarformationOn.

Referenced by blackhole_feedback_ngbiter(), cooling_and_starformation(), get_helium_neutral_fraction_sfreff(), get_neutral_fraction_sfreff(), and get_starformation_rate_full().

Here is the call graph for this function:
Here is the caller graph for this function: