cell.h 49 KB
Newer Older
1
/*******************************************************************************
2
 * This file is part of SWIFT.
3
 * Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
4
5
6
7
 *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
 *               2015 Peter W. Draper (p.w.draper@durham.ac.uk)
 *               2016 John A. Regan (john.a.regan@durham.ac.uk)
 *                    Tom Theuns (tom.theuns@durham.ac.uk)
8
 *
9
10
11
12
 * 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.
13
 *
14
15
16
17
 * 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.
18
 *
19
20
 * 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/>.
21
 *
22
 ******************************************************************************/
23
24
#ifndef SWIFT_CELL_H
#define SWIFT_CELL_H
25

26
27
28
/* Config parameters. */
#include "../config.h"

29
/* Includes. */
30
#include <stddef.h>
31
#include <stdint.h>
32
33

/* Local includes. */
34
#include "align.h"
35
#include "kernel_hydro.h"
Pedro Gonnet's avatar
Pedro Gonnet committed
36
#include "lock.h"
37
#include "multipole.h"
38
#include "part.h"
39
#include "sort_part.h"
40
#include "space.h"
Folkert Nobels's avatar
Folkert Nobels committed
41
#include "star_formation_logger_struct.h"
42
#include "task.h"
43
#include "timeline.h"
44

45
/* Avoid cyclic inclusions */
46
struct engine;
47
struct scheduler;
48

49
50
51
/* Max tag size set to 2^29 to take into account some MPI implementations
 * that use 2^31 as the upper bound on MPI tags and the fact that
 * cell_next_tag is multiplied by 2 when passed to an MPI function.
52
53
 * The maximum was lowered by a further factor of 2 to be on the safe side.*/
#define cell_max_tag (1 << 29)
54

55
#define cell_align 128
56

57
58
59
/* Global variables. */
extern int cell_next_tag;

60
61
62
63
/* Struct to temporarily buffer the particle locations and bin id. */
struct cell_buff {
  double x[3];
  int ind;
64
} SWIFT_STRUCT_ALIGN;
65

66
67
68
69
70
71
72
73
74
75
/* Mini struct to link cells to tasks. Used as a linked list. */
struct link {

  /* The task pointer. */
  struct task *t;

  /* The next pointer. */
  struct link *next;
};

76
77
78
79
80
81
82
83
84
85
86
/* Holds the pairs of progeny for each sid. */
struct cell_split_pair {
  int count;
  struct {
    int pid;
    int pjd;
    int sid;
  } pairs[16];
};
extern struct cell_split_pair cell_split_pairs[13];

87
88
89
90
91
/**
 * @brief Packed cell for information correct at rebuild time.
 *
 * Contains all the information for a tree walk in a non-local cell.
 */
92
93
struct pcell {

94
95
  /*! Hydro variables */
  struct {
Matthieu Schaller's avatar
Matthieu Schaller committed
96

97
98
99
    /*! Number of #part in this cell. */
    int count;

100
    /*! Maximal smoothing length. */
101
    float h_max;
102

103
104
    /*! Minimal integer end-of-timestep in this cell for hydro tasks */
    integertime_t ti_end_min;
105

106
107
    /*! Maximal integer end-of-timestep in this cell for hydro tasks */
    integertime_t ti_end_max;
108

109
110
    /*! Maximal integer beginning-of-timestep in this cell for hydro tasks */
    integertime_t ti_beg_max;
111

112
    /*! Integer time of the last drift of the #part in this cell */
113
    integertime_t ti_old_part;
114

115
  } hydro;
116

117
118
  /*! Gravity variables */
  struct {
119

120
121
    /*! This cell's gravity-related tensors */
    struct multipole m_pole;
122

123
124
    /*! Centre of mass. */
    double CoM[3];
125

126
127
    /*! Centre of mass at rebuild time. */
    double CoM_rebuild[3];
128

129
130
    /*! Upper limit of the CoM<->gpart distance. */
    double r_max;
131

132
133
    /*! Upper limit of the CoM<->gpart distance at last rebuild. */
    double r_max_rebuild;
134

135
136
    /*! Minimal integer end-of-timestep in this cell for gravity tasks */
    integertime_t ti_end_min;
Pedro Gonnet's avatar
Pedro Gonnet committed
137

138
139
    /*! Maximal integer end-of-timestep in this cell for gravity tasks */
    integertime_t ti_end_max;
140

141
142
    /*! Maximal integer beginning-of-timestep in this cell for gravity tasks */
    integertime_t ti_beg_max;
143

144
    /*! Integer time of the last drift of the #gpart in this cell */
145
    integertime_t ti_old_part;
146

147
148
    /*! Integer time of the last drift of the #multipole in this cell */
    integertime_t ti_old_multipole;
149

150
    /*! Number of #gpart in this cell. */
151
    int count;
152
153
154

  } grav;

155
156
157
158
159
160
  /*! Stars variables */
  struct {

    /*! Number of #spart in this cell. */
    int count;

Loic Hausammann's avatar
Loic Hausammann committed
161
    /*! Maximal smoothing length. */
162
    float h_max;
Loic Hausammann's avatar
Loic Hausammann committed
163

164
165
166
    /*! Minimal integer end-of-timestep in this cell for stars tasks */
    integertime_t ti_end_min;

167
168
169
    /*! Maximal integer end-of-timestep in this cell for stars tasks */
    integertime_t ti_end_max;

170
171
172
    /*! Integer time of the last drift of the #spart in this cell */
    integertime_t ti_old_part;

173
174
  } stars;

175
176
177
178
179
180
181
  /*! Black hole variables */
  struct {

    /*! Number of #spart in this cell. */
    int count;

    /*! Maximal smoothing length. */
182
    float h_max;
183
184
185
186
187
188
189
190
191
192
193
194

    /*! Minimal integer end-of-timestep in this cell for black hole tasks */
    integertime_t ti_end_min;

    /*! Maximal integer end-of-timestep in this cell for black hole tasks */
    integertime_t ti_end_max;

    /*! Integer time of the last drift of the #spart in this cell */
    integertime_t ti_old_part;

  } black_holes;

195
196
197
  /*! Maximal depth in that part of the tree */
  int maxdepth;

198
199
  /*! Relative indices of the cell's progeny. */
  int progeny[8];
200

201
202
203
204
205
#ifdef SWIFT_DEBUG_CHECKS
  /* Cell ID (for debugging) */
  int cellID;
#endif

206
} SWIFT_STRUCT_ALIGN;
207

208
209
210
/**
 * @brief Cell information at the end of a time-step.
 */
211
struct pcell_step_hydro {
212

213
214
  /*! Minimal integer end-of-timestep in this cell (hydro) */
  integertime_t ti_end_min;
215

216
217
  /*! Minimal integer end-of-timestep in this cell (hydro) */
  integertime_t ti_end_max;
218

219
220
221
  /*! Maximal distance any #part has travelled since last rebuild */
  float dx_max_part;
};
222

223
struct pcell_step_grav {
224

225
226
  /*! Minimal integer end-of-timestep in this cell (gravity) */
  integertime_t ti_end_min;
227

228
229
230
  /*! Minimal integer end-of-timestep in this cell (gravity) */
  integertime_t ti_end_max;
};
Loic Hausammann's avatar
Loic Hausammann committed
231

232
struct pcell_step_stars {
233

234
235
  /*! Minimal integer end-of-timestep in this cell (stars) */
  integertime_t ti_end_min;
236

237
238
  /*! Maximal integer end-of-timestep in this cell (stars) */
  integertime_t ti_end_max;
239

240
241
  /*! Maximal distance any #part has travelled since last rebuild */
  float dx_max_part;
242
243
};

244
245
246
247
248
249
250
251
252
253
254
255
struct pcell_step_black_holes {

  /*! Minimal integer end-of-timestep in this cell (black_holes) */
  integertime_t ti_end_min;

  /*! Maximal integer end-of-timestep in this cell (black_holes) */
  integertime_t ti_end_max;

  /*! Maximal distance any #part has travelled since last rebuild */
  float dx_max_part;
};

256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/**
 * @brief Cell information to propagate the new counts of star particles.
 */
struct pcell_sf {

  /*! Stars variables */
  struct {

    /* Distance by which the stars pointer has moved since the last rebuild */
    ptrdiff_t delta_from_rebuild;

    /* Number of particles in the cell */
    int count;

    /*! Maximum part movement in this cell since last construction. */
    float dx_max_part;
272

273
274
275
  } stars;
};

276
277
278
279
/**
 * @brief Bitmasks for the cell flags. Beware when adding flags that you don't
 * exceed the size of the flags variable in the struct cell.
 */
280
281
282
283
284
enum cell_flags {
  cell_flag_split = (1UL << 0),
  cell_flag_do_hydro_drift = (1UL << 1),
  cell_flag_do_hydro_sub_drift = (1UL << 2),
  cell_flag_do_hydro_sub_sort = (1UL << 3),
285
286
  cell_flag_do_hydro_limiter = (1UL << 4),
  cell_flag_do_hydro_sub_limiter = (1UL << 5),
287
288
289
290
291
292
  cell_flag_do_grav_drift = (1UL << 6),
  cell_flag_do_grav_sub_drift = (1UL << 7),
  cell_flag_do_stars_sub_sort = (1UL << 8),
  cell_flag_do_stars_drift = (1UL << 9),
  cell_flag_do_stars_sub_drift = (1UL << 10),
  cell_flag_do_bh_drift = (1UL << 11),
293
  cell_flag_do_bh_sub_drift = (1UL << 12),
294
295
  cell_flag_do_stars_resort = (1UL << 13),
  cell_flag_has_tasks = (1UL << 14),
296
297
  cell_flag_do_hydro_sync = (1UL << 15),
  cell_flag_do_hydro_sub_sync = (1UL << 16)
298
299
};

300
301
302
303
304
/**
 * @brief Cell within the tree structure.
 *
 * Contains particles, links to tasks, a multipole object and counters.
 */
305
306
struct cell {

307
  /*! The cell location on the grid. */
308
309
  double loc[3];

310
  /*! The cell dimensions. */
311
  double width[3];
312

313
  /*! Pointers to the next level of cells. */
314
315
  struct cell *progeny[8];

316
317
318
  /*! Linking pointer for "memory management". */
  struct cell *next;

319
  /*! Parent cell. */
320
321
  struct cell *parent;

322
323
324
  /*! Pointer to the top-level cell in a hierarchy */
  struct cell *top;

325
  /*! Super cell, i.e. the highest-level parent cell with *any* task */
326
  struct cell *super;
327

328
  /*! Cell flags bit-mask. */
329
  volatile uint32_t flags;
330

331
332
  /*! Hydro variables */
  struct {
333

334
335
    /*! Pointer to the #part data. */
    struct part *parts;
336

337
338
    /*! Pointer to the #xpart data. */
    struct xpart *xparts;
339

340
    /*! Pointer for the sorted indices. */
Matthieu Schaller's avatar
Matthieu Schaller committed
341
    struct sort_entry *sort;
342

343
344
    /*! Super cell, i.e. the highest-level parent cell that has a hydro
     * pair/self tasks */
345
    struct cell *super;
346

347
348
    /*! The task computing this cell's sorts. */
    struct task *sorts;
349

350
351
    /*! The drift task for parts */
    struct task *drift;
352

353
354
355
356
357
358
359
360
361
    /*! Linked list of the tasks computing this cell's hydro density. */
    struct link *density;

    /* Linked list of the tasks computing this cell's hydro gradients. */
    struct link *gradient;

    /*! Linked list of the tasks computing this cell's hydro forces. */
    struct link *force;

362
363
364
    /*! Linked list of the tasks computing this cell's limiter. */
    struct link *limiter;

365
366
367
368
369
370
371
372
373
374
375
376
    /*! Dependency implicit task for the ghost  (in->ghost->out)*/
    struct task *ghost_in;

    /*! Dependency implicit task for the ghost  (in->ghost->out)*/
    struct task *ghost_out;

    /*! The ghost task itself */
    struct task *ghost;

    /*! The extra ghost task for complex hydro schemes */
    struct task *extra_ghost;

377
378
379
    /*! The task to end the force calculation */
    struct task *end_force;

380
381
382
383
384
    /*! Task for cooling */
    struct task *cooling;

    /*! Task for star formation */
    struct task *star_formation;
385

386
387
388
    /*! Task for sorting the stars again after a SF event */
    struct task *stars_resort;

389
390
391
    /*! Last (integer) time the cell's part were drifted forward in time. */
    integertime_t ti_old_part;

392
393
    /*! Minimum end of (integer) time step in this cell for hydro tasks. */
    integertime_t ti_end_min;
394

395
396
    /*! Maximum end of (integer) time step in this cell for hydro tasks. */
    integertime_t ti_end_max;
397

398
399
    /*! Maximum beginning of (integer) time step in this cell for hydro tasks.
     */
400
    integertime_t ti_beg_max;
401

402
403
    /*! Spin lock for various uses (#part case). */
    swift_lock_type lock;
404

405
406
407
    /*! Max smoothing length in this cell. */
    float h_max;

408
409
    /*! Maximum part movement in this cell since last construction. */
    float dx_max_part;
410

411
412
    /*! Maximum particle movement in this cell since the last sort. */
    float dx_max_sort;
413

414
415
    /*! Values of h_max before the drifts, used for sub-cell tasks. */
    float h_max_old;
416

417
418
419
    /*! Values of dx_max before the drifts, used for sub-cell tasks. */
    float dx_max_part_old;

420
421
    /*! Values of dx_max_sort before the drifts, used for sub-cell tasks. */
    float dx_max_sort_old;
422

423
424
425
    /*! Nr of #part in this cell. */
    int count;

426
427
428
    /*! Nr of #part this cell can hold after addition of new #part. */
    int count_total;

429
430
431
432
433
434
    /*! Number of #part updated in this cell. */
    int updated;

    /*! Is the #part data of this cell being used in a sub-cell? */
    int hold;

435
    /*! Bit mask of sort directions that will be needed in the next timestep. */
436
    uint16_t requires_sorts;
437

438
    /*! Bit mask of sorts that need to be computed for this cell. */
439
    uint16_t do_sort;
440

441
    /*! Bit-mask indicating the sorted directions */
442
    uint16_t sorted;
443

Matthieu Schaller's avatar
Matthieu Schaller committed
444
445
446
    /*! Bit-mask indicating the sorted directions */
    uint16_t sort_allocated;

Matthieu Schaller's avatar
Matthieu Schaller committed
447
#ifdef SWIFT_DEBUG_CHECKS
448

449
450
    /*! Last (integer) time the cell's sort arrays were updated. */
    integertime_t ti_sort;
451

452
#endif
453

454
  } hydro;
455

456
457
  /*! Grav variables */
  struct {
458

459
    /*! Pointer to the #gpart data. */
460
    struct gpart *parts;
461

462
463
    /*! This cell's multipole. */
    struct gravity_tensors *multipole;
464

465
466
467
    /*! Super cell, i.e. the highest-level parent cell that has a grav pair/self
     * tasks */
    struct cell *super;
468

469
470
471
    /*! The drift task for gparts */
    struct task *drift;

472
473
474
    /*! Implicit task (going up- and down the tree) for the #gpart drifts */
    struct task *drift_out;

475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
    /*! Linked list of the tasks computing this cell's gravity forces. */
    struct link *grav;

    /*! Linked list of the tasks computing this cell's gravity M-M forces. */
    struct link *mm;

    /*! The multipole initialistation task */
    struct task *init;

    /*! Implicit task for the gravity initialisation */
    struct task *init_out;

    /*! Task computing long range non-periodic gravity interactions */
    struct task *long_range;

    /*! Implicit task for the down propagation */
    struct task *down_in;

    /*! Task propagating the mesh forces to the particles */
    struct task *mesh;

    /*! Task propagating the multipole to the particles */
    struct task *down;

499
500
501
    /*! The task to end the force calculation */
    struct task *end_force;

502
503
    /*! Minimum end of (integer) time step in this cell for gravity tasks. */
    integertime_t ti_end_min;
504

505
506
    /*! Maximum end of (integer) time step in this cell for gravity tasks. */
    integertime_t ti_end_max;
507

508
509
510
    /*! Maximum beginning of (integer) time step in this cell for gravity tasks.
     */
    integertime_t ti_beg_max;
511

512
    /*! Last (integer) time the cell's gpart were drifted forward in time. */
513
    integertime_t ti_old_part;
514

515
516
    /*! Last (integer) time the cell's multipole was drifted forward in time. */
    integertime_t ti_old_multipole;
517

518
    /*! Spin lock for various uses (#gpart case). */
519
    swift_lock_type plock;
520

521
522
    /*! Spin lock for various uses (#multipole case). */
    swift_lock_type mlock;
523

Loic Hausammann's avatar
Loic Hausammann committed
524
525
526
    /*! Spin lock for star formation use. */
    swift_lock_type star_formation_lock;

527
528
529
    /*! Nr of #gpart in this cell. */
    int count;

530
531
532
    /*! Nr of #gpart this cell can hold after addition of new #gpart. */
    int count_total;

533
    /*! Number of #gpart updated in this cell. */
534
    int updated;
535

536
    /*! Is the #gpart data of this cell being used in a sub-cell? */
537
    int phold;
538

539
540
    /*! Is the #multipole data of this cell being used in a sub-cell? */
    int mhold;
541

542
543
544
    /*! Number of M-M tasks that are associated with this cell. */
    short int nr_mm_tasks;

545
  } grav;
546

547
548
  /*! Stars variables */
  struct {
549

550
551
    /*! Pointer to the #spart data. */
    struct spart *parts;
552

553
554
555
    /*! Pointer to the #spart data at rebuild time. */
    struct spart *parts_rebuild;

556
557
558
559
560
    /*! The star ghost task itself */
    struct task *ghost;

    /*! Linked list of the tasks computing this cell's star density. */
    struct link *density;
561

Alexei Borissov's avatar
Alexei Borissov committed
562
563
564
    /*! Linked list of the tasks computing this cell's star feedback. */
    struct link *feedback;

565
    /*! The task computing this cell's sorts before the density. */
566
    struct task *sorts;
Matthieu Schaller's avatar
Matthieu Schaller committed
567

568
    /*! The drift task for sparts */
569
    struct task *drift;
570

571
572
    /*! Implicit tasks marking the entry of the stellar physics block of tasks
     */
573
574
    struct task *stars_in;

575
    /*! Implicit tasks marking the exit of the stellar physics block of tasks */
576
577
    struct task *stars_out;

578
579
580
    /*! Last (integer) time the cell's spart were drifted forward in time. */
    integertime_t ti_old_part;

581
582
583
    /*! Spin lock for various uses (#spart case). */
    swift_lock_type lock;

584
585
586
    /*! Spin lock for star formation use. */
    swift_lock_type star_formation_lock;

587
588
589
    /*! Nr of #spart in this cell. */
    int count;

590
591
592
    /*! Nr of #spart this cell can hold after addition of new #spart. */
    int count_total;

593
594
595
    /*! Max smoothing length in this cell. */
    float h_max;

Loic Hausammann's avatar
Loic Hausammann committed
596
597
598
599
600
601
602
603
604
    /*! Values of h_max before the drifts, used for sub-cell tasks. */
    float h_max_old;

    /*! Maximum part movement in this cell since last construction. */
    float dx_max_part;

    /*! Values of dx_max before the drifts, used for sub-cell tasks. */
    float dx_max_part_old;

Matthieu Schaller's avatar
Matthieu Schaller committed
605
606
607
608
609
610
611
    /*! Maximum particle movement in this cell since the last sort. */
    float dx_max_sort;

    /*! Values of dx_max_sort before the drifts, used for sub-cell tasks. */
    float dx_max_sort_old;

    /*! Pointer for the sorted indices. */
Matthieu Schaller's avatar
Matthieu Schaller committed
612
    struct sort_entry *sort;
Matthieu Schaller's avatar
Matthieu Schaller committed
613

614
615
    /*! Bit mask of sort directions that will be needed in the next timestep. */
    uint16_t requires_sorts;
Matthieu Schaller's avatar
Matthieu Schaller committed
616
617

    /*! Bit-mask indicating the sorted directions */
618
    uint16_t sorted;
Matthieu Schaller's avatar
Matthieu Schaller committed
619

Matthieu Schaller's avatar
Matthieu Schaller committed
620
621
622
    /*! Bit-mask indicating the sorted directions */
    uint16_t sort_allocated;

Matthieu Schaller's avatar
Matthieu Schaller committed
623
    /*! Bit mask of sorts that need to be computed for this cell. */
624
    uint16_t do_sort;
Matthieu Schaller's avatar
Matthieu Schaller committed
625

626
    /*! Maximum end of (integer) time step in this cell for star tasks. */
Matthieu Schaller's avatar
Matthieu Schaller committed
627
628
    integertime_t ti_end_min;

629
630
631
632
633
634
    /*! Maximum end of (integer) time step in this cell for star tasks. */
    integertime_t ti_end_max;

    /*! Maximum beginning of (integer) time step in this cell for star tasks.
     */
    integertime_t ti_beg_max;
635

636
637
    /*! Number of #spart updated in this cell. */
    int updated;
638

639
640
    /*! Is the #spart data of this cell being used in a sub-cell? */
    int hold;
641

Folkert Nobels's avatar
Folkert Nobels committed
642
    /*! Star formation history struct */
643
    struct star_formation_history sfh;
644

Matthieu Schaller's avatar
Matthieu Schaller committed
645
646
647
648
649
#ifdef SWIFT_DEBUG_CHECKS
    /*! Last (integer) time the cell's sort arrays were updated. */
    integertime_t ti_sort;
#endif

650
  } stars;
651

652
653
654
655
656
657
658
659
660
  /*! Black hole variables */
  struct {

    /*! Pointer to the #bpart data. */
    struct bpart *parts;

    /*! The drift task for bparts */
    struct task *drift;

661
662
663
664
665
666
667
    /*! Implicit tasks marking the entry of the BH physics block of tasks
     */
    struct task *black_holes_in;

    /*! Implicit tasks marking the exit of the BH physics block of tasks */
    struct task *black_holes_out;

668
    /*! The star ghost task itself */
669
    struct task *density_ghost;
670

671
    /*! The star ghost task itself */
672
    struct task *swallow_ghost[3];
673
674

    /*! Linked list of the tasks computing this cell's BH density. */
675
676
    struct link *density;

677
678
679
680
681
    /*! Linked list of the tasks computing this cell's BH swallowing and
     * merging. */
    struct link *swallow;

    /*! Linked list of the tasks processing the particles to swallow */
682
683
684
685
    struct link *do_gas_swallow;

    /*! Linked list of the tasks processing the particles to swallow */
    struct link *do_bh_swallow;
686
687

    /*! Linked list of the tasks computing this cell's BH feedback. */
688
689
    struct link *feedback;

690
691
692
693
694
695
696
697
698
699
700
701
    /*! Last (integer) time the cell's bpart were drifted forward in time. */
    integertime_t ti_old_part;

    /*! Spin lock for various uses (#bpart case). */
    swift_lock_type lock;

    /*! Nr of #bpart in this cell. */
    int count;

    /*! Nr of #bpart this cell can hold after addition of new #bpart. */
    int count_total;

702
703
704
    /*! Max smoothing length in this cell. */
    float h_max;

705
706
707
708
709
710
    /*! Values of h_max before the drifts, used for sub-cell tasks. */
    float h_max_old;

    /*! Maximum part movement in this cell since last construction. */
    float dx_max_part;

711
712
713
    /*! Values of dx_max before the drifts, used for sub-cell tasks. */
    float dx_max_part_old;

714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
    /*! Maximum end of (integer) time step in this cell for black tasks. */
    integertime_t ti_end_min;

    /*! Maximum end of (integer) time step in this cell for black hole tasks. */
    integertime_t ti_end_max;

    /*! Maximum beginning of (integer) time step in this cell for black hole
     * tasks.
     */
    integertime_t ti_beg_max;

    /*! Number of #bpart updated in this cell. */
    int updated;

    /*! Is the #bpart data of this cell being used in a sub-cell? */
    int hold;

  } black_holes;

733
734
735
#ifdef WITH_MPI
  /*! MPI variables */
  struct {
736

737
738
739
    union {
      /* Single list of all send tasks associated with this cell. */
      struct link *send;
740

741
      /* Single list of all recv tasks associated with this cell. */
742
743
      struct link *recv;
    };
744

745
746
747
748
749
750
751
752
753
754
755
    /*! Bit mask of the proxies this cell is registered with. */
    unsigned long long int sendto;

    /*! Pointer to this cell's packed representation. */
    struct pcell *pcell;

    /*! Size of the packed representation */
    int pcell_size;

    /*! MPI tag associated with this cell */
    int tag;
756

757
758
  } mpi;
#endif
759

760
761
  /*! The first kick task */
  struct task *kick1;
762

763
764
  /*! The second kick task */
  struct task *kick2;
765

766
767
768
  /*! The task to compute time-steps */
  struct task *timestep;

769
770
771
  /*! The task to limit the time-step of inactive particles */
  struct task *timestep_limiter;

772
773
  /*! The task to synchronize the time-step of inactive particles hit by
   * feedback */
774
  struct task *timestep_sync;
775

776
#ifdef WITH_LOGGER
Loic Hausammann's avatar
Format    
Loic Hausammann committed
777
778
  /*! The logger task */
  struct task *logger;
779
#endif
Loic Hausammann's avatar
Format    
Loic Hausammann committed
780

781
782
  /*! Minimum dimension, i.e. smallest edge of this cell (min(width)). */
  float dmin;
783

784
785
786
787
788
789
  /*! ID of the previous owner, e.g. runner. */
  int owner;

  /*! ID of the node this cell lives on. */
  int nodeID;

790
791
792
793
794
795
796
797
798
799
800
801
  /*! Number of tasks that are associated with this cell. */
  short int nr_tasks;

  /*! The depth of this cell in the tree. */
  char depth;

  /*! Is this cell split ? */
  char split;

  /*! The maximal depth of this cell and its progenies */
  char maxdepth;

Loic Hausammann's avatar
Loic Hausammann committed
802
#if defined(SWIFT_DEBUG_CHECKS) || defined(SWIFT_CELL_GRAPH)
803
804
  /* Cell ID (for debugging) */
  int cellID;
Loic Hausammann's avatar
Loic Hausammann committed
805
806
807
#endif

#ifdef SWIFT_DEBUG_CHECKS
808

809
810
811
812
813
814
815
  /*! The list of tasks that have been executed on this cell */
  char tasks_executed[64];

  /*! The list of sub-tasks that have been executed on this cell */
  char subtasks_executed[64];
#endif

816
} SWIFT_STRUCT_ALIGN;
817

818
819
820
821
/* Convert cell location to ID. */
#define cell_getid(cdim, i, j, k) \
  ((int)(k) + (cdim)[2] * ((int)(j) + (cdim)[1] * (int)(i)))

822
/* Function prototypes. */
823
void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset,
824
825
                ptrdiff_t bparts_offset, struct cell_buff *buff,
                struct cell_buff *sbuff, struct cell_buff *bbuff,
826
                struct cell_buff *gbuff);
827
void cell_sanitize(struct cell *c, int treated);
828
829
830
831
int cell_locktree(struct cell *c);
void cell_unlocktree(struct cell *c);
int cell_glocktree(struct cell *c);
void cell_gunlocktree(struct cell *c);
832
833
int cell_mlocktree(struct cell *c);
void cell_munlocktree(struct cell *c);
834
835
int cell_slocktree(struct cell *c);
void cell_sunlocktree(struct cell *c);
836
837
int cell_blocktree(struct cell *c);
void cell_bunlocktree(struct cell *c);
838
int cell_pack(struct cell *c, struct pcell *pc, const int with_gravity);
Matthieu Schaller's avatar
Matthieu Schaller committed
839
840
int cell_unpack(struct pcell *pc, struct cell *c, struct space *s,
                const int with_gravity);
841
842
843
844
void cell_pack_part_swallow(const struct cell *c,
                            struct black_holes_part_data *data);
void cell_unpack_part_swallow(struct cell *c,
                              const struct black_holes_part_data *data);
845
846
847
848
void cell_pack_bpart_swallow(const struct cell *c,
                             struct black_holes_bpart_data *data);
void cell_unpack_bpart_swallow(struct cell *c,
                               const struct black_holes_bpart_data *data);
849
850
int cell_pack_tags(const struct cell *c, int *tags);
int cell_unpack_tags(const int *tags, struct cell *c);
851
852
853
854
855
856
int cell_pack_end_step_hydro(struct cell *c, struct pcell_step_hydro *pcell);
int cell_unpack_end_step_hydro(struct cell *c, struct pcell_step_hydro *pcell);
int cell_pack_end_step_grav(struct cell *c, struct pcell_step_grav *pcell);
int cell_unpack_end_step_grav(struct cell *c, struct pcell_step_grav *pcell);
int cell_pack_end_step_stars(struct cell *c, struct pcell_step_stars *pcell);
int cell_unpack_end_step_stars(struct cell *c, struct pcell_step_stars *pcell);
857
858
859
860
int cell_pack_end_step_black_holes(struct cell *c,
                                   struct pcell_step_black_holes *pcell);
int cell_unpack_end_step_black_holes(struct cell *c,
                                     struct pcell_step_black_holes *pcell);
861
862
int cell_pack_multipoles(struct cell *c, struct gravity_tensors *m);
int cell_unpack_multipoles(struct cell *c, struct gravity_tensors *m);
863
864
int cell_pack_sf_counts(struct cell *c, struct pcell_sf *pcell);
int cell_unpack_sf_counts(struct cell *c, struct pcell_sf *pcell);
865
int cell_getsize(struct cell *c);
866
int cell_link_parts(struct cell *c, struct part *parts);
867
int cell_link_gparts(struct cell *c, struct gpart *gparts);
868
int cell_link_sparts(struct cell *c, struct spart *sparts);
869
int cell_link_bparts(struct cell *c, struct bpart *bparts);
870
871
int cell_link_foreign_parts(struct cell *c, struct part *parts);
int cell_link_foreign_gparts(struct cell *c, struct gpart *gparts);
872
void cell_unlink_foreign_particles(struct cell *c);
873
int cell_count_parts_for_tasks(const struct cell *c);
874
int cell_count_gparts_for_tasks(const struct cell *c);
875
void cell_clean_links(struct cell *c, void *data);
876
877
878
879
void cell_make_multipoles(struct cell *c, integertime_t ti_current,
                          const struct gravity_props *const grav_props);
void cell_check_multipole(struct cell *c,
                          const struct gravity_props *const grav_props);
880
void cell_check_foreign_multipole(const struct cell *c);
881
void cell_clean(struct cell *c);
882
883
void cell_check_part_drift_point(struct cell *c, void *data);
void cell_check_gpart_drift_point(struct cell *c, void *data);
884
void cell_check_spart_drift_point(struct cell *c, void *data);
885
void cell_check_multipole_drift_point(struct cell *c, void *data);
886
void cell_reset_task_counters(struct cell *c);
887
int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s);
888
int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s,
889
                            const int with_star_formation);
890
int cell_unskip_black_holes_tasks(struct cell *c, struct scheduler *s);
891
int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s);
892
void cell_drift_part(struct cell *c, const struct engine *e, int force);
893
void cell_drift_gpart(struct cell *c, const struct engine *e, int force);
894
void cell_drift_spart(struct cell *c, const struct engine *e, int force);
895
void cell_drift_bpart(struct cell *c, const struct engine *e, int force);
896
void cell_drift_multipole(struct cell *c, const struct engine *e);
897
void cell_drift_all_multipoles(struct cell *c, const struct engine *e);
898
899
void cell_check_timesteps(const struct cell *c, const integertime_t ti_current,
                          const timebin_t max_bin);
900
void cell_store_pre_drift_values(struct cell *c);
901
void cell_set_star_resort_flag(struct cell *c);
902
903
void cell_activate_star_formation_tasks(struct cell *c, struct scheduler *s,
                                        const int with_feedback);
904
void cell_activate_subcell_hydro_tasks(struct cell *ci, struct cell *cj,
905
906
                                       struct scheduler *s,
                                       const int with_timestep_limiter);
907
908
void cell_activate_subcell_grav_tasks(struct cell *ci, struct cell *cj,
                                      struct scheduler *s);
909
void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj,
910
                                       struct scheduler *s,
911
912
                                       const int with_star_formation,
                                       const int with_timestep_sync);
913
void cell_activate_subcell_black_holes_tasks(struct cell *ci, struct cell *cj,
914
915
                                             struct scheduler *s,
                                             const int with_timestep_sync);
916
917
void cell_activate_subcell_external_grav_tasks(struct cell *ci,
                                               struct scheduler *s);
918
void cell_activate_super_spart_drifts(struct cell *c, struct scheduler *s);
919
void cell_activate_drift_part(struct cell *c, struct scheduler *s);
920
void cell_activate_drift_gpart(struct cell *c, struct scheduler *s);
Loic Hausammann's avatar
Loic Hausammann committed
921
void cell_activate_drift_spart(struct cell *c, struct scheduler *s);
922
void cell_activate_drift_bpart(struct cell *c, struct scheduler *s);
923
void cell_activate_sync_part(struct cell *c, struct scheduler *s);
924
void cell_activate_hydro_sorts(struct cell *c, int sid, struct scheduler *s);
Loic Hausammann's avatar
Loic Hausammann committed
925
void cell_activate_stars_sorts(struct cell *c, int sid, struct scheduler *s);
926
void cell_activate_limiter(struct cell *c, struct scheduler *s);
927
void cell_clear_drift_flags(struct cell *c, void *data);
928
void cell_clear_limiter_flags(struct cell *c, void *data);
Pedro Gonnet's avatar
Pedro Gonnet committed
929
void cell_set_super_mapper(void *map_data, int num_elements, void *extra_data);
930
931
void cell_check_spart_pos(const struct cell *c,
                          const struct spart *global_sparts);
932
933
934
void cell_check_sort_flags(const struct cell *c);
void cell_clear_stars_sort_flags(struct cell *c, const int unused_flags);
void cell_clear_hydro_sort_flags(struct cell *c, const int unused_flags);
935
int cell_has_tasks(struct cell *c);
936
937
void cell_remove_part(const struct engine *e, struct cell *c, struct part *p,
                      struct xpart *xp);
938
939
940
941
void cell_remove_gpart(const struct engine *e, struct cell *c,
                       struct gpart *gp);
void cell_remove_spart(const struct engine *e, struct cell *c,
                       struct spart *sp);
942
943
void cell_remove_bpart(const struct engine *e, struct cell *c,
                       struct bpart *bp);
944
struct spart *cell_add_spart(struct engine *e, struct cell *c);
Loic Hausammann's avatar
Loic Hausammann committed
945
946
947
948
struct gpart *cell_add_gpart(struct engine *e, struct cell *c);
struct spart *cell_spawn_new_spart_from_part(struct engine *e, struct cell *c,
                                             const struct part *p,
                                             const struct xpart *xp);
Matthieu Schaller's avatar
Matthieu Schaller committed
949
950
951
952
struct gpart *cell_convert_part_to_gpart(const struct engine *e, struct cell *c,
                                         struct part *p, struct xpart *xp);
struct gpart *cell_convert_spart_to_gpart(const struct engine *e,
                                          struct cell *c, struct spart *sp);
953
954
struct spart *cell_convert_part_to_spart(struct engine *e, struct cell *c,
                                         struct part *p, struct xpart *xp);
955
void cell_reorder_extra_parts(struct cell *c, const ptrdiff_t parts_offset);
956
957
void cell_reorder_extra_gparts(struct cell *c, struct part *parts,
                               struct spart *sparts);
958
void cell_reorder_extra_sparts(struct cell *c, const ptrdiff_t sparts_offset);
959
960
int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj,
                         const struct engine *e, const struct space *s);
961
int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct