MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Enumerations | Functions
winds.h File Reference
#include "forcetree.h"
#include "utils/paramset.h"
Include dependency graph for winds.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  WindModel {
  WIND_SUBGRID = 1 , WIND_DECOUPLE_SPH = 2 , WIND_USE_HALO = 4 , WIND_FIXED_EFFICIENCY = 8 ,
  WIND_ISOTROPIC = 512
}
 

Functions

void set_winds_params (ParameterSet *ps)
 
void init_winds (double FactorSN, double EgySpecSN, double PhysDensThresh, double UnitTime_in_s)
 
void winds_evolve (int i, double a3inv, double hubble)
 
void winds_and_feedback (int *NewStars, int NumNewStars, const double Time, const double hubble, ForceTree *tree)
 
int winds_make_after_sf (int i, double sm, double vdisp, double atime)
 
void winds_subgrid (int *MaybeWind, int NumMaybeWind, const double Time, const double hubble, ForceTree *tree, MyFloat *StellarMasses)
 
int winds_are_subgrid (void)
 
int winds_is_particle_decoupled (int i)
 
void winds_decoupled_hydro (int i, double atime)
 
int winds_ever_decouple (void)
 

Enumeration Type Documentation

◆ WindModel

enum WindModel
Enumerator
WIND_SUBGRID 
WIND_DECOUPLE_SPH 
WIND_USE_HALO 
WIND_FIXED_EFFICIENCY 
WIND_ISOTROPIC 

Definition at line 12 of file winds.h.

12  {
13  WIND_SUBGRID = 1,/* If this is true, winds are spawned from the star forming gas.
14  * If false, they are spawned from neighbours of the star particle.*/
15  WIND_DECOUPLE_SPH = 2,/* Specifies that wind particles are created temporarily decoupled from the gas dynamics */
16  WIND_USE_HALO = 4,/* Wind speeds depend on the halo circular velocity*/
17  WIND_FIXED_EFFICIENCY = 8, /* Winds have a fixed efficiency and thus fixed wind speed*/
18  WIND_ISOTROPIC = 512, /* Has no effect: only isotropic winds are implemented*/
19 };
@ WIND_ISOTROPIC
Definition: winds.h:18
@ WIND_FIXED_EFFICIENCY
Definition: winds.h:17
@ WIND_USE_HALO
Definition: winds.h:16
@ WIND_DECOUPLE_SPH
Definition: winds.h:15
@ WIND_SUBGRID
Definition: winds.h:13

Function Documentation

◆ init_winds()

void init_winds ( double  FactorSN,
double  EgySpecSN,
double  PhysDensThresh,
double  UnitTime_in_s 
)

Definition at line 97 of file winds.c.

98 {
99  wind_params.WindSpeed = sqrt(2 * wind_params.WindEnergyFraction * FactorSN * EgySpecSN / (1 - FactorSN));
100  /* Convert wind free travel time from Myr to internal units*/
105  message(0, "Windspeed: %g MaxDelay %g\n", wind_params.WindSpeed, wind_params.MaxWindFreeTravelTime);
106  } else if(HAS(wind_params.WindModel, WIND_USE_HALO)) {
107  message(0, "Reference Windspeed: %g, MaxDelay %g\n", wind_params.WindSigma0 * wind_params.WindSpeedFactor, wind_params.MaxWindFreeTravelTime);
108  } else {
109  /* Check for undefined wind models*/
110  endrun(1, "WindModel = 0x%X is strange. This shall not happen.\n", wind_params.WindModel);
111  }
112 }
void message(int where, const char *fmt,...)
Definition: endrun.c:175
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
#define SEC_PER_MEGAYEAR
Definition: physconst.h:31
double WindFreeTravelDensThresh
Definition: winds.c:22
double WindEnergyFraction
Definition: winds.c:28
double WindEfficiency
Definition: winds.c:26
double WindSpeedFactor
Definition: winds.c:31
enum WindModel WindModel
Definition: winds.c:18
double WindSpeed
Definition: winds.c:27
double WindSigma0
Definition: winds.c:30
double WindFreeTravelDensFac
Definition: winds.c:20
double MaxWindFreeTravelTime
Definition: winds.c:24
#define HAS(val, flag)
Definition: types.h:22
static struct WindParams wind_params

References endrun(), HAS, WindParams::MaxWindFreeTravelTime, message(), SEC_PER_MEGAYEAR, WIND_FIXED_EFFICIENCY, wind_params, WIND_USE_HALO, WindParams::WindEfficiency, WindParams::WindEnergyFraction, WindParams::WindFreeTravelDensFac, WindParams::WindFreeTravelDensThresh, WindParams::WindModel, WindParams::WindSigma0, WindParams::WindSpeed, and WindParams::WindSpeedFactor.

Referenced by init_cooling_and_star_formation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_winds_params()

void set_winds_params ( ParameterSet ps)

Definition at line 72 of file winds.c.

73 {
74  int ThisTask;
75  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
76  if(ThisTask == 0) {
77  /*Wind model parameters*/
78  wind_params.WindModel = (enum WindModel) param_get_enum(ps, "WindModel");
79  /* The following two are for VS08 and SH03*/
80  wind_params.WindEfficiency = param_get_double(ps, "WindEfficiency");
81  wind_params.WindEnergyFraction = param_get_double(ps, "WindEnergyFraction");
82 
83  /* The following two are for OFJT10*/
84  wind_params.WindSigma0 = param_get_double(ps, "WindSigma0");
85  wind_params.WindSpeedFactor = param_get_double(ps, "WindSpeedFactor");
86 
87  wind_params.WindThermalFactor = param_get_double(ps, "WindThermalFactor");
88  wind_params.MinWindVelocity = param_get_double(ps, "MinWindVelocity");
89  wind_params.MaxWindFreeTravelTime = param_get_double(ps, "MaxWindFreeTravelTime");
90  wind_params.WindFreeTravelLength = param_get_double(ps, "WindFreeTravelLength");
91  wind_params.WindFreeTravelDensFac = param_get_double(ps, "WindFreeTravelDensFac");
92  }
93  MPI_Bcast(&wind_params, sizeof(struct WindParams), MPI_BYTE, 0, MPI_COMM_WORLD);
94 }
double param_get_double(ParameterSet *ps, const char *name)
Definition: paramset.c:336
int param_get_enum(ParameterSet *ps, const char *name)
Definition: paramset.c:378
double WindThermalFactor
Definition: winds.c:35
double WindFreeTravelLength
Definition: winds.c:19
double MinWindVelocity
Definition: winds.c:33
int ThisTask
Definition: test_exchange.c:23
WindModel
Definition: winds.h:12

References WindParams::MaxWindFreeTravelTime, WindParams::MinWindVelocity, param_get_double(), param_get_enum(), ThisTask, wind_params, WindParams::WindEfficiency, WindParams::WindEnergyFraction, WindParams::WindFreeTravelDensFac, WindParams::WindFreeTravelLength, WindParams::WindModel, WindParams::WindSigma0, WindParams::WindSpeedFactor, and WindParams::WindThermalFactor.

Referenced by read_parameter_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winds_and_feedback()

void winds_and_feedback ( int *  NewStars,
int  NumNewStars,
const double  Time,
const double  hubble,
ForceTree tree 
)

Definition at line 333 of file winds.c.

334 {
335  /*The subgrid model does nothing here*/
337  return;
338 
339  if(!MPIU_Any(NumNewStars > 0, MPI_COMM_WORLD))
340  return;
341 
342  TreeWalk tw[1] = {{0}};
343  struct WindPriv priv[1];
344  int i;
345  winds_find_weights(tw, priv, NewStars, NumNewStars, Time, hubble, tree);
346 
347  for (i = 1; i < omp_get_max_threads(); i++)
348  priv->nvisited[0] += priv->nvisited[i];
349  priv->maxkicks = priv->nvisited[0]+2;
350 
351  /* Some particles may be kicked by multiple stars on the same timestep.
352  * To ensure this happens only once and does not depend on the order in
353  * which the loops are executed, particles are kicked by the nearest new star.
354  * This struct stores all such possible kicks, and we sort it out after the treewalk.*/
355  priv->kicks = (struct StarKick * ) mymalloc("StarKicks", priv->maxkicks * sizeof(struct StarKick));
356  priv->nkicks = 0;
357  ta_free(priv->nvisited);
358 
359  /* Then run feedback */
360  tw->haswork = NULL;
362  tw->postprocess = NULL;
363  tw->reduce = NULL;
364  tw->ev_label = "WIND_KICK";
365  tw->Niteration = 0;
366 
367  treewalk_run(tw, NewStars, NumNewStars);
368 
369  /* Sort the possible kicks*/
370  qsort_openmp(priv->kicks, priv->nkicks, sizeof(struct StarKick), cmp_by_part_id);
371  /* Not parallel as the number of kicked particles should be pretty small*/
372  int64_t last_part = -1;
373  int64_t nkicked = 0;
374  for(i = 0; i < priv->nkicks; i++) {
375  /* Only do the kick for the first particle, which is the closest*/
376  if(priv->kicks[i].part_index == last_part)
377  continue;
378  int other = priv->kicks[i].part_index;
379  last_part = other;
380  nkicked++;
381  wind_do_kick(other, priv->kicks[i].StarKickVelocity, priv->kicks[i].StarTherm, Time);
382  if(priv->kicks[i].StarKickVelocity <= 0 || !isfinite(priv->kicks[i].StarKickVelocity) || !isfinite(SPHP(other).DelayTime))
383  {
384  endrun(5, "Odd v: other = %d, DT = %g v = %g i = %d, nkicks %d maxkicks %d dist %g id %ld\n",
385  other, SPHP(other).DelayTime, priv->kicks[i].StarKickVelocity, i, priv->nkicks, priv->maxkicks,
386  priv->kicks[i].StarDistance, priv->kicks[i].StarID);
387  }
388  }
389  /* Get total number of potential new stars to allocate memory.*/
390  int64_t tot_newstars, tot_kicks, tot_applied;
391  sumup_large_ints(1, &NumNewStars, &tot_newstars);
392  MPI_Allreduce(&priv->nkicks, &tot_kicks, 1, MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
393  MPI_Allreduce(&nkicked, &tot_applied, 1, MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
394  message(0, "Made %ld gas wind, discarded %ld kicks from %d stars\n", tot_applied, tot_kicks - tot_applied, tot_newstars);
395 
396  myfree(priv->kicks);
397  myfree(priv->Winddata);
398  walltime_measure("/Cooling/Wind");
399 }
#define mymalloc(name, size)
Definition: mymalloc.h:15
#define ta_free(p)
Definition: mymalloc.h:28
#define myfree(x)
Definition: mymalloc.h:19
#define SPHP(i)
Definition: slotsmanager.h:124
int64_t Niteration
Definition: treewalk.h:142
TreeWalkHasWorkFunction haswork
Definition: treewalk.h:100
TreeWalkProcessFunction postprocess
Definition: treewalk.h:104
TreeWalkNgbIterFunction ngbiter
Definition: treewalk.h:103
TreeWalkReduceResultFunction reduce
Definition: treewalk.h:102
const char * ev_label
Definition: treewalk.h:91
double hubble
Definition: winds.c:221
double Time
Definition: winds.c:220
void sumup_large_ints(int n, int *src, int64_t *res)
Definition: system.c:192
int MPIU_Any(int condition, MPI_Comm comm)
Definition: system.c:545
#define MPI_INT64
Definition: system.h:12
#define qsort_openmp
Definition: test_exchange.c:14
void treewalk_run(TreeWalk *tw, int *active_set, size_t size)
Definition: treewalk.c:619
void(* TreeWalkNgbIterFunction)(TreeWalkQueryBase *input, TreeWalkResultBase *output, TreeWalkNgbIterBase *iter, LocalTreeWalk *lv)
Definition: treewalk.h:70
#define walltime_measure(name)
Definition: walltime.h:8
static void wind_do_kick(int other, double vel, double therm, double atime)
Definition: winds.c:590
static void sfr_wind_feedback_ngbiter(TreeWalkQueryWind *I, TreeWalkResultWind *O, TreeWalkNgbIterWind *iter, LocalTreeWalk *lv)
Definition: winds.c:650
int cmp_by_part_id(const void *a, const void *b)
Definition: winds.c:231
static void winds_find_weights(TreeWalk *tw, struct WindPriv *priv, int *NewStars, int NumNewStars, const double Time, const double hubble, ForceTree *tree)
Definition: winds.c:255

References cmp_by_part_id(), endrun(), TreeWalk::ev_label, HAS, TreeWalk::haswork, WindPriv::hubble, WindPriv::kicks, WindPriv::maxkicks, message(), MPI_INT64, MPIU_Any(), myfree, mymalloc, TreeWalk::ngbiter, TreeWalk::Niteration, WindPriv::nkicks, WindPriv::nvisited, StarKick::part_index, TreeWalk::postprocess, qsort_openmp, TreeWalk::reduce, sfr_wind_feedback_ngbiter(), SPHP, StarKick::StarDistance, StarKick::StarID, StarKick::StarKickVelocity, StarKick::StarTherm, sumup_large_ints(), ta_free, WindPriv::Time, treewalk_run(), walltime_measure, wind_do_kick(), wind_params, WIND_SUBGRID, WindPriv::Winddata, WindParams::WindModel, and winds_find_weights().

Referenced by cooling_and_starformation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winds_are_subgrid()

int winds_are_subgrid ( void  )

Definition at line 115 of file winds.c.

116 {
118  return 1;
119  else
120  return 0;
121 }

References HAS, wind_params, WIND_SUBGRID, and WindParams::WindModel.

Referenced by cooling_and_starformation().

Here is the caller graph for this function:

◆ winds_decoupled_hydro()

void winds_decoupled_hydro ( int  i,
double  atime 
)

Definition at line 133 of file winds.c.

134 {
135  int k;
136  for(k = 0; k < 3; k++)
137  SPHP(i).HydroAccel[k] = 0;
138 
139  SPHP(i).DtEntropy = 0;
140 
141  double windspeed = wind_params.WindSpeed * atime;
142  const double fac_mu = pow(atime, 3 * (GAMMA - 1) / 2) / atime;
143  windspeed *= fac_mu;
144  double hsml_c = cbrt(wind_params.WindFreeTravelDensThresh /SPHP(i).Density) * atime;
145  SPHP(i).MaxSignalVel = hsml_c * DMAX((2 * windspeed), SPHP(i).MaxSignalVel);
146 }
#define GAMMA
Definition: physconst.h:34
#define DMAX(x, y)
Definition: test_interp.c:11

References DMAX, GAMMA, SPHP, wind_params, WindParams::WindFreeTravelDensThresh, and WindParams::WindSpeed.

Referenced by hydro_postprocess().

Here is the caller graph for this function:

◆ winds_ever_decouple()

int winds_ever_decouple ( void  )

Definition at line 192 of file winds.c.

193 {
195  return 1;
196  else
197  return 0;
198 }

References WindParams::MaxWindFreeTravelTime, and wind_params.

Referenced by wind_do_kick().

Here is the caller graph for this function:

◆ winds_evolve()

void winds_evolve ( int  i,
double  a3inv,
double  hubble 
)

Definition at line 403 of file winds.c.

404 {
405  /*Remove a wind particle from the delay mode if the (physical) density has dropped sufficiently.*/
406  if(SPHP(i).DelayTime > 0 && SPHP(i).Density * a3inv < wind_params.WindFreeTravelDensThresh) {
407  SPHP(i).DelayTime = 0;
408  }
409  /*Reduce the time until the particle can form stars again by the current timestep*/
410  if(SPHP(i).DelayTime > 0) {
411  /* Enforce the maximum in case of restarts*/
412  if(SPHP(i).DelayTime > wind_params.MaxWindFreeTravelTime)
413  SPHP(i).DelayTime = wind_params.MaxWindFreeTravelTime;
414  const double dloga = get_dloga_for_bin(P[i].TimeBin, P[i].Ti_drift);
415  /* the proper time duration of the step */
416  const double dtime = dloga / hubble;
417  SPHP(i).DelayTime = DMAX(SPHP(i).DelayTime - dtime, 0);
418  }
419 }
static double dloga
Definition: lightcone.c:21
#define P
Definition: partmanager.h:88
double get_dloga_for_bin(int timebin, const inttime_t Ti_Current)
Definition: timebinmgr.c:279

References dloga, DMAX, get_dloga_for_bin(), WindPriv::hubble, WindParams::MaxWindFreeTravelTime, P, SPHP, wind_params, and WindParams::WindFreeTravelDensThresh.

Referenced by cooling_and_starformation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winds_is_particle_decoupled()

int winds_is_particle_decoupled ( int  i)

Definition at line 124 of file winds.c.

125 {
127  && P[i].Type == 0 && SPHP(i).DelayTime > 0)
128  return 1;
129  return 0;
130 }

References HAS, P, SPHP, WIND_DECOUPLE_SPH, wind_params, and WindParams::WindModel.

Referenced by add_particle_to_group(), blackhole_accretion_ngbiter(), blackhole_feedback_ngbiter(), density_ngbiter(), hydro_ngbiter(), and hydro_postprocess().

Here is the caller graph for this function:

◆ winds_make_after_sf()

int winds_make_after_sf ( int  i,
double  sm,
double  vdisp,
double  atime 
)

Definition at line 708 of file winds.c.

709 {
711  return 0;
712 
713  /* Get the velocity, thermal energy and efficiency of the kick*/
714  double utherm = 0, vel=0, windeff = 0;
715  get_wind_params(&vel, &windeff, &utherm, vdisp, atime);
716 
717  /* Here comes the Springel Hernquist 03 wind model */
718  /* Notice that this is the mass of the gas particle after forking a star, Mass - Mass/GENERATIONS.*/
719  double pw = windeff * sm / P[i].Mass;
720  double prob = 1 - exp(-pw);
721  if(get_random_number(P[i].ID + 2) < prob) {
722  wind_do_kick(i, vel, utherm, atime);
723  }
724  return 0;
725 }
double get_random_number(uint64_t id)
Definition: system.c:60
static void get_wind_params(double *vel, double *windeff, double *utherm, const double vdisp, const double time)
Definition: winds.c:630

Referenced by winds_subgrid().

Here is the caller graph for this function:

◆ winds_subgrid()

void winds_subgrid ( int *  MaybeWind,
int  NumMaybeWind,
const double  Time,
const double  hubble,
ForceTree tree,
MyFloat StellarMasses 
)

Definition at line 306 of file winds.c.

307 {
308  /*The non-subgrid model does nothing here*/
310  return;
311 
312  if(!MPIU_Any(NumMaybeWind > 0, MPI_COMM_WORLD))
313  return;
314 
315  TreeWalk tw[1] = {{0}};
316  struct WindPriv priv[1];
317  int n;
318  winds_find_weights(tw, priv, MaybeWind, NumMaybeWind, Time, hubble, tree);
319  myfree(priv->nvisited);
320  for(n = 0; n < NumMaybeWind; n++)
321  {
322  int i = MaybeWind ? MaybeWind[n] : n;
323  /* Notice that StellarMasses is indexed like PI, not i!*/
324  MyFloat sm = StellarMasses[P[i].PI];
325  winds_make_after_sf(i, sm, WINDP(i, priv->Winddata).Vdisp, Time);
326  }
327  myfree(priv->Winddata);
328  walltime_measure("/Cooling/Wind");
329 }
LOW_PRECISION MyFloat
Definition: types.h:19
int winds_make_after_sf(int i, double sm, double vdisp, double atime)
Definition: winds.c:708
#define WINDP(i, wind)
Definition: winds.c:251

References HAS, WindPriv::hubble, MPIU_Any(), myfree, WindPriv::nvisited, P, WindPriv::Time, walltime_measure, wind_params, WIND_SUBGRID, WindPriv::Winddata, WindParams::WindModel, WINDP, winds_find_weights(), and winds_make_after_sf().

Referenced by cooling_and_starformation().

Here is the call graph for this function:
Here is the caller graph for this function: