Commit e8b4adc6 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

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, ...@@ -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); const double Z = chemistry_get_total_metal_mass_fraction_for_feedback(sp);
/* Physical density of the gas at the star's birth time */ /* 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; const double n_birth = rho_birth * props->rho_to_n_cgs;
/* Calculate f_E */ /* Calculate f_E */
......
...@@ -122,7 +122,7 @@ void stellar_evolution_compute_continuous_feedback_properties( ...@@ -122,7 +122,7 @@ void stellar_evolution_compute_continuous_feedback_properties(
if (sp->mass <= sp->feedback_data.mass_ejected) { if (sp->mass <= sp->feedback_data.mass_ejected) {
error("Stars cannot have negative mass. (%g <= %g). Initial mass = %g", 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 */ /* Update the mass */
...@@ -154,7 +154,7 @@ void stellar_evolution_compute_continuous_feedback_properties( ...@@ -154,7 +154,7 @@ void stellar_evolution_compute_continuous_feedback_properties(
chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed; chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed;
/* Convert it to total mass */ /* 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( ...@@ -209,7 +209,7 @@ void stellar_evolution_compute_discrete_feedback_properties(
if (sp->mass <= sp->feedback_data.mass_ejected) { if (sp->mass <= sp->feedback_data.mass_ejected) {
error("Stars cannot have negative mass. (%g <= %g). Initial mass = %g", 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 */ /* Update the mass */
...@@ -240,7 +240,7 @@ void stellar_evolution_compute_discrete_feedback_properties( ...@@ -240,7 +240,7 @@ void stellar_evolution_compute_discrete_feedback_properties(
chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed; chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed;
/* Convert it to total mass */ /* 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( ...@@ -301,7 +301,7 @@ void stellar_evolution_evolve_spart(
if (!can_produce_snia && !can_produce_snii) return; if (!can_produce_snia && !can_produce_snii) return;
/* Compute the initial mass */ /* 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 */ /* Compute number of SNIa */
int number_snia = 0; int number_snia = 0;
......
...@@ -1318,6 +1318,8 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6], ...@@ -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 += chemistry_write_sparticles(sparts, list + num_fields);
num_fields += num_fields +=
tracers_write_sparticles(sparts, list + num_fields, with_cosmology); tracers_write_sparticles(sparts, list + num_fields, with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) { if (with_fof) {
num_fields += fof_write_sparts(sparts, list + num_fields); num_fields += fof_write_sparts(sparts, list + num_fields);
} }
...@@ -1799,6 +1801,8 @@ void write_output_parallel(struct engine* e, const char* baseName, ...@@ -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 += chemistry_write_sparticles(sparts, list + num_fields);
num_fields += tracers_write_sparticles(sparts, list + num_fields, num_fields += tracers_write_sparticles(sparts, list + num_fields,
with_cosmology); with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) { if (with_fof) {
num_fields += fof_write_sparts(sparts, list + num_fields); num_fields += fof_write_sparts(sparts, list + num_fields);
} }
...@@ -1827,6 +1831,8 @@ void write_output_parallel(struct engine* e, const char* baseName, ...@@ -1827,6 +1831,8 @@ void write_output_parallel(struct engine* e, const char* baseName,
chemistry_write_sparticles(sparts_written, list + num_fields); chemistry_write_sparticles(sparts_written, list + num_fields);
num_fields += tracers_write_sparticles( num_fields += tracers_write_sparticles(
sparts_written, list + num_fields, with_cosmology); sparts_written, list + num_fields, with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) { if (with_fof) {
num_fields += fof_write_sparts(sparts_written, list + num_fields); num_fields += fof_write_sparts(sparts_written, list + num_fields);
} }
......
...@@ -1407,6 +1407,8 @@ void write_output_serial(struct engine* e, const char* baseName, ...@@ -1407,6 +1407,8 @@ void write_output_serial(struct engine* e, const char* baseName,
chemistry_write_sparticles(sparts, list + num_fields); chemistry_write_sparticles(sparts, list + num_fields);
num_fields += tracers_write_sparticles(sparts, list + num_fields, num_fields += tracers_write_sparticles(sparts, list + num_fields,
with_cosmology); with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) { if (with_fof) {
num_fields += fof_write_sparts(sparts, list + num_fields); num_fields += fof_write_sparts(sparts, list + num_fields);
} }
...@@ -1436,6 +1438,8 @@ void write_output_serial(struct engine* e, const char* baseName, ...@@ -1436,6 +1438,8 @@ void write_output_serial(struct engine* e, const char* baseName,
chemistry_write_sparticles(sparts_written, list + num_fields); chemistry_write_sparticles(sparts_written, list + num_fields);
num_fields += tracers_write_sparticles( num_fields += tracers_write_sparticles(
sparts_written, list + num_fields, with_cosmology); sparts_written, list + num_fields, with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) { if (with_fof) {
num_fields += num_fields +=
fof_write_sparts(sparts_written, list + num_fields); fof_write_sparts(sparts_written, list + num_fields);
......
...@@ -1196,6 +1196,8 @@ void write_output_single(struct engine* e, const char* baseName, ...@@ -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 += chemistry_write_sparticles(sparts, list + num_fields);
num_fields += tracers_write_sparticles(sparts, list + num_fields, num_fields += tracers_write_sparticles(sparts, list + num_fields,
with_cosmology); with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) { if (with_fof) {
num_fields += fof_write_sparts(sparts, list + num_fields); num_fields += fof_write_sparts(sparts, list + num_fields);
} }
...@@ -1224,6 +1226,8 @@ void write_output_single(struct engine* e, const char* baseName, ...@@ -1224,6 +1226,8 @@ void write_output_single(struct engine* e, const char* baseName,
chemistry_write_sparticles(sparts_written, list + num_fields); chemistry_write_sparticles(sparts_written, list + num_fields);
num_fields += tracers_write_sparticles( num_fields += tracers_write_sparticles(
sparts_written, list + num_fields, with_cosmology); sparts_written, list + num_fields, with_cosmology);
num_fields +=
star_formation_write_sparticles(sparts, list + num_fields);
if (with_fof) { if (with_fof) {
num_fields += fof_write_sparts(sparts_written, list + num_fields); num_fields += fof_write_sparts(sparts_written, list + num_fields);
} }
......
...@@ -456,11 +456,11 @@ INLINE static void star_formation_copy_properties( ...@@ -456,11 +456,11 @@ INLINE static void star_formation_copy_properties(
sp->tracers_data = xp->tracers_data; sp->tracers_data = xp->tracers_data;
/* Store the birth density in the star particle */ /* 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 */ /* Store the birth temperature in the star particle */
sp->birth_temperature = cooling_get_temperature(phys_const, hydro_props, us, sp->sf_data.birth_temperature = cooling_get_temperature(
cosmo, cooling, p, xp); phys_const, hydro_props, us, cosmo, cooling, p, xp);
/* Flag that this particle has not done feedback yet */ /* Flag that this particle has not done feedback yet */
sp->f_E = -1.f; sp->f_E = -1.f;
......
...@@ -47,4 +47,32 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles( ...@@ -47,4 +47,32 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles(
return 1; 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 */ #endif /* SWIFT_STAR_FORMATION_EAGLE_IO_H */
...@@ -30,4 +30,17 @@ struct star_formation_xpart_data { ...@@ -30,4 +30,17 @@ struct star_formation_xpart_data {
float SFR; 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 */ #endif /* SWIFT_EAGLE_STAR_FORMATION_STRUCT_H */
...@@ -248,7 +248,7 @@ INLINE static void star_formation_copy_properties( ...@@ -248,7 +248,7 @@ INLINE static void star_formation_copy_properties(
} else { } else {
sp->mass = mass_gas; 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 */ /* Store either the birth_scale_factor or birth_time depending */
if (with_cosmology) { if (with_cosmology) {
...@@ -261,17 +261,17 @@ INLINE static void star_formation_copy_properties( ...@@ -261,17 +261,17 @@ INLINE static void star_formation_copy_properties(
sp->tracers_data = xp->tracers_data; sp->tracers_data = xp->tracers_data;
/* Store the birth density in the star particle */ /* 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*/ /* Store the birth temperature*/
sp->birth.temperature = cooling_get_temperature(phys_const, hydro_props, us, sp->sf_data.birth_temperature = cooling_get_temperature(
cosmo, cooling, p, xp); phys_const, hydro_props, us, cosmo, cooling, p, xp);
/* Copy the chemistry properties */ /* Copy the chemistry properties */
chemistry_copy_star_formation_properties(p, xp, sp); chemistry_copy_star_formation_properties(p, xp, sp);
/* Copy the progenitor id */ /* 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( ...@@ -42,6 +42,43 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles(
return 0; 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 * @brief initialization of the star formation law
* *
......
...@@ -28,6 +28,25 @@ struct star_formation_xpart_data { ...@@ -28,6 +28,25 @@ struct star_formation_xpart_data {
float div_v; 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 * @brief Global star formation properties
*/ */
......
...@@ -43,4 +43,21 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles( ...@@ -43,4 +43,21 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles(
return 0; 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 */ #endif /* SWIFT_STAR_FORMATION_QLA_IO_H */
...@@ -28,4 +28,10 @@ struct star_formation_xpart_data { ...@@ -28,4 +28,10 @@ struct star_formation_xpart_data {
char convert_to_star; 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 */ #endif /* SWIFT_QLA_STAR_FORMATION_STRUCT_H */
...@@ -41,4 +41,19 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles( ...@@ -41,4 +41,19 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles(
return 0; 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 */ #endif /* SWIFT_STAR_FORMATION_NONE_IO_H */
...@@ -25,4 +25,10 @@ ...@@ -25,4 +25,10 @@
*/ */
struct star_formation_xpart_data {}; 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 */ #endif /* SWIFT_NONE_STAR_FORMATION_STRUCT_H */
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
/* Read additional subgrid models */ /* Read additional subgrid models */
#include "chemistry_struct.h" #include "chemistry_struct.h"
#include "feedback_struct.h" #include "feedback_struct.h"
#include "star_formation_struct.h"
#include "tracers_struct.h" #include "tracers_struct.h"
/** /**
...@@ -78,6 +79,9 @@ struct spart { ...@@ -78,6 +79,9 @@ struct spart {
/*! Particle time bin */ /*! Particle time bin */
timebin_t time_bin; timebin_t time_bin;
/*! Star formation struct */
struct star_formation_spart_data sf_data;
/*! Feedback structure */ /*! Feedback structure */
struct feedback_spart_data feedback_data; struct feedback_spart_data feedback_data;
......
...@@ -68,7 +68,7 @@ __attribute__((always_inline)) INLINE static void stars_first_init_spart( ...@@ -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) { const int with_cosmology, const double scale_factor, const double time) {
sp->time_bin = 0; sp->time_bin = 0;
sp->birth_density = 0.f; sp->sf_data.birth_density = 0.f;
sp->f_E = -1.f; sp->f_E = -1.f;
sp->count_since_last_enrichment = -1; sp->count_since_last_enrichment = -1;
......
...@@ -115,7 +115,7 @@ INLINE static void stars_write_particles(const struct spart *sparts, ...@@ -115,7 +115,7 @@ INLINE static void stars_write_particles(const struct spart *sparts,
const int with_cosmology) { const int with_cosmology) {
/* Say how much we want to write */ /* Say how much we want to write */
*num_fields = 10; *num_fields = 8;
/* List what we want to write */ /* List what we want to write */
list[0] = io_make_output_field_convert_spart( list[0] = io_make_output_field_convert_spart(
...@@ -140,37 +140,24 @@ INLINE static void stars_write_particles(const struct spart *sparts, ...@@ -140,37 +140,24 @@ INLINE static void stars_write_particles(const struct spart *sparts,
"SmoothingLengths", FLOAT, 1, UNIT_CONV_LENGTH, 1.f, sparts, h, "SmoothingLengths", FLOAT, 1, UNIT_CONV_LENGTH, 1.f, sparts, h,
"Co-moving smoothing lengths (FWHM of the kernel) of the particles"); "Co-moving smoothing lengths (FWHM of the kernel) of the particles");
list[5] = io_make_output_field( list[5] = io_make_output_field("InitialMasses", FLOAT, 1, UNIT_CONV_MASS, 0.f,
"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,
sparts, mass_init, sparts, mass_init,
"Masses of the star particles at birth time"); "Masses of the star particles at birth time");
if (with_cosmology) { 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, "BirthScaleFactors", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, sparts,
birth_scale_factor, "Scale-factors at which the stars were born"); birth_scale_factor, "Scale-factors at which the stars were born");
} else { } 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, sparts, birth_time,
"Times at which the stars were born"); "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, "FeedbackEnergyFractions", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, sparts, f_E,
"Fractions of the canonical feedback energy that was used for the stars' " "Fractions of the canonical feedback energy that was used for the stars' "
"SNII feedback events"); "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 @@ ...@@ -26,6 +26,7 @@
/* Read additional aubgrid models */ /* Read additional aubgrid models */
#include "chemistry_struct.h" #include "chemistry_struct.h"
#include "feedback_struct.h" #include "feedback_struct.h"
#include "star_formation_struct.h"
#include "tracers_struct.h" #include "tracers_struct.h"
/** /**
...@@ -85,15 +86,12 @@ struct spart { ...@@ -85,15 +86,12 @@ struct spart {
/*! Initial star mass */ /*! Initial star mass */
float mass_init; float mass_init;
/*! Birth density */
float birth_density;
/*! Birth temperature */
float birth_temperature;