chombo-discharge
CD_ParticleManagement.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2022 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_ParticleManagement_H
13 #define CD_ParticleManagement_H
14 
15 // Std includes
16 #include <memory>
17 #include <vector>
18 
19 // Chombo includes
20 #include <RealVect.H>
21 #include <List.H>
22 
23 // Our includes
24 #include <CD_KDNode.H>
25 #include <CD_CellInfo.H>
26 #include <CD_NamespaceHeader.H>
27 
31 namespace ParticleManagement {
32 
38  template <class P>
39  using ParticleMerger = std::function<
40  void(List<P>& a_particles, const CellInfo& a_cellInfo, const int a_numTargetParticles)>;
41 
49  template <class P>
50  using BinaryParticleReconcile = std::function<void(P& p1, P& p2, const P& p0)>;
51 
72  template <class P, Real& (P::*weight)(), const RealVect& (P::*position)() const>
73  static inline void
74  partitionAndSplitEqualWeightKD(
75  KDNode<P>& a_node,
76  const BinaryParticleReconcile<P> a_particleReconcile = [](P& p1, P& p2, const P& p0) -> void {
77  }) noexcept;
78 
99  template <class P, Real& (P::*weight)(), const RealVect& (P::*position)() const>
100  static inline std::vector<std::shared_ptr<KDNode<P>>>
101  recursivePartitionAndSplitEqualWeightKD(
102  typename KDNode<P>::ParticleList& a_inputParticles,
103  const int a_maxLeaves,
104  const BinaryParticleReconcile<P> a_particleReconcile = [](P& p1, P& p2, const P& p0) -> void {
105  }) noexcept;
106 
113  template <typename P, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
114  static inline void
115  removePhysicalParticles(List<P>& a_particles, const T a_numPhysPartToRemove) noexcept;
116 
122  template <typename P>
123  static inline void
124  deleteParticles(List<P>& a_particles, const Real a_weightThresh) noexcept;
125 
131  template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
132  static inline std::vector<T>
133  partitionParticleWeights(const T a_numPhysicalParticles, const T a_maxCompParticles) noexcept;
134 
140  template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
141  static inline T
142  partitionParticles(const T a_numParticles);
143 
152  template <typename P, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
153  static inline void
154  drawRandomParticles(List<P>& a_particles, const T a_numParticles, const std::function<RealVect()>& a_distribution);
155 
165  template <typename P, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
166  static inline void
167  drawSphereParticles(List<P>& a_particles,
168  const T a_numParticles,
169  const RealVect a_center,
170  const Real a_radius) noexcept;
171 
181  template <typename P, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
182  static inline void
183  drawBoxParticles(List<P>& a_particles,
184  const T a_numParticles,
185  const RealVect a_loCorner,
186  const RealVect a_hiCorner) noexcept;
187 
197  template <typename P, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
198  static inline void
199  drawGaussianParticles(List<P>& a_particles,
200  const T a_numParticles,
201  const RealVect a_center,
202  const Real a_radius) noexcept;
203 
204 } // namespace ParticleManagement
205 
206 #include <CD_NamespaceFooter.H>
207 
209 
210 #endif
Simple class for holding some quantities relevant in a grid cell.
Namespace containing various particle management utilities.
Implementation of CD_ParticleManagement.H.
Class for the cell-information that is often queried when merging particles inside a cell.
Definition: CD_CellInfo.H:25
Node in a particle-merging KD-tree.
Definition: CD_KDNode.H:33
std::vector< P > ParticleList
List of particles. This is aliased because the KD-tree construction may require both random access an...
Definition: CD_KDNode.H:39
Namespace for various particle management tools.
Definition: CD_ParticleManagement.H:31
void deleteParticles(List< P > &a_particles, const Real a_weightThresh) noexcept
Remove particles if their weight is below the input weight.
Definition: CD_ParticleManagementImplem.H:349
void removePhysicalParticles(List< P > &a_particles, const T a_numPhysPartToRemove) noexcept
Remove physical particles from the input particles.
Definition: CD_ParticleManagementImplem.H:264
std::function< void(P &p1, P &p2, const P &p0)> BinaryParticleReconcile
Declaration of a reconciliation function when splitting particles.
Definition: CD_ParticleManagement.H:50
void drawGaussianParticles(List< P > &a_particles, const T a_numParticles, const RealVect a_center, const Real a_radius) noexcept
Draw particles from a Gaussian distribution.
Definition: CD_ParticleManagementImplem.H:488
std::vector< T > partitionParticleWeights(const T a_numPhysicalParticles, const T a_maxCompParticles) noexcept
Partition particle weights among a number of computational particles.
Definition: CD_ParticleManagementImplem.H:365
void drawSphereParticles(List< P > &a_particles, const T a_numParticles, const RealVect a_center, const Real a_radius) noexcept
Draw particles in a sphere.
Definition: CD_ParticleManagementImplem.H:436
std::function< void(List< P > &a_particles, const CellInfo &a_cellInfo, const int a_numTargetParticles)> ParticleMerger
Concept for splitting/merging particles.
Definition: CD_ParticleManagement.H:40
T partitionParticles(const T a_numParticles)
Partition particles so that all MPI rank draw a cumulative number of particles equal to a_numParticle...
Definition: CD_ParticleManagementImplem.H:399
void drawBoxParticles(List< P > &a_particles, const T a_numParticles, const RealVect a_loCorner, const RealVect a_hiCorner) noexcept
Draw particles in a box.
Definition: CD_ParticleManagementImplem.H:468
void drawRandomParticles(List< P > &a_particles, const T a_numParticles, const std::function< RealVect()> &a_distribution)
Draw a specified number of random particles distributed according to a predefined distribution.
Definition: CD_ParticleManagementImplem.H:419