diff --git a/src/collectgroup.c b/src/collectgroup.c index 4be3116e3632f1c7e8b60d044af5b3a93d0add1b..8dd9e974f41c979f4c50e84fb555f9b80db19e25 100644 --- a/src/collectgroup.c +++ b/src/collectgroup.c @@ -123,7 +123,7 @@ void collectgroup1_apply(const struct collectgroup1 *grp1, struct engine *e) { e->total_nr_tasks = grp1->total_nr_tasks; e->tasks_per_cell_max = grp1->tasks_per_cell_max; - star_formation_logger_add_to_engine(&e->sfh, &grp1->sfh); + star_formation_logger_add_to_accumulator(&e->sfh, &grp1->sfh); } /** diff --git a/src/engine.c b/src/engine.c index 085160d12eca40641e7a2c22ab55f8f023a51ce2..33f94e9c16475b5281cdb5948e6b31e1026c7d46 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5064,7 +5064,7 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params, /* Initialize the star formation history structure */ if (e->policy & engine_policy_star_formation) { - star_formation_logger_first_init(&e->sfh); + star_formation_logger_accumulator_init(&e->sfh); } engine_init_output_lists(e, params); diff --git a/src/engine.h b/src/engine.h index 8296933561b5f7664904d439ec6ca20f1e37a4b8..967a430871648ac4cb91f390f8b85675a314d3a8 100644 --- a/src/engine.h +++ b/src/engine.h @@ -237,7 +237,7 @@ struct engine { long long b_updates_since_rebuild; /* Star formation logger information */ - struct star_formation_history sfh; + struct star_formation_history_accumulator sfh; /* Properties of the previous step */ int step_props; diff --git a/src/star_formation/GEAR/star_formation_logger.h b/src/star_formation/GEAR/star_formation_logger.h index 2ead5c9c0aa026b274edc87363a9eb863debe226..45d39b18439cf94a66e4875de460836b8f9cd0da 100644 --- a/src/star_formation/GEAR/star_formation_logger.h +++ b/src/star_formation/GEAR/star_formation_logger.h @@ -77,20 +77,6 @@ INLINE static void star_formation_logger_init( sfh->new_stellar_mass = 0.f; sfh->number_new_stars = 0; } -/** - * @brief Initialize the star formation history struct in the #engine when - * starting the simulation. - * - * @param sfh the star_formation_history struct we want to initialize - */ -INLINE static void star_formation_logger_first_init( - struct star_formation_history *sfh) { - /* Initialize all values to zero */ - sfh->new_stellar_mass = 0.f; - sfh->number_new_stars = 0; - sfh->total_number_stars = 0; - sfh->total_stellar_mass = 0.f; -} /** * @brief add a star formation history struct to an other star formation history @@ -109,43 +95,6 @@ INLINE static void star_formation_logger_add( sf_update->new_stellar_mass += sf_add->new_stellar_mass; } -/** - * @brief add a star formation history struct to an other star formation history - * struct - * - * @param sf_add the star formation struct which we want to add to the star - * formation history - * @param sf_update the star formation structure which we want to update - */ -INLINE static void star_formation_logger_add_to_engine( - struct star_formation_history *sf_update, - const struct star_formation_history *sf_add) { - - /* Update the SFH structure */ - sf_update->number_new_stars = sf_add->number_new_stars; - sf_update->new_stellar_mass = sf_add->new_stellar_mass; - sf_update->total_number_stars += sf_add->number_new_stars; - sf_update->total_stellar_mass += sf_add->new_stellar_mass; -} - -/** -za * @brief Write the final SFH to a file - * - * @param fp The file to write to. - * @param time the simulation time (time since Big Bang) in internal units. - * @param a the scale factor. - * @param z the redshift. - * @param sf the #star_formation_history struct. - * @param step The time-step of the simulation. - */ -INLINE static void star_formation_logger_write_to_log_file( - FILE *fp, const double time, const double a, const double z, - struct star_formation_history sf, const int step) { - - fprintf(fp, "%6d %16e %12.7f %14e %14ld %14e %14ld %14e\n", step, time, a, z, - sf.total_number_stars, sf.total_stellar_mass, sf.number_new_stars, - sf.new_stellar_mass); -} /** * @brief Initialize the SFH logger file * @@ -217,4 +166,59 @@ INLINE static void star_formation_logger_log_inactive_part( const struct part *p, const struct xpart *xp, struct star_formation_history *sf) {} + + +/** + * @brief add a star formation history struct to an other star formation history + * struct + * + * @param sf_add the star formation struct which we want to add to the star + * formation history + * @param sf_update the star formation structure which we want to update + */ +INLINE static void star_formation_logger_add_to_accumulator( + struct star_formation_history_accumulator *sf_update, + const struct star_formation_history *sf_add) { + + /* Update the SFH structure */ + sf_update->number_new_stars = sf_add->number_new_stars; + sf_update->new_stellar_mass = sf_add->new_stellar_mass; + sf_update->total_number_stars += sf_add->number_new_stars; + sf_update->total_stellar_mass += sf_add->new_stellar_mass; +} + +/** + * @brief Write the final SFH to a file + * + * @param fp The file to write to. + * @param time the simulation time (time since Big Bang) in internal units. + * @param a the scale factor. + * @param z the redshift. + * @param sf the #star_formation_history struct. + * @param step The time-step of the simulation. + */ +INLINE static void star_formation_logger_write_to_log_file( + FILE *fp, const double time, const double a, const double z, + struct star_formation_history_accumulator sf, const int step) { + + fprintf(fp, "%6d %16e %12.7f %14e %14ld %14e %14ld %14e\n", step, time, a, z, + sf.total_number_stars, sf.total_stellar_mass, sf.number_new_stars, + sf.new_stellar_mass); +} + +/** + * @brief Initialize the star formation history struct in the #engine when + * starting the simulation. + * + * @param sfh the star_formation_history struct we want to initialize + */ +INLINE static void star_formation_logger_accumulator_init( + struct star_formation_history_accumulator *sfh) { + /* Initialize all values to zero */ + sfh->new_stellar_mass = 0.f; + sfh->number_new_stars = 0; + sfh->total_number_stars = 0; + sfh->total_stellar_mass = 0.f; +} + #endif /* SWIFT_GEAR_STARFORMATION_LOGGER_H */ diff --git a/src/star_formation/GEAR/star_formation_logger_struct.h b/src/star_formation/GEAR/star_formation_logger_struct.h index 718066fd61aff958b12386d907522283bf21cc96..e4ae68edff5cc947846fc597c266b9a56d37a166 100644 --- a/src/star_formation/GEAR/star_formation_logger_struct.h +++ b/src/star_formation/GEAR/star_formation_logger_struct.h @@ -21,9 +21,20 @@ #define SWIFT_GEAR_STAR_FORMATION_LOGGER_STRUCT_H /** - * Structure containing the global star formation information. + * Structure containing the local star formation information. */ struct star_formation_history { + /*! Stellar mass created in the current timestep */ + float new_stellar_mass; + + /*! Number of stars created in this timestep */ + long int number_new_stars; +}; + +/** + * Structure containing the global star formation information. + */ +struct star_formation_history_accumulator { /*! Total stellar mass from the begining of the simulation */ float total_stellar_mass;