diff --git a/configure.ac b/configure.ac index cae9bb28c83013894715adf58099293b7bdd3963..933460fb7e7fcdda2d99754e048252b82f929b47 100644 --- a/configure.ac +++ b/configure.ac @@ -1222,7 +1222,7 @@ if test "x$with_grackle" != "xno"; then [AC_DEFINE([HAVE_GRACKLE],1,[The GRACKLE library appears to be present.]) AC_DEFINE([CONFIG_BFLOAT_8],1,[Use doubles in grackle]) ], - [AC_MSG_ERROR(Cannot find grackle library!)], + [AC_MSG_ERROR(Cannot find grackle library! You need to have a version >= 3.1.1)], [$GRACKLE_LIBS]) fi AC_SUBST([GRACKLE_LIBS]) diff --git a/doc/RTD/source/SubgridModels/GEAR/index.rst b/doc/RTD/source/SubgridModels/GEAR/index.rst index 89ee949fb3dd8d917a5039a95ef78f9e933173f3..9faaef245b48b19e49c3a5caff38c61a1d3f70e5 100644 --- a/doc/RTD/source/SubgridModels/GEAR/index.rst +++ b/doc/RTD/source/SubgridModels/GEAR/index.rst @@ -57,7 +57,7 @@ The code uses an iterative method in order to find the correct initial compositi In order to compile SWIFT with Grackle, you need to provide the options ``with-chemistry=GEAR`` and ``with-grackle=$GRACKLE_ROOT`` where ``$GRACKLE_ROOT`` is the root of the install directory (not the ``lib``). -You will need a Grackle version later than 3.1. To compile it, run +You will need a Grackle version later than 3.1.1. To compile it, run the following commands from the root directory of Grackle: ``./configure; cd src/clib``. Update the variables ``LOCAL_HDF5_INSTALL`` and ``MACH_INSTALL_PREFIX`` in @@ -103,6 +103,9 @@ A particle is in the star forming regime if: A star will be able to form if a randomly drawn number is below :math:`\frac{m_g}{m_\star}\left(1 - \exp\left(-c_\star \Delta t / t_\textrm{ff}\right)\right)` where :math:`t_\textrm{ff}` is the free fall time, :math:`\Delta t` is the time step of the particle and :math:`c_\star` is the star formation coefficient (``GEARStarFormation:star_formation_efficiency``), :math:`m_g` the mass of the gas particle and :math:`m_\star` the mass of the possible future star. The mass of the star is computed from the average gas mass in the initial conditions divided by the number of possible stars formed per gas particle (``GEARStarFormation:n_stars_per_particle``). When we cannot have enough mass to form a second star (defined with the fraction of mass ``GEARStarFormation:min_mass_frac``), we fully convert the gas particle into a stellar particle. Once the star is formed, we move it a bit in a random direction and fraction of the smoothing length in order to avoid any division by 0. +Currently, only the following hydro schemes are compatible: SPHENIX and Gadget2. +Implementing the other hydro schemes is not complicated but requires some careful thinking about the cosmological terms in the definition of the velocity divergence (comoving vs non comoving coordinates and if the Hubble flow is included or not). + .. code:: YAML GEARStarFormation: diff --git a/examples/Cooling/CoolingBox/coolingBox.yml b/examples/Cooling/CoolingBox/coolingBox.yml index f776823d1ba2b4703288913d4bf67f3e4851bebd..3907f16d6efab9a71318eace116445d08f6227a0 100644 --- a/examples/Cooling/CoolingBox/coolingBox.yml +++ b/examples/Cooling/CoolingBox/coolingBox.yml @@ -39,20 +39,22 @@ LambdaCooling: lambda_nH2_cgs: 1e-22 # Cooling rate divided by square Hydrogen number density (in cgs units [erg * s^-1 * cm^3]) cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition -# Cooling with Grackle 2.0 +# Cooling with Grackle 3.0 GrackleCooling: - CloudyTable: CloudyData_UVB=HM2012.h5 # Name of the Cloudy Table (available on the grackle bitbucket repository) - WithUVbackground: 0 # Enable or not the UV background - Redshift: 0 # Redshift to use (-1 means time based redshift) - WithMetalCooling: 1 # Enable or not the metal cooling - ProvideVolumetricHeatingRates: 0 # User provide volumetric heating rates - ProvideSpecificHeatingRates: 0 # User provide specific heating rates - SelfShieldingMethod: 0 # Grackle (<= 3) or Gear self shielding method - MaxSteps: 1000 - ConvergenceLimit: 1e-2 - -GearChemistry: - InitialMetallicity: 0.01295 + cloudy_table: CloudyData_UVB=HM2012.h5 # Name of the Cloudy Table (available on the grackle bitbucket repository) + with_UV_background: 0 # Enable or not the UV background + redshift: 0 # Redshift to use (-1 means time based redshift) + with_metal_cooling: 1 # Enable or not the metal cooling + provide_volumetric_heating_rates: 0 # (optional) User provide volumetric heating rates + provide_specific_heating_rates: 0 # (optional) User provide specific heating rates + max_steps: 10000 # (optional) Max number of step when computing the initial composition + convergence_limit: 1e-2 # (optional) Convergence threshold (relative) for initial composition + thermal_time_myr: 5 # (optional) Time (in Myr) for adiabatic cooling after a feedback event. + self_shielding_method: 0 # (optional) Grackle (1->3 for Grackle's ones, 0 for none and -1 for GEAR) + self_shielding_threshold_atom_per_cm3: 0.007 # Required only with GEAR's self shielding. Density threshold of the self shielding + +GEARChemistry: + initial_metallicity: 0.01295 EAGLECooling: dir_name: ./coolingtables/ @@ -74,3 +76,5 @@ EAGLEChemistry: # Solar abundances init_abundance_Silicon: 6.825874e-4 init_abundance_Iron: 1.1032152e-3 +GEARPressureFloor: + jeans_factor: 0. # Number of particles required to suppose a resolved clump and avoid the pressure floor. diff --git a/src/chemistry/none/chemistry.h b/src/chemistry/none/chemistry.h index 4070c4fe7e942778ece03c3d77a9110e33add6eb..3bd4e41a8617714547c3bf7625a939140f1aa2b3 100644 --- a/src/chemistry/none/chemistry.h +++ b/src/chemistry/none/chemistry.h @@ -49,6 +49,17 @@ chemistry_get_element_name(enum chemistry_element elem) { return chemistry_element_names[elem]; } +/** + * @brief Copies the chemistry properties of the gas particle over to the + * star particle. + * + * @param p the gas particles. + * @param xp the additional properties of the gas particles. + * @param sp the new created star particle with its properties. + */ +INLINE static void chemistry_copy_star_formation_properties( + const struct part* p, const struct xpart* xp, struct spart* sp) {} + /** * @brief Initialises the chemistry properties. * diff --git a/src/chemistry/none/chemistry_struct.h b/src/chemistry/none/chemistry_struct.h index 3b065bcdf6cbf2fec6f9cb213180e36267fa6a8f..78f9aed11fe879ae480a336393ac8210b5c7cd65 100644 --- a/src/chemistry/none/chemistry_struct.h +++ b/src/chemistry/none/chemistry_struct.h @@ -43,6 +43,13 @@ struct chemistry_global_data {}; */ struct chemistry_part_data {}; +/** + * @brief Chemistry properties carried by the #spart. + * + * Nothing here. + */ +struct chemistry_spart_data {}; + /** * @brief Chemistry properties carried by the #bpart. * diff --git a/src/cooling/grackle/cooling.c b/src/cooling/grackle/cooling.c index 30c0a50cf8bd72a5c222c504af5746850f1798f5..84b9fa4457f5cce15ea0cdb61f530d8548c43ae0 100644 --- a/src/cooling/grackle/cooling.c +++ b/src/cooling/grackle/cooling.c @@ -18,7 +18,7 @@ ******************************************************************************/ /** * @file src/cooling/grackle/cooling.c - * @brief Cooling using the GRACKLE 3.0 library. + * @brief Cooling using the GRACKLE 3.1.1 library. */ #include "../config.h" diff --git a/src/cooling/grackle/cooling.h b/src/cooling/grackle/cooling.h index 55dbb609f10c7da203e5c626bd7db04d1ad29a1c..a629f6fb7174adfd890ba2e54db1f24b7d3209ab 100644 --- a/src/cooling/grackle/cooling.h +++ b/src/cooling/grackle/cooling.h @@ -21,7 +21,7 @@ /** * @file src/cooling/grackle/cooling.h - * @brief Cooling using the GRACKLE 3.0 library. + * @brief Cooling using the GRACKLE 3.1.1 library. */ /* Some standard headers. */ diff --git a/src/parallel_io.c b/src/parallel_io.c index a8cbdbeca9a1062e38f98f1549f8f5f32c80708c..01fef7fc65a656c88343589145638a05f3d6e8d6 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1010,6 +1010,8 @@ void read_ic_parallel(char* fileName, const struct unit_system* internal_units, if (with_stars) { Nparticles = *Nstars; stars_read_particles(*sparts, list, &num_fields); + num_fields += + star_formation_read_particles(*sparts, list + num_fields); } break; diff --git a/src/serial_io.c b/src/serial_io.c index 1fe5a1a7b69420456e779ecf40424b7aa4b2ff16..c170a0ff4ff029d596da506c7618225ed0c6448b 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -804,6 +804,8 @@ void read_ic_serial(char* fileName, const struct unit_system* internal_units, if (with_stars) { Nparticles = *Nstars; stars_read_particles(*sparts, list, &num_fields); + num_fields += + star_formation_read_particles(*sparts, list + num_fields); } break; diff --git a/src/single_io.c b/src/single_io.c index 5952a7bb4ed21fc5fbe5660edfe06b3f4fad4d8f..865f0c9be6a5630fcd3c1769e599af2588975b3a 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -675,6 +675,8 @@ void read_ic_single(const char* fileName, if (with_stars) { Nparticles = *Nstars; stars_read_particles(*sparts, list, &num_fields); + num_fields += + star_formation_read_particles(*sparts, list + num_fields); } break; diff --git a/src/star_formation/EAGLE/star_formation_io.h b/src/star_formation/EAGLE/star_formation_io.h index fd4b870a7d5b75dd5f6c38c09255ff9786dede1c..aac87d8c0770e439756ecc13ca30e120ade521e9 100644 --- a/src/star_formation/EAGLE/star_formation_io.h +++ b/src/star_formation/EAGLE/star_formation_io.h @@ -25,6 +25,19 @@ /* Local includes */ #include "io_properties.h" +/** + * @brief Specifies which s-particle fields to read from a dataset + * + * @param sparts The s-particle array. + * @param list The list of i/o properties to read. + * + * @return num_fields The number of i/o fields to read. + */ +INLINE static int star_formation_read_particles(struct spart* sparts, + struct io_props* list) { + return 0; +} + /** * @brief Specifies which particle fields to write to a dataset * diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index 3ef57147567d6b9d7ef150ffba5893ef9abd0929..341ed815b1699fef9ad87d30d44e2c3b0a08f459 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.h @@ -21,6 +21,7 @@ #define SWIFT_GEAR_STAR_FORMATION_H /* Local includes */ +#include "chemistry.h" #include "cooling.h" #include "cosmology.h" #include "engine.h" diff --git a/src/star_formation/GEAR/star_formation_io.h b/src/star_formation/GEAR/star_formation_io.h index fc64cb893abe9b212f928d2b6cea7e9d0b7c80d4..46ac7c6e3de567fab148b08a62d8d88e1e8113da 100644 --- a/src/star_formation/GEAR/star_formation_io.h +++ b/src/star_formation/GEAR/star_formation_io.h @@ -26,6 +26,24 @@ /* Local includes */ #include "io_properties.h" +/** + * @brief Specifies which s-particle fields to read from a dataset + * + * @param sparts The s-particle array. + * @param list The list of i/o properties to read. + * + * @return num_fields The number of i/o fields to read. + */ +INLINE static int star_formation_read_particles(struct spart* sparts, + struct io_props* list) { + + /* List what we want to read */ + list[0] = io_make_input_field("BirthMass", FLOAT, 1, OPTIONAL, UNIT_CONV_MASS, + sparts, sf_data.birth_mass); + + return 1; +} + /** * @brief Specifies which particle fields to write to a dataset * @@ -113,7 +131,9 @@ INLINE static void starformation_init_backend( starform->min_mass_frac_plus_one += 1.; /* Get the jeans factor */ - starform->n_jeans_2_3 = pow(pressure_floor_props.n_jeans, 2. / 3.); + starform->n_jeans_2_3 = + parser_get_param_float(parameter_file, "GEARPressureFloor:jeans_factor"); + starform->n_jeans_2_3 = pow(starform->n_jeans_2_3, 2. / 3.); /* Apply unit change */ starform->maximal_temperature *= diff --git a/src/star_formation/QLA/star_formation_io.h b/src/star_formation/QLA/star_formation_io.h index bbdde40761a0e9fb364d4b191f41669c3495b86a..d65a40bf70782dcaf104ea1afe2565df2b2b307e 100644 --- a/src/star_formation/QLA/star_formation_io.h +++ b/src/star_formation/QLA/star_formation_io.h @@ -25,6 +25,19 @@ /* Local includes */ #include "io_properties.h" +/** + * @brief Specifies which s-particle fields to read from a dataset + * + * @param sparts The s-particle array. + * @param list The list of i/o properties to read. + * + * @return num_fields The number of i/o fields to read. + */ +INLINE static int star_formation_read_particles(struct spart* sparts, + struct io_props* list) { + return 0; +} + /** * @brief Specifies which particle fields to write to a dataset * diff --git a/src/star_formation/none/star_formation_io.h b/src/star_formation/none/star_formation_io.h index 8240c42e54e26443012838896ddf5349d1fdbcf2..5c2329b3978ebf0c5ed64c3f978c479456a3efc0 100644 --- a/src/star_formation/none/star_formation_io.h +++ b/src/star_formation/none/star_formation_io.h @@ -25,6 +25,19 @@ /* Local includes */ #include "io_properties.h" +/** + * @brief Specifies which s-particle fields to read from a dataset + * + * @param sparts The s-particle array. + * @param list The list of i/o properties to read. + * + * @return num_fields The number of i/o fields to read. + */ +INLINE static int star_formation_read_particles(struct spart* sparts, + struct io_props* list) { + return 0; +} + /** * @brief Specifies which particle fields to write to a dataset * diff --git a/src/stars/GEAR/stars.h b/src/stars/GEAR/stars.h index 3a6d6ba203c789a46038426d8646cc3c4662144d..a4a9b2ecdc79e45e108b5221e3880c78ca85e609 100644 --- a/src/stars/GEAR/stars.h +++ b/src/stars/GEAR/stars.h @@ -68,8 +68,6 @@ __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->sf_data.birth_density = 0.f; - // sp->birth_time = 0.; stars_init_spart(sp); } diff --git a/src/stars/GEAR/stars_io.h b/src/stars/GEAR/stars_io.h index 97d9f298264c991025dcc328d1b27d78b1c0b70b..7a1ed1fddda4aad485a3e2525b016de535490326 100644 --- a/src/stars/GEAR/stars_io.h +++ b/src/stars/GEAR/stars_io.h @@ -34,7 +34,7 @@ INLINE static void stars_read_particles(struct spart *sparts, int *num_fields) { /* Say how much we want to read */ - *num_fields = 7; + *num_fields = 6; /* List what we want to read */ list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY, @@ -47,10 +47,7 @@ INLINE static void stars_read_particles(struct spart *sparts, UNIT_CONV_NO_UNITS, sparts, id); list[4] = io_make_input_field("SmoothingLength", FLOAT, 1, OPTIONAL, UNIT_CONV_LENGTH, sparts, h); - list[5] = io_make_input_field("BirthMass", FLOAT, 1, OPTIONAL, UNIT_CONV_MASS, - sparts, sf_data.birth_mass); - - list[6] = io_make_input_field("BirthTime", FLOAT, 1, OPTIONAL, UNIT_CONV_MASS, + list[5] = io_make_input_field("BirthTime", FLOAT, 1, OPTIONAL, UNIT_CONV_MASS, sparts, birth_time); } diff --git a/tools/task_plots/plot_tasks.py b/tools/task_plots/plot_tasks.py index a0eb356cac402ebcf0f780d3363a3083efba2584..45f5feb03d4cad88bcb1af7c2b65b77247f1df1a 100755 --- a/tools/task_plots/plot_tasks.py +++ b/tools/task_plots/plot_tasks.py @@ -584,7 +584,7 @@ for rank in ranks: ax.yaxis.set_major_locator(loc) ax.grid(True, which="major", axis="y", linestyle="-") - pl.show() + # pl.show() if mpimode: outpng = outbase + str(rank) + ".png" else: