cell.h 42.7 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
    /*! Maximal smoothing length. */
    double h_max;
99

100
101
    /*! Minimal integer end-of-timestep in this cell for hydro tasks */
    integertime_t ti_end_min;
102

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

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

109
    /*! Integer time of the last drift of the #part in this cell */
110
    integertime_t ti_old_part;
111

112
113
    /*! Number of #part in this cell. */
    int count;
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
162
163
    /*! Maximal smoothing length. */
    double h_max;

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
182
183
184
185
186
187
188
189
190
191
192
193
194
  /*! Black hole variables */
  struct {

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

    /*! Maximal smoothing length. */
    double h_max;

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

Pedro Gonnet's avatar
Pedro Gonnet committed
276
277
/** Bitmasks for the cell flags. Beware when adding flags that you don't exceed
    the size of the flags variable in the struct cell. */
278
279
280
281
282
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),
283
284
  cell_flag_do_hydro_limiter = (1UL << 4),
  cell_flag_do_hydro_sub_limiter = (1UL << 5),
285
286
287
288
289
290
  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),
291
292
  cell_flag_do_bh_sub_drift = (1UL << 12),
  cell_flag_do_stars_resort = (1UL << 13)
293
294
};

295
296
297
298
299
/**
 * @brief Cell within the tree structure.
 *
 * Contains particles, links to tasks, a multipole object and counters.
 */
300
301
struct cell {

302
  /*! The cell location on the grid. */
303
304
  double loc[3];

305
  /*! The cell dimensions. */
306
  double width[3];
307

308
  /*! Pointers to the next level of cells. */
309
310
  struct cell *progeny[8];

311
312
313
  /*! Linking pointer for "memory management". */
  struct cell *next;

314
  /*! Parent cell. */
315
316
  struct cell *parent;

317
318
319
  /*! Pointer to the top-level cell in a hierarchy */
  struct cell *top;

320
  /*! Super cell, i.e. the highest-level parent cell with *any* task */
321
  struct cell *super;
322

323
  /*! Cell flags bit-mask. */
324
  volatile uint32_t flags;
325

326
327
  /*! Hydro variables */
  struct {
328

329
330
    /*! Pointer to the #part data. */
    struct part *parts;
331

332
333
    /*! Pointer to the #xpart data. */
    struct xpart *xparts;
334

335
    /*! Pointer for the sorted indices. */
336
    struct sort_entry *sort[13];
337

338
339
    /*! Super cell, i.e. the highest-level parent cell that has a hydro
     * pair/self tasks */
340
    struct cell *super;
341

342
343
    /*! The task computing this cell's sorts. */
    struct task *sorts;
344

345
346
    /*! The drift task for parts */
    struct task *drift;
347

348
349
350
351
352
353
354
355
356
    /*! 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;

357
358
359
    /*! Linked list of the tasks computing this cell's limiter. */
    struct link *limiter;

360
361
362
363
364
365
366
367
368
369
370
371
    /*! 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;

372
373
374
    /*! The task to end the force calculation */
    struct task *end_force;

375
376
377
378
379
    /*! Task for cooling */
    struct task *cooling;

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

381
382
383
    /*! Task for sorting the stars again after a SF event */
    struct task *stars_resort;

384
385
    /*! Max smoothing length in this cell. */
    double h_max;
386

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

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

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

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

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

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

406
407
    /*! Maximum particle movement in this cell since the last sort. */
    float dx_max_sort;
408

409
410
    /*! Values of h_max before the drifts, used for sub-cell tasks. */
    float h_max_old;
411

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

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

418
419
420
    /*! Nr of #part in this cell. */
    int count;

421
422
423
    /*! Nr of #part this cell can hold after addition of new #part. */
    int count_total;

424
425
426
427
428
429
    /*! Number of #part updated in this cell. */
    int updated;

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

430
    /*! Bit mask of sort directions that will be needed in the next timestep. */
431
    uint16_t requires_sorts;
432

433
    /*! Bit mask of sorts that need to be computed for this cell. */
434
    uint16_t do_sort;
435

436
    /*! Bit-mask indicating the sorted directions */
437
    uint16_t sorted;
438

Matthieu Schaller's avatar
Matthieu Schaller committed
439
#ifdef SWIFT_DEBUG_CHECKS
440

441
442
    /*! Last (integer) time the cell's sort arrays were updated. */
    integertime_t ti_sort;
443

444
#endif
445

446
  } hydro;
447

448
449
  /*! Grav variables */
  struct {
450

451
    /*! Pointer to the #gpart data. */
452
    struct gpart *parts;
453

454
455
    /*! This cell's multipole. */
    struct gravity_tensors *multipole;
456

457
458
459
    /*! Super cell, i.e. the highest-level parent cell that has a grav pair/self
     * tasks */
    struct cell *super;
460

461
462
463
    /*! The drift task for gparts */
    struct task *drift;

464
465
466
    /*! Implicit task (going up- and down the tree) for the #gpart drifts */
    struct task *drift_out;

467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
    /*! 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;

491
492
493
    /*! The task to end the force calculation */
    struct task *end_force;

494
495
    /*! Minimum end of (integer) time step in this cell for gravity tasks. */
    integertime_t ti_end_min;
496

497
498
    /*! Maximum end of (integer) time step in this cell for gravity tasks. */
    integertime_t ti_end_max;
499

500
501
502
    /*! Maximum beginning of (integer) time step in this cell for gravity tasks.
     */
    integertime_t ti_beg_max;
503

504
    /*! Last (integer) time the cell's gpart were drifted forward in time. */
505
    integertime_t ti_old_part;
506

507
508
    /*! Last (integer) time the cell's multipole was drifted forward in time. */
    integertime_t ti_old_multipole;
509

510
    /*! Spin lock for various uses (#gpart case). */
511
    swift_lock_type plock;
512

513
514
    /*! Spin lock for various uses (#multipole case). */
    swift_lock_type mlock;
515

516
517
518
    /*! Nr of #gpart in this cell. */
    int count;

519
520
521
    /*! Nr of #gpart this cell can hold after addition of new #gpart. */
    int count_total;

522
    /*! Number of #gpart updated in this cell. */
523
    int updated;
524

525
    /*! Is the #gpart data of this cell being used in a sub-cell? */
526
    int phold;
527

528
529
    /*! Is the #multipole data of this cell being used in a sub-cell? */
    int mhold;
530

531
532
533
    /*! Number of M-M tasks that are associated with this cell. */
    short int nr_mm_tasks;

534
  } grav;
535

536
537
  /*! Stars variables */
  struct {
538

539
540
    /*! Pointer to the #spart data. */
    struct spart *parts;
541

542
543
544
    /*! Pointer to the #spart data at rebuild time. */
    struct spart *parts_rebuild;

545
546
547
548
549
    /*! The star ghost task itself */
    struct task *ghost;

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

Alexei Borissov's avatar
Alexei Borissov committed
551
552
553
    /*! Linked list of the tasks computing this cell's star feedback. */
    struct link *feedback;

554
    /*! The task computing this cell's sorts before the density. */
555
    struct task *sorts;
Matthieu Schaller's avatar
Matthieu Schaller committed
556

557
    /*! The drift task for sparts */
558
    struct task *drift;
559

560
561
    /*! Implicit tasks marking the entry of the stellar physics block of tasks
     */
562
563
    struct task *stars_in;

564
    /*! Implicit tasks marking the exit of the stellar physics block of tasks */
565
566
    struct task *stars_out;

Loic Hausammann's avatar
Loic Hausammann committed
567
568
569
    /*! Max smoothing length in this cell. */
    double h_max;

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

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

576
577
578
    /*! Spin lock for star formation use. */
    swift_lock_type star_formation_lock;

579
580
581
    /*! Nr of #spart in this cell. */
    int count;

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

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

603
604
    /*! Bit mask of sort directions that will be needed in the next timestep. */
    uint16_t requires_sorts;
Matthieu Schaller's avatar
Matthieu Schaller committed
605
606

    /*! Bit-mask indicating the sorted directions */
607
    uint16_t sorted;
Matthieu Schaller's avatar
Matthieu Schaller committed
608
609

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

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

615
616
617
618
619
620
    /*! 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;
621

622
623
    /*! Number of #spart updated in this cell. */
    int updated;
624

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

Folkert Nobels's avatar
Folkert Nobels committed
628
    /*! Star formation history struct */
629
    struct star_formation_history sfh;
630

Matthieu Schaller's avatar
Matthieu Schaller committed
631
632
633
634
635
#ifdef SWIFT_DEBUG_CHECKS
    /*! Last (integer) time the cell's sort arrays were updated. */
    integertime_t ti_sort;
#endif

636
  } stars;
637

638
639
640
641
642
643
644
645
646
  /*! Black hole variables */
  struct {

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

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

647
648
649
650
651
652
653
    /*! 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;

654
    /*! The star ghost task itself */
655
    struct task *density_ghost;
656

657
    /*! The star ghost task itself */
658
    struct task *swallow_ghost[3];
659
660

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

663
664
665
666
667
    /*! 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 */
668
669
670
671
    struct link *do_gas_swallow;

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

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

676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
    /*! Max smoothing length in this cell. */
    double h_max;

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

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

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

700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
    /*! 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;

719
720
721
#ifdef WITH_MPI
  /*! MPI variables */
  struct {
722

723
724
725
    union {
      /* Single list of all send tasks associated with this cell. */
      struct link *send;
726

727
      /* Single list of all recv tasks associated with this cell. */
728
729
      struct link *recv;
    };
730

731
732
733
734
735
736
737
738
739
740
741
    /*! 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;
742

743
744
  } mpi;
#endif
745

746
747
  /*! The first kick task */
  struct task *kick1;
748

749
750
  /*! The second kick task */
  struct task *kick2;
751

752
753
754
  /*! The task to compute time-steps */
  struct task *timestep;

755
756
  /*! The task to limit the time-step of inactive particles */
  struct task *timestep_limiter;
757

Loic Hausammann's avatar
Format    
Loic Hausammann committed
758
759
760
  /*! The logger task */
  struct task *logger;

761
762
  /*! Minimum dimension, i.e. smallest edge of this cell (min(width)). */
  float dmin;
763

764
765
766
767
768
769
  /*! ID of the previous owner, e.g. runner. */
  int owner;

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

770
771
772
773
774
775
776
777
778
779
780
781
  /*! 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
782
#if defined(SWIFT_DEBUG_CHECKS) || defined(SWIFT_CELL_GRAPH)
783
784
  /* Cell ID (for debugging) */
  int cellID;
Loic Hausammann's avatar
Loic Hausammann committed
785
786
787
#endif

#ifdef SWIFT_DEBUG_CHECKS
788

789
790
791
792
793
794
795
  /*! 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

796
} SWIFT_STRUCT_ALIGN;
797

798
799
800
801
/* Convert cell location to ID. */
#define cell_getid(cdim, i, j, k) \
  ((int)(k) + (cdim)[2] * ((int)(j) + (cdim)[1] * (int)(i)))

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

930
/**
Peter W. Draper's avatar
Peter W. Draper committed
931
 * @brief Compute the square of the minimal distance between any two points in
Matthieu Schaller's avatar
Matthieu Schaller committed
932
 * two cells of the same size
933
934
935
936
937
938
 *
 * @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
 */
Matthieu Schaller's avatar
Matthieu Schaller committed
939
940
941
__attribute__((always_inline)) INLINE static double cell_min_dist2_same_size(
    const struct cell *restrict ci, const struct cell *restrict cj,
    const int periodic, const double dim[3]) {
942
943

#ifdef SWIFT_DEBUG_CHECKS
Matthieu Schaller's avatar
Matthieu Schaller committed
944
945
946
  if (ci->width[0] != cj->width[0]) error("Cells of different size!");
  if (ci->width[1] != cj->width[1]) error("Cells of different size!");
  if (ci->width[2] != cj->width[2]) error("Cells of different size!");
947
948
#endif

Matthieu Schaller's avatar
Matthieu Schaller committed
949
950
951
952
953
954
955
956
957
958
959
960
  const double cix_min = ci->loc[0];
  const double ciy_min = ci->loc[1];
  const double ciz_min = ci->loc[2];
  const double cjx_min = cj->loc[0];
  const double cjy_min = cj->loc[1];
  const double cjz_min = cj->loc[2];

  const double cix_max = ci->loc[0] + ci->width[0];
  const double ciy_max = ci->loc[1] + ci->width[1];
  const double ciz_max = ci->loc[2] + ci->width[2];
  const double cjx_max = cj->loc[0] + cj->width[0];
  const double cjy_max = cj->loc[1] + cj->width[1];
961
962
963
964
965
  const double cjz_max = cj->loc[2] + cj->width[2];

  if (periodic) {

    const double dx = min4(fabs(nearest(cix_min - cjx_min, dim[0])),
Matthieu Schaller's avatar
Matthieu Schaller committed
966
967
968
969
                           fabs(nearest(cix_min - cjx_max, dim[0])),
                           fabs(nearest(cix_max - cjx_min, dim[0])),
                           fabs(nearest(cix_max - cjx_max, dim[0])));

970
    const double dy = min4(fabs(nearest(ciy_min - cjy_min, dim[1])),
Matthieu Schaller's avatar
Matthieu Schaller committed
971
972
973
974
                           fabs(nearest(ciy_min - cjy_max, dim[1])),
                           fabs(nearest(ciy_max - cjy_min, dim[1])),
                           fabs(nearest(ciy_max - cjy_max, dim[1])));

975
    const double dz = min4(fabs(nearest(ciz_min - cjz_min, dim[2])),