OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

particleI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "polyMesh.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00035 
00036 template<class particleType>
00037 inline scalar particle<particleType>::lambda
00038 (
00039     const vector& from,
00040     const vector& to,
00041     const label facei,
00042     const scalar stepFraction
00043 )
00044 {
00045     const polyMesh& mesh = cloud_.polyMesh_;
00046     bool movingMesh = mesh.moving();
00047 
00048     if (movingMesh)
00049     {
00050         vector Sf = mesh.faceAreas()[facei];
00051         Sf /= mag(Sf);
00052         vector Cf = mesh.faceCentres()[facei];
00053 
00054         // move reference point for wall
00055         if (!cloud_.internalFace(facei))
00056         {
00057             const vector& C = mesh.cellCentres()[celli_];
00058             scalar CCf = mag((C - Cf) & Sf);
00059             // check if distance between cell centre and face centre
00060             // is larger than wallImpactDistance
00061             if
00062             (
00063                 CCf
00064               > static_cast<const particleType&>(*this).wallImpactDistance(Sf)
00065             )
00066             {
00067                 Cf -= static_cast<const particleType&>(*this)
00068                     .wallImpactDistance(Sf)*Sf;
00069             }
00070         }
00071 
00072         // for a moving mesh we need to reconstruct the old
00073         // Sf and Cf from oldPoints (they aren't stored)
00074         // NN.
00075 
00076         const vectorField& oldPoints = mesh.oldPoints();
00077 
00078         vector Cf00 = mesh.faces()[facei].centre(oldPoints);
00079         vector Cf0 = Cf00 + stepFraction*(Cf - Cf00);
00080 
00081         vector Sf00 = mesh.faces()[facei].normal(oldPoints);
00082 
00083         // for layer addition Sf00 = vector::zero and we use Sf
00084         if (mag(Sf00) > SMALL)
00085         {
00086             Sf00 /= mag(Sf00);
00087         }
00088         else
00089         {
00090             Sf00 = Sf;
00091         }
00092 
00093         scalar magSfDiff = mag(Sf - Sf00);
00094 
00095         // check if the face is rotating
00096         if (magSfDiff > SMALL)
00097         {
00098             vector Sf0 = Sf00 + stepFraction*(Sf - Sf00);
00099 
00100             // find center of rotation
00101             vector omega = Sf0 ^ Sf;
00102             scalar magOmega = mag(omega);
00103             omega /= magOmega+SMALL;
00104             vector n0 = omega ^ Sf0;
00105             scalar lam = ((Cf - Cf0) & Sf)/(n0 & Sf);
00106             vector r0 = Cf0 + lam*n0;
00107 
00108             // solve '(p - r0) & Sfp = 0', where
00109             // p = from + lambda*(to - from)
00110             // Sfp = Sf0 + lambda*(Sf - Sf0)
00111             // which results in the quadratic eq.
00112             // a*lambda^2 + b*lambda + c = 0
00113             vector alpha = from - r0;
00114             vector beta = to - from;
00115             scalar a = beta & (Sf - Sf0);
00116             scalar b = (alpha & (Sf - Sf0)) + (beta & Sf0);
00117             scalar c = alpha & Sf0;
00118 
00119             if (mag(a) > SMALL)
00120             {
00121                 // solve the second order polynomial
00122                 scalar ap = b/a;
00123                 scalar bp = c/a;
00124                 scalar cp = ap*ap - 4.0*bp;
00125 
00126                 if (cp < 0.0)
00127                 {
00128                     // imaginary roots only
00129                     return GREAT;
00130                 }
00131                 else
00132                 {
00133                     scalar l1 = -0.5*(ap - ::sqrt(cp));
00134                     scalar l2 = -0.5*(ap + ::sqrt(cp));
00135 
00136                     // one root is around 0-1, while
00137                     // the other is very large in mag
00138                     if (mag(l1) < mag(l2))
00139                     {
00140                         return l1;
00141                     }
00142                     else
00143                     {
00144                         return l2;
00145                     }
00146                 }
00147             }
00148             else
00149             {
00150                 // when a==0, solve the first order polynomial
00151                 return (-c/b);
00152             }
00153         }
00154         else // no rotation
00155         {
00156             vector alpha = from - Cf0;
00157             vector beta = to - from - (Cf - Cf0);
00158             scalar lambdaNominator = alpha & Sf;
00159             scalar lambdaDenominator = beta & Sf;
00160 
00161             // check if trajectory is parallel to face
00162             if (mag(lambdaDenominator) < SMALL)
00163             {
00164                 if (lambdaDenominator < 0.0)
00165                 {
00166                     lambdaDenominator = -SMALL;
00167                 }
00168                 else
00169                 {
00170                     lambdaDenominator = SMALL;
00171                 }
00172             }
00173             
00174             return (-lambdaNominator/lambdaDenominator);
00175         }
00176     }
00177     else
00178     {
00179         // mesh is static and stepFraction is not needed
00180         return lambda(from, to, facei);
00181     }
00182 }
00183 
00184 
00185 template<class particleType>
00186 inline scalar particle<particleType>::lambda
00187 (
00188     const vector& from,
00189     const vector& to,
00190     const label facei
00191 )
00192 {
00193     const polyMesh& mesh = cloud_.polyMesh_;
00194 
00195     vector Sf = mesh.faceAreas()[facei];
00196     Sf /= mag(Sf);
00197     vector Cf = mesh.faceCentres()[facei];
00198 
00199     // move reference point for wall
00200     if (!cloud_.internalFace(facei))
00201     {
00202         const vector& C = mesh.cellCentres()[celli_];
00203         scalar CCf = mag((C - Cf) & Sf);
00204         // check if distance between cell centre and face centre
00205         // is larger than wallImpactDistance
00206         if
00207         (
00208             CCf
00209           > static_cast<const particleType&>(*this).wallImpactDistance(Sf)
00210         )
00211         {
00212             Cf -= static_cast<const particleType&>(*this)
00213                 .wallImpactDistance(Sf)*Sf;
00214         }
00215     }
00216 
00217     scalar lambdaNominator = (Cf - from) & Sf;
00218     scalar lambdaDenominator = (to - from) & Sf;
00219         
00220     // check if trajectory is parallel to face
00221     if (mag(lambdaDenominator) < SMALL)
00222     {
00223         if (lambdaDenominator < 0.0)
00224         {
00225             lambdaDenominator = -SMALL;
00226         }
00227         else
00228         {
00229             lambdaDenominator = SMALL;
00230         }
00231     }
00232 
00233     return lambdaNominator/lambdaDenominator;
00234 }
00235 
00236 
00237 template<class particleType>
00238 inline bool particle<particleType>::inCell()
00239 {
00240     labelList faces = findFaces(position_);
00241 
00242     return (!faces.size());
00243 }
00244 
00245 
00246 template<class particleType>
00247 inline bool particle<particleType>::inCell
00248 (
00249     const vector& position,
00250     const label celli,
00251     const scalar stepFraction
00252 )
00253 {
00254     labelList faces = findFaces(position, celli, stepFraction);
00255 
00256     return (!faces.size());
00257 }
00258 
00259 
00260 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00261 
00262 //- Return reference to the particle cloud
00263 template<class particleType>
00264 inline const Cloud<particleType>& particle<particleType>::cloud() const
00265 {
00266     return cloud_;
00267 }
00268 
00269 
00270 template<class particleType>
00271 inline const vector& particle<particleType>::position() const
00272 {
00273     return position_;
00274 }
00275 
00276 
00277 template<class particleType>
00278 inline label particle<particleType>::cell() const
00279 {
00280     return celli_;
00281 }
00282 
00283 
00284 template<class particleType>
00285 inline label particle<particleType>::face() const
00286 {
00287     return facei_;
00288 }
00289 
00290 
00291 //- Is the particle on a boundary face?
00292 template<class particleType>
00293 inline bool particle<particleType>::onBoundary() const
00294 {
00295     return facei_ != -1 && facei_ >= cloud_.pMesh().nInternalFaces();
00296 }
00297 
00298 
00299 template<class particleType>
00300 inline scalar& particle<particleType>::stepFraction()
00301 {
00302     return stepFraction_;
00303 }
00304 
00305 
00306 template<class particleType>
00307 inline scalar particle<particleType>::stepFraction() const
00308 {
00309     return stepFraction_;
00310 }
00311 
00312 
00313 template<class particleType>
00314 inline bool particle<particleType>::softImpact() const
00315 {
00316     return false;
00317 }
00318 
00319 
00320 template<class particleType>
00321 inline label particle<particleType>::patch(const label facei) const
00322 {
00323     return cloud_.facePatch(facei);
00324 }
00325 
00326 
00327 template<class particleType>
00328 inline label particle<particleType>::patchFace
00329 (
00330     const label patchi,
00331     const label facei
00332 ) const
00333 {
00334     return cloud_.patchFace(patchi, facei);
00335 }
00336 
00337 
00338 template<class particleType>
00339 inline scalar particle<particleType>::wallImpactDistance(const vector&) const
00340 {
00341     return 0.0;
00342 }
00343 
00344 
00345 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00346 
00347 } // End namespace Foam
00348 
00349 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd