-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsmooth.h
366 lines (316 loc) · 10.4 KB
/
smooth.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
360
361
362
363
364
365
366
#ifndef __SMOOTH_H
#define __SMOOTH_H
/*
* structure for the priority queue. Also contains information for
* smooth calculation.
*/
#include <queue>
#include "Compute.h"
#include "State.h"
/// Object for priority queue entry.
class pqSmoothNode
{
public:
double fKey; // distance^2 -> place in priority queue
Vector3D<double> dx; // displacement of this particle
GravityParticle *p; // pointer to rest of particle data
inline bool operator<(const pqSmoothNode& n) const {
return fKey < n.fKey;
}
};
/// Object to bookkeep a Bucket Smooth Walk.
class NearNeighborState: public State {
public:
CkVec<pqSmoothNode> *Qs;
int nParticlesPending;
int mynParts;
bool started;
NearNeighborState(int nParts, int nSmooth) {
Qs = new CkVec<pqSmoothNode>[nParts+2];
mynParts = nParts;
}
void finishBucketSmooth(int iBucket, TreePiece *tp);
~NearNeighborState() {
delete [] Qs;
}
};
#include "smoothparams.h"
// XXX so we can access the init function with the Cache unpack
// method.
extern SmoothParams *globalSmoothParams;
/// Class to specify density smooth
class DensitySmoothParams : public SmoothParams
{
virtual void fcnSmooth(GravityParticle *p, int nSmooth,
pqSmoothNode *nList);
virtual int isSmoothActive(GravityParticle *p);
virtual void initSmoothParticle(GravityParticle *p);
virtual void initTreeParticle(GravityParticle *p) {}
virtual void postTreeParticle(GravityParticle *p) {}
virtual void initSmoothCache(GravityParticle *p);
virtual void combSmoothCache(GravityParticle *p1,
ExternalSmoothParticle *p2);
public:
DensitySmoothParams() {}
DensitySmoothParams(int _iType, int am) {
iType = _iType;
activeRung = am;
}
PUPable_decl(DensitySmoothParams);
DensitySmoothParams(CkMigrateMessage *m) : SmoothParams(m) {}
virtual void pup(PUP::er &p) {
SmoothParams::pup(p);//Call base class
}
};
/// Super class for Smooth and Resmooth computation.
class SmoothCompute : public Compute
{
protected:
TreePiece *tp;
public:
SmoothParams *params;
SmoothCompute(TreePiece *_tp, SmoothParams *_params) : Compute(Smooth){
params = _params;
// XXX Assign to global pointer: not thread safe
globalSmoothParams = params;
tp = _tp; // needed in getNewState()
}
~SmoothCompute() { //delete state;
// delete params;
}
virtual
void bucketCompare(TreePiece *tp,
GravityParticle *p, // Particle to test
GenericTreeNode *node, // bucket
GravityParticle *particles, // local particle data
Vector3D<double> offset,
State *state
) = 0;
int doWork(GenericTreeNode *node,
TreeWalk *tw,
State *state,
int chunk,
int reqID,
bool isRoot,
bool &didcomp, int awi);
void reassoc(void *ce, int ar, Opt *o);
void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp);
};
/// Class for computation over k nearest neighbors.
class KNearestSmoothCompute : public SmoothCompute
{
int nSmooth;
// limit small smoothing lengths
int iLowhFix;
// smoothing to gravitational softening ratio limit
double dfBall2OverSoft2;
public:
KNearestSmoothCompute(TreePiece *_tp, SmoothParams *_params, int nSm,
int iLhF, double dfB2OS2)
: SmoothCompute(_tp, _params){
nSmooth = nSm;
iLowhFix = iLhF;
dfBall2OverSoft2 = dfB2OS2;
}
~KNearestSmoothCompute() { //delete state;
delete params;
}
void bucketCompare(TreePiece *tp,
GravityParticle *p, // Particle to test
GenericTreeNode *node, // bucket
GravityParticle *particles, // local particle data
Vector3D<double> offset,
State *state
) ;
void initSmoothPrioQueue(int iBucket, State *state) ;
int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state);
void startNodeProcessEvent(State *state){ }
void finishNodeProcessEvent(TreePiece *owner, State *state){ }
void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket);
void recvdParticlesFull(GravityParticle *egp,int num,int chunk,
int reqID,State *state, TreePiece *tp,
Tree::NodeKey &remoteBucket);
void walkDone(State *state) ;
// this function is used to allocate and initialize a new state object
// these operations were earlier carried out in the constructor of the
// class.
State *getNewState(int d1);
// Unused.
State *getNewState(int d1, int d2) {return 0;}
State *getNewState() {return 0;}
};
/// Object to bookkeep a Bucket ReSmooth Walk. This could be merged
/// with the standard smooth if we changed that to using push_heap()
/// and pop_heap()
class ReNearNeighborState: public State {
public:
CkVec<pqSmoothNode> *Qs;
int nParticlesPending;
bool started;
ReNearNeighborState(int nParts) {
Qs = new CkVec<pqSmoothNode>[nParts+2];
}
void finishBucketSmooth(int iBucket, TreePiece *tp);
~ReNearNeighborState() { delete [] Qs; }
};
/// @brief Class for computation over a set smoothing length
class ReSmoothCompute : public SmoothCompute
{
public:
ReSmoothCompute(TreePiece *_tp, SmoothParams *_params) : SmoothCompute(_tp, _params){}
~ReSmoothCompute() { //delete state;
delete params;
}
void bucketCompare(TreePiece *tp,
GravityParticle *p, // Particle to test
GenericTreeNode *node, // bucket
GravityParticle *particles, // local particle data
Vector3D<double> offset,
State *state
) ;
int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state);
void startNodeProcessEvent(State *state){ }
void finishNodeProcessEvent(TreePiece *owner, State *state){ }
void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket);
void recvdParticlesFull(GravityParticle *egp,int num,int chunk,
int reqID,State *state, TreePiece *tp,
Tree::NodeKey &remoteBucket);
void walkDone(State *state) ;
// this function is used to allocate and initialize a new state object
// these operations were earlier carried out in the constructor of the
// class.
State *getNewState(int d1);
/// @brief default implementation
State *getNewState(int d1, int d2) {return 0;}
/// @brief default implementation
State *getNewState() {return 0;}
};
/// Computation over "inverse" nearest neighbors.
class MarkSmoothCompute : public SmoothCompute
{
public:
MarkSmoothCompute(TreePiece *_tp, SmoothParams *_params) : SmoothCompute(_tp, _params){}
~MarkSmoothCompute() { //delete state;
delete params;
}
void bucketCompare(TreePiece *tp,
GravityParticle *p, // Particle to test
GenericTreeNode *node, // bucket
GravityParticle *particles, // local particle data
Vector3D<double> offset,
State *state
) ;
int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state);
void startNodeProcessEvent(State *state){ }
void finishNodeProcessEvent(TreePiece *owner, State *state){ }
void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket);
void recvdParticlesFull(GravityParticle *egp,int num,int chunk,
int reqID,State *state, TreePiece *tp,
Tree::NodeKey &remoteBucket);
void walkDone(State *state) ;
// this function is used to allocate and initialize a new state object
// these operations were earlier carried out in the constructor of the
// class.
State *getNewState(int d1, int d2) {return 0;}
State *getNewState(int d1);
State *getNewState() {return 0;}
};
/// Object to bookkeep a Bucket MarkSmooth Walk.
class MarkNeighborState: public State {
public:
int nParticlesPending;
bool started;
MarkNeighborState(int nParts) {}
void finishBucketSmooth(int iBucket, TreePiece *tp);
~MarkNeighborState() {}
};
#include "Opt.h"
/// @brief action optimization for the smooth walk.
class SmoothOpt : public Opt{
public:
SmoothOpt() : Opt(Local){
// don't need to open
// these nodes are your concern
action_array[0][Internal] = DUMP;
action_array[0][Bucket] = DUMP;
action_array[0][Boundary] = DUMP;
action_array[0][NonLocal] = DUMP;
action_array[0][NonLocalBucket] = DUMP;
action_array[0][Cached] = DUMP;
action_array[0][CachedBucket] = DUMP;
action_array[0][Empty] = DUMP;
action_array[0][CachedEmpty] = DUMP;
action_array[0][Top] = ERROR;
action_array[0][Invalid] = ERROR;
//--------------
// need to open node
// local data
action_array[1][Internal] = KEEP;
action_array[1][Bucket] = KEEP_LOCAL_BUCKET;
action_array[1][Boundary] = KEEP;
// remote data
action_array[1][NonLocal] = KEEP;
action_array[1][NonLocalBucket] = KEEP_REMOTE_BUCKET;
action_array[1][CachedBucket] = KEEP_REMOTE_BUCKET;
action_array[1][Cached] = KEEP;
// discard
action_array[1][Empty] = DUMP;
action_array[1][CachedEmpty] = DUMP;
action_array[1][Top] = ERROR;
action_array[1][Invalid] = ERROR;
}
};
/* return 1/(h_smooth)^2 for a particle */
inline
double invH2(GravityParticle *p)
{
return 4.0/(p->fBall*p->fBall);
}
#ifdef WENDLAND
inline double KERNEL(double ar2, double nSmooth)
{
double ak;
if (ar2 <= 0) ak = (495/32./8.)*(1-0.01342*pow(nSmooth*0.01,-1.579));/* Dehnen & Aly 2012 correction */
else {
double au = sqrt(ar2*0.25);
ak = 1-au;
ak = ak*ak*ak;
ak = ak*ak;
ak = (495/32./8.)*ak*(1+6*au+(35/3.)*au*au);
}
return ak;
}
inline double DKERNEL(double ar2)
{
double adk;
double _a2,au = sqrt(ar2*0.25);
adk = 1-au;
_a2 = adk*adk;
adk = (-495/32.*7./3./4.)*_a2*_a2*adk*(1+5*au);
return adk;
}
#define KERNEL(ar2) KERNEL(ar2, nSmooth)
#else
/* Standard M_4 Kernel */
inline double KERNEL(double ar2)
{
double ak;
ak = 2.0 - sqrt(ar2);
if (ar2 < 1.0) ak = (1.0 - 0.75*ak*ar2);
else ak = 0.25*ak*ak*ak;
return ak;
}
inline double DKERNEL(double ar2)
{
double adk;
adk = sqrt(ar2);
if (ar2 < 1.0) {
adk = -3 + 2.25*adk;
}
else {
adk = -0.75*(2.0-adk)*(2.0-adk)/adk;
}
return adk;
}
#endif
#endif