stellar_evolution.c 17.7 KB
Newer Older
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
/*******************************************************************************
 * This file is part of SWIFT.
 * Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch)
 *
 * 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/>.
 *
 ******************************************************************************/

/* Include header */
#include "stellar_evolution.h"

/* Include local headers */
#include "hdf5_functions.h"
#include "initial_mass_function.h"
#include "lifetime.h"
#include "random.h"
#include "stellar_evolution_struct.h"
#include "supernovae_ia.h"
#include "supernovae_ii.h"

#include <math.h>
#include <stddef.h>

/**
 * @brief Print the stellar model.
 *
 * @param sm The #stellar_model.
 */
void stellar_model_print(const struct stellar_model* sm) {

  /* Only the master print */
  if (engine_rank != 0) {
    return;
  }

  /* Print the type of yields */
  message("Discrete yields? %i", sm->discrete_yields);

  /* Print the sub properties */
  initial_mass_function_print(&sm->imf);
  lifetime_print(&sm->lifetime);
  supernovae_ia_print(&sm->snia);
  supernovae_ii_print(&sm->snii);
}

/**
 * @brief Compute the integer number of supernovae from the floating number.
 *
 * @param sp The particle to act upon
 * @param number_supernovae_f Floating number of supernovae during this step.
 * @param ti_begin The #integertime_t at the begining of the step.
 * @param random_type The categorie of random.
 *
 * @return The integer number of supernovae.
 */
int stellar_evolution_compute_integer_number_supernovae(
    struct spart* restrict sp, float number_supernovae_f,
    const integertime_t ti_begin, enum random_number_type random_type) {

  const int number_supernovae_i = floor(number_supernovae_f);

  /* Get the random number for the decimal part */
  const float rand_sn = random_unit_interval(sp->id, ti_begin, random_type);

  /* Get the fraction part */
  const float frac_sn = number_supernovae_f - number_supernovae_i;

  /* Get the integer number of SN */
80
  return number_supernovae_i + (rand_sn < frac_sn);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
}

/**
 * @brief Compute the feedback properties.
 *
 * @param sp The particle to act upon
 * @param sm The #stellar_model structure.
 * @param phys_const The physical constants in the internal unit system.
 * @param log_m_beg_step Mass of a star ending its life at the begining of the
 * step (log10(solMass))
 * @param log_m_end_step Mass of a star ending its life at the end of the step
 * (log10(solMass))
 * @param m_beg_step Mass of a star ending its life at the begining of the step
 * (solMass)
 * @param m_end_step Mass of a star ending its life at the end of the step
 * (solMass)
Loic Hausammann's avatar
Loic Hausammann committed
97
 * @param m_init Birth mass of the stellar particle (solMass).
Loic Hausammann's avatar
Loic Hausammann committed
98 99 100 101
 * @param number_snia_f (Floating) Number of SNIa produced by the stellar
 * particle.
 * @param number_snii_f (Floating) Number of SNII produced by the stellar
 * particle.
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
102 103 104 105 106 107
 *
 */
void stellar_evolution_compute_continuous_feedback_properties(
    struct spart* restrict sp, const struct stellar_model* sm,
    const struct phys_const* phys_const, const float log_m_beg_step,
    const float log_m_end_step, const float m_beg_step, const float m_end_step,
108
    const float m_init, const float number_snia_f, const float number_snii_f) {
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
109 110 111

  /* Compute the mass ejected */
  /* SNIa */
Loic Hausammann's avatar
Loic Hausammann committed
112
  const float mass_snia =
Loic Hausammann's avatar
Loic Hausammann committed
113
      supernovae_ia_get_ejected_mass_processed(&sm->snia) * number_snia_f;
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
114 115

  /* SNII */
Loic Hausammann's avatar
Loic Hausammann committed
116 117
  const float mass_frac_snii =
      supernovae_ii_get_ejected_mass_fraction_processed_from_integral(
Loic Hausammann's avatar
Loic Hausammann committed
118
          &sm->snii, log_m_end_step, log_m_beg_step);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
119

Loic Hausammann's avatar
Loic Hausammann committed
120
  /* Sum the contributions from SNIa and SNII */
Loic Hausammann's avatar
Loic Hausammann committed
121 122
  sp->feedback_data.mass_ejected = mass_frac_snii * sp->sf_data.birth_mass +
                                   mass_snia * phys_const->const_solar_mass;
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
123 124 125

  if (sp->mass <= sp->feedback_data.mass_ejected) {
    error("Stars cannot have negative mass. (%g <= %g). Initial mass = %g",
126
          sp->mass, sp->feedback_data.mass_ejected, sp->sf_data.birth_mass);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
127 128 129 130 131 132 133 134 135 136 137 138
  }

  /* Update the mass */
  sp->mass -= sp->feedback_data.mass_ejected;

  /* Now deal with the metals */

  /* Get the SNIa yields */
  const float* snia_yields = supernovae_ia_get_yields(&sm->snia);

  /* Compute the SNII yields */
  float snii_yields[GEAR_CHEMISTRY_ELEMENT_COUNT];
Loic Hausammann's avatar
Loic Hausammann committed
139 140
  supernovae_ii_get_yields_from_integral(&sm->snii, log_m_end_step,
                                         log_m_beg_step, snii_yields);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
141 142

  /* Compute the mass fraction of non processed elements */
Loic Hausammann's avatar
Loic Hausammann committed
143 144 145
  const float non_processed =
      supernovae_ii_get_ejected_mass_fraction_non_processed_from_integral(
          &sm->snii, log_m_end_step, log_m_beg_step);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
146 147 148 149 150

  /* Set the yields */
  for (int i = 0; i < GEAR_CHEMISTRY_ELEMENT_COUNT; i++) {
    /* Compute the mass fraction of metals */
    sp->feedback_data.metal_mass_ejected[i] =
Loic Hausammann's avatar
Loic Hausammann committed
151 152 153 154
        /* Supernovae II yields */
        snii_yields[i] +
        /* Gas contained in stars initial metallicity */
        chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed;
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
155 156

    /* Convert it to total mass */
157
    sp->feedback_data.metal_mass_ejected[i] *= sp->sf_data.birth_mass;
Loic Hausammann's avatar
Loic Hausammann committed
158 159 160

    /* Add the Supernovae Ia */
    sp->feedback_data.metal_mass_ejected[i] +=
Loic Hausammann's avatar
Loic Hausammann committed
161
        snia_yields[i] * number_snia_f * phys_const->const_solar_mass;
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
  }
}

/**
 * @brief Compute the feedback properties.
 *
 * @param sp The particle to act upon
 * @param sm The #stellar_model structure.
 * @param phys_const The physical constants in the internal unit system.
 * @param log_m_beg_step Mass of a star ending its life at the begining of the
 * step (log10(solMass))
 * @param log_m_end_step Mass of a star ending its life at the end of the step
 * (log10(solMass))
 * @param m_beg_step Mass of a star ending its life at the begining of the step
 * (solMass)
 * @param m_end_step Mass of a star ending its life at the end of the step
 * (solMass)
179
 * @param m_init Birth mass in solMass.
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
180 181 182 183 184 185 186 187 188 189
 * @param number_snia Number of SNIa produced by the stellar particle.
 * @param number_snii Number of SNII produced by the stellar particle.
 *
 */
void stellar_evolution_compute_discrete_feedback_properties(
    struct spart* restrict sp, const struct stellar_model* sm,
    const struct phys_const* phys_const, const float log_m_beg_step,
    const float log_m_end_step, const float m_beg_step, const float m_end_step,
    const float m_init, const int number_snia, const int number_snii) {

Loic Hausammann's avatar
Loic Hausammann committed
190 191 192 193
  /* Limit the mass within the imf limits */
  const float m_beg_lim = min(m_beg_step, sm->imf.mass_max);
  const float m_end_lim = max(m_end_step, sm->imf.mass_min);

194
  /* Compute the average mass */
Loic Hausammann's avatar
Loic Hausammann committed
195
  const float m_avg = 0.5 * (m_beg_lim + m_end_lim);
196
  const float log_m_avg = log10(m_avg);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
197 198 199 200

  /* Compute the mass ejected */
  /* SNIa */
  const float mass_snia =
Loic Hausammann's avatar
Loic Hausammann committed
201
      supernovae_ia_get_ejected_mass_processed(&sm->snia) * number_snia;
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
202 203 204

  /* SNII */
  const float mass_snii =
Loic Hausammann's avatar
Loic Hausammann committed
205 206 207
      supernovae_ii_get_ejected_mass_fraction_processed_from_raw(&sm->snii,
                                                                 log_m_avg) *
      m_avg * number_snii;
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
208 209 210 211 212 213 214 215

  sp->feedback_data.mass_ejected = mass_snia + mass_snii;

  /* Transform into internal units */
  sp->feedback_data.mass_ejected *= phys_const->const_solar_mass;

  if (sp->mass <= sp->feedback_data.mass_ejected) {
    error("Stars cannot have negative mass. (%g <= %g). Initial mass = %g",
216
          sp->mass, sp->feedback_data.mass_ejected, sp->sf_data.birth_mass);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
217 218 219 220 221 222 223 224
  }

  /* Update the mass */
  sp->mass -= sp->feedback_data.mass_ejected;

  /* Get the SNIa yields */
  const float* snia_yields = supernovae_ia_get_yields(&sm->snia);

225
  /* Compute the SNII yields */
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
226
  float snii_yields[GEAR_CHEMISTRY_ELEMENT_COUNT];
227
  supernovae_ii_get_yields_from_raw(&sm->snii, log_m_avg, snii_yields);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
228 229 230

  /* Compute the mass fraction of non processed elements */
  const float non_processed =
Loic Hausammann's avatar
Loic Hausammann committed
231 232
      supernovae_ii_get_ejected_mass_fraction_non_processed_from_raw(&sm->snii,
                                                                     log_m_avg);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
233 234 235 236 237

  /* Set the yields */
  for (int i = 0; i < GEAR_CHEMISTRY_ELEMENT_COUNT; i++) {
    /* Compute the mass fraction of metals */
    sp->feedback_data.metal_mass_ejected[i] =
Loic Hausammann's avatar
Loic Hausammann committed
238 239 240 241
        /* Supernovae II yields */
        snii_yields[i] +
        /* Gas contained in stars initial metallicity */
        chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed;
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
242 243

    /* Convert it to total mass */
244 245 246
    sp->feedback_data.metal_mass_ejected[i] *= m_avg * number_snii;

    /* Supernovae Ia yields */
Loic Hausammann's avatar
Loic Hausammann committed
247
    sp->feedback_data.metal_mass_ejected[i] += snia_yields[i] * number_snia;
248 249 250

    /* Convert everything in code units */
    sp->feedback_data.metal_mass_ejected[i] *= phys_const->const_solar_mass;
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
  }
}

/**
 * @brief Evolve the stellar properties of a #spart.
 *
 * This function compute the SN rate and yields before sending
 * this information to a different MPI rank.
 *
 * Here I am using Myr-solar mass units internally in order to
 * avoid numerical errors.
 *
 * @param sp The particle to act upon
 * @param sm The #stellar_model structure.
 * @param cosmo The current cosmological model.
 * @param us The unit system.
 * @param phys_const The physical constants in the internal unit system.
 * @param ti_begin The #integertime_t at the begining of the step.
 * @param star_age_beg_step The age of the star at the star of the time-step in
 * internal units.
 * @param dt The time-step size of this star in internal units.
 */
void stellar_evolution_evolve_spart(
    struct spart* restrict sp, const struct stellar_model* sm,
    const struct cosmology* cosmo, const struct unit_system* us,
    const struct phys_const* phys_const, const integertime_t ti_begin,
    const double star_age_beg_step, const double dt) {

  /* Convert the inputs */
  const double conversion_to_myr = phys_const->const_year * 1e6;
  const double star_age_beg_step_myr = star_age_beg_step / conversion_to_myr;
  const double dt_myr = dt / conversion_to_myr;

  /* Get the metallicity */
  const float metallicity =
      chemistry_get_total_metal_mass_fraction_for_feedback(sp);

  /* Compute masses range */
  const float log_m_beg_step =
      star_age_beg_step == 0.
          ? FLT_MAX
          : lifetime_get_log_mass_from_lifetime(
                &sm->lifetime, log10(star_age_beg_step_myr), metallicity);
  const float log_m_end_step = lifetime_get_log_mass_from_lifetime(
      &sm->lifetime, log10(star_age_beg_step_myr + dt_myr), metallicity);

  const float m_beg_step =
298 299
      star_age_beg_step == 0. ? FLT_MAX : exp10(log_m_beg_step);
  const float m_end_step = exp10(log_m_end_step);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
300 301 302 303 304 305 306 307 308 309 310

  /* Check if the star can produce a supernovae */
  const int can_produce_snia =
      supernovae_ia_can_explode(&sm->snia, m_end_step, m_beg_step);
  const int can_produce_snii =
      supernovae_ii_can_explode(&sm->snii, m_end_step, m_beg_step);

  /* Is it possible to generate a supernovae? */
  if (!can_produce_snia && !can_produce_snii) return;

  /* Compute the initial mass */
311
  const float m_init = sp->sf_data.birth_mass / phys_const->const_solar_mass;
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
312 313

  /* Compute number of SNIa */
Loic Hausammann's avatar
Loic Hausammann committed
314 315
  float number_snia_f = 0;
  if (can_produce_snia) {
316 317 318
    number_snia_f = supernovae_ia_get_number_per_unit_mass(
                        &sm->snia, m_end_step, m_beg_step) *
                    m_init;
Loic Hausammann's avatar
Loic Hausammann committed
319
  }
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
320 321

  /* Compute number of SNII */
Loic Hausammann's avatar
Loic Hausammann committed
322 323
  float number_snii_f = 0;
  if (can_produce_snii) {
324 325 326
    number_snii_f = supernovae_ii_get_number_per_unit_mass(
                        &sm->snii, m_end_step, m_beg_step) *
                    m_init;
Loic Hausammann's avatar
Loic Hausammann committed
327
  }
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
328 329

  /* Does this star produce a supernovae? */
330
  if (number_snia_f == 0 && number_snii_f == 0) return;
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
331 332 333

  /* Compute the properties of the feedback (e.g. yields) */
  if (sm->discrete_yields) {
334 335
    /* Get the integer number of supernovae */
    const int number_snia = stellar_evolution_compute_integer_number_supernovae(
Loic Hausammann's avatar
Loic Hausammann committed
336
        sp, number_snia_f, ti_begin, random_number_stellar_feedback_1);
337 338 339

    /* Get the integer number of supernovae */
    const int number_snii = stellar_evolution_compute_integer_number_supernovae(
Loic Hausammann's avatar
Loic Hausammann committed
340
        sp, number_snii_f, ti_begin, random_number_stellar_feedback_2);
341

342 343 344 345 346 347 348
    /* Do we have a supernovae? */
    if (number_snia == 0 && number_snii == 0) return;

    /* Save the number of supernovae */
    sp->feedback_data.number_sn = number_snia + number_snii;

    /* Compute the yields */
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
349 350 351
    stellar_evolution_compute_discrete_feedback_properties(
        sp, sm, phys_const, log_m_beg_step, log_m_end_step, m_beg_step,
        m_end_step, m_init, number_snia, number_snii);
352

Loic Hausammann's avatar
Gear  
Loic Hausammann committed
353
  } else {
354 355 356 357
    /* Save the number of supernovae */
    sp->feedback_data.number_sn = number_snia_f + number_snii_f;

    /* Compute the yields */
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
358 359
    stellar_evolution_compute_continuous_feedback_properties(
        sp, sm, phys_const, log_m_beg_step, log_m_end_step, m_beg_step,
360
        m_end_step, m_init, number_snia_f, number_snii_f);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
  }
}

/**
 * @brief Get the name of the element i.
 *
 * @param sm The #stellar_model.
 * @param i The element indice.
 */
const char* stellar_evolution_get_element_name(const struct stellar_model* sm,
                                               int i) {

  return sm->elements_name + i * GEAR_LABELS_SIZE;
}

/**
 * @brief Read the name of all the elements present in the tables.
 *
 * @param sm The #stellar_model.
Loic Hausammann's avatar
Loic Hausammann committed
380
 * @param params The #swift_params.
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
381 382 383 384
 */
void stellar_evolution_read_elements(struct stellar_model* sm,
                                     struct swift_params* params) {

Loic Hausammann's avatar
Loic Hausammann committed
385 386 387 388 389 390 391 392
  /* Read the elements from the parameter file. */
  int nval = -1;
  char** elements;
  parser_get_param_string_array(params, "GEARFeedback:elements", &nval,
                                &elements);

  /* Check that we have the correct number of elements. */
  if (nval != GEAR_CHEMISTRY_ELEMENT_COUNT - 1) {
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
393
    error(
Loic Hausammann's avatar
Loic Hausammann committed
394 395 396 397 398
        "You need to provide %i elements but found %i. "
        "If you wish to provide a different number of elements, "
        "you need to compile with --with-chemistry=GEAR_N where N "
        "is the number of elements + 1.",
        GEAR_CHEMISTRY_ELEMENT_COUNT, nval);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
399 400
  }

Loic Hausammann's avatar
Loic Hausammann committed
401 402 403 404
  /* Copy the elements into the stellar model. */
  for (int i = 0; i < nval; i++) {
    if (strlen(elements[i]) >= GEAR_LABELS_SIZE) {
      error("Element name '%s' too long", elements[i]);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
405
    }
Loic Hausammann's avatar
Loic Hausammann committed
406
    strcpy(sm->elements_name + i * GEAR_LABELS_SIZE, elements[i]);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
407 408
  }

Loic Hausammann's avatar
Loic Hausammann committed
409 410
  /* Cleanup. */
  parser_free_param_string_array(nval, elements);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
411

Loic Hausammann's avatar
Loic Hausammann committed
412 413 414 415
  /* Add the metals to the end. */
  strcpy(
      sm->elements_name + (GEAR_CHEMISTRY_ELEMENT_COUNT - 1) * GEAR_LABELS_SIZE,
      "Metals");
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
}

/**
 * @brief Initialize the global properties of the stellar evolution scheme.
 *
 * @param sm The #stellar_model.
 * @param phys_const The physical constants in the internal unit system.
 * @param us The internal unit system.
 * @param params The parsed parameters.
 * @param cosmo The cosmological model.
 */
void stellar_evolution_props_init(struct stellar_model* sm,
                                  const struct phys_const* phys_const,
                                  const struct unit_system* us,
                                  struct swift_params* params,
                                  const struct cosmology* cosmo) {

  /* Read the list of elements */
  stellar_evolution_read_elements(sm, params);

  /* Use the discrete yields approach? */
  sm->discrete_yields =
      parser_get_param_int(params, "GEARFeedback:discrete_yields");

  /* Initialize the initial mass function */
Loic Hausammann's avatar
Loic Hausammann committed
441 442
  initial_mass_function_init(&sm->imf, phys_const, us, params,
                             sm->yields_table);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
443 444

  /* Initialize the lifetime model */
Loic Hausammann's avatar
Loic Hausammann committed
445
  lifetime_init(&sm->lifetime, phys_const, us, params, sm->yields_table);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
446 447 448 449 450

  /* Initialize the supernovae Ia model */
  supernovae_ia_init(&sm->snia, phys_const, us, params, sm);

  /* Initialize the supernovae II model */
451
  supernovae_ii_init(&sm->snii, params, sm);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
}

/**
 * @brief Write a stellar_evolution struct to the given FILE as a stream of
 * bytes.
 *
 * Here we are only writing the arrays, everything has been copied in the
 * feedback.
 *
 * @param sm the struct
 * @param stream the file stream
 */
void stellar_evolution_dump(const struct stellar_model* sm, FILE* stream) {

  /* Dump the initial mass function */
  initial_mass_function_dump(&sm->imf, stream, sm);

  /* Dump the lifetime model */
  lifetime_dump(&sm->lifetime, stream, sm);

  /* Dump the supernovae Ia model */
  supernovae_ia_dump(&sm->snia, stream, sm);

  /* Dump the supernovae II model */
  supernovae_ii_dump(&sm->snii, stream, sm);
}

/**
 * @brief Restore a stellar_evolution struct from the given FILE as a stream of
 * bytes.
 *
 * Here we are only writing the arrays, everything has been copied in the
 * feedback.
 *
 * @param sm the struct
 * @param stream the file stream
 */
489
void stellar_evolution_restore(struct stellar_model* sm, FILE* stream) {
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
490 491 492 493 494 495 496 497 498 499 500

  /* Restore the initial mass function */
  initial_mass_function_restore(&sm->imf, stream, sm);

  /* Restore the lifetime model */
  lifetime_restore(&sm->lifetime, stream, sm);

  /* Restore the supernovae Ia model */
  supernovae_ia_restore(&sm->snia, stream, sm);

  /* Restore the supernovae II model */
501
  supernovae_ii_restore(&sm->snii, stream, sm);
Loic Hausammann's avatar
Gear  
Loic Hausammann committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515
}

/**
 * @brief Clean the allocated memory.
 *
 * @param sm the #stellar_model.
 */
void stellar_evolution_clean(struct stellar_model* sm) {

  initial_mass_function_clean(&sm->imf);
  lifetime_clean(&sm->lifetime);
  supernovae_ia_clean(&sm->snia);
  supernovae_ii_clean(&sm->snii);
}