OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ParticleCashedLayout.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_CASHED_LAYOUT_H
12 #define PARTICLE_CASHED_LAYOUT_H
13 
14 /*
15  * ParticleCashedLayout - 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 ParticleCashedLayout;
42 template <class T, unsigned Dim, class Mesh>
43 std::ostream& operator<<(std::ostream&, const ParticleCashedLayout<T,Dim,Mesh>&);
44 
45 
46 // ParticleCashedLayout 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 ParticleCashedLayout : public ParticleSpatialLayout<T, Dim, Mesh> {
53 
54 public:
55 
59 
60  // type of attributes this layout should use for position, ID, and rad
64 
65 public:
66  // constructor: The Field layout to which we match our particle's
67  // locations.
69 
70  // constructor: this one also takes a Mesh
72 
73  // a similar constructor, but this one takes a RegionLayout.
75 
76  // a default constructor ... in this case, no layout will
77  // be assumed by this class. A layout may be given later via the
78  // 'setLayout' method, either as a FieldLayout or as a RegionLayout.
80 
81  // destructor
83 
84  //
85  // Particle swapping/update routines
86  //
87 
88  // Update the location and indices of all atoms in the given IpplParticleBase
89  // object. This handles swapping particles among processors if
90  // needed, and handles create and destroy requests. When complete,
91  // all nodes have correct layout information.
93  const ParticleAttrib<char>* canSwap=0);
94 
95 
96  // Retrieve a Forward-style iterator for the beginning and end of the
97  // Nth (local) particle's nearest-neighbor pairlist.
98  // If this is the first call of this
99  // method after update(), this must make sure up-to-date info on particles
100  // from neighboring nodes is available.
102 
103  // specify the interaction radius ... two versions, one which gives a
104  // single value for all atoms
105  void setInteractionRadius(const T& r) {
106  InterRadius = r;
107  return;
108  }
109 
110  // Return the maximum interaction radius of the entire system. This is
111  // the value from the most recent call to update()
113 
114  // Return the interaction radius of atom i.
115  T getInteractionRadius(unsigned i) {
116  return InterRadius;
117  }
118 
119  // directly set NeedGhostSwap flag to indicate whether this is needed
120  // useful when a ParticleAttrib other than position R is modified and
121  // we do not need to call update().
122  void setNeedGhostSwap(bool cond=true) {
123  NeedGhostSwap = cond;
124  }
125 
126  //
127  // virtual functions for FieldLayoutUser's (and other UserList users)
128  //
129 
130  // Repartition onto a new layout
131  virtual void Repartition(UserList *);
132 
133 private:
134  // information needed to compute which ghost particles to send/receive
139 
140  // interaction radius data. If the attribute pointer is null, use the
141  // scalar value instead.
142  // also, the maximum interaction radius for the local particles, and for all
143  // the particles
145 
146  // perform common constructor tasks
147  void setup();
148 
149  // recalculate where we need to send ghost particles for building
150  // nearest-neighbor interaction lists
152 
153  // recalculate where we need to send ghost particles for building
154  // nearest-neighbor interaction lists
155  // special version which accounts for periodic boundary conditions
156  void rebuild_interaction_data(const bool periodicBC[2*Dim]);
157 
158  // copy particles to other nodes for pairlist computation. The arguments
159  // are the current number of local particles, and the IpplParticleBase object.
160  // This will also calculate the pairlists if necessary.
161  void swap_ghost_particles(unsigned,
163 
164  // copy particles to other nodes for pairlist computation. The arguments
165  // are the current number of local particles, and the IpplParticleBase object.
166  // This will also calculate the pairlists if necessary.
167  // special version to take account of periodic boundaries
168  void swap_ghost_particles(unsigned,
170  const bool periodicBC[2*Dim]);
171 
172  // change the value of the maximum local interaction radius
173  void setMaxInteractionRadius(T maxval) { MaxGlobalInterRadius = maxval; }
174 
175  // Return the maximum interaction radius of the local particles.
177 };
178 
180 
181 #endif // PARTICLE_CASHED_LAYOUT_H
182 
183 /***************************************************************************
184  * $RCSfile: ParticleCashedLayout.h,v $ $Author: adelmann $
185  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:29 $
186  * IPPL_VERSION_ID: $Id: ParticleCashedLayout.h,v 1.1.1.1 2003/01/23 07:40:29 adelmann Exp $
187  ***************************************************************************/
void update(IpplParticleBase< ParticleCashedLayout< T, Dim, Mesh > > &p, const ParticleAttrib< char > *canSwap=0)
void setNeedGhostSwap(bool cond=true)
Definition: Mesh.h:35
T getInteractionRadius(unsigned i)
Definition: rbendmap.h:8
void setMaxInteractionRadius(T maxval)
ParticleInteractAttrib< SingleParticlePos_t > ParticlePos_t
ParticleLayout< T, Dim >::SingleParticlePos_t SingleParticlePos_t
unsigned Index_t
ParticleInteractAttrib< T > ParticleInterRadius_t
ParticleInteractAttrib< Index_t > ParticleIndex_t
virtual void Repartition(UserList *)
ParticleLayout< T, Dim >::Index_t Index_t
void swap_ghost_particles(unsigned, IpplParticleBase< ParticleCashedLayout< T, Dim, Mesh > > &)
const unsigned Dim
void getCashedParticles(IpplParticleBase< ParticleCashedLayout< T, Dim, Mesh > > &)
void setInteractionRadius(const T &r)