active.h 24.5 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->hydro.ti_old_part > e->ti_current)
43
    error(
44 45
        "Cell has been drifted too far forward in time! c->ti_old_part=%lld "
        "(t=%e) "
46
        "and e->ti_current=%lld (t=%e, a=%e)",
47 48
        c->hydro.ti_old_part, c->hydro.ti_old_part * e->time_base,
        e->ti_current, e->ti_current * e->time_base, e->cosmology->a);
49
#endif
Matthieu Schaller's avatar
Matthieu Schaller committed
50

51
  return (c->hydro.ti_old_part == e->ti_current);
52 53 54 55 56 57 58 59 60 61 62 63 64 65
}

/**
 * @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
66
  if (c->grav.ti_old_part > e->ti_current)
67 68 69
    error(
        "Cell has been drifted too far forward in time! c->ti_old=%lld (t=%e) "
        "and e->ti_current=%lld (t=%e)",
70 71
        c->grav.ti_old_part, c->grav.ti_old_part * e->time_base, e->ti_current,
        e->ti_current * e->time_base);
72 73
#endif

74
  return (c->grav.ti_old_part == e->ti_current);
75 76
}

Loic Hausammann's avatar
Loic Hausammann committed
77 78 79 80 81 82 83 84 85 86 87
/**
 * @brief Check that the #spart 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_spart_drifted(
    const struct cell *c, const struct engine *e) {

88 89 90 91 92 93 94 95 96 97
#ifdef SWIFT_DEBUG_CHECKS
  if (c->stars.ti_old_part > 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->stars.ti_old_part, c->stars.ti_old_part * e->time_base,
        e->ti_current, e->ti_current * e->time_base);
#endif

  return (c->stars.ti_old_part == e->ti_current);
Loic Hausammann's avatar
Loic Hausammann committed
98 99
}

Loic Hausammann's avatar
Loic Hausammann committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
/**
 * @brief Check that the #sink 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_sink_drifted(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->sinks.ti_old_part > 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->sinks.ti_old_part, c->sinks.ti_old_part * e->time_base,
        e->ti_current, e->ti_current * e->time_base);
#endif

  return (c->sinks.ti_old_part == e->ti_current);
}

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
/**
 * @brief Check that the #bpart 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_bpart_drifted(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->black_holes.ti_old_part > 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->black_holes.ti_old_part, c->black_holes.ti_old_part * e->time_base,
        e->ti_current, e->ti_current * e->time_base);
#endif

  return (c->black_holes.ti_old_part == e->ti_current);
}

146 147
/* Are cells / particles active for regular tasks ? */

148
/**
149
 * @brief Does a cell contain any particle finishing their time-step now ?
150 151 152
 *
 * @param c The #cell.
 * @param e The #engine containing information about the current time.
Matthieu Schaller's avatar
Matthieu Schaller committed
153
 * @return 1 if the #cell contains at least an active particle, 0 otherwise.
154
 */
155
__attribute__((always_inline)) INLINE static int cell_is_active_hydro(
156 157
    const struct cell *c, const struct engine *e) {

158
#ifdef SWIFT_DEBUG_CHECKS
159
  if (c->hydro.ti_end_min < e->ti_current)
160
    error(
161
        "cell in an impossible time-zone! c->ti_end_min=%lld (t=%e) and "
162
        "e->ti_current=%lld (t=%e, a=%e) c->nodeID=%d",
163
        c->hydro.ti_end_min, c->hydro.ti_end_min * e->time_base, e->ti_current,
164
        e->ti_current * e->time_base, e->cosmology->a, c->nodeID);
165 166
#endif

167
  return (c->hydro.ti_end_min == e->ti_current);
168 169 170
}

/**
171
 * @brief Are *all* particles in a cell finishing their time-step now ?
172 173 174
 *
 * @param c The #cell.
 * @param e The #engine containing information about the current time.
Matthieu Schaller's avatar
Matthieu Schaller committed
175
 * @return 1 if all particles in a #cell are active, 0 otherwise.
176
 */
177
__attribute__((always_inline)) INLINE static int cell_is_all_active_hydro(
178 179
    const struct cell *c, const struct engine *e) {

180
#ifdef SWIFT_DEBUG_CHECKS
181
  if (c->hydro.count > 0 && c->hydro.ti_end_max < e->ti_current)
182 183 184
    error(
        "cell in an impossible time-zone! c->ti_end_max=%lld "
        "e->ti_current=%lld",
185
        c->hydro.ti_end_max, e->ti_current);
186 187
#endif

188
  return (c->hydro.ti_end_max == e->ti_current);
189 190 191 192 193 194 195 196 197 198 199 200 201
}

/**
 * @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
202
  if (c->grav.ti_end_min < e->ti_current)
203 204
    error(
        "cell in an impossible time-zone! c->ti_end_min=%lld (t=%e) and "
205
        "e->ti_current=%lld (t=%e, a=%e)",
206 207
        c->grav.ti_end_min, c->grav.ti_end_min * e->time_base, e->ti_current,
        e->ti_current * e->time_base, e->cosmology->a);
208 209
#endif

210
  return (c->grav.ti_end_min == e->ti_current);
211 212
}

213
/**
Matthieu Schaller's avatar
Matthieu Schaller committed
214
 * @brief Does a cell contain any multipole requiring calculation ?
215 216 217 218 219 220 221 222
 *
 * @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_mm(
    const struct cell *c, const struct engine *e) {

223
  return (c->grav.ti_end_min == e->ti_current);
224 225
}

226 227 228 229 230 231 232 233 234 235 236
/**
 * @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
237
  if (c->grav.count > 0 && c->grav.ti_end_max < e->ti_current)
238 239 240
    error(
        "cell in an impossible time-zone! c->ti_end_max=%lld "
        "e->ti_current=%lld",
241
        c->grav.ti_end_max, e->ti_current);
242 243
#endif

244
  return (c->grav.ti_end_max == e->ti_current);
245 246
}

247 248 249 250 251 252 253
/**
 * @brief Does a cell contain any s-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.
 */
Loic Hausammann's avatar
Loic Hausammann committed
254
__attribute__((always_inline)) INLINE static int cell_is_active_stars(
255 256
    const struct cell *c, const struct engine *e) {

Loic Hausammann's avatar
Loic Hausammann committed
257 258 259 260 261 262 263 264
#ifdef SWIFT_DEBUG_CHECKS
  if (c->stars.ti_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, a=%e)",
        c->stars.ti_end_min, c->stars.ti_end_min * e->time_base, e->ti_current,
        e->ti_current * e->time_base, e->cosmology->a);
#endif
265

Loic Hausammann's avatar
Loic Hausammann committed
266
  return (c->stars.ti_end_min == e->ti_current);
267 268
}

Loic Hausammann's avatar
Loic Hausammann committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
/**
 * @brief Does a cell contain any sink-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_sinks(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->sinks.ti_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, a=%e)",
        c->sinks.ti_end_min, c->sinks.ti_end_min * e->time_base, e->ti_current,
        e->ti_current * e->time_base, e->cosmology->a);
#endif

  return (c->sinks.ti_end_min == e->ti_current);
}

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
/**
 * @brief Does a cell contain any b-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_black_holes(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->black_holes.ti_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, a=%e)",
306 307
        c->black_holes.ti_end_min, c->black_holes.ti_end_min * e->time_base,
        e->ti_current, e->ti_current * e->time_base, e->cosmology->a);
308 309 310 311 312
#endif

  return (c->black_holes.ti_end_min == e->ti_current);
}

313
/**
314
 * @brief Is this particle finishing its time-step now ?
315 316 317
 *
 * @param p The #part.
 * @param e The #engine containing information about the current time.
318
 * @return 1 if the #part is active, 0 otherwise.
319 320 321 322
 */
__attribute__((always_inline)) INLINE static int part_is_active(
    const struct part *p, const struct engine *e) {

323 324
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t part_bin = p->time_bin;
325

326
#ifdef SWIFT_DEBUG_CHECKS
327 328
  const integertime_t ti_current = e->ti_current;
  const integertime_t ti_end = get_integer_time_end(ti_current, p->time_bin);
329 330 331 332 333
  if (ti_end < ti_current)
    error(
        "particle in an impossible time-zone! p->ti_end=%lld "
        "e->ti_current=%lld",
        ti_end, ti_current);
334 335
#endif

336
  return (part_bin <= max_active_bin);
337 338
}

339 340 341 342 343 344 345 346
__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);
}

347
/**
348
 * @brief Is this g-particle finishing its time-step now ?
349 350 351
 *
 * @param gp The #gpart.
 * @param e The #engine containing information about the current time.
352
 * @return 1 if the #gpart is active, 0 otherwise.
353 354 355 356
 */
__attribute__((always_inline)) INLINE static int gpart_is_active(
    const struct gpart *gp, const struct engine *e) {

357 358 359 360
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t gpart_bin = gp->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
361 362 363 364
  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)
365
    error(
366 367 368
        "g-particle in an impossible time-zone! gp->ti_end=%lld "
        "e->ti_current=%lld",
        ti_end, ti_current);
369 370
#endif

371
  return (gpart_bin <= max_active_bin);
372 373
}

374
/**
Matthieu Schaller's avatar
Matthieu Schaller committed
375
 * @brief Is this s-particle finishing its time-step now ?
376 377 378 379 380 381 382 383
 *
 * @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) {

384 385 386 387
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t spart_bin = sp->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
388 389 390 391 392
  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
393
        "s-particle in an impossible time-zone! sp->ti_end=%lld "
394 395 396 397
        "e->ti_current=%lld",
        ti_end, ti_current);
#endif

398
  return (spart_bin <= max_active_bin);
399 400
}

Loic Hausammann's avatar
Loic Hausammann committed
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
/**
 * @brief Is this sink-particle finishing its time-step now ?
 *
 * @param sink The #sink.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #bpart is active, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int sink_is_active(
    const struct sink *sink, const struct engine *e) {

  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t sink_bin = sink->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
  const integertime_t ti_current = e->ti_current;
  const integertime_t ti_end = get_integer_time_end(ti_current, sink->time_bin);

  if (ti_end < ti_current)
    error(
        "sink-particle in an impossible time-zone! bp->ti_end=%lld "
        "e->ti_current=%lld",
        ti_end, ti_current);
#endif

  return (sink_bin <= max_active_bin);
}

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
/**
 * @brief Is this b-particle finishing its time-step now ?
 *
 * @param bp The #bpart.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #bpart is active, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int bpart_is_active(
    const struct bpart *bp, const struct engine *e) {

  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t bpart_bin = bp->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
  const integertime_t ti_current = e->ti_current;
  const integertime_t ti_end = get_integer_time_end(ti_current, bp->time_bin);

  if (ti_end < ti_current)
    error(
447
        "b-particle in an impossible time-zone! bp->ti_end=%lld "
448 449 450 451 452 453 454
        "e->ti_current=%lld",
        ti_end, ti_current);
#endif

  return (bpart_bin <= max_active_bin);
}

455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
/**
 * @brief Has this particle been inhibited?
 *
 * @param p The #part.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #part is inhibited, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int part_is_inhibited(
    const struct part *p, const struct engine *e) {
  return p->time_bin == time_bin_inhibited;
}

/**
 * @brief Has this gravity particle been inhibited?
 *
 * @param gp The #gpart.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #part is inhibited, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int gpart_is_inhibited(
    const struct gpart *gp, const struct engine *e) {
  return gp->time_bin == time_bin_inhibited;
}

/**
 * @brief Has this star particle been inhibited?
 *
 * @param sp The #spart.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #part is inhibited, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int spart_is_inhibited(
    const struct spart *sp, const struct engine *e) {
  return sp->time_bin == time_bin_inhibited;
}

Loic Hausammann's avatar
Loic Hausammann committed
491 492 493 494 495 496 497 498 499 500 501 502
/**
 * @brief Has this sink particle been inhibited?
 *
 * @param sink The #sink.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #sink is inhibited, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int sink_is_inhibited(
    const struct sink *sink, const struct engine *e) {
  return sink->time_bin == time_bin_inhibited;
}

503 504 505
/**
 * @brief Has this black hole particle been inhibited?
 *
Matthieu Schaller's avatar
Matthieu Schaller committed
506
 * @param bp The #bpart.
507 508 509 510 511 512 513 514
 * @param e The #engine containing information about the current time.
 * @return 1 if the #part is inhibited, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int bpart_is_inhibited(
    const struct bpart *bp, const struct engine *e) {
  return bp->time_bin == time_bin_inhibited;
}

515 516 517 518 519 520 521 522 523
/* 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.
 */
524
__attribute__((always_inline)) INLINE static int cell_is_starting_hydro(
525 526 527
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
528
  if (c->hydro.ti_beg_max > e->ti_current)
529 530
    error(
        "cell in an impossible time-zone! c->ti_beg_max=%lld (t=%e) and "
531
        "e->ti_current=%lld (t=%e, a=%e)",
532
        c->hydro.ti_beg_max, c->hydro.ti_beg_max * e->time_base, e->ti_current,
533
        e->ti_current * e->time_base, e->cosmology->a);
534 535
#endif

536
  return (c->hydro.ti_beg_max == e->ti_current);
537 538 539 540 541 542 543 544 545 546 547 548 549
}

/**
 * @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
550
  if (c->grav.ti_beg_max > e->ti_current)
551 552
    error(
        "cell in an impossible time-zone! c->ti_beg_max=%lld (t=%e) and "
553
        "e->ti_current=%lld (t=%e, a=%e)",
554 555
        c->grav.ti_beg_max, c->grav.ti_beg_max * e->time_base, e->ti_current,
        e->ti_current * e->time_base, e->cosmology->a);
556 557
#endif

558
  return (c->grav.ti_beg_max == e->ti_current);
559 560
}

561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
/**
 * @brief Does a cell contain any s-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_stars(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->stars.ti_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, a=%e)",
        c->stars.ti_beg_max, c->stars.ti_beg_max * e->time_base, e->ti_current,
        e->ti_current * e->time_base, e->cosmology->a);
#endif

  return (c->stars.ti_beg_max == e->ti_current);
}

Loic Hausammann's avatar
Loic Hausammann committed
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
/**
 * @brief Does a cell contain any sink-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_sinks(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->sinks.ti_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, a=%e)",
        c->sinks.ti_beg_max, c->sinks.ti_beg_max * e->time_base, e->ti_current,
        e->ti_current * e->time_base, e->cosmology->a);
#endif

  return (c->sinks.ti_beg_max == e->ti_current);
}

605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
/**
 * @brief Does a cell contain any b-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_black_holes(
    const struct cell *c, const struct engine *e) {

#ifdef SWIFT_DEBUG_CHECKS
  if (c->black_holes.ti_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, a=%e)",
620 621
        c->black_holes.ti_beg_max, c->black_holes.ti_beg_max * e->time_base,
        e->ti_current, e->ti_current * e->time_base, e->cosmology->a);
622 623 624 625 626
#endif

  return (c->black_holes.ti_beg_max == e->ti_current);
}

627 628 629 630 631 632 633 634 635 636
/**
 * @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) {

637 638 639 640
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t part_bin = p->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
641
  const integertime_t ti_current = e->ti_current;
Matthieu Schaller's avatar
Matthieu Schaller committed
642 643
  const integertime_t ti_beg =
      get_integer_time_begin(ti_current + 1, p->time_bin);
644 645 646 647 648 649 650 651

  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

652
  return (part_bin <= max_active_bin);
653 654 655 656 657 658 659 660 661 662 663 664
}

/**
 * @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) {

665 666 667 668
  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t gpart_bin = gp->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
669
  const integertime_t ti_current = e->ti_current;
Matthieu Schaller's avatar
Matthieu Schaller committed
670 671
  const integertime_t ti_beg =
      get_integer_time_begin(ti_current + 1, gp->time_bin);
672 673 674 675 676 677 678 679

  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

680
  return (gpart_bin <= max_active_bin);
681
}
Matthieu Schaller's avatar
Matthieu Schaller committed
682 683 684 685 686 687 688 689 690 691 692

/**
 * @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) {

693 694 695 696
  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
697 698 699 700 701 702 703 704 705 706 707
  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

708
  return (spart_bin <= max_active_bin);
Matthieu Schaller's avatar
Matthieu Schaller committed
709
}
Loikki's avatar
Loikki committed
710

711 712 713
/**
 * @brief Is this b-particle starting its time-step now ?
 *
Matthieu Schaller's avatar
Matthieu Schaller committed
714
 * @param bp The #bpart.
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
 * @param e The #engine containing information about the current time.
 * @return 1 if the #bpart is active, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int bpart_is_starting(
    const struct bpart *bp, const struct engine *e) {

  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t bpart_bin = bp->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
  const integertime_t ti_current = e->ti_current;
  const integertime_t ti_beg =
      get_integer_time_begin(ti_current + 1, bp->time_bin);

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

  return (bpart_bin <= max_active_bin);
}

Loic Hausammann's avatar
Loic Hausammann committed
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
/**
 * @brief Is this sink-particle starting its time-step now ?
 *
 * @param sink The #sink.
 * @param e The #engine containing information about the current time.
 * @return 1 if the #sink is active, 0 otherwise.
 */
__attribute__((always_inline)) INLINE static int sink_is_starting(
    const struct sink *sink, const struct engine *e) {

  const timebin_t max_active_bin = e->max_active_bin;
  const timebin_t sink_bin = sink->time_bin;

#ifdef SWIFT_DEBUG_CHECKS
  const integertime_t ti_current = e->ti_current;
  const integertime_t ti_beg =
      get_integer_time_begin(ti_current + 1, sink->time_bin);

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

  return (sink_bin <= max_active_bin);
}

767
#endif /* SWIFT_ACTIVE_H */