Commit 81c05683 authored by Matthieu Schaller's avatar Matthieu Schaller

Merge branch 'improved_grackle' into 'master'

Add support for Grackle 3.0.

See merge request !499
parents 0cb47d49 e7f6698b
...@@ -962,7 +962,7 @@ esac ...@@ -962,7 +962,7 @@ esac
# Cooling function # Cooling function
AC_ARG_WITH([cooling], AC_ARG_WITH([cooling],
[AS_HELP_STRING([--with-cooling=<function>], [AS_HELP_STRING([--with-cooling=<function>],
[cooling function @<:@none, const-du, const-lambda, grackle default: none@:>@] [cooling function @<:@none, const-du, const-lambda, EAGLE, grackle, grackle1, grackle2, grackle3 default: none@:>@]
)], )],
[with_cooling="$withval"], [with_cooling="$withval"],
[with_cooling="none"] [with_cooling="none"]
...@@ -979,7 +979,20 @@ case "$with_cooling" in ...@@ -979,7 +979,20 @@ case "$with_cooling" in
;; ;;
grackle) grackle)
AC_DEFINE([COOLING_GRACKLE], [1], [Cooling via the grackle library]) AC_DEFINE([COOLING_GRACKLE], [1], [Cooling via the grackle library])
AC_DEFINE([COOLING_GRACKLE_MODE], [0], [Grackle chemistry network, mode 0])
;;
grackle1)
AC_DEFINE([COOLING_GRACKLE], [1], [Cooling via the grackle library])
AC_DEFINE([COOLING_GRACKLE_MODE], [1], [Grackle chemistry network, mode 1])
;; ;;
grackle2)
AC_DEFINE([COOLING_GRACKLE], [1], [Cooling via the grackle library])
AC_DEFINE([COOLING_GRACKLE_MODE], [2], [Grackle chemistry network, mode 2])
;;
grackle3)
AC_DEFINE([COOLING_GRACKLE], [1], [Cooling via the grackle library])
AC_DEFINE([COOLING_GRACKLE_MODE], [3], [Grackle chemistry network, mode 3])
;;
EAGLE) EAGLE)
AC_DEFINE([COOLING_EAGLE], [1], [Cooling following the EAGLE model]) AC_DEFINE([COOLING_EAGLE], [1], [Cooling following the EAGLE model])
;; ;;
......
...@@ -42,11 +42,17 @@ LambdaCooling: ...@@ -42,11 +42,17 @@ LambdaCooling:
# Cooling with Grackle 2.0 # Cooling with Grackle 2.0
GrackleCooling: GrackleCooling:
GrackleCloudyTable: ../CloudyData_UVB=HM2012.h5 # Name of the Cloudy Table (available on the grackle bitbucket repository) CloudyTable: CloudyData_UVB=HM2012.h5 # Name of the Cloudy Table (available on the grackle bitbucket repository)
UVbackground: 0 # Enable or not the UV background WithUVbackground: 0 # Enable or not the UV background
GrackleRedshift: 0 # Redshift to use (-1 means time based redshift) Redshift: 0 # Redshift to use (-1 means time based redshift)
GrackleHSShieldingDensityThreshold: 1.1708e-26 # self shielding threshold in internal system of units 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
OutputMode: 1 # Write in output corresponding primordial chemistry mode
MaxSteps: 1000
ConvergenceLimit: 1e-2
EAGLEChemistry: EAGLEChemistry:
InitMetallicity: 0. InitMetallicity: 0.
InitAbundance_Hydrogen: 0.752 InitAbundance_Hydrogen: 0.752
...@@ -60,3 +66,6 @@ EAGLEChemistry: ...@@ -60,3 +66,6 @@ EAGLEChemistry:
InitAbundance_Iron: 0.000 InitAbundance_Iron: 0.000
CalciumOverSilicon: 0.0941736 CalciumOverSilicon: 0.0941736
SulphurOverSilicon: 0.6054160 SulphurOverSilicon: 0.6054160
GearChemistry:
InitialMetallicity: 0.01295
...@@ -124,7 +124,7 @@ int main(int argc, char *argv[]) { ...@@ -124,7 +124,7 @@ int main(int argc, char *argv[]) {
/* Structs used by the engine. Declare now to make sure these are always in /* Structs used by the engine. Declare now to make sure these are always in
* scope. */ * scope. */
struct chemistry_data chemistry; struct chemistry_global_data chemistry;
struct cooling_function_data cooling_func; struct cooling_function_data cooling_func;
struct cosmology cosmo; struct cosmology cosmo;
struct external_potential potential; struct external_potential potential;
......
...@@ -179,12 +179,18 @@ LambdaCooling: ...@@ -179,12 +179,18 @@ LambdaCooling:
hydrogen_mass_abundance: 0.75 # Hydrogen mass abundance (dimensionless) hydrogen_mass_abundance: 0.75 # Hydrogen mass abundance (dimensionless)
cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition
# Cooling with Grackle 2.0 # Cooling with Grackle 3.0
GrackleCooling: GrackleCooling:
GrackleCloudyTable: CloudyData_UVB=HM2012.h5 # Name of the Cloudy Table (available on the grackle bitbucket repository) CloudyTable: CloudyData_UVB=HM2012.h5 # Name of the Cloudy Table (available on the grackle bitbucket repository)
UVbackground: 1 # Enable or not the UV background WithUVbackground: 1 # Enable or not the UV background
GrackleRedshift: 0 # Redshift to use (-1 means time based redshift) Redshift: 0 # Redshift to use (-1 means time based redshift)
GrackleHSShieldingDensityThreshold: 1.1708e-26 # self shielding threshold in internal system of units WithMetalCooling: 1 # Enable or not the metal cooling
ProvideVolumetricHeatingRates: 0 # (optional) User provide volumetric heating rates
ProvideSpecificHeatingRates: 0 # (optional) User provide specific heating rates
SelfShieldingMethod: 0 # (optional) Grackle (<= 3) or Gear self shielding method
OutputMode: 0 # (optional) Write in output corresponding primordial chemistry mode
MaxSteps: 10000 # (optional) Max number of step when computing the initial composition
ConvergenceLimit: 1e-2 # (optional) Convergence threshold (relative) for initial composition
# Parameters related to chemistry models ----------------------------------------------- # Parameters related to chemistry models -----------------------------------------------
......
...@@ -43,8 +43,8 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \ ...@@ -43,8 +43,8 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \
engine.h swift.h serial_io.h timers.h debug.h scheduler.h proxy.h parallel_io.h \ engine.h swift.h serial_io.h timers.h debug.h scheduler.h proxy.h parallel_io.h \
common_io.h single_io.h multipole.h map.h tools.h partition.h clocks.h parser.h \ common_io.h single_io.h multipole.h map.h tools.h partition.h clocks.h parser.h \
physical_constants.h physical_constants_cgs.h potential.h version.h \ physical_constants.h physical_constants_cgs.h potential.h version.h \
hydro_properties.h riemann.h threadpool.h cooling.h cooling_struct.h sourceterms.h \ hydro_properties.h riemann.h threadpool.h cooling_io.h cooling.h cooling_struct.h \
sourceterms_struct.h statistics.h memswap.h cache.h runner_doiact_vec.h profiler.h \ sourceterms.h sourceterms_struct.h statistics.h memswap.h cache.h runner_doiact_vec.h profiler.h \
dump.h logger.h active.h timeline.h xmf.h gravity_properties.h gravity_derivatives.h \ dump.h logger.h active.h timeline.h xmf.h gravity_properties.h gravity_derivatives.h \
gravity_softened_derivatives.h vector_power.h collectgroup.h hydro_space.h sort_part.h \ gravity_softened_derivatives.h vector_power.h collectgroup.h hydro_space.h sort_part.h \
chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h
...@@ -118,10 +118,15 @@ nobase_noinst_HEADERS = align.h approx_math.h atomic.h barrier.h cycle.h error.h ...@@ -118,10 +118,15 @@ nobase_noinst_HEADERS = align.h approx_math.h atomic.h barrier.h cycle.h error.h
potential/isothermal/potential.h potential/disc_patch/potential.h \ potential/isothermal/potential.h potential/disc_patch/potential.h \
potential/sine_wave/potential.h \ potential/sine_wave/potential.h \
cooling/none/cooling.h cooling/none/cooling_struct.h \ cooling/none/cooling.h cooling/none/cooling_struct.h \
cooling/none/cooling_io.h \
cooling/const_du/cooling.h cooling/const_du/cooling_struct.h \ cooling/const_du/cooling.h cooling/const_du/cooling_struct.h \
cooling/const_du/cooling_io.h \
cooling/const_lambda/cooling.h cooling/const_lambda/cooling_struct.h \ cooling/const_lambda/cooling.h cooling/const_lambda/cooling_struct.h \
cooling/const_lambda/cooling_io.h \
cooling/grackle/cooling.h cooling/grackle/cooling_struct.h \ cooling/grackle/cooling.h cooling/grackle/cooling_struct.h \
cooling/grackle/cooling_io.h \
cooling/EAGLE/cooling.h cooling/EAGLE/cooling_struct.h \ cooling/EAGLE/cooling.h cooling/EAGLE/cooling_struct.h \
cooling/EAGLE/cooling_io.h \
chemistry/none/chemistry.h \ chemistry/none/chemistry.h \
chemistry/none/chemistry_io.h \ chemistry/none/chemistry_io.h \
chemistry/none/chemistry_struct.h \ chemistry/none/chemistry_struct.h \
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
void chemistry_init(const struct swift_params* parameter_file, void chemistry_init(const struct swift_params* parameter_file,
const struct unit_system* us, const struct unit_system* us,
const struct phys_const* phys_const, const struct phys_const* phys_const,
struct chemistry_data* data) { struct chemistry_global_data* data) {
chemistry_init_backend(parameter_file, us, phys_const, data); chemistry_init_backend(parameter_file, us, phys_const, data);
} }
...@@ -46,9 +46,10 @@ void chemistry_init(const struct swift_params* parameter_file, ...@@ -46,9 +46,10 @@ void chemistry_init(const struct swift_params* parameter_file,
* *
* Calls chemistry_print_backend for the chosen chemistry model. * Calls chemistry_print_backend for the chosen chemistry model.
* *
* @brief The #chemistry_data containing information about the current model. * @brief The #chemistry_global_data containing information about the current
* model.
*/ */
void chemistry_print(const struct chemistry_data* data) { void chemistry_print(const struct chemistry_global_data* data) {
chemistry_print_backend(data); chemistry_print_backend(data);
} }
...@@ -58,10 +59,10 @@ void chemistry_print(const struct chemistry_data* data) { ...@@ -58,10 +59,10 @@ void chemistry_print(const struct chemistry_data* data) {
* @param chemistry the struct * @param chemistry the struct
* @param stream the file stream * @param stream the file stream
*/ */
void chemistry_struct_dump(const struct chemistry_data* chemistry, void chemistry_struct_dump(const struct chemistry_global_data* chemistry,
FILE* stream) { FILE* stream) {
restart_write_blocks((void*)chemistry, sizeof(struct chemistry_data), 1, restart_write_blocks((void*)chemistry, sizeof(struct chemistry_global_data),
stream, "chemistry", "chemistry function"); 1, stream, "chemistry", "chemistry function");
} }
/** /**
...@@ -71,8 +72,8 @@ void chemistry_struct_dump(const struct chemistry_data* chemistry, ...@@ -71,8 +72,8 @@ void chemistry_struct_dump(const struct chemistry_data* chemistry,
* @param chemistry the struct * @param chemistry the struct
* @param stream the file stream * @param stream the file stream
*/ */
void chemistry_struct_restore(const struct chemistry_data* chemistry, void chemistry_struct_restore(const struct chemistry_global_data* chemistry,
FILE* stream) { FILE* stream) {
restart_read_blocks((void*)chemistry, sizeof(struct chemistry_data), 1, restart_read_blocks((void*)chemistry, sizeof(struct chemistry_global_data), 1,
stream, NULL, "chemistry function"); stream, NULL, "chemistry function");
} }
...@@ -46,14 +46,14 @@ ...@@ -46,14 +46,14 @@
void chemistry_init(const struct swift_params* parameter_file, void chemistry_init(const struct swift_params* parameter_file,
const struct unit_system* us, const struct unit_system* us,
const struct phys_const* phys_const, const struct phys_const* phys_const,
struct chemistry_data* data); struct chemistry_global_data* data);
void chemistry_print(const struct chemistry_data* data); void chemistry_print(const struct chemistry_global_data* data);
/* Dump/restore. */ /* Dump/restore. */
void chemistry_struct_dump(const struct chemistry_data* chemistry, void chemistry_struct_dump(const struct chemistry_global_data* chemistry,
FILE* stream); FILE* stream);
void chemistry_struct_restore(const struct chemistry_data* chemistry, void chemistry_struct_restore(const struct chemistry_global_data* chemistry,
FILE* stream); FILE* stream);
#endif /* SWIFT_CHEMISTRY_H */ #endif /* SWIFT_CHEMISTRY_H */
...@@ -57,10 +57,10 @@ chemistry_get_element_name(enum chemistry_element elem) { ...@@ -57,10 +57,10 @@ chemistry_get_element_name(enum chemistry_element elem) {
* the various smooth metallicity tasks * the various smooth metallicity tasks
* *
* @param p The particle to act upon * @param p The particle to act upon
* @param cd #chemistry_data containing chemistry informations. * @param cd #chemistry_global_data containing chemistry informations.
*/ */
__attribute__((always_inline)) INLINE static void chemistry_init_part( __attribute__((always_inline)) INLINE static void chemistry_init_part(
struct part* restrict p, const struct chemistry_data* cd) {} struct part* restrict p, const struct chemistry_global_data* cd) {}
/** /**
* @brief Finishes the smooth metal calculation. * @brief Finishes the smooth metal calculation.
...@@ -71,11 +71,11 @@ __attribute__((always_inline)) INLINE static void chemistry_init_part( ...@@ -71,11 +71,11 @@ __attribute__((always_inline)) INLINE static void chemistry_init_part(
* This function requires the #hydro_end_density to have been called. * This function requires the #hydro_end_density to have been called.
* *
* @param p The particle to act upon. * @param p The particle to act upon.
* @param cd #chemistry_data containing chemistry informations. * @param cd #chemistry_global_data containing chemistry informations.
* @param cosmo The current cosmological model. * @param cosmo The current cosmological model.
*/ */
__attribute__((always_inline)) INLINE static void chemistry_end_density( __attribute__((always_inline)) INLINE static void chemistry_end_density(
struct part* restrict p, const struct chemistry_data* cd, struct part* restrict p, const struct chemistry_global_data* cd,
const struct cosmology* cosmo) {} const struct cosmology* cosmo) {}
/** /**
...@@ -87,8 +87,11 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density( ...@@ -87,8 +87,11 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density(
* @param data The global chemistry information. * @param data The global chemistry information.
*/ */
__attribute__((always_inline)) INLINE static void chemistry_first_init_part( __attribute__((always_inline)) INLINE static void chemistry_first_init_part(
struct part* restrict p, struct xpart* restrict xp, const struct phys_const* restrict phys_const,
const struct chemistry_data* data) { const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct chemistry_global_data* data, struct part* restrict p,
struct xpart* restrict xp) {
p->chemistry_data.metal_mass_fraction_total = p->chemistry_data.metal_mass_fraction_total =
data->initial_metal_mass_fraction_total; data->initial_metal_mass_fraction_total;
...@@ -107,7 +110,7 @@ __attribute__((always_inline)) INLINE static void chemistry_first_init_part( ...@@ -107,7 +110,7 @@ __attribute__((always_inline)) INLINE static void chemistry_first_init_part(
*/ */
static INLINE void chemistry_init_backend( static INLINE void chemistry_init_backend(
const struct swift_params* parameter_file, const struct unit_system* us, const struct swift_params* parameter_file, const struct unit_system* us,
const struct phys_const* phys_const, struct chemistry_data* data) { const struct phys_const* phys_const, struct chemistry_global_data* data) {
/* Read the total metallicity */ /* Read the total metallicity */
data->initial_metal_mass_fraction_total = data->initial_metal_mass_fraction_total =
...@@ -133,9 +136,11 @@ static INLINE void chemistry_init_backend( ...@@ -133,9 +136,11 @@ static INLINE void chemistry_init_backend(
/** /**
* @brief Prints the properties of the chemistry model to stdout. * @brief Prints the properties of the chemistry model to stdout.
* *
* @brief The #chemistry_data containing information about the current model. * @brief The #chemistry_global_data containing information about the current
* model.
*/ */
static INLINE void chemistry_print_backend(const struct chemistry_data* data) { static INLINE void chemistry_print_backend(
const struct chemistry_global_data* data) {
message("Chemistry model is 'EAGLE' tracking %d elements.", message("Chemistry model is 'EAGLE' tracking %d elements.",
chemistry_element_count); chemistry_element_count);
......
...@@ -38,7 +38,7 @@ enum chemistry_element { ...@@ -38,7 +38,7 @@ enum chemistry_element {
/** /**
* @brief Global chemical abundance information in the EAGLE model. * @brief Global chemical abundance information in the EAGLE model.
*/ */
struct chemistry_data { struct chemistry_global_data {
/*! Fraction of the particle mass in given elements at the start of the run */ /*! Fraction of the particle mass in given elements at the start of the run */
float initial_metal_mass_fraction[chemistry_element_count]; float initial_metal_mass_fraction[chemistry_element_count];
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <math.h> #include <math.h>
/* Local includes. */ /* Local includes. */
#include "chemistry_io.h"
#include "chemistry_struct.h" #include "chemistry_struct.h"
#include "error.h" #include "error.h"
#include "hydro.h" #include "hydro.h"
...@@ -38,16 +39,16 @@ ...@@ -38,16 +39,16 @@
#include "units.h" #include "units.h"
/** /**
* @brief Return a string containing the name of a given #chemistry_element. * @brief Compute the metal mass fraction
*
* @param p Pointer to the particle data.
* @param xp Pointer to the extended particle data.
* @param data The global chemistry information.
*/ */
__attribute__((always_inline)) INLINE static const char* __attribute__((always_inline)) INLINE static float
chemistry_get_element_name(enum chemistry_element elem) { chemistry_metal_mass_fraction(const struct part* restrict p,
const struct xpart* restrict xp) {
static const char* chemistry_element_names[chemistry_element_count] = { return p->chemistry_data.Z;
"Oxygen", "Magnesium", "Sulfur", "Iron", "Zinc",
"Strontium", "Yttrium", "Barium", "Europium"};
return chemistry_element_names[elem];
} }
/** /**
...@@ -62,16 +63,10 @@ chemistry_get_element_name(enum chemistry_element elem) { ...@@ -62,16 +63,10 @@ chemistry_get_element_name(enum chemistry_element elem) {
*/ */
static INLINE void chemistry_init_backend( static INLINE void chemistry_init_backend(
const struct swift_params* parameter_file, const struct unit_system* us, const struct swift_params* parameter_file, const struct unit_system* us,
const struct phys_const* phys_const, struct chemistry_data* data) {} const struct phys_const* phys_const, struct chemistry_global_data* data) {
/** /* read parameters */
* @brief Prints the properties of the chemistry model to stdout. chemistry_read_parameters(parameter_file, us, phys_const, data);
*
* @brief The #chemistry_data containing information about the current model.
*/
static INLINE void chemistry_print_backend(const struct chemistry_data* data) {
message("Chemistry function is 'Gear'.");
} }
/** /**
...@@ -81,10 +76,10 @@ static INLINE void chemistry_print_backend(const struct chemistry_data* data) { ...@@ -81,10 +76,10 @@ static INLINE void chemistry_print_backend(const struct chemistry_data* data) {
* the various smooth metallicity tasks * the various smooth metallicity tasks
* *
* @param p The particle to act upon * @param p The particle to act upon
* @param cd #chemistry_data containing chemistry informations. * @param cd #chemistry_global_data containing chemistry informations.
*/ */
__attribute__((always_inline)) INLINE static void chemistry_init_part( __attribute__((always_inline)) INLINE static void chemistry_init_part(
struct part* restrict p, const struct chemistry_data* cd) { struct part* restrict p, const struct chemistry_global_data* cd) {
struct chemistry_part_data* cpd = &p->chemistry_data; struct chemistry_part_data* cpd = &p->chemistry_data;
...@@ -102,11 +97,11 @@ __attribute__((always_inline)) INLINE static void chemistry_init_part( ...@@ -102,11 +97,11 @@ __attribute__((always_inline)) INLINE static void chemistry_init_part(
* This function requires the #hydro_end_density to have been called. * This function requires the #hydro_end_density to have been called.
* *
* @param p The particle to act upon. * @param p The particle to act upon.
* @param cd #chemistry_data containing chemistry informations. * @param cd #chemistry_global_data containing chemistry informations.
* @param cosmo The current cosmological model. * @param cosmo The current cosmological model.
*/ */
__attribute__((always_inline)) INLINE static void chemistry_end_density( __attribute__((always_inline)) INLINE static void chemistry_end_density(
struct part* restrict p, const struct chemistry_data* cd, struct part* restrict p, const struct chemistry_global_data* cd,
const struct cosmology* cosmo) { const struct cosmology* cosmo) {
/* Some smoothing length multiples. */ /* Some smoothing length multiples. */
...@@ -138,8 +133,13 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density( ...@@ -138,8 +133,13 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density(
* @param data The global chemistry information. * @param data The global chemistry information.
*/ */
__attribute__((always_inline)) INLINE static void chemistry_first_init_part( __attribute__((always_inline)) INLINE static void chemistry_first_init_part(
struct part* restrict p, struct xpart* restrict xp, const struct phys_const* restrict phys_const,
const struct chemistry_data* data) { const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct chemistry_global_data* data, struct part* restrict p,
struct xpart* restrict xp) {
p->chemistry_data.Z = data->initial_metallicity;
chemistry_init_part(p, data); chemistry_init_part(p, data);
} }
......
...@@ -19,9 +19,38 @@ ...@@ -19,9 +19,38 @@
#ifndef SWIFT_CHEMISTRY_IO_GEAR_H #ifndef SWIFT_CHEMISTRY_IO_GEAR_H
#define SWIFT_CHEMISTRY_IO_GEAR_H #define SWIFT_CHEMISTRY_IO_GEAR_H
#include "chemistry.h"
#include "chemistry_struct.h" #include "chemistry_struct.h"
#include "error.h"
#include "io_properties.h" #include "io_properties.h"
#include "parser.h"
#include "part.h"
#include "physical_constants.h"
#include "units.h"
/**
* @brief Return a string containing the name of a given #chemistry_element.
*/
__attribute__((always_inline)) INLINE static const char*
chemistry_get_element_name(enum chemistry_element elem) {
static const char* chemistry_element_names[chemistry_element_count] = {
"Oxygen", "Magnesium", "Sulfur", "Iron", "Zinc",
"Strontium", "Yttrium", "Barium", "Europium"};
return chemistry_element_names[elem];
}
/**
* @brief Prints the properties of the chemistry model to stdout.
*
* @brief The #chemistry_global_data containing information about the current
* model.
*/
static INLINE void chemistry_print_backend(
const struct chemistry_global_data* data) {
message("Chemistry function is 'Gear'.");
}
/** /**
* @brief Specifies which particle fields to read from a dataset * @brief Specifies which particle fields to read from a dataset
...@@ -31,13 +60,25 @@ ...@@ -31,13 +60,25 @@
* *
* @return Returns the number of fields to read. * @return Returns the number of fields to read.
*/ */
int chemistry_read_particles(struct part* parts, struct io_props* list) { __attribute__((always_inline)) INLINE static int chemistry_read_particles(
struct part* parts, struct io_props* list) {
/* List what we want to read */ /* List what we want to read */
list[0] = io_make_input_field( list[0] = io_make_input_field(
"ElementAbundance", FLOAT, chemistry_element_count, OPTIONAL, "ElementAbundance", FLOAT, chemistry_element_count, OPTIONAL,
UNIT_CONV_NO_UNITS, parts, chemistry_data.metal_mass_fraction); UNIT_CONV_NO_UNITS, parts, chemistry_data.metal_mass_fraction);
return 1; list[1] = io_make_input_field("Z", FLOAT, 1, OPTIONAL, UNIT_CONV_NO_UNITS,
parts, chemistry_data.Z);
return 2;
}
__attribute__((always_inline)) INLINE static void chemistry_read_parameters(
const struct swift_params* parameter_file, const struct unit_system* us,
const struct phys_const* phys_const, struct chemistry_global_data* data) {
data->initial_metallicity = parser_get_opt_param_float(
parameter_file, "GearChemistry:InitialMetallicity", -1);
} }
/** /**
...@@ -48,18 +89,21 @@ int chemistry_read_particles(struct part* parts, struct io_props* list) { ...@@ -48,18 +89,21 @@ int chemistry_read_particles(struct part* parts, struct io_props* list) {
* *
* @return Returns the number of fields to write. * @return Returns the number of fields to write.
*/ */
int chemistry_write_particles(const struct part* parts, struct io_props* list) { __attribute__((always_inline)) INLINE static int chemistry_write_particles(
const struct part* parts, struct io_props* list) {
/* List what we want to write */ /* List what we want to write */
list[0] = io_make_output_field( list[0] = io_make_output_field(
"SmoothedElementAbundance", FLOAT, chemistry_element_count, "SmoothedElementAbundance", FLOAT, chemistry_element_count,
UNIT_CONV_NO_UNITS, parts, chemistry_data.smoothed_metal_mass_fraction); UNIT_CONV_NO_UNITS, parts, chemistry_data.smoothed_metal_mass_fraction);
list[1] = io_make_output_field("Z", FLOAT, 1, UNIT_CONV_NO_UNITS, parts,
chemistry_data.Z);
list[1] = io_make_output_field("ElementAbundance", FLOAT, list[2] = io_make_output_field("ElementAbundance", FLOAT,
chemistry_element_count, UNIT_CONV_NO_UNITS, chemistry_element_count, UNIT_CONV_NO_UNITS,
parts, chemistry_data.metal_mass_fraction); parts, chemistry_data.metal_mass_fraction);
return 2; return 3;
} }
#ifdef HAVE_HDF5 #ifdef HAVE_HDF5
...@@ -68,7 +112,8 @@ int chemistry_write_particles(const struct part* parts, struct io_props* list) { ...@@ -68,7 +112,8 @@ int chemistry_write_particles(const struct part* parts, struct io_props* list) {
* @brief Writes the current model of SPH to the file * @brief Writes the current model of SPH to the file
* @param h_grp The HDF5 group in which to write * @param h_grp The HDF5 group in which to write
*/ */
void chemistry_write_flavour(hid_t h_grp) { __attribute__((always_inline)) INLINE static void chemistry_write_flavour(
hid_t h_grp) {
io_write_attribute_s(h_grp, "Chemistry Model", "GEAR"); io_write_attribute_s(h_grp, "Chemistry Model", "GEAR");
for (enum chemistry_element i = chemistry_element_O; for (enum chemistry_element i = chemistry_element_O;
......
...@@ -38,7 +38,11 @@ enum chemistry_element { ...@@ -38,7 +38,11 @@ enum chemistry_element {
/** /**
* @brief Global chemical abundance information. * @brief Global chemical abundance information.
*/ */
struct chemistry_data {}; struct chemistry_global_data {
/* Initial metallicity Z */
float initial_metallicity;
};
/** /**
* @brief Properties of the chemistry function. * @brief Properties of the chemistry function.
...@@ -50,6 +54,8 @@ struct chemistry_part_data { ...@@ -50,6 +54,8 @@ struct chemistry_part_data {
/*! Smoothed fraction of the particle mass in a given element */ /*! Smoothed fraction of the particle mass in a given element */
float smoothed_metal_mass_fraction[chemistry_element_count]; float smoothed_metal_mass_fraction[chemistry_element_count];
float Z;
}; };
#endif /* SWIFT_CHEMISTRY_STRUCT_GEAR_H */ #endif /* SWIFT_CHEMISTRY_STRUCT_GEAR_H */
...@@ -61,14 +61,16 @@ chemistry_get_element_name(enum chemistry_element elem) { ...@@ -61,14 +61,16 @@ chemistry_get_element_name(enum chemistry_element elem) {
*/ */
static INLINE void chemistry_init_backend( static INLINE void chemistry_init_backend(
const struct swift_params* parameter_file, const struct unit_system* us, const struct swift_params* parameter_file, const struct unit_system* us,
const struct phys_const* phys_const, struct chemistry_data* data) {} const struct phys_const* phys_const, struct chemistry_global_data* data) {}
/** /**
* @brief Prints the properties of the chemistry model to stdout. * @brief Prints the properties of the chemistry model to stdout.
* *
* @brief The #chemistry_data containing information about the current model. * @brief The #chemistry_global_data containing information about the current
* model.
*/ */
static INLINE void chemistry_print_backend(const struct chemistry_data* data) { static INLINE void chemistry_print_backend(
const struct chemistry_global_data* data) {
message("Chemistry function is 'No chemistry'."); message("Chemistry function is 'No chemistry'.");
} }
...@@ -81,7 +83,7 @@ static INLINE void chemistry_print_backend(const struct chemistry_data* data) { ...@@ -81,7 +83,7 @@ static INLINE void chemistry_print_backend(const struct chemistry_data* data) {
* @param cosmo The current cosmological model. * @param cosmo The current cosmological model.
*/ */
__attribute__((always_inline)) INLINE static void chemistry_end_density( __attribute__((always_inline)) INLINE static void chemistry_end_density(
struct part* restrict p, const struct chemistry_data* cd, struct part* restrict p, const struct chemistry_global_data* cd,
const struct cosmology* cosmo) {} const struct cosmology* cosmo) {}
/** /**
...@@ -90,13 +92,19 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density( ...@@ -90,13 +92,19 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density(
* *
* Nothing to do here. * Nothing to do here.
* *
* @param phys_const The physical constant in internal units.
* @param us The unit system.
* @param cosmo The current cosmological model.
* @param data The global chemistry information used for this run.
* @param p Pointer to the particle data. * @param p Pointer to the particle data.
* @param xp Pointer to the extended particle data. * @param xp Pointer to the extended particle data.
* @param data The global chemistry information used for this run.
*/ */
__attribute__((always_inline)) INLINE static void chemistry_first_init_part( __attribute__((always_inline)) INLINE static void chemistry_first_init_part(
const struct part* restrict p, struct xpart* restrict xp, const struct phys_const* restrict phys_const,
const struct chemistry_data* data) {} const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct chemistry_global_data* data, const struct part* restrict p,
struct xpart* restrict xp) {}
/** /**
* @brief Sets the chemistry properties of the (x-)particles to a valid start * @brief Sets the chemistry properties of the (x-)particles to a valid start
...@@ -108,6 +116,6 @@ __attribute__((always_inline)) INLINE static void chemistry_first_init_part( ...@@ -108,6 +116,6 @@ __attribute__((always_inline)) INLINE static void chemistry_first_init_part(
* @param data The global chemistry information. * @param data The global chemistry information.
*/