GADGET-4
lcparticles.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 LCPART_H
13 #define LCPART_H
14 
15 #if defined(LIGHTCONE) && defined(LIGHTCONE_PARTICLES)
16 
17 #include <math.h>
18 
19 #include "gadgetconfig.h"
20 
21 #include "../data/constants.h"
22 #include "../data/dtypes.h"
23 #include "../data/intposconvert.h"
24 #include "../data/lightcone_particle_data.h"
25 #include "../data/macros.h"
26 #include "../data/mymalloc.h"
27 #include "../data/particle_data.h"
28 #include "../data/sph_particle_data.h"
29 #include "../mpi_utils/mpi_utils.h"
30 #include "../mpi_utils/setcomm.h"
31 #include "../system/system.h"
32 #include "../time_integration/timestep.h"
33 
34 class lcparticles : public intposconvert, public setcomm
35 {
36  public:
37  lcparticles(MPI_Comm comm) : setcomm(comm) {}
38 
39  int NumPart;
40  int NumGas = 0; /* this is added here to simplify the template code */
41 
42  int MaxPart;
43  int MaxPartSph = 0; /* this is added here to simplify the template code */
44 
45  long long TotNumPart;
46  long long TotNumGas;
47 
48  typedef lightcone_particle_data pdata;
49 
53  lightcone_particle_data *P;
55  /* the following struture holds data that is stored for each SPH particle in addition to the collisionless
56  * variables.
57  */
58 
59  sph_particle_data *SphP = NULL; /* the current code does not yet support actual Sph particles on the lightcone */
60 
61  subfind_data *PS;
62 
63  int *HealPixTab_PartCount;
64  int Npix;
65  int FirstPix;
66  int NpixLoc;
67 
68  /* This routine allocates memory for
69  * particle storage, both the collisionless and the SPH particles.
70  * The memory for the ordered binary tree of the timeline
71  * is also allocated.
72  */
73  void allocate_memory(void)
74  {
75  if(MaxPart < BASENUMBER)
76  MaxPart = BASENUMBER;
77 
78  P = (lightcone_particle_data *)Mem.mymalloc_movable_clear(&P, "P", MaxPart * sizeof(lightcone_particle_data));
79  }
80 
81  void free_memory(void) { Mem.myfree(P); }
82 
83  void reallocate_memory_maxpart(int maxpartNew)
84  {
85  MaxPart = maxpartNew;
86 
87  if(MaxPart < BASENUMBER)
88  MaxPart = BASENUMBER;
89 
90  P = (lightcone_particle_data *)Mem.myrealloc_movable(P, MaxPart * sizeof(lightcone_particle_data));
91 
92  /*
93  if(NumPart > MaxPart) // should be ok because this only happens when P has already been copied away
94  Terminate("NumPart=%d > MaxPart=%d", NumPart, MaxPart);
95  */
96  }
97 
98  void reallocate_memory_maxpartsph(int maxpartNew)
99  {
100  // Don't need to do anything here.
101  }
102 
103  bool TestIfAboveFillFactor(int SpMaxPart)
104  {
105  int max_in[2] = {NumPart, SpMaxPart}, max_out[2];
106  MPI_Allreduce(max_in, max_out, 2, MPI_INT, MPI_MAX, Communicator);
107 
108  /* also recompute the total number of particles in buffer to have current value */
109  sumup_large_ints(1, &NumPart, &TotNumPart, Communicator);
110 
111  if(max_out[0] > 0 && (All.Ti_Current >= TIMEBASE || max_out[0] >= LIGHTCONE_MAX_FILLFACTOR * max_out[1]))
112  return true;
113  else
114  return false;
115  }
116 
117  static bool compare_ID(const lightcone_particle_data &a, const lightcone_particle_data &b) { return a.ID.get() < b.ID.get(); }
118 
119  static bool compare_ipnest(const lightcone_particle_data &a, const lightcone_particle_data &b) { return a.ipnest < b.ipnest; }
120 
121 #ifdef REARRANGE_OPTION
122  static bool compare_TreeID_ID(const lightcone_particle_data &a, const lightcone_particle_data &b)
123  {
124  if(a.TreeID < b.TreeID)
125  return true;
126 
127  if(a.TreeID > b.TreeID)
128  return false;
129 
130  return a.ID.get() < b.ID.get();
131  }
132 #endif
133 
134  void dump_particles(void) {}
135 
136  inline int drift_particle(lightcone_particle_data *P, sph_particle_data *SphP, integertime time1, bool ignore_light_cone = false)
137  {
138  return 0;
139  }
140 
141  inline MyFloat get_Hsml(int i) { return 0; }
142 
143  inline MyFloat get_DtHsml(int i) { return 0; }
144 
145  inline MyFloat get_OldAcc(int i) { return 0; }
146 
147  inline MyFloat get_Csnd(int i) { return 0; }
148 
149  inline double get_utherm_from_entropy(int i) { return 0; }
150 
151  inline int getTimeBinSynchronized(int bin) { return 1; }
152 
153  void fill_active_gravity_list_with_all_particles(void) {}
154 
155 #ifdef FOF
156  MyIDStorage *MinID;
157  int *Head, *Len, *Next, *Tail, *MinIDTask;
158  MyFloat *fof_nearest_distance;
159  MyFloat *fof_nearest_hsml;
160 #if defined(LIGHTCONE_PARTICLES_GROUPS)
161  double *DistanceOrigin;
162 #endif
163 
164  struct bit_flags
165  {
166  unsigned char Nonlocal : 2, MinIDChanged : 2, Marked : 2, Changed : 2;
167  } * Flags;
168 
169  double LinkL;
170 
171  void link_two_particles(int target, int j)
172  {
173  if(Head[target] != Head[j]) /* only if not yet linked */
174  {
175  int p, s;
176  if(Len[Head[target]] > Len[Head[j]]) /* p group is longer */
177  {
178  p = target;
179  s = j;
180  }
181  else
182  {
183  p = j;
184  s = target;
185  }
186  Next[Tail[Head[p]]] = Head[s];
187 
188  Tail[Head[p]] = Tail[Head[s]];
189 
190  Len[Head[p]] += Len[Head[s]];
191 
192  if(MinID[Head[s]].get() < MinID[Head[p]].get())
193  {
194  MinID[Head[p]] = MinID[Head[s]];
195  MinIDTask[Head[p]] = MinIDTask[Head[s]];
196  }
197 
198 #if defined(LIGHTCONE_PARTICLES_GROUPS)
199  if(DistanceOrigin[Head[p]] < DistanceOrigin[Head[s]])
200  DistanceOrigin[Head[s]] = DistanceOrigin[Head[p]];
201  else
202  DistanceOrigin[Head[p]] = DistanceOrigin[Head[s]];
203 #endif
204 
205  int ss = Head[s];
206  do
207  Head[ss] = Head[p];
208  while((ss = Next[ss]) >= 0);
209  }
210  }
211 
212 #ifdef SUBFIND
213  struct nearest_r2_data
214  {
215  double dist[2];
216  } * R2Loc;
217 
218 #endif
219 #endif
220 };
221 
222 #endif
223 
224 #endif
global_data_all_processes All
Definition: main.cc:40
#define LIGHTCONE_MAX_FILLFACTOR
Definition: constants.h:70
int integertime
Definition: constants.h:331
#define TIMEBASE
Definition: constants.h:333
#define BASENUMBER
Definition: constants.h:303
float MyFloat
Definition: dtypes.h:86
void sumup_large_ints(int n, int *src, long long *res, MPI_Comm comm)
memory Mem
Definition: main.cc:44
integertime Ti_Current
Definition: allvars.h:188