Commit 5f6f331d authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'master' into schaye08

parents 8931ca11 4beb6b9d
......@@ -203,7 +203,7 @@ code will be :math:`\epsilon=\min(\epsilon_{max},
The time-step of a given particle is given by :math:`\Delta t =
\eta\sqrt{\frac{\epsilon}{|\overrightarrow{a}|}}`, where
:math:`\overrightarrow{a}` is the particle's acceleration. Power et al. (2003) recommend using :math:`\eta=0.025`.
:math:`\overrightarrow{a}` is the particle's acceleration. `Power et al. (2003) <http://adsabs.harvard.edu/abs/2003MNRAS.338...14P>`_ recommend using :math:`\eta=0.025`.
The last tree-related parameter is
* The tree rebuild frequency: ``rebuild_frequency``.
......
......@@ -143,6 +143,37 @@ Whilst one would use the following values for solar abundances
init_abundance_Silicon: 6.825874e-4 # Mass fraction in Silicon
init_abundance_Iron: 1.1032152e-3 # Mass fraction in Iron
Individual element abundances for each particle can also be read
directly from the ICs. By default these are overwritten in the code by
the values read from the YAML file. However, users can set the
parameter ``init_abundance_metal`` to ``-1`` to make SWIFT ignore the
values provided in the parameter file:
.. code:: YAML
EAGLEChemistry:
init_abundance_metal: -1 # Read the particles' metal mass fractions from the ICs.
The ICs must then contain values for these three fields (same as what
is written to the snapshots):
+----------------------------------+-------------------------------------+-----------+-----------------------------+
| Name | Description | Units | Comments |
+==================================+=====================================+===========+=============================+
| ``ElementAbundance`` | | Fraction of the gas/star mass | [-] | | Array of length |
| | | in the different elements | | | 9 for each particle |
+----------------------------------+-------------------------------------+-----------+-----------------------------+
| ``Metallicity`` | | Fraction of the gas/star mass | [-] | |
| | | in *all* metals | | |
+----------------------------------+-------------------------------------+-----------+-----------------------------+
| ``IronMassFracFromSNIa`` | | Fraction of the *total* gas/star | [-] | |
| | | mass in *iron* produced produced | | |
| | | by enrichment from SNIa stars | | |
+----------------------------------+-------------------------------------+-----------+-----------------------------+
If these fields are absent, then a value of ``0`` will be used for all
of them, likely leading to issues in the way the code will run.
.. _EAGLE_cooling:
......
......@@ -229,7 +229,7 @@ int main(int argc, char **argv) {
// Init cooling
cooling_init(params, &us, &internal_const, &cooling);
cooling_print(&cooling);
cooling_update(&cosmo, &cooling, /*restart=*/0);
cooling_update(&cosmo, &cooling);
// Calculate abundance ratios
float abundance_ratio[(chemistry_element_count + 2)];
......
......@@ -129,7 +129,21 @@ chemistry_part_has_no_neighbours(struct part* restrict p,
struct xpart* restrict xp,
const struct chemistry_global_data* cd,
const struct cosmology* cosmo) {
error("Needs implementing!");
/* Just make all the smoothed fields default to the un-smoothed values */
struct chemistry_part_data* cpd = &p->chemistry_data;
/* Total metal mass fraction */
cpd->smoothed_metal_mass_fraction_total = cpd->metal_mass_fraction_total;
/* Iron frac from SNIa */
cpd->smoothed_iron_mass_fraction_from_SNIa =
cpd->iron_mass_fraction_from_SNIa;
/* Individual metal mass fractions */
for (int i = 0; i < chemistry_element_count; i++) {
cpd->smoothed_metal_mass_fraction[i] = cpd->metal_mass_fraction[i];
}
}
/**
......
......@@ -44,8 +44,8 @@ __attribute__((always_inline)) INLINE static void runner_iact_chemistry(
struct chemistry_part_data *chi = &pi->chemistry_data;
struct chemistry_part_data *chj = &pj->chemistry_data;
float wi, wi_dx;
float wj, wj_dx;
float wi;
float wj;
/* Get the masses. */
const float mi = pi->mass;
......@@ -56,11 +56,11 @@ __attribute__((always_inline)) INLINE static void runner_iact_chemistry(
/* Compute the kernel function for pi */
const float ui = r / hi;
kernel_deval(ui, &wi, &wi_dx);
kernel_eval(ui, &wi);
/* Compute the kernel function for pj */
const float uj = r / hj;
kernel_deval(uj, &wj, &wj_dx);
kernel_eval(uj, &wj);
/* Compute contribution to the smooth metallicity */
for (int i = 0; i < chemistry_element_count; i++) {
......@@ -103,7 +103,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_chemistry(
struct chemistry_part_data *chi = &pi->chemistry_data;
const struct chemistry_part_data *chj = &pj->chemistry_data;
float wi, wi_dx;
float wi;
/* Get the masses. */
const float mj = pj->mass;
......@@ -113,7 +113,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_chemistry(
/* Compute the kernel function for pi */
const float ui = r / hi;
kernel_deval(ui, &wi, &wi_dx);
kernel_eval(ui, &wi);
/* Compute contribution to the smooth metallicity */
for (int i = 0; i < chemistry_element_count; i++) {
......
......@@ -37,9 +37,9 @@ INLINE static int chemistry_read_particles(struct part* parts,
"ElementAbundance", FLOAT, chemistry_element_count, OPTIONAL,
UNIT_CONV_NO_UNITS, parts, chemistry_data.metal_mass_fraction);
list[1] =
io_make_input_field("Z", FLOAT, 1, OPTIONAL, UNIT_CONV_NO_UNITS, parts,
chemistry_data.metal_mass_fraction_total);
list[2] = io_make_input_field("IronFromSNIa", FLOAT, 1, OPTIONAL,
io_make_input_field("Metallicity", FLOAT, 1, OPTIONAL, UNIT_CONV_NO_UNITS,
parts, chemistry_data.metal_mass_fraction_total);
list[2] = io_make_input_field("IronMassFracFromSNIa", FLOAT, 1, OPTIONAL,
UNIT_CONV_NO_UNITS, parts,
chemistry_data.iron_mass_fraction_from_SNIa);
......
......@@ -53,31 +53,3 @@ void cooling_print(const struct cooling_function_data* cooling) {
cooling_print_backend(cooling);
}
/**
* @brief Write a cooling struct to the given FILE as a stream of bytes.
*
* @param cooling the struct
* @param stream the file stream
*/
void cooling_struct_dump(const struct cooling_function_data* cooling,
FILE* stream) {
restart_write_blocks((void*)cooling, sizeof(struct cooling_function_data), 1,
stream, "cooling", "cooling function");
}
/**
* @brief Restore a cooling_function struct from the given FILE as a stream of
* bytes.
*
* @param cooling the struct
* @param stream the file stream
* @param cosmo #cosmology structure
*/
void cooling_struct_restore(struct cooling_function_data* cooling, FILE* stream,
const struct cosmology* cosmo) {
restart_read_blocks((void*)cooling, sizeof(struct cooling_function_data), 1,
stream, NULL, "cooling function");
cooling_restore_tables(cooling, cosmo);
}
......@@ -76,7 +76,7 @@ static const double newton_log_u_guess_cgs = 1.414213562e6; /* log10(2e12) */
* @param cooling #cooling_function_data structure containing redshift table.
*/
__attribute__((always_inline)) INLINE void get_redshift_index(
float z, int *z_index, float *dz,
const float z, int *z_index, float *dz,
struct cooling_function_data *restrict cooling) {
/* Before the earliest redshift or before hydrogen reionization, flag for
......@@ -124,11 +124,9 @@ __attribute__((always_inline)) INLINE void get_redshift_index(
*
* @param cosmo The current cosmological model.
* @param cooling The #cooling_function_data used in the run.
* @param restart_flag Flag indicating restarted run.
*/
void cooling_update(const struct cosmology *cosmo,
struct cooling_function_data *cooling,
const int restart_flag) {
struct cooling_function_data *cooling) {
/* Current redshift */
const float redshift = cosmo->z;
......@@ -839,7 +837,6 @@ void cooling_init_backend(struct swift_params *parameter_file,
/* Set the redshift indices to invalid values */
cooling->z_index = -10;
cooling->previous_z_index = eagle_cooling_N_redshifts + 2;
/* set previous_z_index and to last value of redshift table*/
cooling->previous_z_index = eagle_cooling_N_redshifts - 2;
......@@ -872,8 +869,8 @@ void cooling_restore_tables(struct cooling_function_data *cooling,
/* Force a re-read of the cooling tables */
cooling->z_index = -10;
cooling->previous_z_index = eagle_cooling_N_redshifts + 2;
cooling_update(cosmo, cooling, /*restart_flag=*/1);
cooling->previous_z_index = eagle_cooling_N_redshifts - 2;
cooling_update(cosmo, cooling);
}
/**
......@@ -911,3 +908,52 @@ void cooling_clean(struct cooling_function_data *cooling) {
free(cooling->table.H_plus_He_heating);
free(cooling->table.H_plus_He_electron_abundance);
}
/**
* @brief Write a cooling struct to the given FILE as a stream of bytes.
*
* @param cooling the struct
* @param stream the file stream
*/
void cooling_struct_dump(const struct cooling_function_data *cooling,
FILE *stream) {
/* To make sure everything is restored correctly, we zero all the pointers to
tables. If they are not restored correctly, we would crash after restart on
the first call to the cooling routines. Helps debugging. */
struct cooling_function_data cooling_copy = *cooling;
cooling_copy.Redshifts = NULL;
cooling_copy.nH = NULL;
cooling_copy.Temp = NULL;
cooling_copy.Therm = NULL;
cooling_copy.SolarAbundances = NULL;
cooling_copy.SolarAbundances_inv = NULL;
cooling_copy.table.metal_heating = NULL;
cooling_copy.table.H_plus_He_heating = NULL;
cooling_copy.table.H_plus_He_electron_abundance = NULL;
cooling_copy.table.temperature = NULL;
cooling_copy.table.electron_abundance = NULL;
restart_write_blocks((void *)&cooling_copy,
sizeof(struct cooling_function_data), 1, stream,
"cooling", "cooling function");
}
/**
* @brief Restore a hydro_props struct from the given FILE as a stream of
* bytes.
*
* Read the structure from the stream and restore the cooling tables by
* re-reading them.
*
* @param cooling the struct
* @param stream the file stream
* @param cosmo #cosmology structure
*/
void cooling_struct_restore(struct cooling_function_data *cooling, FILE *stream,
const struct cosmology *cosmo) {
restart_read_blocks((void *)cooling, sizeof(struct cooling_function_data), 1,
stream, NULL, "cooling function");
cooling_restore_tables(cooling, cosmo);
}
......@@ -33,8 +33,7 @@
#include "units.h"
void cooling_update(const struct cosmology *cosmo,
struct cooling_function_data *cooling,
const int restart_flag);
struct cooling_function_data *cooling);
void cooling_cool_part(const struct phys_const *restrict phys_const,
const struct unit_system *restrict us,
......
......@@ -54,11 +54,9 @@
*
* @param cosmo The current cosmological model.
* @param cooling The #cooling_function_data used in the run.
* @param restart_flag Are we calling this directly after a restart?
*/
INLINE static void cooling_update(const struct cosmology* cosmo,
struct cooling_function_data* cooling,
const int restart_flag) {
struct cooling_function_data* cooling) {
// Add content if required.
}
......@@ -685,6 +683,18 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
hydro_set_physical_internal_energy_dt(p, cosmo, hydro_du_dt + du_dt);
}
static INLINE float cooling_get_temperature(
const struct phys_const* restrict phys_const,
const struct hydro_props* restrict hydro_props,
const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling,
const struct part* restrict p, const struct xpart* restrict xp) {
error("This function needs implementing!!");
return 0.;
}
/**
* @brief Computes the cooling time-step.
*
......@@ -815,15 +825,6 @@ __attribute__((always_inline)) INLINE static void cooling_init_backend(
cooling_init_grackle(cooling);
}
/**
* @brief Restore cooling tables (if applicable) after
* restart
*
* @param cooling the cooling_function_data structure
* @param cosmo cosmology structure
*/
static INLINE void cooling_restore_tables(struct cooling_function_data* cooling,
const struct cosmology* cosmo) {}
/**
* @brief Clean-up the memory allocated for the cooling routines
*
......@@ -834,4 +835,35 @@ static INLINE void cooling_clean(struct cooling_function_data* cooling) {
// MATTHIEU: To do: free stuff here
}
/**
* @brief Write a cooling struct to the given FILE as a stream of bytes.
*
* Nothing to do beyond writing the structure from the stream.
*
* @param cooling the struct
* @param stream the file stream
*/
static INLINE void cooling_struct_dump(
const struct cooling_function_data* cooling, FILE* stream) {
restart_write_blocks((void*)cooling, sizeof(struct cooling_function_data), 1,
stream, "cooling", "cooling function");
}
/**
* @brief Restore a hydro_props struct from the given FILE as a stream of
* bytes.
*
* Nothing to do beyond reading the structure from the stream.
*
* @param cooling the struct
* @param stream the file stream
* @param cosmo #cosmology structure
*/
static INLINE void cooling_struct_restore(struct cooling_function_data* cooling,
FILE* stream,
const struct cosmology* cosmo) {
restart_read_blocks((void*)cooling, sizeof(struct cooling_function_data), 1,
stream, NULL, "cooling function");
}
#endif /* SWIFT_COOLING_GRACKLE_H */
......@@ -59,7 +59,7 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
* @return Returns the number of fields to write.
*/
__attribute__((always_inline)) INLINE static int cooling_write_particles(
const struct xpart* xparts, struct io_props* list,
const struct part* parts, const struct xpart* xparts, struct io_props* list,
const struct cooling_function_data* cooling) {
int num = 0;
......
......@@ -46,8 +46,7 @@
* @param cooling The #cooling_function_data used in the run.
*/
INLINE static void cooling_update(const struct cosmology* cosmo,
struct cooling_function_data* cooling,
const int restart_flag) {
struct cooling_function_data* cooling) {
// Add content if required.
}
......@@ -191,18 +190,6 @@ static INLINE void cooling_init_backend(struct swift_params* parameter_file,
struct cooling_function_data* cooling) {
}
/**
* @brief Restore cooling tables (if applicable) after
* restart
*
* Nothing to do here
*
* @param cooling the cooling_function_data structure
* @param cosmo cosmology structure
*/
static INLINE void cooling_restore_tables(struct cooling_function_data* cooling,
const struct cosmology* cosmo) {}
/**
* @brief Prints the properties of the cooling model to stdout.
*
......@@ -221,4 +208,29 @@ static INLINE void cooling_print_backend(
*/
static INLINE void cooling_clean(struct cooling_function_data* cooling) {}
/**
* @brief Write a cooling struct to the given FILE as a stream of bytes.
*
* Empty structure so nothing to do here.
*
* @param cooling the struct
* @param stream the file stream
*/
static INLINE void cooling_struct_dump(
const struct cooling_function_data* cooling, FILE* stream) {}
/**
* @brief Restore a hydro_props struct from the given FILE as a stream of
* bytes.
*
* Empty structure so nothing to do here.
*
* @param cooling the struct
* @param stream the file stream
* @param cosmo #cosmology structure
*/
static INLINE void cooling_struct_restore(struct cooling_function_data* cooling,
FILE* stream,
const struct cosmology* cosmo) {}
#endif /* SWIFT_COOLING_NONE_H */
......@@ -2800,7 +2800,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
/* Update the cooling function */
if ((e->policy & engine_policy_cooling) ||
(e->policy & engine_policy_temperature))
cooling_update(e->cosmology, e->cooling_func, /*restart_flag=*/0);
cooling_update(e->cosmology, e->cooling_func);
#ifdef WITH_LOGGER
/* Mark the first time step in the particle logger file. */
......@@ -3060,7 +3060,7 @@ void engine_step(struct engine *e) {
/* Update the cooling function */
if ((e->policy & engine_policy_cooling) ||
(e->policy & engine_policy_temperature))
cooling_update(e->cosmology, e->cooling_func, /*restart_flag=*/0);
cooling_update(e->cosmology, e->cooling_func);
/*****************************************************/
/* OK, we now know what the next end of time-step is */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment