MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Macros | Functions | Variables
test_cooling.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <libgadget/config.h>
#include <libgadget/physconst.h>
#include <libgadget/cosmology.h>
#include <libgadget/cooling.h>
#include <libgadget/cooling_rates.h>
#include <libgadget/utils/peano.h>
#include <libgadget/partmanager.h>
#include <libgadget/utils/endrun.h>
#include "stub.h"
Include dependency graph for test_cooling.c:

Go to the source code of this file.

Macros

#define NSTEP   20
 

Functions

double get_long_mean_free_path_heating (double redshift)
 
void init_qso_lightup (char *reion_hist_file)
 
int during_helium_reionization (double redshift)
 
static void test_DoCooling (void **state)
 
int main (void)
 

Variables

static double unew_table [NSTEP *NSTEP]
 
static double tcool_table [NSTEP *NSTEP]
 
struct part_manager_type PartManager [1]
 

Macro Definition Documentation

◆ NSTEP

#define NSTEP   20

Definition at line 41 of file test_cooling.c.

Function Documentation

◆ during_helium_reionization()

int during_helium_reionization ( double  redshift)

Definition at line 36 of file test_cooling.c.

37 {
38  return 0;
39 }

◆ get_long_mean_free_path_heating()

double get_long_mean_free_path_heating ( double  redshift)

Definition at line 23 of file test_cooling.c.

24 {
25  redshift *= 2;
26  return 0;
27 }

◆ init_qso_lightup()

void init_qso_lightup ( char *  reion_hist_file)

Definition at line 30 of file test_cooling.c.

31 {
32  return;
33 }

◆ main()

int main ( void  )

Definition at line 243 of file test_cooling.c.

243  {
244  const struct CMUnitTest tests[] = {
245  cmocka_unit_test(test_DoCooling),
246 
247  };
248  return cmocka_run_group_tests_mpi(tests, NULL, NULL);
249 }
static void test_DoCooling(void **state)
Definition: test_cooling.c:156

References test_DoCooling().

Here is the call graph for this function:

◆ test_DoCooling()

static void test_DoCooling ( void **  state)
static

Definition at line 156 of file test_cooling.c.

157 {
158  int i, j;
159  struct cooling_params coolpar;
160  coolpar.CMBTemperature = 2.7255;
161  coolpar.PhotoIonizeFactor = 1;
162  coolpar.SelfShieldingOn = 0;
163  coolpar.fBar = 0.17;
164  coolpar.PhotoIonizationOn = 1;
165  coolpar.recomb = Cen92;
166  coolpar.cooling = KWH92;
167  coolpar.HeliumHeatOn = 0;
168  coolpar.HeliumHeatAmp = 1.;
169  coolpar.HeliumHeatExp = 0.;
170  coolpar.HeliumHeatThresh = 10;
171  coolpar.MinGasTemp = 0;
172  coolpar.UVRedshiftThreshold = -1;
173  coolpar.HydrogenHeatAmp = 0;
174  coolpar.rho_crit_baryon = 0.045 * 3.0 * pow(0.7*HUBBLE,2.0) /(8.0*M_PI*GRAVITY);
175 
176  char * TreeCool = GADGET_TESTDATA_ROOT "/examples/TREECOOL_ep_2018p";
177  char * MetalCool = "";
178 
179  /*unit system*/
180  double HubbleParam = 0.7;
181  double UnitDensity_in_cgs = 6.76991e-22;
182  double UnitTime_in_s = 3.08568e+16;
183  double UnitMass_in_g = 1.989e+43;
184  double UnitLength_in_cm = 3.08568e+21;
185  double UnitEnergy_in_cgs = UnitMass_in_g * pow(UnitLength_in_cm, 2) / pow(UnitTime_in_s, 2);
186 
187  Cosmology CP = {0};
188  CP.OmegaCDM = 0.3;
189  CP.OmegaBaryon = coolpar.fBar * CP.OmegaCDM;
190  CP.HubbleParam = HubbleParam;
191 
192  struct cooling_units coolunits;
193  coolunits.CoolingOn = 1;
194  coolunits.density_in_phys_cgs = UnitDensity_in_cgs * HubbleParam * HubbleParam;
195  coolunits.uu_in_cgs = UnitEnergy_in_cgs / UnitMass_in_g;
196  coolunits.tt_in_s = UnitTime_in_s / HubbleParam;
197  coolunits.rho_crit_baryon = 3 * pow(CP.HubbleParam * HUBBLE,2) * CP.OmegaBaryon / (8 * M_PI * GRAVITY);
198 
199  double meanweight = 4.0 / (1 + 3 * HYDROGEN_MASSFRAC);
200  double MinEgySpec = 1 / meanweight * (1.0 / GAMMA_MINUS1) * (BOLTZMANN / PROTONMASS) * 1;
201  MinEgySpec /= coolunits.uu_in_cgs;
202 
203  set_coolpar(coolpar);
204  init_cooling(TreeCool, MetalCool, NULL, coolunits, &CP);
205  struct UVBG uvbg = get_global_UVBG(0);
206  assert_true(fabs(uvbg.epsH0/3.65296e-25 -1) < 1e-5);
207  assert_true(fabs(uvbg.epsHe0/3.98942e-25 -1) < 1e-5);
208  assert_true(fabs(uvbg.epsHep/3.33253e-26 -1) < 1e-5);
209 
210  double umax = 36000, umin = 200;
211  double dmax = 1e-2, dmin = 1e-9;
212 
213  double ne= 1.0;
214  /*Check two particular values*/
215  double tcool = GetCoolingTime(0, 949.755, 7.07946e-06, &uvbg, &ne, 0);
216  assert_true(fabs(tcool/ 0.0172379) -1 < 1e-3);
217  double unew = DoCooling(0, 9828.44, 7.07946e-06, 0.2, &uvbg, &ne, 0, MinEgySpec, 1);
218  assert_true(fabs(unew/ 531.724) -1 < 1e-3);
219 
220  double dt = 0.2;
221  for(i=0; i < NSTEP; i++)
222  {
223  double dens = exp(log(dmin) + i * (log(dmax) - log(dmin)) / 1. /NSTEP);
224  for (j = 0; j<NSTEP; j++)
225  {
226  double ne=1.0, ne2=1.0;
227  double uu = exp(log(umin) + j * (log(umax) - log(umin)) / 1. /NSTEP);
228  double tcool = GetCoolingTime(0, uu, dens, &uvbg, &ne2, 0);
229  double unew = DoCooling(0, uu, dens, dt, &uvbg, &ne, 0, MinEgySpec, 1);
230  assert_false(isnan(unew));
231 // message(0, "d = %g u = %g tcool = %g tcool_table = %g unew = %g ne_after = %g unew_table = %g\n", dens, uu, tcool, tcool_table[i*NSTEP + j], unew, ne, unew_table[i*NSTEP+j]);
232  assert_true(fabs(unew/unew_table[i*NSTEP + j] - 1) < 5e-3);
233  assert_true(fabs(1/(1e-20 + tcool) - 1./(1e-20 + tcool_table[i*NSTEP + j])) < 1 || fabs((1e-20 + tcool)/(1e-20 + tcool_table[i*NSTEP + j]) - 1) < 2e-2);
234  /*Make the tables*/
235  //printf("%g , ", unew);
236  //printf("%g , ", tcool);
237 
238  }
239  }
240 // printf("\n");
241 }
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
double DoCooling(double redshift, double u_old, double rho, double dt, struct UVBG *uvbg, double *ne_guess, double Z, double MinEgySpec, int isHeIIIionized)
Definition: cooling.c:71
struct UVBG get_global_UVBG(double redshift)
void set_coolpar(struct cooling_params cp)
@ KWH92
Definition: cooling_rates.h:17
@ Cen92
Definition: cooling_rates.h:11
struct @1 MetalCool
#define HUBBLE
Definition: physconst.h:25
#define HYDROGEN_MASSFRAC
Definition: physconst.h:37
#define GRAVITY
Definition: physconst.h:5
#define GAMMA_MINUS1
Definition: physconst.h:35
#define PROTONMASS
Definition: physconst.h:21
#define BOLTZMANN
Definition: physconst.h:11
static Cosmology * CP
Definition: power.c:27
static double UnitLength_in_cm
Definition: power.c:26
double HubbleParam
Definition: cosmology.h:20
double OmegaCDM
Definition: cosmology.h:11
double OmegaBaryon
Definition: cosmology.h:19
Definition: cooling.h:8
double epsHep
Definition: cooling.h:13
double epsH0
Definition: cooling.h:12
double epsHe0
Definition: cooling.h:14
double CMBTemperature
Definition: cooling_rates.h:41
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
#define NSTEP
Definition: test_cooling.c:41
static double unew_table[NSTEP *NSTEP]
Definition: test_cooling.c:43
static double tcool_table[NSTEP *NSTEP]
Definition: test_cooling.c:97

References BOLTZMANN, Cen92, cooling_params::CMBTemperature, cooling_params::cooling, cooling_units::CoolingOn, coolunits, CP, cooling_units::density_in_phys_cgs, DoCooling(), UVBG::epsH0, UVBG::epsHe0, UVBG::epsHep, cooling_params::fBar, GAMMA_MINUS1, get_global_UVBG(), GetCoolingTime(), GRAVITY, cooling_params::HeliumHeatAmp, cooling_params::HeliumHeatExp, cooling_params::HeliumHeatOn, cooling_params::HeliumHeatThresh, HUBBLE, Cosmology::HubbleParam, HYDROGEN_MASSFRAC, cooling_params::HydrogenHeatAmp, init_cooling(), KWH92, MetalCool, cooling_params::MinGasTemp, NSTEP, Cosmology::OmegaBaryon, Cosmology::OmegaCDM, cooling_params::PhotoIonizationOn, cooling_params::PhotoIonizeFactor, PROTONMASS, cooling_params::recomb, cooling_units::rho_crit_baryon, cooling_params::rho_crit_baryon, cooling_params::SelfShieldingOn, set_coolpar(), tcool_table, cooling_units::tt_in_s, unew_table, UnitLength_in_cm, cooling_units::uu_in_cgs, and cooling_params::UVRedshiftThreshold.

Referenced by main().

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

Variable Documentation

◆ PartManager

struct part_manager_type PartManager[1]

Definition at line 97 of file test_cooling.c.

◆ tcool_table

double tcool_table[NSTEP *NSTEP]
static

Definition at line 97 of file test_cooling.c.

Referenced by test_DoCooling().

◆ unew_table

double unew_table[NSTEP *NSTEP]
static

Definition at line 43 of file test_cooling.c.

Referenced by test_DoCooling().