active.h 11.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*******************************************************************************
 * This file is part of SWIFT.
 * Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/
#ifndef SWIFT_ACTIVE_H
#define SWIFT_ACTIVE_H

/* Config parameters. */
#include "../config.h"

/* Local includes. */
#include "cell.h"
#include "engine.h"
#include "part.h"
29
#include "timeline.h"
30

31
/**
32
 * @brief Check that the #part in a #cell have been drifted to the current time.
33
34
35
 *
 * @param c The #cell.
 * @param e The #engine containing information about the current time.
36
 * @return 1 if the #cell has been drifted to the current time, 0 otherwise.
37
 */
38
__attribute__((always_inline)) INLINE static int cell_are_part_drifted(
39
40
41
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
42
  if (c->ti_old_part > e->ti_current)
43
    error(
44
45
        "Cell has been drifted too far forward in time! c->ti_old=%lld (t=%e) "
        "and e->ti_current=%lld (t=%e)",
46
        c->ti_old_part, c->ti_old_part * e->timeBase, e->ti_current,
Pedro Gonnet's avatar
Pedro Gonnet committed
47
        e->ti_current * e->timeBase);
48
#endif
Matthieu Schaller's avatar
Matthieu Schaller committed
49

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  return (c->ti_old_part == e->ti_current);
}

/**
 * @brief Check that the #gpart in a #cell have been drifted to the current
 * time.
 *
 * @param c The #cell.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #cell has been drifted to the current time, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int cell_are_gpart_drifted(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->ti_old_gpart > e->ti_current)
    error(
        "Cell has been drifted too far forward in time! c->ti_old=%lld (t=%e) "
        "and e->ti_current=%lld (t=%e)",
        c->ti_old_gpart, c->ti_old_gpart * e->timeBase, e->ti_current,
        e->ti_current * e->timeBase);
#endif

  return (c->ti_old_gpart == e->ti_current);
74
75
}

76
77
/* Are cells / particles active for regular tasks ? */

78
/**
79
 * @brief Does a cell contain any particle finishing their time-step now ?
80
81
82
 *
 * @param c The #cell.
 * @param e The #engine containing information about the current time.
Matthieu Schaller's avatar
Matthieu Schaller committed
83
 * @return 1 if the #cell contains at least an active particle, 0 otherwise.
84
 */
85
__attribute__((always_inline)) INLINE static int cell_is_active_hydro(
86
87
    const struct cell *c, const struct engine *e) {

88
#ifdef SWIFT_DEBUG_CHECKS
89
  if (c->ti_hydro_end_min < e->ti_current)
90
    error(
91
92
        "cell in an impossible time-zone! c->ti_end_min=%lld (t=%e) and "
        "e->ti_current=%lld (t=%e)",
93
        c->ti_hydro_end_min, c->ti_hydro_end_min * e->timeBase, e->ti_current,
Pedro Gonnet's avatar
Pedro Gonnet committed
94
        e->ti_current * e->timeBase);
95
96
#endif

97
  return (c->ti_hydro_end_min == e->ti_current);
98
99
100
}

/**
101
 * @brief Are *all* particles in a cell finishing their time-step now ?
102
103
104
 *
 * @param c The #cell.
 * @param e The #engine containing information about the current time.
Matthieu Schaller's avatar
Matthieu Schaller committed
105
 * @return 1 if all particles in a #cell are active, 0 otherwise.
106
 */
107
__attribute__((always_inline)) INLINE static int cell_is_all_active_hydro(
108
109
    const struct cell *c, const struct engine *e) {

110
#ifdef SWIFT_DEBUG_CHECKS
111
  if (c->ti_hydro_end_max < e->ti_current)
112
113
114
    error(
        "cell in an impossible time-zone! c->ti_end_max=%lld "
        "e->ti_current=%lld",
115
        c->ti_hydro_end_max, e->ti_current);
116
117
#endif

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
  return (c->ti_hydro_end_max == e->ti_current);
}

/**
 * @brief Does a cell contain any g-particle finishing their time-step now ?
 *
 * @param c The #cell.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #cell contains at least an active particle, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int cell_is_active_gravity(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->ti_gravity_end_min < e->ti_current)
    error(
        "cell in an impossible time-zone! c->ti_end_min=%lld (t=%e) and "
        "e->ti_current=%lld (t=%e)",
        c->ti_gravity_end_min, c->ti_gravity_end_min * e->timeBase,
        e->ti_current, e->ti_current * e->timeBase);
#endif

  return (c->ti_gravity_end_min == e->ti_current);
}

/**
 * @brief Are *all* g-particles in a cell finishing their time-step now ?
 *
 * @param c The #cell.
 * @param e The #engine containing information about the current time.
 * @return 1 if all particles in a #cell are active, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int cell_is_all_active_gravity(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->ti_gravity_end_max < e->ti_current)
    error(
        "cell in an impossible time-zone! c->ti_end_max=%lld "
        "e->ti_current=%lld",
        c->ti_gravity_end_max, e->ti_current);
#endif

  return (c->ti_gravity_end_max == e->ti_current);
162
163
164
}

/**
165
 * @brief Is this particle finishing its time-step now ?
166
167
168
 *
 * @param p The #part.
 * @param e The #engine containing information about the current time.
169
 * @return 1 if the #part is active, 0 otherwise.
170
171
172
173
 */
__attribute__((always_inline)) INLINE static int part_is_active(
    const struct part *p, const struct engine *e) {

174
175
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t part_bin = p->time_bin;
176

177
#ifdef SWIFT_DEBUG_CHECKS
178
179
  const integertime_t ti_current = e->ti_current;
  const integertime_t ti_end = get_integer_time_end(ti_current, p->time_bin);
180
181
182
183
184
  if (ti_end < ti_current)
    error(
        "particle in an impossible time-zone! p->ti_end=%lld "
        "e->ti_current=%lld",
        ti_end, ti_current);
185
186
#endif

187
  return (part_bin <= max_active_bin);
188
189
}

190
191
192
193
194
195
196
197
__attribute__((always_inline)) INLINE static int part_is_active_no_debug(
    const struct part *p, const timebin_t max_active_bin) {

  const timebin_t part_bin = p->time_bin;

  return (part_bin <= max_active_bin);
}

198
/**
199
 * @brief Is this g-particle finishing its time-step now ?
200
201
202
 *
 * @param gp The #gpart.
 * @param e The #engine containing information about the current time.
203
 * @return 1 if the #gpart is active, 0 otherwise.
204
205
206
207
 */
__attribute__((always_inline)) INLINE static int gpart_is_active(
    const struct gpart *gp, const struct engine *e) {

208
209
210
211
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t gpart_bin = gp->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
212
213
214
215
  const integertime_t ti_current = e->ti_current;
  const integertime_t ti_end = get_integer_time_end(ti_current, gp->time_bin);

  if (ti_end < ti_current)
216
    error(
217
218
219
        "g-particle in an impossible time-zone! gp->ti_end=%lld "
        "e->ti_current=%lld",
        ti_end, ti_current);
220
221
#endif

222
  return (gpart_bin <= max_active_bin);
223
224
}

225
/**
Matthieu Schaller's avatar
Matthieu Schaller committed
226
 * @brief Is this s-particle finishing its time-step now ?
227
228
229
230
231
232
233
234
 *
 * @param sp The #spart.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #spart is active, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int spart_is_active(
    const struct spart *sp, const struct engine *e) {

235
236
237
238
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t spart_bin = sp->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
239
240
241
242
243
  const integertime_t ti_current = e->ti_current;
  const integertime_t ti_end = get_integer_time_end(ti_current, sp->time_bin);

  if (ti_end < ti_current)
    error(
Matthieu Schaller's avatar
Matthieu Schaller committed
244
        "s-particle in an impossible time-zone! sp->ti_end=%lld "
245
246
247
248
        "e->ti_current=%lld",
        ti_end, ti_current);
#endif

249
  return (spart_bin <= max_active_bin);
250
251
}

252
253
254
255
256
257
258
259
260
/* Are cells / particles active for kick1 tasks ? */

/**
 * @brief Does a cell contain any particle starting their time-step now ?
 *
 * @param c The #cell.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #cell contains at least an active particle, 0 otherwise.
 */
261
__attribute__((always_inline)) INLINE static int cell_is_starting_hydro(
262
263
264
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
265
  if (c->ti_hydro_beg_max > e->ti_current)
266
267
268
    error(
        "cell in an impossible time-zone! c->ti_beg_max=%lld (t=%e) and "
        "e->ti_current=%lld (t=%e)",
269
        c->ti_hydro_beg_max, c->ti_hydro_beg_max * e->timeBase, e->ti_current,
270
271
272
        e->ti_current * e->timeBase);
#endif

273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
  return (c->ti_hydro_beg_max == e->ti_current);
}

/**
 * @brief Does a cell contain any g-particle starting their time-step now ?
 *
 * @param c The #cell.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #cell contains at least an active particle, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int cell_is_starting_gravity(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->ti_gravity_beg_max > e->ti_current)
    error(
        "cell in an impossible time-zone! c->ti_beg_max=%lld (t=%e) and "
        "e->ti_current=%lld (t=%e)",
        c->ti_gravity_beg_max, c->ti_gravity_beg_max * e->timeBase,
        e->ti_current, e->ti_current * e->timeBase);
#endif

  return (c->ti_gravity_beg_max == e->ti_current);
296
297
298
299
300
301
302
303
304
305
306
307
}

/**
 * @brief Is this particle starting its time-step now ?
 *
 * @param p The #part.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #part is active, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int part_is_starting(
    const struct part *p, const struct engine *e) {

308
309
310
311
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t part_bin = p->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
312
  const integertime_t ti_current = e->ti_current;
Matthieu Schaller's avatar
Matthieu Schaller committed
313
314
  const integertime_t ti_beg =
      get_integer_time_begin(ti_current + 1, p->time_bin);
315
316
317
318
319
320
321
322

  if (ti_beg > ti_current)
    error(
        "particle in an impossible time-zone! p->ti_beg=%lld "
        "e->ti_current=%lld",
        ti_beg, ti_current);
#endif

323
  return (part_bin <= max_active_bin);
324
325
326
327
328
329
330
331
332
333
334
335
}

/**
 * @brief Is this g-particle starting its time-step now ?
 *
 * @param gp The #gpart.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #gpart is active, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int gpart_is_starting(
    const struct gpart *gp, const struct engine *e) {

336
337
338
339
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t gpart_bin = gp->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
340
  const integertime_t ti_current = e->ti_current;
Matthieu Schaller's avatar
Matthieu Schaller committed
341
342
  const integertime_t ti_beg =
      get_integer_time_begin(ti_current + 1, gp->time_bin);
343
344
345
346
347
348
349
350

  if (ti_beg > ti_current)
    error(
        "g-particle in an impossible time-zone! gp->ti_beg=%lld "
        "e->ti_current=%lld",
        ti_beg, ti_current);
#endif

351
  return (gpart_bin <= max_active_bin);
352
}
Matthieu Schaller's avatar
Matthieu Schaller committed
353
354
355
356
357
358
359
360
361
362
363

/**
 * @brief Is this s-particle starting its time-step now ?
 *
 * @param sp The #spart.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #spart is active, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int spart_is_starting(
    const struct spart *sp, const struct engine *e) {

364
365
366
367
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t spart_bin = sp->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
Matthieu Schaller's avatar
Matthieu Schaller committed
368
369
370
371
372
373
374
375
376
377
378
  const integertime_t ti_current = e->ti_current;
  const integertime_t ti_beg =
      get_integer_time_begin(ti_current + 1, sp->time_bin);

  if (ti_beg > ti_current)
    error(
        "s-particle in an impossible time-zone! sp->ti_beg=%lld "
        "e->ti_current=%lld",
        ti_beg, ti_current);
#endif

379
  return (spart_bin <= max_active_bin);
Matthieu Schaller's avatar
Matthieu Schaller committed
380
}
381
#endif /* SWIFT_ACTIVE_H */