diff --git a/src/chemistry.c b/src/chemistry.c new file mode 100644 index 0000000000000000000000000000000000000000..4d2a5e7ba9565931ef371273baf1f6b7e3c5bc34 --- /dev/null +++ b/src/chemistry.c @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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 chemistry The chemistry properties to initialize + */ +void chemistry_init(const struct swift_params* parameter_file, + const struct unit_system* us, + const struct phys_const* phys_const, + struct chemistry_data* chemistry) { + + chemistry_init_backend(parameter_file, us, phys_const, chemistry); +} + +/** + * @brief Prints the properties of the chemistry model to stdout. + * + * Calls chemistry_print_backend for the chosen chemistry function. + * + * @param chemistry The properties of the chemistry function. + */ +void chemistry_print(const struct chemistry_data* chemistry) { + + chemistry_print_backend(chemistry); +} diff --git a/src/chemistry.h b/src/chemistry.h new file mode 100644 index 0000000000000000000000000000000000000000..25769240eb852e6b67a76ff3bc4e429305d09af6 --- /dev/null +++ b/src/chemistry.h @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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" +#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* chem); + +void chemistry_print(const struct chemistry_data* chem); + +#endif /* SWIFT_CHEMISTRY_H */ diff --git a/src/chemistry/none/chemistry.h b/src/chemistry/none/chemistry.h new file mode 100644 index 0000000000000000000000000000000000000000..6c17af00fd240d6d928168d0ab3a94882718bf17 --- /dev/null +++ b/src/chemistry/none/chemistry.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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 "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. + * @param chemistry The chemistry properties to initialize + */ +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* chemistry) {} + +/** + * @brief Prints the properties of the chemistry model to stdout. + * + * @param chemistry The properties of the chemistry function. + */ +static INLINE void chemistry_print_backend( + const struct chemistry_data* chemistry) { + + message("Chemistry function is 'No chemistry'."); +} + +#endif /* SWIFT_CHEMISTRY_NONE_H */ diff --git a/src/chemistry/none/chemistry_io.h b/src/chemistry/none/chemistry_io.h new file mode 100644 index 0000000000000000000000000000000000000000..979bd393855efa47ffcf236d668ddfe7136bf6f7 --- /dev/null +++ b/src/chemistry/none/chemistry_io.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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/>. + * + ******************************************************************************/ + +#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. + * @param num_fields The number of i/o fields to read. + */ +void chemistry_read_particles(struct part* parts, struct io_props* list, + int* num_fields) { + + /* update num_fields and list according to hydro_io */ +} + + +/** + * @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. + * @param num_fields The number of i/o fields to write. + */ +void chemistry_write_particles(const struct part* parts, struct io_props* list, + int* num_fields) { + + /* update num_fields and list according to hydro_io */ +} + + +/** + * @brief Writes the current model of SPH to the file + * @param h_grpsph The HDF5 group in which to write + */ +void writeChemistryFlavor(hid_t h_grpsph) { + + /* Viscosity and thermal conduction */ + io_write_attribute_s( + h_grpsph, "Chemistry Model", + "None"); +} diff --git a/src/chemistry/none/chemistry_struct.h b/src/chemistry/none/chemistry_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..01c39d9c1d321d0d68fcb5d499346c3202fc427e --- /dev/null +++ b/src/chemistry/none/chemistry_struct.h @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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 Properties of the chemistry function. + */ +struct chemistry_part_data {}; + +#endif /* SWIFT_CHEMISTRY_STRUCT_NONE_H */ diff --git a/src/chemistry_io.h b/src/chemistry_io.h new file mode 100644 index 0000000000000000000000000000000000000000..adcfb2b3ba53cbed4dd375b91fac484a49c4bfac --- /dev/null +++ b/src/chemistry_io.h @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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" +#else +#error "Invalid choice of chemistry function." +#endif + +#endif /* SWIFT_CHEMISTRY_IO_H */ diff --git a/src/chemistry_struct.h b/src/chemistry_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..25998f8a4dc3d0a8441d67e713b4c74e71b96c48 --- /dev/null +++ b/src/chemistry_struct.h @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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" +#else +#error "Invalid choice of chemistry function." +#endif + +#endif /* SWIFT_CHEMISTRY_STRUCT_H */ diff --git a/src/cooling/grackle/cooling.h b/src/cooling/grackle/cooling.h index f24105d70fbd681ea29e897bb74e43a09968ac28..94acc8641491f3d872384df7611ad3722e26900b 100644 --- a/src/cooling/grackle/cooling.h +++ b/src/cooling/grackle/cooling.h @@ -32,6 +32,7 @@ /* Local includes. */ #include "error.h" #include "hydro.h" +#include "io_properties.h" #include "parser.h" #include "part.h" #include "physical_constants.h" @@ -41,6 +42,18 @@ #define GRACKLE_NPART 1 #define GRACKLE_RANK 3 +/** + * @brief Writes the current model of SPH to the file + * @param h_grpsph The HDF5 group in which to write + */ +void writeCoolingFlavor(hid_t h_grpsph) { + + /* Viscosity and thermal conduction */ + io_write_attribute_s( + h_grpsph, "Chemistry Model", + "Grackle"); +} + /** * @brief Sets the cooling properties of the (x-)particles to a valid start * state. diff --git a/src/cooling/grackle/cooling_io.h b/src/cooling/grackle/cooling_io.h index 4f6e02f9b9220c51510418b969ac4315a925604d..2b9859d39ccb248bc790f7c6c9fadff508b83d3f 100644 --- a/src/cooling/grackle/cooling_io.h +++ b/src/cooling/grackle/cooling_io.h @@ -19,46 +19,6 @@ #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. - * @param num_fields The number of i/o fields to read. - */ -void cooling_read_particles(struct part* parts, struct io_props* list, - int* num_fields) { - - list += *num_fields; - *num_fields += 1; - - /* List what we want to read */ - list[0] = io_make_input_field("HeDensity", FLOAT, 1, COMPULSORY, - UNIT_CONV_DENSITY, parts, cooling_data.He_density); - -} - - -/** - * @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. - * @param num_fields The number of i/o fields to write. - */ -void cooling_write_particles(const struct part* parts, struct io_props* list, - int* num_fields) { - - int i = *num_fields; - /* List what we want to write */ - list[i] = io_make_output_field( - "HeDensity", FLOAT, 1, UNIT_CONV_DENSITY, parts, cooling_data.He_density); - i++; - - *num_fields = i; -} - - /** * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write diff --git a/src/cooling/grackle/cooling_struct.h b/src/cooling/grackle/cooling_struct.h index ec1bd6cb8f4f9025e25f1b59c78183921761f9ff..8895137eb9884c54fd982ee9a2b1d61db453a44d 100644 --- a/src/cooling/grackle/cooling_struct.h +++ b/src/cooling/grackle/cooling_struct.h @@ -62,13 +62,4 @@ struct cooling_xpart_data { float radiated_energy; }; -/** - * @brief Properties of the cooling stored in the particle data - */ -struct cooling_part_data { - - /*! Quick example */ - float He_density; -}; - #endif /* SWIFT_COOLING_STRUCT_NONE_H */ diff --git a/src/hydro/Gadget2/hydro_part.h b/src/hydro/Gadget2/hydro_part.h index 4bfdbcf7ff9f25d1448c8e44cf914f6b8a9da9e6..98ad9c86be620454a92a5bb01e1127385b561642 100644 --- a/src/hydro/Gadget2/hydro_part.h +++ b/src/hydro/Gadget2/hydro_part.h @@ -31,7 +31,7 @@ * Gadget-2 tree-code neighbours search. */ -#include "cooling_struct.h" +#include "chemistry_struct.h" /* Extra particle data not needed during the SPH loops over neighbours. */ struct xpart { @@ -133,7 +133,7 @@ struct part { /* Time-step length */ timebin_t time_bin; - struct cooling_part_data cooling_data; + struct chemistry_part_data chemistry_data; #ifdef SWIFT_DEBUG_CHECKS