MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Macros | Functions | Variables
cooling.c File Reference
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <bigfile.h>
#include "utils/endrun.h"
#include "utils/mymalloc.h"
#include "utils/interp.h"
#include "physconst.h"
#include "cooling.h"
#include "cooling_rates.h"
#include "cooling_qso_lightup.h"
#include "cosmology.h"
Include dependency graph for cooling.c:

Go to the source code of this file.

Macros

#define MAXITER   1000
 

Functions

void init_cooling (const char *TreeCoolFile, const char *MetalCoolFile, char *reion_hist_file, struct cooling_units cu, Cosmology *CP)
 
static double get_lambdanet (double rho, double u, double redshift, double Z, struct UVBG *uvbg, double *ne_guess, int isHeIIIionized)
 
double DoCooling (double redshift, double u_old, double rho, double dt, struct UVBG *uvbg, double *ne_guess, double Z, double MinEgySpec, int isHeIIIionized)
 
double GetCoolingTime (double redshift, double u_old, double rho, struct UVBG *uvbg, double *ne_guess, double Z)
 
double GetNeutralFraction (double u_old, double rho, const struct UVBG *uvbg, double ne_init)
 
double GetHeliumIonFraction (int ion, double u_old, double rho, const struct UVBG *uvbg, double ne_init)
 

Variables

static struct cooling_units coolunits
 

Macro Definition Documentation

◆ MAXITER

#define MAXITER   1000

Definition at line 46 of file cooling.c.

Function Documentation

◆ DoCooling()

double DoCooling ( double  redshift,
double  u_old,
double  rho,
double  dt,
struct UVBG uvbg,
double *  ne_guess,
double  Z,
double  MinEgySpec,
int  isHeIIIionized 
)

Definition at line 71 of file cooling.c.

72 {
73  if(!coolunits.CoolingOn) return 0;
74 
75  double u, du;
76  double u_lower, u_upper;
77  double LambdaNet;
78  int iter = 0;
79 
80  rho *= coolunits.density_in_phys_cgs / PROTONMASS; /* convert to (physical) protons/cm^3 */
81  u_old *= coolunits.uu_in_cgs;
82  MinEgySpec *= coolunits.uu_in_cgs;
83  if(u_old < MinEgySpec)
84  u_old = MinEgySpec;
85  dt *= coolunits.tt_in_s;
86 
87  u = u_old;
88  u_lower = u;
89  u_upper = u;
90 
91  LambdaNet = get_lambdanet(rho, u, redshift, Z, uvbg, ne_guess, isHeIIIionized);
92 
93  /* bracketing */
94  if(u - u_old - LambdaNet * dt < 0) /* heating */
95  {
96  do
97  {
98  u_lower = u_upper;
99  u_upper *= 1.1;
100  } while(u_upper - u_old - get_lambdanet(rho, u_upper, redshift, Z, uvbg, ne_guess, isHeIIIionized) * dt < 0);
101  }
102  else
103  {
104  do {
105  u_upper = u_lower;
106  u_lower /= 1.1;
107  /* This means that we don't need an initial bracket*/
108  if(u_upper <= MinEgySpec) {
109  break;
110  }
111  } while(u_lower - u_old - get_lambdanet(rho, u_lower, redshift, Z, uvbg, ne_guess, isHeIIIionized) * dt > 0);
112  }
113 
114  do
115  {
116  u = 0.5 * (u_lower + u_upper);
117  /* If we know that the new energy
118  * is below the minimum gas internal energy, we are done here.*/
119  if(u_upper <= MinEgySpec) {
120  u = MinEgySpec;
121  break;
122  }
123 
124  LambdaNet = get_lambdanet(rho, u, redshift, Z, uvbg, ne_guess, isHeIIIionized);
125 
126  if(u - u_old - LambdaNet * dt > 0)
127  {
128  u_upper = u;
129  }
130  else
131  {
132  u_lower = u;
133  }
134 
135  du = u_upper - u_lower;
136 
137  iter++;
138 
139  if(iter >= (MAXITER - 10))
140  message(1, "u= %g\n", u);
141  }
142  while(fabs(du / u) > 1.0e-6 && iter < MAXITER);
143 
144  if(iter >= MAXITER)
145  {
146  endrun(10, "failed to converge in DoCooling()\n");
147  }
148 
149  u /= coolunits.uu_in_cgs; /*convert back to internal units */
150 
151  return u;
152 }
static double get_lambdanet(double rho, double u, double redshift, double Z, struct UVBG *uvbg, double *ne_guess, int isHeIIIionized)
Definition: cooling.c:57
#define MAXITER
Definition: cooling.c:46
static struct cooling_units coolunits
Definition: cooling.c:33
void message(int where, const char *fmt,...)
Definition: endrun.c:175
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
#define PROTONMASS
Definition: physconst.h:21
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

References cooling_units::CoolingOn, coolunits, cooling_units::density_in_phys_cgs, endrun(), get_lambdanet(), MAXITER, message(), PROTONMASS, cooling_units::tt_in_s, and cooling_units::uu_in_cgs.

Referenced by cooling_direct(), and test_DoCooling().

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

◆ get_lambdanet()

static double get_lambdanet ( double  rho,
double  u,
double  redshift,
double  Z,
struct UVBG uvbg,
double *  ne_guess,
int  isHeIIIionized 
)
static

Definition at line 57 of file cooling.c.

58 {
59  double LambdaNet = get_heatingcooling_rate(rho, u, 1 - HYDROGEN_MASSFRAC, redshift, Z, uvbg, ne_guess);
60  if(!isHeIIIionized) {
61  /* get_long_mean_free_path_heating returns the heating in units of erg/s/cm^3,
62  * the factor of the mean density converts from erg/s/cm^3 to erg/s/g */
63  LambdaNet += get_long_mean_free_path_heating(redshift) / (coolunits.rho_crit_baryon * pow(1 + redshift,3));
64  }
65  return LambdaNet;
66 }
double get_long_mean_free_path_heating(double redshift)
double get_heatingcooling_rate(double density, double ienergy, double helium, double redshift, double metallicity, const struct UVBG *uvbg, double *ne_equilib)
#define HYDROGEN_MASSFRAC
Definition: physconst.h:37
double rho_crit_baryon
Definition: cooling.h:31

References coolunits, get_heatingcooling_rate(), get_long_mean_free_path_heating(), HYDROGEN_MASSFRAC, and cooling_units::rho_crit_baryon.

Referenced by DoCooling().

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

◆ GetCoolingTime()

double GetCoolingTime ( double  redshift,
double  u_old,
double  rho,
struct UVBG uvbg,
double *  ne_guess,
double  Z 
)

Definition at line 157 of file cooling.c.

158 {
159  if(!coolunits.CoolingOn) return 0;
160 
161  /* convert to physical cgs units */
163  u_old *= coolunits.uu_in_cgs;
164 
165  /* Note: this does not include the long mean free path heating from helium reionization*/
166  double LambdaNet = get_heatingcooling_rate(rho, u_old, 1 - HYDROGEN_MASSFRAC, redshift, Z, uvbg, ne_guess);
167 
168  if(LambdaNet >= 0) /* ups, we have actually heating due to UV background */
169  return 0;
170 
171  double coolingtime = u_old / (- LambdaNet);
172 
173  /*Convert back to internal units*/
174  coolingtime /= coolunits.tt_in_s;
175 
176  return coolingtime;
177 }

References cooling_units::CoolingOn, coolunits, cooling_units::density_in_phys_cgs, get_heatingcooling_rate(), HYDROGEN_MASSFRAC, PROTONMASS, cooling_units::tt_in_s, and cooling_units::uu_in_cgs.

Referenced by cooling_relaxed(), get_egyeff(), init_cooling_and_star_formation(), and test_DoCooling().

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

◆ GetHeliumIonFraction()

double GetHeliumIonFraction ( int  ion,
double  u_old,
double  rho,
const struct UVBG uvbg,
double  ne_init 
)

Definition at line 192 of file cooling.c.

193 {
194  /* convert to physical cgs units */
196  u_old *= coolunits.uu_in_cgs;
197  double helium_ion = get_helium_ion_phys_cgs(ion, rho, u_old, 1 - HYDROGEN_MASSFRAC, uvbg, ne_init);
198  return helium_ion;
199 }
double get_helium_ion_phys_cgs(int ion, double density, double ienergy, double helium, const struct UVBG *uvbg, double ne_init)

References coolunits, cooling_units::density_in_phys_cgs, get_helium_ion_phys_cgs(), HYDROGEN_MASSFRAC, PROTONMASS, and cooling_units::uu_in_cgs.

Referenced by get_helium_neutral_fraction_sfreff().

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

◆ GetNeutralFraction()

double GetNeutralFraction ( double  u_old,
double  rho,
const struct UVBG uvbg,
double  ne_init 
)

Definition at line 181 of file cooling.c.

182 {
183  /* convert to physical cgs units */
185  u_old *= coolunits.uu_in_cgs;
186  double nh0 = get_neutral_fraction_phys_cgs(rho, u_old, 1 - HYDROGEN_MASSFRAC, uvbg, &ne_init);
187  return nh0;
188 }
double get_neutral_fraction_phys_cgs(double density, double ienergy, double helium, const struct UVBG *uvbg, double *ne_init)

References coolunits, cooling_units::density_in_phys_cgs, get_neutral_fraction_phys_cgs(), HYDROGEN_MASSFRAC, PROTONMASS, and cooling_units::uu_in_cgs.

Referenced by get_neutral_fraction_sfreff().

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

◆ init_cooling()

void init_cooling ( const char *  TreeCoolFile,
const char *  MetalCoolFile,
char *  reion_hist_file,
struct cooling_units  cu,
Cosmology CP 
)

Definition at line 36 of file cooling.c.

37 {
38  coolunits = cu;
39  /*Initialize the cooling rates*/
41  init_cooling_rates(TreeCoolFile, MetalCoolFile, CP);
42  /* Initialize the helium reionization model*/
43  init_qso_lightup(reion_hist_file);
44 }
void init_qso_lightup(char *reion_hist_file)
void init_cooling_rates(const char *TreeCoolFile, const char *MetalCoolFile, Cosmology *CP)
static Cosmology * CP
Definition: power.c:27

References cooling_units::CoolingOn, coolunits, CP, init_cooling_rates(), and init_qso_lightup().

Referenced by init_cooling_and_star_formation(), and test_DoCooling().

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

Variable Documentation

◆ coolunits

struct cooling_units coolunits
static