forked from martinjrobins/SPH-DEM
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewDataLL.h
executable file
·359 lines (308 loc) · 13.1 KB
/
newDataLL.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#ifndef DATALL_H
#define DATALL_H
#include <vector>
#include <list>
#include <blitz/array.h>
#include <mpi.h>
#include <sys/time.h>
#include "customConstants.h"
#include "particle.h"
#include "sphConstants.h"
#include "globalVars.h"
class CdataLL {
public:
int calcBufferSize(vectInt coords);
CdataLL(vector<particleT> &in_ps, CglobalVars &in_globals,bool opt): ps(in_ps),globals(in_globals) {
hmax = H;
gBufferSize = MAX_NUM_PARTICLES_PER_CPU;
pBufferSize = MAX_NUM_PARTICLES_PER_CPU;
//gBufferSize = int(ps.size()*4/(pow(3.0,NDIM)-2));
//pBufferSize = int(ps.size()*4/(10*pow(3.0,NDIM)));
cout << "gBufferSize = "<<gBufferSize<<" pBufferSize = "<<pBufferSize<<endl;
ghostBuffersSend.resize(3);
for (Array<CghostData*,NDIM>::iterator i=ghostBuffersSend.begin();i!=ghostBuffersSend.end();i++) {
vectInt coords = i.position()-1;
if (globals.procNeighbrs(i.position()) >= 0) {
*i = new CghostData[calcBufferSize(coords)];
}
}
particleBuffersSend.resize(3);
for (Array<Cparticle*,NDIM>::iterator i=particleBuffersSend.begin();i!=particleBuffersSend.end();i++) {
vectInt coords = i.position()-1;
if (globals.procNeighbrs(i.position()) >= 0) {
*i = new Cparticle[calcBufferSize(coords)/4];
}
}
ghostBuffersRecv.resize(3);
for (Array<CghostData*,NDIM>::iterator i=ghostBuffersRecv.begin();i!=ghostBuffersRecv.end();i++) {
vectInt coords = i.position()-1;
if (globals.procNeighbrs(i.position()) >= 0) {
*i = new CghostData[calcBufferSize(coords)];
}
}
particleBuffersRecv.resize(3);
for (Array<Cparticle*,NDIM>::iterator i=particleBuffersRecv.begin();i!=particleBuffersRecv.end();i++) {
vectInt coords = i.position()-1;
if (globals.procNeighbrs(i.position()) >= 0) {
*i = new Cparticle[calcBufferSize(coords)/4];
}
}
ghostedParticles.resize(3);
for (Array<Cparticle**,NDIM>::iterator i=ghostedParticles.begin();i!=ghostedParticles.end();i++) {
vectInt coords = i.position()-1;
if (globals.procNeighbrs(i.position()) >= 0) {
*i = new Cparticle*[calcBufferSize(coords)];
}
}
syncBuffersSend.resize(3);
for (Array<void*,NDIM>::iterator i=syncBuffersSend.begin();i!=syncBuffersSend.end();i++) {
vectInt coords = i.position()-1;
if (globals.procNeighbrs(i.position()) >= 0) {
*i = new unsigned char[sizeof(CghostData)*calcBufferSize(coords)];
}
}
syncBuffersRecv.resize(3);
for (Array<void*,NDIM>::iterator i=syncBuffersRecv.begin();i!=syncBuffersRecv.end();i++) {
vectInt coords = i.position()-1;
if (globals.procNeighbrs(i.position()) >= 0) {
*i = new unsigned char[sizeof(CghostData)*calcBufferSize(coords)];
}
}
sendSizesGhosts.resize(3);
recvSizesGhosts.resize(3);
procGhostMax2H.resize(3);
procGhostMax2H = 1.1*KERNAL_RADIUS*H;
cout << "Processor "<<globals.mpiRank<<" of "<<globals.mpiSize<<" has domain ";
for (int i=0;i<NDIM*2;i++) {
cout<<globals.procDomain[i]<<' ';
}
#ifdef GRID_SMOOTHING
vectInt smSize;
for (int i=0;i<NDIM;i++) {
double size = (RMAX[i]-RMIN[i])/(SMOOTH_GRID_SIZE);
smSize[i] = int(floor((RMAX[i]-RMIN[i])/(SMOOTH_GRID_SIZE) + 0.5));
if (smSize[i]/size != 1) {
cerr << "Error: SMOOTH_GRID_SIZE doesn't give an integer number of grid cells in domain!" << endl;
exit(-1);
}
}
vectInt minI,maxI;
for (int i=0;i<NDIM;i++) {
double test = (globals.procDomain[i*2]-RMIN[i])/SMOOTH_GRID_SIZE;
minI[i] = int(floor(test));
if (test==double(minI[i])) {
minI[i]--;
}
minI[i]--;
test = (globals.procDomain[i*2+1]-RMIN[i])/SMOOTH_GRID_SIZE;
maxI[i] = int(ceil(test));
maxI[i]++;
smSize[i] = maxI[i]-minI[i]+1;
smGridMin[i] = minI[i]*SMOOTH_GRID_SIZE+RMIN[i];
}
cout <<"Processor "<<globals.mpiRank<<": smSize = "<<smSize<<"smGridMin = "<<smGridMin<<" minI = "<<minI<<" maxI = "<<maxI<<endl;
smGrid.resize(smSize);
for (Array<CsmVertex,NDIM>::iterator i=smGrid.begin();i!=smGrid.end();i++) {
vectInt coords = i.position();
for (int j=0;j<NDIM;j++) {
i->pos[j] = coords[j]*SMOOTH_GRID_SIZE + smGridMin[j];
}
}
smGridBuffersRecv.resize(3);
smGridBuffersSend.resize(3);
smGridViews.resize(3);
for (Array<CsmVertex*,NDIM>::iterator i = smGridBuffersSend.begin();i != smGridBuffersSend.end();i++) {
vectInt coords = i.position();
int neighbr = globals.procNeighbrs(coords);
if (neighbr >= 0) {
vectInt upperBounds,lowerBounds;
for (int j=0;j<NDIM;j++) {
int extent = smGrid.extent(j);
if (coords[j]==1) {
lowerBounds[j] = 0;
upperBounds[j] = extent-1;
} else if (coords[j]==0) {
lowerBounds[j] = 0;
upperBounds[j] = 3;
} else if (coords[j]==2) {
lowerBounds[j] = extent-4;
upperBounds[j] = extent-1;
}
}
RectDomain<NDIM> subdomain(lowerBounds, upperBounds);
smGridViews(coords).reference(smGrid(subdomain));
*i = new CsmVertex[smGridViews(coords).size()];
smGridBuffersRecv(coords) = new CsmVertex[smGridViews(coords).size()];
}
}
#endif
if (opt) {
initTraverseOrder();
}
reset();
}
void reset();
void reset(const double scale);
void sumOverProcs(vect *data,int num);
void sumOverProcs(double *data,int num);
template <class T, T readFunct(particleT &), void writeFunct(particleT &,T)>
void syncParticlesBetweenProcs();
template <void Thefunct(particleT &,CglobalVars &)>
void traverse();
template <class T, void Thefunct(particleT &,CglobalVars &,T &)>
void traverse(T &);
template <void Thefunct(particleT &,CglobalVars &), bool Iffunct(particleT &)>
void traverse();
template <class T, void Thefunct(particleT &,CglobalVars &,T &), bool Iffunct(particleT &)>
void traverse(T &);
template <void Thefunct(particleT &,particleT &,CglobalVars &)>
void neighboursUsing(vector<particleT> &_ps);
template <void Thefunct(particleT &,vector<particleT *> &,CglobalVars &)>
void neighboursUsing(vector<particleT> &_ps);
template <void Thefunct(particleT &,particleT &,CglobalVars &)>
void neighbours();
template <void Thefunct(particleT &,particleT &,CglobalVars &), bool Iffunct(particleT &)>
void neighbours();
template <void Thefunct(particleT &,vector<particleT *> &,CglobalVars &)>
void neighboursGroup();
template <void Thefunct(particleT &,vector<particleT *> &,CglobalVars &), bool Iffunct(particleT &)>
void neighboursGroup();
template <class T, void Thefunct(particleT &,vector<particleT *> &,CglobalVars &,T &), bool Iffunct(particleT &)>
void neighboursGroup(T &);
template <void theFunct(particleT &,particleT &,CglobalVars &)>
void functionOverGrid(vector<particleT> &outPs,vectInt &gridDimN);
void calcNeighbours(vector<particleT *> &_neighbrs,particleT &_p);
void setGlobalTimestep(double dt);
void printMe();
void calcTraverseOrder();
int numParticles() { return ps.size(); };
vector<particleT> *getParticles() { return &ps; }
void updateParticles();
void insertNewParticle(particleT &newP);
void markForDeletion(particleT &p);
void deleteParticles();
particleT *getParticleFromTag(int tag);
CpInfo *getPinfoFromTag(int tag);
template <void Thefunct(particleT &,vector<particleT *> &,CglobalVars &), bool Iffunct(particleT &)>
void neighboursGroupScaled();
template <bool Iffunct(particleT &)>
void findBothNeighbours();
template <bool Iffunct(particleT &)>
void findNeighbours();
template<void Thefunct(particleT &,Array<CsmVertex*,NDIM> &,CglobalVars &), bool Iffunct(particleT &)>
//template<void Thefunct(particleT &,vector<CsmVertex *> &,CglobalVars &), bool Iffunct(particleT &)>
void useSmGrid();
template<void Thefunct(CsmVertex &,CglobalVars &)>
void traverseSmGrid();
void syncSmGrid();
CglobalVars &globals;
private:
class CsmVertex {
public:
vect v;
vect pos;
int num;
};
class CtagPP {
public:
int tag;
particleT *p;
CtagPP() {
tag = -1;
}
};
class CpInfoLink;
class CpInfo {
public:
particleT *p;
CpInfoLink *ppInfoLink;
unsigned long key;
vector<particleT *> neighbrs;
vector<particleT *> scaledNeighbrs;
CpInfo() {}
CpInfo(const CpInfo &pInfo) {
p = pInfo.p;
ppInfoLink = pInfo.ppInfoLink;
key = pInfo.key;
}
CpInfo& operator=(CpInfo &pInfo) {
p = pInfo.p;
ppInfoLink = pInfo.ppInfoLink;
key = pInfo.key;
return *this;
}
};
class CtagPI {
public:
int tag;
CpInfo *pInfo;
CtagPI() {
tag = -1;
}
};
class CpInfoLink {
public:
CpInfo *ppInfo;
};
void insertionSort(std::list<CpInfo> &v);
void sendRecvSmGridData(vectInt coords,int num,MPI_Request *requestSendRecv,CsmVertex *sendBuf,CsmVertex *recvBuf,int size);
void getVerticesFromPosition(vect pos,vectInt &lowerB);
void calcDomainLimits();
void insert(particleT &,const double);
void addIfNeighbr(particleT &_p,vector<particleT *> &_neighbrs,vector<particleT *> &_toAdd);
void deleteParticle(vector<CpInfoLink>::iterator &ppInfoLink,CpInfo *ppInfo);
void addIfBothNeighbr(particleT &_p,vector<particleT *> &_scaledNeighbrs,vector<particleT *> &_neighbrs,vector<Cparticle *> &_toAdd);
void calcBothNeighbours(vector<particleT *> &_scaledNeighbrs,vector<particleT *> &_neighbrs,particleT &_p);
void addIfScaledNeighbr(particleT &_p,vector<particleT *> &_neighbrs,vector<particleT *> &_toAdd);
void calcScaledNeighbours(vector<particleT *> &_neighbrs,particleT &_p);
inline vectInt getCellI(vect r) {
return static_cast<vectInt>((r-rmin)/(KERNAL_RADIUS*scale*hmax)+2);
}
void insertGhosts();
void removeGhosts();
unsigned long calcKey(vect r);
void initPinfos();
void checkPinfos();
void initTraverseOrder();
void updateDomain();
void sendRecvData(const vectInt coords,const int num,MPI_Request *request,int *ghostSizesSend,int *ghostSizesRecv,int *particleSizesSend,int *particleSizesRecv);
void sendRecvGhosts(const vectInt coords,const int num,MPI_Request *request,int *ghostSizesSend,int *ghostSizesRecv);
void sendRecvParticles(const vectInt coords,const int num,MPI_Request *request,int *particleSizesSend,int *particleSizesRecv);
void sendRecvDataSync(const vectInt coords,const int num,MPI_Request *request,int sendSize, void *sendBuffer, int recvSize, void *recvBuffer);
void sortPInfos();
vector<CtagPP<particleT> > tagSortedParticlePointers;
vector<CtagPI<particleT> > tagSortedPinfoPointers;
double scale;
vector<particleT> &ps;
vect rmax;
vect rmin;
double hmax;
//vector<vector<particleT *> > neighbrs;
Array<vector<particleT *>,NDIM> cells;
int n;
vector<CpInfo> pInfos;
//vector<particleT *> traverseOrder;
//vector<unsigned long> traverseKeys;
Array<particleT **,NDIM> ghostedParticles;
//vector<particleT>::iterator startOfRecvGhostParticles;
Array<void*,NDIM> syncBuffersSend;
Array<void*,NDIM> syncBuffersRecv;
Array<int,NDIM> sendSizesGhosts;
Array<int,NDIM> recvSizesGhosts;
Array<particleT::ghost*,NDIM> ghostBuffersSend;
Array<particleT*,NDIM> particleBuffersSend;
Array<CsmVertex*,NDIM> smGridBuffersSend;
Array<particleT::ghost*,NDIM> ghostBuffersRecv;
Array<particleT*,NDIM> particleBuffersRecv;
Array<CsmVertex*,NDIM> smGridBuffersRecv;
Array<Array<CsmVertex,NDIM>,NDIM> smGridViews;
int pBufferSize;
int gBufferSize;
vector<particleT> procGhostParticles;
Array<double,NDIM> procGhostMax2H;
Array<CsmVertex,NDIM> smGrid;
vect smGridMin;
vector<CpInfoLink> pInfoLinks;
};
#include "dataLL.impl"
#endif