Skip to content
Snippets Groups Projects
Commit b4868c7e authored by lhausamm's avatar lhausamm
Browse files

Gear: Change chemistry_data -> chemistry_global_data + minor changes

parent 65e0568d
No related branches found
No related tags found
1 merge request!499Improved grackle
...@@ -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"
...@@ -62,14 +63,18 @@ chemistry_get_element_name(enum chemistry_element elem) { ...@@ -62,14 +63,18 @@ 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 */
chemistry_read_parameters(parameter_file, us, phys_const, 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 'Gear'."); message("Chemistry function is 'Gear'.");
} }
...@@ -81,10 +86,10 @@ static INLINE void chemistry_print_backend(const struct chemistry_data* data) { ...@@ -81,10 +86,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 +107,11 @@ __attribute__((always_inline)) INLINE static void chemistry_init_part( ...@@ -102,11 +107,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. */
...@@ -139,7 +144,7 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density( ...@@ -139,7 +144,7 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density(
*/ */
__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, struct part* restrict p, struct xpart* restrict xp,
const struct chemistry_data* data) { const struct chemistry_global_data* data) {
chemistry_init_part(p, data); chemistry_init_part(p, data);
} }
......
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
#include "chemistry.h" #include "chemistry.h"
#include "chemistry_struct.h" #include "chemistry_struct.h"
#include "io_properties.h" #include "io_properties.h"
#include "parser.h"
#include "part.h"
#include "physical_constants.h"
#include "units.h"
/** /**
* @brief Specifies which particle fields to read from a dataset * @brief Specifies which particle fields to read from a dataset
...@@ -31,15 +35,30 @@ ...@@ -31,15 +35,30 @@
* *
* @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);
} }
/** /**
* @brief Specifies which particle fields to write to a dataset * @brief Specifies which particle fields to write to a dataset
* *
...@@ -48,18 +67,21 @@ int chemistry_read_particles(struct part* parts, struct io_props* list) { ...@@ -48,18 +67,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 +90,8 @@ int chemistry_write_particles(const struct part* parts, struct io_props* list) { ...@@ -68,7 +90,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_grpsph) {
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;
...@@ -80,4 +103,5 @@ void chemistry_write_flavour(hid_t h_grp) { ...@@ -80,4 +103,5 @@ void chemistry_write_flavour(hid_t h_grp) {
} }
#endif #endif
#endif /* SWIFT_CHEMISTRY_IO_GEAR_H */ #endif /* SWIFT_CHEMISTRY_IO_GEAR_H */
...@@ -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 */
...@@ -810,7 +810,7 @@ __attribute__((always_inline)) INLINE static void cooling_init_backend( ...@@ -810,7 +810,7 @@ __attribute__((always_inline)) INLINE static void cooling_init_backend(
error("Grackle with multiple particles not implemented"); error("Grackle with multiple particles not implemented");
/* read parameters */ /* read parameters */
cooling_parse_arguments(parameter_file, cooling); cooling_read_parameters(parameter_file, cooling);
/* Set up the units system. */ /* Set up the units system. */
cooling_init_units(us, cooling); cooling_init_units(us, cooling);
......
...@@ -119,10 +119,11 @@ __attribute__((always_inline)) INLINE static int cooling_write_particles( ...@@ -119,10 +119,11 @@ __attribute__((always_inline)) INLINE static int cooling_write_particles(
/** /**
* @brief Parser the parameter file and initialize the #cooling_function_data * @brief Parser the parameter file and initialize the #cooling_function_data
*
* @param parameter_file The parser parameter file * @param parameter_file The parser parameter file
* @param cooling The cooling properties to initialize * @param cooling The cooling properties to initialize
*/ */
__attribute__((always_inline)) INLINE static void cooling_parse_arguments( __attribute__((always_inline)) INLINE static void cooling_read_parameters(
const struct swift_params* parameter_file, const struct swift_params* parameter_file,
struct cooling_function_data* cooling) { struct cooling_function_data* cooling) {
...@@ -146,7 +147,6 @@ __attribute__((always_inline)) INLINE static void cooling_parse_arguments( ...@@ -146,7 +147,6 @@ __attribute__((always_inline)) INLINE static void cooling_parse_arguments(
cooling->self_shielding_method = cooling->self_shielding_method =
parser_get_opt_param_int(parameter_file, "GrackleCooling:SelfShieldingMethod", 0); parser_get_opt_param_int(parameter_file, "GrackleCooling:SelfShieldingMethod", 0);
#if COOLING_GRACKLE_MODE > 0
cooling->output_mode = cooling->output_mode =
parser_get_opt_param_int(parameter_file, "GrackleCooling:OutputMode", 0); parser_get_opt_param_int(parameter_file, "GrackleCooling:OutputMode", 0);
...@@ -158,7 +158,6 @@ __attribute__((always_inline)) INLINE static void cooling_parse_arguments( ...@@ -158,7 +158,6 @@ __attribute__((always_inline)) INLINE static void cooling_parse_arguments(
cooling->omega = cooling->omega =
parser_get_opt_param_double(parameter_file, "GrackleCooling:Omega", 0.8); parser_get_opt_param_double(parameter_file, "GrackleCooling:Omega", 0.8);
#endif
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment