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_LAYOUT_H 00012 #define PARTICLE_LAYOUT_H 00013 00014 /* 00015 * ParticleLayout - base class for all particle layout classes. 00016 * 00017 * This class is used as the generic base class for all classes 00018 * which maintain the information on where all the particles are located 00019 * on a parallel machine. It is responsible for performing particle 00020 * swapping and load balancing, and for determining pair lists. 00021 * 00022 * If more general layout information is needed, such as the global -> local 00023 * mapping for each particle, then derived classes must provide this info. 00024 * 00025 * When particles are created or destroyed, this class is also responsible 00026 * for determining where particles are to be created, gathering this 00027 * information, and recalculating the global indices of all the particles. 00028 * For consistency, creation and destruction requests are cached, and then 00029 * performed all in one step when the update routine is called. 00030 * 00031 * Derived classes must provide the following: 00032 * 1) Specific version of update and loadBalance. These are not virtual, 00033 * as this class is used as a template parameter (instead of being 00034 * assigned to a base class pointer). 00035 * 2) Internal storage to maintain their specific layout mechanism 00036 * 3) the definition of a class pair_iterator, and a function 00037 * void getPairlist(int, pair_iterator&, pair_iterator&) to get a 00038 * begin/end iterator pair to access the local neighbor of the Nth 00039 * local atom. This is not a virtual function, it is a requirement of 00040 * the templated class for use in other parts of the code. 00041 */ 00042 00043 // include files 00044 #include "Particle/ParticleBConds.h" 00045 00046 00047 // forward declarations 00048 template<class T, unsigned Dim> class Vektor; 00049 00050 00051 // ParticleLayout class definition. Template parameters are the type 00052 // and dimension of the ParticlePos object used for the particles. 00053 template<class T, unsigned Dim> 00054 class ParticleLayout { 00055 00056 public: 00057 // useful enumerations 00058 enum { Dimension = Dim }; // dim of coord data 00059 enum UpdateFlags { SWAP, BCONDS, NUMFLAGS, OPTDESTROY, ALL }; // update opts 00060 00061 // useful typedefs common to all layouts 00062 typedef T Position_t; 00063 typedef unsigned Index_t; 00064 typedef Vektor<T,Dim> SingleParticlePos_t; 00065 00066 // in addition, all subclasses must provide a typedef or class definition 00067 // for a type 'pair_iterator', which iterates over lists of 'pair_t' objs, 00068 // and typedefs for the ParticlePos_t and ParticleIndex_t types. 00069 00070 public: 00071 // constructor and destructor: no arguments 00072 ParticleLayout(); 00073 ~ParticleLayout() { } 00074 00075 // set the flags used to indicate what to do during the update 00076 void setUpdateFlag(UpdateFlags f, bool val) { 00077 if (f == ALL) { 00078 UpdateOptions = (~0); 00079 } else { 00080 unsigned int mask = (1 << f); 00081 UpdateOptions = (val ? (UpdateOptions|mask) : (UpdateOptions&(~mask))); 00082 } 00083 } 00084 00085 // get the flags used to indicate what to do during the update 00086 bool getUpdateFlag(UpdateFlags f) const { 00087 return (f==ALL ? (UpdateOptions==(~0)) : ((UpdateOptions & (1 << f))!=0)); 00088 } 00089 00090 // get the boundary conditions container 00091 ParticleBConds<T,Dim>& getBConds() { return BoundConds; } 00092 00093 // copy over the given boundary conditions 00094 void setBConds(const ParticleBConds<T,Dim>& bc) { BoundConds = bc; } 00095 00096 protected: 00097 // apply the given boundary conditions to the given set of n particle 00098 // positions. This modifies the position values based on the BC type. 00099 //mwerks template<class PPT, class NDI> 00100 //mwerks void apply_bconds(unsigned, PPT&, const ParticleBConds<T,Dim>&, const NDI&); 00102 // Apply the given boundary conditions to the current particle positions. 00103 // PPT is the type of particle position attribute container, and NDI is 00104 // the type of index object (NDIndex or NDRegion) 00105 template<class PPT, class NDI> 00106 void apply_bconds(unsigned n, PPT& R, 00107 const ParticleBConds<T,Dim>& bcs, 00108 const NDI& nr) { 00109 TAU_TYPE_STRING(taustr, "void (unsigned, " + CT(R) + ", " 00110 + CT(bcs) + ", " + CT(nr) + " )"); 00111 TAU_PROFILE("ParticleLayout::apply_bconds()", taustr, 00112 TAU_PARTICLE | TAU_ASSIGN); 00113 00114 // apply boundary conditions to the positions 00115 for (int i=0; i < n; ++i) 00116 for (int j=0; j < Dim; j++) 00117 R[i][j] = bcs.apply(R[i][j], j, nr); 00118 } 00119 00120 private: 00121 // the list of boundary conditions for this set of particles 00122 ParticleBConds<T,Dim> BoundConds; 00123 00124 // flags indicating what should be updated 00125 unsigned int UpdateOptions; 00126 }; 00127 00128 #include "Particle/ParticleLayout.cpp" 00129 00130 #endif // PARTICLE_LAYOUT_H 00131 00132 /*************************************************************************** 00133 * $RCSfile: ParticleLayout.h,v $ $Author: adelmann $ 00134 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:29 $ 00135 * IPPL_VERSION_ID: $Id: ParticleLayout.h,v 1.1.1.1 2003/01/23 07:40:29 adelmann Exp $ 00136 ***************************************************************************/