00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef PARTICLE_ATTRIB_H
00012 #define PARTICLE_ATTRIB_H
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 #include "Particle/ParticleAttribBase.h"
00075 #include "Particle/ParticleAttribElem.h"
00076 #include "SubParticle/SubParticleAttrib.h"
00077 #include "DataSource/DataSource.h"
00078 #include "DataSource/MakeDataSource.h"
00079 #include "PETE/IpplExpressions.h"
00080 #include "Index/NDIndex.h"
00081 #include "Utility/DiscType.h"
00082 #include "Utility/Inform.h"
00083 #include "Utility/IpplStats.h"
00084
00085 #ifdef IPPL_STDSTL
00086 #include <vector>
00087 using std::vector;
00088 #include <utility>
00089 using std::pair;
00090 #else
00091 #include <vector.h>
00092 #include <pair.h>
00093 #endif // IPPL_STDSTL
00094
00095
00096
00097 template<class T, unsigned Dim> class Vektor;
00098 template<class T, unsigned Dim, class M, class C> class Field;
00099 template <class T> class ParticleAttribIterator;
00100
00101
00102
00103 template <class T>
00104 class ParticleAttrib : public ParticleAttribBase, public DataSource,
00105 public PETE_Expr< ParticleAttrib<T> >
00106 {
00107
00108 friend class ParticleAttribIterator<T>;
00109
00110 public:
00111
00112 typedef T Return_t;
00113 typedef vector<T> ParticleList_t;
00114 typedef ParticleAttribIterator<T> iterator;
00115 typedef ParticleAttribBase::SortListIndex_t SortListIndex_t;
00116 typedef ParticleAttribBase::SortList_t SortList_t;
00117
00118 public:
00119
00120 ParticleAttrib() : ParticleAttribBase(sizeof(T), DiscType<T>::str()) {
00121 INCIPPLSTAT(incParticleAttribs);
00122 }
00123
00124
00125 ParticleAttrib(const ParticleAttrib<T>& pa)
00126 : ParticleAttribBase(pa), ParticleList(pa.ParticleList) {
00127 INCIPPLSTAT(incParticleAttribs);
00128 }
00129
00130
00131 ~ParticleAttrib() { }
00132
00133
00134
00135
00136
00137 typename ParticleList_t::reference
00138 operator[](size_t n) {
00139 return ParticleList[n];
00140 }
00141
00142 typename ParticleList_t::const_reference
00143 operator[](size_t n) const {
00144 return ParticleList[n];
00145 }
00146
00147
00148
00149
00150
00151 template<unsigned Dim>
00152 SubParticleAttrib<ParticleAttrib<T>, T, Dim>
00153 operator[](const SIndex<Dim> &s) const {
00154 ParticleAttrib<T> &a = const_cast<ParticleAttrib<T> &>(*this);
00155 return SubParticleAttrib<ParticleAttrib<T>, T, Dim>(a, s);
00156 }
00157
00158
00159
00160
00161 enum { IsExpr = 0 };
00162 typedef iterator PETE_Expr_t;
00163 PETE_Expr_t MakeExpression() const { return begin(); }
00164
00165
00166 iterator begin() const { return iterator((ParticleList_t&) ParticleList); }
00167 iterator end() const {
00168 return iterator((ParticleList_t&) ParticleList).at_end();
00169 }
00170
00171 size_t size(void) const { return ParticleList.size(); }
00172
00173
00174
00175
00176
00177
00178
00179 ParticleAttribElem<T,1U> operator()(unsigned);
00180
00181
00182 ParticleAttribElem<T,2U> operator()(unsigned, unsigned);
00183
00184
00185 ParticleAttribElem<T,3U> operator()(unsigned, unsigned, unsigned);
00186
00187
00188
00189
00190
00191
00192
00193 template <unsigned Dim, class M, class C, class PT, class IntOp>
00194 void
00195 scatter(Field<T,Dim,M,C>& f,
00196 const ParticleAttrib< Vektor<PT,Dim> >& pp,
00197 const IntOp& intop) const {
00198 TAU_TYPE_STRING(taustr, "void (" + CT(f) + ", " + CT(pp) + ", "
00199 + CT(intop) + ")");
00200 TAU_PROFILE("ParticleAttrib::scatter()", taustr, TAU_PARTICLE);
00201
00202
00203 f.Uncompress();
00204 T zero = 0;
00205 f.setGuardCells(zero);
00206
00207 const M& mesh = f.get_mesh();
00208
00209 typename ParticleList_t::const_iterator curr, last = ParticleList.end();
00210 typename ParticleAttrib< Vektor<PT,Dim> >::iterator ppiter=pp.begin();
00211 for (curr = ParticleList.begin(); curr != last; ++curr, ++ppiter)
00212 IntOp::scatter(*curr,f,*ppiter,mesh);
00213
00214
00215 f.accumGuardCells();
00216
00217 INCIPPLSTAT(incParticleScatters);
00218 return;
00219 }
00220
00221
00222
00223 template <unsigned Dim, class M, class C, class PT,
00224 class IntOp, class CacheData>
00225 void
00226 scatter(Field<T,Dim,M,C>& f,
00227 const ParticleAttrib< Vektor<PT,Dim> >& pp,
00228 const IntOp& intop,
00229 ParticleAttrib<CacheData>& cache) const {
00230
00231 TAU_TYPE_STRING(taustr, "void (" + CT(f) + ", " + CT(pp) + ", "
00232 + CT(intop) + ", " + CT(cache) + ")");
00233 TAU_PROFILE("ParticleAttrib::scatter()", taustr, TAU_PARTICLE);
00234
00235
00236 f.Uncompress();
00237 T zero = 0;
00238 f.setGuardCells(zero);
00239
00240 const M& mesh = f.get_mesh();
00241
00242 typename ParticleList_t::const_iterator curr, last = ParticleList.end();
00243 typename ParticleAttrib< Vektor<PT,Dim> >::iterator ppiter=pp.begin();
00244 typename ParticleAttrib<CacheData>::iterator citer=cache.begin();
00245 for (curr = ParticleList.begin(); curr != last; ++curr, ++ppiter, ++citer)
00246 IntOp::scatter(*curr,f,*ppiter,mesh,*citer);
00247
00248
00249 f.accumGuardCells();
00250
00251 INCIPPLSTAT(incParticleScatters);
00252 return;
00253 }
00254
00255
00256
00257 template <unsigned Dim, class M, class C, class IntOp, class CacheData>
00258 void
00259 scatter(Field<T,Dim,M,C>& f, const IntOp& intop,
00260 const ParticleAttrib<CacheData>& cache) const {
00261
00262 TAU_TYPE_STRING(taustr, "void (" + CT(f) + ", " + CT(intop) + ", "
00263 + CT(cache) + " )" );
00264 TAU_PROFILE("ParticleAttrib::scatter()", taustr, TAU_PARTICLE);
00265
00266
00267 f.Uncompress();
00268 T zero = 0;
00269 f.setGuardCells(zero);
00270
00271
00272 typename ParticleList_t::const_iterator curr, last = ParticleList.end();
00273 typename ParticleAttrib<CacheData>::iterator citer=cache.begin();
00274 for (curr = ParticleList.begin(); curr != last; ++curr, ++citer)
00275 IntOp::scatter(*curr,f,*citer);
00276
00277
00278 f.accumGuardCells();
00279
00280 INCIPPLSTAT(incParticleScatters);
00281 return;
00282 }
00283
00284
00285
00286 template <unsigned Dim, class M, class C, class PT, class IntOp>
00287 void
00288 gather(const Field<T,Dim,M,C>& f,
00289 const ParticleAttrib< Vektor<PT,Dim> >& pp,
00290 const IntOp& intop) {
00291 TAU_TYPE_STRING(taustr, "void (" + CT(f) + ", " + CT(pp) + ", "
00292 + CT(intop) + " )" );
00293 TAU_PROFILE("ParticleAttrib::gather()", taustr, TAU_PARTICLE);
00294
00295
00296 f.Uncompress();
00297
00298 if (f.isDirty())
00299 f.fillGuardCells(true);
00300
00301 const M& mesh = f.get_mesh();
00302
00303 typename ParticleList_t::iterator curr, last = ParticleList.end();
00304 typename ParticleAttrib< Vektor<PT,Dim> >::iterator ppiter=pp.begin();
00305 for (curr = ParticleList.begin(); curr != last; ++curr, ++ppiter)
00306 IntOp::gather(*curr,f,*ppiter,mesh);
00307
00308
00309 f.Compress();
00310
00311 INCIPPLSTAT(incParticleGathers);
00312 return;
00313 }
00314
00315
00316
00317 template <unsigned Dim, class M, class C, class PT,
00318 class IntOp, class CacheData>
00319 void
00320 gather(const Field<T,Dim,M,C>& f,
00321 const ParticleAttrib< Vektor<PT,Dim> >& pp,
00322 const IntOp& intop,
00323 ParticleAttrib<CacheData>& cache) {
00324
00325 TAU_TYPE_STRING(taustr, "void (" + CT(f) + ", " + CT(pp) + ", "
00326 + CT(intop) + ", " + CT(cache) + ")");
00327 TAU_PROFILE("ParticleAttrib::gather()", taustr, TAU_PARTICLE);
00328
00329
00330 f.Uncompress();
00331
00332 if (f.isDirty())
00333 f.fillGuardCells(true);
00334
00335 const M& mesh = f.get_mesh();
00336
00337 typename ParticleList_t::iterator curr, last = ParticleList.end();
00338 typename ParticleAttrib< Vektor<PT,Dim> >::iterator ppiter=pp.begin();
00339 typename ParticleAttrib<CacheData>::iterator citer=cache.begin();
00340 for (curr=ParticleList.begin(); curr != last; ++curr,++ppiter,++citer)
00341 IntOp::gather(*curr,f,*ppiter,mesh,*citer);
00342
00343
00344 f.Compress();
00345
00346 INCIPPLSTAT(incParticleGathers);
00347 return;
00348 }
00349
00350
00351
00352 template <unsigned Dim, class M, class C, class IntOp, class CacheData>
00353 void
00354 gather(const Field<T,Dim,M,C>& f, const IntOp& intop,
00355 const ParticleAttrib<CacheData>& cache) {
00356
00357 TAU_TYPE_STRING(taustr, "void (" + CT(f) + ", " + CT(intop) + ", "
00358 + CT(cache) + " )" );
00359 TAU_PROFILE("ParticleAttrib::gather()", taustr, TAU_PARTICLE);
00360
00361
00362 f.Uncompress();
00363
00364 if (f.isDirty())
00365 f.fillGuardCells(true);
00366
00367
00368 typename ParticleList_t::iterator curr, last = ParticleList.end();
00369 typename ParticleAttrib<CacheData>::iterator citer=cache.begin();
00370 for (curr = ParticleList.begin(); curr != last; ++curr, ++citer)
00371 IntOp::gather(*curr,f,*citer);
00372
00373
00374 f.Compress();
00375
00376 INCIPPLSTAT(incParticleGathers);
00377 return;
00378 }
00379
00380
00381
00382
00383
00384
00385 template<class T1>
00386 const ParticleAttrib<T>& operator=(const PETE_Expr<T1>& rhs) {
00387 assign(*this,rhs);
00388 return *this;
00389 }
00390
00391
00392 const ParticleAttrib<T>& operator=(const ParticleAttrib<T>& rhs) {
00393 if (size() != rhs.size()) {
00394 ERRORMSG("Attempting to copy particle attributes with unequal sizes.");
00395 ERRORMSG("\n" << size() << " != " << rhs.size() << endl);
00396 }
00397 assign(*this,rhs);
00398 return *this;
00399 }
00400
00401
00402 const ParticleAttrib<T>& operator=(T rhs) {
00403 assign(*this,rhs);
00404 return *this;
00405 }
00406
00407
00408
00409
00410
00411
00412
00413 virtual void create(size_t);
00414
00415
00416
00417
00418
00419
00420
00421 virtual void destroy(size_t M, size_t I, bool optDestroy=true);
00422
00423
00424
00425 virtual void destroy(const vector< pair<size_t,size_t> >& dlist,
00426 bool optDestroy=true);
00427
00428
00429
00430 virtual size_t putMessage(Message&, size_t, size_t);
00431
00432
00433
00434 virtual size_t putMessage(Message&, const vector<size_t>&);
00435
00436
00437
00438
00439 virtual size_t getMessage(Message&, size_t);
00440
00441
00442
00443
00444
00445
00446
00447
00448 virtual size_t ghostDestroy(size_t, size_t) {
00449 return 0;
00450 }
00451
00452
00453
00454
00455
00456 virtual size_t ghostPutMessage(Message&, size_t, size_t) {
00457 return 0;
00458 }
00459
00460
00461 virtual size_t ghostPutMessage(Message&, const vector<size_t>&) {
00462 return 0;
00463 }
00464
00465
00466 virtual size_t ghostGetMessage(Message&, size_t) {
00467 return 0;
00468 }
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 virtual void calcSortList(SortList_t &slist, bool ascending = true);
00483
00484
00485
00486
00487
00488
00489
00490
00491 virtual void sort(SortList_t &slist);
00492
00493
00494
00495
00496
00497
00498 virtual void printDebug(Inform&);
00499
00500 protected:
00501
00502
00503
00504 virtual DataSourceObject *createDataSourceObject(const char *nm,
00505 DataConnect *dc, int tm) {
00506 return make_DataSourceObject(nm, dc, tm, *this);
00507 }
00508
00509
00510 ParticleList_t ParticleList;
00511 };
00512
00513
00514
00515
00516
00517
00518 template <class T>
00519 class ParticleAttribIterator : public PETE_Expr< ParticleAttribIterator<T> >
00520 {
00521 public:
00522 typedef typename ParticleAttrib<T>::ParticleList_t ParticleList_t;
00523
00524 ParticleAttribIterator() : myList(0), curr(0) { }
00525 #ifdef __MWERKS__
00526 ParticleAttribIterator(ParticleList_t& pa)
00527 : myList(&pa), curr(&(*pa.begin())) { }
00528 #else
00529
00530
00531
00532 ParticleAttribIterator(ParticleList_t& pa)
00533 : myList(&pa), curr(&(*pa.begin())) { }
00534 #endif // __MWERKS
00535 ParticleAttribIterator(const ParticleAttribIterator<T>& i)
00536 : myList(i.myList), curr(i.curr) { }
00537
00538
00539 typedef ParticleAttribIterator<T> PETE_Expr_t;
00540 typedef T PETE_Return_t;
00541 PETE_Expr_t MakeExpression() const { return *this; }
00542 PETE_Return_t& operator*(void) const { return *curr; }
00543
00544 ParticleAttribIterator<T>& operator++(void) {
00545 ++curr;
00546 return *this;
00547 }
00548 ParticleAttribIterator<T>& at_end(void) {
00549 #ifdef __MWERKS__
00550 curr = &*myList->end();
00551 #else
00552
00553
00554 curr = &*myList->end();
00555 #endif // __MWERKS__
00556 return *this;
00557 }
00558 bool operator==(const ParticleAttribIterator<T>& a) const {
00559 return (curr == a.curr);
00560 }
00561 bool operator!=(const ParticleAttribIterator<T>& a) const {
00562 return !(curr == a.curr);
00563 }
00564 const ParticleList_t& getParticleList() const { return *myList; }
00565 T* getP() const { return curr; }
00566
00567 private:
00568 ParticleList_t* myList;
00569 T* curr;
00570 };
00571
00572
00573
00574
00575
00576
00577 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
00578 inline
00579 void scatter(const ParticleAttrib<FT>& attrib, Field<FT,Dim,M,C>& f,
00580 const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop) {
00581 attrib.scatter(f, pp, intop);
00582 }
00583
00584
00585
00586 template <class FT, unsigned Dim, class M, class C, class PT,
00587 class IntOp, class CacheData>
00588 inline
00589 void scatter(const ParticleAttrib<FT>& attrib, Field<FT,Dim,M,C>& f,
00590 const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop,
00591 ParticleAttrib<CacheData>& cache) {
00592 attrib.scatter(f, pp, intop, cache);
00593 }
00594
00595
00596
00597 template <class FT, unsigned Dim, class M, class C,
00598 class IntOp, class CacheData>
00599 inline
00600 void scatter(const ParticleAttrib<FT>& attrib, Field<FT,Dim,M,C>& f,
00601 const IntOp& intop, const ParticleAttrib<CacheData>& cache) {
00602 attrib.scatter(f, intop, cache);
00603 }
00604
00605
00606
00607 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
00608 inline
00609 void gather(ParticleAttrib<FT>& attrib, const Field<FT,Dim,M,C>& f,
00610 const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop) {
00611 attrib.gather(f, pp, intop);
00612 }
00613
00614
00615
00616 template <class FT, unsigned Dim, class M, class C, class PT,
00617 class IntOp, class CacheData>
00618 inline
00619 void gather(ParticleAttrib<FT>& attrib, const Field<FT,Dim,M,C>& f,
00620 const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop,
00621 ParticleAttrib<CacheData>& cache) {
00622 attrib.gather(f, pp, intop, cache);
00623 }
00624
00625
00626
00627 template <class FT, unsigned Dim, class M, class C,
00628 class CacheData, class IntOp>
00629 inline
00630 void gather(ParticleAttrib<FT>& attrib, const Field<FT,Dim,M,C>& f,
00631 const IntOp& intop, const ParticleAttrib<CacheData>& cache) {
00632 attrib.gather(f, intop, cache);
00633 }
00634
00635
00636
00637 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
00638 void scatter(Field<FT,Dim,M,C>& f, const ParticleAttrib< Vektor<PT,Dim> >& pp,
00639 const IntOp& intop, FT val);
00640
00641
00642 template <class FT, unsigned Dim, class M, class C, class PT,
00643 class IntOp, class CacheData>
00644 void scatter(Field<FT,Dim,M,C>& f, const ParticleAttrib< Vektor<PT,Dim> >& pp,
00645 const IntOp& intop, ParticleAttrib<CacheData>& cache,
00646 FT val);
00647
00648
00649 template <class FT, unsigned Dim, class M, class C,
00650 class IntOp, class CacheData>
00651 void scatter(Field<FT,Dim,M,C>& f, const IntOp& intop,
00652 const ParticleAttrib<CacheData>& cache, FT val);
00653
00654
00655
00656
00657 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
00658 void scatter(Field<FT,Dim,M,C>& f, const ParticleAttrib< Vektor<PT,Dim> >& pp,
00659 const IntOp& intop){
00660 scatter(f, pp, intop, FT(1));
00661 }
00662
00663
00664
00665 template <class FT, unsigned Dim, class M, class C, class PT,
00666 class IntOp, class CacheData>
00667 void scatter(Field<FT,Dim,M,C>& f, const ParticleAttrib< Vektor<PT,Dim> >& pp,
00668 const IntOp& intop, ParticleAttrib<CacheData>& cache) {
00669 scatter(f, pp, intop, cache, FT(1));
00670 }
00671
00672
00673
00674 template <class FT, unsigned Dim, class M, class C,
00675 class IntOp, class CacheData>
00676 void scatter(Field<FT,Dim,M,C>& f, const IntOp& intop,
00677 const ParticleAttrib<CacheData>& cache) {
00678 scatter(f, intop, cache, FT(1));
00679 }
00680
00681 #include "Particle/ParticleAttrib.cpp"
00682
00683 #endif // PARTICLE_ATTRIB_H
00684
00685
00686
00687
00688
00689