SpatialOps
ParticleOperators.h
1 /*
2  * Copyright (c) 2014-2017 The University of Utah
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  */
22 #ifndef ParticleOperators_h
23 #define ParticleOperators_h
24 
26 #include <spatialops/particles/ParticlesOperatorHelper.h>
27 #include <spatialops/Nebo.h>
28 #include <spatialops/structured/SpatialMask.h>
30 #include <spatialops/particles/ParticleGrid.h>
31 
32 #include <stdexcept>
33 #include <cmath>
34 #include <algorithm>
35 #include <vector>
36 
37 namespace SpatialOps{
38  namespace Particle{
39 
48  template< typename CellField >
50  {
51  public:
53  typedef CellField DestFieldType;
54 
64  ParticlesPerCell( const double dx, const double xlo,
65  const double dy=-1, const double ylo =0,
66  const double dz=-1, const double zlo =0,
67  const InterpOptions method=INTERPOLATE);
68 
75  void set_coordinate_information( const ParticleField * const pxcoord,
76  const ParticleField * const pycoord,
77  const ParticleField * const pzcoord,
78  const ParticleField * const psize );
79 
83  void apply_to_field( DestFieldType& dest ) const;
84 
85  private:
86  const double dx_, dy_, dz_;
87  const double xlo_, ylo_, zlo_;
88  const ParticleField *px_, *py_, *pz_, *psize_;
89  const InterpOptions method_;
90  };
91 
92 
102  template< typename CellField >
104  {
105  public:
106  typedef ParticleField SrcFieldType;
107  typedef CellField DestFieldType;
108 
118  ParticleToCell( const double dx, const double xlo,
119  const double dy=-1, const double ylo =0,
120  const double dz=-1, const double zlo =0,
121  const InterpOptions method=INTERPOLATE );
122 
123 
130  void set_coordinate_information( const ParticleField * const pxcoord,
131  const ParticleField * const pycoord,
132  const ParticleField * const pzcoord,
133  const ParticleField * const psize );
134 
139  void apply_to_field( const SrcFieldType& src,
140  DestFieldType& dest ) const;
141 
142 
143  private:
144 
145  const double dx_, dy_, dz_;
146  const double xlo_, ylo_, zlo_;
147  const ParticleField *px_, *py_, *pz_, *psize_;
148  const InterpOptions method_;
149  };
150 
151 
152  //==================================================================
153 
154 
164  template< typename CellField >
166  {
167  public:
168  typedef CellField SrcFieldType;
170 
180  CellToParticle( const double dx, const double xlo,
181  const double dy=-1, const double ylo =0,
182  const double dz=-1, const double zlo =0,
183  const InterpOptions method=INTERPOLATE );
184 
192  void set_coordinate_information( const ParticleField* pxcoord,
193  const ParticleField* pycoord,
194  const ParticleField* pzcoord,
195  const ParticleField* psize );
196 
201  void apply_to_field( const SrcFieldType& src,
202  DestFieldType& dest ) const;
203 
204  void apply_to_field( const SrcFieldType& src,
205  DestFieldType& dest,
206  const std::string& method ) const;
207 
208  private:
209 
210  const double dx_, dy_, dz_;
211  const double xlo_, ylo_, zlo_;
212  const ParticleField *px_, *py_, *pz_, *psize_;
213  const InterpOptions method_;
214  };
215 
224  {
225  public:
226 
228  typedef typename ParticleGrid::GridState search_state;
229 
246  RangeSearch( const MemoryWindow& pParticleMemoryWindow,
247  const GhostData& pParticleGhostData,
248  const BoundaryCellInfo& pParticleBoundaryInfo,
249  const IntVec pParticleMinExtent,
250  const IntVec pParticleMaxExtent,
251  const size_t pNumParticles,
252  const double pSmoothingRadius,
253  const ParticleField& pXcoord,
254  const ParticleField& pYcoord,
255  const ParticleField& pZcoord,
256  const bool pUseGrid = false,
257  const bool pSortData = false,
258  const short int pLocation = CPU_INDEX);
259 
260 
276  RangeSearch( const MemoryWindow& pParticleMemoryWindow,
277  const GhostData& pParticleGhostData,
278  const BoundaryCellInfo& pParticleBoundaryInfo,
279  const IntVec pParticleMinExtent,
280  const IntVec pParticleMaxExtent,
281  const size_t pNumParticles,
282  const double pSmoothingRadius,
283  const ParticleField& pXcoord,
284  const ParticleField& pYcoord,
285  const bool pUseGrid = false,
286  const bool pSortData = false,
287  const short int pLocation = CPU_INDEX);
288 
295  search_state GetCurrentState (short int location = CPU_INDEX) {
296  return grid_.GetCurrentState(location, useGrid_);
297  }
298 
299 #ifndef __CUDACC__
300 #ifndef NDEBUG
301 
304  long num_pairs_found () const {
305  return grid_.NumPairsFound();
306  }
307 #endif
308 #endif
309 
310  private:
311 
318  void setup_grid(bool sortData = false, short int location = CPU_INDEX);
319 
320 
321  ParticleGrid grid_;
322 
323  bool useGrid_;
324  bool sortData_;
325 
326  const ParticleField *px_, *py_, *pz_;
327  };
328 
329 
330 
331  } // namespace Particle
332 } // namespace SpatialOps
333 
334 #endif // ParticleOperators_h
335 
long num_pairs_found() const
Returns the number of pairs found during the range search (available only for Debug build) ...
Provides tools to index into a sub-block of memory.
Definition: MemoryWindow.h:63
Maintains particle state information, needed to perform Nebo Mapped reduction for SPH simulations...
Stores the particle information needed to perform range search operation.
Definition: ParticleGrid.h:72
Computes the number of particles per cell and accounts for fractional contributions.
search_state GetCurrentState(short int location=CPU_INDEX)
Returns the state information needed to perform the nebo mapped reduction.
Holds information about the number of ghost cells on each side of the domain.
Definition: GhostData.h:54
Operator to interpolate a mesh field onto a particle.
Interpolates an extensive particle field onto an underlying mesh field.Note that this should only be ...
Maintains the grid information needed to perform particle range search based on the device (CPU/GPU) ...
Definition: ParticleGrid.h:102
void set_coordinate_information(const ParticleField *const pxcoord, const ParticleField *const pycoord, const ParticleField *const pzcoord, const ParticleField *const psize)
Iterator used to index the particles found during the range search.
Definition: ParticleGrid.h:80
Abstracts a field.
Definition: SpatialField.h:132
void apply_to_field(DestFieldType &dest) const
ParticlesPerCell(const double dx, const double xlo, const double dy=-1, const double ylo=0, const double dz=-1, const double zlo=0, const InterpOptions method=INTERPOLATE)
construct a ParticlesPerCell operator
Defines objects for containing and operating on matrices of fields.
Provides information about boundary cells for various fields.