OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
ParticleInteractLayout.h
Go to the documentation of this file.
1 //
2 // Class ParticleInteractLayout
3 // Please note: for the time being this class is *not* used! But since it
4 // might be used in future projects, we keep this file.
5 //
6 // Copyright (c) 2003 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
7 // All rights reserved
8 //
9 // This file is part of OPAL.
10 //
11 // OPAL is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18 //
19 
20 #ifndef PARTICLE_INTERACT_LAYOUT_H
21 #define PARTICLE_INTERACT_LAYOUT_H
22 
23 /*
24  * ParticleInteractLayout - particle layout based on spatial decomposition,
25  * with particle interaction (nearest-neighbor with cutoff)
26  *
27  * This is a specialized version of ParticleLayout, which places particles
28  * on processors based on their spatial location relative to a fixed grid.
29  * In particular, this can maintain particles on processors based on a
30  * specified FieldLayout or RegionLayout, so that particles are always on
31  * the same node as the node containing the Field region to which they are
32  * local. This may also be used if there is no associated Field at all,
33  * in which case a grid is selected based on an even distribution of
34  * particles among processors.
35  */
36 
37 // include files
41 #include "Region/RegionLayout.h"
42 
43 #include <vector>
44 #include <iostream>
45 
46 // forward declarations
47 class UserList;
48 template <unsigned Dim> class FieldLayout;
49 template <unsigned Dim, class T> class UniformCartesian;
50 template <class T, unsigned Dim, class Mesh> class ParticleInteractLayout;
51 template <class T, unsigned Dim, class Mesh>
52 std::ostream& operator<<(std::ostream&, const ParticleInteractLayout<T,Dim,Mesh>&);
53 
54 
55 // ParticleInteractLayout class definition. Template parameters are the type
56 // and dimension of the ParticlePos object used for the particles. The
57 // dimension of the position must match the dimension of the FieldLayout
58 // object used in this particle layout, if any.
59 // Optional template parameter for the mesh type
60 template < class T, unsigned Dim, class Mesh=UniformCartesian<Dim,T> >
61 class ParticleInteractLayout : public ParticleSpatialLayout<T, Dim, Mesh> {
62 
63 public:
64  // a struct which holds data for a single pairwise interaction
65  struct pair_t {
66  unsigned first; // index of 2nd member of pair
67  T second; // separation of particles
68  pair_t(unsigned f, T s) : first(f), second(s) { }
69  pair_t() { }
70  };
71 
72  // type of iterator over pairs
74 
78 
79  // type of attributes this layout should use for position, ID, and rad
83 
84 public:
85  // constructor: The Field layout to which we match our particle's
86  // locations.
88 
89  // constructor: this one also takes a Mesh
91 
92  // a similar constructor, but this one takes a RegionLayout.
94 
95  // a default constructor ... in this case, no layout will
96  // be assumed by this class. A layout may be given later via the
97  // 'setLayout' method, either as a FieldLayout or as a RegionLayout.
99 
100  // destructor
102 
103  //
104  // Particle swapping/update routines
105  //
106 
107  // Update the location and indices of all atoms in the given IpplParticleBase
108  // object. This handles swapping particles among processors if
109  // needed, and handles create and destroy requests. When complete,
110  // all nodes have correct layout information.
112  const ParticleAttrib<char>* canSwap=0);
113 
114  //
115  // Nearest-neighbor interaction calculation routines
116  //
117 
118  // Retrieve a Forward-style iterator for the beginning and end of the
119  // Nth (local) particle's nearest-neighbor pairlist.
120  // If this is the first call of this
121  // method after update(), this must make sure up-to-date info on particles
122  // from neighboring nodes is available.
123  void getPairlist(unsigned, pair_iterator&, pair_iterator&,
125 
126  // specify the interaction radius ... two versions, one which gives a
127  // single value for all atoms, the other giving a ParticleAttrib<T>
128  // object with interaction radii for all the atoms in this object
129  void setInteractionRadius(const T& r) {
130  InterRadius = r;
131  InterRadiusArray = 0;
132  return;
133  }
135  InterRadiusArray = &rAttrib;
136  return;
137  }
138 
139  // Return the maximum interaction radius of the entire system. This is
140  // the value from the most recent call to update()
142 
143  // Return the interaction radius of atom i.
144  T getInteractionRadius(unsigned i) {
145  return (InterRadiusArray != 0 ? (*InterRadiusArray)[i] : InterRadius);
146  }
147 
148  // directly set NeedGhostSwap flag to indicate whether this is needed
149  // useful when a ParticleAttrib other than position R is modified and
150  // we do not need to call update().
151  void setNeedGhostSwap(bool cond=true) {
152  NeedGhostSwap = cond;
153  }
154 
155  //
156  // virtual functions for FieldLayoutUser's (and other UserList users)
157  //
158 
159  // Repartition onto a new layout
160  virtual void Repartition(UserList *);
161 
162 private:
163  // information needed to compute which ghost particles to send/receive
168 
169  // pairlist storage - a set of vectors
170  std::vector< std::vector<pair_t>* > PairList;
171 
172  // interaction radius data. If the attribute pointer is null, use the
173  // scalar value instead.
174  // also, the maximum interaction radius for the local particles, and for all
175  // the particles
178 
179  // perform common constructor tasks
180  void setup();
181 
182  // recalculate where we need to send ghost particles for building
183  // nearest-neighbor interaction lists
185 
186  // recalculate where we need to send ghost particles for building
187  // nearest-neighbor interaction lists
188  // special version which accounts for periodic boundary conditions
189  void rebuild_interaction_data(const bool periodicBC[2*Dim]);
190 
191  // copy particles to other nodes for pairlist computation. The arguments
192  // are the current number of local particles, and the IpplParticleBase object.
193  // This will also calculate the pairlists if necessary.
194  void swap_ghost_particles(unsigned,
196 
197  // copy particles to other nodes for pairlist computation. The arguments
198  // are the current number of local particles, and the IpplParticleBase object.
199  // This will also calculate the pairlists if necessary.
200  // special version to take account of periodic boundaries
201  void swap_ghost_particles(unsigned,
203  const bool periodicBC[2*Dim]);
204 
205  // find the pairs between our local particles and particles a1 ... (a2 - 1).
206  // if the last argument is true, initialize all the pairlists to be empty.
207  void find_pairs(const unsigned LocalNum, const unsigned a1,
208  const unsigned a2, const bool initLists,
210 
211  // change the value of the maximum local interaction radius
212  void setMaxInteractionRadius(T maxval) { MaxGlobalInterRadius = maxval; }
213 
214  // Return the maximum interaction radius of the local particles.
216 };
217 
219 
220 #endif
const unsigned Dim
std::ostream & operator<<(std::ostream &, const ParticleInteractLayout< T, Dim, Mesh > &)
std::string::iterator iterator
Definition: MSLang.h:16
Definition: Mesh.h:35
void find_pairs(const unsigned LocalNum, const unsigned a1, const unsigned a2, const bool initLists, IpplParticleBase< ParticleInteractLayout< T, Dim, Mesh > > &PData)
void setInteractionRadius(const T &r)
void setInteractionRadius(ParticleInterRadius_t &rAttrib)
std::vector< std::vector< pair_t > * > PairList
ParticleInteractAttrib< T > ParticleInterRadius_t
void setMaxInteractionRadius(T maxval)
void setNeedGhostSwap(bool cond=true)
virtual void Repartition(UserList *)
ParticleLayout< T, Dim >::SingleParticlePos_t SingleParticlePos_t
ParticleInterRadius_t * InterRadiusArray
void update(IpplParticleBase< ParticleInteractLayout< T, Dim, Mesh > > &p, const ParticleAttrib< char > *canSwap=0)
void swap_ghost_particles(unsigned, IpplParticleBase< ParticleInteractLayout< T, Dim, Mesh > > &)
ParticleInteractAttrib< SingleParticlePos_t > ParticlePos_t
std::vector< pair_t >::iterator pair_iterator
ParticleLayout< T, Dim >::Index_t Index_t
void getPairlist(unsigned, pair_iterator &, pair_iterator &, IpplParticleBase< ParticleInteractLayout< T, Dim, Mesh > > &)
ParticleInteractAttrib< Index_t > ParticleIndex_t
unsigned Index_t