From e5e3c94008131aa14760716f568613667b28bbcc Mon Sep 17 00:00:00 2001 From: loikki <loic.hausammann@protonmail.ch> Date: Thu, 11 Jul 2019 09:10:24 +0200 Subject: [PATCH] GEAR: add star_formation_history_accumulator --- src/collectgroup.c | 2 +- src/engine.c | 2 +- src/engine.h | 2 +- .../GEAR/star_formation_logger.h | 106 +++++++++--------- .../GEAR/star_formation_logger_struct.h | 13 ++- 5 files changed, 70 insertions(+), 55 deletions(-) diff --git a/src/collectgroup.c b/src/collectgroup.c index 4be3116e36..8dd9e974f4 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 085160d12e..33f94e9c16 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 8296933561..967a430871 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 2ead5c9c0a..45d39b1843 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 718066fd61..e4ae68edff 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; -- GitLab