Cloud.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "Cloud.H"
00028 #include "processorPolyPatch.H"
00029 #include "globalMeshData.H"
00030 #include "PstreamCombineReduceOps.H"
00031 #include "mapPolyMesh.H"
00032 #include "Time.H"
00033 #include "OFstream.H"
00034
00035
00036
00037 template<class ParticleType>
00038 Foam::Cloud<ParticleType>::Cloud
00039 (
00040 const polyMesh& pMesh,
00041 const IDLList<ParticleType>& particles
00042 )
00043 :
00044 cloud(pMesh),
00045 IDLList<ParticleType>(),
00046 polyMesh_(pMesh),
00047 particleCount_(0)
00048 {
00049 IDLList<ParticleType>::operator=(particles);
00050 }
00051
00052
00053 template<class ParticleType>
00054 Foam::Cloud<ParticleType>::Cloud
00055 (
00056 const polyMesh& pMesh,
00057 const word& cloudName,
00058 const IDLList<ParticleType>& particles
00059 )
00060 :
00061 cloud(pMesh, cloudName),
00062 IDLList<ParticleType>(),
00063 polyMesh_(pMesh),
00064 particleCount_(0)
00065 {
00066 IDLList<ParticleType>::operator=(particles);
00067 }
00068
00069
00070
00071
00072 template<class ParticleType>
00073 Foam::label Foam::Cloud<ParticleType>::getNewParticleID() const
00074 {
00075 label id = particleCount_++;
00076
00077 if (id == labelMax)
00078 {
00079 WarningIn("Cloud<ParticleType>::getNewParticleID() const")
00080 << "Particle counter has overflowed. This might cause problems"
00081 << " when reconstructing particle tracks." << endl;
00082 }
00083 return id;
00084 }
00085
00086
00087 template<class ParticleType>
00088 void Foam::Cloud<ParticleType>::addParticle(ParticleType* pPtr)
00089 {
00090 append(pPtr);
00091 }
00092
00093
00094 template<class ParticleType>
00095 void Foam::Cloud<ParticleType>::deleteParticle(ParticleType& p)
00096 {
00097 delete(this->remove(&p));
00098 }
00099
00100
00101 namespace Foam
00102 {
00103
00104 class combineNsTransPs
00105 {
00106
00107 public:
00108
00109 void operator()(labelListList& x, const labelListList& y) const
00110 {
00111 forAll(y, i)
00112 {
00113 if (y[i].size())
00114 {
00115 x[i] = y[i];
00116 }
00117 }
00118 }
00119 };
00120
00121 }
00122
00123
00124 template<class ParticleType>
00125 template<class TrackingData>
00126 void Foam::Cloud<ParticleType>::move(TrackingData& td)
00127 {
00128 const globalMeshData& pData = polyMesh_.globalData();
00129 const labelList& processorPatches = pData.processorPatches();
00130 const labelList& processorPatchIndices = pData.processorPatchIndices();
00131 const labelList& processorPatchNeighbours =
00132 pData.processorPatchNeighbours();
00133
00134
00135 forAllIter(typename Cloud<ParticleType>, *this, pIter)
00136 {
00137 pIter().stepFraction() = 0;
00138 }
00139
00140
00141 bool transfered = true;
00142
00143
00144 while (transfered)
00145 {
00146
00147
00148 List<IDLList<ParticleType> > transferList(processorPatches.size());
00149
00150
00151 forAllIter(typename Cloud<ParticleType>, *this, pIter)
00152 {
00153 ParticleType& p = pIter();
00154
00155
00156 bool keepParticle = p.move(td);
00157
00158
00159
00160 if (keepParticle)
00161 {
00162
00163
00164 if (Pstream::parRun() && p.facei_ >= pMesh().nInternalFaces())
00165 {
00166 label patchi = pMesh().boundaryMesh().whichPatch(p.facei_);
00167 label n = processorPatchIndices[patchi];
00168
00169
00170
00171 if (n != -1)
00172 {
00173 p.prepareForParallelTransfer(patchi, td);
00174 transferList[n].append(this->remove(&p));
00175 }
00176 }
00177 }
00178 else
00179 {
00180 deleteParticle(p);
00181 }
00182 }
00183
00184 if (Pstream::parRun())
00185 {
00186
00187
00188 labelList nsTransPs(transferList.size());
00189
00190 forAll(transferList, i)
00191 {
00192 nsTransPs[i] = transferList[i].size();
00193 }
00194
00195
00196
00197 labelListList allNTrans(Pstream::nProcs());
00198 allNTrans[Pstream::myProcNo()] = nsTransPs;
00199 combineReduce(allNTrans, combineNsTransPs());
00200
00201 transfered = false;
00202
00203 forAll(allNTrans, i)
00204 {
00205 forAll(allNTrans[i], j)
00206 {
00207 if (allNTrans[i][j])
00208 {
00209 transfered = true;
00210 break;
00211 }
00212 }
00213 }
00214
00215 if (!transfered)
00216 {
00217 break;
00218 }
00219
00220 forAll(transferList, i)
00221 {
00222 if (transferList[i].size())
00223 {
00224 OPstream particleStream
00225 (
00226 Pstream::blocking,
00227 refCast<const processorPolyPatch>
00228 (
00229 pMesh().boundaryMesh()[processorPatches[i]]
00230 ).neighbProcNo()
00231 );
00232
00233 particleStream << transferList[i];
00234 }
00235 }
00236
00237 forAll(processorPatches, i)
00238 {
00239 label patchi = processorPatches[i];
00240
00241 const processorPolyPatch& procPatch =
00242 refCast<const processorPolyPatch>
00243 (pMesh().boundaryMesh()[patchi]);
00244
00245 label neighbProci =
00246 procPatch.neighbProcNo() - Pstream::masterNo();
00247
00248 label neighbProcPatchi = processorPatchNeighbours[patchi];
00249
00250 label nRecPs = allNTrans[neighbProci][neighbProcPatchi];
00251
00252 if (nRecPs)
00253 {
00254 IPstream particleStream
00255 (
00256 Pstream::blocking,
00257 procPatch.neighbProcNo()
00258 );
00259 IDLList<ParticleType> newParticles
00260 (
00261 particleStream,
00262 typename ParticleType::iNew(*this)
00263 );
00264
00265 forAllIter
00266 (
00267 typename Cloud<ParticleType>,
00268 newParticles,
00269 newpIter
00270 )
00271 {
00272 ParticleType& newp = newpIter();
00273 newp.correctAfterParallelTransfer(patchi, td);
00274 addParticle(newParticles.remove(&newp));
00275 }
00276 }
00277 }
00278 }
00279 else
00280 {
00281 transfered = false;
00282 }
00283 }
00284 }
00285
00286
00287 template<class ParticleType>
00288 void Foam::Cloud<ParticleType>::autoMap(const mapPolyMesh& mapper)
00289 {
00290 if (cloud::debug)
00291 {
00292 Info<< "Cloud<ParticleType>::autoMap(const morphFieldMapper& map) "
00293 "for lagrangian cloud " << cloud::name() << endl;
00294 }
00295
00296 const labelList& reverseCellMap = mapper.reverseCellMap();
00297 const labelList& reverseFaceMap = mapper.reverseFaceMap();
00298
00299 forAllIter(typename Cloud<ParticleType>, *this, pIter)
00300 {
00301 if (reverseCellMap[pIter().celli_] >= 0)
00302 {
00303 pIter().celli_ = reverseCellMap[pIter().celli_];
00304
00305 if (pIter().facei_ >= 0 && reverseFaceMap[pIter().facei_] >= 0)
00306 {
00307 pIter().facei_ = reverseFaceMap[pIter().facei_];
00308 }
00309 else
00310 {
00311 pIter().facei_ = -1;
00312 }
00313 }
00314 else
00315 {
00316 label trackStartCell = mapper.mergedCell(pIter().celli_);
00317
00318 if (trackStartCell < 0)
00319 {
00320 trackStartCell = 0;
00321 }
00322
00323 vector p = pIter().position();
00324 const_cast<vector&>(pIter().position()) =
00325 polyMesh_.cellCentres()[trackStartCell];
00326 pIter().stepFraction() = 0;
00327 pIter().track(p);
00328 }
00329 }
00330 }
00331
00332
00333 template<class ParticleType>
00334 void Foam::Cloud<ParticleType>::writePositions() const
00335 {
00336 OFstream pObj
00337 (
00338 this->db().time().path()/this->name() + "_positions.obj"
00339 );
00340
00341 forAllConstIter(typename Cloud<ParticleType>, *this, pIter)
00342 {
00343 const ParticleType& p = pIter();
00344 pObj<< "v " << p.position().x() << " " << p.position().y() << " "
00345 << p.position().z() << nl;
00346 }
00347
00348 pObj.flush();
00349 }
00350
00351
00352
00353
00354 #include "CloudIO.C"
00355
00356
Copyright © 2000-2009 OpenCFD Ltd