Chombo + EB + MF  3.2
ParticleData.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _PARTICLEDATA_H_
12 #define _PARTICLEDATA_H_
13 
14 #include <map>
15 using std::map;
16 
17 #include "BaseFab.H"
18 #include "RealVect.H"
19 #include "List.H"
20 #include "Box.H"
21 #include "LevelData.H"
22 #include "ListBox.H"
23 #include "ListBoxFactory.H"
24 #include "NamespaceHeader.H"
25 
26 struct boxids
27 {
28  boxids(const unsigned id, const unsigned pi)
29  : idx(id), pid(pi) {}
30 
31  boxids(const boxids& bi)
32  : idx(bi.idx), pid(bi.pid) {}
33 
35  : idx(0), pid(0) {}
36 
37  void operator=(const boxids& bi)
38  {
39  idx=bi.idx;
40  pid=bi.pid;
41  }
42  unsigned idx;
43  unsigned pid;
44 };
45 
46 /// compute the cell index containing the physical position of the item
47 inline IntVect locateBin(const RealVect a_x, const RealVect a_dx, const RealVect a_origin)
48 {
49  CH_TIME("locateBin");
50  const IntVect bin(D_DECL6((int)floor((a_x[0] - a_origin[0])/a_dx[0]),
51  (int)floor((a_x[1] - a_origin[1])/a_dx[1]),
52  (int)floor((a_x[2] - a_origin[2])/a_dx[2]),
53  (int)floor((a_x[3] - a_origin[3])/a_dx[3]),
54  (int)floor((a_x[4] - a_origin[4])/a_dx[4]),
55  (int)floor((a_x[5] - a_origin[5])/a_dx[5])));
56  return bin;
57 }
58 
59 ///
60 /** This is a class for holding and sorting particle items. Class <T>
61  must have a \p RealVect \b <T>::position() const function which is
62  used to assign the item in a list. See class \p BinItem for a
63  base class for particles.
64 */
65 ///
66 template<class P>
67 class ParticleData : public LayoutData< ListBox<P> >
68 {
69 public:
70 
71  /// Weak Constructor
72  ParticleData();
73 
74  /// Full Constructor. Arguments:
75  ///
76  /// a_dp: The BoxLayout on which the particle data will be defined.
77  /// Note that this *must* be a 'fixed size' layout.
78  /// a_fixedBoxSize: The (fixed) box size in cells.
79  /// a_domain: the problem domain, used for enforcing periodic boundary conditions.
80  /// a_meshSpacing: the physical mesh spacing, used for binning the particles.
81  /// a_origin: the origin of the coordinate system, also for particle binning.
82  ParticleData(const BoxLayout& a_dp,
83  const ProblemDomain& a_domain,
84  const int& a_fixedBoxSize,
85  const RealVect& a_meshSpacing,
86  const RealVect& a_origin);
87 
88  /// Define function. Same as the full constructor
89  void define(const BoxLayout& a_dp,
90  const ProblemDomain& a_domain,
91  const int& a_fixedBoxSize,
92  const RealVect& a_meshSpacing,
93  const RealVect& a_origin);
94 
95  /// Get the BoxLayout on which this ParticleData<P> is defined.
96  const BoxLayout& getBoxes() const;
97 
98  /// Removes all the items from all the boxes in the container
99  void clear();
100 
101  /// Return the number of particles in the container, outcast and valid.
102  // Note that this does not do a parallel reduce operation; each process
103  /// returns the total number of particles in all the boxes it owns.
104  size_t numParticlesLocal() const;
105 
106  /// Return the number of particles in the container, outcast and valid.
107  /// This version does a parallel reduce to count all the particles on
108  /// all processes.
109  size_t numParticles() const;
110 
111  /// Return the number of valid particles in the container, not counting outcasts.
112  // Note that this does not a do parallel reduce operation; each process
113  /// returns the total number of particles in all the boxes it owns.
114  size_t numValidLocal() const;
115 
116  /// Return the number of valid particles in the container, not counting outcasts.
117  /// This version does a parallel reduce to count all the particles on
118  /// all processes.
119  size_t numValid() const;
120 
121  /// Return the number of particles in the outcast list.
122  // Note that this does not a do parallel reduce operation; each process
123  /// returns the total number of outcasts it owns.
124  size_t numOutcastLocal() const;
125 
126  /// Return the number of particles in the outcast list.
127  /// This version does a parallel reduce to count all the outcasts on
128  /// all processes.
129  size_t numOutcast() const;
130 
131  /// Return a reference to the list of "outcast" particles - a list with
132  /// particles not currently associated with any box in the container.
133  List<P>& outcast();
134 
135  /// Is this ParticleData<P> closed - i.e. is the outcast list empty?
136  bool isClosed() const;
137 
138  /// Get the physical domain associated with this ParticleData.
139  const ProblemDomain& physDomain() const;
140 
141  /// Get the mesh spacing associated with this ParticleData,
142  const RealVect& meshSpacing() const;
143 
144  /// Get the origin of the coordinate system
145  const RealVect& origin() const;
146 
147  /// Get the fixed Box size
148  const int& fixedBoxSize() const;
149 
150  /// After the particles have moved, they might not still belong in the same ListBox
151  /// they started in. This function collects all the particles that are no longer in
152  /// the right box and puts them in the outcast list.
153  void gatherOutcast();
154 
155  /// Redistribute the particles in the outcast list onto the proper
156  /// box and process.
157  void remapOutcast();
158 
159  /// Routine for filling ghost particles. This function will augment each
160  /// ListBox in a_particlesWithGhosts with copies of all the particles that
161  /// lie within a_numGhost cells of the box boundaries. If the problem domain
162  /// used to define this ParticleData is periodic, then ghost particles will be
163  /// grabbed from the opposite sides of the domain as well. Ghost particles that are
164  /// copied from accross periodic boundaries in this fashion will have their position
165  /// coordinates periodically shifted such that computing the distance between them
166  /// and the "valid" particles will return the *shortest* distance defined on the
167  /// periodic domain.
168  ///
169  /// Arguments:
170  /// a_particlesWithGhost: this is a ParticleData built on a BoxLayout like this one,
171  /// except that each box has been grown by a_numGhosts cells.
172  /// On exit, each ListBox in a_particlesWithGhost will contain
173  /// both "valid" and "ghost" particls.
174  /// a_numGhost the number of ghost cells to fill
175  void fillGhosts(ParticleData<P>& a_particlesWithGhosts,
176  const int a_numGhost) const;
177 
178  bool isDefined() const;
179 
180 private:
181 
182  void allocateVector();
183 
184  IntVect enforcePeriodic(const IntVect& a_index) const;
185 
193 };
194 
196 {
197  bool operator() (const IntVect& a, const IntVect& b) const
198  {
199  D_TERM6(
200  if (a[0]>b[0]) return true;
201  else if (a[0]<b[0]) return false;
202  ,
203  if (a[1]>b[1]) return true;
204  else if (a[1]<b[1]) return false;
205  ,
206  if (a[2]>b[2]) return true;
207  else if (a[2]<b[2]) return false;
208  ,
209  if (a[3]>b[3]) return true;
210  else if (a[3]<b[3]) return false;
211  ,
212  if (a[4]>b[4]) return true;
213  else if (a[4]<b[4]) return false;
214  ,
215  if (a[5]>b[5]) return true;
216  else if (a[5]<b[5]) return false;
217  );
218  return false;
219  }
220 };
221 
222 /// Routine for transfering particles between AMR levels. Arguments:
223 /// a_partValid: the destination to which particles will be sent if
224 /// they meet the requirements.
225 /// a_PD: the source from which the particles will be transfered.
226 /// a_mask: this defines the valid region. If a_flip is false, a
227 /// particle will be transfered from the source to the
228 /// dest if it lies in a region of the domain where the mask
229 /// is true.
230 /// a_dx: particle position will be converted to integer indices
231 /// by binning them by this cell spacing.
232 /// a_refRatio: a_mask will be copied onto a boxlayout that has been
233 /// refined or coarsened by this argument (refined if
234 /// positive, coarsened if negative.) This is to allow
235 /// comparison with mask arrays defined on arbitrary
236 /// refinement levels
237 /// a_flip if true, the sign of mask will be treated as reversed
238 /// (i.e., this becomes a collectInvalidParticles function).
239 template <class P>
240 void collectValidParticles(List<P>& a_partValid,
241  ParticleData<P>& a_PD,
242  const LevelData<BaseFab<bool> >* a_mask,
243  const RealVect a_meshSpacing,
244  const int a_refRatio,
245  const bool a_flip=false,
246  const RealVect a_origin=RealVect(D_DECL6(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
247 
248 /// overloaded version of the above
249 template <class P>
250 void collectValidParticles(ParticleData<P>& a_PDValid,
251  ParticleData<P>& a_PD,
252  const LevelData<BaseFab<bool> >* a_mask,
253  const RealVect a_meshSpacing,
254  const int a_refRatio,
255  const bool a_flip=false,
256  const RealVect a_origin=RealVect(D_DECL6(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
257 
258 
259 #include "NamespaceFooter.H"
260 
261 // Implementation
262 #include "ParticleDataI.H"
263 
264 #endif
#define D_DECL6(a, b, c, d, e, f)
Definition: CHArray.H:39
boxids()
Definition: ParticleData.H:34
void operator=(const boxids &bi)
Definition: ParticleData.H:37
IntVect locateBin(const RealVect a_x, const RealVect a_dx, const RealVect a_origin)
compute the cell index containing the physical position of the item
Definition: ParticleData.H:47
unsigned idx
Definition: ParticleData.H:42
#define D_TERM6(a, b, c, d, e, f)
Definition: CHArray.H:40
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
boxids(const unsigned id, const unsigned pi)
Definition: ParticleData.H:28
const int & fixedBoxSize() const
Get the fixed Box size.
Definition: ParticleDataI.H:372
void gatherOutcast()
Definition: ParticleDataI.H:406
size_t numParticlesLocal() const
Return the number of particles in the container, outcast and valid.
Definition: ParticleDataI.H:212
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:145
Data that maintains a one-to-one mapping of T to the boxes in a BoxLayout.
Definition: BoxLayout.H:26
void clear()
Removes all the items from all the boxes in the container.
Definition: ParticleDataI.H:199
void collectValidParticles(List< P > &a_partValid, ParticleData< P > &a_PD, const LevelData< BaseFab< bool > > *a_mask, const RealVect a_meshSpacing, const int a_refRatio, const bool a_flip=false, const RealVect a_origin=RealVect(D_DECL6(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)))
Definition: ParticleDataI.H:28
const BoxLayout & getBoxes() const
Get the BoxLayout on which this ParticleData.
Definition: ParticleDataI.H:193
void remapOutcast()
Definition: ParticleDataI.H:417
const RealVect & origin() const
Get the origin of the coordinate system.
Definition: ParticleDataI.H:366
const ProblemDomain & physDomain() const
Get the physical domain associated with this ParticleData.
Definition: ParticleDataI.H:354
boxids(const boxids &bi)
Definition: ParticleData.H:31
ProblemDomain m_physDomain
Definition: ParticleData.H:187
RealVect m_origin
Definition: ParticleData.H:189
const RealVect & meshSpacing() const
Get the mesh spacing associated with this ParticleData,.
Definition: ParticleDataI.H:360
#define CH_TIME(name)
Definition: CH_Timer.H:82
bool isDefined() const
bool m_isDefined
Definition: ParticleData.H:192
new code
Definition: BoxLayoutData.H:170
bool operator()(const IntVect &a, const IntVect &b) const
Definition: ParticleData.H:197
List< P > m_outcast
Definition: ParticleData.H:186
Definition: ParticleData.H:195
size_t numValid() const
Definition: ParticleDataI.H:273
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
ParticleData()
Weak Constructor.
Definition: ParticleDataI.H:157
RealVect m_meshSpacing
Definition: ParticleData.H:188
unsigned pid
Definition: ParticleData.H:43
Definition: ParticleData.H:26
void define(const BoxLayout &a_dp, const ProblemDomain &a_domain, const int &a_fixedBoxSize, const RealVect &a_meshSpacing, const RealVect &a_origin)
Define function. Same as the full constructor.
Definition: ParticleDataI.H:175
void allocateVector()
Definition: ParticleDataI.H:378
int m_fixedBoxSize
Definition: ParticleData.H:190
size_t numParticles() const
Definition: ParticleDataI.H:229
IntVect enforcePeriodic(const IntVect &a_index) const
Definition: ParticleDataI.H:550
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
size_t numValidLocal() const
Return the number of valid particles in the container, not counting outcasts.
Definition: ParticleDataI.H:258
List< P > & outcast()
Definition: ParticleDataI.H:342
bool isClosed() const
Is this ParticleData.
Definition: ParticleDataI.H:348
size_t numOutcastLocal() const
Return the number of particles in the outcast list.
Definition: ParticleDataI.H:302
void fillGhosts(ParticleData< P > &a_particlesWithGhosts, const int a_numGhost) const
Definition: ParticleDataI.H:579
Definition: ParticleData.H:67
ListBoxFactory< P > m_factory
Definition: ParticleData.H:191
size_t numOutcast() const
Definition: ParticleDataI.H:313