diff --git a/examples/main.c b/examples/main.c index 30e27cc55a6ec508dc352f1acc7f2eed71d71bdd..2d3e2e28c8abd82c1ce0cb6181f1ae7a0fa318c1 100644 --- a/examples/main.c +++ b/examples/main.c @@ -143,6 +143,7 @@ int main(int argc, char *argv[]) { int nsteps = -2; int with_cosmology = 0; int with_external_gravity = 0; + int with_cooling = 0; int with_self_gravity = 0; int with_hydro = 0; int with_fp_exceptions = 0; @@ -160,6 +161,9 @@ int main(int argc, char *argv[]) { case 'c': with_cosmology = 1; break; + case 'C': + with_cooling = 1; + break; case 'd': dry_run = 1; break; @@ -335,6 +339,11 @@ int main(int argc, char *argv[]) { if (with_external_gravity) potential_init(params, &us, &potential); if (with_external_gravity && myrank == 0) potential_print(&potential); + /* Initialise the external potential properties */ + struct cooling_data cooling; + if (with_cooling) cooling_init(params, &us, &cooling); + if (with_cooling && myrank == 0) cooling_print(&cooling); + /* Read particles and space information from (GADGET) ICs */ char ICfileName[200] = ""; parser_get_param_string(params, "InitialConditions:file_name", ICfileName); @@ -441,6 +450,7 @@ int main(int argc, char *argv[]) { if (with_self_gravity) engine_policies |= engine_policy_self_gravity; if (with_external_gravity) engine_policies |= engine_policy_external_gravity; if (with_cosmology) engine_policies |= engine_policy_cosmology; + if (with_cooling) engine_policies |= engine_policy_cooling; /* Initialize the engine with the space and policies. */ if (myrank == 0) clocks_gettime(&tic); diff --git a/src/cell.h b/src/cell.h index 150718eeb4bd3857e37d517718fe53661033a330..61f0b0550a0d888aa5361d12c90fd59586841a03 100644 --- a/src/cell.h +++ b/src/cell.h @@ -136,6 +136,9 @@ struct cell { /* Task for external gravity */ struct task *grav_external; + /* Task for cooling */ + struct task *cooling_task; + /* Number of tasks that are associated with this cell. */ int nr_tasks; diff --git a/src/engine.c b/src/engine.c index ebd589bbb0af01cec3196c658c4d014daca8df38..fab9b4f0845df0d7e12f1efa8b06e576de39a176 100644 --- a/src/engine.c +++ b/src/engine.c @@ -68,7 +68,7 @@ #include "units.h" #include "version.h" -const char *engine_policy_names[13] = {"none", +const char *engine_policy_names[14] = {"none", "rand", "steal", "keep", @@ -80,7 +80,8 @@ const char *engine_policy_names[13] = {"none", "hydro", "self_gravity", "external_gravity", - "cosmology_integration"}; + "cosmology_integration", + "cooling"}; /** The rank of the engine as a global variable (for messages). */ int engine_rank; @@ -191,6 +192,9 @@ void engine_make_hydro_hierarchical_tasks(struct engine *e, struct cell *c, struct scheduler *s = &e->sched; const int is_fixdt = (e->policy & engine_policy_fixdt) == engine_policy_fixdt; + const int is_with_cooling = + (e->policy & engine_policy_cooling) == + engine_policy_cooling; /* Is this the super-cell? */ if (super == NULL && (c->density != NULL || (c->count > 0 && !c->split))) { @@ -225,6 +229,10 @@ void engine_make_hydro_hierarchical_tasks(struct engine *e, struct cell *c, /* Generate the ghost task. */ c->ghost = scheduler_addtask(s, task_type_ghost, task_subtype_none, 0, 0, c, NULL, 0); + + if (is_with_cooling) + c->cooling_task = scheduler_addtask( + s, task_type_cooling, task_subtype_none, 0, 0, c, NULL, 0); } } @@ -1611,6 +1619,12 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) { scheduler_addunlock(sched, t->ci->init, t); scheduler_addunlock(sched, t, t->ci->kick); } + + /* Cooling tasks should depend on kick and does not unlock anything since + it is the last task*/ + else if (t->type == task_type_cooling) { + scheduler_addunlock(sched, t->ci->kick, t); + } } } @@ -2612,6 +2626,11 @@ void engine_step(struct engine *e) { mask |= 1 << task_type_grav_external; } + /* Add the tasks corresponding to cooling to the masks */ + if (e->policy & engine_policy_cooling) { + mask |= 1 << task_type_cooling; + } + /* Add MPI tasks if need be */ if (e->policy & engine_policy_mpi) { @@ -2937,7 +2956,9 @@ void engine_init(struct engine *e, struct space *s, const struct UnitSystem *internal_units, const struct phys_const *physical_constants, const struct hydro_props *hydro, - const struct external_potential *potential) { + const struct external_potential *potential, + const struct cooling_data *cooling) { + /* Clean-up everything */ bzero(e, sizeof(struct engine)); @@ -2986,6 +3007,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->parameter_file = params; engine_rank = nodeID; diff --git a/src/engine.h b/src/engine.h index d708198c32b67c5118bbd7f4676f1ea0fe821c7d..fa304e97d83cb9edf1aea3522d635bcac1dee691 100644 --- a/src/engine.h +++ b/src/engine.h @@ -61,7 +61,8 @@ enum engine_policy { engine_policy_hydro = (1 << 8), engine_policy_self_gravity = (1 << 9), engine_policy_external_gravity = (1 << 10), - engine_policy_cosmology = (1 << 11) + engine_policy_cosmology = (1 << 11), + engine_policy_cooling = (1 << 12) }; extern const char *engine_policy_names[]; @@ -204,6 +205,9 @@ struct engine { /* Properties of external gravitational potential */ const struct external_potential *external_potential; + /* Properties of the cooling scheme */ + const struct cooling_data *cooling_data; + /* The (parsed) parameter file */ const struct swift_params *parameter_file; }; diff --git a/src/runner.h b/src/runner.h index 6838b959955c4e54e208b8d2d16339e7fdb1740f..c1bb57fa9a333abdd69d9ac18f6ce6f8672ff737 100644 --- a/src/runner.h +++ b/src/runner.h @@ -53,6 +53,7 @@ void runner_do_kick(struct runner *r, struct cell *c, int timer); void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer); void runner_do_drift(struct runner *r, struct cell *c, int timer); void runner_do_init(struct runner *r, struct cell *c, int timer); +void runner_do_cooling(struct runner *r, struct cell *c, int timer); void *runner_main(void *data); #endif /* SWIFT_RUNNER_H */ diff --git a/src/task.h b/src/task.h index ee49568b143282b9e3025f6d2bc81ded04ffee41..bc657cda0f160fd7e21909206324fa50212cf62d 100644 --- a/src/task.h +++ b/src/task.h @@ -51,6 +51,7 @@ enum task_types { task_type_grav_mm, task_type_grav_up, task_type_grav_external, + task_type_cooling, task_type_part_sort, task_type_gpart_sort, task_type_split_cell,