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

Go to the source code of this file.

Classes

struct  SyncPoint
 

Macros

#define TIMEBINS   20
 
#define TIMEBASE   (1u<<TIMEBINS)
 
#define MAXSNAPSHOTS   (1u<<(30-TIMEBINS))
 

Typedefs

typedef struct SyncPoint SyncPoint
 

Functions

double loga_from_ti (inttime_t ti)
 
inttime_t ti_from_loga (double loga)
 
inttime_t dti_from_dloga (double loga, const inttime_t Ti_Current)
 
double dloga_from_dti (inttime_t dti, const inttime_t Ti_Current)
 
double get_dloga_for_bin (int timebin, const inttime_t Ti_Current)
 
static inttime_t dti_from_timebin (int bin)
 
inttime_t round_down_power_of_two (inttime_t ti)
 
inttime_t find_next_outputtime (inttime_t ti_curr)
 
inttime_t out_from_ti (inttime_t ti)
 
int OutputListAction (ParameterSet *ps, const char *name, void *data)
 
void set_sync_params (int OutputListLength, double *OutputListTimes)
 
void setup_sync_points (double TimeIC, double TimeMax, double no_snapshot_until_time, int SnapshotWithFOF)
 
SyncPointfind_next_sync_point (inttime_t ti)
 
SyncPointfind_current_sync_point (inttime_t ti)
 
SyncPointmake_unplanned_sync_point (inttime_t ti)
 

Macro Definition Documentation

◆ MAXSNAPSHOTS

#define MAXSNAPSHOTS   (1u<<(30-TIMEBINS))

Definition at line 15 of file timebinmgr.h.

◆ TIMEBASE

#define TIMEBASE   (1u<<TIMEBINS)

Definition at line 14 of file timebinmgr.h.

◆ TIMEBINS

#define TIMEBINS   20

< The simulated timespan is mapped onto the integer interval [0,TIMEBASE], where TIMEBASE needs to be a power of 2. Note that (1<<28) corresponds to 2^29. We allow some bits at the top of the integer timeline for snapshot outputs. Note that because each snapshot uses TIMEBASE on the integer timeline, the conversion factor between loga and ti is not constant across snapshots.

Definition at line 13 of file timebinmgr.h.

Typedef Documentation

◆ SyncPoint

typedef struct SyncPoint SyncPoint

Definition at line 1 of file timebinmgr.h.

Function Documentation

◆ dloga_from_dti()

double dloga_from_dti ( inttime_t  dti,
const inttime_t  Ti_Current 
)

Definition at line 256 of file timebinmgr.c.

257 {
258  double Dloga = Dloga_interval_ti(Ti_Current);
259  int sign = 1;
260  if(dti < 0) {
261  dti = -dti;
262  sign = -1;
263  }
264  if((unsigned int) dti > TIMEBASE) {
265  endrun(1, "Requesting dti %d larger than TIMEBASE %u\n", sign*dti, TIMEBASE);
266  }
267  return Dloga * dti * sign;
268 }
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
static double Dloga_interval_ti(inttime_t ti)
Definition: timebinmgr.c:207
#define TIMEBASE
Definition: timebinmgr.h:14

References Dloga_interval_ti(), endrun(), and TIMEBASE.

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

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

◆ dti_from_dloga()

inttime_t dti_from_dloga ( double  loga,
const inttime_t  Ti_Current 
)

Definition at line 271 of file timebinmgr.c.

272 {
273  inttime_t ti = ti_from_loga(loga_from_ti(Ti_Current));
274  inttime_t tip = ti_from_loga(loga+loga_from_ti(Ti_Current));
275  return tip - ti;
276 }
inttime_t ti_from_loga(double loga)
Definition: timebinmgr.c:236
double loga_from_ti(inttime_t ti)
Definition: timebinmgr.c:223
int32_t inttime_t
Definition: types.h:8

References loga_from_ti(), and ti_from_loga().

Referenced by get_PM_timestep_ti(), and get_timestep_ti().

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

◆ dti_from_timebin()

static inttime_t dti_from_timebin ( int  bin)
inlinestatic

Definition at line 44 of file timebinmgr.h.

44  {
45  /*Casts to work around bug in intel compiler 18.0*/
46  return bin > 0 ? (1u << (unsigned) bin) : 0;
47 }

Referenced by apply_half_kick(), cooling_direct(), find_next_kick(), find_timesteps(), and is_timebin_active().

Here is the caller graph for this function:

◆ find_current_sync_point()

SyncPoint* find_current_sync_point ( inttime_t  ti)

Definition at line 188 of file timebinmgr.c.

189 {
190  int i;
191  for(i = 0; i < NSyncPoints; i ++) {
192  if(SyncPoints[i].ti == ti) {
193  return &SyncPoints[i];
194  }
195  }
196  return NULL;
197 }
static int NSyncPoints
Definition: timebinmgr.c:10
static SyncPoint * SyncPoints
Definition: timebinmgr.c:9

References NSyncPoints, and SyncPoints.

Referenced by run(), test_conversions(), and test_skip_first().

Here is the caller graph for this function:

◆ find_next_outputtime()

inttime_t find_next_outputtime ( inttime_t  ti_curr)

this function returns the next output time after ti_curr.

◆ find_next_sync_point()

SyncPoint* find_next_sync_point ( inttime_t  ti)

this function returns the next output time that is in the future of ti_curr; if none is find it return NULL, indication the run shall terminate.

Definition at line 174 of file timebinmgr.c.

175 {
176  int i;
177  for(i = 0; i < NSyncPoints; i ++) {
178  if(SyncPoints[i].ti > ti) {
179  return &SyncPoints[i];
180  }
181  }
182  return NULL;
183 }

References NSyncPoints, and SyncPoints.

Referenced by get_PM_timestep_ti(), run(), and test_conversions().

Here is the caller graph for this function:

◆ get_dloga_for_bin()

double get_dloga_for_bin ( int  timebin,
const inttime_t  Ti_Current 
)

Definition at line 279 of file timebinmgr.c.

280 {
281  double logDTime = Dloga_interval_ti(Ti_Current);
282  return (timebin > 0 ? (1u << (unsigned) timebin) : 0 ) * logDTime;
283 }

References Dloga_interval_ti().

Referenced by blackhole_accretion_postprocess(), blackhole_feedback_copy(), cooling_direct(), get_helium_neutral_fraction_sfreff(), get_neutral_fraction_sfreff(), get_sfr_eeqos(), get_timestep_dloga(), hydro_copy(), hydro_ngbiter(), print_timebin_statistics(), run(), sfr_wind_copy(), test_dloga(), and winds_evolve().

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

◆ loga_from_ti()

double loga_from_ti ( inttime_t  ti)

Definition at line 223 of file timebinmgr.c.

224 {
225  inttime_t lastsnap = ti >> TIMEBINS;
226  if(lastsnap > NSyncPoints) {
227  endrun(1, "Requesting snap %d, from ti %d, beyond last sync point %d\n", lastsnap, ti, NSyncPoints);
228  }
229  double last = SyncPoints[lastsnap].loga;
230  inttime_t dti = ti & (TIMEBASE - 1);
231  double logDTime = Dloga_interval_ti(ti);
232  return last + dti * logDTime;
233 }
double loga
Definition: timebinmgr.h:25
#define TIMEBINS
Definition: timebinmgr.h:13

References Dloga_interval_ti(), endrun(), SyncPoint::loga, NSyncPoints, SyncPoints, TIMEBASE, and TIMEBINS.

Referenced by dti_from_dloga().

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

◆ make_unplanned_sync_point()

SyncPoint* make_unplanned_sync_point ( inttime_t  ti)

◆ out_from_ti()

inttime_t out_from_ti ( inttime_t  ti)

◆ OutputListAction()

int OutputListAction ( ParameterSet ps,
const char *  name,
void *  data 
)

This function parses a string containing a comma-separated list of variables, each of which is interpreted as a double. The purpose is to read an array of output times into the code. So specifying the output list now looks like: OutputList 0.1,0.3,0.5,1.0

We sort the input after reading it, so that the initial list need not be sorted. This function could be repurposed for reading generic arrays in future.

Definition at line 31 of file timebinmgr.c.

32 {
33  char * outputlist = param_get_string(ps, name);
34  char * strtmp = fastpm_strdup(outputlist);
35  char * token;
36  int count;
37 
38  /* Note TimeInit and TimeMax not yet initialised here*/
39 
40  /*First parse the string to get the number of outputs*/
41  for(count=0, token=strtok(strtmp,","); token; count++, token=strtok(NULL, ","))
42  {}
43 /* message(1, "Found %d times in output list.\n", count); */
44 
45  /*Allocate enough memory*/
46  Sync.OutputListLength = count;
47  int maxcount = sizeof(Sync.OutputListTimes) / sizeof(Sync.OutputListTimes[0]);
48  if(maxcount > (int) MAXSNAPSHOTS)
49  maxcount = MAXSNAPSHOTS;
50  if(Sync.OutputListLength > maxcount) {
51  message(1, "Too many entries (%d) in the OutputList, can take no more than %d.\n", Sync.OutputListLength, maxcount);
52  return 1;
53  }
54  /*Now read in the values*/
55  for(count=0,token=strtok(outputlist,","); count < Sync.OutputListLength && token; count++, token=strtok(NULL,","))
56  {
57  /* Skip a leading quote if one exists.
58  * Extra characters are ignored by atof, so
59  * no need to skip matching char.*/
60  if(token[0] == '"')
61  token+=1;
62 
63  double a = atof(token);
64 
65  if(a < 0.0) {
66  endrun(1, "Requesting a negative output scaling factor a = %g\n", a);
67  }
68  Sync.OutputListTimes[count] = a;
69 /* message(1, "Output at: %g\n", Sync.OutputListTimes[count]); */
70  }
71  myfree(strtmp);
72  return 0;
73 }
const char * name
Definition: densitykernel.c:93
void message(int where, const char *fmt,...)
Definition: endrun.c:175
#define myfree(x)
Definition: mymalloc.h:19
char * param_get_string(ParameterSet *ps, const char *name)
Definition: paramset.c:346
char * fastpm_strdup(const char *str)
Definition: string.c:31
int OutputListLength
Definition: timebinmgr.c:13
double OutputListTimes[1024]
Definition: timebinmgr.c:14
static struct sync_params Sync
#define MAXSNAPSHOTS
Definition: timebinmgr.h:15

References endrun(), fastpm_strdup(), MAXSNAPSHOTS, message(), myfree, name, sync_params::OutputListLength, sync_params::OutputListTimes, param_get_string(), and Sync.

Referenced by create_gadget_parameter_set().

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

◆ round_down_power_of_two()

inttime_t round_down_power_of_two ( inttime_t  ti)

Definition at line 286 of file timebinmgr.c.

287 {
288  /* make dti a power 2 subdivision */
289  inttime_t ti_min = TIMEBASE;
290  int sign = 1;
291  if(dti < 0) {
292  dti = -dti;
293  sign = -1;
294  }
295  while(ti_min > dti)
296  ti_min >>= 1;
297  return ti_min * sign;
298 }

References TIMEBASE.

Referenced by find_timesteps(), get_PM_timestep_ti(), init_timeline(), and test_dloga().

Here is the caller graph for this function:

◆ set_sync_params()

void set_sync_params ( int  OutputListLength,
double *  OutputListTimes 
)

Definition at line 76 of file timebinmgr.c.

77 {
78  int i;
80  for(i = 0; i < OutputListLength; i++)
81  Sync.OutputListTimes[i] = OutputListTimes[i];
82 }
#define OutputListLength

References OutputListLength, sync_params::OutputListLength, sync_params::OutputListTimes, and Sync.

Referenced by setup().

Here is the caller graph for this function:

◆ setup_sync_points()

void setup_sync_points ( double  TimeIC,
double  TimeMax,
double  no_snapshot_until_time,
int  SnapshotWithFOF 
)

Definition at line 97 of file timebinmgr.c.

98 {
99  int i;
100 
102 
103  if(NSyncPoints > 0)
105  SyncPoints = (SyncPoint *) mymalloc("SyncPoints", sizeof(SyncPoint) * (Sync.OutputListLength+2));
106 
107  /* Set up first and last entry to SyncPoints; TODO we can insert many more! */
108 
109  SyncPoints[0].a = TimeIC;
110  SyncPoints[0].loga = log(TimeIC);
111  SyncPoints[0].write_snapshot = 0; /* by default no output here. */
112  SyncPoints[0].write_fof = 0;
113  SyncPoints[1].a = TimeMax;
114  SyncPoints[1].loga = log(TimeMax);
115  SyncPoints[1].write_snapshot = 1;
116  if(SnapshotWithFOF)
117  SyncPoints[1].write_fof = 1;
118  else
119  SyncPoints[1].write_fof = 0;
120  NSyncPoints = 2;
121 
122  /* we do an insertion sort here. A heap is faster but who cares the speed for this? */
123  for(i = 0; i < Sync.OutputListLength; i ++) {
124  int j = 0;
125  double a = Sync.OutputListTimes[i];
126  double loga = log(a);
127 
128  for(j = 0; j < NSyncPoints; j ++) {
129  if(a <= SyncPoints[j].a) {
130  break;
131  }
132  }
133  if(j == NSyncPoints) {
134  /* beyond TimeMax, skip */
135  continue;
136  }
137  /* found, so loga >= SyncPoints[j].loga */
138  if(a == SyncPoints[j].a) {
139  /* requesting output on an existing entry, e.g. TimeInit or duplicated entry */
140  } else {
141  /* insert the item; */
142  memmove(&SyncPoints[j + 1], &SyncPoints[j],
143  sizeof(SyncPoints[0]) * (NSyncPoints - j));
144  SyncPoints[j].a = a;
145  SyncPoints[j].loga = loga;
146  NSyncPoints ++;
147  }
148  if(SyncPoints[j].a > no_snapshot_until_time) {
149  SyncPoints[j].write_snapshot = 1;
150  if(SnapshotWithFOF) {
151  SyncPoints[j].write_fof = 1;
152  }
153  else
154  SyncPoints[j].write_fof = 0;
155  } else {
156  SyncPoints[j].write_snapshot = 0;
157  SyncPoints[j].write_fof = 0;
158  }
159  }
160 
161  for(i = 0; i < NSyncPoints; i++) {
162  SyncPoints[i].ti = (i * 1L) << (TIMEBINS);
163  }
164 
165 /* for(i = 0; i < NSyncPoints; i++) { */
166 /* message(1,"Out: %g %ld\n", exp(SyncPoints[i].loga), SyncPoints[i].ti); */
167 /* } */
168 }
#define mymalloc(name, size)
Definition: mymalloc.h:15
inttime_t ti
Definition: timebinmgr.h:28
double a
Definition: timebinmgr.h:24
int write_fof
Definition: timebinmgr.h:27
int write_snapshot
Definition: timebinmgr.h:26
#define qsort_openmp
Definition: test_exchange.c:14
int cmp_double(const void *a, const void *b)
Definition: timebinmgr.c:17

References SyncPoint::a, cmp_double(), SyncPoint::loga, myfree, mymalloc, NSyncPoints, sync_params::OutputListLength, sync_params::OutputListTimes, qsort_openmp, Sync, SyncPoints, SyncPoint::ti, TIMEBINS, SyncPoint::write_fof, and SyncPoint::write_snapshot.

Referenced by init_timeline(), setup_density(), test_conversions(), test_dloga(), and test_skip_first().

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

◆ ti_from_loga()

inttime_t ti_from_loga ( double  loga)

Definition at line 236 of file timebinmgr.c.

237 {
238  int i;
239  int ti;
240  /* First syncpoint is simulation start*/
241  for(i = 1; i < NSyncPoints - 1; i++)
242  {
243  if(SyncPoints[i].loga > loga)
244  break;
245  }
246  /*If loop didn't trigger, i == All.NSyncPointTimes-1*/
247  double logDTime = (SyncPoints[i].loga - SyncPoints[i-1].loga)/TIMEBASE;
248  ti = (i-1) << TIMEBINS;
249  /* Note this means if we overrun the end of the timeline,
250  * we still get something reasonable*/
251  ti += (loga - SyncPoints[i-1].loga)/logDTime;
252  return ti;
253 }

References SyncPoint::loga, NSyncPoints, SyncPoints, TIMEBASE, and TIMEBINS.

Referenced by dti_from_dloga(), init_timebins(), init_timeline(), test_conversions(), and test_dloga().

Here is the caller graph for this function: