diff --git a/src/Makefile.am b/src/Makefile.am index c309735f52db9142caba95b8fff265c57a3516b6..8099524651d8b3bb0a2765f1c0e7f05ef570af08 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -384,6 +384,7 @@ nobase_noinst_HEADERS += star_formation/EAGLE/star_formation_debug.h nobase_noinst_HEADERS += star_formation/GEAR/star_formation.h star_formation/GEAR/star_formation_struct.h nobase_noinst_HEADERS += star_formation/GEAR/star_formation_io.h star_formation/GEAR/star_formation_iact.h nobase_noinst_HEADERS += star_formation/GEAR/star_formation_csds.h star_formation/GEAR/star_formation_debug.h +nobase_noinst_HEADERS += star_formation/GEAR/star_formation_setters.h nobase_noinst_HEADERS += star_formation/EAGLE/star_formation_logger.h star_formation/EAGLE/star_formation_logger_struct.h nobase_noinst_HEADERS += star_formation/GEAR/star_formation_logger.h star_formation/GEAR/star_formation_logger_struct.h nobase_noinst_HEADERS += star_formation/none/star_formation_logger.h star_formation/none/star_formation_logger_struct.h diff --git a/src/feedback/GEAR/initial_mass_function.c b/src/feedback/GEAR/initial_mass_function.c index d38b9e85edf0d5ad87f97bcf875cb5d84f649cdd..5c4f1f8838943dcca832575af03bfa88c820f0b5 100644 --- a/src/feedback/GEAR/initial_mass_function.c +++ b/src/feedback/GEAR/initial_mass_function.c @@ -32,8 +32,13 @@ float initial_mass_function_get_exponent( #ifdef SWIFT_DEBUG_CHECKS if (mass_max > imf->mass_max) error("Cannot have mass larger than the largest one in the IMF"); - if (mass_min < imf->mass_min) - error("Cannot have mass smaller than the smallest one in the IMF"); + + /* 18.05.2024: This check is ill-defined. It needs to be improved. + For population II stars, no problem. + For population III stars, the snia->mass_min_progenitor can be smaller + than the minimal mass of the IMF, which causes the code to crash here. */ + /* if (mass_min < imf->mass_min) */ + /* error("Cannot have mass smaller than the smallest one in the IMF"); */ if (mass_max < mass_min) error("Cannot have mass_min larger than mass_max"); #endif diff --git a/src/sink/Default/sink_properties.h b/src/sink/Default/sink_properties.h index 98166add5a144335f5ac05fe16f7051390651029..08b458c77597daba7d94903d71af895ad925c55e 100644 --- a/src/sink/Default/sink_properties.h +++ b/src/sink/Default/sink_properties.h @@ -36,13 +36,15 @@ struct sink_props { * @param us The internal unit system. * @param params The parsed parameters. * @param cosmo The cosmological model. + * @param with_feedback Are we running with feedback? */ INLINE static void sink_props_init(struct sink_props *sp, struct feedback_props *fp, const struct phys_const *phys_const, const struct unit_system *us, struct swift_params *params, - const struct cosmology *cosmo) { + const struct cosmology *cosmo, + const int with_feedback) { sp->cut_off_radius = parser_get_param_float(params, "DefaultSink:cut_off_radius"); diff --git a/src/sink/GEAR/sink.h b/src/sink/GEAR/sink.h index b88787c70fada57ec4cdece084ad30adb5d45754..488b1a92d372949e532f843bd8c6b6bb76862766 100644 --- a/src/sink/GEAR/sink.h +++ b/src/sink/GEAR/sink.h @@ -35,6 +35,7 @@ #include "random.h" #include "sink_part.h" #include "sink_properties.h" +#include "star_formation.h" /** * @brief Computes the time-step of a given sink particle. @@ -791,18 +792,20 @@ INLINE static void sink_copy_properties_to_star( /* Note: The sink module need to be compiled with GEAR SF as we store data in the SF struct. However, we do not need to run with --star-formation */ - /* Store either the birth_scale_factor or birth_time depending */ - if (with_cosmology) { - sp->birth_scale_factor = cosmo->a; - } else { - sp->birth_time = e->time; - } + /* Mass at birth */ + star_formation_set_spart_birth_mass(sp, sp->mass); - /* Copy the chemistry properties */ - chemistry_copy_sink_properties_to_star(sink, sp); + /* Store either the birth_scale_factor or birth_time */ + star_formation_set_spart_birth_time_or_scale_factor(sp, e->time, cosmo->a, + with_cosmology); /* Copy the progenitor id */ - sp->sf_data.progenitor_id = sink->id; + star_formation_set_spart_progenitor_id(sp, sink->id); + + /* Copy the chemistry properties */ + /* ----------------------------- */ + + chemistry_copy_sink_properties_to_star(sink, sp); } /** diff --git a/src/sink/GEAR/sink_properties.h b/src/sink/GEAR/sink_properties.h index a5607a3524d56ef6c8c04ba95e5bf1289e2292e6..50bde9097e4d9db0dfef058a73bb3090ef4f7b4f 100644 --- a/src/sink/GEAR/sink_properties.h +++ b/src/sink/GEAR/sink_properties.h @@ -155,13 +155,21 @@ INLINE static void sink_props_init_probabilities( * @param us The internal unit system. * @param params The parsed parameters. * @param cosmo The cosmological model. + * @param with_feedback Are we running with feedback? */ INLINE static void sink_props_init(struct sink_props *sp, struct feedback_props *fp, const struct phys_const *phys_const, const struct unit_system *us, struct swift_params *params, - const struct cosmology *cosmo) { + const struct cosmology *cosmo, + const int with_feedback) { + + /* If we do not run with feedback, abort and print an error */ + if (!with_feedback) + error( + "ERROR: Running with sink but without feedback. GEAR sink model needs " + "to be run with --sink and --feedback"); /* Default values */ const float default_f_acc = 0.8; diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index 2fde11013a5ac45f49504efd10d02c9deec5c728..ac3e04e1eae6b938853a045cd930022d5dbf9c4b 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.h @@ -33,6 +33,7 @@ #include "part.h" #include "physical_constants.h" #include "random.h" +#include "star_formation_setters.h" #include "star_formation_struct.h" #include "stars.h" #include "units.h" diff --git a/src/star_formation/GEAR/star_formation_setters.h b/src/star_formation/GEAR/star_formation_setters.h new file mode 100644 index 0000000000000000000000000000000000000000..31e6d06781c044888aaa6f87d07d2266adb78ce2 --- /dev/null +++ b/src/star_formation/GEAR/star_formation_setters.h @@ -0,0 +1,101 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2024 Darwin Roduit (darwin.roduit@epfl.ch) + * + * 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_GEAR_STAR_FORMATION_SETTERS_H +#define SWIFT_GEAR_STAR_FORMATION_SETTERS_H + +#include "star_formation_struct.h" + +/** + * @file src/star_formation/GEAR/star_formation_setters.h + * @brief Setters functions for GEAR star formation scheme to avoid exposing + * implementation details to the outer world. Keep the code clean and lean. + */ + +/** + * @brief Set the birth density of a star particle. + * + * @param sp The #spart. + * @param birth_density Birth density of the star. + */ + +__attribute__((always_inline)) INLINE void +star_formation_set_spart_birth_density(struct spart *restrict sp, + const float birth_density) { + sp->sf_data.birth_density = birth_density; +} + +/** + * @brief Set the birth temperature of a star particle. + * + * @param sp The #spart. + * @param birth_temperature Birth temperature of the star. + */ + +__attribute__((always_inline)) INLINE void +star_formation_set_spart_birth_temperature(struct spart *restrict sp, + const float birth_temperature) { + sp->sf_data.birth_temperature = birth_temperature; +} + +/** + * @brief Set the birth mass of a star particle. + * + * @param sp The #spart. + * @param birth_mass Birth mass of the star. + */ + +__attribute__((always_inline)) INLINE void star_formation_set_spart_birth_mass( + struct spart *restrict sp, const float birth_mass) { + sp->sf_data.birth_mass = birth_mass; +} + +/** + * @brief Set the id of the particle creating the star particle. + * + * @param sp The #spart. + * @param progenitor_id The id of the particle creating sp. + */ + +__attribute__((always_inline)) INLINE void +star_formation_set_spart_progenitor_id(struct spart *restrict sp, + const long long progenitor_id) { + sp->sf_data.progenitor_id = progenitor_id; +} + +/** + * @brief Set the birth time/scale-factor of a star particle. + * + * @param sp The #spart. + * @param birth_time Birth time of the star. + * @param birth_scale_factor Birth scale-factor of the star. + * @param with_cosmology If we run with cosmology. + */ + +__attribute__((always_inline)) INLINE void +star_formation_set_spart_birth_time_or_scale_factor( + struct spart *restrict sp, const float birth_time, + const float birth_scale_factor, const int with_cosmology) { + if (with_cosmology) { + sp->birth_scale_factor = birth_scale_factor; + } else { + sp->birth_time = birth_time; + } +} + +#endif /* SWIFT_GEAR_STAR_FORMATION_SETTERS_H */ diff --git a/swift.c b/swift.c index ac765be171586bd73bf93c76cc9de8e5edd8311f..b63941cd63538e3226669bfed06bdb1837c73411 100644 --- a/swift.c +++ b/swift.c @@ -1168,7 +1168,7 @@ int main(int argc, char *argv[]) { /* Initialise the sink properties */ if (with_sinks) { sink_props_init(&sink_properties, &feedback_properties, &prog_const, &us, - params, &cosmo); + params, &cosmo, with_feedback); } else bzero(&sink_properties, sizeof(struct sink_props));