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

Go to the source code of this file.

Functions

void hydro_force (const ActiveParticles *act, const double atime, struct sph_pred_data *SPH_predicted, double MinEgySpec, const DriftKickTimes times, Cosmology *CP, const ForceTree *const tree)
 
void set_hydro_params (ParameterSet *ps)
 
int DensityIndependentSphOn (void)
 

Function Documentation

◆ DensityIndependentSphOn()

int DensityIndependentSphOn ( void  )

Definition at line 49 of file hydra.c.

50 {
52 }
static struct hydro_params HydroParams
int DensityIndependentSphOn
Definition: hydra.c:28

References hydro_params::DensityIndependentSphOn, and HydroParams.

Referenced by register_io_blocks(), run(), setup_density_indep_entropy(), and setup_smoothinglengths().

Here is the caller graph for this function:

◆ hydro_force()

void hydro_force ( const ActiveParticles act,
const double  atime,
struct sph_pred_data SPH_predicted,
double  MinEgySpec,
const DriftKickTimes  times,
Cosmology CP,
const ForceTree *const  tree 
)

This function is the driver routine for the calculation of hydrodynamical force and rate of change of entropy due to shock heating for all active particles .

Definition at line 147 of file hydra.c.

148 {
149  int i;
150  TreeWalk tw[1] = {{0}};
151 
152  struct HydraPriv priv[1];
153 
154  tw->ev_label = "HYDRO";
158  tw->haswork = hydro_haswork;
164  tw->tree = tree;
165  tw->priv = priv;
166 
167  if(!tree->hmax_computed_flag)
168  endrun(5, "Hydro called before hmax computed\n");
169  /* Cache the pressure for speed*/
170  HYDRA_GET_PRIV(tw)->SPH_predicted = SPH_predicted;
171  HYDRA_GET_PRIV(tw)->PressurePred = (double *) mymalloc("PressurePred", SlotsManager->info[0].size * sizeof(double));
172  memset(HYDRA_GET_PRIV(tw)->PressurePred, 0, SlotsManager->info[0].size * sizeof(double));
173 
174  /* Compute pressure for active particles*/
175  if(act->ActiveParticle) {
176  #pragma omp parallel for
177  for(i = 0; i < act->NumActiveParticle; i++) {
178  int p_i = act->ActiveParticle[i];
179  if(P[p_i].Type != 0)
180  continue;
181  int pi = P[p_i].PI;
182  HYDRA_GET_PRIV(tw)->PressurePred[pi] = PressurePred(SPH_EOMDensity(&SphP[pi]), SPH_predicted->EntVarPred[pi]);
183  }
184  }
185  else{
186  /* Do it in slot order for memory locality*/
187  #pragma omp parallel for
188  for(i = 0; i < SlotsManager->info[0].size; i++)
189  HYDRA_GET_PRIV(tw)->PressurePred[i] = PressurePred(SPH_EOMDensity(&SphP[i]), SPH_predicted->EntVarPred[i]);
190  }
191 
192 
193  double timeall = 0, timenetwork = 0;
194  double timecomp, timecomm, timewait;
195 
196  walltime_measure("/SPH/Hydro/Init");
197 
198  /* Initialize some time factors*/
199  const double hubble = hubble_function(CP, atime);
200  HYDRA_GET_PRIV(tw)->fac_mu = pow(atime, 3 * (GAMMA - 1) / 2) / atime;
201  HYDRA_GET_PRIV(tw)->fac_vsic_fix = hubble * pow(atime, 3 * GAMMA_MINUS1);
202  HYDRA_GET_PRIV(tw)->atime = atime;
203  HYDRA_GET_PRIV(tw)->hubble_a2 = hubble * atime * atime;
204  priv->MinEgySpec = MinEgySpec;
205  priv->times = &times;
207  memset(priv->gravkicks, 0, sizeof(priv->gravkicks[0])*(TIMEBINS+1));
208  memset(priv->hydrokicks, 0, sizeof(priv->hydrokicks[0])*(TIMEBINS+1));
209  memset(priv->drifts, 0, sizeof(priv->drifts[0])*(TIMEBINS+1));
210  /* Compute the factors to move a current kick times velocity to the drift time velocity.
211  * We need to do the computation for all timebins up to the maximum because even inactive
212  * particles may have interactions. */
213  #pragma omp parallel for
214  for(i = times.mintimebin; i <= TIMEBINS; i++)
215  {
216  priv->gravkicks[i] = get_exact_gravkick_factor(CP, times.Ti_kick[i], times.Ti_Current);
217  priv->hydrokicks[i] = get_exact_hydrokick_factor(CP, times.Ti_kick[i], times.Ti_Current);
218  /* For density: last active drift time is Ti_kick - 1/2 timestep as the kick time is half a timestep ahead.
219  * For active particles no density drift is needed.*/
222  }
223 
225 
227  /* collect some timing information */
228 
229  timeall += walltime_measure(WALLTIME_IGNORE);
230 
231  timecomp = tw->timecomp1 + tw->timecomp2 + tw->timecomp3;
232  timewait = tw->timewait1 + tw->timewait2;
233  timecomm = tw->timecommsumm1 + tw->timecommsumm2;
234 
235  walltime_add("/SPH/Hydro/Compute", timecomp);
236  walltime_add("/SPH/Hydro/Wait", timewait);
237  walltime_add("/SPH/Hydro/Comm", timecomm);
238  walltime_add("/SPH/Hydro/Misc", timeall - (timecomp + timewait + timecomm + timenetwork));
239 }
double hubble_function(const Cosmology *CP, double a)
Definition: cosmology.c:58
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
static void hydro_reduce(int place, TreeWalkResultHydro *result, enum TreeWalkReduceMode mode, TreeWalk *tw)
Definition: hydra.c:273
static void hydro_copy(int place, TreeWalkQueryHydro *input, TreeWalk *tw)
Definition: hydra.c:242
static MyFloat SPH_EOMDensity(const struct sph_particle_data *const pi)
Definition: hydra.c:56
static void hydro_ngbiter(TreeWalkQueryHydro *I, TreeWalkResultHydro *O, TreeWalkNgbIterHydro *iter, LocalTreeWalk *lv)
Definition: hydra.c:305
static void hydro_postprocess(int i, TreeWalk *tw)
Definition: hydra.c:501
static double PressurePred(MyFloat EOMDensityPred, double EntVarPred)
Definition: hydra.c:67
#define HYDRA_GET_PRIV(tw)
Definition: hydra.c:89
static int hydro_haswork(int n, TreeWalk *tw)
Definition: hydra.c:495
#define mymalloc(name, size)
Definition: mymalloc.h:15
#define myfree(x)
Definition: mymalloc.h:19
#define P
Definition: partmanager.h:88
#define GAMMA_MINUS1
Definition: physconst.h:35
#define GAMMA
Definition: physconst.h:34
static Cosmology * CP
Definition: power.c:27
struct slots_manager_type SlotsManager[1]
Definition: slotsmanager.c:7
#define SphP
Definition: slotsmanager.h:119
int * ActiveParticle
Definition: timestep.h:13
int64_t NumActiveParticle
Definition: timestep.h:12
inttime_t PM_kick
Definition: timestep.h:31
inttime_t Ti_lastactivedrift[TIMEBINS+1]
Definition: timestep.h:25
inttime_t Ti_Current
Definition: timestep.h:27
inttime_t Ti_kick[TIMEBINS+1]
Definition: timestep.h:23
int mintimebin
Definition: timestep.h:20
int hmax_computed_flag
Definition: forcetree.h:80
double MinEgySpec
Definition: hydra.c:82
double atime
Definition: hydra.c:80
DriftKickTimes const * times
Definition: hydra.c:81
struct sph_pred_data * SPH_predicted
Definition: hydra.c:74
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
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
int64_t size
Definition: slotsmanager.h:12
struct slot_info info[6]
Definition: slotsmanager.h:112
MyFloat * EntVarPred
Definition: density.h:28
#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_drift_factor(Cosmology *CP, inttime_t ti0, inttime_t ti1)
Definition: timefac.c:64
double get_exact_gravkick_factor(Cosmology *CP, inttime_t ti0, inttime_t ti1)
Definition: timefac.c:70
int is_timebin_active(int i, inttime_t current)
Definition: timestep.c:149
int treewalk_visit_ngbiter(TreeWalkQueryBase *I, TreeWalkResultBase *O, LocalTreeWalk *lv)
Definition: treewalk.c:924
void treewalk_run(TreeWalk *tw, int *active_set, size_t size)
Definition: treewalk.c:619
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
#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 ActiveParticles::ActiveParticle, HydraPriv::atime, CP, HydraPriv::drifts, endrun(), sph_pred_data::EntVarPred, TreeWalk::ev_label, HydraPriv::FgravkickB, TreeWalk::fill, GAMMA, GAMMA_MINUS1, get_exact_drift_factor(), get_exact_gravkick_factor(), get_exact_hydrokick_factor(), HydraPriv::gravkicks, TreeWalk::haswork, ForceTree::hmax_computed_flag, hubble_function(), HYDRA_GET_PRIV, hydro_copy(), hydro_haswork(), hydro_ngbiter(), hydro_postprocess(), hydro_reduce(), HydraPriv::hydrokicks, slots_manager_type::info, is_timebin_active(), HydraPriv::MinEgySpec, DriftKickTimes::mintimebin, myfree, mymalloc, TreeWalk::ngbiter, TreeWalk::ngbiter_type_elsize, ActiveParticles::NumActiveParticle, P, DriftKickTimes::PM_kick, TreeWalk::postprocess, PressurePred(), TreeWalk::priv, TreeWalk::query_type_elsize, TreeWalk::reduce, TreeWalk::result_type_elsize, slot_info::size, SlotsManager, SPH_EOMDensity(), HydraPriv::SPH_predicted, SphP, DriftKickTimes::Ti_Current, DriftKickTimes::Ti_kick, DriftKickTimes::Ti_lastactivedrift, TIMEBINS, TreeWalk::timecommsumm1, TreeWalk::timecommsumm2, TreeWalk::timecomp1, TreeWalk::timecomp2, TreeWalk::timecomp3, HydraPriv::times, TreeWalk::timewait1, TreeWalk::timewait2, TreeWalk::tree, treewalk_run(), treewalk_visit_ngbiter(), TreeWalk::visit, walltime_add, WALLTIME_IGNORE, and walltime_measure.

Referenced by run().

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

◆ set_hydro_params()

void set_hydro_params ( ParameterSet ps)

Definition at line 37 of file hydra.c.

38 {
39  int ThisTask;
40  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
41  if(ThisTask == 0) {
42  HydroParams.ArtBulkViscConst = param_get_double(ps, "ArtBulkViscConst");
43  HydroParams.DensityContrastLimit = param_get_double(ps, "DensityContrastLimit");
44  HydroParams.DensityIndependentSphOn= param_get_int(ps, "DensityIndependentSphOn");
45  }
46  MPI_Bcast(&HydroParams, sizeof(struct hydro_params), MPI_BYTE, 0, MPI_COMM_WORLD);
47 }
double param_get_double(ParameterSet *ps, const char *name)
Definition: paramset.c:336
int param_get_int(ParameterSet *ps, const char *name)
Definition: paramset.c:368
double DensityContrastLimit
Definition: hydra.c:30
double ArtBulkViscConst
Definition: hydra.c:32
int ThisTask
Definition: test_exchange.c:23

References hydro_params::ArtBulkViscConst, hydro_params::DensityContrastLimit, hydro_params::DensityIndependentSphOn, HydroParams, param_get_double(), param_get_int(), and ThisTask.

Referenced by read_parameter_file().

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