changa  3.5
 All Classes Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
smooth.h
1 #ifndef __SMOOTH_H
2 #define __SMOOTH_H
3 /*
4  * structure for the priority queue. Also contains information for
5  * smooth calculation.
6  */
7 #include <queue>
8 #include "Compute.h"
9 #include "State.h"
10 
13 {
14  public:
15  double fKey; // distance^2 -> place in priority queue
16  Vector3D<double> dx; // displacement of this particle
17  GravityParticle *p; // pointer to rest of particle data
18 
19  inline bool operator<(const pqSmoothNode& n) const {
20  return fKey < n.fKey;
21  }
22  };
23 
24 
26 
27 class NearNeighborState: public State {
28 public:
29  CkVec<pqSmoothNode> *Qs;
30  int nParticlesPending;
31  int mynParts;
32  bool started;
33 
34  NearNeighborState(int nParts, int nSmooth) {
35  Qs = new CkVec<pqSmoothNode>[nParts+2];
36  mynParts = nParts;
37  }
38 
39  void finishBucketSmooth(int iBucket, TreePiece *tp);
41  delete [] Qs;
42  }
43 };
44 
45 #include "smoothparams.h"
46 
47 // XXX so we can access the init function with the Cache unpack
48 // method.
49 
50 extern SmoothParams *globalSmoothParams;
51 
54 {
55  virtual void fcnSmooth(GravityParticle *p, int nSmooth,
56  pqSmoothNode *nList);
57  virtual int isSmoothActive(GravityParticle *p);
58  virtual void initSmoothParticle(GravityParticle *p);
59  virtual void initTreeParticle(GravityParticle *p) {}
60  virtual void postTreeParticle(GravityParticle *p) {}
61  virtual void initSmoothCache(GravityParticle *p);
62  virtual void combSmoothCache(GravityParticle *p1,
64  public:
66  DensitySmoothParams(int _iType, int am) {
67  iType = _iType;
68  activeRung = am;
69  }
70  PUPable_decl(DensitySmoothParams);
71  DensitySmoothParams(CkMigrateMessage *m) : SmoothParams(m) {}
72  virtual void pup(PUP::er &p) {
73  SmoothParams::pup(p);//Call base class
74  }
75  };
76 
78 class SmoothCompute : public Compute
79 {
80  protected:
81  TreePiece *tp;
82 
83  public:
84  SmoothParams *params;
85 
86  SmoothCompute(TreePiece *_tp, SmoothParams *_params) : Compute(Smooth){
87  params = _params;
88  // XXX Assign to global pointer: not thread safe
89  globalSmoothParams = params;
90  tp = _tp; // needed in getNewState()
91  params->tp = tp;
92  }
93  ~SmoothCompute() { //delete state;
94  // delete params;
95  }
96 
97  virtual
98  void bucketCompare(TreePiece *tp,
99  GravityParticle *p, // Particle to test
100  GenericTreeNode *node, // bucket
101  GravityParticle *particles, // local particle data
102  Vector3D<double> offset,
103  State *state
104  ) = 0;
105 
106  int doWork(GenericTreeNode *node,
107  TreeWalk *tw,
108  State *state,
109  int chunk,
110  int reqID,
111  bool isRoot,
112  bool &didcomp, int awi);
113  void reassoc(void *ce, int ar, Opt *o);
114  void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp);
115 
116 
117 
118 };
119 
122 {
123  int nSmooth;
124  // limit small smoothing lengths
125  int iLowhFix;
126  // smoothing to gravitational softening ratio limit
127  double dfBall2OverSoft2;
128 
129 public:
130 
131  KNearestSmoothCompute(TreePiece *_tp, SmoothParams *_params, int nSm,
132  int iLhF, double dfB2OS2)
133  : SmoothCompute(_tp, _params){
134  nSmooth = nSm;
135  iLowhFix = iLhF;
136  dfBall2OverSoft2 = dfB2OS2;
137  }
138  ~KNearestSmoothCompute() { //delete state;
139  delete params;
140  }
141 
142  void bucketCompare(TreePiece *tp,
143  GravityParticle *p, // Particle to test
144  GenericTreeNode *node, // bucket
145  GravityParticle *particles, // local particle data
146  Vector3D<double> offset,
147  State *state
148  ) ;
149 
150  void initSmoothPrioQueue(int iBucket, State *state) ;
151  int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state);
152  void startNodeProcessEvent(State *state){ }
153  void finishNodeProcessEvent(TreePiece *owner, State *state){ }
154  void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket);
155  void recvdParticlesFull(GravityParticle *egp,int num,int chunk,
156  int reqID,State *state, TreePiece *tp,
157  Tree::NodeKey &remoteBucket);
158  void walkDone(State *state) ;
159 
160  // this function is used to allocate and initialize a new state object
161  // these operations were earlier carried out in the constructor of the
162  // class.
163  State *getNewState(int d1);
164  // Unused.
165  State *getNewState(int d1, int d2) {return 0;}
166  State *getNewState() {return 0;}
167  };
168 
172 
173 class ReNearNeighborState: public State {
174 public:
175  CkVec<pqSmoothNode> *Qs;
176  int nParticlesPending;
177  bool started;
178  ReNearNeighborState(int nParts) {
179  Qs = new CkVec<pqSmoothNode>[nParts+2];
180  }
181  void finishBucketSmooth(int iBucket, TreePiece *tp);
182  ~ReNearNeighborState() { delete [] Qs; }
183 };
184 
187 {
188 
189 public:
190  ReSmoothCompute(TreePiece *_tp, SmoothParams *_params) : SmoothCompute(_tp, _params){}
191 
192  ~ReSmoothCompute() { //delete state;
193  delete params;
194  }
195 
196  void bucketCompare(TreePiece *tp,
197  GravityParticle *p, // Particle to test
198  GenericTreeNode *node, // bucket
199  GravityParticle *particles, // local particle data
200  Vector3D<double> offset,
201  State *state
202  ) ;
203 
204  int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state);
205  void startNodeProcessEvent(State *state){ }
206  void finishNodeProcessEvent(TreePiece *owner, State *state){ }
207  void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket);
208  void recvdParticlesFull(GravityParticle *egp,int num,int chunk,
209  int reqID,State *state, TreePiece *tp,
210  Tree::NodeKey &remoteBucket);
211  void walkDone(State *state) ;
212 
213  // this function is used to allocate and initialize a new state object
214  // these operations were earlier carried out in the constructor of the
215  // class.
216  State *getNewState(int d1);
218  State *getNewState(int d1, int d2) {return 0;}
220  State *getNewState() {return 0;}
221  };
222 
225 {
226 
227 public:
228  MarkSmoothCompute(TreePiece *_tp, SmoothParams *_params) : SmoothCompute(_tp, _params){}
229 
230  ~MarkSmoothCompute() { //delete state;
231  delete params;
232  }
233 
234  void bucketCompare(TreePiece *tp,
235  GravityParticle *p, // Particle to test
236  GenericTreeNode *node, // bucket
237  GravityParticle *particles, // local particle data
238  Vector3D<double> offset,
239  State *state
240  ) ;
241 
242  int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state);
243  void startNodeProcessEvent(State *state){ }
244  void finishNodeProcessEvent(TreePiece *owner, State *state){ }
245  void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket);
246  void recvdParticlesFull(GravityParticle *egp,int num,int chunk,
247  int reqID,State *state, TreePiece *tp,
248  Tree::NodeKey &remoteBucket);
249  void walkDone(State *state) ;
250 
251  // this function is used to allocate and initialize a new state object
252  // these operations were earlier carried out in the constructor of the
253  // class.
254  State *getNewState(int d1, int d2) {return 0;}
255  State *getNewState(int d1);
256  State *getNewState() {return 0;}
257  };
258 
260 
261 class MarkNeighborState: public State {
262 public:
263  int nParticlesPending;
264  bool started;
265  MarkNeighborState(int nParts) {}
266  void finishBucketSmooth(int iBucket, TreePiece *tp);
267  ~MarkNeighborState() {}
268 };
269 
270 #include "Opt.h"
271 
273 class SmoothOpt : public Opt{
274  public:
275  SmoothOpt() : Opt(Local){
276  // don't need to open
277  // these nodes are your concern
278  action_array[0][Internal] = DUMP;
279  action_array[0][Bucket] = DUMP;
280 
281  action_array[0][Boundary] = DUMP;
282  action_array[0][NonLocal] = DUMP;
283  action_array[0][NonLocalBucket] = DUMP;
284  action_array[0][Cached] = DUMP;
285  action_array[0][CachedBucket] = DUMP;
286 
287  action_array[0][Empty] = DUMP;
288  action_array[0][CachedEmpty] = DUMP;
289  action_array[0][Top] = ERROR;
290  action_array[0][Invalid] = ERROR;
291  //--------------
292  // need to open node
293  // local data
294  action_array[1][Internal] = KEEP;
295  action_array[1][Bucket] = KEEP_LOCAL_BUCKET;
296  action_array[1][Boundary] = KEEP;
297 
298  // remote data
299  action_array[1][NonLocal] = KEEP;
300  action_array[1][NonLocalBucket] = KEEP_REMOTE_BUCKET;
301  action_array[1][CachedBucket] = KEEP_REMOTE_BUCKET;
302  action_array[1][Cached] = KEEP;
303 
304  // discard
305  action_array[1][Empty] = DUMP;
306  action_array[1][CachedEmpty] = DUMP;
307  action_array[1][Top] = ERROR;
308  action_array[1][Invalid] = ERROR;
309  }
310 
311 };
312 
313 /* return 1/(h_smooth)^2 for a particle */
314 inline
315 double invH2(GravityParticle *p)
316 {
317  return 4.0/(p->fBall*p->fBall);
318  }
319 
337 inline double kernelWendland(double ar2, int nSmooth)
338 {
339  double ak;
340  if (nSmooth < 32)
341  {
342  ak = 2.0 - sqrt(ar2);
343  if (ar2 < 1.0) ak = (1.0 - 0.75*ak*ar2);
344  else ak = 0.25*ak*ak*ak;
345  return ak;
346  }
347  if (ar2 <= 0) ak = (495/32./8.)*(1-0.01342*pow(nSmooth*0.01,-1.579));/* Dehnen & Aly 2012 correction */
348  else {
349  double au = sqrt(ar2*0.25);
350  ak = 1-au;
351  ak = ak*ak*ak;
352  ak = ak*ak;
353  ak = (495/32./8.)*ak*(1+6*au+(35/3.)*au*au);
354  }
355  return ak;
356  }
370 inline double dkernelWendland(double ar2)
371 {
372  double adk;
373  double _a2,au = sqrt(ar2*0.25);
374  adk = 1-au;
375  _a2 = adk*adk;
376  adk = (-495/32.*7./3./4.)*_a2*_a2*adk*(1+5*au);
377  return adk;
378  }
379 
396 inline double kernelM6(double ar2) {
397  double r = 0.5 * sqrt(ar2);
398  double w;
399  // Sanity checks
400  CkAssert(r >= 0.0);
401  CkAssert(r <= 1.0000001);
402  w = pow(1. - r, 5);
403  if (r < 2./3.) {
404  w += -6. * pow(2./3. - r, 5);
405  if (r < 1./3.) {
406  w += 15. * pow(1./3. - r, 5);
407  }
408  }
409  return 6.834375 * w;
410 }
411 
424 inline double dkernelM6(double ar2) {
425  double r = 0.5 * sqrt(ar2);
426  double dw = 0.0;
427  // Sanity checks
428  CkAssert(r >= 0.0);
429  CkAssert(r <= 1.0000001);
430  dw = -5. * pow(1. - r, 4);
431  if (r < 2./3.) {
432  dw += 30. * pow(2./3. - r, 4);
433  if (r < 1./3.) {
434  if (r == 0.) {
435  dw = 0.0;
436  r = 1.;
437  } else {
438  dw += -75. * pow(1./3. - r, 4);
439  }
440  }
441  }
442  dw /= r;
443  // Normalize by 3^7/(32*40)
444  dw *= 1.70859375;
445  return dw;
446 }
447 
448 /* Standard M_4 Kernel */
462 inline double kernelM4(double ar2)
463 {
464  double ak;
465  ak = 2.0 - sqrt(ar2);
466  if (ar2 < 1.0) ak = (1.0 - 0.75*ak*ar2);
467  else ak = 0.25*ak*ak*ak;
468  return ak;
469  }
483 inline double dkernelM4(double ar2)
484 {
485  double adk;
486  adk = sqrt(ar2);
487  if (ar2 < 1.0) {
488  adk = -3 + 2.25*adk;
489  }
490  else {
491  adk = -0.75*(2.0-adk)*(2.0-adk)/adk;
492  }
493  return adk;
494  }
495 
506 inline double KERNEL(double ar2, int nSmooth) {
507 #if WENDLAND == 1
508  return kernelWendland(ar2, nSmooth);
509 #elif M6KERNEL == 1
510  return kernelM6(ar2);
511 #elif M4KERNEL == 1
512  return kernelM4(ar2);
513 #else
514  #error No available kernel selected.
515 #endif //KERNEL
516 }
517 
528 inline double DKERNEL(double ar2) {
529 #if WENDLAND == 1
530  return dkernelWendland(ar2);
531 #elif M6KERNEL == 1
532  return dkernelM6(ar2);
533 #elif M4KERNEL == 1
534  return dkernelM4(ar2);
535 #else
536  #error No available kernel selected.
537 #endif //KERNEL
538 }
539 #endif
Class for cross processor data needed for smooth operations.
Definition: GravityParticle.h:568
Definition: smooth.h:173
int doWork(GenericTreeNode *node, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi)
Work to be done at each node.
Definition: smooth.cpp:57
void finishNodeProcessEvent(TreePiece *owner, State *state)
Allow book-keeping when finished with a node.
Definition: smooth.h:206
Base clase for all tree based computations.
Definition: Compute.h:26
void startNodeProcessEvent(State *state)
Definition: smooth.h:243
Computation over &quot;inverse&quot; nearest neighbors.
Definition: smooth.h:224
action optimization for the smooth walk.
Definition: smooth.h:273
void finishNodeProcessEvent(TreePiece *owner, State *state)
Allow book-keeping when finished with a node.
Definition: smooth.h:153
void bucketCompare(TreePiece *tp, GravityParticle *p, GenericTreeNode *node, GravityParticle *particles, Vector3D< double > offset, State *state)
Definition: smooth.cpp:1078
void startNodeProcessEvent(State *state)
Definition: smooth.h:205
Base class for walking trees.
Definition: TreeWalk.h:11
void recvdParticlesFull(GravityParticle *egp, int num, int chunk, int reqID, State *state, TreePiece *tp, Tree::NodeKey &remoteBucket)
Allow book-keeping of a cache receive event.
Definition: smooth.cpp:870
State * getNewState()
default implementation
Definition: smooth.h:220
void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket)
Allow book-keeping of a cache receive event.
Definition: smooth.cpp:1122
virtual void pup(PUP::er &p)
required method for remote entry call.
Definition: smooth.h:72
State * getNewState(int d1, int d2)
default implementation
Definition: smooth.h:218
int iType
Particle type to smooth over; &quot;TreeActive&quot;.
Definition: smoothparams.h:11
Object to bookkeep a Bucket MarkSmooth Walk.
Definition: smooth.h:261
Base class for tree nodes.
Definition: GenericTreeNode.h:59
Object for priority queue entry.
Definition: smooth.h:12
void finishNodeProcessEvent(TreePiece *owner, State *state)
Allow book-keeping when finished with a node.
Definition: smooth.h:244
void startNodeProcessEvent(State *state)
Definition: smooth.h:152
Base class for maintaining the state of a tree walk.
Definition: State.h:6
int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state)
Definition: smooth.cpp:804
virtual void pup(PUP::er &p)
required method for remote entry call.
Definition: smoothparams.h:45
void walkDone(State *state)
execute SmoothParams::fcnSmooth() for all particles in the bucket.
Definition: smooth.cpp:1017
Fundamental structure that holds particle and tree data.
Definition: ParallelGravity.h:730
void bucketCompare(TreePiece *tp, GravityParticle *p, GenericTreeNode *node, GravityParticle *particles, Vector3D< double > offset, State *state)
Definition: smooth.cpp:237
Object to bookkeep a Bucket Smooth Walk.
Definition: smooth.h:27
void recvdParticlesFull(GravityParticle *egp, int num, int chunk, int reqID, State *state, TreePiece *tp, Tree::NodeKey &remoteBucket)
Definition: smooth.cpp:291
A base class from which parameters for all smooth operations can be derived.
Definition: smoothparams.h:8
Class for computation over a set smoothing length.
Definition: smooth.h:186
Class to specify density smooth.
Definition: smooth.h:53
void recvdParticlesFull(GravityParticle *egp, int num, int chunk, int reqID, State *state, TreePiece *tp, Tree::NodeKey &remoteBucket)
Allow book-keeping of a cache receive event.
Definition: smooth.cpp:1103
Class for computation over k nearest neighbors.
Definition: smooth.h:121
Base class for optimizing walk actions.
Definition: Opt.h:12
int activeRung
Currently active rung.
Definition: smoothparams.h:12
Fundamental type for a particle.
Definition: GravityParticle.h:316
void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp)
Allow book-keeping of a cache miss.
Definition: smooth.cpp:146
Super class for Smooth and Resmooth computation.
Definition: smooth.h:78
double fBall
Neighbor search radius for smoothing.
Definition: GravityParticle.h:326
void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket)
Allow book-keeping of a cache receive event.
Definition: smooth.cpp:889
int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state)
Definition: smooth.cpp:206
void bucketCompare(TreePiece *tp, GravityParticle *p, GenericTreeNode *node, GravityParticle *particles, Vector3D< double > offset, State *state)
Definition: smooth.cpp:832
void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket)
Allow book-keeping of a cache receive event.
Definition: smooth.cpp:310