star_formation_io.h 4.68 KB
Newer Older
1 2
/*******************************************************************************
 * This file is part of SWIFT.
Loic Hausammann's avatar
Loic Hausammann committed
3 4
 * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch)
 *               2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch)
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
 *
 * 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/>.
 *
 ******************************************************************************/
#ifndef SWIFT_STAR_FORMATION_GEAR_IO_H
#define SWIFT_STAR_FORMATION_GEAR_IO_H

/* Config parameters. */
#include "../config.h"

/* Local includes */
#include "io_properties.h"

/**
 * @brief Specifies which particle fields to write to a dataset
 *
 * @param parts The particle array.
 * @param xparts The extended data particle array.
 * @param list The list of i/o properties to write.
 *
 * @return Returns the number of fields to write.
 */
__attribute__((always_inline)) INLINE static int star_formation_write_particles(
    const struct part* parts, const struct xpart* xparts,
    struct io_props* list) {
Loic Hausammann's avatar
Loic Hausammann committed
41
  /* Nothing to write here */
42
  return 0;
Loic Hausammann's avatar
Loic Hausammann committed
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 80 81
/**
 * @brief Specifies which sparticle fields to write to a dataset
 *
 * @param sparts The star particle array.
 * @param list The list of i/o properties to write.
 *
 * @return Returns the number of fields to write.
 */
__attribute__((always_inline)) INLINE static int
star_formation_write_sparticles(const struct spart* sparts,
                                struct io_props* list) {

  list[0] = io_make_output_field(
      "BirthDensities", FLOAT, 1, UNIT_CONV_DENSITY, 0.f, sparts,
      sf_data.birth_density,
      "Physical densities at the time of birth of the gas particles that "
      "turned into stars (note that "
      "we store the physical density at the birth redshift, no conversion is "
      "needed)");

  list[1] =
      io_make_output_field("BirthTemperatures", FLOAT, 1, UNIT_CONV_TEMPERATURE,
                           0.f, sparts, sf_data.birth_temperature,
                           "Temperatures at the time of birth of the gas "
                           "particles that turned into stars");

  list[2] = io_make_output_field("BirthMasses", FLOAT, 1, UNIT_CONV_MASS, 0.f,
                                 sparts, sf_data.birth_mass,
                                 "Masses of the star particles at birth time");

  list[3] = io_make_output_field(
      "ProgenitorIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, 0.f, sparts,
      sf_data.progenitor_id, "Unique IDs of the progenitor particle");

  return 4;
}

Loic Hausammann's avatar
Loic Hausammann committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
/**
 * @brief initialization of the star formation law
 *
 * @param parameter_file The parsed parameter file
 * @param phys_const Physical constants in internal units
 * @param us The current internal system of units
 * @param starform the star formation law properties to initialize
 *
 */
INLINE static void starformation_init_backend(
    struct swift_params* parameter_file, const struct phys_const* phys_const,
    const struct unit_system* us, const struct hydro_props* hydro_props,
    struct star_formation* starform) {

  /* Star formation efficiency */
  starform->star_formation_efficiency = parser_get_param_double(
      parameter_file, "GEARStarFormation:star_formation_efficiency");

  /* Maximum temperature for star formation */
  starform->maximal_temperature = parser_get_param_double(
      parameter_file, "GEARStarFormation:maximal_temperature");

Loic Hausammann's avatar
Loic Hausammann committed
104 105 106 107 108 109 110 111 112 113
  /* Number of stars per particles */
  starform->n_stars_per_part = parser_get_param_double(
      parameter_file, "GEARStarFormation:n_stars_per_particle");

  /* Minimal fraction of mass for the last star formed. */
  starform->min_mass_frac_plus_one = parser_get_param_double(
      parameter_file, "GEARStarFormation:min_mass_frac");
  /* Avoid generating gas particle with mass below the fraction => + 1. */
  starform->min_mass_frac_plus_one += 1.;

114 115 116
  /* Get the jeans factor */
  starform->n_jeans_2_3 = pow(pressure_floor_props.n_jeans, 2. / 3.);

Loic Hausammann's avatar
Loic Hausammann committed
117 118 119
  /* Apply unit change */
  starform->maximal_temperature *=
      units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE);
Loic Hausammann's avatar
Loic Hausammann committed
120 121 122

  /* Initialize the mass of the stars to 0 for the stats computation */
  starform->mass_stars = 0;
Loic Hausammann's avatar
Loic Hausammann committed
123 124
}

125
#endif /* SWIFT_STAR_FORMATION_GEAR_IO_H */