OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
ParticleInteractAttrib.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_INTERACT_ATTRIB_H
12 #define PARTICLE_INTERACT_ATTRIB_H
13 
14 /*
15  * ParticleInteractAttrib - 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  * ParticleInteractAttrib 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  * ParticleInteractAttrib a capable expression-template participant.
29  *
30  * For some types such as Vektor, Tenzor, etc. which have multipple 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  * ParticleInteractAttribElem, which will use the () operator on each
34  * individual elem to access an item over which one can iterate and get the
35  * Nth item from each data element. For example, if we have an attribute
36  * like this:
37  * ParticleInteractAttrib< 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  * Each ParticleInteractAttrib contains a set of ghost particle attributes as
52  * well. These are stored in a separate vector container, but to users
53  * this object looks like a single array with (local + ghost) attributes total.
54  */
55 
56 // include files
58 #include "PETE/IpplExpressions.h"
59 
60 #include <vector>
61 
62 // forward declarations
63 class Inform;
64 class Message;
65 
66 // ParticleInteractAttrib class definition
67 template <class T>
69 
70 public:
72 
73  // default constructor
75 
76  // copy constructor
78  : ParticleAttrib<T>(pa), GhostList(pa.GhostList) { }
80  : ParticleAttrib<T>(pa) { }
81 
82  // destructor: delete the storage of the attribute array
84 
85  //
86  // Assignment operators
87  //
88 
89  // assign a general expression
90  template<class T1>
92  assign(*this,rhs);
93  return *this;
94  }
95 
96  // assignment of a ParticleInteractAttrib
99  if (this->size() != rhs.size()) {
100  ERRORMSG("Attempting to copy particle attributes with unequal sizes.");
101  ERRORMSG("\n" << this->size() << " != " << rhs.size() << endl);
102  }
103  assign(*this,rhs);
104  return *this;
105  }
106 
107  // assignment of a ParticleAttrib
109  if (this->size() != rhs.size()) {
110  ERRORMSG("Attempting to copy particle attributes with unequal sizes.");
111  ERRORMSG("\n" << this->size() << " != " << rhs.size() << endl);
112  }
113  assign(*this,rhs);
114  return *this;
115  }
116 
117  // assignment of a scalar
119  assign(*this,rhs);
120  return *this;
121  }
122 
123  //
124  // methods specific to ghost particle data
125  //
126 
127  // provide a new version of the [] operator; if the argument is greater
128  // than the size of our normal storage, then it refers to one of the
129  // 'ghost' particles
130  typename ParticleList_t::reference operator[](size_t n) {
131  return (n < this->size() ? this->ParticleList[n] : GhostList[n - this->size()]);
132  }
133 
134  typename ParticleList_t::const_reference operator[](size_t n) const {
135  return (n < this->size() ? this->ParticleList[n] : GhostList[n - this->size()]);
136  }
137 
138  // return the attrib data for the Nth ghost particle
139  typename ParticleList_t::reference ghostAttrib(size_t n)
140  { return GhostList[n]; }
141 
142  typename ParticleList_t::const_reference ghostAttrib(size_t n) const
143  { return GhostList[n]; }
144 
145  // puts M particle's data starting from index I into a Message.
146  // Return the number of particles put into the message.
147  virtual size_t putMessage(Message&, size_t, size_t);
148 
149  // Another version of putMessage, which takes list of indices
150  // Return the number of particles put into the message.
151  virtual size_t putMessage(Message& m, const std::vector<size_t>& v) {
152  return ParticleAttrib<T>::putMessage(m, v);
153  }
154 
155  //
156  // methods used to manipulate the ghost particle data
157  //
158 
159  // Delete the ghost attrib storage for M particles, starting at pos I.
160  // Items from the end of the list are moved up to fill in the space.
161  // Return the number of items actually destroyed.
162  virtual size_t ghostDestroy(size_t M, size_t I);
163 
164  // puts M particle's data starting from index I into a Message.
165  // Return the number of particles put into the message. This is for
166  // when particles are being swapped to build ghost particle interaction
167  // lists.
168  virtual size_t ghostPutMessage(Message &msg, size_t M, size_t I) {
169  return putMessage(msg, M, I);
170  }
171  // puts data for a list of particles into a Message, for interaction lists.
172  // Return the number of particles put into the message.
173  virtual size_t ghostPutMessage(Message &msg, const std::vector<size_t> &v) {
174  return putMessage(msg, v);
175  }
176 
177  // Get ghost particle data from a message.
178  virtual size_t ghostGetMessage(Message&, size_t);
179 
180  //
181  // other functions
182  //
183 
184  // Print out information for debugging purposes.
185  virtual void printDebug(Inform&);
186 
187 private:
188  // storage for 'ghost' particles, those stored on the local node which
189  // actually belong to other nodes
191 };
192 
194 
195 #endif // PARTICLE_INTERACT_ATTRIB_H
196 
197 /***************************************************************************
198  * $RCSfile: ParticleInteractAttrib.h,v $ $Author: adelmann $
199  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:29 $
200  * IPPL_VERSION_ID: $Id: ParticleInteractAttrib.h,v 1.1.1.1 2003/01/23 07:40:29 adelmann Exp $
201  ***************************************************************************/
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define ERRORMSG(msg)
Definition: IpplInfo.h:350
size_t size(void) const
ParticleList_t ParticleList
std::vector< T > ParticleList_t
virtual size_t putMessage(Message &, size_t, size_t)
virtual size_t ghostPutMessage(Message &msg, size_t M, size_t I)
virtual size_t putMessage(Message &m, const std::vector< size_t > &v)
const ParticleInteractAttrib< T > & operator=(const ParticleInteractAttrib< T > &rhs)
const ParticleInteractAttrib< T > & operator=(const ParticleAttrib< T > &rhs)
virtual size_t ghostGetMessage(Message &, size_t)
virtual size_t ghostDestroy(size_t M, size_t I)
ParticleInteractAttrib(const ParticleAttrib< T > &pa)
virtual void printDebug(Inform &)
ParticleList_t::const_reference ghostAttrib(size_t n) const
virtual size_t putMessage(Message &, size_t, size_t)
ParticleList_t::const_reference operator[](size_t n) const
ParticleAttrib< T >::ParticleList_t ParticleList_t
const ParticleInteractAttrib< T > & operator=(const PETE_Expr< T1 > &rhs)
ParticleInteractAttrib(const ParticleInteractAttrib< T > &pa)
ParticleList_t::reference ghostAttrib(size_t n)
virtual size_t ghostPutMessage(Message &msg, const std::vector< size_t > &v)
const ParticleInteractAttrib< T > & operator=(T rhs)
ParticleList_t::reference operator[](size_t n)
Definition: PETE.h:77
Definition: Inform.h:42