OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ParticleAttribBase.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_BASE_H
12 #define PARTICLE_ATTRIB_BASE_H
13 
14 /*
15  * ParticleAttribBase - base class for all particle attribute classes.
16  * This class is used as the generic base class for all (templated) classes
17  * which represent a single attribute of a Particle. An attribute class
18  * contains an array of data for N particles, and methods to operate with
19  * this data.
20  *
21  * This base class provides virtual methods used to create and destroy
22  * elements of the attribute array.
23  */
24 
25 // include files
26 #include <cstddef>
27 
28 #include <vector>
29 #include <utility>
30 
31 // forward declarations
32 class Inform;
33 class Message;
34 
35 
36 // ParticleAttribBase class definition
38 
39 public:
40  //
41  // Public typedefs
42  //
43 
44  // Type of storage used for "sort lists", that store indices of
45  // where particles should be located in a sort operation. Used with
46  // virtual functions "calcSortList" and "sort".
47  typedef long SortListIndex_t;
48  typedef std::vector<SortListIndex_t> SortList_t;
49 
50  //
51  // Constructors and Destructors
52  //
53 
54  // constructor: just store the size of an element, in bytes.
55  ParticleAttribBase(unsigned int size, const std::string &typestr)
56  : ElementSize(size), TypeString(typestr), Temporary(false) { }
57 
58  // copy constructor
61  Temporary(pa.Temporary) { }
62 
63  // destructor: does nothing, this is basically an interface class.
64  virtual ~ParticleAttribBase() { }
65 
66  //
67  // accessor methods
68  //
69 
70  // return the size of a single element item, in bytes
71  unsigned int elementSize() const { return ElementSize; }
72 
73  // return a simple string with a description of the data type. This is
74  // determined using the DiscType class
75  const std::string &typeString() const { return TypeString; }
76 
77  // make this a temporary, or a non-temporary. Temporary attribs just
78  // make sure they keep the proper length when create or destroy are called,
79  // they do not do any communication
80  void setTemporary(bool t) { Temporary = t; }
81 
82  // query if this is a temporary attribute
83  bool isTemporary() const { return Temporary; }
84 
85  //
86  // virtual methods used to manipulate the normal attrib data
87  //
88 
89  // Create storage for M particle attributes. The storage is uninitialized.
90  // New items are appended to the end of the array.
91  virtual void create(size_t M) = 0;
92 
93  // Delete the attribute storage for M particle attributes, starting at
94  // the position I. Boolean flag indicates whether to use optimized method.
95  virtual void destroy(size_t M, size_t I, bool optDestroy) = 0;
96  // Delete the attribute storage for a list of particle destroy events
97  // Boolean flag indicates whether to use optimized destroy method.
98  virtual void destroy(const std::vector< std::pair<size_t,size_t> >& dlist,
99  bool optDestroy) = 0;
100 
101  // puts M particle's data starting from index I into a Message.
102  // Return the number of particles put into the message.
103  virtual size_t putMessage(Message&, size_t, size_t) = 0;
104  // puts data for a list of particles into a Message.
105  // Return the number of particles put into the message.
106  virtual size_t putMessage(Message&, const std::vector<size_t>&) = 0;
107 
108  // Get data out of a Message containing N particle's attribute data,
109  // and store it here. Data is appended to the end of the list. Return
110  // the number of particles retrieved.
111  virtual size_t getMessage(Message&, size_t) = 0;
112 
113  //
114  // virtual methods used to manipulate the ghost particle data
115  //
116 
117  // Delete the ghost attrib storage for M particles, starting at pos I.
118  // Items from the end of the list are moved up to fill in the space.
119  // Return the number of items actually destroyed.
120  virtual size_t ghostDestroy(size_t M, size_t I) = 0;
121 
122  virtual void ghostCreate(size_t M) = 0;
123 
124  // puts M particle's data starting from index I into a Message.
125  // Return the number of particles put into the message. This is for
126  // when particles are being swapped to build ghost particle interaction
127  // lists.
128  virtual size_t ghostPutMessage(Message&, size_t, size_t) = 0;
129  // puts data for a list of particles into a Message, for interaction lists.
130  // Return the number of particles put into the message.
131  virtual size_t ghostPutMessage(Message&, const std::vector<size_t>&) = 0;
132 
133  // Get ghost particle data from a message.
134  virtual size_t ghostGetMessage(Message&, size_t) = 0;
135 
136  //
137  // virtual methods used to sort data
138  //
139 
140  // Calculate a "sort list", which is an array of data of the same
141  // length as this attribute, with each element indicating the
142  // (local) index wherethe ith particle shoulkd go. For example,
143  // if there are four particles, and the sort-list is {3,1,0,2}, that
144  // means the particle currently with index=0 should be moved to the third
145  // position, the one with index=1 should stay where it is, etc.
146  // The optional second argument indicates if the sort should be ascending
147  // (true, the default) or descending (false).
148  virtual void calcSortList(SortList_t &slist, bool ascending = true) = 0;
149 
150  // Process a sort-list, as described for "calcSortList", to reorder
151  // the elements in this attribute. All indices in the sort list are
152  // considered "local", so they should be in the range 0 ... localnum-1.
153  // The sort-list does not have to have been calcualted by calcSortList,
154  // it could be calculated by some other means, but it does have to
155  // be in the same format. Note that the routine may need to modify
156  // the sort-list temporarily, but it will return it in the same state.
157  virtual void sort(SortList_t &slist) = 0;
158 
159  //
160  //
161  // other virtual functions
162  //
163 
164  // Print out information for debugging purposes.
165  virtual void printDebug(Inform&) = 0;
166 
167 private:
168  // the size, in bytes, of a single element
169  unsigned int ElementSize;
170 
171  // the data type as a simple string
172  std::string TypeString;
173 
174  // is this a temporary attribute (one that does not need to do any
175  // communication, just keep the right length)?
176  bool Temporary;
177 };
178 
179 #endif // PARTICLE_ATTRIB_BASE_H
180 
181 
182 /***************************************************************************
183  * $RCSfile: ParticleAttribBase.h,v $ $Author: adelmann $
184  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:28 $
185  * IPPL_VERSION_ID: $Id: ParticleAttribBase.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $
186  ***************************************************************************/
virtual size_t getMessage(Message &, size_t)=0
virtual void ghostCreate(size_t M)=0
ParticleAttribBase(const ParticleAttribBase &pa)
virtual size_t putMessage(Message &, size_t, size_t)=0
virtual void destroy(size_t M, size_t I, bool optDestroy)=0
virtual size_t ghostPutMessage(Message &, size_t, size_t)=0
virtual void sort(SortList_t &slist)=0
std::vector< SortListIndex_t > SortList_t
ParticleAttribBase(unsigned int size, const std::string &typestr)
void setTemporary(bool t)
unsigned int elementSize() const
virtual void calcSortList(SortList_t &slist, bool ascending=true)=0
bool isTemporary() const
virtual void create(size_t M)=0
virtual size_t ghostDestroy(size_t M, size_t I)=0
virtual size_t ghostGetMessage(Message &, size_t)=0
const std::string & typeString() const
Definition: Inform.h:41
virtual void printDebug(Inform &)=0