1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 template<class CloudType>
31 inline const Foam::KinematicCloud<CloudType>&
32 Foam::KinematicCloud<CloudType>::cloudCopy() const
34 return cloudCopyPtr_();
38 template<class CloudType>
39 inline const Foam::fvMesh& Foam::KinematicCloud<CloudType>::mesh() const
45 template<class CloudType>
46 inline const Foam::IOdictionary&
47 Foam::KinematicCloud<CloudType>::particleProperties() const
49 return particleProperties_;
53 template<class CloudType>
54 inline const Foam::cloudSolution&
55 Foam::KinematicCloud<CloudType>::solution() const
61 template<class CloudType>
62 inline Foam::cloudSolution& Foam::KinematicCloud<CloudType>::solution()
68 template<class CloudType>
69 inline const typename CloudType::particleType::constantProperties&
70 Foam::KinematicCloud<CloudType>::constProps() const
76 template<class CloudType>
77 inline const Foam::dictionary&
78 Foam::KinematicCloud<CloudType>::subModelProperties() const
80 return subModelProperties_;
84 template<class CloudType>
85 inline const Foam::volScalarField& Foam::KinematicCloud<CloudType>::rho() const
91 template<class CloudType>
92 inline const Foam::volVectorField& Foam::KinematicCloud<CloudType>::U() const
98 template<class CloudType>
99 inline const Foam::volScalarField& Foam::KinematicCloud<CloudType>::mu() const
105 template<class CloudType>
106 inline const Foam::dimensionedVector& Foam::KinematicCloud<CloudType>::g() const
112 template<class CloudType>
113 inline Foam::scalar Foam::KinematicCloud<CloudType>::pAmbient() const
119 template<class CloudType>
120 inline Foam::scalar& Foam::KinematicCloud<CloudType>::pAmbient()
126 template<class CloudType>
127 //inline const typename CloudType::parcelType::forceType&
128 inline const typename Foam::KinematicCloud<CloudType>::forceType&
129 Foam::KinematicCloud<CloudType>::forces() const
135 template<class CloudType>
136 inline typename Foam::KinematicCloud<CloudType>::functionType&
137 Foam::KinematicCloud<CloudType>::functions()
143 template<class CloudType>
144 inline const Foam::DispersionModel<Foam::KinematicCloud<CloudType> >&
145 Foam::KinematicCloud<CloudType>::dispersion() const
147 return dispersionModel_;
151 template<class CloudType>
152 inline Foam::DispersionModel<Foam::KinematicCloud<CloudType> >&
153 Foam::KinematicCloud<CloudType>::dispersion()
155 return dispersionModel_();
159 template<class CloudType>
160 inline const Foam::InjectionModel<Foam::KinematicCloud<CloudType> >&
161 Foam::KinematicCloud<CloudType>::injection() const
163 return injectionModel_;
167 template<class CloudType>
168 inline const Foam::PatchInteractionModel<Foam::KinematicCloud<CloudType> >&
169 Foam::KinematicCloud<CloudType>::patchInteraction() const
171 return patchInteractionModel_;
175 template<class CloudType>
176 inline Foam::PatchInteractionModel<Foam::KinematicCloud<CloudType> >&
177 Foam::KinematicCloud<CloudType>::patchInteraction()
179 return patchInteractionModel_();
183 template<class CloudType>
184 inline Foam::InjectionModel<Foam::KinematicCloud<CloudType> >&
185 Foam::KinematicCloud<CloudType>::injection()
187 return injectionModel_();
191 template<class CloudType>
192 inline const Foam::SurfaceFilmModel<Foam::KinematicCloud<CloudType> >&
193 Foam::KinematicCloud<CloudType>::surfaceFilm() const
195 return surfaceFilmModel_();
199 template<class CloudType>
200 inline Foam::SurfaceFilmModel<Foam::KinematicCloud<CloudType> >&
201 Foam::KinematicCloud<CloudType>::surfaceFilm()
203 return surfaceFilmModel_();
207 template<class CloudType>
208 inline const Foam::vectorIntegrationScheme&
209 Foam::KinematicCloud<CloudType>::UIntegrator() const
215 template<class CloudType>
216 inline Foam::scalar Foam::KinematicCloud<CloudType>::massInSystem() const
218 scalar sysMass = 0.0;
219 forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
221 const parcelType& p = iter();
222 sysMass += p.mass()*p.nParticle();
229 template<class CloudType>
231 Foam::KinematicCloud<CloudType>::linearMomentumOfSystem() const
233 vector linearMomentum(vector::zero);
235 forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
237 const parcelType& p = iter();
239 linearMomentum += p.mass()*p.U();
242 return linearMomentum;
246 template<class CloudType>
248 Foam::KinematicCloud<CloudType>::linearKineticEnergyOfSystem() const
250 scalar linearKineticEnergy = 0.0;
252 forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
254 const parcelType& p = iter();
256 linearKineticEnergy += 0.5*p.mass()*(p.U() & p.U());
259 return linearKineticEnergy;
263 template<class CloudType>
265 Foam::KinematicCloud<CloudType>::rotationalKineticEnergyOfSystem() const
267 scalar rotationalKineticEnergy = 0.0;
269 forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
271 const parcelType& p = iter();
273 rotationalKineticEnergy +=
274 0.5*p.momentOfInertia()*(p.omega() & p.omega());
277 return rotationalKineticEnergy;
281 template<class CloudType>
282 inline Foam::scalar Foam::KinematicCloud<CloudType>::Dij
290 forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
292 const parcelType& p = iter();
293 si += p.nParticle()*pow(p.d(), i);
294 sj += p.nParticle()*pow(p.d(), j);
297 reduce(si, sumOp<scalar>());
298 reduce(sj, sumOp<scalar>());
299 sj = max(sj, VSMALL);
305 template<class CloudType>
306 inline Foam::scalar Foam::KinematicCloud<CloudType>::penetration
311 scalar distance = 0.0;
314 label np = this->size();
316 // arrays containing the parcels mass and
317 // distance from injector in ascending order
318 scalarField mass(np);
319 scalarField dist(np);
325 // first arrange the parcels in ascending order
326 // the first parcel is closest to its injection position
327 // and the last one is most far away.
328 forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
330 const parcelType& p = iter();
331 scalar mi = p.nParticle()*p.mass();
332 scalar di = mag(p.position() - p.position0());
335 // insert at the last place
342 // insert the parcel in the correct place
343 // and move the others
344 while ((i < n) && (!found))
349 for (label j=n; j>i; j--)
363 reduce(mTot, sumOp<scalar>());
367 scalar mLimit = prc*mTot;
368 scalar mOff = (1.0 - prc)*mTot;
372 // 'prc' is large enough that the parcel most far
373 // away will be used, no need to loop...
374 if (mLimit > mTot - mass[np-1])
376 distance = dist[np-1];
380 scalar mOffSum = 0.0;
383 while ((mOffSum < mOff) && (i>0))
390 + (dist[i] - dist[i+1])*(mOffSum - mOff)
400 reduce(distance, maxOp<scalar>());
406 template<class CloudType>
407 inline Foam::cachedRandom& Foam::KinematicCloud<CloudType>::rndGen()
413 template<class CloudType>
414 inline Foam::List<Foam::DynamicList<typename CloudType::particleType*> >&
415 Foam::KinematicCloud<CloudType>::cellOccupancy()
417 if (cellOccupancyPtr_.empty())
419 buildCellOccupancy();
422 return cellOccupancyPtr_();
426 template<class CloudType>
427 inline Foam::DimensionedField<Foam::vector, Foam::volMesh>&
428 Foam::KinematicCloud<CloudType>::UTrans()
434 template<class CloudType>
435 inline const Foam::DimensionedField<Foam::vector, Foam::volMesh>&
436 Foam::KinematicCloud<CloudType>::UTrans() const
442 template<class CloudType>
443 inline Foam::DimensionedField<Foam::scalar, Foam::volMesh>&
444 Foam::KinematicCloud<CloudType>::UCoeff()
450 template<class CloudType>
451 inline const Foam::DimensionedField<Foam::scalar, Foam::volMesh>&
452 Foam::KinematicCloud<CloudType>::UCoeff() const
458 template<class CloudType>
459 inline Foam::tmp<Foam::fvVectorMatrix>
460 Foam::KinematicCloud<CloudType>::SU(volVectorField& U) const
464 Info<< "UTrans min/max = " << min(UTrans()).value() << ", "
465 << max(UTrans()).value() << nl
466 << "UCoeff min/max = " << min(UCoeff()).value() << ", "
467 << max(UCoeff()).value() << endl;
470 if (solution_.coupled())
472 if (solution_.semiImplicit("U"))
474 const DimensionedField<scalar, volMesh>
475 Vdt(mesh_.V()*this->db().time().deltaT());
477 return UTrans()/Vdt - fvm::Sp(UCoeff()/Vdt, U) + UCoeff()/Vdt*U;
481 tmp<fvVectorMatrix> tfvm(new fvVectorMatrix(U, dimForce));
482 fvVectorMatrix& fvm = tfvm();
484 fvm.source() = -UTrans()/(this->db().time().deltaT());
490 return tmp<fvVectorMatrix>(new fvVectorMatrix(U, dimForce));
494 template<class CloudType>
495 inline const Foam::tmp<Foam::volScalarField>
496 Foam::KinematicCloud<CloudType>::theta() const
498 tmp<volScalarField> ttheta
504 this->name() + "Theta",
505 this->db().time().timeName(),
512 dimensionedScalar("zero", dimless, 0.0),
513 zeroGradientFvPatchScalarField::typeName
517 volScalarField& theta = ttheta();
518 forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
520 const parcelType& p = iter();
521 const label cellI = p.cell();
523 theta[cellI] += p.nParticle()*p.volume();
526 theta.internalField() /= mesh_.V();
527 theta.correctBoundaryConditions();
533 template<class CloudType>
534 inline const Foam::tmp<Foam::volScalarField>
535 Foam::KinematicCloud<CloudType>::alpha() const
537 tmp<volScalarField> talpha
543 this->name() + "Alpha",
544 this->db().time().timeName(),
551 dimensionedScalar("zero", dimless, 0.0)
555 scalarField& alpha = talpha().internalField();
556 forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
558 const parcelType& p = iter();
559 const label cellI = p.cell();
561 alpha[cellI] += p.nParticle()*p.mass();
564 alpha /= (mesh_.V()*rho_);
570 template<class CloudType>
571 inline const Foam::tmp<Foam::volScalarField>
572 Foam::KinematicCloud<CloudType>::rhoEff() const
574 tmp<volScalarField> trhoEff
580 this->name() + "RhoEff",
581 this->db().time().timeName(),
588 dimensionedScalar("zero", dimDensity, 0.0)
592 scalarField& rhoEff = trhoEff().internalField();
593 forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
595 const parcelType& p = iter();
596 const label cellI = p.cell();
598 rhoEff[cellI] += p.nParticle()*p.mass();
607 // ************************************************************************* //