Commit e8b4adc6 authored by Matthieu Schaller's avatar Matthieu Schaller

Merge branch 'star_formation_birth_struct' into 'master'

Add Star formation spart struct

See merge request !1056
parents 090ff617 fb90e893
......@@ -240,7 +240,7 @@ double eagle_feedback_energy_fraction(const struct spart* sp,
const double Z = chemistry_get_total_metal_mass_fraction_for_feedback(sp);
/* Physical density of the gas at the star's birth time */
const double rho_birth = sp->birth_density;
const double rho_birth = sp->sf_data.birth_density;
const double n_birth = rho_birth * props->rho_to_n_cgs;
/* Calculate f_E */
......
......@@ -122,7 +122,7 @@ void stellar_evolution_compute_continuous_feedback_properties(
if (sp->mass <= sp->feedback_data.mass_ejected) {
error("Stars cannot have negative mass. (%g <= %g). Initial mass = %g",
sp->mass, sp->feedback_data.mass_ejected, sp->birth.mass);
sp->mass, sp->feedback_data.mass_ejected, sp->sf_data.birth_mass);
}
/* Update the mass */
......@@ -154,7 +154,7 @@ void stellar_evolution_compute_continuous_feedback_properties(
chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed;
/* Convert it to total mass */
sp->feedback_data.metal_mass_ejected[i] *= sp->birth.mass;
sp->feedback_data.metal_mass_ejected[i] *= sp->sf_data.birth_mass;
}
}
......@@ -209,7 +209,7 @@ void stellar_evolution_compute_discrete_feedback_properties(
if (sp->mass <= sp->feedback_data.mass_ejected) {
error("Stars cannot have negative mass. (%g <= %g). Initial mass = %g",
sp->mass, sp->feedback_data.mass_ejected, sp->birth.mass);
sp->mass, sp->feedback_data.mass_ejected, sp->sf_data.birth_mass);
}
/* Update the mass */
......@@ -240,7 +240,7 @@ void stellar_evolution_compute_discrete_feedback_properties(
chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed;
/* Convert it to total mass */
sp->feedback_data.metal_mass_ejected[i] *= sp->birth.mass;
sp->feedback_data.metal_mass_ejected[i] *= sp->sf_data.birth_mass;
}
}
......@@ -301,7 +301,7 @@ void stellar_evolution_evolve_spart(
if (!can_produce_snia && !can_produce_snii) return;
/* Compute the initial mass */
const float m_init = sp->birth.mass / phys_const->const_solar_mass;
const float m_init = sp->sf_data.birth_mass / phys_const->const_solar_mass;
/* Compute number of SNIa */
int number_snia = 0;
......
......@@ -1318,6 +1318,8 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6],
num_fields += chemistry_write_sparticles(sparts, list + num_fields);
num_fields +=
tracers_write_sparticles(sparts, list + num_fields, with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) {
num_fields += fof_write_sparts(sparts, list + num_fields);
}
......@@ -1799,6 +1801,8 @@ void write_output_parallel(struct engine* e, const char* baseName,
num_fields += chemistry_write_sparticles(sparts, list + num_fields);
num_fields += tracers_write_sparticles(sparts, list + num_fields,
with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) {
num_fields += fof_write_sparts(sparts, list + num_fields);
}
......@@ -1827,6 +1831,8 @@ void write_output_parallel(struct engine* e, const char* baseName,
chemistry_write_sparticles(sparts_written, list + num_fields);
num_fields += tracers_write_sparticles(
sparts_written, list + num_fields, with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) {
num_fields += fof_write_sparts(sparts_written, list + num_fields);
}
......
......@@ -1407,6 +1407,8 @@ void write_output_serial(struct engine* e, const char* baseName,
chemistry_write_sparticles(sparts, list + num_fields);
num_fields += tracers_write_sparticles(sparts, list + num_fields,
with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) {
num_fields += fof_write_sparts(sparts, list + num_fields);
}
......@@ -1436,6 +1438,8 @@ void write_output_serial(struct engine* e, const char* baseName,
chemistry_write_sparticles(sparts_written, list + num_fields);
num_fields += tracers_write_sparticles(
sparts_written, list + num_fields, with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) {
num_fields +=
fof_write_sparts(sparts_written, list + num_fields);
......
......@@ -1196,6 +1196,8 @@ void write_output_single(struct engine* e, const char* baseName,
num_fields += chemistry_write_sparticles(sparts, list + num_fields);
num_fields += tracers_write_sparticles(sparts, list + num_fields,
with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) {
num_fields += fof_write_sparts(sparts, list + num_fields);
}
......@@ -1224,6 +1226,8 @@ void write_output_single(struct engine* e, const char* baseName,
chemistry_write_sparticles(sparts_written, list + num_fields);
num_fields += tracers_write_sparticles(
sparts_written, list + num_fields, with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) {
num_fields += fof_write_sparts(sparts_written, list + num_fields);
}
......
......@@ -456,11 +456,11 @@ INLINE static void star_formation_copy_properties(
sp->tracers_data = xp->tracers_data;
/* Store the birth density in the star particle */
sp->birth_density = hydro_get_physical_density(p, cosmo);
sp->sf_data.birth_density = hydro_get_physical_density(p, cosmo);
/* Store the birth temperature in the star particle */
sp->birth_temperature = cooling_get_temperature(phys_const, hydro_props, us,
cosmo, cooling, p, xp);
sp->sf_data.birth_temperature = cooling_get_temperature(
phys_const, hydro_props, us, cosmo, cooling, p, xp);
/* Flag that this particle has not done feedback yet */
sp->f_E = -1.f;
......
......@@ -47,4 +47,32 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles(
return 1;
}
/**
* @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");
return 2;
}
#endif /* SWIFT_STAR_FORMATION_EAGLE_IO_H */
......@@ -30,4 +30,17 @@ struct star_formation_xpart_data {
float SFR;
};
/**
* @brief Star-formation-related properties stored in the star particle
* data.
*/
struct star_formation_spart_data {
/*! The physical birth density */
float birth_density;
/*! The birth temperature */
float birth_temperature;
};
#endif /* SWIFT_EAGLE_STAR_FORMATION_STRUCT_H */
......@@ -248,7 +248,7 @@ INLINE static void star_formation_copy_properties(
} else {
sp->mass = mass_gas;
}
sp->birth.mass = sp->mass;
sp->sf_data.birth_mass = sp->mass;
/* Store either the birth_scale_factor or birth_time depending */
if (with_cosmology) {
......@@ -261,17 +261,17 @@ INLINE static void star_formation_copy_properties(
sp->tracers_data = xp->tracers_data;
/* Store the birth density in the star particle */
sp->birth.density = hydro_get_physical_density(p, cosmo);
sp->sf_data.birth_density = hydro_get_physical_density(p, cosmo);
/* Store the birth temperature*/
sp->birth.temperature = cooling_get_temperature(phys_const, hydro_props, us,
cosmo, cooling, p, xp);
sp->sf_data.birth_temperature = cooling_get_temperature(
phys_const, hydro_props, us, cosmo, cooling, p, xp);
/* Copy the chemistry properties */
chemistry_copy_star_formation_properties(p, xp, sp);
/* Copy the progenitor id */
sp->prog_id = p->id;
sp->sf_data.progenitor_id = p->id;
}
/**
......
......@@ -42,6 +42,43 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles(
return 0;
}
/**
* @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;
}
/**
* @brief initialization of the star formation law
*
......
......@@ -28,6 +28,25 @@ struct star_formation_xpart_data {
float div_v;
};
/**
* @brief Star-formation-related properties stored in the star particle
* data.
*/
struct star_formation_spart_data {
/*! The birth density */
float birth_density;
/*! The birth temperature */
float birth_temperature;
/*! The birth mass */
float birth_mass;
/*! The progenitor ID */
long long progenitor_id;
};
/**
* @brief Global star formation properties
*/
......
......@@ -43,4 +43,21 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles(
return 0;
}
/**
* @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) {
/* No SF-related fields in the Quick Lyman-alpha model */
return 0;
}
#endif /* SWIFT_STAR_FORMATION_QLA_IO_H */
......@@ -28,4 +28,10 @@ struct star_formation_xpart_data {
char convert_to_star;
};
/**
* @brief Star-formation-related properties stored in the star particle
* data.
*/
struct star_formation_spart_data {};
#endif /* SWIFT_QLA_STAR_FORMATION_STRUCT_H */
......@@ -41,4 +41,19 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles(
return 0;
}
/**
* @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) {
return 0;
}
#endif /* SWIFT_STAR_FORMATION_NONE_IO_H */
......@@ -25,4 +25,10 @@
*/
struct star_formation_xpart_data {};
/**
* @brief Star-formation-related properties stored in the star particle
* data.
*/
struct star_formation_spart_data {};
#endif /* SWIFT_NONE_STAR_FORMATION_STRUCT_H */
......@@ -25,6 +25,7 @@
/* Read additional subgrid models */
#include "chemistry_struct.h"
#include "feedback_struct.h"
#include "star_formation_struct.h"
#include "tracers_struct.h"
/**
......@@ -78,6 +79,9 @@ struct spart {
/*! Particle time bin */
timebin_t time_bin;
/*! Star formation struct */
struct star_formation_spart_data sf_data;
/*! Feedback structure */
struct feedback_spart_data feedback_data;
......
......@@ -68,7 +68,7 @@ __attribute__((always_inline)) INLINE static void stars_first_init_spart(
const int with_cosmology, const double scale_factor, const double time) {
sp->time_bin = 0;
sp->birth_density = 0.f;
sp->sf_data.birth_density = 0.f;
sp->f_E = -1.f;
sp->count_since_last_enrichment = -1;
......
......@@ -115,7 +115,7 @@ INLINE static void stars_write_particles(const struct spart *sparts,
const int with_cosmology) {
/* Say how much we want to write */
*num_fields = 10;
*num_fields = 8;
/* List what we want to write */
list[0] = io_make_output_field_convert_spart(
......@@ -140,37 +140,24 @@ INLINE static void stars_write_particles(const struct spart *sparts,
"SmoothingLengths", FLOAT, 1, UNIT_CONV_LENGTH, 1.f, sparts, h,
"Co-moving smoothing lengths (FWHM of the kernel) of the particles");
list[5] = io_make_output_field(
"BirthDensities", FLOAT, 1, UNIT_CONV_DENSITY, 0.f, sparts, 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[6] = io_make_output_field("InitialMasses", FLOAT, 1, UNIT_CONV_MASS, 0.f,
list[5] = io_make_output_field("InitialMasses", FLOAT, 1, UNIT_CONV_MASS, 0.f,
sparts, mass_init,
"Masses of the star particles at birth time");
if (with_cosmology) {
list[7] = io_make_output_field(
list[6] = io_make_output_field(
"BirthScaleFactors", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, sparts,
birth_scale_factor, "Scale-factors at which the stars were born");
} else {
list[7] = io_make_output_field("BirthTimes", FLOAT, 1, UNIT_CONV_TIME, 0.f,
list[6] = io_make_output_field("BirthTimes", FLOAT, 1, UNIT_CONV_TIME, 0.f,
sparts, birth_time,
"Times at which the stars were born");
}
list[8] = io_make_output_field(
list[7] = io_make_output_field(
"FeedbackEnergyFractions", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, sparts, f_E,
"Fractions of the canonical feedback energy that was used for the stars' "
"SNII feedback events");
list[9] =
io_make_output_field("BirthTemperatures", FLOAT, 1, UNIT_CONV_TEMPERATURE,
0.f, sparts, birth_temperature,
"Temperatures at the time of birth of the gas "
"particles that turned into stars");
}
/**
......
......@@ -26,6 +26,7 @@
/* Read additional aubgrid models */
#include "chemistry_struct.h"
#include "feedback_struct.h"
#include "star_formation_struct.h"
#include "tracers_struct.h"
/**
......@@ -85,15 +86,12 @@ struct spart {
/*! Initial star mass */
float mass_init;
/*! Birth density */
float birth_density;
/*! Birth temperature */
float birth_temperature;
/*! Feedback energy fraction */
float f_E;
/*! Star formation struct */
struct star_formation_spart_data sf_data;
/*! Feedback structure */
struct feedback_spart_data feedback_data;
......
......@@ -65,7 +65,7 @@ __attribute__((always_inline)) INLINE static void stars_first_init_spart(
const int with_cosmology, const double scale_factor, const double time) {
sp->time_bin = 0;
sp->birth.density = 0.f;
sp->sf_data.birth_density = 0.f;
// sp->birth_time = 0.;
stars_init_spart(sp);
......
......@@ -49,7 +49,7 @@ INLINE static void stars_read_particles(struct spart *sparts,
UNIT_CONV_LENGTH, sparts, h);
// TODO take it from initial mass
list[5] = io_make_input_field("BirthMass", FLOAT, 1, COMPULSORY,
UNIT_CONV_MASS, sparts, birth.mass);
UNIT_CONV_MASS, sparts, sf_data.birth_mass);
// TODO make it optional
list[6] = io_make_input_field("BirthTime", FLOAT, 1, OPTIONAL, UNIT_CONV_MASS,
......@@ -119,7 +119,7 @@ INLINE static void stars_write_particles(const struct spart *sparts,
const int with_cosmology) {
/* Say how much we want to write */
*num_fields = 10;
*num_fields = 7;
/* List what we want to write */
list[0] = io_make_output_field_convert_spart(
......@@ -152,27 +152,6 @@ INLINE static void stars_write_particles(const struct spart *sparts,
"Times at which the stars were born");
}
list[6] = io_make_output_field(
"BirthDensities", FLOAT, 1, UNIT_CONV_DENSITY, 0.f, sparts, 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[7] =
io_make_output_field("BirthTemperatures", FLOAT, 1, UNIT_CONV_TEMPERATURE,
0.f, sparts, birth.temperature,
"Temperatures at the time of birth of the gas "
"particles that turned into stars");
list[8] = io_make_output_field("BirthMasses", FLOAT, 1, UNIT_CONV_MASS, 0.f,
sparts, birth.mass,
"Masses of the star particles at birth time");
list[9] = io_make_output_field("ProgenitorIDs", LONGLONG, 1,
UNIT_CONV_NO_UNITS, 0.f, sparts, prog_id,
"Unique IDs of the progenitor particle");
#ifdef DEBUG_INTERACTIONS_STARS
list += *num_fields;
......
......@@ -25,6 +25,7 @@
/* Read additional subgrid models */
#include "chemistry_struct.h"
#include "feedback_struct.h"
#include "star_formation_struct.h"
#include "tracers_struct.h"
/**
......@@ -37,9 +38,6 @@ struct spart {
/*! Particle ID. */
long long id;
/*! Progenitor ID */
long long prog_id;
/*! Pointer to corresponding gravity part. */
struct gpart* gpart;
......@@ -71,17 +69,6 @@ struct spart {
} density;
struct {
/*! birth density*/
float density;
/*! birth temperature*/
float temperature;
/*! birth mass */
float mass;
} birth;
/*! Union for the birth time and birth scale factor */
union {
......@@ -92,6 +79,9 @@ struct spart {
float birth_scale_factor;
};
/*! Star formation struct */
struct star_formation_spart_data sf_data;
/*! Feedback structure */
struct feedback_spart_data feedback_data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment