star_formation.h 25.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*******************************************************************************
 * This file is part of SWIFT.
 * Copyright (c) 2018 Folkert Nobels (nobels@strw.leidenuniv.nl)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *******************************************************************************/
19
20
#ifndef SWIFT_EAGLE_STAR_FORMATION_H
#define SWIFT_EAGLE_STAR_FORMATION_H
21

22
/* Local includes */
Folkert Nobels's avatar
Folkert Nobels committed
23
24
#include "adiabatic_index.h"
#include "cooling.h"
25
#include "cosmology.h"
Folkert Nobels's avatar
Folkert Nobels committed
26
#include "engine.h"
Folkert Nobels's avatar
Folkert Nobels committed
27
#include "entropy_floor.h"
28
#include "equation_of_state.h"
29
#include "exp10.h"
30
#include "hydro.h"
Folkert Nobels's avatar
Folkert Nobels committed
31
32
33
#include "parser.h"
#include "part.h"
#include "physical_constants.h"
34
#include "random.h"
35
#include "stars.h"
Folkert Nobels's avatar
Folkert Nobels committed
36
#include "units.h"
37

38
/**
39
40
 * @file src/star_formation/EAGLE/star_formation.h
 * @brief Star formation model used in the EAGLE model
41
42
43
44
45
 */

/**
 * @brief Properties of the EAGLE star formation model.
 */
46
struct star_formation {
Folkert Nobels's avatar
Folkert Nobels committed
47

48
  /*! Normalization of the KS star formation law (internal units) */
49
  double KS_normalization;
50

51
  /*! Normalization of the KS star formation law (Msun / kpc^2 / yr) */
52
  double KS_normalization_MSUNpYRpKPC2;
53

54
  /*! Slope of the KS law */
55
  double KS_power_law;
56
57

  /*! Slope of the high density KS law */
58
  double KS_high_den_power_law;
59

60
  /*! KS law High density threshold (internal units) */
61
  double KS_high_den_thresh;
62

63
  /*! KS high density normalization (internal units) */
64
  double KS_high_den_normalization;
Folkert Nobels's avatar
Folkert Nobels committed
65

66
  /*! KS high density normalization (H atoms per cm^3)  */
67
  double KS_high_den_thresh_HpCM3;
68

69
  /*! Critical overdensity */
70
  double min_over_den;
71

72
  /*! Dalla Vecchia & Schaye temperature criteria */
73
  double temperature_margin_threshold_dex;
74

75
76
  /*! 10^Tdex of Dalla Vecchia & SChaye temperature criteria */
  double ten_to_temperature_margin_threshold_dex;
77

78
  /*! gas fraction */
79
  double fgas;
80

81
  /*! Star formation law slope */
82
  double SF_power_law;
83

84
  /*! star formation normalization (internal units) */
85
  double SF_normalization;
Folkert Nobels's avatar
Folkert Nobels committed
86
87

  /*! star formation high density slope */
88
  double SF_high_den_power_law;
Folkert Nobels's avatar
Folkert Nobels committed
89

90
  /*! Star formation high density normalization (internal units) */
91
  double SF_high_den_normalization;
92

93
  /*! Density threshold to form stars (internal units) */
94
  double density_threshold;
95

96
  /*! Density threshold to form stars in user units */
97
  double density_threshold_HpCM3;
98

99
  /*! Maximum density threshold to form stars (internal units) */
100
  double density_threshold_max;
101

102
  /*! Maximum density threshold to form stars (H atoms per cm^3) */
103
  double density_threshold_max_HpCM3;
104

105
  /*! Reference metallicity for metal-dependant threshold */
106
  double Z0;
107

108
  /*! Inverse of reference metallicity */
109
  double Z0_inv;
110

111
  /*! critical density Metallicity power law (internal units) */
112
  double n_Z0;
113

114
  /*! Polytropic index */
115
  double EOS_polytropic_index;
116

117
  /*! EOS density norm (H atoms per cm^3) */
118
  double EOS_density_norm_HpCM3;
119

120
  /*! EOS Temperature norm (Kelvin)  */
121
  double EOS_temperature_norm_K;
122

123
124
  /*! EOS pressure norm, eq. 13 of Schaye & Dalla Vecchia 2008 (internal units)
   */
125
  double EOS_pressure_c;
126

127
128
  /*! EOS Temperarure norm, eq. 13 of Schaye & Dalla Vecchia 2008 (internal
   * units) */
129
  double EOS_temperature_c;
130
131
132

  /*! EOS density norm, eq. 13 of Schaye & Dalla Vecchia 2008 (internal units)
   */
133
  double EOS_density_c;
134

135
136
137
  /*! Inverse of EOS density norm (internal units) */
  double EOS_density_c_inv;

138
  /*! Max physical density (H atoms per cm^3)*/
139
  double max_gas_density_HpCM3;
140

141
  /*! Max physical density (internal units) */
142
  double max_gas_density;
143
144
};

145
146
147
148
149
150
151
152
153
154
155
/**
 * @brief Computes the density threshold for star-formation fo a given total
 * metallicity.
 *
 * Follows Schaye (2004) eq. 19 and 24 (see also Schaye et al. 2015, eq. 2).
 *
 * @param Z The metallicity (metal mass fraction).
 * @param starform The properties of the star formation model.
 * @param phys_const The physical constants.
 * @return The physical density threshold for star formation in internal units.
 */
156
157
INLINE static double star_formation_threshold(
    const double Z, const struct star_formation* starform,
158
159
    const struct phys_const* phys_const) {

160
  double density_threshold;
161
162

  /* Schaye (2004), eq. 19 and 24 */
163
  if (Z > 0.) {
164
165
166
167
168
169
170
171
172
173
174
    density_threshold = starform->density_threshold *
                        powf(Z * starform->Z0_inv, starform->n_Z0);
    density_threshold = min(density_threshold, starform->density_threshold_max);
  } else {
    density_threshold = starform->density_threshold_max;
  }

  /* Convert to mass density */
  return density_threshold * phys_const->const_proton_mass;
}

175
176
177
178
179
180
181
182
183
184
/**
 * @brief Compute the pressure on the polytropic equation of state for a given
 * Hydrogen number density.
 *
 * Schaye & Dalla Vecchia 2008, eq. 13.
 *
 * @param n_H The Hydrogen number density in internal units.
 * @param starform The properties of the star formation model.
 * @return The pressure on the equation of state in internal units.
 */
185
186
INLINE static double EOS_pressure(const double n_H,
                                  const struct star_formation* starform) {
187
188

  return starform->EOS_pressure_c *
189
         pow(n_H * starform->EOS_density_c_inv, starform->EOS_polytropic_index);
190
191
}

192
/**
193
194
195
 * @brief Calculate if the gas has the potential of becoming
 * a star.
 *
196
 * @param starform the star formation law properties to use.
197
198
199
200
201
202
203
 * @param p the gas particles.
 * @param xp the additional properties of the gas particles.
 * @param phys_const the physical constants in internal units.
 * @param cosmo the cosmological parameters and properties.
 * @param hydro_props The properties of the hydro scheme.
 * @param us The internal system of units.
 * @param cooling The cooling data struct.
204
 * @param entropy_floor The entropy floor assumed in this run.
205
 */
206
INLINE static int star_formation_is_star_forming(
207
208
    const struct part* restrict p, const struct xpart* restrict xp,
    const struct star_formation* starform, const struct phys_const* phys_const,
Folkert Nobels's avatar
Folkert Nobels committed
209
210
211
    const struct cosmology* cosmo,
    const struct hydro_props* restrict hydro_props,
    const struct unit_system* restrict us,
212
    const struct cooling_function_data* restrict cooling,
213
    const struct entropy_floor_properties* restrict entropy_floor_props) {
214

215
  /* Minimal density (converted from critical density) for star formation */
216
217
  const double rho_crit_times_min_over_den =
      cosmo->critical_density * starform->min_over_den;
218
219
220

  /* Physical density of the particle */
  const double physical_density = hydro_get_physical_density(p, cosmo);
Folkert Nobels's avatar
Folkert Nobels committed
221

222
223
224
  /* Deside whether we should form stars or not,
   * first we deterime if we have the correct over density
   * if that is true we calculate if either the maximum density
Folkert Nobels's avatar
Folkert Nobels committed
225
226
   * threshold is reached or if the metallicity dependent
   * threshold is reached, after this we calculate if the
227
   * temperature is appropriate */
228
  if (physical_density < rho_crit_times_min_over_den) return 0;
229
230
231
232
233

  /* In this case there are actually multiple possibilities
   * because we also need to check if the physical density exceeded
   * the appropriate limit */

234
235
236
  const double Z = p->chemistry_data.smoothed_metal_mass_fraction_total;
  const double X_H = p->chemistry_data.smoothed_metal_mass_fraction[0];
  const double n_H = physical_density * X_H;
237

238
  /* Get the density threshold */
239
  const double density_threshold =
240
      star_formation_threshold(Z, starform, phys_const);
241

242
  /* Check if it exceeded the minimum density */
243
  if (n_H < density_threshold) return 0;
244

Folkert Nobels's avatar
Folkert Nobels committed
245
246
  /* Calculate the entropy of the particle */
  const double entropy = hydro_get_physical_entropy(p, xp, cosmo);
Folkert Nobels's avatar
Folkert Nobels committed
247

Folkert Nobels's avatar
Folkert Nobels committed
248
  /* Calculate the entropy EOS of the particle */
Folkert Nobels's avatar
Folkert Nobels committed
249
  const double entropy_eos = entropy_floor(p, cosmo, entropy_floor_props);
250

251
  /* Check the Scahye & Dalla Vecchia 2012 EOS-based temperature critrion */
Folkert Nobels's avatar
Folkert Nobels committed
252
253
  return (entropy <
          entropy_eos * starform->ten_to_temperature_margin_threshold_dex);
254
255
}

256
/**
257
258
 * @brief Compute the star-formation rate of a given particle and store
 * it into the #xpart.
Folkert Nobels's avatar
Folkert Nobels committed
259
 *
260
261
262
 * @param p #part.
 * @param xp the #xpart.
 * @param starform the star formation law properties to use
263
264
 * @param phys_const the physical constants in internal units.
 * @param cosmo the cosmological parameters and properties.
265
 * @param dt_star The time-step of this particle.
266
 */
267
INLINE static void star_formation_compute_SFR(
268
    const struct part* restrict p, struct xpart* restrict xp,
269
270
    const struct star_formation* starform, const struct phys_const* phys_const,
    const struct cosmology* cosmo, const double dt_star) {
Folkert Nobels's avatar
Folkert Nobels committed
271

272
  /* Abort early if time-step size is 0 */
273
  if (dt_star == 0.) {
274
275
276

    xp->sf_data.SFR = 0.f;
    return;
277
  }
278

279
280
281
282
  /* Hydrogen number density of this particle */
  const double physical_density = hydro_get_physical_density(p, cosmo);
  const double X_H = p->chemistry_data.smoothed_metal_mass_fraction[0];
  const double n_H = physical_density * X_H / phys_const->const_proton_mass;
Matthieu Schaller's avatar
Matthieu Schaller committed
283

284
285
286
  /* Are we above the threshold for automatic star formation? */
  if (physical_density >
      starform->max_gas_density * phys_const->const_proton_mass) {
287

288
    xp->sf_data.SFR = hydro_get_mass(p) / dt_star;
289
290
    return;
  }
291

292
293
  /* Pressure on the effective EOS for this particle */
  const double pressure = EOS_pressure(n_H, starform);
Folkert Nobels's avatar
Folkert Nobels committed
294

295
296
297
298
  /* Calculate the specific star formation rate */
  double SFRpergasmass;
  if (hydro_get_physical_density(p, cosmo) <
      starform->KS_high_den_thresh * phys_const->const_proton_mass) {
299

300
301
    SFRpergasmass =
        starform->SF_normalization * pow(pressure, starform->SF_power_law);
302

303
  } else {
304

305
306
307
    SFRpergasmass = starform->SF_high_den_normalization *
                    pow(pressure, starform->SF_high_den_power_law);
  }
308

309
  /* Store the SFR */
310
  xp->sf_data.SFR = SFRpergasmass * hydro_get_mass(p);
311
}
312

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/**
 * @brief Decides whether a particle should be converted into a
 * star or not.
 *
 * Equation 21 of Schaye & Dalla Vecchia 2008.
 *
 * @param p The #part.
 * @param xp The #xpart.
 * @param starform The properties of the star formation model.
 * @param e The #engine (for random numbers).
 * @param dt_star The time-step of this particle
 * @return 1 if a conversion should be done, 0 otherwise.
 */
INLINE static int star_formation_should_convert_to_star(
    const struct part* p, const struct xpart* xp,
    const struct star_formation* starform, const struct engine* e,
    const double dt_star) {
330

331
  /* Calculate the propability of forming a star */
332
  const double prob = xp->sf_data.SFR * dt_star / hydro_get_mass(p);
333

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
  /* Get a unique random number between 0 and 1 for star formation */
  const double random_number =
      random_unit_interval(p->id, e->ti_current, random_number_star_formation);

  /* Have we been lucky and need to form a star? */
  return (prob > random_number);
}

/**
 * @brief Update the SF properties of a particle that is not star forming.
 *
 * @param p The #part.
 * @param xp The #xpart.
 * @param e The #engine.
 * @param starform The properties of the star formation model.
 * @param with_cosmology Are we running with cosmology switched on?
 */
INLINE static void star_formation_update_part_not_SFR(
    struct part* p, struct xpart* xp, const struct engine* e,
    const struct star_formation* starform, const int with_cosmology) {
354
355

  /* Check if it is the first time steps after star formation */
356
  if (xp->sf_data.SFR > 0.f) {
357
358
359

    /* Record the current time as an indicator of when this particle was last
       star-forming. */
360
    if (with_cosmology) {
361
      xp->sf_data.SFR = -e->cosmology->a;
362
    } else {
363
      xp->sf_data.SFR = -e->time;
364
    }
365
  }
366
}
Folkert Nobels's avatar
Folkert Nobels committed
367

368
/**
369
370
371
372
373
374
 * @brief Copies the properties of the gas particle over to the
 * star particle
 *
 * @param e The #engine
 * @param p the gas particles.
 * @param xp the additional properties of the gas particles.
375
 * @param sp the new created star particle with its properties.
376
377
378
379
 * @param starform the star formation law properties to use.
 * @param cosmo the cosmological parameters and properties.
 * @param with_cosmology if we run with cosmology.
 */
380
INLINE static void star_formation_copy_properties(
381
382
    const struct part* p, const struct xpart* xp, struct spart* sp,
    const struct engine* e, const struct star_formation* starform,
383
384
385
386
387
    const struct cosmology* cosmo, const int with_cosmology,
    const struct phys_const* phys_const,
    const struct hydro_props* restrict hydro_props,
    const struct unit_system* restrict us,
    const struct cooling_function_data* restrict cooling) {
Folkert Nobels's avatar
Folkert Nobels committed
388

389
  /* Store the current mass */
390
  sp->mass = hydro_get_mass(p);
391
392

  /* Store the current mass as the initial mass */
393
  sp->mass_init = hydro_get_mass(p);
394
395

  /* Store either the birth_scale_factor or birth_time depending  */
396
  if (with_cosmology) {
397
    sp->birth_scale_factor = cosmo->a;
398
  } else {
Folkert Nobels's avatar
Folkert Nobels committed
399
    sp->birth_time = e->time;
400
  }
401
402

  /* Store the chemistry struct in the star particle */
Folkert Nobels's avatar
Folkert Nobels committed
403
  sp->chemistry_data = p->chemistry_data;
404
405

  /* Store the tracers data */
406
  sp->tracers_data = xp->tracers_data;
407
408

  /* Store the birth density in the star particle */
409
  sp->birth_density = hydro_get_physical_density(p, cosmo);
410

411
  /* Store the birth temperature in the star particle */
Folkert Nobels's avatar
Folkert Nobels committed
412
413
  sp->birth_temperature = cooling_get_temperature(phys_const, hydro_props, us,
                                                  cosmo, cooling, p, xp);
414

415
416
  /* Flag that this particle has not done feedback yet */
  sp->f_E = -1.f;
417
}
418

419
/**
Folkert Nobels's avatar
Folkert Nobels committed
420
 * @brief initialization of the star formation law
421
422
423
 *
 * @param parameter_file The parsed parameter file
 * @param phys_const Physical constants in internal units
424
425
 * @param us The current internal system of units.
 * @param hydro_props The propertis of the hydro model.
426
 * @param starform the star formation law properties to initialize
427
 */
428
INLINE static void starformation_init_backend(
Folkert Nobels's avatar
Folkert Nobels committed
429
    struct swift_params* parameter_file, const struct phys_const* phys_const,
430
431
    const struct unit_system* us, const struct hydro_props* hydro_props,
    struct star_formation* starform) {
Folkert Nobels's avatar
Folkert Nobels committed
432
433

  /* Get the Gravitational constant */
434
  const double G_newton = phys_const->const_newton_G;
Folkert Nobels's avatar
Folkert Nobels committed
435

436
  /* Initial Hydrogen abundance (mass fraction) */
437
  const double X_H = hydro_props->hydrogen_mass_fraction;
438
439

  /* Mean molecular weight assuming neutral gas */
440
  const double mean_molecular_weight = hydro_props->mu_neutral;
441

442
  /* Get the surface density unit Msun / pc^2 in internal units */
443
  const double Msun_per_pc2 =
444
445
      phys_const->const_solar_mass /
      (phys_const->const_parsec * phys_const->const_parsec);
Folkert Nobels's avatar
Folkert Nobels committed
446

447
448
449
450
  /* Get the SF surface density unit Msun / kpc^2 / yr in internal units */
  const double kpc = 1000. * phys_const->const_parsec;
  const double Msun_per_kpc2_per_year =
      phys_const->const_solar_mass / (kpc * kpc) / phys_const->const_year;
Folkert Nobels's avatar
Folkert Nobels committed
451

452
  /* Conversion of number density from cgs */
453
  const double number_density_from_cgs =
454
      1. / units_cgs_conversion_factor(us, UNIT_CONV_NUMBER_DENSITY);
455

Folkert Nobels's avatar
Folkert Nobels committed
456
457
458
  /* Quantities that have to do with the Normal Kennicutt-
   * Schmidt law will be read in this part of the code*/

459
  /* Load the equation of state for this model */
460
  starform->EOS_polytropic_index = parser_get_param_double(
461
      parameter_file, "EAGLEStarFormation:EOS_gamma_effective");
462
  starform->EOS_temperature_norm_K = parser_get_param_double(
463
      parameter_file, "EAGLEStarFormation:EOS_temperature_norm_K");
464
465
  starform->EOS_density_norm_HpCM3 = parser_get_param_double(
      parameter_file, "EAGLEStarFormation:EOS_density_norm_H_p_cm3");
466
  starform->EOS_density_c =
467
      starform->EOS_density_norm_HpCM3 * number_density_from_cgs;
468
  starform->EOS_density_c_inv = 1. / starform->EOS_density_c;
469
470

  /* Calculate the EOS pressure normalization */
471
472
  starform->EOS_pressure_c =
      starform->EOS_density_c * starform->EOS_temperature_norm_K *
473
      phys_const->const_boltzmann_k / mean_molecular_weight / X_H;
474

475
476
477
478
479
480
  /* Normalisation of the temperature in the EOS calculatio */
  starform->EOS_temperature_c =
      starform->EOS_pressure_c / phys_const->const_boltzmann_k;
  starform->EOS_temperature_c *=
      pow(starform->EOS_density_c, starform->EOS_polytropic_index);

481
  /* Read the critical density contrast from the parameter file*/
482
  starform->min_over_den = parser_get_param_double(
483
      parameter_file, "EAGLEStarFormation:KS_min_over_density");
484
485

  /* Read the gas fraction from the file */
486
487
  starform->fgas = parser_get_opt_param_double(
      parameter_file, "EAGLEStarFormation:gas_fraction", 1.);
488
489

  /* Read the Kennicutt-Schmidt power law exponent */
Folkert Nobels's avatar
Folkert Nobels committed
490
  starform->KS_power_law =
491
      parser_get_param_double(parameter_file, "EAGLEStarFormation:KS_exponent");
492
493

  /* Calculate the power law of the corresponding star formation Schmidt law */
494
  starform->SF_power_law = (starform->KS_power_law - 1.) / 2.;
495

496
  /* Read the normalization of the KS law in KS law units */
497
  starform->KS_normalization_MSUNpYRpKPC2 = parser_get_param_double(
498
      parameter_file, "EAGLEStarFormation:KS_normalisation");
Folkert Nobels's avatar
Folkert Nobels committed
499

500
  /* Convert to internal units */
501
  starform->KS_normalization =
502
      starform->KS_normalization_MSUNpYRpKPC2 * Msun_per_kpc2_per_year;
Folkert Nobels's avatar
Folkert Nobels committed
503

504
505
  /* Calculate the starformation pre-factor (eq. 12 of Schaye & Dalla Vecchia
   * 2008) */
Folkert Nobels's avatar
Folkert Nobels committed
506
  starform->SF_normalization =
507
      starform->KS_normalization * pow(Msun_per_pc2, -starform->KS_power_law) *
Folkert Nobels's avatar
Folkert Nobels committed
508
      pow(hydro_gamma * starform->fgas / G_newton, starform->SF_power_law);
Folkert Nobels's avatar
Folkert Nobels committed
509

510
  /* Read the high density Kennicutt-Schmidt power law exponent */
511
  starform->KS_high_den_power_law = parser_get_param_double(
512
      parameter_file, "EAGLEStarFormation:KS_high_density_exponent");
513

Folkert Nobels's avatar
Folkert Nobels committed
514
  /* Calculate the SF high density power law */
515
  starform->SF_high_den_power_law = (starform->KS_high_den_power_law - 1.) / 2.;
516

517
  /* Read the high density criteria for the KS law in number density per cm^3 */
518
  starform->KS_high_den_thresh_HpCM3 = parser_get_param_double(
519
      parameter_file, "EAGLEStarFormation:KS_high_density_threshold_H_p_cm3");
520

521
522
523
  /* Transform the KS high density criteria to simulation units */
  starform->KS_high_den_thresh =
      starform->KS_high_den_thresh_HpCM3 * number_density_from_cgs;
524

525
  /* Pressure at the high-density threshold */
526
  const double EOS_high_den_pressure =
527
      EOS_pressure(starform->KS_high_den_thresh, starform);
528

529
  /* Calculate the KS high density normalization
530
   * We want the SF law to be continous so the normalisation of the second
531
532
   * power-law is the value of the first power-law at the high-density threshold
   */
Folkert Nobels's avatar
Folkert Nobels committed
533
534
  starform->KS_high_den_normalization =
      starform->KS_normalization *
535
536
537
538
      pow(Msun_per_pc2,
          starform->KS_high_den_power_law - starform->KS_power_law) *
      pow(hydro_gamma * EOS_high_den_pressure * starform->fgas / G_newton,
          (starform->KS_power_law - starform->KS_high_den_power_law) * 0.5f);
539

Folkert Nobels's avatar
Folkert Nobels committed
540
  /* Calculate the SF high density normalization */
Folkert Nobels's avatar
Folkert Nobels committed
541
542
  starform->SF_high_den_normalization =
      starform->KS_high_den_normalization *
543
      pow(Msun_per_pc2, -starform->KS_high_den_power_law) *
Folkert Nobels's avatar
Folkert Nobels committed
544
545
      pow(hydro_gamma * starform->fgas / G_newton,
          starform->SF_high_den_power_law);
546

547
  /* Get the maximum physical density for SF */
548
  starform->max_gas_density_HpCM3 = parser_get_opt_param_double(
549
550
      parameter_file, "EAGLEStarFormation:KS_max_density_threshold_H_p_cm3",
      FLT_MAX);
551
552
553
554
555

  /* Convert the maximum physical density to internal units */
  starform->max_gas_density =
      starform->max_gas_density_HpCM3 * number_density_from_cgs;

556
557
  starform->temperature_margin_threshold_dex = parser_get_opt_param_double(
      parameter_file, "EAGLEStarFormation:KS_temperature_margin_dex", FLT_MAX);
558

559
560
  starform->ten_to_temperature_margin_threshold_dex =
      exp10(starform->temperature_margin_threshold_dex);
561

Folkert Nobels's avatar
Folkert Nobels committed
562
  /* Read the normalization of the metallicity dependent critical
563
   * density*/
564
  starform->density_threshold_HpCM3 = parser_get_param_double(
565
      parameter_file, "EAGLEStarFormation:threshold_norm_H_p_cm3");
566

567
  /* Convert to internal units */
568
  starform->density_threshold =
569
      starform->density_threshold_HpCM3 * number_density_from_cgs;
570
571

  /* Read the scale metallicity Z0 */
572
573
574
  starform->Z0 = parser_get_param_double(parameter_file,
                                         "EAGLEStarFormation:threshold_Z0");
  starform->Z0_inv = 1. / starform->Z0;
575
576

  /* Read the power law of the critical density scaling */
577
578
  starform->n_Z0 = parser_get_param_double(
      parameter_file, "EAGLEStarFormation:threshold_slope");
579
580

  /* Read the maximum allowed density for star formation */
581
  starform->density_threshold_max_HpCM3 = parser_get_param_double(
582
      parameter_file, "EAGLEStarFormation:threshold_max_density_H_p_cm3");
583

584
  /* Convert to internal units */
585
  starform->density_threshold_max =
586
      starform->density_threshold_max_HpCM3 * number_density_from_cgs;
587
588
}

589
590
/**
 * @brief Prints the used parameters of the star formation law
591
 *
592
 * @param starform the star formation law properties.
593
 * */
594
INLINE static void starformation_print_backend(
Folkert Nobels's avatar
Folkert Nobels committed
595
596
    const struct star_formation* starform) {

597
  message("Star formation law is EAGLE (Schaye & Dalla Vecchia 2008)");
598
599
  message(
      "With properties: normalization = %e Msun/kpc^2/yr, slope of the"
600
      "Kennicutt-Schmidt law = %e and gas fraction = %e ",
601
602
      starform->KS_normalization_MSUNpYRpKPC2, starform->KS_power_law,
      starform->fgas);
603
  message("At densities of %e H/cm^3 the slope changes to %e.",
Matthieu Schaller's avatar
Matthieu Schaller committed
604
          starform->KS_high_den_thresh_HpCM3, starform->KS_high_den_power_law);
605
606
607
  message(
      "The effective equation of state is given by: polytropic "
      "index = %e , normalization density = %e #/cm^3 and normalization "
608
      "temperature = %e K",
609
610
      starform->EOS_polytropic_index, starform->EOS_density_norm_HpCM3,
      starform->EOS_temperature_norm_K);
611
  message("Density threshold follows Schaye (2004)");
Folkert Nobels's avatar
Folkert Nobels committed
612
  message(
613
      "the normalization of the density threshold is given by"
614
      " %e #/cm^3, with metallicity slope of %e, and metallicity normalization"
615
      " of %e, the maximum density threshold is given by %e #/cm^3",
616
      starform->density_threshold_HpCM3, starform->n_Z0, starform->Z0,
617
      starform->density_threshold_max_HpCM3);
618
  message("Temperature threshold is given by Dalla Vecchia and Schaye (2012)");
619
620
  message("The temperature threshold offset from the EOS is given by: %e dex",
          starform->temperature_margin_threshold_dex);
621
622
  message("Running with a maximum gas density given by: %e #/cm^3",
          starform->max_gas_density_HpCM3);
623
624
}

625
626
627
/**
 * @brief Finishes the density calculation.
 *
628
629
630
 * Nothing to do here. We do not need to compute any quantity in the hydro
 * density loop for the EAGLE star formation model.
 *
631
632
633
634
635
636
637
638
639
640
641
 * @param p The particle to act upon
 * @param cd The global star_formation information.
 * @param cosmo The current cosmological model.
 */
__attribute__((always_inline)) INLINE static void star_formation_end_density(
    struct part* restrict p, const struct star_formation* cd,
    const struct cosmology* cosmo) {}

/**
 * @brief Sets all particle fields to sensible values when the #part has 0 ngbs.
 *
642
643
644
 * Nothing to do here. We do not need to compute any quantity in the hydro
 * density loop for the EAGLE star formation model.
 *
645
646
647
648
649
650
651
 * @param p The particle to act upon
 * @param xp The extended particle data to act upon
 * @param cd #star_formation containing star_formation informations.
 * @param cosmo The current cosmological model.
 */
__attribute__((always_inline)) INLINE static void
star_formation_part_has_no_neighbours(struct part* restrict p,
Loic Hausammann's avatar
Format    
Loic Hausammann committed
652
653
654
                                      struct xpart* restrict xp,
                                      const struct star_formation* cd,
                                      const struct cosmology* cosmo) {}
655
656

/**
Loic Hausammann's avatar
Format    
Loic Hausammann committed
657
658
 * @brief Sets the star_formation properties of the (x-)particles to a valid
 * start state.
659
660
661
662
663
664
665
666
667
668
 *
 * Nothing to do here.
 *
 * @param phys_const The physical constant in internal units.
 * @param us The unit system.
 * @param cosmo The current cosmological model.
 * @param data The global star_formation information used for this run.
 * @param p Pointer to the particle data.
 * @param xp Pointer to the extended particle data.
 */
Loic Hausammann's avatar
Format    
Loic Hausammann committed
669
670
671
672
673
674
675
__attribute__((always_inline)) INLINE static void
star_formation_first_init_part(const struct phys_const* restrict phys_const,
                               const struct unit_system* restrict us,
                               const struct cosmology* restrict cosmo,
                               const struct star_formation* data,
                               const struct part* restrict p,
                               struct xpart* restrict xp) {}
676
677

/**
Loic Hausammann's avatar
Format    
Loic Hausammann committed
678
679
 * @brief Sets the star_formation properties of the (x-)particles to a valid
 * start state.
680
 *
681
682
 * Nothing to do here. We do not need to compute any quantity in the hydro
 * density loop for the EAGLE star formation model.
683
684
685
686
687
688
689
 *
 * @param p Pointer to the particle data.
 * @param data The global star_formation information.
 */
__attribute__((always_inline)) INLINE static void star_formation_init_part(
    struct part* restrict p, const struct star_formation* data) {}

690
#endif /* SWIFT_EAGLE_STAR_FORMATION_H */