diff --git a/src/Makefile.am b/src/Makefile.am index 2343ab99ffd90a27e588344c1fae4f1491b4625e..6b663b9d4e50a3580238311ca45b13402f3067f3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -43,7 +43,7 @@ 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 \ 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 potentials.h version.h \ - hydro_properties.h threadpool.h cooling.h + hydro_properties.h threadpool.h cooling.h cooling_struct.h # Common source files @@ -73,7 +73,9 @@ nobase_noinst_HEADERS = approx_math.h atomic.h cycle.h error.h inline.h kernel_h hydro/Gizmo/hydro_debug.h hydro/Gizmo/hydro_part.h \ riemann.h riemann/riemann_hllc.h riemann/riemann_trrs.h \ riemann/riemann_exact.h riemann/riemann_vacuum.h \ - cooling/const_du/cooling.h cooling/const_lambda/cooling.h + cooling/none/cooling.h cooling/none/cooling_struct.h \ + cooling/const_du/cooling.h cooling/const_du/cooling_struct.h \ + cooling/const_lambda/cooling.h cooling/const_lambda/cooling_struct.h # Sources and flags for regular library diff --git a/src/cooling/const_du/cooling.h b/src/cooling/const_du/cooling.h index feb680645125892f54aae0b40fde9524f5b9d649..2d3ff5bcc6528545e019d0215873c2e72eb0664b 100644 --- a/src/cooling/const_du/cooling.h +++ b/src/cooling/const_du/cooling.h @@ -35,6 +35,7 @@ /* Local includes. */ #include "const.h" +#include "cooling_struct.h" #include "error.h" #include "hydro.h" #include "parser.h" @@ -42,21 +43,6 @@ #include "physical_constants.h" #include "units.h" -/** - * @brief Properties of the cooling function. - */ -struct cooling_function_data { - - /*! Cooling rate in internal units. du_dt = -cooling_rate */ - float cooling_rate; - - /*! Minimally allowed internal energy of the particles */ - float min_energy; - - /*! Constant multiplication factor for time-step criterion */ - float cooling_tstep_mult; -}; - /** * @brief Apply the cooling function to a particle. * diff --git a/src/cooling/const_du/cooling_struct.h b/src/cooling/const_du/cooling_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..f5d4f9775775821e85b57203783840bde73050c7 --- /dev/null +++ b/src/cooling/const_du/cooling_struct.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk) + * Richard Bower (r.g.bower@durham.ac.uk) + * Stefan Arridge (stefan.arridge@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_COOLING_STRUCT_CONST_DU_H +#define SWIFT_COOLING_STRUCT_CONST_DU_H + +/** + * @file src/cooling/const_du/cooling_struct.h + * @brief Structure related to the "constant cooling" cooling function. + * + * This is the simplest possible cooling function. A constant cooling rate with + * a minimal energy floor is applied. Should be used as a template for more + * realistic functions. + */ + +/** + * @brief Properties of the cooling function. + */ +struct cooling_function_data { + + /*! Cooling rate in internal units. du_dt = -cooling_rate */ + float cooling_rate; + + /*! Minimally allowed internal energy of the particles */ + float min_energy; + + /*! Constant multiplication factor for time-step criterion */ + float cooling_tstep_mult; +}; + +/** + * @brief Properties of the cooling stored in the particle data. + * + * This is used to carry properties such as the total amount of + * energy radiated away. + */ +struct cooling_xpart_data {}; + +#endif /* SWIFT_COOLING_STRUCT_CONST_DU_H */ diff --git a/src/cooling/const_lambda/cooling.h b/src/cooling/const_lambda/cooling.h index b563c299992f4263e5e972e9efad42f62fcc53f5..9f149915d05aa952b8abe8fb29bf41fdf0315b90 100644 --- a/src/cooling/const_lambda/cooling.h +++ b/src/cooling/const_lambda/cooling.h @@ -35,29 +35,6 @@ #include "physical_constants.h" #include "units.h" -/* Cooling Properties */ -struct cooling_function_data { - - /*! Cooling rate in cgs units. Defined by 'rho * du/dt = -lambda * n_H^2'*/ - float lambda; - - /*! Minimum temperature (in Kelvin) for all gas particles*/ - float min_temperature; - - /*! Fraction of gas mass that is Hydrogen. Used to calculate n_H*/ - float hydrogen_mass_abundance; - - /* 'mu', used to convert min_temperature to min_internal energy*/ - float mean_molecular_weight; - - /*! Minimally allowed internal energy of the particles */ - float min_energy; - float min_energy_cgs; - - /*! Constant multiplication factor for time-step criterion */ - float cooling_tstep_mult; -}; - /** * @brief Calculates du/dt in code units for a particle. * diff --git a/src/cooling/const_lambda/cooling_struct.h b/src/cooling/const_lambda/cooling_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..97b6f27a768fb30900aeaa5a4e83294b87cd03d6 --- /dev/null +++ b/src/cooling/const_lambda/cooling_struct.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2016 Tom Theuns (tom.theuns@durham.ac.uk) + * Matthieu Schaller (matthieu.schaller@durham.ac.uk) + * Richard Bower (r.g.bower@durham.ac.uk) + * Stefan Arridge (stefan.arridge@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_COOLING_STRUCT_CONST_LAMBDA_H +#define SWIFT_COOLING_STRUCT_CONST_LAMBDA_H + +/** + * @brief Properties of the cooling function. + */ +struct cooling_function_data { + + /*! Cooling rate in cgs units. Defined by 'rho * du/dt = -lambda * n_H^2'*/ + float lambda; + + /*! Minimum temperature (in Kelvin) for all gas particles*/ + float min_temperature; + + /*! Fraction of gas mass that is Hydrogen. Used to calculate n_H*/ + float hydrogen_mass_abundance; + + /* 'mu', used to convert min_temperature to min_internal energy*/ + float mean_molecular_weight; + + /*! Minimally allowed internal energy of the particles */ + float min_energy; + float min_energy_cgs; + + /*! Constant multiplication factor for time-step criterion */ + float cooling_tstep_mult; +}; + +/** + * @brief Properties of the cooling stored in the particle data + */ +struct cooling_xpart_data {}; + +#endif /* SWIFT_COOLING_STRUCT_CONST_LAMBDA_H */ diff --git a/src/cooling/none/cooling.h b/src/cooling/none/cooling.h index 22252fc62e8eb892502f9fe5c004395e19557409..535fdd5b196a056ef99e4b06118e48f96a248831 100644 --- a/src/cooling/none/cooling.h +++ b/src/cooling/none/cooling.h @@ -36,11 +36,6 @@ #include "physical_constants.h" #include "units.h" -/** - * @brief Properties of the cooling function. - */ -struct cooling_function_data {}; - /** * @brief Apply the cooling function to a particle. * diff --git a/src/cooling/none/cooling_struct.h b/src/cooling/none/cooling_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..a08530c44d7405df934136f2861f84ba619d2595 --- /dev/null +++ b/src/cooling/none/cooling_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_COOLING_STRUCT_NONE_H +#define SWIFT_COOLING_STRUCT_NONE_H + +/** + * @file src/cooling/none/cooling_struct.h + * @brief Empty infrastructure for the cases without cooling function + */ + +/** + * @brief Properties of the cooling function. + */ +struct cooling_function_data {}; + +/** + * @brief Properties of the cooling stored in the particle data + */ +struct cooling_xpart_data {}; + +#endif /* SWIFT_COOLING_STRUCT_NONE_H */ diff --git a/src/cooling_struct.h b/src/cooling_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..0c567788423ae39507864de8b4a687eeed358cb6 --- /dev/null +++ b/src/cooling_struct.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_COOLING_STRUCT_H +#define SWIFT_COOLING_STRUCT_H + +/** + * @file src/cooling_struct.h + * @brief Branches between the different cooling functions. + */ + +/* Config parameters. */ +#include "../config.h" + +/* Local headers. */ +#include "const.h" + +/* Import the right cooling definition */ +#if defined(COOLING_NONE) +#include "./cooling/none/cooling_struct.h" +#elif defined(COOLING_CONST_DU) +#include "./cooling/const_du/cooling_struct.h" +#elif defined(COOLING_CONST_LAMBDA) +#include "./cooling/const_lambda/cooling_struct.h" +#elif defined(COOLING_GRACKLE) +#include "./cooling/grackle/cooling_struct.h" +#else +#error "Invalid choice of cooling function." +#endif + +#endif /* SWIFT_COOLING_STRUCT_H */ diff --git a/src/engine.h b/src/engine.h index 383b46950ae8f132b3aa37a6487b03bf99f4a74c..e043b7eb7611b90e3944582f62e7692bf10ac48d 100644 --- a/src/engine.h +++ b/src/engine.h @@ -38,7 +38,7 @@ /* Includes. */ #include "clocks.h" -#include "cooling.h" +#include "cooling_struct.h" #include "parser.h" #include "partition.h" #include "potentials.h" diff --git a/src/hydro/Default/hydro_part.h b/src/hydro/Default/hydro_part.h index f42c3dc886ae1ab8f472ffdf5ff508f6735d1bb1..1b9dd01b845c5e0e7c29381c5136ee8dded54479 100644 --- a/src/hydro/Default/hydro_part.h +++ b/src/hydro/Default/hydro_part.h @@ -19,6 +19,8 @@ #ifndef SWIFT_DEFAULT_HYDRO_PART_H #define SWIFT_DEFAULT_HYDRO_PART_H +#include "cooling_struct.h" + /* Extra particle data not needed during the SPH loops over neighbours. */ struct xpart { @@ -28,6 +30,9 @@ struct xpart { /* Velocity at the last full step. */ float v_full[3]; + /* Additional data used to record cooling information */ + struct cooling_xpart_data cooling_data; + float u_full; /* Old density. */ diff --git a/src/hydro/Gadget2/hydro_iact.h b/src/hydro/Gadget2/hydro_iact.h index 8a4edfe62f59a3fae551fdb65f46987509f89251..82e98e87d0a50ee4346d272c7fbd1ba3f4316fc7 100644 --- a/src/hydro/Gadget2/hydro_iact.h +++ b/src/hydro/Gadget2/hydro_iact.h @@ -26,13 +26,10 @@ * @brief SPH interaction functions following the Gadget-2 version of SPH. * * The interactions computed here are the ones presented in the Gadget-2 paper - *and use the same - * numerical coefficients as the Gadget-2 code. When used with the Spline-3 - *kernel, the results - * should be equivalent to the ones obtained with Gadget-2 up to the rounding - *errors and interactions - * missed by the Gadget-2 tree-code neighbours search. - * + * and use the same numerical coefficients as the Gadget-2 code. When used with + * the Spline-3 kernel, the results should be equivalent to the ones obtained + * with Gadget-2 up to the rounding errors and interactions missed by the + * Gadget-2 tree-code neighbours search. */ /** diff --git a/src/hydro/Gadget2/hydro_part.h b/src/hydro/Gadget2/hydro_part.h index 484792438d2717413c1ca8d4f429eac2e6d21b20..8ce279326e6aac7daace5006cffeca7735470395 100644 --- a/src/hydro/Gadget2/hydro_part.h +++ b/src/hydro/Gadget2/hydro_part.h @@ -19,6 +19,8 @@ #ifndef SWIFT_GADGET2_HYDRO_PART_H #define SWIFT_GADGET2_HYDRO_PART_H +#include "cooling_struct.h" + /* Extra particle data not needed during the SPH loops over neighbours. */ struct xpart { @@ -28,6 +30,9 @@ struct xpart { /* Velocity at the last full step. */ float v_full[3]; + /* Additional data used to record cooling information */ + struct cooling_xpart_data cooling_data; + } __attribute__((aligned(xpart_align))); /* Data of a single particle. */ diff --git a/src/hydro/Gizmo/hydro_part.h b/src/hydro/Gizmo/hydro_part.h index d425294671d4bc172f45c928c2290f8cfa8e093c..781f078aa13c8ab4b02cb9509afe11fd47ed9774 100644 --- a/src/hydro/Gizmo/hydro_part.h +++ b/src/hydro/Gizmo/hydro_part.h @@ -16,6 +16,10 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * ******************************************************************************/ +#ifndef SWIFT_GIZMO_HYDRO_PART_H +#define SWIFT_GIZMO_HYDRO_PART_H + +#include "cooling_struct.h" /* Extra particle data not needed during the computation. */ struct xpart { @@ -26,6 +30,9 @@ struct xpart { /* Velocity at the last full step. */ float v_full[3]; + /* Additional data used to record cooling information */ + struct cooling_xpart_data cooling_data; + } __attribute__((aligned(xpart_align))); /* Data of a single particle. */ @@ -197,3 +204,5 @@ struct part { struct gpart *gpart; } __attribute__((aligned(part_align))); + +#endif /* SWIFT_GIZMO_HYDRO_PART_H */ diff --git a/src/hydro/Minimal/hydro_part.h b/src/hydro/Minimal/hydro_part.h index ad65f8b44fc67f4aae6470246cbab91bc3710007..8b1b2f74203b32809ed3f4d2305ce660ab3dd0b5 100644 --- a/src/hydro/Minimal/hydro_part.h +++ b/src/hydro/Minimal/hydro_part.h @@ -33,6 +33,8 @@ * pp. 759-794. */ +#include "cooling_struct.h" + /** * @brief Particle fields not needed during the SPH loops over neighbours. * @@ -47,6 +49,9 @@ struct xpart { float v_full[3]; /*!< Velocity at the last full step. */ + struct cooling_xpart_data + cooling_data; /*!< Additional data used to record cooling information */ + } __attribute__((aligned(xpart_align))); /**