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

Go to the source code of this file.

Classes

struct  density_params
 
struct  sph_pred_data
 

Functions

void set_density_params (ParameterSet *ps)
 
void set_densitypar (struct density_params dp)
 
void density (const ActiveParticles *act, int update_hsml, int DoEgyDensity, int BlackHoleOn, double MinEgySpec, const DriftKickTimes times, Cosmology *CP, struct sph_pred_data *SPH_predicted, MyFloat *GradRho, const ForceTree *const tree)
 
double GetNumNgb (enum DensityKernelType KernelType)
 
enum DensityKernelType GetDensityKernelType (void)
 
struct sph_pred_data slots_allocate_sph_pred_data (int nsph)
 
void slots_free_sph_pred_data (struct sph_pred_data *sph_pred)
 
MyFloat SPH_EntVarPred (int PI, double MinEgySpec, double a3inv, double dloga)
 
void SPH_VelPred (int i, MyFloat *VelPred, const double FgravkickB, double gravkick, double hydrokick)
 

Function Documentation

◆ density()

void density ( const ActiveParticles act,
int  update_hsml,
int  DoEgyDensity,
int  BlackHoleOn,
double  MinEgySpec,
const DriftKickTimes  times,
Cosmology CP,
struct sph_pred_data SPH_predicted,
MyFloat GradRho,
const ForceTree *const  tree 
)

This function computes the local density for each active SPH particle, the number of neighbours in the current smoothing radius, and the divergence and rotation of the velocity field. The pressure is updated as well. If a particle with its smoothing region is fully inside the local domain, it is not exported to the other processors. The function also detects particles that have a number of neighbours outside the allowed tolerance range. For these particles, the smoothing length is adjusted accordingly, and the density() computation is called again. Note that the smoothing length is not allowed to fall below the lower bound set by MinGasHsml (this may mean that one has to deal with substantially more than normal number of neighbours.)

Definition at line 203 of file density.c.

204 {
205  TreeWalk tw[1] = {{0}};
206  struct DensityPriv priv[1];
207 
208  tw->ev_label = "DENSITY";
210  tw->NoNgblist = 1;
213  tw->haswork = density_haswork;
219  tw->priv = priv;
220  tw->tree = tree;
221 
222  int i;
223 
224  double timeall = 0;
225  double timecomp, timecomm, timewait;
226  const double atime = exp(loga_from_ti(times.Ti_Current));
227 
228  walltime_measure("/Misc");
229 
230  DENSITY_GET_PRIV(tw)->Left = (MyFloat *) mymalloc("DENS_PRIV->Left", PartManager->NumPart * sizeof(MyFloat));
231  DENSITY_GET_PRIV(tw)->Right = (MyFloat *) mymalloc("DENS_PRIV->Right", PartManager->NumPart * sizeof(MyFloat));
232  DENSITY_GET_PRIV(tw)->NumNgb = (MyFloat *) mymalloc("DENS_PRIV->NumNgb", PartManager->NumPart * sizeof(MyFloat));
233  DENSITY_GET_PRIV(tw)->Rot = (MyFloat (*) [3]) mymalloc("DENS_PRIV->Rot", SlotsManager->info[0].size * sizeof(priv->Rot[0]));
234  /* This one stores the gradient for h finding. The factor stored in SPHP->DhsmlEgyDensityFactor depends on whether PE SPH is enabled.*/
235  DENSITY_GET_PRIV(tw)->DhsmlDensityFactor = (MyFloat *) mymalloc("DENSITY_GET_PRIV(tw)->DhsmlDensity", PartManager->NumPart * sizeof(MyFloat));
236 
237  DENSITY_GET_PRIV(tw)->update_hsml = update_hsml;
238  DENSITY_GET_PRIV(tw)->DoEgyDensity = DoEgyDensity;
239 
241  DENSITY_GET_PRIV(tw)->MinGasHsml = DensityParams.MinGasHsmlFractional * (FORCE_SOFTENING(1, 1)/2.8);
242 
243  DENSITY_GET_PRIV(tw)->BlackHoleOn = BlackHoleOn;
244  DENSITY_GET_PRIV(tw)->SPH_predicted = SPH_predicted;
245  DENSITY_GET_PRIV(tw)->GradRho = GradRho;
246 
247  /* Init Left and Right: this has to be done before treewalk */
248  #pragma omp parallel for
249  for(i = 0; i < act->NumActiveParticle; i++) {
250  int p_i = act->ActiveParticle ? act->ActiveParticle[i] : i;
251  /* We only really need active particles with work
252  * but I don't want to read the particle table here*/
253  DENSITY_GET_PRIV(tw)->Right[p_i] = tree->BoxSize;
254  DENSITY_GET_PRIV(tw)->NumNgb[p_i] = 0;
255  DENSITY_GET_PRIV(tw)->Left[p_i] = 0;
256  }
257 
258  priv->a3inv = pow(atime, -3);
259  priv->MinEgySpec = MinEgySpec;
260  /* Factor this out since all particles have the same drift time*/
262  memset(priv->gravkicks, 0, sizeof(priv->gravkicks[0])*(TIMEBINS+1));
263  memset(priv->hydrokicks, 0, sizeof(priv->hydrokicks[0])*(TIMEBINS+1));
264  /* Compute the factors to move a current kick times velocity to the drift time velocity.
265  * We need to do the computation for all timebins up to the maximum because even inactive
266  * particles may have interactions. */
267  #pragma omp parallel for
268  for(i = times.mintimebin; i <= TIMEBINS; i++)
269  {
270  priv->gravkicks[i] = get_exact_gravkick_factor(CP, times.Ti_kick[i], times.Ti_Current);
271  priv->hydrokicks[i] = get_exact_hydrokick_factor(CP, times.Ti_kick[i], times.Ti_Current);
272  }
273  priv->times = &times;
274 
275  #pragma omp parallel for
276  for(i = 0; i < act->NumActiveParticle; i++)
277  {
278  int p_i = act->ActiveParticle ? act->ActiveParticle[i] : i;
279  if(P[p_i].Type == 0 && !P[p_i].IsGarbage) {
280  int bin = P[p_i].TimeBin;
281  double dloga = dloga_from_dti(priv->times->Ti_Current - priv->times->Ti_kick[bin], priv->times->Ti_Current);
282  priv->SPH_predicted->EntVarPred[P[p_i].PI] = SPH_EntVarPred(P[p_i].PI, priv->MinEgySpec, priv->a3inv, dloga);
283  SPH_VelPred(p_i, priv->SPH_predicted->VelPred + 3 * P[p_i].PI, priv->FgravkickB, priv->gravkicks[bin], priv->hydrokicks[bin]);
284  }
285  }
286 
287  /* allocate buffers to arrange communication */
288 
289  walltime_measure("/SPH/Density/Init");
290 
291  /* Do the treewalk with looping for hsml*/
293 
299 
300 
301  /* collect some timing information */
302 
304 
305  timecomp = tw->timecomp3 + tw->timecomp1 + tw->timecomp2;
306  timewait = tw->timewait1 + tw->timewait2;
307  timecomm = tw->timecommsumm1 + tw->timecommsumm2;
308 
309  walltime_add("/SPH/Density/Compute", timecomp);
310  walltime_add("/SPH/Density/Wait", timewait);
311  walltime_add("/SPH/Density/Comm", timecomm);
312  walltime_add("/SPH/Density/Misc", timeall - (timecomp + timewait + timecomm));
313 }
void SPH_VelPred(int i, MyFloat *VelPred, const double FgravkickB, double gravkick, double hydrokick)
Definition: density.c:89
static void density_ngbiter(TreeWalkQueryDensity *I, TreeWalkResultDensity *O, TreeWalkNgbIterDensity *iter, LocalTreeWalk *lv)
Definition: density.c:388
double GetNumNgb(enum DensityKernelType KernelType)
Definition: density.c:55
MyFloat SPH_EntVarPred(int PI, double MinEgySpec, double a3inv, double dloga)
Definition: density.c:71
static void density_copy(int place, TreeWalkQueryDensity *I, TreeWalk *tw)
Definition: density.c:316
static struct density_params DensityParams
Definition: density.c:21
static void density_reduce(int place, TreeWalkResultDensity *remote, enum TreeWalkReduceMode mode, TreeWalk *tw)
Definition: density.c:339
static void density_postprocess(int i, TreeWalk *tw)
Definition: density.c:512
static int density_haswork(int n, TreeWalk *tw)
Definition: density.c:501
#define DENSITY_GET_PRIV(tw)
Definition: density.c:166
double FORCE_SOFTENING(int i, int type)
static double dloga
Definition: lightcone.c:21
#define mymalloc(name, size)
Definition: mymalloc.h:15
#define myfree(x)
Definition: mymalloc.h:19
struct part_manager_type PartManager[1]
Definition: partmanager.c:11
#define P
Definition: partmanager.h:88
static Cosmology * CP
Definition: power.c:27
struct slots_manager_type SlotsManager[1]
Definition: slotsmanager.c:7
int * ActiveParticle
Definition: timestep.h:13
int64_t NumActiveParticle
Definition: timestep.h:12
int update_hsml
Definition: density.c:148
int DoEgyDensity
Definition: density.c:149
struct sph_pred_data * SPH_predicted
Definition: density.c:133
MyFloat * Left
Definition: density.c:140
DriftKickTimes const * times
Definition: density.c:160
MyFloat * GradRho
Definition: density.c:136
MyFloat(* Rot)[3]
Definition: density.c:141
MyFloat * NumNgb
Definition: density.c:138
int BlackHoleOn
Definition: density.c:155
double MinEgySpec
Definition: density.c:159
MyFloat * Right
Definition: density.c:140
MyFloat * DhsmlDensityFactor
Definition: density.c:147
inttime_t PM_kick
Definition: timestep.h:31
inttime_t Ti_Current
Definition: timestep.h:27
inttime_t Ti_kick[TIMEBINS+1]
Definition: timestep.h:23
int mintimebin
Definition: timestep.h:20
double BoxSize
Definition: forcetree.h:106
void * priv
Definition: treewalk.h:85
TreeWalkHasWorkFunction haswork
Definition: treewalk.h:100
size_t ngbiter_type_elsize
Definition: treewalk.h:97
double timecomp2
Definition: treewalk.h:124
double timecomp3
Definition: treewalk.h:125
double timecommsumm1
Definition: treewalk.h:126
const ForceTree * tree
Definition: treewalk.h:88
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 timewait2
Definition: treewalk.h:122
int NoNgblist
Definition: treewalk.h:156
TreeWalkVisitFunction visit
Definition: treewalk.h:99
size_t result_type_elsize
Definition: treewalk.h:96
TreeWalkFillQueryFunction fill
Definition: treewalk.h:101
double timecomp1
Definition: treewalk.h:123
double timewait1
Definition: treewalk.h:121
double timecommsumm2
Definition: treewalk.h:127
size_t query_type_elsize
Definition: treewalk.h:95
double MinGasHsmlFractional
Definition: density.h:22
enum DensityKernelType DensityKernelType
Definition: density.h:18
int64_t size
Definition: slotsmanager.h:12
struct slot_info info[6]
Definition: slotsmanager.h:112
double loga_from_ti(int ti)
Definition: test_timefac.c:51
double dloga_from_dti(inttime_t dti, const inttime_t Ti_Current)
Definition: timebinmgr.c:256
#define TIMEBINS
Definition: timebinmgr.h:13
double get_exact_hydrokick_factor(Cosmology *CP, inttime_t ti0, inttime_t ti1)
Definition: timefac.c:75
double get_exact_gravkick_factor(Cosmology *CP, inttime_t ti0, inttime_t ti1)
Definition: timefac.c:70
int treewalk_visit_nolist_ngbiter(TreeWalkQueryBase *I, TreeWalkResultBase *O, LocalTreeWalk *lv)
Definition: treewalk.c:1143
void treewalk_do_hsml_loop(TreeWalk *tw, int *queue, int64_t queuesize, int update_hsml)
Definition: treewalk.c:1254
int(* TreeWalkVisitFunction)(TreeWalkQueryBase *input, TreeWalkResultBase *output, LocalTreeWalk *lv)
Definition: treewalk.h:68
void(* TreeWalkReduceResultFunction)(const int j, TreeWalkResultBase *result, const enum TreeWalkReduceMode mode, TreeWalk *tw)
Definition: treewalk.h:76
void(* TreeWalkProcessFunction)(const int i, TreeWalk *tw)
Definition: treewalk.h:73
void(* TreeWalkNgbIterFunction)(TreeWalkQueryBase *input, TreeWalkResultBase *output, TreeWalkNgbIterBase *iter, LocalTreeWalk *lv)
Definition: treewalk.h:70
void(* TreeWalkFillQueryFunction)(const int j, TreeWalkQueryBase *query, TreeWalk *tw)
Definition: treewalk.h:75
LOW_PRECISION MyFloat
Definition: types.h:19
#define walltime_measure(name)
Definition: walltime.h:8
#define WALLTIME_IGNORE
Definition: walltime.h:6
#define walltime_add(name, dt)
Definition: walltime.h:9

References DensityPriv::a3inv, ActiveParticles::ActiveParticle, DensityPriv::BlackHoleOn, ForceTree::BoxSize, CP, density_copy(), DENSITY_GET_PRIV, density_haswork(), density_ngbiter(), density_postprocess(), density_reduce(), density_params::DensityKernelType, DensityParams, DensityPriv::DhsmlDensityFactor, dloga, dloga_from_dti(), DensityPriv::DoEgyDensity, sph_pred_data::EntVarPred, TreeWalk::ev_label, DensityPriv::FgravkickB, TreeWalk::fill, FORCE_SOFTENING(), get_exact_gravkick_factor(), get_exact_hydrokick_factor(), GetNumNgb(), DensityPriv::GradRho, DensityPriv::gravkicks, TreeWalk::haswork, DensityPriv::hydrokicks, slots_manager_type::info, DensityPriv::Left, loga_from_ti(), DensityPriv::MinEgySpec, density_params::MinGasHsmlFractional, DriftKickTimes::mintimebin, myfree, mymalloc, TreeWalk::ngbiter, TreeWalk::ngbiter_type_elsize, TreeWalk::NoNgblist, ActiveParticles::NumActiveParticle, DensityPriv::NumNgb, part_manager_type::NumPart, P, PartManager, DriftKickTimes::PM_kick, TreeWalk::postprocess, TreeWalk::priv, TreeWalk::query_type_elsize, TreeWalk::reduce, TreeWalk::result_type_elsize, DensityPriv::Right, DensityPriv::Rot, slot_info::size, SlotsManager, SPH_EntVarPred(), DensityPriv::SPH_predicted, SPH_VelPred(), DriftKickTimes::Ti_Current, DriftKickTimes::Ti_kick, TIMEBINS, TreeWalk::timecommsumm1, TreeWalk::timecommsumm2, TreeWalk::timecomp1, TreeWalk::timecomp2, TreeWalk::timecomp3, DensityPriv::times, TreeWalk::timewait1, TreeWalk::timewait2, TreeWalk::tree, treewalk_do_hsml_loop(), treewalk_visit_nolist_ngbiter(), DensityPriv::update_hsml, sph_pred_data::VelPred, TreeWalk::visit, walltime_add, WALLTIME_IGNORE, and walltime_measure.

Referenced by density_postprocess(), do_density_test(), get_compton_cooling(), get_equilib_ne(), get_heatingcooling_rate(), get_helium_ion_phys_cgs(), get_individual_cooling(), get_ne_by_nh(), get_neutral_fraction_phys_cgs(), get_temp(), run(), runfof(), setup_density_indep_entropy(), and setup_smoothinglengths().

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

◆ GetDensityKernelType()

enum DensityKernelType GetDensityKernelType ( void  )

Definition at line 55 of file density.c.

64 {
66 }

References density_kernel_desnumngb(), density_kernel_init(), DensityParams, density_params::DensityResolutionEta, and kernel().

Referenced by blackhole_accretion_ngbiter(), blackhole_dynfric_ngbiter(), blackhole_feedback_ngbiter(), do_density_test(), hydro_ngbiter(), metal_return_ngbiter(), petaio_write_header(), set_density_params(), set_init_hsml(), setup_smoothinglengths(), stellar_density(), and stellar_density_ngbiter().

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

◆ GetNumNgb()

double GetNumNgb ( enum DensityKernelType  KernelType)

Definition at line 55 of file density.c.

56 {
58  density_kernel_init(&kernel, 1.0, KernelType);
60 }
void density_kernel_init(DensityKernel *kernel, double H, enum DensityKernelType type)
double density_kernel_desnumngb(DensityKernel *kernel, double eta)
static double kernel(double loga, void *params)
Definition: lightcone.c:59
double DensityResolutionEta
Definition: density.h:11

Referenced by density(), do_density_test(), set_density_params(), set_init_hsml(), setup_smoothinglengths(), and stellar_density().

Here is the caller graph for this function:

◆ set_density_params()

void set_density_params ( ParameterSet ps)

Definition at line 32 of file density.c.

33 {
34  int ThisTask;
35  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
36  if(ThisTask == 0) {
37  DensityParams.DensityKernelType = (enum DensityKernelType) param_get_enum(ps, "DensityKernelType");
38  DensityParams.MaxNumNgbDeviation = param_get_double(ps, "MaxNumNgbDeviation");
39  DensityParams.DensityResolutionEta = param_get_double(ps, "DensityResolutionEta");
40  DensityParams.MinGasHsmlFractional = param_get_double(ps, "MinGasHsmlFractional");
41 
44  message(1, "The Density Kernel type is %s\n", kernel.name);
45  message(1, "The Density resolution is %g * mean separation, or %g neighbours\n",
47  /*These two look like black hole parameters but they are really neighbour finding parameters*/
48  DensityParams.BlackHoleNgbFactor = param_get_double(ps, "BlackHoleNgbFactor");
49  DensityParams.BlackHoleMaxAccretionRadius = param_get_double(ps, "BlackHoleMaxAccretionRadius");
50  }
51  MPI_Bcast(&DensityParams, sizeof(struct density_params), MPI_BYTE, 0, MPI_COMM_WORLD);
52 }
enum DensityKernelType GetDensityKernelType(void)
Definition: density.c:63
DensityKernelType
Definition: densitykernel.h:17
void message(int where, const char *fmt,...)
Definition: endrun.c:175
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 MaxNumNgbDeviation
Definition: density.h:12
double BlackHoleNgbFactor
Definition: density.h:15
double BlackHoleMaxAccretionRadius
Definition: density.h:16
int ThisTask
Definition: test_exchange.c:23

References density_params::BlackHoleMaxAccretionRadius, density_params::BlackHoleNgbFactor, density_kernel_init(), density_params::DensityKernelType, DensityParams, density_params::DensityResolutionEta, GetDensityKernelType(), GetNumNgb(), kernel(), density_params::MaxNumNgbDeviation, message(), density_params::MinGasHsmlFractional, param_get_double(), param_get_enum(), and ThisTask.

Referenced by read_parameter_file().

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

◆ set_densitypar()

void set_densitypar ( struct density_params  dp)

Definition at line 25 of file density.c.

26 {
27  DensityParams = dp;
28 }

References DensityParams.

Referenced by do_density_test(), and setup_density().

Here is the caller graph for this function:

◆ slots_allocate_sph_pred_data()

struct sph_pred_data slots_allocate_sph_pred_data ( int  nsph)

Definition at line 554 of file density.c.

655 {
656  struct sph_pred_data sph_scratch;
657  /*Data is allocated high so that we can free the tree around it*/
658  sph_scratch.EntVarPred = (MyFloat *) mymalloc2("EntVarPred", sizeof(MyFloat) * nsph);
659  memset(sph_scratch.EntVarPred, 0, sizeof(sph_scratch.EntVarPred[0]) * nsph);
660  sph_scratch.VelPred = (MyFloat *) mymalloc2("VelPred", sizeof(MyFloat) * 3 * nsph);
661  return sph_scratch;
662 }
#define mymalloc2(name, size)
Definition: mymalloc.h:16
MyFloat * EntVarPred
Definition: density.h:28

Referenced by run(), runfof(), setup_density(), and setup_smoothinglengths().

Here is the caller graph for this function:

◆ slots_free_sph_pred_data()

void slots_free_sph_pred_data ( struct sph_pred_data sph_pred)

Definition at line 665 of file density.c.

666 {
667  myfree(sph_scratch->VelPred);
668  sph_scratch->VelPred = NULL;
669  myfree(sph_scratch->EntVarPred);
670  sph_scratch->EntVarPred = NULL;
671 }

References sph_pred_data::EntVarPred, myfree, and sph_pred_data::VelPred.

Referenced by run(), runfof(), and setup_smoothinglengths().

Here is the caller graph for this function:

◆ SPH_EntVarPred()

MyFloat SPH_EntVarPred ( int  PI,
double  MinEgySpec,
double  a3inv,
double  dloga 
)

Definition at line 71 of file density.c.

72 {
73  double EntVarPred = SphP[PI].Entropy + SphP[PI].DtEntropy * dloga;
74  /*Entropy limiter for the predicted entropy: makes sure entropy stays positive. */
75  if(dloga > 0 && EntVarPred < 0.5*SphP[PI].Entropy)
76  EntVarPred = 0.5 * SphP[PI].Entropy;
77  const double enttou = pow(SphP[PI].Density * a3inv, GAMMA_MINUS1) / GAMMA_MINUS1;
78  if(EntVarPred < MinEgySpec / enttou)
79  EntVarPred = MinEgySpec / enttou;
80  EntVarPred = pow(EntVarPred, 1/GAMMA);
81  return EntVarPred;
82 }
#define GAMMA_MINUS1
Definition: physconst.h:35
#define GAMMA
Definition: physconst.h:34
#define SphP
Definition: slotsmanager.h:119

References dloga, GAMMA, GAMMA_MINUS1, and SphP.

Referenced by density(), density_ngbiter(), and hydro_ngbiter().

Here is the caller graph for this function:

◆ SPH_VelPred()

void SPH_VelPred ( int  i,
MyFloat VelPred,
const double  FgravkickB,
double  gravkick,
double  hydrokick 
)

Definition at line 89 of file density.c.

90 {
91  int j;
92  for(j = 0; j < 3; j++) {
93  VelPred[j] = P[i].Vel[j] + gravkick * P[i].GravAccel[j]
94  + P[i].GravPM[j] * FgravkickB + hydrokick * SPHP(i).HydroAccel[j];
95  }
96 }
#define SPHP(i)
Definition: slotsmanager.h:124

References P, and SPHP.

Referenced by density(), density_ngbiter(), and hydro_ngbiter().

Here is the caller graph for this function: