cell.h 43.6 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. */
341
    struct sort_entry *sort[13];
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
#ifdef SWIFT_DEBUG_CHECKS
445

446
447
    /*! Last (integer) time the cell's sort arrays were updated. */
    integertime_t ti_sort;
448

449
#endif
450

451
  } hydro;
452

453
454
  /*! Grav variables */
  struct {
455

456
    /*! Pointer to the #gpart data. */
457
    struct gpart *parts;
458

459
460
    /*! This cell's multipole. */
    struct gravity_tensors *multipole;
461

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

466
467
468
    /*! The drift task for gparts */
    struct task *drift;

469
470
471
    /*! Implicit task (going up- and down the tree) for the #gpart drifts */
    struct task *drift_out;

472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
    /*! 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;

496
497
498
    /*! The task to end the force calculation */
    struct task *end_force;

499
500
    /*! Minimum end of (integer) time step in this cell for gravity tasks. */
    integertime_t ti_end_min;
501

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

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

509
    /*! Last (integer) time the cell's gpart were drifted forward in time. */
510
    integertime_t ti_old_part;
511

512
513
    /*! Last (integer) time the cell's multipole was drifted forward in time. */
    integertime_t ti_old_multipole;
514

515
    /*! Spin lock for various uses (#gpart case). */
516
    swift_lock_type plock;
517

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

521
522
523
    /*! Nr of #gpart in this cell. */
    int count;

524
525
526
    /*! Nr of #gpart this cell can hold after addition of new #gpart. */
    int count_total;

527
    /*! Number of #gpart updated in this cell. */
528
    int updated;
529

530
    /*! Is the #gpart data of this cell being used in a sub-cell? */
531
    int phold;
532

533
534
    /*! Is the #multipole data of this cell being used in a sub-cell? */
    int mhold;
535

536
537
538
    /*! Number of M-M tasks that are associated with this cell. */
    short int nr_mm_tasks;

539
  } grav;
540

541
542
  /*! Stars variables */
  struct {
543

544
545
    /*! Pointer to the #spart data. */
    struct spart *parts;
546

547
548
549
    /*! Pointer to the #spart data at rebuild time. */
    struct spart *parts_rebuild;

550
551
552
553
554
    /*! The star ghost task itself */
    struct task *ghost;

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

Alexei Borissov's avatar
Alexei Borissov committed
556
557
558
    /*! Linked list of the tasks computing this cell's star feedback. */
    struct link *feedback;

559
    /*! The task computing this cell's sorts before the density. */
560
    struct task *sorts;
Matthieu Schaller's avatar
Matthieu Schaller committed
561

562
    /*! The drift task for sparts */
563
    struct task *drift;
564

565
566
    /*! Implicit tasks marking the entry of the stellar physics block of tasks
     */
567
568
    struct task *stars_in;

569
    /*! Implicit tasks marking the exit of the stellar physics block of tasks */
570
571
    struct task *stars_out;

572
573
574
    /*! Last (integer) time the cell's spart were drifted forward in time. */
    integertime_t ti_old_part;

575
576
577
    /*! Spin lock for various uses (#spart case). */
    swift_lock_type lock;

578
579
580
    /*! Spin lock for star formation use. */
    swift_lock_type star_formation_lock;

581
582
583
    /*! Nr of #spart in this cell. */
    int count;

584
585
586
    /*! Nr of #spart this cell can hold after addition of new #spart. */
    int count_total;

587
588
589
    /*! Max smoothing length in this cell. */
    float h_max;

Loic Hausammann's avatar
Loic Hausammann committed
590
591
592
593
594
595
596
597
598
    /*! 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
599
600
601
602
603
604
605
    /*! 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. */
606
    struct sort_entry *sort[13];
Matthieu Schaller's avatar
Matthieu Schaller committed
607

608
609
    /*! Bit mask of sort directions that will be needed in the next timestep. */
    uint16_t requires_sorts;
Matthieu Schaller's avatar
Matthieu Schaller committed
610
611

    /*! Bit-mask indicating the sorted directions */
612
    uint16_t sorted;
Matthieu Schaller's avatar
Matthieu Schaller committed
613
614

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

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

620
621
622
623
624
625
    /*! 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;
626

627
628
    /*! Number of #spart updated in this cell. */
    int updated;
629

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

Folkert Nobels's avatar
Folkert Nobels committed
633
    /*! Star formation history struct */
634
    struct star_formation_history sfh;
635

Matthieu Schaller's avatar
Matthieu Schaller committed
636
637
638
639
640
#ifdef SWIFT_DEBUG_CHECKS
    /*! Last (integer) time the cell's sort arrays were updated. */
    integertime_t ti_sort;
#endif

641
  } stars;
642

643
644
645
646
647
648
649
650
651
  /*! Black hole variables */
  struct {

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

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

652
653
654
655
656
657
658
    /*! 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;

659
    /*! The star ghost task itself */
660
    struct task *density_ghost;
661

662
    /*! The star ghost task itself */
663
    struct task *swallow_ghost[3];
664
665

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

668
669
670
671
672
    /*! 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 */
673
674
675
676
    struct link *do_gas_swallow;

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

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

681
682
683
684
685
686
687
688
689
690
691
692
    /*! 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;

693
694
695
    /*! Max smoothing length in this cell. */
    float h_max;

696
697
698
699
700
701
    /*! 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;

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

705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
    /*! 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;

724
725
726
#ifdef WITH_MPI
  /*! MPI variables */
  struct {
727

728
729
730
    union {
      /* Single list of all send tasks associated with this cell. */
      struct link *send;
731

732
      /* Single list of all recv tasks associated with this cell. */
733
734
      struct link *recv;
    };
735

736
737
738
739
740
741
742
743
744
745
746
    /*! 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;
747

748
749
  } mpi;
#endif
750

751
752
  /*! The first kick task */
  struct task *kick1;
753

754
755
  /*! The second kick task */
  struct task *kick2;
756

757
758
759
  /*! The task to compute time-steps */
  struct task *timestep;

760
761
762
  /*! The task to limit the time-step of inactive particles */
  struct task *timestep_limiter;

763
764
  /*! The task to synchronize the time-step of inactive particles hit by
   * feedback */
765
  struct task *timestep_sync;
766

767
#ifdef WITH_LOGGER
Loic Hausammann's avatar
Format    
Loic Hausammann committed
768
769
  /*! The logger task */
  struct task *logger;
770
#endif
Loic Hausammann's avatar
Format    
Loic Hausammann committed
771

772
773
  /*! Minimum dimension, i.e. smallest edge of this cell (min(width)). */
  float dmin;
774

775
776
777
778
779
780
  /*! ID of the previous owner, e.g. runner. */
  int owner;

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

781
782
783
784
785
786
787
788
789
790
791
792
  /*! 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
793
#if defined(SWIFT_DEBUG_CHECKS) || defined(SWIFT_CELL_GRAPH)
794
795
  /* Cell ID (for debugging) */
  int cellID;
Loic Hausammann's avatar
Loic Hausammann committed
796
797
798
#endif

#ifdef SWIFT_DEBUG_CHECKS
799

800
801
802
803
804
805
806
  /*! 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

807
} SWIFT_STRUCT_ALIGN;
808

809
810
811
812
/* Convert cell location to ID. */
#define cell_getid(cdim, i, j, k) \
  ((int)(k) + (cdim)[2] * ((int)(j) + (cdim)[1] * (int)(i)))

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

950
/**
Peter W. Draper's avatar
Peter W. Draper committed
951
 * @brief Compute the square of the minimal distance between any two points in
Matthieu Schaller's avatar
Matthieu Schaller committed
952
 * two cells of the same size
953
954
955
956
957
958
 *
 * @param ci The first #cell.
 * @param cj The second #cell.
 * @param periodic Are we using periodic BCs?
 * @param dim The dimensions of the simulation volume
 */