diff --git a/AUTHORS b/AUTHORS index c822300c22885a05b42d58a51cc86af9da410429..6f283405b69a7d3a5397916f0a3afa7f4fb54a4a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,3 +10,4 @@ Tom Theuns tom.theuns@durham.ac.uk Richard G. Bower r.g.bower@durham.ac.uk Stefan Arridge stefan.arridge@durham.ac.uk Massimiliano Culpo massimiliano.culpo@googlemail.com +Yves Revaz yves.revaz@epfl.ch diff --git a/examples/main.c b/examples/main.c index 084a34723a7b1c3d6e075a67936c14b2380e69ad..895bb9003e04a4723b13ea1eaa360c5aa44e7228 100644 --- a/examples/main.c +++ b/examples/main.c @@ -439,9 +439,9 @@ int main(int argc, char *argv[]) { if (with_external_gravity && myrank == 0) potential_print(&potential); /* Initialise the cooling function properties */ - struct cooling_data cooling; - if (with_cooling) cooling_init(params, &us, &prog_const, &cooling); - if (with_cooling && myrank == 0) cooling_print(&cooling); + struct cooling_function_data cooling_func; + if (with_cooling) cooling_init(params, &us, &prog_const, &cooling_func); + if (with_cooling && myrank == 0) cooling_print(&cooling_func); /* Construct the engine policy */ int engine_policies = ENGINE_POLICY | engine_policy_steal; @@ -457,7 +457,7 @@ int main(int argc, char *argv[]) { struct engine e; engine_init(&e, &s, params, nr_nodes, myrank, nr_threads, with_aff, engine_policies, talking, &us, &prog_const, &hydro_properties, - &potential, &cooling); + &potential, &cooling_func); if (myrank == 0) { clocks_gettime(&toc); message("engine_init took %.3f %s.", clocks_diff(&tic, &toc), diff --git a/src/Makefile.am b/src/Makefile.am index 2343ab99ffd90a27e588344c1fae4f1491b4625e..095b11272dae027363628977c6b3098c3ab2a409 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 @@ -55,7 +55,7 @@ AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \ runner_doiact_fft.c threadpool.c cooling.c # Include files for distribution, not installation. -nobase_noinst_HEADERS = approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h \ +nobase_noinst_HEADERS = align.h approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h \ kernel_long_gravity.h vector.h runner_doiact.h runner_doiact_grav.h runner_doiact_fft.h \ units.h intrinsics.h minmax.h kick.h timestep.h drift.h adiabatic_index.h io_properties.h \ dimension.h equation_of_state.h \ @@ -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/align.h b/src/align.h new file mode 100644 index 0000000000000000000000000000000000000000..84e2909c0866c18f0f8378df9d0efc8d0f6545b5 --- /dev/null +++ b/src/align.h @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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_ALIGN_H +#define SWIFT_ALIGN_H + +/** + * @brief Defines alignment of structures + */ +#define SWIFT_STRUCT_ALIGN __attribute__((aligned(32))) + +#endif /* SWIFT_ALIGN_H */ diff --git a/src/cell.h b/src/cell.h index fd836206241c55cd6b9da2e29157c11a14c5a892..b78cc0a8f842770f60777e3986616a175d2f33ca 100644 --- a/src/cell.h +++ b/src/cell.h @@ -30,6 +30,7 @@ #include <stddef.h> /* Local includes. */ +#include "align.h" #include "lock.h" #include "multipole.h" #include "part.h" @@ -44,7 +45,7 @@ struct space; * The maximum was lowered by a further factor of 2 to be on the safe side.*/ #define cell_max_tag (1 << 29) -#define cell_align 32 +#define cell_align 128 /* Global variables. */ extern int cell_next_tag; @@ -74,7 +75,8 @@ struct pcell { /* Relative indices of the cell's progeny. */ int progeny[8]; -}; + +} SWIFT_STRUCT_ALIGN; /* Structure to store the data of a single cell. */ struct cell { @@ -182,7 +184,7 @@ struct cell { double mom[3], ang_mom[3]; /* Mass, potential, internal and kinetic energy of particles in this cell. */ - double mass, e_pot, e_int, e_kin, entropy; + double mass, e_pot, e_int, e_kin, e_rad, entropy; /* Number of particles updated in this cell. */ int updated, g_updated; @@ -208,7 +210,7 @@ struct cell { #endif -} __attribute__((aligned(cell_align))); +} SWIFT_STRUCT_ALIGN; /* Convert cell location to ID. */ #define cell_getid(cdim, i, j, k) \ diff --git a/src/const.h b/src/const.h index 552d49c8f1e4dd9f4fa2855e5fed548acd5c0b3f..1082bccc0bd514316c1457d67ea3f1023943c9e5 100644 --- a/src/const.h +++ b/src/const.h @@ -95,8 +95,9 @@ //#define EXTERNAL_POTENTIAL_DISK_PATCH /* Cooling properties */ +#define COOLING_NONE //#define COOLING_CONST_DU -#define COOLING_CONST_LAMBDA +//#define COOLING_CONST_LAMBDA //#define COOLING_GRACKLE /* Are we debugging ? */ diff --git a/src/cooling.c b/src/cooling.c index 102adba9d521dbe53caeff3c4409292bb64a29b2..e0208dbb591445d0877ef1e703d6e8cf349ddfd6 100644 --- a/src/cooling.c +++ b/src/cooling.c @@ -36,7 +36,7 @@ void cooling_init(const struct swift_params* parameter_file, const struct UnitSystem* us, const struct phys_const* phys_const, - struct cooling_data* cooling) { + struct cooling_function_data* cooling) { cooling_init_backend(parameter_file, us, phys_const, cooling); } @@ -48,7 +48,7 @@ void cooling_init(const struct swift_params* parameter_file, * * @param cooling The properties of the cooling function. */ -void cooling_print(const struct cooling_data* cooling) { +void cooling_print(const struct cooling_function_data* cooling) { cooling_print_backend(cooling); } diff --git a/src/cooling.h b/src/cooling.h index 034ee2329d91b17b875932bc4eb40d0d80a05111..1b326f6dc4fdf796dd1587e73e9b591f0f500ccb 100644 --- a/src/cooling.h +++ b/src/cooling.h @@ -31,7 +31,9 @@ #include "const.h" /* Import the right cooling definition */ -#if defined(COOLING_CONST_DU) +#if defined(COOLING_NONE) +#include "./cooling/none/cooling.h" +#elif defined(COOLING_CONST_DU) #include "./cooling/const_du/cooling.h" #elif defined(COOLING_CONST_LAMBDA) #include "./cooling/const_lambda/cooling.h" @@ -45,8 +47,8 @@ void cooling_init(const struct swift_params* parameter_file, const struct UnitSystem* us, const struct phys_const* phys_const, - struct cooling_data* cooling); + struct cooling_function_data* cooling); -void cooling_print(const struct cooling_data* cooling); +void cooling_print(const struct cooling_function_data* cooling); #endif /* SWIFT_COOLING_H */ diff --git a/src/cooling/const_du/cooling.h b/src/cooling/const_du/cooling.h index 072bd0f80cfba1f1e408988c0a7a23b37bafc190..e7f4f27db79712e6bff54559cf6781fb3aa4a438 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_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. * @@ -65,15 +51,16 @@ struct cooling_data { * * @param phys_const The physical constants in internal units. * @param us The internal system of units. - * @param cooling The #cooling_data used in the run. + * @param cooling The #cooling_function_data used in the run. * @param p Pointer to the particle data. + * @param xp Pointer to the extended particle data. * @param dt The time-step of this particle. */ __attribute__((always_inline)) INLINE static void cooling_cool_part( const struct phys_const* restrict phys_const, const struct UnitSystem* restrict us, - const struct cooling_data* restrict cooling, struct part* restrict p, - float dt) { + const struct cooling_function_data* restrict cooling, + struct part* restrict p, struct xpart* restrict xp, float dt) { /* Get current internal energy (dt=0) */ const float u_old = hydro_get_internal_energy(p, 0.f); @@ -92,6 +79,9 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part( /* Update the internal energy */ hydro_set_internal_energy(p, u_new); + + /* Store the radiated energy */ + xp->cooling_data.radiated_energy += hydro_get_mass(p) * (u_old - u_new); } /** @@ -101,13 +91,13 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part( * This is used to compute the time-step of the particle. Cooling functions * that are solved implicitly can simply return FLT_MAX here. * - * @param cooling The #cooling_data used in the run. + * @param cooling The #cooling_function_data used in the run. * @param phys_const The physical constants in internal units. * @param us The internal system of units. * @param p Pointer to the particle data. */ -__attribute__((always_inline)) INLINE static double cooling_timestep( - const struct cooling_data* restrict cooling, +__attribute__((always_inline)) INLINE static float cooling_timestep( + const struct cooling_function_data* restrict cooling, const struct phys_const* restrict phys_const, const struct UnitSystem* restrict us, const struct part* restrict p) { @@ -117,7 +107,41 @@ __attribute__((always_inline)) INLINE static double cooling_timestep( } /** - * @brief Initialises the cooling properties. + * @brief Sets the cooling properties of the (x-)particles to a valid start + * state. + * + * In this case, we set the total radiated energy to 0. Note that the particle + * structure is just passed in for cases where information needs to be read + * from there. + * + * @param p Pointer to the particle data. + * @param xp Pointer to the extended particle data. + */ +__attribute__((always_inline)) INLINE static void cooling_init_part( + const struct part* restrict p, struct xpart* restrict xp) { + + xp->cooling_data.radiated_energy = 0.f; +} + +/** + * @brief Returns the total radiated energy by this particle. + * + * In this simple example we jsut return the quantity accumulated in the + * #cooling_xpart_data of this particle. + * + * @param xp The extended particle data + */ +__attribute__((always_inline)) INLINE static float cooling_get_radiated_energy( + const struct xpart* restrict xp) { + + return xp->cooling_data.radiated_energy; +} + +/** + * @brief Initialises the cooling function properties from the parameter file + * + * In this example, we just read in the values from the YAML file without + * doing any conversions or multiplying any constants in. * * @param parameter_file The parsed parameter file. * @param us The current internal system of units. @@ -126,7 +150,8 @@ __attribute__((always_inline)) INLINE static double cooling_timestep( */ static INLINE void cooling_init_backend( const struct swift_params* parameter_file, const struct UnitSystem* us, - const struct phys_const* phys_const, struct cooling_data* cooling) { + const struct phys_const* phys_const, + struct cooling_function_data* cooling) { cooling->cooling_rate = parser_get_param_double(parameter_file, "ConstCooling:cooling_rate"); @@ -141,9 +166,10 @@ static INLINE void cooling_init_backend( * * @param cooling The properties of the cooling function. */ -static INLINE void cooling_print_backend(const struct cooling_data* cooling) { +static INLINE void cooling_print_backend( + const struct cooling_function_data* cooling) { - message("Cooling function is 'Constant cooling' with rate %f and floor %f", + message("Cooling function is 'Constant cooling' with rate %f and floor %f.", cooling->cooling_rate, cooling->min_energy); } diff --git a/src/cooling/const_du/cooling_struct.h b/src/cooling/const_du/cooling_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..cc00b001cf6b576266de02dac885f87d089bd8e4 --- /dev/null +++ b/src/cooling/const_du/cooling_struct.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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 { + + /*! Energy radiated away by this particle since the start of the run */ + float radiated_energy; +}; + +#endif /* SWIFT_COOLING_STRUCT_CONST_DU_H */ diff --git a/src/cooling/const_lambda/cooling.h b/src/cooling/const_lambda/cooling.h index 826f008914a7960bf81c36c2a377c5fb071d966e..0a5672a63ea1e6fe92da216349af25c50115dc2e 100644 --- a/src/cooling/const_lambda/cooling.h +++ b/src/cooling/const_lambda/cooling.h @@ -59,12 +59,12 @@ struct cooling_data { * * @param phys_const The physical constants in internal units. * @param us The internal system of units. - * @param cooling The #cooling_data used in the run. + * @param cooling The #cooling_function_data used in the run. * @param p Pointer to the particle data.. */ __attribute__((always_inline)) INLINE static float cooling_rate( const struct phys_const* const phys_const, const struct UnitSystem* us, - const struct cooling_data* cooling, const struct part* p) { + const struct cooling_function_data* cooling, const struct part* p) { /* Get particle density */ const float rho = p->rho; @@ -83,15 +83,15 @@ __attribute__((always_inline)) INLINE static float cooling_rate( * * @param phys_const The physical constants in internal units. * @param us The internal system of units. - * @param cooling The #cooling_data used in the run. + * @param cooling The #cooling_function_data used in the run. * @param p Pointer to the particle data. * @param dt The time-step of this particle. */ __attribute__((always_inline)) INLINE static void cooling_cool_part( const struct phys_const* restrict phys_const, const struct UnitSystem* restrict us, - const struct cooling_data* restrict cooling, struct part* restrict p, - float dt) { + const struct cooling_function_data* restrict cooling, + struct part* restrict p, struct xpart* restrict xp, float dt) { /* Get current internal energy (dt=0) */ const float u_old = hydro_get_internal_energy(p, 0.f); @@ -111,18 +111,21 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part( } /* Update the internal energy */ hydro_set_internal_energy(p, u_new); + + /* Store the radiated energy */ + xp->cooling_data.radiated_energy += hydro_get_mass(p) * (u_old - u_new); } /** * @brief Computes the time-step due to cooling * - * @param cooling The #cooling_data used in the run. + * @param cooling The #cooling_function_data used in the run. * @param phys_const The physical constants in internal units. * @param us The internal system of units. * @param p Pointer to the particle data. */ __attribute__((always_inline)) INLINE static float cooling_timestep( - const struct cooling_data* restrict cooling, + const struct cooling_function_data* restrict cooling, const struct phys_const* restrict phys_const, const struct UnitSystem* restrict us, const struct part* restrict p) { @@ -135,6 +138,30 @@ __attribute__((always_inline)) INLINE static float cooling_timestep( return u / abs(du_dt); } +/** + * @brief Sets the cooling 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. + */ +__attribute__((always_inline)) INLINE static void cooling_init_part( + const struct part* restrict p, struct xpart* restrict xp) { + + xp->cooling_data.radiated_energy = 0.f; +} + +/** + * @brief Returns the total radiated energy by this particle. + * + * @param xp The extended particle data + */ +__attribute__((always_inline)) INLINE static float cooling_get_radiated_energy( + const struct xpart* restrict xp) { + + return xp->cooling_data.radiated_energy; +} + /** * @brief Initialises the cooling properties. * @@ -145,7 +172,8 @@ __attribute__((always_inline)) INLINE static float cooling_timestep( */ static INLINE void cooling_init_backend( const struct swift_params* parameter_file, const struct UnitSystem* us, - const struct phys_const* phys_const, struct cooling_data* cooling) { + const struct phys_const* phys_const, + struct cooling_function_data* cooling) { const double lambda_cgs = parser_get_param_double(parameter_file, "LambdaCooling:lambda_cgs"); @@ -178,7 +206,8 @@ static INLINE void cooling_init_backend( * * @param cooling The properties of the cooling function. */ -static INLINE void cooling_print_backend(const struct cooling_data* cooling) { +static INLINE void cooling_print_backend( + const struct cooling_function_data* cooling) { message( "Cooling function is 'Constant lambda' with " diff --git a/src/cooling/const_lambda/cooling_struct.h b/src/cooling/const_lambda/cooling_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..27c5df16bffbe7d165237d201ca68ea4ba89dd73 --- /dev/null +++ b/src/cooling/const_lambda/cooling_struct.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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 { + + /*! Energy radiated away by this particle since the start of the run */ + float radiated_energy; +}; + +#endif /* SWIFT_COOLING_STRUCT_CONST_LAMBDA_H */ diff --git a/src/cooling/none/cooling.h b/src/cooling/none/cooling.h new file mode 100644 index 0000000000000000000000000000000000000000..0461100dc11e7ffbb4616766923142442b4ac943 --- /dev/null +++ b/src/cooling/none/cooling.h @@ -0,0 +1,125 @@ +/******************************************************************************* + * 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_NONE_H +#define SWIFT_COOLING_NONE_H + +/** + * @file src/cooling/none/cooling.h + * @brief Empty infrastructure for the cases without cooling 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 Apply the cooling function to a particle. + * + * We do nothing. + * + * @param phys_const The physical constants in internal units. + * @param us The internal system of units. + * @param cooling The #cooling_function_data used in the run. + * @param p Pointer to the particle data. + * @param dt The time-step of this particle. + */ +__attribute__((always_inline)) INLINE static void cooling_cool_part( + const struct phys_const* restrict phys_const, + const struct UnitSystem* restrict us, + const struct cooling_function_data* restrict cooling, + struct part* restrict p, struct xpart* restrict xp, float dt) {} + +/** + * @brief Computes the cooling time-step. + * + * We return FLT_MAX so as to impose no limit on the time-step. + * + * @param cooling The #cooling_function_data used in the run. + * @param phys_const The physical constants in internal units. + * @param us The internal system of units. + * @param p Pointer to the particle data. + */ +__attribute__((always_inline)) INLINE static float cooling_timestep( + const struct cooling_function_data* restrict cooling, + const struct phys_const* restrict phys_const, + const struct UnitSystem* restrict us, const struct part* restrict p) { + + return FLT_MAX; +} + +/** + * @brief Sets the cooling 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 cooling_init_part( + const struct part* restrict p, struct xpart* restrict xp) {} + +/** + * @brief Returns the total radiated energy by this particle. + * + * No cooling, so return 0. + * + * @param xp The extended particle data + */ +__attribute__((always_inline)) INLINE static float cooling_get_radiated_energy( + const struct xpart* restrict xp) { + + return 0.f; +} + +/** + * @brief Initialises the cooling 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 cooling The cooling properties to initialize + */ +static INLINE void cooling_init_backend( + const struct swift_params* parameter_file, const struct UnitSystem* us, + const struct phys_const* phys_const, + struct cooling_function_data* cooling) {} + +/** + * @brief Prints the properties of the cooling model to stdout. + * + * @param cooling The properties of the cooling function. + */ +static INLINE void cooling_print_backend( + const struct cooling_function_data* cooling) { + + message("Cooling function is 'No cooling'."); +} + +#endif /* SWIFT_COOLING_NONE_H */ 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.c b/src/engine.c index b9f903237a36286c976cad23c6ffd98e39c13d70..8217bd79778a16422e5eb570afa3fb0329f8de38 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2465,7 +2465,8 @@ void engine_print_stats(struct engine *e) { const ticks tic = getticks(); const struct space *s = e->s; - double e_kin = 0.0, e_int = 0.0, e_pot = 0.0, entropy = 0.0, mass = 0.0; + double e_kin = 0.0, e_int = 0.0, e_pot = 0.0, e_rad = 0.0; + double entropy = 0.0, mass = 0.0; double mom[3] = {0.0, 0.0, 0.0}, ang_mom[3] = {0.0, 0.0, 0.0}; /* Collect the cell data. */ @@ -2476,6 +2477,7 @@ void engine_print_stats(struct engine *e) { e_kin += c->e_kin; e_int += c->e_int; e_pot += c->e_pot; + e_rad += c->e_rad; entropy += c->entropy; mom[0] += c->mom[0]; mom[1] += c->mom[1]; @@ -2488,33 +2490,35 @@ void engine_print_stats(struct engine *e) { /* Aggregate the data from the different nodes. */ #ifdef WITH_MPI { - double in[11] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}; - double out[11]; + double in[12] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}; + double out[12]; out[0] = e_kin; out[1] = e_int; out[2] = e_pot; - out[3] = mom[0]; - out[4] = mom[1]; - out[5] = mom[2]; - out[6] = ang_mom[0]; - out[7] = ang_mom[1]; - out[8] = ang_mom[2]; - out[9] = mass; - out[10] = entropy; + out[3] = e_rad; + out[4] = mom[0]; + out[5] = mom[1]; + out[6] = mom[2]; + out[7] = ang_mom[0]; + out[8] = ang_mom[1]; + out[9] = ang_mom[2]; + out[10] = mass; + out[11] = entropy; if (MPI_Reduce(out, in, 11, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD) != MPI_SUCCESS) error("Failed to aggregate stats."); e_kin = out[0]; e_int = out[1]; e_pot = out[2]; - mom[0] = out[3]; - mom[1] = out[4]; - mom[2] = out[5]; - ang_mom[0] = out[6]; - ang_mom[1] = out[7]; - ang_mom[2] = out[8]; - mass = out[9]; - entropy = out[10]; + e_rad = out[3]; + mom[0] = out[4]; + mom[1] = out[5]; + mom[2] = out[6]; + ang_mom[0] = out[7]; + ang_mom[1] = out[8]; + ang_mom[2] = out[9]; + mass = out[10]; + entropy = out[11]; } #endif @@ -2522,11 +2526,11 @@ void engine_print_stats(struct engine *e) { /* Print info */ if (e->nodeID == 0) { - fprintf( - e->file_stats, - " %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e\n", - e->time, mass, e_tot, e_kin, e_int, e_pot, entropy, mom[0], mom[1], - mom[2], ang_mom[0], ang_mom[1], ang_mom[2]); + fprintf(e->file_stats, + " %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e " + "%14e\n", + e->time, mass, e_tot, e_kin, e_int, e_pot, e_rad, entropy, mom[0], + mom[1], mom[2], ang_mom[0], ang_mom[1], ang_mom[2]); fflush(e->file_stats); } @@ -3146,7 +3150,7 @@ void engine_unpin() { * @param physical_constants The #phys_const used for this run. * @param hydro The #hydro_props used for this run. * @param potential The properties of the external potential. - * @param cooling The properties of the cooling function. + * @param cooling_func The properties of the cooling function. */ void engine_init(struct engine *e, struct space *s, const struct swift_params *params, int nr_nodes, int nodeID, @@ -3155,7 +3159,7 @@ void engine_init(struct engine *e, struct space *s, const struct phys_const *physical_constants, const struct hydro_props *hydro, const struct external_potential *potential, - const struct cooling_data *cooling) { + const struct cooling_function_data *cooling_func) { /* Clean-up everything */ bzero(e, sizeof(struct engine)); @@ -3207,7 +3211,7 @@ void engine_init(struct engine *e, struct space *s, e->physical_constants = physical_constants; e->hydro_properties = hydro; e->external_potential = potential; - e->cooling_data = cooling; + e->cooling_func = cooling_func; e->parameter_file = params; engine_rank = nodeID; @@ -3358,11 +3362,11 @@ void engine_init(struct engine *e, struct space *s, engine_default_energy_file_name); sprintf(energyfileName + strlen(energyfileName), ".txt"); e->file_stats = fopen(energyfileName, "w"); - fprintf( - e->file_stats, - "#%14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s\n", - "Time", "Mass", "E_tot", "E_kin", "E_int", "E_pot", "Entropy", "p_x", - "p_y", "p_z", "ang_x", "ang_y", "ang_z"); + fprintf(e->file_stats, + "#%14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s " + "%14s\n", + "Time", "Mass", "E_tot", "E_kin", "E_int", "E_pot", "E_radcool", + "Entropy", "p_x", "p_y", "p_z", "ang_x", "ang_y", "ang_z"); fflush(e->file_stats); char timestepsfileName[200] = ""; diff --git a/src/engine.h b/src/engine.h index c35163a44e1c6fa4e399fb421bfbfd0224b9486c..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" @@ -205,7 +205,7 @@ struct engine { const struct external_potential *external_potential; /* Properties of the cooling scheme */ - const struct cooling_data *cooling_data; + const struct cooling_function_data *cooling_func; /* The (parsed) parameter file */ const struct swift_params *parameter_file; @@ -223,7 +223,7 @@ void engine_init(struct engine *e, struct space *s, const struct phys_const *physical_constants, const struct hydro_props *hydro, const struct external_potential *potential, - const struct cooling_data *cooling); + const struct cooling_function_data *cooling); void engine_launch(struct engine *e, int nr_runners, unsigned int mask, unsigned int submask); void engine_prepare(struct engine *e, int nodrift); diff --git a/src/gravity/Default/gravity_part.h b/src/gravity/Default/gravity_part.h index 1850ff0a1644d3593f78f150646eae8b2f074e1e..f06e65e5b30ebcd609c0c6204de33da17b770add 100644 --- a/src/gravity/Default/gravity_part.h +++ b/src/gravity/Default/gravity_part.h @@ -53,6 +53,6 @@ struct gpart { which this gpart is linked. */ long long id_or_neg_offset; -} __attribute__((aligned(gpart_align))); +} SWIFT_STRUCT_ALIGN; #endif /* SWIFT_DEFAULT_GRAVITY_PART_H */ diff --git a/src/hydro/Default/hydro_part.h b/src/hydro/Default/hydro_part.h index f42c3dc886ae1ab8f472ffdf5ff508f6735d1bb1..c7464bcf338b1c5b81ffa91d92264c2bd35e9313 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,12 +30,15 @@ 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. */ float omega; -} __attribute__((aligned(xpart_align))); +} SWIFT_STRUCT_ALIGN; /* Data of a single particle. */ struct part { @@ -120,6 +125,6 @@ struct part { /* Pointer to corresponding gravity part. */ struct gpart* gpart; -} __attribute__((aligned(part_align))); +} SWIFT_STRUCT_ALIGN; #endif /* SWIFT_DEFAULT_HYDRO_PART_H */ 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..0cdc1a8ab2b8d865f360dfba40486f3fb3056286 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,7 +30,10 @@ struct xpart { /* Velocity at the last full step. */ float v_full[3]; -} __attribute__((aligned(xpart_align))); + /* Additional data used to record cooling information */ + struct cooling_xpart_data cooling_data; + +} SWIFT_STRUCT_ALIGN; /* Data of a single particle. */ struct part { diff --git a/src/hydro/Gizmo/hydro_io.h b/src/hydro/Gizmo/hydro_io.h index e5f221ae4345dc519a50d332131ecf296f318338..5de2260bf3046e0d09bf94aa56c4fb772045dac7 100644 --- a/src/hydro/Gizmo/hydro_io.h +++ b/src/hydro/Gizmo/hydro_io.h @@ -124,8 +124,8 @@ void hydro_write_particles(struct part* parts, struct io_props* list, UNIT_CONV_ACCELERATION, parts, a_hydro); list[7] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, primitives.rho); - list[8] = io_make_output_field("Volume", FLOAT, 1, UNIT_CONV_VOLUME, parts, - geometry.volume); + list[8] = io_make_output_field("Volume", FLOAT, 1, UNIT_CONV_INV_VOLUME, + parts, geometry.volume); list[9] = io_make_output_field("GradDensity", FLOAT, 3, UNIT_CONV_DENSITY, parts, primitives.gradients.rho); list[10] = io_make_output_field_convert_part( diff --git a/src/hydro/Gizmo/hydro_part.h b/src/hydro/Gizmo/hydro_part.h index d425294671d4bc172f45c928c2290f8cfa8e093c..16159bc8b958feaebf5fb9d17fb73832057d4573 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,7 +30,10 @@ struct xpart { /* Velocity at the last full step. */ float v_full[3]; -} __attribute__((aligned(xpart_align))); + /* Additional data used to record cooling information */ + struct cooling_xpart_data cooling_data; + +} SWIFT_STRUCT_ALIGN; /* Data of a single particle. */ struct part { diff --git a/src/hydro/Minimal/hydro_part.h b/src/hydro/Minimal/hydro_part.h index ad65f8b44fc67f4aae6470246cbab91bc3710007..c83797b42b73f8cd8dd5bc993053769ba0cd354e 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,7 +49,10 @@ struct xpart { float v_full[3]; /*!< Velocity at the last full step. */ -} __attribute__((aligned(xpart_align))); + struct cooling_xpart_data + cooling_data; /*!< Additional data used to record cooling information */ + +} SWIFT_STRUCT_ALIGN; /** * @brief Particle fields for the SPH particles diff --git a/src/part.h b/src/part.h index ea895e6e0295d6a8b63309c7bd6855daa2cf7d64..af39d10fafc11d4435ddbcc087fbf08178b18959 100644 --- a/src/part.h +++ b/src/part.h @@ -31,12 +31,13 @@ #endif /* Local headers. */ +#include "align.h" #include "const.h" /* Some constants. */ -#define part_align 64 -#define xpart_align 32 -#define gpart_align 32 +#define part_align 128 +#define xpart_align 128 +#define gpart_align 128 /* Import the right hydro particle definition */ #if defined(MINIMAL_SPH) diff --git a/src/runner.c b/src/runner.c index 352a64664460343dd9004d60a9102b4875fce600..76dc9fd84db2dab9bc3562693be3cc1413a1f051 100644 --- a/src/runner.c +++ b/src/runner.c @@ -170,9 +170,10 @@ void runner_do_grav_external(struct runner *r, struct cell *c, int timer) { void runner_do_cooling(struct runner *r, struct cell *c, int timer) { struct part *restrict parts = c->parts; + struct xpart *restrict xparts = c->xparts; const int count = c->count; const int ti_current = r->e->ti_current; - const struct cooling_data *cooling = r->e->cooling_data; + const struct cooling_function_data *cooling_func = r->e->cooling_func; const struct phys_const *constants = r->e->physical_constants; const struct UnitSystem *us = r->e->internalUnits; const double timeBase = r->e->timeBase; @@ -195,13 +196,14 @@ void runner_do_cooling(struct runner *r, struct cell *c, int timer) { /* Get a direct pointer on the part. */ struct part *restrict p = &parts[i]; + struct xpart *restrict xp = &xparts[i]; /* Kick has already updated ti_end, so need to check ti_begin */ if (p->ti_begin == ti_current) { const double dt = (p->ti_end - p->ti_begin) * timeBase; - cooling_cool_part(constants, us, cooling, p, dt); + cooling_cool_part(constants, us, cooling_func, p, xp, dt); } } @@ -732,7 +734,8 @@ static void runner_do_drift(struct cell *c, struct engine *e) { const double dt = (ti_current - ti_old) * timeBase; float dx_max = 0.f, dx2_max = 0.f, h_max = 0.f; - double e_kin = 0.0, e_int = 0.0, e_pot = 0.0, entropy = 0.0, mass = 0.0; + double e_kin = 0.0, e_int = 0.0, e_pot = 0.0, e_rad = 0.0; + double entropy = 0.0, mass = 0.0; double mom[3] = {0.0, 0.0, 0.0}; double ang_mom[3] = {0.0, 0.0, 0.0}; @@ -804,6 +807,7 @@ static void runner_do_drift(struct cell *c, struct engine *e) { e_kin += 0.5 * m * (v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); e_pot += 0.; e_int += m * hydro_get_internal_energy(p, half_dt); + e_rad += cooling_get_radiated_energy(xp); /* Collect entropy */ entropy += m * hydro_get_entropy(p, half_dt); @@ -830,6 +834,7 @@ static void runner_do_drift(struct cell *c, struct engine *e) { e_kin += cp->e_kin; e_int += cp->e_int; e_pot += cp->e_pot; + e_rad += cp->e_rad; entropy += cp->entropy; mom[0] += cp->mom[0]; mom[1] += cp->mom[1]; @@ -847,6 +852,7 @@ static void runner_do_drift(struct cell *c, struct engine *e) { c->e_kin = e_kin; c->e_int = e_int; c->e_pot = e_pot; + c->e_rad = e_rad; c->entropy = entropy; c->mom[0] = mom[0]; c->mom[1] = mom[1]; diff --git a/src/space.c b/src/space.c index cdd5958cbc515003f4a86a41c9a7075fa3b4364f..a9958f6fbd7d85060db99a9682b0de10f507085d 100644 --- a/src/space.c +++ b/src/space.c @@ -42,6 +42,7 @@ /* Local headers. */ #include "atomic.h" #include "const.h" +#include "cooling.h" #include "engine.h" #include "error.h" #include "gravity.h" @@ -1471,6 +1472,23 @@ void space_init_parts(struct space *s) { } } +/** + * @brief Initialises all the extra particle data + * + * Calls cooling_init_xpart() on all the particles + */ +void space_init_xparts(struct space *s) { + + const size_t nr_parts = s->nr_parts; + struct part *restrict p = s->parts; + struct xpart *restrict xp = s->xparts; + + for (size_t i = 0; i < nr_parts; ++i) { + + cooling_init_part(&p[i], &xp[i]); + } +} + /** * @brief Initialises all the g-particles by setting them into a valid state * @@ -1630,6 +1648,7 @@ void space_init(struct space *s, const struct swift_params *params, /* Set the particles in a state where they are ready for a run */ space_init_parts(s); + space_init_xparts(s); space_init_gparts(s); /* Init the space lock. */ diff --git a/src/task.h b/src/task.h index f070451fe4e79e0c16dc3dcca1ce145c08841c47..4928dc00bcd7958efdd6987b5aec90ab4b3e92fa 100644 --- a/src/task.h +++ b/src/task.h @@ -26,6 +26,7 @@ #include "../config.h" /* Includes. */ +#include "align.h" #include "cell.h" #include "cycle.h" @@ -149,7 +150,7 @@ struct task { /*! Is this task implicit (i.e. does not do anything) ? */ char implicit; -} __attribute__((aligned(32))); +} SWIFT_STRUCT_ALIGN; /* Function prototypes. */ void task_unlock(struct task *t); diff --git a/src/timestep.h b/src/timestep.h index 6f6ef74f2bce60f32d643f26ebca377730385438..ca754a439a49db68e0f060c4b6e7e6988a5cd6cb 100644 --- a/src/timestep.h +++ b/src/timestep.h @@ -104,7 +104,7 @@ __attribute__((always_inline)) INLINE static int get_part_timestep( /* Compute the next timestep (cooling condition) */ float new_dt_cooling = FLT_MAX; if (e->policy & engine_policy_cooling) - new_dt_cooling = cooling_timestep(e->cooling_data, e->physical_constants, + new_dt_cooling = cooling_timestep(e->cooling_func, e->physical_constants, e->internalUnits, p); /* Compute the next timestep (gravity condition) */ diff --git a/src/units.h b/src/units.h index d6a9dee1e279fb72fa70e19d839f371fcef1006c..d9b88bfdf22818966b2419d2cae54b78705eb1cf 100644 --- a/src/units.h +++ b/src/units.h @@ -92,7 +92,8 @@ enum UnitConversionFactor { UNIT_CONV_MAGNETIC_FIELD, UNIT_CONV_MAGNETIC_INDUCTANCE, UNIT_CONV_TEMPERATURE, - UNIT_CONV_VOLUME + UNIT_CONV_VOLUME, + UNIT_CONV_INV_VOLUME }; void units_init_cgs(struct UnitSystem*); diff --git a/tests/test125cells.c b/tests/test125cells.c index a385a7c890fe27ed11d3c5d87d6903fa6d254516..e666658f43de135e3e72521b52f2a688c596a6f6 100644 --- a/tests/test125cells.c +++ b/tests/test125cells.c @@ -519,6 +519,7 @@ int main(int argc, char *argv[]) { hp.CFL_condition = 0.1; struct engine engine; + bzero(&engine, sizeof(struct engine)); engine.hydro_properties = &hp; engine.physical_constants = &prog_const; engine.s = &space; diff --git a/tests/testSPHStep.c b/tests/testSPHStep.c index fa49ed9d00c37393abd2f7e17ae628d79b4125f6..ff2ec841b27bd5ca6190517bc39f4da0c28fbc0c 100644 --- a/tests/testSPHStep.c +++ b/tests/testSPHStep.c @@ -102,10 +102,6 @@ int main() { int i, j, k, offset[3]; struct part *p; - struct hydro_props hp; - hp.target_neighbours = 48.; - hp.delta_neighbours = 1.; - hp.max_smoothing_iterations = 30; int N = 10; float dim = 1.; @@ -146,11 +142,24 @@ int main() { /* Create the infrastructure */ struct space space; space.periodic = 0; - space.h_max = 1.; + space.cell_min = 1.; + + struct phys_const prog_const; + prog_const.const_newton_G = 1.f; + + struct hydro_props hp; + hp.target_neighbours = 48.f; + hp.delta_neighbours = 2.; + hp.max_smoothing_iterations = 1; + hp.CFL_condition = 0.1; struct engine e; - e.s = &space; + bzero(&e, sizeof(struct engine)); e.hydro_properties = &hp; + e.physical_constants = &prog_const; + e.s = &space; + e.time = 0.1f; + e.ti_current = 1; struct runner r; r.e = &e;