diff --git a/configure.ac b/configure.ac index c2954cacd28499b80e9d003f32003885caf2dcaf..e7b7cb3c171946ac202a34e7625ffc8dab2fce7d 100644 --- a/configure.ac +++ b/configure.ac @@ -935,7 +935,7 @@ esac # chemistry function AC_ARG_WITH([chemistry], [AS_HELP_STRING([--with-chemistry=<function>], - [chemistry function @<:@none, gear default: none@:>@] + [chemistry function @<:@none, gear, EAGLE default: none@:>@] )], [with_chemistry="$withval"], [with_chemistry="none"] @@ -947,6 +947,9 @@ case "$with_chemistry" in gear) AC_DEFINE([CHEMISTRY_GEAR], [1], [Chemistry taken from the GEAR model]) ;; + EAGLE) + AC_DEFINE([CHEMISTRY_EAGLE], [1], [Chemistry taken from the EAGLE model]) + ;; *) AC_MSG_ERROR([Unknown chemistry function: $with_chemistry]) ;; diff --git a/src/Makefile.am b/src/Makefile.am index e191bb9008e5f4eb9b2aaec4876acc76cd00fd59..5107f35a17c26d21a3b875a09b2def292528fd12 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -125,7 +125,10 @@ nobase_noinst_HEADERS = align.h approx_math.h atomic.h barrier.h cycle.h error.h chemistry/none/chemistry_struct.h \ chemistry/gear/chemistry.h \ chemistry/gear/chemistry_io.h \ - chemistry/gear/chemistry_struct.h + chemistry/gear/chemistry_struct.h \ + chemistry/EAGLE/chemistry.h \ + chemistry/EAGLE/chemistry_io.h \ + chemistry/EAGLE/chemistry_struct.h # Sources and flags for regular library diff --git a/src/chemistry.h b/src/chemistry.h index c464106a7c09eb4dd13f57a0b17cb34131f99091..57c1fc877dcfc512d735d64bacfa88e8fd693d23 100644 --- a/src/chemistry.h +++ b/src/chemistry.h @@ -33,6 +33,8 @@ #include "./chemistry/none/chemistry.h" #elif defined(CHEMISTRY_GEAR) #include "./chemistry/gear/chemistry.h" +#elif defined(CHEMISTRY_EAGLE) +#include "./chemistry/EAGLE/chemistry.h" #else #error "Invalid choice of chemistry function." #endif diff --git a/src/chemistry/EAGLE/chemistry.h b/src/chemistry/EAGLE/chemistry.h new file mode 100644 index 0000000000000000000000000000000000000000..8553f5004150add2e99f8b735d2ef51dd69ffac7 --- /dev/null +++ b/src/chemistry/EAGLE/chemistry.h @@ -0,0 +1,73 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk) + * + * 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_CHEMISTRY_EAGLE_H +#define SWIFT_CHEMISTRY_EAGLE_H + +/** + * @file src/chemistry/gear/chemistry.h + * @brief Empty infrastructure for the cases without chemistry function + */ + +/* Some standard headers. */ +#include <float.h> +#include <math.h> + +/* Local includes. */ +#include "chemistry_struct.h" +#include "error.h" +#include "hydro.h" +#include "parser.h" +#include "part.h" +#include "physical_constants.h" +#include "units.h" + +/** + * @brief Sets the chemistry properties of the (x-)particles to a valid start + * state. + * + * Nothing to do here. + * + * @param p Pointer to the particle data. + * @param xp Pointer to the extended particle data. + */ +__attribute__((always_inline)) INLINE static void chemistry_init_part( + const struct part* restrict p, struct xpart* restrict xp) {} + +/** + * @brief Initialises the chemistry properties. + * + * Nothing to do here. + * + * @param parameter_file The parsed parameter file. + * @param us The current internal system of units. + * @param phys_const The physical constants in internal units. + */ +static INLINE void chemistry_init_backend( + const struct swift_params* parameter_file, const struct unit_system* us, + const struct phys_const* phys_const) {} + +/** + * @brief Prints the properties of the chemistry model to stdout. + */ +static INLINE void chemistry_print_backend() { + + message("Chemistry model is 'EAGLE'."); +} + +#endif /* SWIFT_CHEMISTRY_EAGLE_H */ diff --git a/src/chemistry/EAGLE/chemistry_io.h b/src/chemistry/EAGLE/chemistry_io.h new file mode 100644 index 0000000000000000000000000000000000000000..7d036414cfeecdf66ce74615833138603757ff81 --- /dev/null +++ b/src/chemistry/EAGLE/chemistry_io.h @@ -0,0 +1,106 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk) + * + * 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_CHEMISTRY_IO_EAGLE_H +#define SWIFT_CHEMISTRY_IO_EAGLE_H + +#include "io_properties.h" + +/** + * @brief Specifies which particle fields to read from a dataset + * + * @param parts The particle array. + * @param list The list of i/o properties to read. + * + * @return Returns the number of fields to read. + */ +int chemistry_read_particles(struct part* parts, struct io_props* list) { + + /* Nothing to read */ + return 0; +} + +/** + * @brief Specifies which particle fields to write to a dataset + * + * @param parts The particle array. + * @param list The list of i/o properties to write. + * + * @return Returns the number of fields to write. + */ +int chemistry_write_particles(const struct part* parts, struct io_props* list) { + + /* List what we want to write */ + list[0] = io_make_output_field("ElementAbundance", FLOAT, eagle_element_count, + UNIT_CONV_NO_UNITS, parts, + chemistry_data.metal_mass_fraction); + + list[1] = io_make_output_field("SmoothedElementAbundance", FLOAT, + eagle_element_count, UNIT_CONV_NO_UNITS, parts, + chemistry_data.smoothed_metal_mass_fraction); + + list[2] = + io_make_output_field("Metallicity", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, + chemistry_data.metal_mass_fraction_total); + + list[3] = io_make_output_field( + "SmoothedMetallicity", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, + chemistry_data.smoothed_metal_mass_fraction_total); + + list[4] = io_make_output_field("TotalMassFromSNIa", FLOAT, 1, UNIT_CONV_MASS, + parts, chemistry_data.mass_from_SNIa); + + list[5] = io_make_output_field("MetalMassFracFromSNIa", FLOAT, 1, + UNIT_CONV_NO_UNITS, parts, + chemistry_data.metal_mass_fraction_from_SNIa); + + list[6] = io_make_output_field("TotalMassFromAGB", FLOAT, 1, UNIT_CONV_MASS, + parts, chemistry_data.mass_from_AGB); + + list[7] = + io_make_output_field("MetalMassFracFromAGB", FLOAT, 1, UNIT_CONV_NO_UNITS, + parts, chemistry_data.metal_mass_fraction_from_AGB); + + list[8] = io_make_output_field("TotalMassFromSNII", FLOAT, 1, UNIT_CONV_MASS, + parts, chemistry_data.mass_from_SNII); + + list[9] = io_make_output_field("MetalMassFracFromSNII", FLOAT, 1, + UNIT_CONV_NO_UNITS, parts, + chemistry_data.metal_mass_fraction_from_SNII); + + list[10] = + io_make_output_field("IronMassFracFromSNIa", FLOAT, 1, UNIT_CONV_NO_UNITS, + parts, chemistry_data.iron_mass_fraction_from_SNIa); + + list[11] = io_make_output_field( + "SmoothedIronMassFracFromSNIa", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, + chemistry_data.smoothed_iron_mass_fraction_from_SNIa); + + return 12; +} + +/** + * @brief Writes the current model of SPH to the file + * @param h_grpsph The HDF5 group in which to write + */ +void chemistry_write_flavour(hid_t h_grpsph) { + + io_write_attribute_s(h_grpsph, "Chemistry Model", "EAGLE"); +} + +#endif /* SWIFT_CHEMISTRY_IO_EAGLE_H */ diff --git a/src/chemistry/EAGLE/chemistry_struct.h b/src/chemistry/EAGLE/chemistry_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..5138e6343b6b8331a31a4014ddad635c55a5bc36 --- /dev/null +++ b/src/chemistry/EAGLE/chemistry_struct.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk) + * + * 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_CHEMISTRY_STRUCT_EAGLE_H +#define SWIFT_CHEMISTRY_STRUCT_EAGLE_H + +/** + * @brief The individual elements traced in the EAGLE model. + */ +enum eagle_chemisty_element { + eagle_element_H = 0, + eagle_element_He, + eagle_element_C, + eagle_element_N, + eagle_element_O, + eagle_element_Ne, + eagle_element_Mg, + eagle_element_Si, + eagle_element_Fe, + eagle_element_count +}; + +/** + * @brief Chemical abundances traced in the EAGLE model. + */ +struct chemistry_part_data { + + /*! Fraction of the particle mass in a given element */ + float metal_mass_fraction[eagle_element_count]; + + /*! Fraction of the particle mass in *all* metals */ + float metal_mass_fraction_total; + + /*! Smoothed fraction of the particle mass in a given element */ + float smoothed_metal_mass_fraction[eagle_element_count]; + + /*! Smoothed fraction of the particle mass in *all* metals */ + float smoothed_metal_mass_fraction_total; + + /*! Mass coming from SNIa */ + float mass_from_SNIa; + + /*! Fraction of total gas mass in metals coming from SNIa */ + float metal_mass_fraction_from_SNIa; + + /*! Mass coming from AGB */ + float mass_from_AGB; + + /*! Fraction of total gas mass in metals coming from AGB */ + float metal_mass_fraction_from_AGB; + + /*! Mass coming from SNII */ + float mass_from_SNII; + + /*! Fraction of total gas mass in metals coming from SNII */ + float metal_mass_fraction_from_SNII; + + /*! Fraction of total gas mass in Iron coming from SNIa */ + float iron_mass_fraction_from_SNIa; + + /*! Smoothed fraction of total gas mass in Iron coming from SNIa */ + float smoothed_iron_mass_fraction_from_SNIa; +}; + +#endif /* SWIFT_CHEMISTRY_STRUCT_EAGLE_H */ diff --git a/src/chemistry_io.h b/src/chemistry_io.h index 8ba1c8f78de9adb87fc327c1ce04b13849755aa6..2a690b6a85ae4b0805a67b5bb7059303df4835c0 100644 --- a/src/chemistry_io.h +++ b/src/chemistry_io.h @@ -27,6 +27,8 @@ #include "./chemistry/none/chemistry_io.h" #elif defined(CHEMISTRY_GEAR) #include "./chemistry/gear/chemistry_io.h" +#elif defined(CHEMISTRY_EAGLE) +#include "./chemistry/EAGLE/chemistry_io.h" #else #error "Invalid choice of chemistry function." #endif diff --git a/src/chemistry_struct.h b/src/chemistry_struct.h index 5bb228dac084ab080ba720fd64283e147c7e1fff..aa8cfb369679583639cbd381d725a40ff2b62d4b 100644 --- a/src/chemistry_struct.h +++ b/src/chemistry_struct.h @@ -32,6 +32,8 @@ #include "./chemistry/none/chemistry_struct.h" #elif defined(CHEMISTRY_GEAR) #include "./chemistry/gear/chemistry_struct.h" +#elif defined(CHEMISTRY_EAGLE) +#include "./chemistry/EAGLE/chemistry_struct.h" #else #error "Invalid choice of chemistry function." #endif