OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ParticleAttrib.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef PARTICLE_ATTRIB_H
12 #define PARTICLE_ATTRIB_H
13 
14 /*
15  * ParticleAttrib - Templated class for all particle attribute classes.
16  *
17  * This templated class is used to represent a single particle attribute.
18  * An attribute is one data element within a particle object, and is
19  * stored as an array. This class stores the type information for the
20  * attribute, and provides methods to create and destroy new items, and
21  * to perform operations involving this attribute with others. It also
22  * provides iterators to allow the user to operate on single particles
23  * instead of the entire array.
24  *
25  * ParticleAttrib is the primary element involved in expressions for
26  * particles (just as Field is the primary element there). This file
27  * defines the necessary templated classes and functions to make
28  * ParticleAttrib a capable expression-template participant.
29  *
30  * For some types such as Vektor, Tenzor, etc. which have multiple items,
31  * we want to involve just the Nth item from each data element in an
32  * expression. The () operator here returns an object of type
33  * ParticleAttribElem, which will use the () operator on each individual
34  * element to access an item over which one can iterate and get just the
35  * Nth item from each data element. For example, if we have an attribute
36  * like this:
37  * ParticleAttrib< Vektor<float, 4> > Data
38  * we can involve just the 2nd item of each Vektor in an expression by
39  * referring to this as
40  * Data(1)
41  * which returns an object of type ParticleAttribElem that knows to return
42  * just the 2nd item from each Vektor. ParticleAttribElem is also expression-
43  * template-aware; in fact, it is intended primarily for use in expressions
44  * and not in many other situations. The ParticleAttribElem will use the
45  * () operator to get the Nth item out of each data element, so this requires
46  * the user to define operator () for the particle attribute type being
47  * used (for Vektor, Tenzor, etc., this has already been done). This same
48  * thing has been done for operator () involving either one or two indices,
49  * which is needed to get the i,j element of a Tenzor, for example.
50  *
51  * To perform gather/scatter type operations involving sparse indices, in
52  * which the sparse indices represent a list of points in a dense field
53  * onto which we want to gather/scatter values, you can use the [] operator
54  * to get a SubParticleAttrib object that knows about the particle
55  * elements and associated sparse index points. This allows us to have
56  * the syntax
57  * P[S] = expr(A[S])
58  * where P is a ParticleAttrib, A is some other object such as a Field that
59  * can be indexed by an SIndex, and S is an SIndex object. In this case,
60  * the length of the ParticleAttrib would be changed to match the number
61  * of local points in the SIndex, and the expression would be evaluated at
62  * all the points in the SIndex and stored into P. It also allows the
63  * syntax
64  * A[S] = expr(B[S], P[S])
65  * where A, B are things like Field, S in an SIndex, and P is a ParticleAttrib.
66  * Here, the LHS is assigned, at all the points in the SIndex, to the values
67  * of the expression, which can include a ParticleAttrib only if it is
68  * indexed by an SIndex. This is because SubParticleAttrib contains the
69  * ability to provide an iterator with the right interface for the expression
70  * evaluation.
71  */
72 
73 // include files
77 #include "DataSource/DataSource.h"
79 #include "PETE/IpplExpressions.h"
80 #include "Index/NDIndex.h"
81 #include "Utility/DiscType.h"
82 #include "Utility/Inform.h"
83 #include "Utility/IpplStats.h"
84 
85 #include <vector>
86 #include <utility>
87 
88 // forward declarations
89 template<class T, unsigned Dim> class Vektor;
90 template<class T, unsigned Dim, class M, class C> class Field;
91 template <class T> class ParticleAttribIterator;
92 template <class T> class ParticleAttribConstIterator;
93 
94 
95 // ParticleAttrib class definition
96 template <class T>
97 class ParticleAttrib : public ParticleAttribBase, public DataSource,
98  public PETE_Expr< ParticleAttrib<T> >
99 {
100 
101  friend class ParticleAttribIterator<T>;
103 
104 public:
105  // useful typedefs for type of data contained here
106  typedef T Return_t;
107  typedef std::vector<T> ParticleList_t;
112 
113 public:
114  // default constructor
116  INCIPPLSTAT(incParticleAttribs);
117  }
118 
119  // copy constructor
122  INCIPPLSTAT(incParticleAttribs);
123  }
124 
125  // destructor: delete the storage of the attribute array
127 
128  //
129  // bracket operators to access the Nth particle data
130  //
131 
134  bool isDirty() {
136  return attributeIsDirty_;
137  }
138 
139  void resetDirtyFlag() {
140  attributeIsDirty_ = false;
141  }
142 
143  typename ParticleList_t::reference
144  operator[](size_t n) {
145  attributeIsDirty_ = true;
146  return ParticleList[n];
147  }
148 
149  typename ParticleList_t::const_reference
150  operator[](size_t n) const {
151  return ParticleList[n];
152  }
153 
154  //
155  // bracket operator to refer to an attrib and an SIndex object
156  //
157 
158  template<unsigned Dim>
160  operator[](const SIndex<Dim> &s) const {
161  ParticleAttrib<T> &a = const_cast<ParticleAttrib<T> &>(*this);
162  return SubParticleAttrib<ParticleAttrib<T>, T, Dim>(a, s);
163  }
164 
165  //
166  // PETE interface.
167  //
168  enum { IsExpr = 0 };
170  PETE_Expr_t MakeExpression() const { return cbegin(); }
171 
172  // Get begin and end point iterators
173  iterator begin() { return iterator(this); }
174  iterator end() { return iterator(this, LocalSize); }
175 
176  const_iterator cbegin() const { const_iterator A(this); return A;}
177  const_iterator cend() const { const_iterator A(this, LocalSize); return A; }
178 
179  size_t size(void) const { return LocalSize; }
180 
181  //
182  // methods to allow the user to access components of multiple-item attribs
183  //
184 
185  // Create a ParticleAttribElem to allow the user to access just the Nth
186  // element of the attribute stored here.
188 
189  // Same as above, but specifying two indices
190  ParticleAttribElem<T,2U> operator()(unsigned, unsigned);
191 
192  // Same as above, but specifying three indices
193  ParticleAttribElem<T,3U> operator()(unsigned, unsigned, unsigned);
194 
195  //
196  // Particle <-> Field interaction methods
197  //
198 
199  // scatter the data from this attribute onto the given Field, using
200  // the given Position attribute
201  template <unsigned Dim, class M, class C, class PT, class IntOp>
202  void
204  const ParticleAttrib< Vektor<PT,Dim> >& pp,
205  const IntOp& intop) const {
206 
207 
208  // make sure field is uncompressed and guard cells are zeroed
209  f.Uncompress();
210  T zero = 0;
211  f.setGuardCells(zero);
212 
213  const M& mesh = f.get_mesh();
214  // iterate through ParticleAttrib data and call scatter operation
215  typename ParticleList_t::const_iterator curr, last = ParticleList.begin()+LocalSize;
216  typename ParticleAttrib< Vektor<PT,Dim> >::const_iterator ppiter=pp.cbegin();
217  for (curr = ParticleList.begin(); curr != last; ++curr, ++ppiter)
218  IntOp::scatter(*curr,f,*ppiter,mesh);
219 
220  // accumulate values in guard cells (and compress result)
221  f.accumGuardCells();
222 
223  INCIPPLSTAT(incParticleScatters);
224  return;
225  }
226 
227  // scatter the data from this attribute onto the given Field, using
228  // the given Position attribute, and store the mesh information
229  template <unsigned Dim, class M, class C, class PT,
230  class IntOp, class CacheData>
231  void
233  const ParticleAttrib< Vektor<PT,Dim> >& pp,
234  const IntOp& intop,
235  ParticleAttrib<CacheData>& cache) const {
236 
237 
238 
239  // make sure field is uncompressed and guard cells are zeroed
240  f.Uncompress();
241  T zero = 0;
242  f.setGuardCells(zero);
243 
244  const M& mesh = f.get_mesh();
245  // iterate through ParticleAttrib data and call scatter operation
246  typename ParticleList_t::const_iterator curr, last = ParticleList.begin()+LocalSize;
247  typename ParticleAttrib< Vektor<PT,Dim> >::const_iterator ppiter=pp.cbegin();
248  typename ParticleAttrib<CacheData>::iterator citer=cache.begin();
249  for (curr = ParticleList.begin(); curr != last; ++curr, ++ppiter, ++citer)
250  IntOp::scatter(*curr,f,*ppiter,mesh,*citer);
251 
252  // accumulate values in guard cells (and compress result)
253  f.accumGuardCells();
254 
255  INCIPPLSTAT(incParticleScatters);
256  return;
257  }
258 
259  // scatter the data from this attribute onto the given Field, using
260  // the precomputed mesh information
261  template <unsigned Dim, class M, class C, class IntOp, class CacheData>
262  void
263  scatter(Field<T,Dim,M,C>& f, const IntOp& /*intop*/,
264  const ParticleAttrib<CacheData>& cache) const {
265 
266 
267 
268  // make sure field is uncompressed and guard cells are zeroed
269  f.Uncompress();
270  T zero = 0;
271  f.setGuardCells(zero);
272 
273  // iterate through ParticleAttrib data and call scatter operation
274  typename ParticleList_t::const_iterator curr, last = ParticleList.begin()+LocalSize;
275  typename ParticleAttrib<CacheData>::const_iterator citer=cache.cbegin();
276  for (curr = ParticleList.begin(); curr != last; ++curr, ++citer)
277  IntOp::scatter(*curr,f,*citer);
278 
279  // accumulate values in guard cells (and compress result)
280  f.accumGuardCells();
281 
282  INCIPPLSTAT(incParticleScatters);
283  return;
284  }
285 
286  // gather the data from the given Field into this attribute, using
287  // the given Position attribute
288  template <unsigned Dim, class M, class C, class PT, class IntOp>
289  void
291  const ParticleAttrib< Vektor<PT,Dim> >& pp,
292  const IntOp& /*intop*/) {
293 
294 
295  // make sure field is uncompressed
296  f.Uncompress();
297  // fill guard cells if they are dirty
298  if (f.isDirty())
299  f.fillGuardCells(true);
300 
301  const M& mesh = f.get_mesh();
302  // iterate through ParticleAttrib data and call gather operation
303  typename ParticleList_t::iterator curr, last = ParticleList.begin()+LocalSize;
304  typename ParticleAttrib< Vektor<PT,Dim> >::const_iterator ppiter=pp.cbegin();
305  for (curr = ParticleList.begin(); curr != last; ++curr, ++ppiter)
306  IntOp::gather(*curr,f,*ppiter,mesh);
307 
308  // try to compress the Field again
309  f.Compress();
310 
311  INCIPPLSTAT(incParticleGathers);
312  return;
313  }
314 
315  // gather the data from the given Field into this attribute, using
316  // the given Position attribute, and store the mesh information
317  template <unsigned Dim, class M, class C, class PT,
318  class IntOp, class CacheData>
319  void
321  const ParticleAttrib< Vektor<PT,Dim> >& pp,
322  const IntOp& /*intop*/,
323  ParticleAttrib<CacheData>& cache) {
324 
325 
326  // make sure field is uncompressed
327  f.Uncompress();
328  // fill guard cells if they are dirty
329  if (f.isDirty())
330  f.fillGuardCells(true);
331 
332  const M& mesh = f.get_mesh();
333  // iterate through ParticleAttrib data and call gather operation
334  typename ParticleList_t::iterator curr, last = ParticleList.begin()+LocalSize;
335  typename ParticleAttrib< Vektor<PT,Dim> >::const_iterator ppiter=pp.cbegin();
336  typename ParticleAttrib<CacheData>::iterator citer=cache.begin();
337  for (curr=ParticleList.begin(); curr != last; ++curr,++ppiter,++citer)
338  IntOp::gather(*curr,f,*ppiter,mesh,*citer);
339 
340  // try to compress the Field again
341  f.Compress();
342 
343  INCIPPLSTAT(incParticleGathers);
344  return;
345  }
346 
347  // gather the data from the given Field into this attribute, using
348  // the precomputed mesh information
349  template <unsigned Dim, class M, class C, class IntOp, class CacheData>
350  void
351  gather(const Field<T,Dim,M,C>& f, const IntOp& /*intop*/,
352  const ParticleAttrib<CacheData>& cache) {
353 
354 
355  // make sure field is uncompressed
356  f.Uncompress();
357  // fill guard cells if they are dirty
358  if (f.isDirty())
359  f.fillGuardCells(true);
360 
361  // iterate through ParticleAttrib data and call gather operation
362  typename ParticleList_t::iterator curr, last = ParticleList.begin()+LocalSize;
363  typename ParticleAttrib<CacheData>::const_iterator citer=cache.cbegin();
364  for (curr = ParticleList.begin(); curr != last; ++curr, ++citer)
365  IntOp::gather(*curr,f,*citer);
366 
367  // try to compress the Field again
368  f.Compress();
369 
370  INCIPPLSTAT(incParticleGathers);
371  return;
372  }
373 
374  //
375  // Assignment operators
376  //
377 
378  // assign a general expression
379  template<class T1>
381  assign(*this,rhs);
382  return *this;
383  }
384 
385  // assignment of a ParticleAttrib
387  if (size() != rhs.size()) {
388  ERRORMSG("Attempting to copy particle attributes with unequal sizes.");
389  ERRORMSG("\n" << size() << " != " << rhs.size() << endl);
390  }
391  assign(*this,rhs);
392  return *this;
393  }
394 
395  // assignment of a scalar
397  assign(*this,rhs);
398  return *this;
399  }
400 
401  //
402  // methods used to manipulate the normal attrib data
403  //
404 
405  // Create storage for M particle attributes. The storage is uninitialized.
406  // New items are appended to the end of the array.
407  virtual void create(size_t);
408 
409  // Delete the attribute storage for M particle attributes, starting at
410  // the position I.
411  // This really erases the data, which will change local indices
412  // of the data. It actually just copies the data from the end of the
413  // storage into the selected block
414  // Boolean flag indicates whether to use optimized destroy method
415  virtual void destroy(size_t M, size_t I, bool optDestroy=true);
416 
417  // This version takes a list of particle destroy events
418  // Boolean flag indicates whether to use optimized destroy method
419  virtual void destroy(const std::vector< std::pair<size_t,size_t> >& dlist,
420  bool optDestroy=true);
421 
422  // puts M particle's data starting from index I into a Message.
423  // Return the number of particles put into the message.
424  virtual size_t putMessage(Message&, size_t, size_t);
425 
426  // Another version of putMessage, which takes list of indices
427  // Return the number of particles put into the message.
428  virtual size_t putMessage(Message&, const std::vector<size_t>&);
429 
430  // Get data out of a Message containing N particle's attribute data,
431  // and store it here. Data is appended to the end of the list. Return
432  // the number of particles retrieved.
433  virtual size_t getMessage(Message&, size_t);
434 
435  //
436  // methods used to manipulate the ghost particle data
437  //
438 
439  // Delete the ghost attrib storage for M particles, starting at pos I.
440  // Items from the end of the list are moved up to fill in the space.
441  // Return the number of items actually destroyed.
442  virtual size_t ghostDestroy(size_t, size_t);/* {
443  return 0;
444  }*/
445  virtual void ghostCreate(size_t);/*
446  {
447 
448  }*/
449  // puts M particle's data starting from index I into a Message.
450  // Return the number of particles put into the message. This is for
451  // when particles are being swapped to build ghost particle interaction
452  // lists.
453  virtual size_t ghostPutMessage(Message&, size_t, size_t);/* {
454  return 0;
455  }*/
456  // puts data for a list of particles into a Message, for interaction lists.
457  // Return the number of particles put into the message.
458  virtual size_t ghostPutMessage(Message&, const std::vector<size_t>&);/* {
459  return 0;
460  }*/
461 
462  // Get ghost particle data from a message.
463  virtual size_t ghostGetMessage(Message&, size_t);/* {
464  return 0;
465  }*/
466 
467  //
468  // virtual methods used to sort data
469  //
470 
471  // Calculate a "sort list", which is an array of data of the same
472  // length as this attribute, with each element indicating the
473  // (local) index wherethe ith particle shoulkd go. For example,
474  // if there are four particles, and the sort-list is {3,1,0,2}, that
475  // means the particle currently with index=0 should be moved to the third
476  // position, the one with index=1 should stay where it is, etc.
477  // The optional second argument indicates if the sort should be ascending
478  // (true, the default) or descending (false).
479  virtual void calcSortList(SortList_t &slist, bool ascending = true);
480 
481  // Process a sort-list, as described for "calcSortList", to reorder
482  // the elements in this attribute. All indices in the sort list are
483  // considered "local", so they should be in the range 0 ... localnum-1.
484  // The sort-list does not have to have been calculated by calcSortList,
485  // it could be calculated by some other means, but it does have to
486  // be in the same format. Note that the routine may need to modify
487  // the sort-list temporarily, but it will return it in the same state.
488  virtual void sort(SortList_t &slist);
489 
490  //
491  // other functions
492  //
493 
494  // Print out information for debugging purposes.
495  virtual void printDebug(Inform&);
496 
497 protected:
498  // a virtual function which is called by this base class to get a
499  // specific instance of DataSourceObject based on the type of data
500  // and the connection method (the argument to the call).
501  virtual DataSourceObject *createDataSourceObject(const char *nm,
502  DataConnect *dc, int tm) {
503  return make_DataSourceObject(nm, dc, tm, *this);
504  }
505 
506  // storage for particle data
508  size_t LocalSize;
509 
510 private:
512 };
513 
514 
515 //
516 // iterator for data in a ParticleAttrib
517 //
518 //~
519 //~ template <class T>
520 //~ class ParticleAttribIterator : public PETE_Expr< ParticleAttribIterator<T> >
521 //~ {
522 //~ public:
523 //~ typedef typename ParticleAttrib<T>::ParticleList_t ParticleList_t;
524 //~
525 //~ ParticleAttribIterator() : myList(0), curr(0) { }
526 //~
527 //~ ParticleAttribIterator(ParticleList_t& pa)
528 //~ : myList(&pa), curr(&(*pa.begin())) { }
529 //~
530 //~ ParticleAttribIterator(ParticleList_t& pa, size_t offset)
531 //~ : myList(&pa), curr(&(*(pa.begin()+offset))) { }
532 //~
533 //~ ParticleAttribIterator(const ParticleAttribIterator<T>& i)
534 //~ : myList(i.myList), curr(i.curr) { }
535 //~
536 //~ // PETE interface.
537 //~ typedef ParticleAttribIterator<T> PETE_Expr_t;
538 //~ typedef T PETE_Return_t;
539 //~ PETE_Expr_t MakeExpression() const { return *this; }
540 //~ PETE_Return_t& operator*(void) const { return *curr; }
541 //~
542 //~ ParticleAttribIterator<T>& operator++(void) {
543 //~ ++curr;
544 //~ return *this;
545 //~ }
546 //~ ParticleAttribIterator<T>& at_end(void) {
547 //~ curr = &*myList->end();
548 //~ return *this;
549 //~ }
550 //~ bool operator==(const ParticleAttribIterator<T>& a) const {
551 //~ return (curr == a.curr);
552 //~ }
553 //~ bool operator!=(const ParticleAttribIterator<T>& a) const {
554 //~ return !(curr == a.curr);
555 //~ }
556 //~ const ParticleList_t& getParticleList() const { return *myList; }
557 //~ T* getP() const { return curr; }
558 //~
559 //~ private:
560 //~ ParticleList_t* myList; // ParticleList I iterate over
561 //~ T* curr; // iterator current position
562 //~ };
563 
564 
565 template <class T>
566 class ParticleAttribIterator : public PETE_Expr< ParticleAttribIterator<T> >
567 {
568 public:
570  typedef T value_type;
571  typedef std::ptrdiff_t difference_type;
572  typedef T* pointer;
573  typedef T& reference;
574  typedef std::random_access_iterator_tag iterator_category;
575 
577 
579  : attrib(pa), curr(pa->ParticleList.begin()) { }
580 
582  : attrib(pa), curr(pa->ParticleList.begin()+offset) { }
583 
585  : attrib(i.attrib), curr(i.curr) { }
586 
587  // PETE interface.
589  typedef T PETE_Return_t;
590  PETE_Expr_t MakeExpression() const { return *this; }
591  PETE_Return_t& operator*(void) const { return *curr; }
592  T* operator->() const { return getP(); }
593 
595  ++curr;
596  return *this;
597  }
598 
600  ParticleAttribIterator<T> tmp(*this);
601  ++curr;
602  return tmp;
603  }
604 
606  --curr;
607  return *this;
608  }
609 
611  ParticleAttribIterator<T> tmp(*this);
612  --curr;
613  return tmp;
614  }
615 
617  curr += n;
618  return *this;
619  }
620 
622  ParticleAttribIterator<T> tmp(*this);
623  tmp += n;
624  return tmp;
625  }
626 
628  curr -= n;
629  return *this;
630  }
631 
633  ParticleAttribIterator<T> tmp(*this);
634  tmp -= n;
635  return tmp;
636  }
637 
638  size_t operator-(const ParticleAttribIterator<T>& a) const {
639  return (curr - a.curr);
640  }
641 
643  return (*this + n);
644  }
645 
647  curr = attrib->ParticleList.begin()+attrib->LocalSize;
648  return *this;
649  }
650 
651  bool operator==(const ParticleAttribIterator<T>& a) const {
652  return (curr == a.curr);
653  }
654 
655  bool operator!=(const ParticleAttribIterator<T>& a) const {
656  return !(curr == a.curr);
657  }
658 
659  bool operator<(const ParticleAttribIterator<T>& a) const {
660  return (curr < a.curr);
661  }
662 
663  bool operator<=(const ParticleAttribIterator<T>& a) const {
664  return (curr <= a.curr);
665  }
666 
667  bool operator>(const ParticleAttribIterator<T>& a) const {
668  return (curr > a.curr);
669  }
670 
671  bool operator>=(const ParticleAttribIterator<T>& a) const {
672  return (curr >= a.curr);
673  }
674  //const ParticleList_t& getParticleList() const { return attrib->ParticleList; }
675  size_t size() const { return attrib->LocalSize; }
676  T* getP() const { return &(*curr); }
677 
678 private:
679  ParticleAttrib<T> *attrib; // ParticleList I iterate over
680  typename ParticleList_t::iterator curr; // iterator current position
681 };
682 
683 template <class T>
685  return (a + n);
686 }
687 
688 template <class T>
689 class ParticleAttribConstIterator : public PETE_Expr< ParticleAttribConstIterator<T> >
690 {
691 public:
693  typedef T value_type;
694  typedef std::ptrdiff_t difference_type;
695  typedef T* pointer;
696  typedef T& reference;
697  typedef std::random_access_iterator_tag iterator_category;
698 
700 
702  : attrib(pa), curr(pa->ParticleList.begin()) { }
703 
705  : attrib(pa), curr(pa->ParticleList.begin()+offset) { }
706 
708  : attrib(i.attrib), curr(i.curr) { }
709 
710  // PETE interface.
712  typedef T PETE_Return_t;
713  PETE_Expr_t MakeExpression() const { return *this; }
714  const PETE_Return_t& operator*(void) const { return *curr; }
715 
716  T const * operator->() const { return getP(); }
717 
719  ++curr;
720  return *this;
721  }
722 
725  ++curr;
726  return tmp;
727  }
728 
730  --curr;
731  return *this;
732  }
733 
736  --curr;
737  return tmp;
738  }
739 
741  curr += n;
742  return *this;
743  }
744 
747  tmp += n;
748  return tmp;
749  }
750 
752  curr -= n;
753  return *this;
754  }
755 
758  tmp -= n;
759  return tmp;
760  }
761 
762  size_t operator-(const ParticleAttribConstIterator<T>& a) const {
763  return (curr - a.curr);
764  }
765 
767  return (*this + n);
768  }
769 
771  curr = attrib->ParticleList.begin()+attrib->LocalSize;
772  return *this;
773  }
774 
776  return (curr == a.curr);
777  }
778 
780  return !(curr == a.curr);
781  }
782 
783  bool operator<(const ParticleAttribConstIterator<T>& a) const {
784  return (curr < a.curr);
785  }
786 
787  bool operator<=(const ParticleAttribConstIterator<T>& a) const {
788  return (curr <= a.curr);
789  }
790 
792  return (curr > a.curr);
793  }
794 
796  return (curr >= a.curr);
797  }
798 
799  //const ParticleList_t& getParticleList() const { return attrib->ParticleList; }
800  size_t size() const { return attrib->LocalSize; }
801  T const * getP() const { return &(*curr); }
802 
803 private:
804  ParticleAttrib<T> const * attrib; // ParticleList I iterate over
805  typename ParticleList_t::const_iterator curr; // iterator current position
806 };
807 
808 template <class T>
810  return (a + n);
811 }
812 
813 // Global template functions for gather/scatter operations
814 
815 // scatter the data from the given attribute onto the given Field, using
816 // the given Position attribute
817 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
818 inline
820  const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop) {
821  attrib.scatter(f, pp, intop);
822 }
823 
824 // scatter the data from the given attribute onto the given Field, using
825 // the given Position attribute, and save the mesh information for reuse
826 template <class FT, unsigned Dim, class M, class C, class PT,
827  class IntOp, class CacheData>
828 inline
830  const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop,
831  ParticleAttrib<CacheData>& cache) {
832  attrib.scatter(f, pp, intop, cache);
833 }
834 
835 // scatter the data from the given attribute onto the given Field, using
836 // the precomputed mesh information
837 template <class FT, unsigned Dim, class M, class C,
838  class IntOp, class CacheData>
839 inline
841  const IntOp& intop, const ParticleAttrib<CacheData>& cache) {
842  attrib.scatter(f, intop, cache);
843 }
844 
845 // gather the data from the given Field into the given attribute, using
846 // the given Position attribute
847 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
848 inline
850  const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop) {
851  attrib.gather(f, pp, intop);
852 }
853 
854 // gather the data from the given Field into the given attribute, using
855 // the given Position attribute, and save the mesh information for reuse
856 template <class FT, unsigned Dim, class M, class C, class PT,
857  class IntOp, class CacheData>
858 inline
860  const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop,
861  ParticleAttrib<CacheData>& cache) {
862  attrib.gather(f, pp, intop, cache);
863 }
864 
865 // gather the data from the given Field into the given attribute, using
866 // the precomputed mesh information
867 template <class FT, unsigned Dim, class M, class C,
868  class CacheData, class IntOp>
869 inline
871  const IntOp& intop, const ParticleAttrib<CacheData>& cache) {
872  attrib.gather(f, intop, cache);
873 }
874 
875 // This scatter function computes the particle number density by
876 // scattering the scalar value val for each particle into the Field.
877 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
879  const IntOp& intop, FT val);
880 
881 // version which also caches mesh info
882 template <class FT, unsigned Dim, class M, class C, class PT,
883  class IntOp, class CacheData>
885  const IntOp& intop, ParticleAttrib<CacheData>& cache,
886  FT val);
887 
888 // version which uses cached mesh info
889 template <class FT, unsigned Dim, class M, class C,
890  class IntOp, class CacheData>
891 void scatter(Field<FT,Dim,M,C>& f, const IntOp& intop,
892  const ParticleAttrib<CacheData>& cache, FT val);
893 
894 // mwerks: addeded this to work around default-arg bug:
895 // This scatter function computes the particle number density by
896 // scattering the scalar value val for each particle into the Field.
897 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
899  const IntOp& intop){
900  scatter(f, pp, intop, FT(1));
901 }
902 
903 // mwerks: addeded this to work around default-arg bug:
904 // version which also caches mesh info
905 template <class FT, unsigned Dim, class M, class C, class PT,
906  class IntOp, class CacheData>
908  const IntOp& intop, ParticleAttrib<CacheData>& cache) {
909  scatter(f, pp, intop, cache, FT(1));
910 }
911 
912 // mwerks: addeded this to work around default-arg bug:
913 // version which uses cached mesh info
914 template <class FT, unsigned Dim, class M, class C,
915  class IntOp, class CacheData>
916 inline void scatter(Field<FT,Dim,M,C>& f, const IntOp& intop,
917  const ParticleAttrib<CacheData>& cache) {
918  scatter(f, intop, cache, FT(1));
919 }
920 
922 
923 #endif // PARTICLE_ATTRIB_H
924 
925 /***************************************************************************
926  * $RCSfile: ParticleAttrib.h,v $ $Author: adelmann $
927  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:28 $
928  * IPPL_VERSION_ID: $Id: ParticleAttrib.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $
929  ***************************************************************************/
std::random_access_iterator_tag iterator_category
Matrix< T > operator+(const Matrix< T > &, const Matrix< T > &)
Matrix addition.
Definition: Matrix.h:275
ParticleAttribConstIterator< T > operator--(int)
ParticleAttribIterator< T > operator[](size_t n) const
ParticleAttribIterator(ParticleAttrib< T > *pa, size_t offset)
ParticleAttribConstIterator(const ParticleAttrib< T > *pa)
bool operator>(const ParticleAttribIterator< T > &a) const
Definition: PETE.h:80
void gather(const Field< T, Dim, M, C > &f, const IntOp &, const ParticleAttrib< CacheData > &cache)
ParticleAttribIterator< T > PETE_Expr_t
virtual void ghostCreate(size_t)
bool isDirty() const
Definition: BareField.h:115
ParticleAttribConstIterator< T > operator[](size_t n) const
virtual void create(size_t)
virtual size_t getMessage(Message &, size_t)
DataSourceObject * make_DataSourceObject(const char *, DataConnect *, int, Field< T, Dim, M, C > &)
iterator begin()
Definition: TSVMeta.h:24
Definition: rbendmap.h:8
ParticleAttribElem< T, 1U > operator()(unsigned)
bool operator!=(const ParticleAttribConstIterator< T > &a) const
const_iterator PETE_Expr_t
T const * operator->() const
iterator end()
void scatter(Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &intop) const
ParticleAttribConstIterator< T > const_iterator
ParticleAttribIterator< T > & operator-=(size_t n)
virtual void sort(SortList_t &slist)
PETE_Expr_t MakeExpression() const
Definition: SIndex.h:28
void Compress() const
Definition: BareField.hpp:1304
ParticleAttribIterator< T > & operator+=(size_t n)
#define ERRORMSG(msg)
Definition: IpplInfo.h:399
size_t size(void) const
ParticleAttribConstIterator< T > operator++(int)
bool operator==(const ParticleAttribConstIterator< T > &a) const
const_iterator cbegin() const
ParticleAttribIterator< T > & operator++(void)
PETE_Expr_t MakeExpression() const
const ParticleAttrib< T > & operator=(const PETE_Expr< T1 > &rhs)
void Uncompress() const
Definition: BareField.hpp:1318
void setGuardCells(const T &) const
Definition: BareField.hpp:682
void gather(const Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &, ParticleAttrib< CacheData > &cache)
bool scatter(Communicate &, InputIterator, InputIterator, RandomIterator, int *, int *, const ScatterOp &)
Definition: GlobalComm.hpp:353
bool operator>=(const ParticleAttribIterator< T > &a) const
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
std::ptrdiff_t difference_type
ParticleAttribConstIterator(const ParticleAttribConstIterator< T > &i)
std::vector< SortListIndex_t > SortList_t
std::vector< T > ParticleList_t
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
Definition: GlobalComm.hpp:55
void fillGuardCells(bool reallyFill=true) const
bool operator==(const ParticleAttribIterator< T > &a) const
std::random_access_iterator_tag iterator_category
ParticleAttribIterator< T > operator++(int)
ParticleAttribIterator(ParticleAttrib< T > *pa)
void gather(const T *input, T *output, int count, int root=0)
Definition: GlobalComm.hpp:449
const ParticleAttrib< T > & operator=(const ParticleAttrib< T > &rhs)
ParticleAttribBase::SortListIndex_t SortListIndex_t
ParticleAttribConstIterator< T > operator+(size_t n) const
size_t operator-(const ParticleAttribConstIterator< T > &a) const
ParticleAttrib< T >::ParticleList_t ParticleList_t
ParticleAttrib< T >::ParticleList_t ParticleList_t
ParticleAttribConstIterator< T > & operator--(void)
virtual size_t ghostDestroy(size_t, size_t)
ParticleAttribConstIterator< T > & operator++(void)
bool operator>(const ParticleAttribConstIterator< T > &a) const
ParticleAttrib< T > * attrib
virtual void printDebug(Inform &)
virtual void calcSortList(SortList_t &slist, bool ascending=true)
virtual size_t putMessage(Message &, size_t, size_t)
ParticleList_t::const_iterator curr
bool operator!=(const ParticleAttribIterator< T > &a) const
PETE_Expr_t MakeExpression() const
virtual void destroy(size_t M, size_t I, bool optDestroy=true)
ParticleAttribIterator< T > operator+(size_t n) const
#define INCIPPLSTAT(stat)
Definition: IpplStats.h:235
ParticleAttribIterator< T > & operator--(void)
void accumGuardCells()
Definition: BareField.hpp:764
ParticleAttribConstIterator< T > & operator+=(size_t n)
const PETE_Return_t & operator*(void) const
ParticleAttribConstIterator< T > & at_end(void)
ParticleAttribConstIterator< T > operator-(size_t n) const
ParticleAttribIterator< T > operator-(size_t n) const
void scatter(Field< T, Dim, M, C > &f, const IntOp &, const ParticleAttrib< CacheData > &cache) const
bool operator>=(const ParticleAttribConstIterator< T > &a) const
ParticleList_t ParticleList
SubParticleAttrib< ParticleAttrib< T >, T, Dim > operator[](const SIndex< Dim > &s) const
ParticleAttribIterator< T > & at_end(void)
void scatter(Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &intop, ParticleAttrib< CacheData > &cache) const
const_iterator cend() const
void gather(const Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &)
PETE_Return_t & operator*(void) const
size_t size() const
virtual size_t ghostGetMessage(Message &, size_t)
size_t operator-(const ParticleAttribIterator< T > &a) const
ParticleAttribConstIterator< T > & operator-=(size_t n)
ParticleAttribConstIterator(const ParticleAttrib< T > *pa, size_t offset)
std::string::iterator iterator
Definition: MSLang.h:16
const unsigned Dim
Mesh_t & get_mesh() const
Definition: Field.h:113
ParticleAttribIterator< T > iterator
ParticleList_t::reference operator[](size_t n)
Definition: rbendmap.h:8
Definition: Inform.h:41
ParticleAttribIterator< T > operator--(int)
ParticleList_t::iterator curr
const ParticleAttrib< T > & operator=(T rhs)
ParticleAttribBase::SortList_t SortList_t
ParticleList_t::const_reference operator[](size_t n) const
ParticleAttrib< T > const * attrib
virtual size_t ghostPutMessage(Message &, size_t, size_t)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
virtual DataSourceObject * createDataSourceObject(const char *nm, DataConnect *dc, int tm)
ParticleAttrib(const ParticleAttrib< T > &pa)
ParticleAttribIterator(const ParticleAttribIterator< T > &i)
ParticleAttribConstIterator< T > PETE_Expr_t