Skip to content
Snippets Groups Projects
Commit cb2debe8 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'chemistry' into 'master'

Add chemistry in part

See merge request !486
parents 832eabec adf069f1
Branches
Tags
1 merge request!486Add chemistry in part
Showing
with 973 additions and 7 deletions
......@@ -932,6 +932,29 @@ case "$with_cooling" in
;;
esac
# chemistry function
AC_ARG_WITH([chemistry],
[AS_HELP_STRING([--with-chemistry=<function>],
[chemistry function @<:@none, gear, EAGLE default: none@:>@]
)],
[with_chemistry="$withval"],
[with_chemistry="none"]
)
case "$with_chemistry" in
none)
AC_DEFINE([CHEMISTRY_NONE], [1], [No chemistry function])
;;
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])
;;
esac
# External potential
AC_ARG_WITH([ext-potential],
[AS_HELP_STRING([--with-ext-potential=<pot>],
......@@ -1031,6 +1054,7 @@ AC_MSG_RESULT([
Adiabatic index : $with_gamma
Riemann solver : $with_riemann
Cooling function : $with_cooling
Chemistry : $with_chemistry
External potential : $with_potential
Multipole order : $with_multipole_order
......
......@@ -765,7 +765,8 @@ INPUT += @top_srcdir@/src/gravity/Default
INPUT += @top_srcdir@/src/stars/Default
INPUT += @top_srcdir@/src/riemann
INPUT += @top_srcdir@/src/potential/point_mass
INPUT += @top_srcdir@/src/cooling/const_du
INPUT += @top_srcdir@/src/cooling/none
INPUT += @top_srcdir@/src/chemistry/none
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
......
......@@ -46,3 +46,17 @@ GrackleCooling:
UVbackground: 0 # Enable or not the UV background
GrackleRedshift: 0 # Redshift to use (-1 means time based redshift)
GrackleHSShieldingDensityThreshold: 1.1708e-26 # self shielding threshold in internal system of units
EAGLEChemistry:
InitMetallicity: 0.
InitAbundance_Hydrogen: 0.752
InitAbundance_Helium: 0.248
InitAbundance_Carbon: 0.000
InitAbundance_Nitrogen: 0.000
InitAbundance_Oxygen: 0.000
InitAbundance_Neon: 0.000
InitAbundance_Magnesium: 0.000
InitAbundance_Silicon: 0.000
InitAbundance_Iron: 0.000
CalciumOverSilicon: 0.0941736
SulphurOverSilicon: 0.6054160
......@@ -612,6 +612,11 @@ int main(int argc, char *argv[]) {
if (with_cooling) cooling_init(params, &us, &prog_const, &cooling_func);
if (with_cooling && myrank == 0) cooling_print(&cooling_func);
/* Initialise the chemistry */
struct chemistry_data chemistry;
chemistry_init(params, &us, &prog_const, &chemistry);
if (myrank == 0) chemistry_print(&chemistry);
/* Initialise the feedback properties */
struct sourceterms sourceterms;
if (with_sourceterms) sourceterms_init(params, &us, &sourceterms);
......@@ -636,7 +641,7 @@ int main(int argc, char *argv[]) {
engine_init(&e, &s, params, nr_nodes, myrank, nr_threads, N_total[0],
N_total[1], with_aff, engine_policies, talking, &reparttype, &us,
&prog_const, &hydro_properties, &gravity_properties, &potential,
&cooling_func, &sourceterms);
&cooling_func, &chemistry, &sourceterms);
if (myrank == 0) {
clocks_gettime(&toc);
message("engine_init took %.3f %s.", clocks_diff(&tic, &toc),
......
......@@ -151,3 +151,21 @@ GrackleCooling:
UVbackground: 1 # Enable or not the UV background
GrackleRedshift: 0 # Redshift to use (-1 means time based redshift)
GrackleHSShieldingDensityThreshold: 1.1708e-26 # self shielding threshold in internal system of units
# Parameters related to chemistry models -----------------------------------------------
# EAGLE model
EAGLEChemistry:
InitMetallicity: 0. # Inital fraction of particle mass in *all* metals
InitAbundance_Hydrogen: 0.752 # Inital fraction of particle mass in Hydrogen
InitAbundance_Helium: 0.248 # Inital fraction of particle mass in Helium
InitAbundance_Carbon: 0.000 # Inital fraction of particle mass in Carbon
InitAbundance_Nitrogen: 0.000 # Inital fraction of particle mass in Nitrogen
InitAbundance_Oxygen: 0.000 # Inital fraction of particle mass in Oxygen
InitAbundance_Neon: 0.000 # Inital fraction of particle mass in Neon
InitAbundance_Magnesium: 0.000 # Inital fraction of particle mass in Magnesium
InitAbundance_Silicon: 0.000 # Inital fraction of particle mass in Silicon
InitAbundance_Iron: 0.000 # Inital fraction of particle mass in Iron
CalciumOverSilicon: 0.0941736 # Constant ratio of Calcium over Silicon abundance
SulphurOverSilicon: 0.6054160 # Constant ratio of Sulphur over Silicon abundance
......@@ -46,7 +46,8 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \
hydro_properties.h riemann.h threadpool.h cooling.h cooling_struct.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 \
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
# Common source files
AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
......@@ -57,7 +58,8 @@ AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
runner_doiact_fft.c threadpool.c cooling.c sourceterms.c \
statistics.c runner_doiact_vec.c profiler.c dump.c logger.c \
part_type.c xmf.c gravity_properties.c gravity.c \
collectgroup.c hydro_space.c equation_of_state.c
collectgroup.c hydro_space.c equation_of_state.c \
chemistry.c
# Include files for distribution, not installation.
......@@ -117,7 +119,16 @@ nobase_noinst_HEADERS = align.h approx_math.h atomic.h barrier.h cycle.h error.h
cooling/const_du/cooling.h cooling/const_du/cooling_struct.h \
cooling/const_lambda/cooling.h cooling/const_lambda/cooling_struct.h \
cooling/grackle/cooling.h cooling/grackle/cooling_struct.h \
memswap.h dump.h logger.h
memswap.h dump.h logger.h \
chemistry/none/chemistry.h \
chemistry/none/chemistry_io.h \
chemistry/none/chemistry_struct.h \
chemistry/gear/chemistry.h \
chemistry/gear/chemistry_io.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
......
/*******************************************************************************
* 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/>.
*
******************************************************************************/
/* Config parameters. */
#include "../config.h"
/* This object's header. */
#include "chemistry.h"
/**
* @brief Initialises the chemistry properties.
*
* Calls chemistry_init_backend for the chosen chemistry function.
*
* @param parameter_file The parsed parameter file.
* @param us The current internal system of units.
* @param phys_const The physical constants in internal units.
* @param data The properties to initialise.
*/
void chemistry_init(const struct swift_params* parameter_file,
const struct unit_system* us,
const struct phys_const* phys_const,
struct chemistry_data* data) {
chemistry_init_backend(parameter_file, us, phys_const, data);
}
/**
* @brief Prints the properties of the chemistry model to stdout.
*
* Calls chemistry_print_backend for the chosen chemistry model.
*
* @brief The #chemistry_data containing information about the current model.
*/
void chemistry_print(const struct chemistry_data* data) {
chemistry_print_backend(data);
}
/*******************************************************************************
* 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_H
#define SWIFT_CHEMISTRY_H
/**
* @file src/chemistry.h
* @brief Branches between the different chemistry functions.
*/
/* Config parameters. */
#include "../config.h"
#include "chemistry_struct.h"
/* Import the right chemistry definition */
#if defined(CHEMISTRY_NONE)
#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
/* Common functions */
void chemistry_init(const struct swift_params* parameter_file,
const struct unit_system* us,
const struct phys_const* phys_const,
struct chemistry_data* data);
void chemistry_print(const struct chemistry_data* data);
#endif /* SWIFT_CHEMISTRY_H */
/*******************************************************************************
* 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 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] = {
"Hydrogen", "Helium", "Carbon", "Nitrogen", "Oxygen",
"Neon", "Magnesium", "Silicon", "Iron"};
return chemistry_element_names[elem];
}
/**
* @brief Sets the chemistry properties of the (x-)particles to a valid start
* state.
*
* @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 void chemistry_first_init_part(
struct part* restrict p, struct xpart* restrict xp,
const struct chemistry_data* data) {
p->chemistry_data.metal_mass_fraction_total =
data->initial_metal_mass_fraction_total;
for (int elem = 0; elem < chemistry_element_count; ++elem)
p->chemistry_data.metal_mass_fraction[elem] =
data->initial_metal_mass_fraction[elem];
}
/**
* @brief Initialises the chemistry properties.
*
* @param parameter_file The parsed parameter file.
* @param us The current internal system of units.
* @param phys_const The physical constants in internal units.
* @param data The properties to initialise.
*/
static INLINE void chemistry_init_backend(
const struct swift_params* parameter_file, const struct unit_system* us,
const struct phys_const* phys_const, struct chemistry_data* data) {
/* Read the total metallicity */
data->initial_metal_mass_fraction_total =
parser_get_param_float(parameter_file, "EAGLEChemistry:InitMetallicity");
/* Read the individual mass fractions */
for (int elem = 0; elem < chemistry_element_count; ++elem) {
char buffer[50];
sprintf(buffer, "EAGLEChemistry:InitAbundance_%s",
chemistry_get_element_name(elem));
data->initial_metal_mass_fraction[elem] =
parser_get_param_float(parameter_file, buffer);
}
/* Read the constant ratios */
data->calcium_over_silicon_ratio = parser_get_param_float(
parameter_file, "EAGLEChemistry:CalciumOverSilicon");
data->sulphur_over_silicon_ratio = parser_get_param_float(
parameter_file, "EAGLEChemistry:SulphurOverSilicon");
}
/**
* @brief Prints the properties of the chemistry model to stdout.
*
* @brief The #chemistry_data containing information about the current model.
*/
static INLINE void chemistry_print_backend(const struct chemistry_data* data) {
message("Chemistry model is 'EAGLE' tracking %d elements.",
chemistry_element_count);
}
#endif /* SWIFT_CHEMISTRY_EAGLE_H */
/*******************************************************************************
* 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 "chemistry.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,
chemistry_element_count, UNIT_CONV_NO_UNITS,
parts, chemistry_data.metal_mass_fraction);
list[1] = io_make_output_field(
"SmoothedElementAbundance", FLOAT, chemistry_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_grp) {
io_write_attribute_s(h_grp, "Chemistry Model", "EAGLE");
for (int elem = 0; elem < chemistry_element_count; ++elem) {
char buffer[20];
sprintf(buffer, "Element %d", elem);
io_write_attribute_s(h_grp, buffer, chemistry_get_element_name(elem));
}
}
#endif /* SWIFT_CHEMISTRY_IO_EAGLE_H */
/*******************************************************************************
* 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 chemistry_element {
chemistry_element_H = 0,
chemistry_element_He,
chemistry_element_C,
chemistry_element_N,
chemistry_element_O,
chemistry_element_Ne,
chemistry_element_Mg,
chemistry_element_Si,
chemistry_element_Fe,
chemistry_element_count
};
/**
* @brief Global chemical abundance information in the EAGLE model.
*/
struct chemistry_data {
/*! Fraction of the particle mass in given elements at the start of the run */
float initial_metal_mass_fraction[chemistry_element_count];
/*! Fraction of the particle mass in *all* metals at the start of the run */
float initial_metal_mass_fraction_total;
/*! Constant ratio of Calcium over Silicium */
float calcium_over_silicon_ratio;
/*! Constant ratio of Calcium over Silicium */
float sulphur_over_silicon_ratio;
};
/**
* @brief Chemical abundances traced by the #part in the EAGLE model.
*/
struct chemistry_part_data {
/*! Fraction of the particle mass in a given element */
float metal_mass_fraction[chemistry_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[chemistry_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 */
/*******************************************************************************
* 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_GEAR_H
#define SWIFT_CHEMISTRY_GEAR_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.
* @param data The global chemistry information.
*/
__attribute__((always_inline)) INLINE static void chemistry_first_init_part(
const struct part* restrict p, struct xpart* restrict xp,
const struct chemistry_data* data) {}
/**
* @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.
* @param data The properties to initialise.
*/
static INLINE void chemistry_init_backend(
const struct swift_params* parameter_file, const struct unit_system* us,
const struct phys_const* phys_const, struct chemistry_data* data) {}
/**
* @brief Prints the properties of the chemistry model to stdout.
*
* @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'.");
}
#endif /* SWIFT_CHEMISTRY_GEAR_H */
/*******************************************************************************
* 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_GEAR_H
#define SWIFT_CHEMISTRY_IO_GEAR_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) {
/* List what we want to read */
list[0] =
io_make_input_field("HeDensity", FLOAT, 1, COMPULSORY, UNIT_CONV_DENSITY,
parts, chemistry_data.he_density);
return 1;
}
/**
* @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("HeDensity", FLOAT, 1, UNIT_CONV_DENSITY,
parts, chemistry_data.he_density);
return 1;
}
/**
* @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", "GEAR");
}
#endif /* SWIFT_CHEMISTRY_IO_GEAR_H */
/*******************************************************************************
* 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_GEAR_H
#define SWIFT_CHEMISTRY_STRUCT_GEAR_H
/**
* @brief The individual elements traced in the model.
*/
enum chemistry_element { chemistry_element_count = 0 };
/**
* @brief Global chemical abundance information.
*/
struct chemistry_data {};
/**
* @brief Properties of the chemistry function.
*/
struct chemistry_part_data {
float he_density;
};
#endif /* SWIFT_CHEMISTRY_STRUCT_GEAR_H */
/*******************************************************************************
* 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_NONE_H
#define SWIFT_CHEMISTRY_NONE_H
/**
* @file src/chemistry/none/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.
* @param data The global chemistry information used for this run.
*/
__attribute__((always_inline)) INLINE static void chemistry_first_init_part(
const struct part* restrict p, struct xpart* restrict xp,
const struct chemistry_data* data) {}
/**
* @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.
* @param data The global chemistry information (to be filled).
*/
static INLINE void chemistry_init_backend(
const struct swift_params* parameter_file, const struct unit_system* us,
const struct phys_const* phys_const, struct chemistry_data* data) {}
/**
* @brief Prints the properties of the chemistry model to stdout.
*
* @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 'No chemistry'.");
}
#endif /* SWIFT_CHEMISTRY_NONE_H */
/*******************************************************************************
* 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_NONE_H
#define SWIFT_CHEMISTRY_IO_NONE_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 write.
*/
int chemistry_read_particles(struct part* parts, struct io_props* list) {
/* update list according to hydro_io */
/* Return the number of fields 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) {
/* update list according to hydro_io */
/* Return the number of fields to write */
return 0;
}
/**
* @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", "None");
}
#endif /* SWIFT_CHEMISTRY_IO_NONE_H */
/*******************************************************************************
* 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_NONE_H
#define SWIFT_CHEMISTRY_STRUCT_NONE_H
/**
* @file src/chemistry/none/chemistry_struct.h
* @brief Empty infrastructure for the cases without chemistry function
*/
/**
* @brief The individual elements traced in the model.
*/
enum chemistry_element { chemistry_element_count = 0 };
/**
* @brief Global chemical abundance information.
*
* Nothing here.
*/
struct chemistry_data {};
/**
* @brief Chemistry properties carried by the #part.
*
* Nothing here.
*/
struct chemistry_part_data {};
#endif /* SWIFT_CHEMISTRY_STRUCT_NONE_H */
/*******************************************************************************
* 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_H
#define SWIFT_CHEMISTRY_IO_H
/* Config parameters. */
#include "../config.h"
/* Import the right functions */
#if defined(CHEMISTRY_NONE)
#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
#endif /* SWIFT_CHEMISTRY_IO_H */
/*******************************************************************************
* 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_H
#define SWIFT_CHEMISTRY_STRUCT_H
/**
* @file src/chemistry_struct.h
* @brief Branches between the different chemistry functions.
*/
/* Config parameters. */
#include "../config.h"
/* Import the right chemistry definition */
#if defined(CHEMISTRY_NONE)
#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
#endif /* SWIFT_CHEMISTRY_STRUCT_H */
......@@ -38,11 +38,22 @@
#include "cooling_struct.h"
#include "error.h"
#include "hydro.h"
#include "io_properties.h"
#include "parser.h"
#include "part.h"
#include "physical_constants.h"
#include "units.h"
/**
* @brief Writes the current model of SPH to the file
* @param h_grpsph The HDF5 group in which to write
*/
__attribute__((always_inline)) INLINE static void cooling_write_flavour(
hid_t h_grpsph) {
io_write_attribute_s(h_grpsph, "Cooling Model", "Constant du/dt");
}
/**
* @brief Apply the cooling function to a particle.
*
......@@ -120,9 +131,11 @@ __attribute__((always_inline)) INLINE static float cooling_timestep(
*
* @param p Pointer to the particle data.
* @param xp Pointer to the extended particle data.
* @param cooling The properties of the cooling function.
*/
__attribute__((always_inline)) INLINE static void cooling_init_part(
const struct part* restrict p, struct xpart* restrict xp) {
__attribute__((always_inline)) INLINE static void cooling_first_init_part(
const struct part* restrict p, struct xpart* restrict xp,
const struct cooling_function_data* cooling) {
xp->cooling_data.radiated_energy = 0.f;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment