OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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
76 #include "Particle/PAssign.h"
78 #include "DataSource/DataSource.h"
80 #include "PETE/IpplExpressions.h"
81 #include "Index/NDIndex.h"
82 #include "Utility/DiscType.h"
83 #include "Utility/Inform.h"
84 #include "Utility/IpplStats.h"
85 
86 #include <vector>
87 #include <utility>
88 
89 // forward declarations
90 template<class T, unsigned Dim> class Vektor;
91 template<class T, unsigned Dim, class M, class C> class Field;
92 template <class T> class ParticleAttribIterator;
93 template <class T> class ParticleAttribConstIterator;
94 
95 
96 // ParticleAttrib class definition
97 template <class T>
99  public PETE_Expr< ParticleAttrib<T> >
100 {
101 
102  friend class ParticleAttribIterator<T>;
103  friend class ParticleAttribConstIterator<T>;
104 
105 public:
106  // useful typedefs for type of data contained here
107  typedef T Return_t;
108  typedef std::vector<T> ParticleList_t;
113 
114 public:
115  // default constructor
117  INCIPPLSTAT(incParticleAttribs);
118  }
119 
120  // copy constructor
123  INCIPPLSTAT(incParticleAttribs);
124  }
125 
126  // destructor: delete the storage of the attribute array
128 
129  //
130  // bracket operators to access the Nth particle data
131  //
132 
135  bool isDirty() {
137  return attributeIsDirty_;
138  }
139 
140  void resetDirtyFlag() {
141  attributeIsDirty_ = false;
142  }
143 
144  typename ParticleList_t::reference
145  operator[](size_t n) {
146  attributeIsDirty_ = true;
147  return ParticleList[n];
148  }
149 
150  typename ParticleList_t::const_reference
151  operator[](size_t n) const {
152  return ParticleList[n];
153  }
154 
155  //
156  // bracket operator to refer to an attrib and an SIndex object
157  //
158 
159  template<unsigned Dim>
161  operator[](const SIndex<Dim> &s) const {
162  ParticleAttrib<T> &a = const_cast<ParticleAttrib<T> &>(*this);
164  }
165 
166  //
167  // PETE interface.
168  //
169  enum { IsExpr = 0 };
171  PETE_Expr_t MakeExpression() const { return cbegin(); }
172 
173  // Get begin and end point iterators
174  iterator begin() { return iterator(this); }
175  iterator end() { return iterator(this, LocalSize); }
176 
177  const_iterator cbegin() const { const_iterator A(this); return A;}
178  const_iterator cend() const { const_iterator A(this, LocalSize); return A; }
179 
180  size_t size(void) const { return LocalSize; }
181 
182  //
183  // methods to allow the user to access components of multiple-item attribs
184  //
185 
186  // Create a ParticleAttribElem to allow the user to access just the Nth
187  // element of the attribute stored here.
189 
190  // Same as above, but specifying two indices
191  ParticleAttribElem<T,2U> operator()(unsigned, unsigned);
192 
193  // Same as above, but specifying three indices
194  ParticleAttribElem<T,3U> operator()(unsigned, unsigned, unsigned);
195 
196  //
197  // Particle <-> Field interaction methods
198  //
199 
200  // scatter the data from this attribute onto the given Field, using
201  // the given Position attribute
202  template <unsigned Dim, class M, class C, class PT, class IntOp>
203  void
205  const ParticleAttrib< Vektor<PT,Dim> >& pp,
206  const IntOp& /*intop*/) const {
207 
208 
209  // make sure field is uncompressed and guard cells are zeroed
210  f.Uncompress();
211  T zero = 0;
212  f.setGuardCells(zero);
213 
214  const M& mesh = f.get_mesh();
215  // iterate through ParticleAttrib data and call scatter operation
216  typename ParticleList_t::const_iterator curr, last = ParticleList.begin()+LocalSize;
217  typename ParticleAttrib< Vektor<PT,Dim> >::const_iterator ppiter=pp.cbegin();
218  for (curr = ParticleList.begin(); curr != last; ++curr, ++ppiter)
219  IntOp::scatter(*curr,f,*ppiter,mesh);
220 
221  // accumulate values in guard cells (and compress result)
222  f.accumGuardCells();
223 
224  INCIPPLSTAT(incParticleScatters);
225  return;
226  }
227 
228  // scatter the data from this attribute onto the given Field, using
229  // the given Position attribute, and store the mesh information
230  template <unsigned Dim, class M, class C, class PT,
231  class IntOp, class CacheData>
232  void
234  const ParticleAttrib< Vektor<PT,Dim> >& pp,
235  const IntOp& /*intop*/,
236  ParticleAttrib<CacheData>& cache) const {
237 
238 
239 
240  // make sure field is uncompressed and guard cells are zeroed
241  f.Uncompress();
242  T zero = 0;
243  f.setGuardCells(zero);
244 
245  const M& mesh = f.get_mesh();
246  // iterate through ParticleAttrib data and call scatter operation
247  typename ParticleList_t::const_iterator curr, last = ParticleList.begin()+LocalSize;
248  typename ParticleAttrib< Vektor<PT,Dim> >::const_iterator ppiter=pp.cbegin();
249  typename ParticleAttrib<CacheData>::iterator citer=cache.begin();
250  for (curr = ParticleList.begin(); curr != last; ++curr, ++ppiter, ++citer)
251  IntOp::scatter(*curr,f,*ppiter,mesh,*citer);
252 
253  // accumulate values in guard cells (and compress result)
254  f.accumGuardCells();
255 
256  INCIPPLSTAT(incParticleScatters);
257  return;
258  }
259 
260  // scatter the data from this attribute onto the given Field, using
261  // the precomputed mesh information
262  template <unsigned Dim, class M, class C, class IntOp, class CacheData>
263  void
264  scatter(Field<T,Dim,M,C>& f, const IntOp& /*intop*/,
265  const ParticleAttrib<CacheData>& cache) const {
266 
267 
268 
269  // make sure field is uncompressed and guard cells are zeroed
270  f.Uncompress();
271  T zero = 0;
272  f.setGuardCells(zero);
273 
274  // iterate through ParticleAttrib data and call scatter operation
275  typename ParticleList_t::const_iterator curr, last = ParticleList.begin()+LocalSize;
276  typename ParticleAttrib<CacheData>::const_iterator citer=cache.cbegin();
277  for (curr = ParticleList.begin(); curr != last; ++curr, ++citer)
278  IntOp::scatter(*curr,f,*citer);
279 
280  // accumulate values in guard cells (and compress result)
281  f.accumGuardCells();
282 
283  INCIPPLSTAT(incParticleScatters);
284  return;
285  }
286 
287  // gather the data from the given Field into this attribute, using
288  // the given Position attribute
289  template <unsigned Dim, class M, class C, class PT, class IntOp>
290  void
292  const ParticleAttrib< Vektor<PT,Dim> >& pp,
293  const IntOp& /*intop*/) {
294 
295 
296  // make sure field is uncompressed
297  f.Uncompress();
298  // fill guard cells if they are dirty
299  if (f.isDirty())
300  f.fillGuardCells(true);
301 
302  const M& mesh = f.get_mesh();
303  // iterate through ParticleAttrib data and call gather operation
304  typename ParticleList_t::iterator curr, last = ParticleList.begin()+LocalSize;
305  typename ParticleAttrib< Vektor<PT,Dim> >::const_iterator ppiter=pp.cbegin();
306  for (curr = ParticleList.begin(); curr != last; ++curr, ++ppiter)
307  IntOp::gather(*curr,f,*ppiter,mesh);
308 
309  // try to compress the Field again
310  f.Compress();
311 
312  INCIPPLSTAT(incParticleGathers);
313  return;
314  }
315 
316  // gather the data from the given Field into this attribute, using
317  // the given Position attribute, and store the mesh information
318  template <unsigned Dim, class M, class C, class PT,
319  class IntOp, class CacheData>
320  void
322  const ParticleAttrib< Vektor<PT,Dim> >& pp,
323  const IntOp& /*intop*/,
324  ParticleAttrib<CacheData>& cache) {
325 
326 
327  // make sure field is uncompressed
328  f.Uncompress();
329  // fill guard cells if they are dirty
330  if (f.isDirty())
331  f.fillGuardCells(true);
332 
333  const M& mesh = f.get_mesh();
334  // iterate through ParticleAttrib data and call gather operation
335  typename ParticleList_t::iterator curr, last = ParticleList.begin()+LocalSize;
336  typename ParticleAttrib< Vektor<PT,Dim> >::const_iterator ppiter=pp.cbegin();
337  typename ParticleAttrib<CacheData>::iterator citer=cache.begin();
338  for (curr=ParticleList.begin(); curr != last; ++curr,++ppiter,++citer)
339  IntOp::gather(*curr,f,*ppiter,mesh,*citer);
340 
341  // try to compress the Field again
342  f.Compress();
343 
344  INCIPPLSTAT(incParticleGathers);
345  return;
346  }
347 
348  // gather the data from the given Field into this attribute, using
349  // the precomputed mesh information
350  template <unsigned Dim, class M, class C, class IntOp, class CacheData>
351  void
352  gather(const Field<T,Dim,M,C>& f, const IntOp& /*intop*/,
353  const ParticleAttrib<CacheData>& cache) {
354 
355 
356  // make sure field is uncompressed
357  f.Uncompress();
358  // fill guard cells if they are dirty
359  if (f.isDirty())
360  f.fillGuardCells(true);
361 
362  // iterate through ParticleAttrib data and call gather operation
363  typename ParticleList_t::iterator curr, last = ParticleList.begin()+LocalSize;
364  typename ParticleAttrib<CacheData>::const_iterator citer=cache.cbegin();
365  for (curr = ParticleList.begin(); curr != last; ++curr, ++citer)
366  IntOp::gather(*curr,f,*citer);
367 
368  // try to compress the Field again
369  f.Compress();
370 
371  INCIPPLSTAT(incParticleGathers);
372  return;
373  }
374 
375  //
376  // Assignment operators
377  //
378 
379  // assign a general expression
380  template<class T1>
382  assign(*this,rhs);
383  return *this;
384  }
385 
386  // assignment of a ParticleAttrib
388  if (size() != rhs.size()) {
389  ERRORMSG("Attempting to copy particle attributes with unequal sizes.");
390  ERRORMSG("\n" << size() << " != " << rhs.size() << endl);
391  }
392  assign(*this,rhs);
393  return *this;
394  }
395 
396  // assignment of a scalar
398  assign(*this,rhs);
399  return *this;
400  }
401 
402  //
403  // methods used to manipulate the normal attrib data
404  //
405 
406  // Create storage for M particle attributes. The storage is uninitialized.
407  // New items are appended to the end of the array.
408  virtual void create(size_t);
409 
410  // Delete the attribute storage for M particle attributes, starting at
411  // the position I.
412  // This really erases the data, which will change local indices
413  // of the data. It actually just copies the data from the end of the
414  // storage into the selected block
415  // Boolean flag indicates whether to use optimized destroy method
416  virtual void destroy(size_t M, size_t I, bool optDestroy=true);
417 
418  // This version takes a list of particle destroy events
419  // Boolean flag indicates whether to use optimized destroy method
420  virtual void destroy(const std::vector< std::pair<size_t,size_t> >& dlist,
421  bool optDestroy=true);
422 
423  // puts M particle's data starting from index I into a Message.
424  // Return the number of particles put into the message.
425  virtual size_t putMessage(Message&, size_t, size_t);
426 
427  // Another version of putMessage, which takes list of indices
428  // Return the number of particles put into the message.
429  virtual size_t putMessage(Message&, const std::vector<size_t>&);
430 
431  // Get data out of a Message containing N particle's attribute data,
432  // and store it here. Data is appended to the end of the list. Return
433  // the number of particles retrieved.
434  virtual size_t getMessage(Message&, size_t);
435 
436  //
437  // methods used to manipulate the ghost particle data
438  //
439 
440  // Delete the ghost attrib storage for M particles, starting at pos I.
441  // Items from the end of the list are moved up to fill in the space.
442  // Return the number of items actually destroyed.
443  virtual size_t ghostDestroy(size_t, size_t);/* {
444  return 0;
445  }*/
446  virtual void ghostCreate(size_t);/*
447  {
448 
449  }*/
450  // puts M particle's data starting from index I into a Message.
451  // Return the number of particles put into the message. This is for
452  // when particles are being swapped to build ghost particle interaction
453  // lists.
454  virtual size_t ghostPutMessage(Message&, size_t, size_t);/* {
455  return 0;
456  }*/
457  // puts data for a list of particles into a Message, for interaction lists.
458  // Return the number of particles put into the message.
459  virtual size_t ghostPutMessage(Message&, const std::vector<size_t>&);/* {
460  return 0;
461  }*/
462 
463  // Get ghost particle data from a message.
464  virtual size_t ghostGetMessage(Message&, size_t);/* {
465  return 0;
466  }*/
467 
468  //
469  // virtual methods used to sort data
470  //
471 
472  // Calculate a "sort list", which is an array of data of the same
473  // length as this attribute, with each element indicating the
474  // (local) index wherethe ith particle shoulkd go. For example,
475  // if there are four particles, and the sort-list is {3,1,0,2}, that
476  // means the particle currently with index=0 should be moved to the third
477  // position, the one with index=1 should stay where it is, etc.
478  // The optional second argument indicates if the sort should be ascending
479  // (true, the default) or descending (false).
480  virtual void calcSortList(SortList_t &slist, bool ascending = true);
481 
482  // Process a sort-list, as described for "calcSortList", to reorder
483  // the elements in this attribute. All indices in the sort list are
484  // considered "local", so they should be in the range 0 ... localnum-1.
485  // The sort-list does not have to have been calculated by calcSortList,
486  // it could be calculated by some other means, but it does have to
487  // be in the same format. Note that the routine may need to modify
488  // the sort-list temporarily, but it will return it in the same state.
489  virtual void sort(SortList_t &slist);
490 
491  //
492  // other functions
493  //
494 
495  // Print out information for debugging purposes.
496  virtual void printDebug(Inform&);
497 
498 protected:
499  // a virtual function which is called by this base class to get a
500  // specific instance of DataSourceObject based on the type of data
501  // and the connection method (the argument to the call).
502  virtual DataSourceObject *createDataSourceObject(const char *nm,
503  DataConnect *dc, int tm) {
504  return make_DataSourceObject(nm, dc, tm, *this);
505  }
506 
507  // storage for particle data
509  size_t LocalSize;
510 
511 private:
513 };
514 
515 
516 //
517 // iterator for data in a ParticleAttrib
518 //
519 //~
520 //~ template <class T>
521 //~ class ParticleAttribIterator : public PETE_Expr< ParticleAttribIterator<T> >
522 //~ {
523 //~ public:
524 //~ typedef typename ParticleAttrib<T>::ParticleList_t ParticleList_t;
525 //~
526 //~ ParticleAttribIterator() : myList(0), curr(0) { }
527 //~
528 //~ ParticleAttribIterator(ParticleList_t& pa)
529 //~ : myList(&pa), curr(&(*pa.begin())) { }
530 //~
531 //~ ParticleAttribIterator(ParticleList_t& pa, size_t offset)
532 //~ : myList(&pa), curr(&(*(pa.begin()+offset))) { }
533 //~
534 //~ ParticleAttribIterator(const ParticleAttribIterator<T>& i)
535 //~ : myList(i.myList), curr(i.curr) { }
536 //~
537 //~ // PETE interface.
538 //~ typedef ParticleAttribIterator<T> PETE_Expr_t;
539 //~ typedef T PETE_Return_t;
540 //~ PETE_Expr_t MakeExpression() const { return *this; }
541 //~ PETE_Return_t& operator*(void) const { return *curr; }
542 //~
543 //~ ParticleAttribIterator<T>& operator++(void) {
544 //~ ++curr;
545 //~ return *this;
546 //~ }
547 //~ ParticleAttribIterator<T>& at_end(void) {
548 //~ curr = &*myList->end();
549 //~ return *this;
550 //~ }
551 //~ bool operator==(const ParticleAttribIterator<T>& a) const {
552 //~ return (curr == a.curr);
553 //~ }
554 //~ bool operator!=(const ParticleAttribIterator<T>& a) const {
555 //~ return !(curr == a.curr);
556 //~ }
557 //~ const ParticleList_t& getParticleList() const { return *myList; }
558 //~ T* getP() const { return curr; }
559 //~
560 //~ private:
561 //~ ParticleList_t* myList; // ParticleList I iterate over
562 //~ T* curr; // iterator current position
563 //~ };
564 
565 
566 template <class T>
567 class ParticleAttribIterator : public PETE_Expr< ParticleAttribIterator<T> >
568 {
569 public:
571  typedef T value_type;
572  typedef std::ptrdiff_t difference_type;
573  typedef T* pointer;
574  typedef T& reference;
575  typedef std::random_access_iterator_tag iterator_category;
576 
578 
580  : attrib(pa), curr(pa->ParticleList.begin()) { }
581 
583  : attrib(pa), curr(pa->ParticleList.begin()+offset) { }
584 
586  : attrib(i.attrib), curr(i.curr) { }
587 
588  // PETE interface.
590  typedef T PETE_Return_t;
591  PETE_Expr_t MakeExpression() const { return *this; }
592  PETE_Return_t& operator*(void) const { return *curr; }
593  T* operator->() const { return getP(); }
594 
596  ++curr;
597  return *this;
598  }
599 
601  ParticleAttribIterator<T> tmp(*this);
602  ++curr;
603  return tmp;
604  }
605 
607  --curr;
608  return *this;
609  }
610 
612  ParticleAttribIterator<T> tmp(*this);
613  --curr;
614  return tmp;
615  }
616 
618  curr += n;
619  return *this;
620  }
621 
623  ParticleAttribIterator<T> tmp(*this);
624  tmp += n;
625  return tmp;
626  }
627 
629  curr -= n;
630  return *this;
631  }
632 
634  ParticleAttribIterator<T> tmp(*this);
635  tmp -= n;
636  return tmp;
637  }
638 
639  size_t operator-(const ParticleAttribIterator<T>& a) const {
640  return (curr - a.curr);
641  }
642 
644  return (*this + n);
645  }
646 
648  curr = attrib->ParticleList.begin()+attrib->LocalSize;
649  return *this;
650  }
651 
653  return (curr == a.curr);
654  }
655 
657  return !(curr == a.curr);
658  }
659 
660  bool operator<(const ParticleAttribIterator<T>& a) const {
661  return (curr < a.curr);
662  }
663 
665  return (curr <= a.curr);
666  }
667 
668  bool operator>(const ParticleAttribIterator<T>& a) const {
669  return (curr > a.curr);
670  }
671 
673  return (curr >= a.curr);
674  }
675  //const ParticleList_t& getParticleList() const { return attrib->ParticleList; }
676  size_t size() const { return attrib->LocalSize; }
677  T* getP() const { return &(*curr); }
678 
679 private:
680  ParticleAttrib<T> *attrib; // ParticleList I iterate over
681  typename ParticleList_t::iterator curr; // iterator current position
682 };
683 
684 template <class T>
686  return (a + n);
687 }
688 
689 template <class T>
690 class ParticleAttribConstIterator : public PETE_Expr< ParticleAttribConstIterator<T> >
691 {
692 public:
694  typedef T value_type;
695  typedef std::ptrdiff_t difference_type;
696  typedef T* pointer;
697  typedef T& reference;
698  typedef std::random_access_iterator_tag iterator_category;
699 
701 
703  : attrib(pa), curr(pa->ParticleList.begin()) { }
704 
706  : attrib(pa), curr(pa->ParticleList.begin()+offset) { }
707 
709  : attrib(i.attrib), curr(i.curr) { }
710 
711  // PETE interface.
713  typedef T PETE_Return_t;
714  PETE_Expr_t MakeExpression() const { return *this; }
715  const PETE_Return_t& operator*(void) const { return *curr; }
716 
717  T const * operator->() const { return getP(); }
718 
720 
721 
723  ++curr;
724  return *this;
725  }
726 
729  ++curr;
730  return tmp;
731  }
732 
734  --curr;
735  return *this;
736  }
737 
740  --curr;
741  return tmp;
742  }
743 
745  curr += n;
746  return *this;
747  }
748 
751  tmp += n;
752  return tmp;
753  }
754 
756  curr -= n;
757  return *this;
758  }
759 
762  tmp -= n;
763  return tmp;
764  }
765 
767  return (curr - a.curr);
768  }
769 
771  return (*this + n);
772  }
773 
775  curr = attrib->ParticleList.begin()+attrib->LocalSize;
776  return *this;
777  }
778 
780  return (curr == a.curr);
781  }
782 
784  return !(curr == a.curr);
785  }
786 
788  return (curr < a.curr);
789  }
790 
792  return (curr <= a.curr);
793  }
794 
796  return (curr > a.curr);
797  }
798 
800  return (curr >= a.curr);
801  }
802 
803  //const ParticleList_t& getParticleList() const { return attrib->ParticleList; }
804  size_t size() const { return attrib->LocalSize; }
805  T const * getP() const { return &(*curr); }
806 
807 private:
808  ParticleAttrib<T> const * attrib; // ParticleList I iterate over
809  typename ParticleList_t::const_iterator curr; // iterator current position
810 };
811 
812 template <class T>
814  return (a + n);
815 }
816 
817 // Global template functions for gather/scatter operations
818 
819 // scatter the data from the given attribute onto the given Field, using
820 // the given Position attribute
821 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
822 inline
824  const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop) {
825  attrib.scatter(f, pp, intop);
826 }
827 
828 // scatter the data from the given attribute onto the given Field, using
829 // the given Position attribute, and save the mesh information for reuse
830 template <class FT, unsigned Dim, class M, class C, class PT,
831  class IntOp, class CacheData>
832 inline
834  const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop,
835  ParticleAttrib<CacheData>& cache) {
836  attrib.scatter(f, pp, intop, cache);
837 }
838 
839 // scatter the data from the given attribute onto the given Field, using
840 // the precomputed mesh information
841 template <class FT, unsigned Dim, class M, class C,
842  class IntOp, class CacheData>
843 inline
845  const IntOp& intop, const ParticleAttrib<CacheData>& cache) {
846  attrib.scatter(f, intop, cache);
847 }
848 
849 // gather the data from the given Field into the given attribute, using
850 // the given Position attribute
851 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
852 inline
854  const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop) {
855  attrib.gather(f, pp, intop);
856 }
857 
858 // gather the data from the given Field into the given attribute, using
859 // the given Position attribute, and save the mesh information for reuse
860 template <class FT, unsigned Dim, class M, class C, class PT,
861  class IntOp, class CacheData>
862 inline
864  const ParticleAttrib< Vektor<PT,Dim> >& pp, const IntOp& intop,
865  ParticleAttrib<CacheData>& cache) {
866  attrib.gather(f, pp, intop, cache);
867 }
868 
869 // gather the data from the given Field into the given attribute, using
870 // the precomputed mesh information
871 template <class FT, unsigned Dim, class M, class C,
872  class CacheData, class IntOp>
873 inline
875  const IntOp& intop, const ParticleAttrib<CacheData>& cache) {
876  attrib.gather(f, intop, cache);
877 }
878 
879 // This scatter function computes the particle number density by
880 // scattering the scalar value val for each particle into the Field.
881 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
883  const IntOp& intop, FT val);
884 
885 // version which also caches mesh info
886 template <class FT, unsigned Dim, class M, class C, class PT,
887  class IntOp, class CacheData>
889  const IntOp& intop, ParticleAttrib<CacheData>& cache,
890  FT val);
891 
892 // version which uses cached mesh info
893 template <class FT, unsigned Dim, class M, class C,
894  class IntOp, class CacheData>
895 void scatter(Field<FT,Dim,M,C>& f, const IntOp& intop,
896  const ParticleAttrib<CacheData>& cache, FT val);
897 
898 // mwerks: addeded this to work around default-arg bug:
899 // This scatter function computes the particle number density by
900 // scattering the scalar value val for each particle into the Field.
901 template <class FT, unsigned Dim, class M, class C, class PT, class IntOp>
903  const IntOp& intop){
904  scatter(f, pp, intop, FT(1));
905 }
906 
907 // mwerks: addeded this to work around default-arg bug:
908 // version which also caches mesh info
909 template <class FT, unsigned Dim, class M, class C, class PT,
910  class IntOp, class CacheData>
912  const IntOp& intop, ParticleAttrib<CacheData>& cache) {
913  scatter(f, pp, intop, cache, FT(1));
914 }
915 
916 // mwerks: addeded this to work around default-arg bug:
917 // version which uses cached mesh info
918 template <class FT, unsigned Dim, class M, class C,
919  class IntOp, class CacheData>
920 inline void scatter(Field<FT,Dim,M,C>& f, const IntOp& intop,
921  const ParticleAttrib<CacheData>& cache) {
922  scatter(f, intop, cache, FT(1));
923 }
924 
926 
927 #endif // PARTICLE_ATTRIB_H
928 
929 /***************************************************************************
930  * $RCSfile: ParticleAttrib.h,v $ $Author: adelmann $
931  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:28 $
932  * IPPL_VERSION_ID: $Id: ParticleAttrib.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $
933  ***************************************************************************/
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
const unsigned Dim
DataSourceObject * make_DataSourceObject(const char *, DataConnect *, int, Field< T, Dim, M, C > &)
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
Definition: GlobalComm.hpp:55
ParticleAttribIterator< T > operator+(size_t n, const ParticleAttribIterator< T > &a)
void gather(ParticleAttrib< FT > &attrib, const Field< FT, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &intop)
void scatter(const ParticleAttrib< FT > &attrib, Field< FT, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &intop)
std::complex< double > a
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define ERRORMSG(msg)
Definition: IpplInfo.h:350
#define INCIPPLSTAT(stat)
Definition: IpplStats.h:236
std::string::iterator iterator
Definition: MSLang.h:16
Definition: Vektor.h:32
Definition: Field.h:33
void fillGuardCells(bool reallyFill=true) const
Mesh_t & get_mesh() const
Definition: Field.h:110
ParticleAttribIterator< T > iterator
ParticleAttribElem< T, 1U > operator()(unsigned)
virtual void printDebug(Inform &)
virtual DataSourceObject * createDataSourceObject(const char *nm, DataConnect *dc, int tm)
size_t size(void) const
ParticleList_t ParticleList
ParticleAttribBase::SortList_t SortList_t
SubParticleAttrib< ParticleAttrib< T >, T, Dim > operator[](const SIndex< Dim > &s) const
virtual void ghostCreate(size_t)
const ParticleAttrib< T > & operator=(const PETE_Expr< T1 > &rhs)
virtual void sort(SortList_t &slist)
const_iterator cend() const
ParticleList_t::const_reference operator[](size_t n) const
void scatter(Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &) const
virtual size_t ghostGetMessage(Message &, size_t)
std::vector< T > ParticleList_t
iterator begin()
ParticleAttrib(const ParticleAttrib< T > &pa)
const ParticleAttrib< T > & operator=(const ParticleAttrib< T > &rhs)
void gather(const Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &)
virtual size_t putMessage(Message &, size_t, size_t)
ParticleAttribConstIterator< T > const_iterator
virtual void destroy(size_t M, size_t I, bool optDestroy=true)
virtual size_t getMessage(Message &, size_t)
ParticleList_t::reference operator[](size_t n)
void scatter(Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &, ParticleAttrib< CacheData > &cache) const
const ParticleAttrib< T > & operator=(T rhs)
const_iterator PETE_Expr_t
void gather(const Field< T, Dim, M, C > &f, const IntOp &, const ParticleAttrib< CacheData > &cache)
ParticleAttribBase::SortListIndex_t SortListIndex_t
const_iterator cbegin() const
virtual size_t ghostDestroy(size_t, size_t)
void gather(const Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &, ParticleAttrib< CacheData > &cache)
virtual size_t ghostPutMessage(Message &, size_t, size_t)
virtual void create(size_t)
void scatter(Field< T, Dim, M, C > &f, const IntOp &, const ParticleAttrib< CacheData > &cache) const
iterator end()
PETE_Expr_t MakeExpression() const
virtual void calcSortList(SortList_t &slist, bool ascending=true)
void accumGuardCells()
Definition: BareField.hpp:698
bool isDirty() const
Definition: BareField.h:116
void Uncompress() const
Definition: BareField.hpp:1005
void Compress() const
Definition: BareField.hpp:991
void setGuardCells(const T &) const
Definition: BareField.hpp:616
Definition: SIndex.h:64
bool operator>(const ParticleAttribIterator< T > &a) const
PETE_Return_t & operator*(void) const
ParticleAttribIterator< T > & at_end(void)
PETE_Expr_t MakeExpression() const
ParticleAttribIterator(ParticleAttrib< T > *pa)
ParticleAttrib< T > * attrib
ParticleAttrib< T >::ParticleList_t ParticleList_t
ParticleAttribIterator< T > & operator--(void)
bool operator!=(const ParticleAttribIterator< T > &a) const
ParticleAttribIterator< T > & operator++(void)
bool operator<=(const ParticleAttribIterator< T > &a) const
ParticleAttribIterator< T > & operator-=(size_t n)
std::ptrdiff_t difference_type
ParticleAttribIterator(ParticleAttrib< T > *pa, size_t offset)
ParticleAttribIterator< T > & operator+=(size_t n)
ParticleAttribIterator< T > operator+(size_t n) const
bool operator<(const ParticleAttribIterator< T > &a) const
ParticleAttribIterator< T > operator-(size_t n) const
ParticleAttribIterator< T > operator[](size_t n) const
std::random_access_iterator_tag iterator_category
ParticleList_t::iterator curr
size_t operator-(const ParticleAttribIterator< T > &a) const
ParticleAttribIterator< T > operator++(int)
ParticleAttribIterator(const ParticleAttribIterator< T > &i)
ParticleAttribIterator< T > operator--(int)
bool operator>=(const ParticleAttribIterator< T > &a) const
bool operator==(const ParticleAttribIterator< T > &a) const
ParticleAttribIterator< T > PETE_Expr_t
size_t operator-(const ParticleAttribConstIterator< T > &a) const
ParticleAttribConstIterator< T > & operator=(const ParticleAttribConstIterator< T > &)=default
bool operator!=(const ParticleAttribConstIterator< T > &a) const
ParticleAttribConstIterator< T > & operator+=(size_t n)
ParticleAttribConstIterator< T > operator-(size_t n) const
bool operator<=(const ParticleAttribConstIterator< T > &a) const
std::random_access_iterator_tag iterator_category
const PETE_Return_t & operator*(void) const
ParticleAttribConstIterator< T > operator[](size_t n) const
bool operator<(const ParticleAttribConstIterator< T > &a) const
bool operator>=(const ParticleAttribConstIterator< T > &a) const
ParticleAttrib< T > const * attrib
ParticleAttribConstIterator(const ParticleAttrib< T > *pa, size_t offset)
ParticleList_t::const_iterator curr
ParticleAttribConstIterator< T > PETE_Expr_t
ParticleAttrib< T >::ParticleList_t ParticleList_t
ParticleAttribConstIterator< T > & operator++(void)
bool operator==(const ParticleAttribConstIterator< T > &a) const
ParticleAttribConstIterator< T > operator--(int)
bool operator>(const ParticleAttribConstIterator< T > &a) const
PETE_Expr_t MakeExpression() const
ParticleAttribConstIterator(const ParticleAttrib< T > *pa)
ParticleAttribConstIterator< T > operator+(size_t n) const
ParticleAttribConstIterator< T > & operator-=(size_t n)
ParticleAttribConstIterator< T > & operator--(void)
ParticleAttribConstIterator< T > & at_end(void)
T const * operator->() const
ParticleAttribConstIterator< T > operator++(int)
ParticleAttribConstIterator(const ParticleAttribConstIterator< T > &i)
std::vector< SortListIndex_t > SortList_t
Definition: PETE.h:77
Definition: Inform.h:42