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

Go to the source code of this file.

Classes

struct  ActiveParticles
 
struct  DriftKickTimes
 

Typedefs

typedef struct ActiveParticles ActiveParticles
 

Functions

int rebuild_activelist (ActiveParticles *act, const DriftKickTimes *const times, int NumCurrentTiStep, const double Time)
 
void free_activelist (ActiveParticles *act)
 
double get_atime (const inttime_t Ti_Current)
 
int find_timesteps (const ActiveParticles *act, DriftKickTimes *times, const double atime, int FastParticleType, const Cosmology *CP, const double asmth, const int isFirstTimeStep)
 
void apply_half_kick (const ActiveParticles *act, Cosmology *CP, DriftKickTimes *times, const double atime, const double MinEgySpec)
 
void apply_PM_half_kick (Cosmology *CP, DriftKickTimes *times)
 
int is_timebin_active (int i, inttime_t current)
 
inttime_t find_next_kick (inttime_t Ti_Current, int minTimeBin)
 
inttime_t init_timebins (double TimeInit)
 
void update_lastactive_drift (DriftKickTimes *times)
 
DriftKickTimes init_driftkicktime (inttime_t Ti_Current)
 
int is_PM_timestep (const DriftKickTimes *const times)
 
void set_timestep_params (ParameterSet *ps)
 

Typedef Documentation

◆ ActiveParticles

Function Documentation

◆ apply_half_kick()

void apply_half_kick ( const ActiveParticles act,
Cosmology CP,
DriftKickTimes times,
const double  atime,
const double  MinEgySpec 
)

Definition at line 323 of file timestep.c.

324 {
325  int pa, bin;
326  walltime_measure("/Misc");
327  double gravkick[TIMEBINS+1] = {0}, hydrokick[TIMEBINS+1] = {0};
328  /* Do nothing for the first timestep when the kicks are always zero*/
329  if(times->mintimebin == 0 && times->maxtimebin == 0)
330  return;
331  #pragma omp parallel for
332  for(bin = times->mintimebin; bin <= TIMEBINS; bin++)
333  {
334  /* Kick the active timebins*/
335  if(is_timebin_active(bin, times->Ti_Current)) {
336  /* do the kick for half a step*/
337  inttime_t dti = dti_from_timebin(bin);
338  inttime_t newkick = times->Ti_kick[bin] + dti/2;
339  /* Compute kick factors for occupied bins*/
340  gravkick[bin] = get_exact_gravkick_factor(CP, times->Ti_kick[bin], newkick);
341  hydrokick[bin] = get_exact_hydrokick_factor(CP, times->Ti_kick[bin], newkick);
342  // message(0, "drift %d bin %d kick: %d->%d\n", times->Ti_Current, bin, times->Ti_kick[bin], newkick);
343  times->Ti_kick[bin] = newkick;
344  }
345  }
346  /* Advance the shorter bins without particles by the minimum occupied timestep.*/
347  for(bin=1; bin < times->mintimebin; bin++)
348  times->Ti_kick[bin] += dti_from_timebin(times->mintimebin)/2;
349  // message(0, "drift %d bin %d kick: %d\n", times->Ti_Current, bin, times->Ti_kick[bin]);
350  /* Now assign new timesteps and kick */
351  #pragma omp parallel for
352  for(pa = 0; pa < act->NumActiveParticle; pa++)
353  {
354  const int i = get_active_particle(act, pa);
355  if(P[i].Swallowed || P[i].IsGarbage)
356  continue;
357  int bin = P[i].TimeBin;
358  if(bin > TIMEBINS)
359  endrun(4, "Particle %d (type %d, id %ld) had unexpected timebin %d\n", i, P[i].Type, P[i].ID, P[i].TimeBin);
360 #ifdef DEBUG
361  if(isnan(gravkick[bin]) || gravkick[bin] == 0.)
362  endrun(5, "Bad kicks %lg bin %d tik %d\n", gravkick[bin], bin, times->Ti_kick[bin]);
363 #endif
364  inttime_t dti = dti_from_timebin(bin);
365  const double dt_entr = dloga_from_dti(dti/2, times->Ti_Current);
366  /*This only changes particle i, so is thread-safe.*/
367  do_the_short_range_kick(i, dt_entr, gravkick[bin], hydrokick[bin], atime, MinEgySpec);
368  }
369  walltime_measure("/Timeline/HalfKick/Short");
370 }
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
#define P
Definition: partmanager.h:88
static Cosmology * CP
Definition: power.c:27
int64_t NumActiveParticle
Definition: timestep.h:12
int maxtimebin
Definition: timestep.h:21
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 dloga_from_dti(inttime_t dti, const inttime_t Ti_Current)
Definition: timebinmgr.c:256
#define TIMEBINS
Definition: timebinmgr.h:13
static inttime_t dti_from_timebin(int bin)
Definition: timebinmgr.h:44
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
static void do_the_short_range_kick(int i, double dt_entr, double Fgravkick, double Fhydrokick, const double atime, const double MinEgySpec)
Definition: timestep.c:396
static int get_active_particle(const ActiveParticles *act, int pa)
Definition: timestep.c:68
int is_timebin_active(int i, inttime_t current)
Definition: timestep.c:149
int32_t inttime_t
Definition: types.h:8
#define walltime_measure(name)
Definition: walltime.h:8

References CP, dloga_from_dti(), do_the_short_range_kick(), dti_from_timebin(), endrun(), get_active_particle(), get_exact_gravkick_factor(), get_exact_hydrokick_factor(), is_timebin_active(), DriftKickTimes::maxtimebin, DriftKickTimes::mintimebin, ActiveParticles::NumActiveParticle, P, DriftKickTimes::Ti_Current, DriftKickTimes::Ti_kick, TIMEBINS, and walltime_measure.

Referenced by run().

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

◆ apply_PM_half_kick()

void apply_PM_half_kick ( Cosmology CP,
DriftKickTimes times 
)

Definition at line 373 of file timestep.c.

374 {
375  /*Always do a PM half-kick, because this should be called just after a PM step*/
376  const inttime_t tistart = times->PM_kick;
377  const inttime_t tiend = tistart + times->PM_length / 2;
378  /* Do long-range kick */
379  int i;
380  const double Fgravkick = get_exact_gravkick_factor(CP, tistart, tiend);
381 
382  #pragma omp parallel for
383  for(i = 0; i < PartManager->NumPart; i++)
384  {
385  int j;
386  if(P[i].Swallowed || P[i].IsGarbage)
387  continue;
388  for(j = 0; j < 3; j++) /* do the kick */
389  P[i].Vel[j] += P[i].GravPM[j] * Fgravkick;
390  }
391  times->PM_kick = tiend;
392  walltime_measure("/Timeline/HalfKick/Long");
393 }
static struct gravpm_params GravPM
struct part_manager_type PartManager[1]
Definition: partmanager.c:11
inttime_t PM_kick
Definition: timestep.h:31
inttime_t PM_length
Definition: timestep.h:29

References CP, get_exact_gravkick_factor(), GravPM, part_manager_type::NumPart, P, PartManager, DriftKickTimes::PM_kick, DriftKickTimes::PM_length, and walltime_measure.

Referenced by run().

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

◆ find_next_kick()

inttime_t find_next_kick ( inttime_t  Ti_Current,
int  minTimeBin 
)

This function finds the next synchronization point of the system (i.e. the earliest point of time any of the particles needs a force computation), and drifts the system to this point of time. If the system drifts over the desired time of a snapshot file, the function will drift to this moment, generate an output, and then resume the drift.

Definition at line 712 of file timestep.c.

713 {
714  /* Current value plus the increment for the smallest active bin. */
715  return Ti_Current + dti_from_timebin(minTimeBin);
716 }

References dti_from_timebin().

Referenced by run().

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

◆ find_timesteps()

int find_timesteps ( const ActiveParticles act,
DriftKickTimes times,
const double  atime,
int  FastParticleType,
const Cosmology CP,
const double  asmth,
const int  isFirstTimeStep 
)

Definition at line 176 of file timestep.c.

177 {
178  int pa;
179  inttime_t dti_min = TIMEBASE;
180 
181  walltime_measure("/Misc");
182 
183  /*Update the PM timestep size */
184  const int isPM = is_PM_timestep(times);
185  inttime_t dti_max = times->PM_length;
186 
187  if(isPM) {
188  dti_max = get_PM_timestep_ti(times, atime, CP, FastParticleType, asmth);
189  times->PM_length = dti_max;
190  times->PM_start = times->PM_kick;
191  }
192 
193  const double hubble = hubble_function(CP, atime);
194  /* Now assign new timesteps and kick */
196  int i;
197  #pragma omp parallel for reduction(min:dti_min)
198  for(i = 0; i < PartManager->NumPart; i++)
199  {
200  enum TimeStepType titype;
201  /* Because we don't GC on short timesteps, there can be garbage here.
202  * Avoid making it active. */
203  if(P[i].IsGarbage || P[i].Swallowed)
204  continue;
205  inttime_t dti = get_timestep_ti(i, dti_max, times->Ti_Current, atime, hubble, &titype);
206  if(dti < dti_min)
207  dti_min = dti;
208  }
209  MPI_Allreduce(MPI_IN_PLACE, &dti_min, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
210  }
211 
212  int64_t ntiaccel=0, nticourant=0, ntiaccrete=0, ntineighbour=0, ntihsml=0;
213  int badstepsizecount = 0;
214  int mTimeBin = TIMEBINS, maxTimeBin = 0;
215  #pragma omp parallel for reduction(min: mTimeBin) reduction(+: badstepsizecount, ntiaccel, nticourant, ntiaccrete, ntineighbour, ntihsml) reduction(max:maxTimeBin)
216  for(pa = 0; pa < act->NumActiveParticle; pa++)
217  {
218  const int i = get_active_particle(act, pa);
219 
220  if(P[i].IsGarbage || P[i].Swallowed)
221  continue;
222 
223  enum TimeStepType titype;
224  inttime_t dti;
226  dti = dti_min;
227  } else {
228  dti = get_timestep_ti(i, dti_max, times->Ti_Current, atime, hubble, &titype);
229  if(titype == TI_ACCEL)
230  ntiaccel++;
231  else if (titype == TI_COURANT)
232  nticourant++;
233  else if (titype == TI_ACCRETE)
234  ntiaccrete++;
235  else if (titype == TI_NEIGH)
236  ntineighbour++;
237  else if (titype == TI_HSML)
238  ntihsml++;
239  }
240 
241  /* make it a power 2 subdivision */
242  dti = round_down_power_of_two(dti);
243 
244  int bin = get_timestep_bin(dti);
245  if(bin < 1) {
246  message(1, "Time-step of integer size %d not allowed, id = %lu, debugging info follows.\n", dti, P[i].ID);
247  badstepsizecount++;
248  }
249  int binold = P[i].TimeBin;
250 
251  /* timestep wants to increase */
252  if(bin > binold)
253  {
254  /* make sure the new step is currently active,
255  * so that particles do not miss a step */
256  while(!is_timebin_active(bin, times->Ti_Current) && bin > binold && bin > 1)
257  bin--;
258  }
259  /* This moves particles between time bins:
260  * active particles always remain active
261  * until rebuild_activelist is called
262  * (after domain, on new timestep).*/
263  P[i].TimeBin = bin;
264  /*Find max and min*/
265  if(bin < mTimeBin)
266  mTimeBin = bin;
267  if(bin > maxTimeBin)
268  maxTimeBin = bin;
269  }
270 
271  MPI_Allreduce(MPI_IN_PLACE, &badstepsizecount, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
272  MPI_Allreduce(MPI_IN_PLACE, &mTimeBin, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
273  MPI_Allreduce(MPI_IN_PLACE, &maxTimeBin, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
274 
275  MPI_Allreduce(MPI_IN_PLACE, &ntiaccel, 1, MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
276  MPI_Allreduce(MPI_IN_PLACE, &nticourant, 1, MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
277  MPI_Allreduce(MPI_IN_PLACE, &ntihsml, 1, MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
278  MPI_Allreduce(MPI_IN_PLACE, &ntiaccrete, 1, MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
279  MPI_Allreduce(MPI_IN_PLACE, &ntineighbour, 1, MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
280 
281  /* Ensure that the PM timestep is not longer than the longest tree timestep;
282  * this prevents particles in the longest timestep being active and moving into a higher bin
283  * between PM timesteps, thus skipping the PM step entirely.*/
284  if(isPM && times->PM_length > dti_from_timebin(maxTimeBin))
285  times->PM_length = dti_from_timebin(maxTimeBin);
286  message(0, "PM timebin: %x (dloga: %g Max: %g). Criteria: Accel: %ld Soundspeed: %ld DivVel: %ld Accrete: %ld Neighbour: %ld\n",
288  ntiaccel, nticourant, ntihsml, ntiaccrete, ntineighbour);
289 
290  /* BH particles have their timesteps set by a timestep limiter.
291  * On the first timestep this is not effective because all the particles have zero timestep.
292  * So on the first timestep only set all BH particles to the smallest allowable timestep*/
293  if(isFirstTimeStep) {
294  #pragma omp parallel for
295  for(pa = 0; pa < PartManager->NumPart; pa++)
296  {
297  if(P[pa].Type == 5)
298  P[pa].TimeBin = mTimeBin;
299  }
300  }
301  walltime_measure("/Timeline");
302  times->mintimebin = mTimeBin;
303  times->maxtimebin = maxTimeBin;
304  return badstepsizecount;
305 }
double hubble_function(const Cosmology *CP, double a)
Definition: cosmology.c:58
void message(int where, const char *fmt,...)
Definition: endrun.c:175
inttime_t PM_start
Definition: timestep.h:30
double MaxSizeTimestep
Definition: timestep.c:36
int ForceEqualTimesteps
Definition: timestep.c:33
#define MPI_INT64
Definition: system.h:12
inttime_t round_down_power_of_two(inttime_t dti)
Definition: timebinmgr.c:286
#define TIMEBASE
Definition: timebinmgr.h:14
int is_PM_timestep(const DriftKickTimes *const times)
Definition: timestep.c:160
static struct timestep_params TimestepParams
static inttime_t get_PM_timestep_ti(const DriftKickTimes *const times, const double atime, const Cosmology *CP, const int FastParticleType, const double asmth)
Definition: timestep.c:667
static inttime_t get_timestep_ti(const int p, const inttime_t dti_max, const inttime_t Ti_Current, const double atime, const double hubble, enum TimeStepType *titype)
Definition: timestep.c:537
static int get_timestep_bin(inttime_t dti)
Definition: timestep.c:686
TimeStepType
Definition: timestep.c:107
@ TI_NEIGH
Definition: timestep.c:111
@ TI_COURANT
Definition: timestep.c:109
@ TI_ACCEL
Definition: timestep.c:108
@ TI_ACCRETE
Definition: timestep.c:110
@ TI_HSML
Definition: timestep.c:112

References CP, dloga_from_dti(), dti_from_timebin(), timestep_params::ForceEqualTimesteps, get_active_particle(), get_PM_timestep_ti(), get_timestep_bin(), get_timestep_ti(), hubble_function(), is_PM_timestep(), is_timebin_active(), timestep_params::MaxSizeTimestep, DriftKickTimes::maxtimebin, message(), DriftKickTimes::mintimebin, MPI_INT64, ActiveParticles::NumActiveParticle, part_manager_type::NumPart, P, PartManager, DriftKickTimes::PM_kick, DriftKickTimes::PM_length, DriftKickTimes::PM_start, round_down_power_of_two(), TI_ACCEL, TI_ACCRETE, TI_COURANT, DriftKickTimes::Ti_Current, TI_HSML, TI_NEIGH, TIMEBASE, TIMEBINS, TimestepParams, and walltime_measure.

Referenced by run().

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

◆ free_activelist()

void free_activelist ( ActiveParticles act)

Definition at line 795 of file timestep.c.

796 {
797  if(act->ActiveParticle) {
798  myfree(act->ActiveParticle);
799  }
801 }
int event_unlisten(EventSpec *eh, eventfunc func, void *userdata)
Definition: event.c:26
EventSpec EventSlotsFork
Definition: event.c:54
#define myfree(x)
Definition: mymalloc.h:19
int * ActiveParticle
Definition: timestep.h:13
static int timestep_eh_slots_fork(EIBase *event, void *userdata)
Definition: timestep.c:77

References ActiveParticles::ActiveParticle, event_unlisten(), EventSlotsFork, myfree, and timestep_eh_slots_fork().

Referenced by run().

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

◆ get_atime()

double get_atime ( const inttime_t  Ti_Current)

Definition at line 168 of file timestep.c.

168  {
169  return exp(loga_from_ti(Ti_Current));
170 }
double loga_from_ti(int ti)
Definition: test_timefac.c:51

References loga_from_ti().

Referenced by run().

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

◆ init_driftkicktime()

DriftKickTimes init_driftkicktime ( inttime_t  Ti_Current)

Definition at line 133 of file timestep.c.

134 {
135  DriftKickTimes times = {0};
136  times.Ti_Current = Ti_Current;
137  int i;
138  for(i = 0; i <= TIMEBINS; i++) {
139  times.Ti_kick[i] = times.Ti_Current;
140  times.Ti_lastactivedrift[i] = times.Ti_Current;
141  }
142  /* this makes sure the first step is a PM step. */
143  times.PM_length = 0;
144  times.PM_kick = times.Ti_Current;
145  times.PM_start = times.Ti_Current;
146  return times;
147 }
inttime_t Ti_lastactivedrift[TIMEBINS+1]
Definition: timestep.h:25

References DriftKickTimes::PM_kick, DriftKickTimes::PM_length, DriftKickTimes::PM_start, DriftKickTimes::Ti_Current, DriftKickTimes::Ti_kick, DriftKickTimes::Ti_lastactivedrift, and TIMEBINS.

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

Here is the caller graph for this function:

◆ init_timebins()

inttime_t init_timebins ( double  TimeInit)

Definition at line 123 of file timestep.c.

124 {
125  inttime_t Ti_Current = ti_from_loga(log(TimeInit));
126  /*Enforce Ti_Current is initially even*/
127  if(Ti_Current % 2 == 1)
128  Ti_Current++;
129  message(0, "Initial TimeStep at TimeInit %g Ti_Current = %d \n", TimeInit, Ti_Current);
130  return Ti_Current;
131 }
inttime_t ti_from_loga(double loga)
Definition: timebinmgr.c:236

References message(), and ti_from_loga().

Referenced by init().

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

◆ is_PM_timestep()

int is_PM_timestep ( const DriftKickTimes *const  times)

Definition at line 160 of file timestep.c.

161 {
162  if(times->Ti_Current > times->PM_start + times->PM_length)
163  endrun(12, "Passed end of PM step! ti=%d, PM = %d + %d\n",times->Ti_Current, times->PM_start, times->PM_length);
164  return times->Ti_Current == times->PM_start + times->PM_length;
165 }

References endrun(), DriftKickTimes::PM_length, DriftKickTimes::PM_start, and DriftKickTimes::Ti_Current.

Referenced by find_timesteps(), print_timebin_statistics(), rebuild_activelist(), and run().

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

◆ is_timebin_active()

int is_timebin_active ( int  i,
inttime_t  current 
)

Definition at line 149 of file timestep.c.

149  {
150  /*Bin 0 is always active and at time 0 all bins are active*/
151  if(i <= 0 || current <= 0)
152  return 1;
153  if(current % dti_from_timebin(i) == 0)
154  return 1;
155  return 0;
156 }

References dti_from_timebin().

Referenced by apply_half_kick(), find_timesteps(), hydro_force(), print_timebin_statistics(), rebuild_activelist(), run(), timestep_eh_slots_fork(), and update_lastactive_drift().

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

◆ rebuild_activelist()

int rebuild_activelist ( ActiveParticles act,
const DriftKickTimes *const  times,
int  NumCurrentTiStep,
const double  Time 
)

Definition at line 721 of file timestep.c.

722 {
723  int i;
724 
725  int NumThreads = omp_get_max_threads();
726  /*Since we use a static schedule, only need NumPart/NumThreads elements per thread.*/
727  size_t narr = PartManager->NumPart / NumThreads + NumThreads;
728 
729  /*We know all particles are active on a PM timestep*/
730  if(is_PM_timestep(times)) {
731  act->ActiveParticle = NULL;
733  }
734  else {
735  /*Need space for more particles than we have, because of star formation*/
736  act->ActiveParticle = (int *) mymalloc("ActiveParticle", narr * NumThreads * sizeof(int));
737  act->NumActiveParticle = 0;
738  }
739 
740  int * TimeBinCountType = (int *) mymalloc("TimeBinCountType", 6*(TIMEBINS+1)*NumThreads * sizeof(int));
741  memset(TimeBinCountType, 0, 6 * (TIMEBINS+1) * NumThreads * sizeof(int));
742 
743  /*We want a lockless algorithm which preserves the ordering of the particle list.*/
744  size_t *NActiveThread = ta_malloc("NActiveThread", size_t, NumThreads);
745  int **ActivePartSets = ta_malloc("ActivePartSets", int *, NumThreads);
746  gadget_setup_thread_arrays(act->ActiveParticle, ActivePartSets, NActiveThread, narr, NumThreads);
747 
748  /* We enforce schedule static to imply monotonic, ensure that each thread executes on contiguous particles
749  * and ensure no thread gets more than narr particles.*/
750  size_t schedsz = PartManager->NumPart / NumThreads + 1;
751  #pragma omp parallel for schedule(static, schedsz)
752  for(i = 0; i < PartManager->NumPart; i++)
753  {
754  const int bin = P[i].TimeBin;
755  const int tid = omp_get_thread_num();
756  if(P[i].IsGarbage || P[i].Swallowed)
757  continue;
758  /* when we are in PM, all particles must have been synced. */
759  if (P[i].Ti_drift != times->Ti_Current) {
760  endrun(5, "Particle %d type %d has drift time %x not ti_current %x!",i, P[i].Type, P[i].Ti_drift, times->Ti_Current);
761  }
762 
763  if(act->ActiveParticle && is_timebin_active(bin, times->Ti_Current))
764  {
765  /* Store this particle in the ActiveSet for this thread*/
766  ActivePartSets[tid][NActiveThread[tid]] = i;
767  NActiveThread[tid]++;
768  }
769  TimeBinCountType[(TIMEBINS + 1) * (6* tid + P[i].Type) + bin] ++;
770  }
771  if(act->ActiveParticle) {
772  /*Now we want a merge step for the ActiveParticle list.*/
773  act->NumActiveParticle = gadget_compact_thread_arrays(act->ActiveParticle, ActivePartSets, NActiveThread, NumThreads);
774  }
775  ta_free(ActivePartSets);
776  ta_free(NActiveThread);
777 
778  /*Print statistics for this time bin*/
779  print_timebin_statistics(times, NumCurrentTiStep, TimeBinCountType, Time);
780  myfree(TimeBinCountType);
781 
782  /* Shrink the ActiveParticle array. We still need extra space for star formation,
783  * but we do not need space for the known-inactive particles*/
784  if(act->ActiveParticle) {
785  act->ActiveParticle = (int *) myrealloc(act->ActiveParticle, sizeof(int)*(act->NumActiveParticle + PartManager->MaxPart - PartManager->NumPart));
787  /* listen to the slots events such that we can set timebin of new particles */
788  }
790  walltime_measure("/Timeline/Active");
791 
792  return 0;
793 }
int event_listen(EventSpec *eh, eventfunc func, void *userdata)
Definition: event.c:6
#define mymalloc(name, size)
Definition: mymalloc.h:15
#define ta_malloc(name, type, nele)
Definition: mymalloc.h:25
#define myrealloc(ptr, size)
Definition: mymalloc.h:18
#define ta_free(p)
Definition: mymalloc.h:28
int64_t MaxActiveParticle
Definition: timestep.h:11
void gadget_setup_thread_arrays(int *dest, int *srcs[], size_t sizes[], size_t total_size, int narrays)
Definition: system.c:600
size_t gadget_compact_thread_arrays(int *dest, int *srcs[], size_t sizes[], int narrays)
Definition: system.c:587
static void print_timebin_statistics(const DriftKickTimes *const times, const int NumCurrentTiStep, int *TimeBinCountType, const double Time)
Definition: timestep.c:807

References ActiveParticles::ActiveParticle, endrun(), event_listen(), EventSlotsFork, gadget_compact_thread_arrays(), gadget_setup_thread_arrays(), is_PM_timestep(), is_timebin_active(), ActiveParticles::MaxActiveParticle, part_manager_type::MaxPart, myfree, mymalloc, myrealloc, ActiveParticles::NumActiveParticle, part_manager_type::NumPart, P, PartManager, print_timebin_statistics(), ta_free, ta_malloc, DriftKickTimes::Ti_Current, TIMEBINS, timestep_eh_slots_fork(), and walltime_measure.

Referenced by run(), and run_gravity_test().

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

◆ set_timestep_params()

void set_timestep_params ( ParameterSet ps)

Definition at line 51 of file timestep.c.

52 {
53  int ThisTask;
54  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
55  if(ThisTask == 0) {
56  TimestepParams.ErrTolIntAccuracy = param_get_double(ps, "ErrTolIntAccuracy");
57  TimestepParams.MaxGasVel = param_get_double(ps, "MaxGasVel");
58  TimestepParams.MaxSizeTimestep = param_get_double(ps, "MaxSizeTimestep");
59 
60  TimestepParams.MinSizeTimestep = param_get_double(ps, "MinSizeTimestep");
61  TimestepParams.ForceEqualTimesteps = param_get_int(ps, "ForceEqualTimesteps");
62  TimestepParams.MaxRMSDisplacementFac = param_get_double(ps, "MaxRMSDisplacementFac");
63  TimestepParams.CourantFac = param_get_double(ps, "CourantFac");
64  }
65  MPI_Bcast(&TimestepParams, sizeof(struct timestep_params), MPI_BYTE, 0, MPI_COMM_WORLD);
66 }
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 MaxGasVel
Definition: timestep.c:45
double MinSizeTimestep
Definition: timestep.c:35
double MaxRMSDisplacementFac
Definition: timestep.c:38
double ErrTolIntAccuracy
Definition: timestep.c:30
double CourantFac
Definition: timestep.c:46
int ThisTask
Definition: test_exchange.c:23

References timestep_params::CourantFac, timestep_params::ErrTolIntAccuracy, timestep_params::ForceEqualTimesteps, timestep_params::MaxGasVel, timestep_params::MaxRMSDisplacementFac, timestep_params::MaxSizeTimestep, timestep_params::MinSizeTimestep, param_get_double(), param_get_int(), ThisTask, and TimestepParams.

Referenced by read_parameter_file().

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

◆ update_lastactive_drift()

void update_lastactive_drift ( DriftKickTimes times)

Definition at line 309 of file timestep.c.

310 {
311  int bin;
312  #pragma omp parallel for
313  for(bin = 0; bin <= TIMEBINS; bin++)
314  {
315  /* Update active timestep even if no particles in it*/
316  if(is_timebin_active(bin, times->Ti_Current))
317  times->Ti_lastactivedrift[bin] = times->Ti_Current;
318  }
319 }

References is_timebin_active(), DriftKickTimes::Ti_Current, DriftKickTimes::Ti_lastactivedrift, and TIMEBINS.

Referenced by run().

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