Commit 868f5f26 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Completely remove the source term task.

parent 92fe81e9
......@@ -110,7 +110,6 @@ const char *engine_policy_names[] = {"none",
"drift everything",
"reconstruct multi-poles",
"cooling",
"sourceterms",
"stars",
"structure finding",
"star formation",
......@@ -1923,9 +1922,6 @@ int engine_estimate_nr_tasks(struct engine *e) {
if (e->policy & engine_policy_star_formation) {
n1 += 1;
}
if (e->policy & engine_policy_sourceterms) {
n1 += 2;
}
if (e->policy & engine_policy_stars) {
/* 1 self, 1 sort, 26/2 pairs */
n1 += 15;
......@@ -2579,8 +2575,7 @@ void engine_skip_force_and_kick(struct engine *e) {
t->type == task_type_timestep || t->subtype == task_subtype_force ||
t->subtype == task_subtype_grav || t->type == task_type_end_force ||
t->type == task_type_grav_long_range || t->type == task_type_grav_mm ||
t->type == task_type_grav_down || t->type == task_type_cooling ||
t->type == task_type_sourceterms)
t->type == task_type_grav_down || t->type == task_type_cooling)
t->skip = 1;
}
......
......@@ -71,13 +71,12 @@ enum engine_policy {
engine_policy_drift_all = (1 << 11),
engine_policy_reconstruct_mpoles = (1 << 12),
engine_policy_cooling = (1 << 13),
engine_policy_sourceterms = (1 << 14),
engine_policy_stars = (1 << 15),
engine_policy_structure_finding = (1 << 16),
engine_policy_star_formation = (1 << 17),
engine_policy_feedback = (1 << 18)
engine_policy_stars = (1 << 14),
engine_policy_structure_finding = (1 << 15),
engine_policy_star_formation = (1 << 16),
engine_policy_feedback = (1 << 17)
};
#define engine_maxpolicy 19
#define engine_maxpolicy 18
extern const char *engine_policy_names[engine_maxpolicy + 1];
/**
......
......@@ -666,7 +666,6 @@ void engine_add_ghosts(struct engine *e, struct cell *c, struct task *ghost_in,
void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c) {
struct scheduler *s = &e->sched;
const int is_with_sourceterms = (e->policy & engine_policy_sourceterms);
/* Are we in a super-cell ? */
if (c->hydro.super == c) {
......@@ -696,12 +695,6 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c) {
c->hydro.extra_ghost = scheduler_addtask(
s, task_type_extra_ghost, task_subtype_none, 0, 0, c, NULL);
#endif
/* add source terms */
if (is_with_sourceterms) {
c->sourceterms = scheduler_addtask(s, task_type_sourceterms,
task_subtype_none, 0, 0, c, NULL);
}
}
} else { /* We are above the super-cell so need to go deeper */
......
......@@ -58,7 +58,6 @@
#include "runner_doiact_vec.h"
#include "scheduler.h"
#include "sort_part.h"
#include "sourceterms.h"
#include "space.h"
#include "space_getsid.h"
#include "stars.h"
......@@ -100,42 +99,6 @@
/* Import the stars loop functions. */
#include "runner_doiact_stars.h"
/**
* @brief Perform source terms
*
* @param r runner task
* @param c cell
* @param timer 1 if the time is to be recorded.
*/
void runner_do_sourceterms(struct runner *r, struct cell *c, int timer) {
const int count = c->hydro.count;
const double cell_min[3] = {c->loc[0], c->loc[1], c->loc[2]};
const double cell_width[3] = {c->width[0], c->width[1], c->width[2]};
struct sourceterms *sourceterms = r->e->sourceterms;
const int dimen = 3;
TIMER_TIC;
/* Recurse? */
if (c->split) {
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL) runner_do_sourceterms(r, c->progeny[k], 0);
} else {
if (count > 0) {
/* do sourceterms in this cell? */
const int incell =
sourceterms_test_cell(cell_min, cell_width, sourceterms, dimen);
if (incell == 1) {
sourceterms_apply(r, sourceterms, c);
}
}
}
if (timer) TIMER_TOC(timer_dosource);
}
/**
* @brief Intermediate task after the density to check that the smoothing
* lengths are correct.
......@@ -2945,9 +2908,6 @@ void *runner_main(void *data) {
case task_type_star_formation:
runner_do_star_formation(r, t->ci, 1);
break;
case task_type_sourceterms:
runner_do_sourceterms(r, t->ci, 1);
break;
default:
error("Unknown/invalid task type (%d).", t->type);
}
......
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2016 Tom Theuns (tom.theuns@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/>.
*
******************************************************************************/
/* Config parameters. */
#include "../config.h"
/* Local includes. */
#include "const.h"
#include "hydro.h"
#include "parser.h"
#include "units.h"
/* This object's header. */
#include "sourceterms.h"
/**
* @brief Initialises the sourceterms
*
* @param parameter_file The parsed parameter file
* @param us The current internal system of units
* @param source the structure that has all the source term properties
*/
void sourceterms_init(struct swift_params *parameter_file,
struct unit_system *us, struct sourceterms *source) {
#ifdef SOURCETERMS_SN_FEEDBACK
supernova_init(parameter_file, us, source);
#endif /* SOURCETERMS_SN_FEEDBACK */
};
/**
* @brief Prints the properties of the source terms to stdout
* @param source the structure that has all the source term properties
*/
void sourceterms_print(struct sourceterms *source) {
#ifdef SOURCETERMS_NONE
error(" no sourceterms defined yet you ran with -F");
#ifdef SOURCETERMS_SN_FEEDBACK
#error "can't have sourceterms when defined SOURCETERMS_NONE"
#endif
#endif
#ifdef SOURCETERMS_SN_FEEDBACK
supernova_print(source);
#endif /* SOURCETERMS_SN_FEEDBACK */
};
/**
* @brief Write a sourceterms struct to the given FILE as a stream of bytes.
*
* @param sourceterms the struct
* @param stream the file stream
*/
void sourceterms_struct_dump(const struct sourceterms *sourceterms,
FILE *stream) {
restart_write_blocks((void *)sourceterms, sizeof(struct sourceterms), 1,
stream, "sourceterms", "sourceterms");
}
/**
* @brief Restore a sourceterms struct from the given FILE as a stream of
* bytes.
*
* @param sourceterms the struct
* @param stream the file stream
*/
void sourceterms_struct_restore(const struct sourceterms *sourceterms,
FILE *stream) {
restart_read_blocks((void *)sourceterms, sizeof(struct sourceterms), 1,
stream, NULL, "sourceterms");
}
/*******************************************************************************
* This file is part of SWIFT.
* Coypright (c) 2015 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_SOURCETERMS_H
#define SWIFT_SOURCETERMS_H
/**
* @file src/sourceterms.h
* @brief Branches between the different sourceterms functions.
*/
#include "./const.h"
#include "runner.h"
#ifdef SOURCETERMS_SN_FEEDBACK
#include "sourceterms/sn_feedback/sn_feedback_struct.h"
#endif
/* So far only one model here */
struct sourceterms {
#ifdef SOURCETERMS_SN_FEEDBACK
struct supernova_struct supernova;
#endif
};
#ifdef SOURCETERMS_SN_FEEDBACK
#include "sourceterms/sn_feedback/sn_feedback.h"
#endif
void sourceterms_init(struct swift_params* parameter_file,
struct unit_system* us, struct sourceterms* source);
void sourceterms_print(struct sourceterms* source);
/* Dump/restore. */
void sourceterms_struct_dump(const struct sourceterms* source, FILE* stream);
void sourceterms_struct_restore(const struct sourceterms* source, FILE* stream);
/**
* @brief Routines related to source terms
* @param cell_min: corner of cell to test
* @param cell_width: width of cell to test
* @param sourceterms: properties of source terms to test
* @param dimen: dimensionality of the problem
*
* This routine tests whether a source term should be applied to this cell
* return: 1 if yes, return: 0 if no
*/
__attribute__((always_inline)) INLINE static int sourceterms_test_cell(
const double cell_min[], const double cell_width[],
struct sourceterms* sourceterms, const int dimen) {
#ifdef SOURCETERMS_SN_FEEDBACK
return supernova_feedback_test_cell(cell_min, cell_width, sourceterms, dimen);
#endif
return 0;
};
__attribute__((always_inline)) INLINE static void sourceterms_apply(
struct runner* r, struct sourceterms* sourceterms, struct cell* c) {
#ifdef SOURCETERMS_SN_FEEDBACK
supernova_feedback_apply(r, sourceterms, c);
#endif
};
#endif /* SWIFT_SOURCETERMS_H */
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2016 Tom Theuns (tom.theuns@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_SN_FEEDBACK_H
#define SWIFT_SN_FEEDBACK_H
#include <float.h>
/* Config parameters. */
#include "../config.h"
#include "engine.h"
#include "equation_of_state.h"
#include "hydro.h"
#include "runner.h"
#include "timestep.h"
/**
* @file src/sourceterms/sn_feedback.h
*
* @brief Routines related to sourceterms (supernova feedback): determine if
* feedback occurs in this cell
*
* @param cell_min: corner of cell to test
* @param cell_width: width of cell to test
* @param sourceterms: properties of source terms to test
* @param dimen: dimensionality of the problem
*
* This routine tests whether a source term should be applied to this cell
* return: 1 if yes, return: 0 if no
*/
__attribute__((always_inline)) INLINE static int supernova_feedback_test_cell(
const double cell_min[], const double cell_width[],
struct sourceterms* sourceterms, const int dimen) {
if (sourceterms->supernova.status == supernova_is_done) return 0;
const double location[3] = {sourceterms->supernova.x,
sourceterms->supernova.y,
sourceterms->supernova.z};
for (int i = 0; i < dimen; i++) {
if (cell_min[i] > location[i]) return 0;
if ((cell_min[i] + cell_width[i]) <= location[i]) return 0;
};
return 1;
};
/**
* @file src/sourceterms/sn_feedback.h
*
* @brief Routines related to source terms (supernova feedback): perform
* feedback in this cell
* @param r: the runner
* @param sourceterms the structure describing the source terms properties
* @param c the cell to apply feedback to
*
* This routine heats an individual particle (p), increasing its thermal energy
* per unit mass
* by supernova energy / particle mass.
*/
__attribute__((always_inline)) INLINE static void supernova_feedback_apply(
struct runner* restrict r, struct sourceterms* restrict sourceterms,
struct cell* restrict c) {
const int count = c->count;
struct part* restrict parts = c->parts;
struct xpart* restrict xparts = c->xparts;
const double timeBase = r->e->timeBase;
const int ti_current = r->e->ti_current;
/* inject SN energy into the particle with highest id in this cell if it is
* active */
int imax = 0;
struct part* restrict p_sn = NULL;
struct xpart* restrict xp_sn = NULL;
for (int i = 0; i < count; i++) {
/* Get a direct pointer on the part. */
struct part* restrict p = &parts[i];
if (p->id > imax) {
imax = p->id;
p_sn = p;
xp_sn = &xparts[i];
}
}
/* Is this part within the time step? */
if (p_sn->ti_begin == ti_current) {
/* Does this time step straddle the feedback injection time? */
const float t_begin = p_sn->ti_begin * timeBase;
const float t_end = p_sn->ti_end * timeBase;
if (t_begin <= sourceterms->supernova.time &&
t_end > sourceterms->supernova.time) {
/* store old time step */
const int dti_old = p_sn->ti_end - p_sn->ti_begin;
/* add supernova feedback */
const float u_old = hydro_get_internal_energy(p_sn, 0);
const float ent_old = hydro_get_entropy(p_sn, 0.0);
const float u_new =
u_old + sourceterms->supernova.energy / hydro_get_mass(p_sn);
hydro_set_internal_energy(p_sn, u_new);
const float u_set = hydro_get_internal_energy(p_sn, 0.0);
const float ent_set = hydro_get_entropy(p_sn, 0.0);
message(
" applied super nova, time = %e, location= %e %e %e velocity= %e %e "
"%e",
ti_current * timeBase, p_sn->x[0], p_sn->x[1], p_sn->x[2], p_sn->v[0],
p_sn->v[1], p_sn->v[2]);
message(
" injected SN energy in particle = %lld, increased energy from %e to "
"%e and is notw %e, entropy from %e to %e",
p_sn->id, u_old, u_new, u_set, ent_old, ent_set);
/* label supernova as done */
sourceterms->supernova.status = supernova_is_done;
/* update timestep if new time step shorter than old time step */
const int dti = get_part_timestep(p_sn, xp_sn, r->e);
if (dti < dti_old) {
p_sn->ti_end = p_sn->ti_begin + dti;
message(" changed timestep from %d to %d", dti_old, dti);
/* apply simple time-step limiter on all particles in same cell:
*/
int i_limit = 0;
for (int i = 0; i < count; i++) {
struct part* restrict p = &parts[i];
const int dti_old = p->ti_end - p->ti_begin;
if (dti_old > 2 * dti) {
i_limit++;
const int dti_new = 2 * dti;
p->ti_end = p->ti_begin + dti_new;
message(" old step = %d new step = %d", dti_old, dti_new);
} else
message(" old step = %d", dti_old);
}
message(" count= %d limited timestep of %d particles ", count, i_limit);
} /* end of limiter */
error("end");
}
}
};
/**
* @file src/sourceterms/sn_feedback.h
*
* @brief Routine to initialise supernova feedback
* @param parameterfile: the parse parmeter file
* @param us: the unit system in use
* @param sourceterms the structure describing the source terms properties
*
* This routine heats an individual particle (p), increasing its thermal energy
* per unit mass
* by supernova energy / particle mass.
*/
__attribute__((always_inline)) INLINE static void supernova_init(
struct swift_params* parameter_file, struct unit_system* us,
struct sourceterms* source) {
source->supernova.time = parser_get_param_double(parameter_file, "SN:time");
source->supernova.energy =
parser_get_param_double(parameter_file, "SN:energy");
source->supernova.x = parser_get_param_double(parameter_file, "SN:x");
source->supernova.y = parser_get_param_double(parameter_file, "SN:y");
source->supernova.z = parser_get_param_double(parameter_file, "SN:z");
source->supernova.status = supernova_is_not_done;
}
__attribute__((always_inline)) INLINE static void supernova_print(
struct sourceterms* source) {
message(
" Single SNe of energy= %e will explode at time= %e at location "
"(%e,%e,%e)",
source->supernova.energy, source->supernova.time, source->supernova.x,
source->supernova.y, source->supernova.z);
}
#endif /* SWIFT_SN_FEEDBACK_H */
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2016 Tom Theuns (tom.theuns@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/>.
*
******************************************************************************/
/**
* @file src/sourceterms/sn_feedback_struct.h
* @brief Routines related to source terms (feedback)
*
* enumeration type that sets if supernova explosion is done (is_done) or still
* needs doing (is_not_done)
*/
#ifndef SWIFT_SN_FEEDBACK_STRUCT_H
#define SWIFT_SN_FEEDBACK_STRUCT_H
enum supernova_status { supernova_is_done, supernova_is_not_done };
/**
* @file src/sourceterms/sn_feedback_struct.h
* @brief Routines related to source terms (feedback)
*
* The structure that describes the source term (supernova feedback)
* It specifies the time, energy and location of the desired supernova
* explosion, and a status (supernova_is_done/supernova_is_not_done)
* that records the status of the supernova
*/
struct supernova_struct {
double time;
double energy;
double x, y, z;
enum supernova_status status;
};
#endif /* SWIFT_SN_FEEDBACK_STRUCT_H */
/*******************************************************************************
* This file is part of SWIFT.
* Coypright (c) 2015 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_SOURCETERMS_STRUCT_H
#define SWIFT_SOURCETERMS_STRUCT_H
#include "./const.h"
#ifdef SOURCETERMS_SN_FEEDBACK
#include "sourceterms/sn_feedback/sn_feedback_struct.h"
#endif
#endif /* SWIFT_SOURCETERMS_STRUCT_H */
......@@ -75,7 +75,6 @@ const char *taskID_names[task_type_count] = {"none",
"grav_mesh",
"cooling",
"star_formation",
"sourceterms",
"logger",
"stars_ghost_in",
"stars_ghost",
......@@ -141,7 +140,6 @@ __attribute__((always_inline)) INLINE static enum task_actions task_acts_on(
case task_type_ghost:
case task_type_extra_ghost:
case task_type_cooling:
case task_type_sourceterms:
return task_action_part;
break;
......
......@@ -67,7 +67,6 @@ enum task_types {
task_type_grav_mesh,
task_type_cooling,
task_type_star_formation,
task_type_sourceterms,
task_type_logger,
task_type_stars_ghost_in,
task_type_stars_ghost,
......
......@@ -61,7 +61,6 @@ const char* timers_names[timer_count] = {
"dograv_mesh",
"dograv_top_level",
"dograv_long_range",
"dosource",
"dosub_self_density",
"dosub_self_gradient",
"dosub_self_force",
......
......@@ -62,7 +62,6 @@ enum {
timer_dograv_mesh,
timer_dograv_top_level,
timer_dograv_long_range,
timer_dosource,
timer_dosub_self_density,
timer_dosub_self_gradient,
timer_dosub_self_force,
......
......@@ -91,7 +91,6 @@ TASKTYPES = [
"grav_mesh",
"cooling",
"star_formation",
"sourceterms",
"logger",
"stars_ghost_in",
"stars_ghost",
......
......@@ -176,7 +176,6 @@ TASKTYPES = [
"grav_mesh",
"cooling",
"star_formation",
"sourceterms",
"logger",
"stars_ghost_in",