diff --git a/src/const.h b/src/const.h index b8b8434cc5e085e54b0d60be4b85530f0b077eb7..1082bccc0bd514316c1457d67ea3f1023943c9e5 100644 --- a/src/const.h +++ b/src/const.h @@ -95,8 +95,8 @@ //#define EXTERNAL_POTENTIAL_DISK_PATCH /* Cooling properties */ -//#define COOLING_NONE -#define COOLING_CONST_DU +#define COOLING_NONE +//#define COOLING_CONST_DU //#define COOLING_CONST_LAMBDA //#define COOLING_GRACKLE diff --git a/src/cooling/const_du/cooling.h b/src/cooling/const_du/cooling.h index f6fce4f1c1e223a43b37c163b2b4a8bf6f3ab5e8..8f005ee0bf3d866ed196bd7b6a1e1094c39f22ef 100644 --- a/src/cooling/const_du/cooling.h +++ b/src/cooling/const_du/cooling.h @@ -53,6 +53,7 @@ * @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 xp Pointer to the extended particle data. * @param dt The time-step of this particle. */ __attribute__((always_inline)) INLINE static void cooling_cool_part( @@ -103,7 +104,27 @@ __attribute__((always_inline)) INLINE static float 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 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. diff --git a/src/cooling/const_du/cooling_struct.h b/src/cooling/const_du/cooling_struct.h index f5d4f9775775821e85b57203783840bde73050c7..1355ae9fa4bc04f619e475fe6f9205f547bc76bc 100644 --- a/src/cooling/const_du/cooling_struct.h +++ b/src/cooling/const_du/cooling_struct.h @@ -51,6 +51,11 @@ struct cooling_function_data { * This is used to carry properties such as the total amount of * energy radiated away. */ -struct cooling_xpart_data {}; +struct cooling_xpart_data { + + /*! Amount of 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 19921537a794b1b97d3205dcb34ace7527a2bd9f..458babf540a40db1f42da4750e0bb4c9a6ed8ce2 100644 --- a/src/cooling/const_lambda/cooling.h +++ b/src/cooling/const_lambda/cooling.h @@ -138,6 +138,19 @@ __attribute__((always_inline)) INLINE static float cooling_timestep( return u / 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 Initialises the cooling properties. * diff --git a/src/cooling/const_lambda/cooling_struct.h b/src/cooling/const_lambda/cooling_struct.h index 97b6f27a768fb30900aeaa5a4e83294b87cd03d6..5792e6be32e83db8905604a38dc2a58bbaf6e58c 100644 --- a/src/cooling/const_lambda/cooling_struct.h +++ b/src/cooling/const_lambda/cooling_struct.h @@ -48,9 +48,14 @@ struct cooling_function_data { float cooling_tstep_mult; }; + /** - * @brief Properties of the cooling stored in the particle data + * @brief Properties of the cooling stored in the particle data. */ -struct cooling_xpart_data {}; +struct cooling_xpart_data { + + /*! Amount of 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 index 4fc9c6e1c54e7fd5e7ab08294197c090f994c409..172781f0668cf142cd4966c9f952dc7fabbe049e 100644 --- a/src/cooling/none/cooling.h +++ b/src/cooling/none/cooling.h @@ -71,6 +71,18 @@ __attribute__((always_inline)) INLINE static float cooling_timestep( 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 Initialises the cooling properties. * 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. */