MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
partmanager.h
Go to the documentation of this file.
1 #ifndef _PART_DATA_H
2 #define _PART_DATA_H
3 
4 #include "types.h"
5 #include "utils/peano.h"
6 
11 {
12  double Pos[3];
13  float Mass;
15  struct {
16  /* particle type. 0=gas, 1=halo, 2=disk, 3=bulge, 4=stars, 5=bndry */
17  unsigned int Type :4;
18 
19  unsigned int IsGarbage :1; /* True for a garbage particle. readonly: Use slots_mark_garbage to mark this.*/
20  unsigned int Swallowed :1; /* True if the particle is being swallowed; used in BH to determine swallower and swallowee;*/
21  unsigned int spare_1 :1; /*Unused, ensures alignment to a char*/
22  unsigned int BHHeated :1; /* Flags that particle was heated by a BH this timestep*/
23  unsigned char Generation; /* How many particles it has spawned; used to generate unique particle ID.
24  may wrap around with too many SFR/BH if a feedback model goes rogue */
25 
26  unsigned char TimeBin; /* Time step bin; 0 for unassigned.*/
27  /* To ensure alignment to a 32-bit boundary.*/
28  unsigned char HeIIIionized; /* True if the particle has undergone helium reionization.
29  * This could be a bitfield: it isn't because we need to change it in an atomic.
30  * Changing a bitfield in an atomic seems to work in OpenMP 5.0 on gcc 9 and icc 18 and 19,
31  * so we should be able to make it a bitfield at some point. */
32  };
33 
34  int PI; /* particle property index; used by BH, SPH and STAR.
35  points to the corresponding structure in (SPH|BH|STAR)P array.*/
39 
40  MyFloat Vel[3]; /* particle velocity at its current time */
41  MyFloat GravAccel[3]; /* particle acceleration due to short-range gravity */
42 
43  MyFloat GravPM[3]; /* particle acceleration due to long-range PM gravity force */
44 
45  MyFloat Potential; /* gravitational potential. This is the total potential after gravtree+gravpm is called. */
46 
47  /* DtHsml is 1/3 DivVel * Hsml evaluated at the last active timestep for this particle.
48  * This predicts Hsml during the current timestep in the way used in Gadget-4, more accurate
49  * than the Gadget-2 prediction which could run away in deep timesteps. Used also
50  * to limit timesteps by density change. */
51  union {
53  /* This is the destination task during the fof particle exchange.
54  * It is never used outside of that code, and the
55  * particles are copied into a new PartManager before setting it,
56  * so it is safe to union with DtHsml.*/
58  };
60 
61  /* Union these two because they are transients: they are hard to move
62  * to private arrays because they need to travel with the particle during exchange*/
63  union {
64  /* The peano key is a hash of the position used in the domain decomposition.
65  * It is slow to generate so we store it here.*/
66  peano_t Key; /* only by domain.c and force_tree_rebuild */
67  /* FOF Group number: only has meaning during FOF.*/
68  int64_t GrNr;
69  };
70 
71 };
72 
73 extern struct part_manager_type {
74  struct particle_data *Base; /* Pointer to particle data on local processor. */
76  int64_t NumPart;
78  int64_t MaxPart;
79  /* Random shift applied to the box. This is changed
80  * every domain decomposition to prevent correlated
81  * errors building up in the tree force. */
83  /* Current box size so we can work out periodic boundaries*/
84  double BoxSize;
86 
87 /*Compatibility define*/
88 #define P PartManager->Base
89 
90 /*Allocate memory for the particles*/
91 void particle_alloc_memory(struct part_manager_type * PartManager, double BoxSize, int64_t MaxPart);
92 
93 /* Updates the global storing the current random offset of the particles,
94  * and stores the relative offset from the last random offset in rel_random_shift.
95  * RandomParticleOffset is the max adjustment as a fraction of the box. */
96 void update_random_offset(struct part_manager_type * PartManager, double * rel_random_shift, double RandomParticleOffset);
97 
98 /* Finds the correct relative position accounting for periodicity*/
99 #define NEAREST(x, BoxSize) (((x)>0.5*BoxSize)?((x)-BoxSize):(((x)<-0.5*BoxSize)?((x)+BoxSize):(x)))
100 
101 static inline double DMAX(double a, double b) {
102  if(a > b) return a;
103  return b;
104 }
105 static inline double DMIN(double a, double b) {
106  if(a < b) return a;
107  return b;
108 }
109 static inline int IMAX(int a, int b) {
110  if(a > b) return a;
111  return b;
112 }
113 static inline int IMIN(int a, int b) {
114  if(a < b) return a;
115  return b;
116 }
117 
118 #endif
static double DMIN(double a, double b)
Definition: partmanager.h:105
static double DMAX(double a, double b)
Definition: partmanager.h:101
static int IMIN(int a, int b)
Definition: partmanager.h:113
static int IMAX(int a, int b)
Definition: partmanager.h:109
struct part_manager_type PartManager[1]
void update_random_offset(struct part_manager_type *PartManager, double *rel_random_shift, double RandomParticleOffset)
Definition: partmanager.c:43
void particle_alloc_memory(struct part_manager_type *PartManager, double BoxSize, int64_t MaxPart)
Definition: partmanager.c:14
uint64_t peano_t
Definition: peano.h:7
struct particle_data * Base
Definition: partmanager.h:74
double CurrentParticleOffset[3]
Definition: partmanager.h:82
unsigned char TimeBin
Definition: partmanager.h:26
int64_t GrNr
Definition: partmanager.h:68
MyFloat Potential
Definition: partmanager.h:45
unsigned int spare_1
Definition: partmanager.h:21
unsigned char HeIIIionized
Definition: partmanager.h:28
MyFloat Hsml
Definition: partmanager.h:59
MyIDType ID
Definition: partmanager.h:38
unsigned int Swallowed
Definition: partmanager.h:20
MyFloat DtHsml
Definition: partmanager.h:52
MyFloat Vel[3]
Definition: partmanager.h:40
MyFloat GravAccel[3]
Definition: partmanager.h:41
double Pos[3]
Definition: partmanager.h:12
MyFloat GravPM[3]
Definition: partmanager.h:43
peano_t Key
Definition: partmanager.h:66
unsigned int Type
Definition: partmanager.h:17
unsigned int IsGarbage
Definition: partmanager.h:19
unsigned int BHHeated
Definition: partmanager.h:22
inttime_t Ti_drift
Definition: partmanager.h:36
unsigned char Generation
Definition: partmanager.h:23
int32_t inttime_t
Definition: types.h:8
uint64_t MyIDType
Definition: types.h:10
LOW_PRECISION MyFloat
Definition: types.h:19