Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
ParticleSystemBase.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MODEL is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef _MODEL_ParticleSystemBase_h_
9#define _MODEL_ParticleSystemBase_h_
10
11#include <deque>
12//#include <modelMacros.h> // model_checkInput
13#include <FieldPoint.h>
14#include <PointSource.h>
15#include <SpatialCellObserver.h>
16
17
18namespace model
19{
20
21
22
23 template <typename _ParticleType>
25 /* inheritance */ public std::deque<_ParticleType> // iteration and fast insertion are priority
26 {
27
28 public:
29
30 typedef _ParticleType ParticleType; // make ParticleType available outside the class
31 typedef typename _ParticleType::PositionType PositionType;
32 typedef SpatialCellObserver<_ParticleType,_ParticleType::dim> SpatialCellObserverType;
33 typedef typename SpatialCellObserverType::SpatialCellType SpatialCellType;
34 typedef std::deque<_ParticleType> ParticleContainerType;
35
36 /**********************************************************************/
37 template <typename ...AdditionalConstructorTypes>
38 ParticleType* addParticle(const PositionType& p, const AdditionalConstructorTypes&... args)
39 {
43 this->emplace_back(p,args...);
44 return &*this->rbegin();
45 }
46
47 /**********************************************************************/
49 {
51 this->clear();
52 }
53
54 /**********************************************************************/
56 {/*\returns the const base container of particles
57 */
58 return *static_cast<const ParticleContainerType* const>(this);
59 }
60
61 /**********************************************************************/
62 const typename SpatialCellObserverType::CellMapType& cells() const
63 {
64 return SpatialCellObserverType::cells();
65 }
66
67 /**********************************************************************/
68 static void setCellSize(const double& cellSize)
69 {
70 assert(cellSize>0.0);
71 // SpatialCellObserverType::cellSize=cellSize;
72 SpatialCellObserverType::setCellSize(cellSize);
73 }
74
75 /**********************************************************************/
76 template <typename OtherParticleType, typename FieldType,typename... OtherSourceTypes>
77 void computeField(OtherParticleType& part, const OtherSourceTypes&... otherSources) const
78 {
83 if(static_cast<FieldPointBase<OtherParticleType,FieldType>* const>(&part)->enabled)
84 {
85 // Nearest-neighbor interaction
86 typename SpatialCellType::CellMapType neighborCells(part.template neighborCells<_ParticleType>());
87
89 for (typename SpatialCellType::CellMapType::const_iterator cIter =neighborCells.begin();
90 /* */ cIter!=neighborCells.end();
91 /* */ ++cIter)
92 {
94 for(typename SpatialCellType::ParticleContainerType::const_iterator qIter =cIter->second->particleBegin();
95 /* */ qIter!=cIter->second->particleEnd();
96 /* */ ++qIter)
97 {
98 //part.template field<FieldType>() += FieldType::compute(**qIter,part);
99 if(static_cast<const SingleSourcePoint<_ParticleType,FieldType>* const>(*qIter)->enabled)
100 {// source is enabled
101 *static_cast<FieldPointBase<OtherParticleType,FieldType>* const>(&part) += FieldType::compute(**qIter,part);
102 }
103 }
104 }
105
106 // Non-nearest-neighbor interaction
107 if(FieldType::use_multipole)
108 {
109 typename SpatialCellType::CellMapType farCells(part.template farCells<_ParticleType>());
110 //
111 // part.template field<FieldType>() += FieldType::multipole(part,farCells);
112 *static_cast<FieldPointBase<OtherParticleType,FieldType>* const>(&part) += FieldType::multipole(part,farCells);
113 }
114
115 // Add contribution of other sources
116 if(sizeof...(OtherSourceTypes))
117 {
118 *static_cast<FieldPointBase<OtherParticleType,FieldType>* const>(&part) += FieldType::addSourceContribution(part,otherSources...);
119 }
120 }
121
122 }
123
124 /**********************************************************************/
125 template <class T>
126 friend T& operator<< (T& os, const ParticleSystemBase<ParticleType>& system)
127 {
129 for (const auto& particle : system)
130 {
131 os << particle <<"\n";
132 }
133 return os;
134 }
135
136 };
137
138
139
140} // end namespace
141#endif
142
const SpatialCellObserverType::CellMapType & cells() const
void computeField(OtherParticleType &part, const OtherSourceTypes &... otherSources) const
static void setCellSize(const double &cellSize)
const ParticleContainerType & particles() const
SpatialCellObserver< _ParticleType, _ParticleType::dim > SpatialCellObserverType
SpatialCellObserverType::SpatialCellType SpatialCellType
_ParticleType::PositionType PositionType
ParticleType * addParticle(const PositionType &p, const AdditionalConstructorTypes &... args)
friend T & operator<<(T &os, const ParticleSystemBase< ParticleType > &system)
std::deque< _ParticleType > ParticleContainerType
A class template that contains the underlying FieldType data of the Derived particle.
vertex p[3]