cell.h 49.5 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>
Matthieu Schaller's avatar
Matthieu Schaller committed
32
#include <string.h>
33
34

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

47
/* Avoid cyclic inclusions */
48
struct engine;
49
struct scheduler;
50

51
52
53
/* 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.
54
55
 * The maximum was lowered by a further factor of 2 to be on the safe side.*/
#define cell_max_tag (1 << 29)
56

57
#define cell_align 128
58

59
60
61
/* Global variables. */
extern int cell_next_tag;

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

68
69
70
71
72
73
74
75
76
77
/* 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;
};

78
79
80
81
82
83
84
85
86
87
88
/* 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];

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

96
97
  /*! Hydro variables */
  struct {
Matthieu Schaller's avatar
Matthieu Schaller committed
98

99
100
101
    /*! Number of #part in this cell. */
    int count;

102
    /*! Maximal smoothing length. */
103
    float h_max;
104

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

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

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

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

117
  } hydro;
118

119
120
  /*! Gravity variables */
  struct {
121

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

125
126
    /*! Centre of mass. */
    double CoM[3];
127

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

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

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

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

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

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

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

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

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

  } grav;

157
158
159
160
161
162
  /*! Stars variables */
  struct {

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

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

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

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

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

175
176
  } stars;

177
178
179
180
181
182
183
  /*! Black hole variables */
  struct {

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

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

    /*! 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;

197
198
199
  /*! Maximal depth in that part of the tree */
  int maxdepth;

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

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

208
} SWIFT_STRUCT_ALIGN;
209

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

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

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

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

225
struct pcell_step_grav {
226

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

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

234
struct pcell_step_stars {
235

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

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

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

246
247
248
249
250
251
252
253
254
255
256
257
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;
};

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/**
 * @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;
274

275
  } stars;
276
277
278
279
280
281
282
283
284
285
286

  /*! Grav. variables */
  struct {

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

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

  } grav;
287
288
};

289
290
291
292
/**
 * @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.
 */
293
294
295
296
297
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),
298
299
  cell_flag_do_hydro_limiter = (1UL << 4),
  cell_flag_do_hydro_sub_limiter = (1UL << 5),
300
301
302
303
304
305
  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),
306
  cell_flag_do_bh_sub_drift = (1UL << 12),
307
308
  cell_flag_do_stars_resort = (1UL << 13),
  cell_flag_has_tasks = (1UL << 14),
309
310
  cell_flag_do_hydro_sync = (1UL << 15),
  cell_flag_do_hydro_sub_sync = (1UL << 16)
311
312
};

313
314
315
316
317
/**
 * @brief Cell within the tree structure.
 *
 * Contains particles, links to tasks, a multipole object and counters.
 */
318
319
struct cell {

320
  /*! The cell location on the grid. */
321
322
  double loc[3];

323
  /*! The cell dimensions. */
324
  double width[3];
325

326
  /*! Pointers to the next level of cells. */
327
328
  struct cell *progeny[8];

329
330
331
  /*! Linking pointer for "memory management". */
  struct cell *next;

332
  /*! Parent cell. */
333
334
  struct cell *parent;

335
336
337
  /*! Pointer to the top-level cell in a hierarchy */
  struct cell *top;

338
  /*! Super cell, i.e. the highest-level parent cell with *any* task */
339
  struct cell *super;
340

341
  /*! Cell flags bit-mask. */
342
  volatile uint32_t flags;
343

344
345
  /*! Hydro variables */
  struct {
346

347
348
    /*! Pointer to the #part data. */
    struct part *parts;
349

350
351
    /*! Pointer to the #xpart data. */
    struct xpart *xparts;
352

353
    /*! Pointer for the sorted indices. */
Matthieu Schaller's avatar
Matthieu Schaller committed
354
    struct sort_entry *sort;
355

356
357
    /*! Super cell, i.e. the highest-level parent cell that has a hydro
     * pair/self tasks */
358
    struct cell *super;
359

360
361
    /*! The task computing this cell's sorts. */
    struct task *sorts;
362

363
364
    /*! The drift task for parts */
    struct task *drift;
365

366
367
368
369
370
371
372
373
374
    /*! 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;

375
376
377
    /*! Linked list of the tasks computing this cell's limiter. */
    struct link *limiter;

378
379
380
381
382
383
384
385
386
387
388
389
    /*! 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;

390
391
392
    /*! The task to end the force calculation */
    struct task *end_force;

393
394
395
396
397
398
    /*! Dependency implicit task for cooling (in->cooling->out) */
    struct task *cooling_in;

    /*! Dependency implicit task for cooling (in->cooling->out) */
    struct task *cooling_out;

399
400
401
402
403
    /*! Task for cooling */
    struct task *cooling;

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

405
406
407
    /*! Task for sorting the stars again after a SF event */
    struct task *stars_resort;

408
409
410
    /*! Last (integer) time the cell's part were drifted forward in time. */
    integertime_t ti_old_part;

411
412
    /*! Minimum end of (integer) time step in this cell for hydro tasks. */
    integertime_t ti_end_min;
413

414
415
    /*! Maximum end of (integer) time step in this cell for hydro tasks. */
    integertime_t ti_end_max;
416

417
418
    /*! Maximum beginning of (integer) time step in this cell for hydro tasks.
     */
419
    integertime_t ti_beg_max;
420

421
422
    /*! Spin lock for various uses (#part case). */
    swift_lock_type lock;
423

424
425
426
    /*! Max smoothing length in this cell. */
    float h_max;

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

430
431
    /*! Maximum particle movement in this cell since the last sort. */
    float dx_max_sort;
432

433
434
    /*! Values of h_max before the drifts, used for sub-cell tasks. */
    float h_max_old;
435

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

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

442
443
444
    /*! Nr of #part in this cell. */
    int count;

445
446
447
    /*! Nr of #part this cell can hold after addition of new #part. */
    int count_total;

448
449
450
451
452
453
    /*! Number of #part updated in this cell. */
    int updated;

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

454
    /*! Bit mask of sort directions that will be needed in the next timestep. */
455
    uint16_t requires_sorts;
456

457
    /*! Bit mask of sorts that need to be computed for this cell. */
458
    uint16_t do_sort;
459

460
    /*! Bit-mask indicating the sorted directions */
461
    uint16_t sorted;
462

Matthieu Schaller's avatar
Matthieu Schaller committed
463
464
465
    /*! Bit-mask indicating the sorted directions */
    uint16_t sort_allocated;

Matthieu Schaller's avatar
Matthieu Schaller committed
466
#ifdef SWIFT_DEBUG_CHECKS
467

468
469
    /*! Last (integer) time the cell's sort arrays were updated. */
    integertime_t ti_sort;
470

471
#endif
472

473
  } hydro;
474

475
476
  /*! Grav variables */
  struct {
477

478
    /*! Pointer to the #gpart data. */
479
    struct gpart *parts;
480

481
482
483
    /*! Pointer to the #spart data at rebuild time. */
    struct gpart *parts_rebuild;

484
485
    /*! This cell's multipole. */
    struct gravity_tensors *multipole;
486

487
488
489
    /*! Super cell, i.e. the highest-level parent cell that has a grav pair/self
     * tasks */
    struct cell *super;
490

491
492
493
    /*! The drift task for gparts */
    struct task *drift;

494
495
496
    /*! Implicit task (going up- and down the tree) for the #gpart drifts */
    struct task *drift_out;

497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
    /*! 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;

521
522
523
    /*! The task to end the force calculation */
    struct task *end_force;

524
525
    /*! Minimum end of (integer) time step in this cell for gravity tasks. */
    integertime_t ti_end_min;
526

527
528
    /*! Maximum end of (integer) time step in this cell for gravity tasks. */
    integertime_t ti_end_max;
529

530
531
532
    /*! Maximum beginning of (integer) time step in this cell for gravity tasks.
     */
    integertime_t ti_beg_max;
533

534
    /*! Last (integer) time the cell's gpart were drifted forward in time. */
535
    integertime_t ti_old_part;
536

537
538
    /*! Last (integer) time the cell's multipole was drifted forward in time. */
    integertime_t ti_old_multipole;
539

540
    /*! Spin lock for various uses (#gpart case). */
541
    swift_lock_type plock;
542

543
544
    /*! Spin lock for various uses (#multipole case). */
    swift_lock_type mlock;
545

Loic Hausammann's avatar
Loic Hausammann committed
546
547
548
    /*! Spin lock for star formation use. */
    swift_lock_type star_formation_lock;

549
550
551
    /*! Nr of #gpart in this cell. */
    int count;

552
553
554
    /*! Nr of #gpart this cell can hold after addition of new #gpart. */
    int count_total;

555
    /*! Number of #gpart updated in this cell. */
556
    int updated;
557

558
    /*! Is the #gpart data of this cell being used in a sub-cell? */
559
    int phold;
560

561
562
    /*! Is the #multipole data of this cell being used in a sub-cell? */
    int mhold;
563

564
565
566
    /*! Number of M-M tasks that are associated with this cell. */
    short int nr_mm_tasks;

567
  } grav;
568

569
570
  /*! Stars variables */
  struct {
571

572
573
    /*! Pointer to the #spart data. */
    struct spart *parts;
574

575
576
577
    /*! Pointer to the #spart data at rebuild time. */
    struct spart *parts_rebuild;

578
579
580
581
582
    /*! The star ghost task itself */
    struct task *ghost;

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

Alexei Borissov's avatar
Alexei Borissov committed
584
585
586
    /*! Linked list of the tasks computing this cell's star feedback. */
    struct link *feedback;

587
    /*! The task computing this cell's sorts before the density. */
588
    struct task *sorts;
Matthieu Schaller's avatar
Matthieu Schaller committed
589

590
    /*! The drift task for sparts */
591
    struct task *drift;
592

593
594
    /*! Implicit tasks marking the entry of the stellar physics block of tasks
     */
595
596
    struct task *stars_in;

597
    /*! Implicit tasks marking the exit of the stellar physics block of tasks */
598
599
    struct task *stars_out;

600
601
602
    /*! Last (integer) time the cell's spart were drifted forward in time. */
    integertime_t ti_old_part;

603
604
605
    /*! Spin lock for various uses (#spart case). */
    swift_lock_type lock;

606
607
608
    /*! Spin lock for star formation use. */
    swift_lock_type star_formation_lock;

609
610
611
    /*! Nr of #spart in this cell. */
    int count;

612
613
614
    /*! Nr of #spart this cell can hold after addition of new #spart. */
    int count_total;

615
616
617
    /*! Max smoothing length in this cell. */
    float h_max;

Loic Hausammann's avatar
Loic Hausammann committed
618
619
620
621
622
623
624
625
626
    /*! 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
627
628
629
630
631
632
633
    /*! 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
634
    struct sort_entry *sort;
Matthieu Schaller's avatar
Matthieu Schaller committed
635

636
637
    /*! Bit mask of sort directions that will be needed in the next timestep. */
    uint16_t requires_sorts;
Matthieu Schaller's avatar
Matthieu Schaller committed
638
639

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

Matthieu Schaller's avatar
Matthieu Schaller committed
642
643
644
    /*! Bit-mask indicating the sorted directions */
    uint16_t sort_allocated;

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

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

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

658
659
    /*! Number of #spart updated in this cell. */
    int updated;
660

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

Folkert Nobels's avatar
Folkert Nobels committed
664
    /*! Star formation history struct */
665
    struct star_formation_history sfh;
666

Matthieu Schaller's avatar
Matthieu Schaller committed
667
668
669
670
671
#ifdef SWIFT_DEBUG_CHECKS
    /*! Last (integer) time the cell's sort arrays were updated. */
    integertime_t ti_sort;
#endif

672
  } stars;
673

674
675
676
677
678
679
680
681
682
  /*! Black hole variables */
  struct {

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

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

683
684
685
686
687
688
689
    /*! 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;

690
    /*! The star ghost task itself */
691
    struct task *density_ghost;
692

693
    /*! The star ghost task itself */
694
    struct task *swallow_ghost[3];
695
696

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

699
700
701
702
703
    /*! 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 */
704
705
706
707
    struct link *do_gas_swallow;

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

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

712
713
714
715
716
717
718
719
720
721
722
723
    /*! 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;

724
725
726
    /*! Max smoothing length in this cell. */
    float h_max;

727
728
729
730
731
732
    /*! 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;

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

736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
    /*! 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;

755
756
757
#ifdef WITH_MPI
  /*! MPI variables */
  struct {
758

759
760
761
    union {
      /* Single list of all send tasks associated with this cell. */
      struct link *send;
762

763
      /* Single list of all recv tasks associated with this cell. */
764
765
      struct link *recv;
    };
766

767
768
769
770
771
772
773
774
775
776
777
    /*! 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;
778

779
780
  } mpi;
#endif
781

782
783
  /*! The first kick task */
  struct task *kick1;
784

785
786
  /*! The second kick task */
  struct task *kick2;
787

788
789
790
  /*! The task to compute time-steps */
  struct task *timestep;

791
792
793
  /*! The task to limit the time-step of inactive particles */
  struct task *timestep_limiter;

794
795
  /*! The task to synchronize the time-step of inactive particles hit by
   * feedback */
796
  struct task *timestep_sync;
797

798
#ifdef WITH_LOGGER
Loic Hausammann's avatar
Format    
Loic Hausammann committed
799
800
  /*! The logger task */
  struct task *logger;
801
#endif
Loic Hausammann's avatar
Format    
Loic Hausammann committed
802

803
804
  /*! Minimum dimension, i.e. smallest edge of this cell (min(width)). */
  float dmin;
805

806
807
808
809
810
811
  /*! ID of the previous owner, e.g. runner. */
  int owner;

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

812
813
814
815
816
817
818
819
820
821
822
823
  /*! 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
824
#if defined(SWIFT_DEBUG_CHECKS) || defined(SWIFT_CELL_GRAPH)
825
826
  /* Cell ID (for debugging) */
  int cellID;
Loic Hausammann's avatar
Loic Hausammann committed
827
828
829
#endif

#ifdef SWIFT_DEBUG_CHECKS
830

831
832
833
834
835
836
837
  /*! 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

838
} SWIFT_STRUCT_ALIGN;
839

840
841
842
843
/* Convert cell location to ID. */
#define cell_getid(cdim, i, j, k) \
  ((int)(k) + (cdim)[2] * ((int)(j) + (cdim)[1] * (int)(i)))

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