Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
ParticleSystemSerial.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_ParticleSystemSerial_h_
9#define _MODEL_ParticleSystemSerial_h_
10
11
12#ifdef _OPENMP
13#include <omp.h>
14#endif
15
16
17#include <memory> // for auto_ptr
18#include <time.h>
19#include <iomanip> // std::scientific
20#include <utility> // std::pair
21
22#include <PointSource.h>
23#include <FieldPoint.h>
24#include <ParticleSystemBase.h>
25#include <SpatialCellObserver.h>
26
27
28//#include <ParallelFor.h> // alterative to openmp using std::thread
29
30namespace model {
31
32
33
34
35 /**************************************************************************/
36 /**************************************************************************/
39 template <typename _ParticleType >
40 class ParticleSystemSerial : public ParticleSystemBase<_ParticleType>
41 {
42 typedef ParticleSystemBase<_ParticleType> ParticleSystemBaseType;
43 typedef _ParticleType ParticleType; // make ParticleType available outside the class
44 typedef ParticleSystemSerial<_ParticleType> ParticleSystemSerialType;
45
46 public:
47
50
51
52 /**********************************************************************/
53 template <typename FieldType,typename... OtherSourceTypes>
54 void computeNeighborField(const OtherSourceTypes&... otherSources)
55 {
56 // Nearest-neighbor interaction
58#ifdef _OPENMP
59#pragma omp parallel for
60#endif
61 for (unsigned int k=0; k<this->size();++k)
62 {
63 if(static_cast<FieldPointBase<ParticleType,FieldType>* const>(&this->operator[](k))->enabled)
64 {
66 for (typename SpatialCellType::CellMapType::const_iterator cIter =this->operator[](k).neighborCellsBegin();
67 /* */ cIter!=this->operator[](k).neighborCellsEnd();
68 /* */ ++cIter)
69 {
71 for(typename SpatialCellType::ParticleContainerType::const_iterator qIter =cIter->second->particleBegin();
72 /* */ qIter!=cIter->second->particleEnd();
73 /* */ ++qIter)
74 {
75 if(static_cast<const SingleSourcePoint<_ParticleType,FieldType>* const>(*qIter)->enabled)
76 {
77 *static_cast<FieldPointBase<ParticleType,FieldType>* const>(&this->operator[](k)) += FieldType::compute(**qIter,this->operator[](k));
78 }
79 }
80 }
81
82 // Non-nearest-neighbor interaction
83 if(FieldType::use_multipole)
84 {
85 typename SpatialCellType::CellMapType farCells(this->operator[](k).template farCells<_ParticleType>());
86 *static_cast<FieldPointBase<ParticleType,FieldType>* const>(&this->operator[](k)) += FieldType::multipole(this->operator[](k),farCells);
87 }
88
89 // Add contribution of other sources
90 if(sizeof...(OtherSourceTypes))
91 {
92 *static_cast<FieldPointBase<ParticleType,FieldType>* const>(&this->operator[](k)) += FieldType::addSourceContribution(this->operator[](k),otherSources...);
93 }
94 }
95 }
96 }
97
98
99
100 /**********************************************************************/
101 template <typename OtherParticleType, typename FieldType,typename... OtherSourceTypes>
102 void computeField(std::deque<OtherParticleType>& fpDeq, const OtherSourceTypes&... otherSources) const
103 {
104#ifdef _OPENMP
105#pragma omp parallel for
106#endif
107 for (unsigned int k=0; k<fpDeq.size();++k)
108 {
109 if(static_cast<FieldPointBase<OtherParticleType,FieldType>* const>(&fpDeq[k])->enabled)
110 {
111 // Nearest-neighbor interaction
112 typename SpatialCellType::CellMapType neighborCells(fpDeq[k].template neighborCells<_ParticleType>());
113
115 for (typename SpatialCellType::CellMapType::const_iterator cIter =neighborCells.begin();
116 /* */ cIter!=neighborCells.end();
117 /* */ ++cIter)
118 {
120 for(typename SpatialCellType::ParticleContainerType::const_iterator qIter =cIter->second->particleBegin();
121 /* */ qIter!=cIter->second->particleEnd();
122 /* */ ++qIter)
123 {
124 //fpDeq[k].template field<FieldType>() += FieldType::compute(**qIter,fpDeq[k]);
125 if(static_cast<const SingleSourcePoint<_ParticleType,FieldType>* const>(*qIter)->enabled)
126 {// source is enabled
127 *static_cast<FieldPointBase<OtherParticleType,FieldType>* const>(&fpDeq[k]) += FieldType::compute(**qIter,fpDeq[k]);
128 }
129 }
130 }
131
132 // Non-nearest-neighbor interaction
133 if(FieldType::use_multipole)
134 {
135 typename SpatialCellType::CellMapType farCells(fpDeq[k].template farCells<_ParticleType>());
136 //
137 // fpDeq[k].template field<FieldType>() += FieldType::multipole(fpDeq[k],farCells);
138 *static_cast<FieldPointBase<OtherParticleType,FieldType>* const>(&fpDeq[k]) += FieldType::multipole(fpDeq[k],farCells);
139 }
140
141 // Add contribution of other sources
142 if(sizeof...(OtherSourceTypes))
143 {
144 *static_cast<FieldPointBase<OtherParticleType,FieldType>* const>(&fpDeq[k]) += FieldType::addSourceContribution(fpDeq[k],otherSources...);
145 }
146 }
147 }
148 }
149
150 /**********************************************************************/
151 template <typename OtherParticleType, typename FieldType,typename... OtherSourceTypes>
152 void computeField(OtherParticleType& part, const OtherSourceTypes&... otherSources) const
153 {
158 ParticleSystemBaseType::template computeField<OtherParticleType,FieldType,OtherSourceTypes...>(part,otherSources...);
159 }
160
161 /**********************************************************************/
162 template <class T>
163 friend T& operator<< (T& os, const ParticleContainerType& pS)
164 {
166 for (typename ParticleContainerType::const_iterator pIter=pS.begin();pIter!=pS.end();++pIter)
167 {
168 os<<(*pIter);
169 }
170 return os;
171 }
172
173 };
174
175} // end namespace
176#endif
177
178
179// /**********************************************************************/
180// template <typename OtherParticleType, typename FieldType>
181// void computeField(std::deque<OtherParticleType* const>& fpDeq) const
182// {
183//#ifdef _OPENMP
184//#pragma omp parallel for
185//#endif
186// for (unsigned int k=0; k<fpDeq.size();++k)
187// {
188// typename SpatialCellType::CellMapType neighborCells(fpDeq[k]->template neighborCells<_ParticleType>());
189//
190// //! -2 loop over neighbor cells of current particle
191// for (typename SpatialCellType::CellMapType::const_iterator cIter =neighborCells.begin();
192// /* */ cIter!=neighborCells.end();
193// /* */ ++cIter)
194// {
195// //! -3 loop over particles in the current neighbor cell
196// for(typename SpatialCellType::ParticleContainerType::const_iterator qIter =cIter->second->particleBegin();
197// /* */ qIter!=cIter->second->particleEnd();
198// /* */ ++qIter)
199// {
200// fpDeq[k]->template field<FieldType>() += FieldType::compute(**qIter,*fpDeq[k]);
201// }
202// }
203// }
204//
205// }
206
207
208
209
210// ParallelFor().runRange(0,this->size(),this,&ParticleSystemSerial<_ParticleType>::neighborFieldIteration<FieldType>); // alternative to openmp
211
212// /**********************************************************************/
213// template <typename FieldType>
214// void neighborFieldIteration(const size_t& _begin, const size_t& _end)
215// {
216// for (unsigned int k=_begin; k<_end;++k)
217// {
218// //! -2 loop over neighbor cells of current particle
219// for (typename SpatialCellType::CellMapType::const_iterator cIter =this->operator[](k).neighborCellsBegin();
220// /* */ cIter!=this->operator[](k).neighborCellsEnd();
221// /* */ ++cIter)
222// {
223// //! -3 loop over particles in the current neighbor cell
224// for(typename SpatialCellType::ParticleContainerType::const_iterator qIter =cIter->second->particleBegin();
225// /* */ qIter!=cIter->second->particleEnd();
226// /* */ ++qIter)
227// {
228// *static_cast<FieldPointBase<ParticleType,FieldType>* const>(&this->operator[](k)) += FieldType::compute(**qIter,this->operator[](k));
229// }
230// }
231// }
232// }
233
SpatialCellObserverType::SpatialCellType SpatialCellType
std::deque< _ParticleType > ParticleContainerType
Serial Version (openMP only).
void computeField(OtherParticleType &part, const OtherSourceTypes &... otherSources) const
void computeField(std::deque< OtherParticleType > &fpDeq, const OtherSourceTypes &... otherSources) const
ParticleSystemBaseType::ParticleContainerType ParticleContainerType
friend T & operator<<(T &os, const ParticleContainerType &pS)
ParticleSystemBaseType::SpatialCellType SpatialCellType
void computeNeighborField(const OtherSourceTypes &... otherSources)
A class template that contains the underlying FieldType data of the Derived particle.
int k