OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ParticleInteractLayout.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_LAYOUT_H
12 #define PARTICLE_INTERACT_LAYOUT_H
13 
14 /*
15  * ParticleInteractLayout - particle layout based on spatial decomposition,
16  * with particle interaction (nearest-neighbor with cutoff)
17  *
18  * This is a specialized version of ParticleLayout, which places particles
19  * on processors based on their spatial location relative to a fixed grid.
20  * In particular, this can maintain particles on processors based on a
21  * specified FieldLayout or RegionLayout, so that particles are always on
22  * the same node as the node containing the Field region to which they are
23  * local. This may also be used if there is no associated Field at all,
24  * in which case a grid is selected based on an even distribution of
25  * particles among processors.
26  */
27 
28 // include files
32 #include "Region/RegionLayout.h"
33 
34 #include <vector>
35 #include <iostream>
36 
37 // forward declarations
38 class UserList;
39 template <unsigned Dim> class FieldLayout;
40 template <unsigned Dim, class T> class UniformCartesian;
41 template <class T, unsigned Dim, class Mesh> class ParticleInteractLayout;
42 template <class T, unsigned Dim, class Mesh>
43 std::ostream& operator<<(std::ostream&, const ParticleInteractLayout<T,Dim,Mesh>&);
44 
45 
46 // ParticleInteractLayout class definition. Template parameters are the type
47 // and dimension of the ParticlePos object used for the particles. The
48 // dimension of the position must match the dimension of the FieldLayout
49 // object used in this particle layout, if any.
50 // Optional template parameter for the mesh type
51 template < class T, unsigned Dim, class Mesh=UniformCartesian<Dim,T> >
52 class ParticleInteractLayout : public ParticleSpatialLayout<T, Dim, Mesh> {
53 
54 public:
55  // a struct which holds data for a single pairwise interaction
56  struct pair_t {
57  unsigned first; // index of 2nd member of pair
58  T second; // separation of particles
59  pair_t(unsigned f, T s) : first(f), second(s) { }
60  pair_t() { }
61  };
62 
63  // type of iterator over pairs
65 
69 
70  // type of attributes this layout should use for position, ID, and rad
74 
75 public:
76  // constructor: The Field layout to which we match our particle's
77  // locations.
79 
80  // constructor: this one also takes a Mesh
82 
83  // a similar constructor, but this one takes a RegionLayout.
85 
86  // a default constructor ... in this case, no layout will
87  // be assumed by this class. A layout may be given later via the
88  // 'setLayout' method, either as a FieldLayout or as a RegionLayout.
90 
91  // destructor
93 
94  //
95  // Particle swapping/update routines
96  //
97 
98  // Update the location and indices of all atoms in the given IpplParticleBase
99  // object. This handles swapping particles among processors if
100  // needed, and handles create and destroy requests. When complete,
101  // all nodes have correct layout information.
103  const ParticleAttrib<char>* canSwap=0);
104 
105  //
106  // Nearest-neighbor interaction calculation routines
107  //
108 
109  // Retrieve a Forward-style iterator for the beginning and end of the
110  // Nth (local) particle's nearest-neighbor pairlist.
111  // If this is the first call of this
112  // method after update(), this must make sure up-to-date info on particles
113  // from neighboring nodes is available.
114  void getPairlist(unsigned, pair_iterator&, pair_iterator&,
116 
117  // specify the interaction radius ... two versions, one which gives a
118  // single value for all atoms, the other giving a ParticleAttrib<T>
119  // object with interaction radii for all the atoms in this object
120  void setInteractionRadius(const T& r) {
121  InterRadius = r;
122  InterRadiusArray = 0;
123  return;
124  }
126  InterRadiusArray = &rAttrib;
127  return;
128  }
129 
130  // Return the maximum interaction radius of the entire system. This is
131  // the value from the most recent call to update()
133 
134  // Return the interaction radius of atom i.
135  T getInteractionRadius(unsigned i) {
136  return (InterRadiusArray != 0 ? (*InterRadiusArray)[i] : InterRadius);
137  }
138 
139  // directly set NeedGhostSwap flag to indicate whether this is needed
140  // useful when a ParticleAttrib other than position R is modified and
141  // we do not need to call update().
142  void setNeedGhostSwap(bool cond=true) {
143  NeedGhostSwap = cond;
144  }
145 
146  //
147  // virtual functions for FieldLayoutUser's (and other UserList users)
148  //
149 
150  // Repartition onto a new layout
151  virtual void Repartition(UserList *);
152 
153 private:
154  // information needed to compute which ghost particles to send/receive
159 
160  // pairlist storage - a set of vectors
161  std::vector< std::vector<pair_t>* > PairList;
162 
163  // interaction radius data. If the attribute pointer is null, use the
164  // scalar value instead.
165  // also, the maximum interaction radius for the local particles, and for all
166  // the particles
169 
170  // perform common constructor tasks
171  void setup();
172 
173  // recalculate where we need to send ghost particles for building
174  // nearest-neighbor interaction lists
176 
177  // recalculate where we need to send ghost particles for building
178  // nearest-neighbor interaction lists
179  // special version which accounts for periodic boundary conditions
180  void rebuild_interaction_data(const bool periodicBC[2*Dim]);
181 
182  // copy particles to other nodes for pairlist computation. The arguments
183  // are the current number of local particles, and the IpplParticleBase object.
184  // This will also calculate the pairlists if necessary.
185  void swap_ghost_particles(unsigned,
187 
188  // copy particles to other nodes for pairlist computation. The arguments
189  // are the current number of local particles, and the IpplParticleBase object.
190  // This will also calculate the pairlists if necessary.
191  // special version to take account of periodic boundaries
192  void swap_ghost_particles(unsigned,
194  const bool periodicBC[2*Dim]);
195 
196  // find the pairs between our local particles and particles a1 ... (a2 - 1).
197  // if the last argument is true, initialize all the pairlists to be empty.
198  void find_pairs(const unsigned LocalNum, const unsigned a1,
199  const unsigned a2, const bool initLists,
201 
202  // change the value of the maximum local interaction radius
203  void setMaxInteractionRadius(T maxval) { MaxGlobalInterRadius = maxval; }
204 
205  // Return the maximum interaction radius of the local particles.
207 };
208 
210 
211 #endif // PARTICLE_INTERACT_LAYOUT_H
212 
213 /***************************************************************************
214  * $RCSfile: ParticleInteractLayout.h,v $ $Author: adelmann $
215  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:29 $
216  * IPPL_VERSION_ID: $Id: ParticleInteractLayout.h,v 1.1.1.1 2003/01/23 07:40:29 adelmann Exp $
217  ***************************************************************************/
Definition: Mesh.h:35
void swap_ghost_particles(unsigned, IpplParticleBase< ParticleInteractLayout< T, Dim, Mesh > > &)
Definition: rbendmap.h:8
ParticleInteractAttrib< T > ParticleInterRadius_t
ParticleInteractAttrib< Index_t > ParticleIndex_t
void setInteractionRadius(ParticleInterRadius_t &rAttrib)
unsigned Index_t
virtual void Repartition(UserList *)
ParticleLayout< T, Dim >::Index_t Index_t
void update(IpplParticleBase< ParticleInteractLayout< T, Dim, Mesh > > &p, const ParticleAttrib< char > *canSwap=0)
void setMaxInteractionRadius(T maxval)
ParticleInterRadius_t * InterRadiusArray
ParticleInteractAttrib< SingleParticlePos_t > ParticlePos_t
ParticleLayout< T, Dim >::SingleParticlePos_t SingleParticlePos_t
void setNeedGhostSwap(bool cond=true)
std::vector< pair_t >::iterator pair_iterator
void getPairlist(unsigned, pair_iterator &, pair_iterator &, IpplParticleBase< ParticleInteractLayout< T, Dim, Mesh > > &)
void setInteractionRadius(const T &r)
std::string::iterator iterator
Definition: MSLang.h:16
const unsigned Dim
void find_pairs(const unsigned LocalNum, const unsigned a1, const unsigned a2, const bool initLists, IpplParticleBase< ParticleInteractLayout< T, Dim, Mesh > > &PData)
std::vector< std::vector< pair_t > * > PairList