src/Particle/ParticleAttribBase.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef PARTICLE_ATTRIB_BASE_H
00012 #define PARTICLE_ATTRIB_BASE_H
00013 
00014 /*
00015  * ParticleAttribBase - base class for all particle attribute classes.
00016  *   This class is used as the generic base class for all (templated) classes
00017  *   which represent a single attribute of a Particle.  An attribute class
00018  *   contains an array of data for N particles, and methods to operate with
00019  *   this data.
00020  *
00021  *   This base class provides virtual methods used to create and destroy
00022  *   elements of the attribute array.
00023  */
00024 
00025 // include files
00026 #include "Utility/Pstring.h"
00027 #include <stddef.h>
00028 
00029 #ifdef IPPL_STDSTL
00030 #include <vector>
00031 using std::vector;
00032 #include <utility>
00033 using std::pair;
00034 #else
00035 #include <vector.h>
00036 #include <pair.h>
00037 #endif
00038 
00039 // forward declarations
00040 class Inform;
00041 class Message;
00042 
00043 
00044 // ParticleAttribBase class definition
00045 class ParticleAttribBase {
00046 
00047 public:
00048   //
00049   // Public typedefs
00050   //
00051 
00052   // Type of storage used for "sort lists", that store indices of
00053   // where particles should be located in a sort operation.  Used with
00054   // virtual functions "calcSortList" and "sort".
00055   typedef long                    SortListIndex_t;
00056   typedef vector<SortListIndex_t> SortList_t;
00057 
00058   //
00059   // Constructors and Destructors
00060   //
00061 
00062   // constructor: just store the size of an element, in bytes.
00063   ParticleAttribBase(unsigned int size, const string &typestr)
00064     : ElementSize(size), Temporary(false), TypeString(typestr) { }
00065 
00066   // copy constructor
00067   ParticleAttribBase(const ParticleAttribBase &pa)
00068     : ElementSize(pa.ElementSize), Temporary(pa.Temporary),
00069       TypeString(pa.TypeString) { }
00070 
00071   // destructor: does nothing, this is basically an interface class.
00072   virtual ~ParticleAttribBase() { }
00073 
00074   //
00075   // accessor methods
00076   //
00077 
00078   // return the size of a single element item, in bytes
00079   unsigned int elementSize() const { return ElementSize; }
00080 
00081   // return a simple string with a description of the data type.  This is
00082   // determined using the DiscType class
00083   const string &typeString() const { return TypeString; }
00084 
00085   // make this a temporary, or a non-temporary.  Temporary attribs just
00086   // make sure they keep the proper length when create or destroy are called,
00087   // they do not do any communication
00088   void setTemporary(bool t) { Temporary = t; }
00089 
00090   // query if this is a temporary attribute
00091   bool isTemporary() const { return Temporary; }
00092 
00093   //
00094   // virtual methods used to manipulate the normal attrib data
00095   //
00096 
00097   // Create storage for M particle attributes.  The storage is uninitialized.
00098   // New items are appended to the end of the array.
00099   virtual void create(size_t M) = 0;
00100 
00101   // Delete the attribute storage for M particle attributes, starting at
00102   // the position I.  Boolean flag indicates whether to use optimized method.
00103   virtual void destroy(size_t M, size_t I, bool optDestroy) = 0;
00104   // Delete the attribute storage for a list of particle destroy events
00105   // Boolean flag indicates whether to use optimized destroy method.
00106   virtual void destroy(const vector< pair<size_t,size_t> >& dlist,
00107                        bool optDestroy) = 0;
00108 
00109   // puts M particle's data starting from index I into a Message.
00110   // Return the number of particles put into the message.
00111   virtual size_t putMessage(Message&, size_t, size_t) = 0;
00112   // puts data for a list of particles into a Message.
00113   // Return the number of particles put into the message.
00114   virtual size_t putMessage(Message&, const vector<size_t>&) = 0;
00115 
00116   // Get data out of a Message containing N particle's attribute data,
00117   // and store it here.  Data is appended to the end of the list.  Return
00118   // the number of particles retrieved.
00119   virtual size_t getMessage(Message&, size_t) = 0;
00120 
00121   //
00122   // virtual methods used to manipulate the ghost particle data
00123   //
00124 
00125   // Delete the ghost attrib storage for M particles, starting at pos I.
00126   // Items from the end of the list are moved up to fill in the space.
00127   // Return the number of items actually destroyed.
00128   virtual size_t ghostDestroy(size_t M, size_t I) = 0;
00129 
00130   // puts M particle's data starting from index I into a Message.
00131   // Return the number of particles put into the message.  This is for
00132   // when particles are being swapped to build ghost particle interaction
00133   // lists.
00134   virtual size_t ghostPutMessage(Message&, size_t, size_t) = 0;
00135   // puts data for a list of particles into a Message, for interaction lists.
00136   // Return the number of particles put into the message.
00137   virtual size_t ghostPutMessage(Message&, const vector<size_t>&) = 0;
00138 
00139   // Get ghost particle data from a message.
00140   virtual size_t ghostGetMessage(Message&, size_t) = 0;
00141 
00142   //
00143   // virtual methods used to sort data
00144   //
00145 
00146   // Calculate a "sort list", which is an array of data of the same
00147   // length as this attribute, with each element indicating the
00148   // (local) index wherethe ith particle shoulkd go.  For example, 
00149   // if there are four particles, and the sort-list is {3,1,0,2}, that
00150   // means the particle currently with index=0 should be moved to the third
00151   // position, the one with index=1 should stay where it is, etc.
00152   // The optional second argument indicates if the sort should be ascending
00153   // (true, the default) or descending (false).
00154   virtual void calcSortList(SortList_t &slist, bool ascending = true) =  0;
00155 
00156   // Process a sort-list, as described for "calcSortList", to reorder
00157   // the elements in this attribute.  All indices in the sort list are
00158   // considered "local", so they should be in the range 0 ... localnum-1.
00159   // The sort-list does not have to have been calcualted by calcSortList,
00160   // it could be calculated by some other means, but it does have to
00161   // be in the same format.  Note that the routine may need to modify
00162   // the sort-list temporarily, but it will return it in the same state.
00163   virtual void sort(SortList_t &slist) = 0;
00164 
00165   // 
00166   //
00167   // other virtual functions
00168   //
00169 
00170   // Print out information for debugging purposes.
00171   virtual void printDebug(Inform&) = 0;
00172 
00173 private:
00174   // the size, in bytes, of a single element
00175   unsigned int ElementSize;
00176 
00177   // the data type as a simple string
00178   string TypeString;
00179 
00180   // is this a temporary attribute (one that does not need to do any
00181   // communication, just keep the right length)?
00182   bool Temporary;
00183 };
00184 
00185 #endif // PARTICLE_ATTRIB_BASE_H
00186 
00187 
00188 /***************************************************************************
00189  * $RCSfile: ParticleAttribBase.h,v $   $Author: adelmann $
00190  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:28 $
00191  * IPPL_VERSION_ID: $Id: ParticleAttribBase.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $ 
00192  ***************************************************************************/

Generated on Mon Jan 16 13:23:52 2006 for IPPL by  doxygen 1.4.6