diff --git a/src/cooling.c b/src/cooling.c index d9349f16e07facb967925b625007bc9a10768b0a..c3e1a6625e7f451f38815cdf4669acdea75bd546 100644 --- a/src/cooling.c +++ b/src/cooling.c @@ -64,7 +64,7 @@ void cooling_print(const struct cooling_data* cooling) { void update_entropy(const struct cooling_data* cooling, const struct phys_const* const phys_const, struct part* p, - float dt){ + double dt){ /*updates the entropy of a particle after integrating the cooling equation*/ float u_old; @@ -80,7 +80,7 @@ void update_entropy(const struct cooling_data* cooling, } -float calculate_new_thermal_energy(float u_old, float dt, const struct cooling_data* cooling){ +float calculate_new_thermal_energy(float u_old, double dt, const struct cooling_data* cooling){ #ifdef CONST_COOLING //This function integrates the cooling equation, given the initial thermal energy and the timestep dt. //Returns 0 if successful and 1 if not diff --git a/src/cooling.h b/src/cooling.h index 59558856802e5150f786249376747102cf7dd805..b2be8ba066f1c203305d17ab28631a85f6249fa6 100644 --- a/src/cooling.h +++ b/src/cooling.h @@ -97,5 +97,5 @@ void cooling_print(const struct cooling_data* cooling); float calculate_new_thermal_energy(float u_old, float dt, const struct cooling_data* cooling); void update_entropy(const struct cooling_data* cooling, const struct phys_const* const phys_const, struct part* p, - float dt); + double dt); #endif /* SWIFT_COOLING_H */ diff --git a/src/runner.c b/src/runner.c index 6e99d8cece2cf086b1209ac2f8314301b9779e20..98491590b2d0804b68f2c48cec589149cf309506 100644 --- a/src/runner.c +++ b/src/runner.c @@ -135,6 +135,53 @@ void runner_do_grav_external(struct runner *r, struct cell *c, int timer) { if (timer) TIMER_TOC(timer_dograv_external); } + +/** + * @brief Calculate change in entropy from cooling + * + * @param r runner task + * @param c cell + * @param timer 1 if the time is to be recorded. + */ +void runner_do_cooling(struct runner *r, struct cell *c, int timer) { + + struct part *restrict parts = c->parts; + const int count = c->count; + const int ti_current = r->e->ti_current; + const struct cooling_data *cooling = r->e->cooling; + const struct phys_const *constants = r->e->physical_constants; + const double timeBase = r->e->timeBase; + double dt; + + TIMER_TIC; + + /* Recurse? */ + if (c->split) { + for (int k = 0; k < 8; k++) + if (c->progeny[k] != NULL) runner_do_cooling(r, c->progeny[k], 0); + return; + } + +#ifdef TASK_VERBOSE + OUT; +#endif + + /* Loop over the gparts in this cell. */ + for (int i = 0; i < count; i++) { + + /* Get a direct pointer on the part. */ + struct part *restrict p = &parts[i]; + + /* Is this part within the time step? */ + if (p->ti_end <= ti_current) { + dt = (p->ti_end - p->ti_begin)*timeBase; + update_entropy(cooling, constants, p, dt); + } + } + + if (timer) TIMER_TOC(timer_do_cooling); +} + /** * @brief Sort the entries in ascending order using QuickSort. * @@ -1158,6 +1205,9 @@ void *runner_main(void *data) { case task_type_grav_external: runner_do_grav_external(r, t->ci, 1); break; + case task_type_cooling: + runner_do_cooling(r, t->ci, 1); + break; case task_type_part_sort: space_do_parts_sort(); break;