GADGET-4
particle_data.h
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#ifndef PARTDATA_H
13#define PARTDATA_H
14
15#include "gadgetconfig.h"
16
17#include <atomic>
18#include <climits>
19
20#include "../data/constants.h"
21#include "../data/dtypes.h"
22#include "../data/idstorage.h"
23#include "../data/intposconvert.h"
24#include "../data/macros.h"
25#include "../data/mymalloc.h"
26#include "../data/symtensors.h"
27#include "../mpi_utils/setcomm.h"
28#include "../system/system.h"
29#include "../time_integration/timestep.h"
30
35{
36 // we do this ugly trick of using memcpy for our own copy constructor and assignment operator
37 // because the atomic_flag in particle_data has an implicitly deleted copy operator... so that the implicit functions
38 // for this are unavailable. But we know what we are doing here, and surrounding this with an ugly hack
39 // is the easiest way at the moment to work around this in our case unnecessary protection
40
42
43 // declare our own copy constructor
44 particle_data(particle_data& other) { memcpy(static_cast<void*>(this), static_cast<void*>(&other), sizeof(particle_data)); }
45
46 // declare our own assignment operator
48 {
49 memcpy(static_cast<void*>(this), static_cast<void*>(&other), sizeof(particle_data));
50 return *this;
51 }
52
56#if defined(PMGRID) && defined(PERIODIC) && !defined(TREEPM_NOTIMESPLIT)
57 MyFloat GravPM[3];
58#endif
59
60 std::atomic<integertime> Ti_Current;
61 float OldAcc;
64#ifndef LEAN
65 private:
66 MyDouble Mass;
67 public:
68#endif
69
70 MyIDStorage ID; // 6-byte
71 signed char TimeBinGrav; // 1-byte
72#ifndef LEAN
73 signed char TimeBinHydro;
74#endif
75#if defined(MERGERTREE) && defined(SUBFIND)
76 compactrank_t PrevRankInSubhalo; // 1-byte
77 MyHaloNrType PrevSubhaloNr; // 6-byte
78 approxlen PrevSizeOfSubhalo; // 2-byte
79#endif
80
81#ifndef LEAN
82 private:
83 unsigned char Type;
84 public:
85#endif
86
87#ifndef LEAN
88 std::atomic_flag access;
89#endif
90
91#ifdef REARRANGE_OPTION
92 unsigned long long TreeID;
93#endif
94
95#if NSOFTCLASSES > 1
96 private:
97 unsigned char
98 SofteningClass : 7; /* we use only 7 bits here so that we can stuff 1 bit for ActiveFlag into it in the Tree_Points structure */
99 public:
100#endif
101
102#if defined(PMGRID) && defined(PLACEHIGHRESREGION)
103 unsigned char InsideOutsideFlag : 1;
104#endif
105
106#ifdef FORCETEST
107 MyFloat GravAccelDirect[3];
108 MyFloat PotentialDirect;
109 MyFloat DistToID1;
110#ifdef PMGRID
111 MyFloat GravAccelShortRange[3];
112 MyFloat PotentialShortRange;
113#ifdef PLACEHIGHRESREGION
114 MyFloat GravAccelVeryShortRange[3];
115 MyFloat PotentialVeryShortRange;
116 MyFloat PotentialHPM;
117 MyFloat GravAccelHPM[3];
118#endif
119#endif
120#ifdef FORCETEST_FIXEDPARTICLESET
121 bool SelectedFlag;
122#endif
123#endif
124
125#if defined(EVALPOTENTIAL) || defined(OUTPUT_POTENTIAL)
126 MyFloat Potential;
127#if defined(PMGRID)
128 MyFloat PM_Potential;
129#endif
130#ifdef EXTERNALGRAVITY
131 MyFloat ExtPotential;
132#endif
133#endif
134
135#ifdef STARFORMATION
136 MyFloat StellarAge;
137 MyFloat Metallicity;
138#endif
139
140 inline unsigned char getType(void)
141 {
142#ifdef LEAN
143 return 1;
144#else
145 return Type;
146#endif
147 }
148
149 inline unsigned char getTimeBinHydro(void)
150 {
151#ifndef LEAN
152 return TimeBinHydro;
153#else
154 return 0;
155#endif
156 }
157
158 inline void setTimeBinHydro(unsigned char bin)
159 {
160#ifndef LEAN
161 TimeBinHydro = bin;
162#endif
163 }
164
165 inline void setType(unsigned char type)
166 {
167#ifndef LEAN
168 Type = type;
169#endif
170 }
171
172 inline float getOldAcc(void) { return OldAcc; }
173
174 inline int getGravCost(void) { return GravCost; }
175
176 inline MyDouble getMass(void)
177 {
178#ifdef LEAN
179 return All.PartMass;
180#else
181 return Mass;
182#endif
183 }
184
185 inline void setMass(MyDouble mass)
186 {
187#ifndef LEAN
188 Mass = mass;
189#endif
190 }
191
192 inline integertime get_Ti_Current(void) { return Ti_Current; }
193
194 inline signed char getTimeBinGrav(void) { return TimeBinGrav; }
195
196 inline unsigned char getSofteningClass(void)
197 {
198#if NSOFTCLASSES > 1
199 return SofteningClass;
200#else
201 return 0;
202#endif
203 }
204
205 inline void setSofteningClass(unsigned char softclass)
206 {
207#if NSOFTCLASSES > 1
208 SofteningClass = softclass;
209#endif
210 }
211
212 inline double getAscale(void) { return All.Time; }
213
214#if defined(LIGHTCONE_PARTICLES_GROUPS)
215 inline void setFlagSaveDistance(void) {}
216 inline void clearFlagSaveDistance(void) {}
217
218 inline bool getFlagSaveDistance(void) { return true; }
219#endif
220};
221
223{
225#if defined(MERGERTREE)
226 MyHaloNrType SubhaloNr;
227 approxlen SizeOfSubhalo;
228 compactrank_t RankInSubhalo;
229#endif
231
234
235#ifdef SUBFIND
236 int SubRankInGr;
237
238#ifndef SUBFIND_HBT
239 struct nearest_ngb_data
240 {
241 location index[2];
242 int count;
243 };
244
245 nearest_ngb_data nearest;
246
247 int submark;
248 int InvIndex;
249#endif
250
251#ifndef LEAN
252 int Type;
253 MyFloat Utherm;
254#endif
255
256#ifdef SUBFIND_STORE_LOCAL_DENSITY
257 MyFloat SubfindHsml; // search radius used for SUBFIND dark matter neighborhood
258 MyFloat SubfindDensity; // total matter density
259 MyFloat SubfindVelDisp; // 3D dark matter velocity dispersion
260#endif
261
262 union
263 {
264 struct
265 {
266 int originindex, origintask;
267
268 union
269 {
270 MyFloat DM_Density;
271 MyFloat DM_Potential;
272 } u;
273
274 } s;
275
277 } u;
278
279 union
280 {
281 MyFloat DM_Hsml;
282 MyFloat DM_BindingEnergy;
283 } v;
284#else
285 /* this are fields defined when we have FOF without SUBFIND */
286#ifndef LEAN
287 int Type;
288#endif
289 union
290 {
292 } u;
293#endif
294};
295
296#ifdef SUBFIND_ORPHAN_TREATMENT
297struct idstoredata
298{
299 int NumPart;
300 MyIDType* ID;
301};
302
303#endif
304
305#endif
global_data_all_processes All
Definition: main.cc:40
int integertime
Definition: constants.h:331
float MyDouble
Definition: dtypes.h:87
float MyFloat
Definition: dtypes.h:86
uint32_t MyIntPosType
Definition: dtypes.h:35
unsigned int MyIDType
Definition: dtypes.h:68
std::atomic_flag access
Definition: particle_data.h:88
void setSofteningClass(unsigned char softclass)
std::atomic< integertime > Ti_Current
Definition: particle_data.h:60
integertime get_Ti_Current(void)
particle_data & operator=(particle_data &other)
Definition: particle_data.h:47
MyDouble getMass(void)
void setMass(MyDouble mass)
int getGravCost(void)
unsigned char getSofteningClass(void)
unsigned char getTimeBinHydro(void)
MyFloat Vel[3]
Definition: particle_data.h:54
MyIDStorage ID
Definition: particle_data.h:70
signed char TimeBinGrav
Definition: particle_data.h:71
signed char getTimeBinGrav(void)
unsigned char getType(void)
float getOldAcc(void)
particle_data(particle_data &other)
Definition: particle_data.h:44
void setTimeBinHydro(unsigned char bin)
signed char TimeBinHydro
Definition: particle_data.h:73
vector< MyFloat > GravAccel
Definition: particle_data.h:55
void setType(unsigned char type)
MyIntPosType IntPos[3]
Definition: particle_data.h:53
double getAscale(void)
MyHaloNrType GroupNr
peanokey Key
union subfind_data::@0 u