OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

faceLimitedGrads.C

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-2009 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 "faceLimitedGrad.H"
00028 #include "gaussGrad.H"
00029 #include "fvMesh.H"
00030 #include "volMesh.H"
00031 #include "surfaceMesh.H"
00032 #include "volFields.H"
00033 #include "fixedValueFvPatchFields.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 
00042 namespace fv
00043 {
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 makeFvGradScheme(faceLimitedGrad)
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 template<class Type>
00052 inline void faceLimitedGrad<Type>::limitFace
00053 (
00054     scalar& limiter,
00055     const scalar maxDelta,
00056     const scalar minDelta,
00057     const scalar extrapolate
00058 ) const
00059 {
00060     if (extrapolate > maxDelta + VSMALL)
00061     {
00062         limiter = min(limiter, maxDelta/extrapolate);
00063     }
00064     else if (extrapolate < minDelta - VSMALL)
00065     {
00066         limiter = min(limiter, minDelta/extrapolate);
00067     }
00068 }
00069 
00070 
00071 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00072 
00073 template<>
00074 tmp<volVectorField> faceLimitedGrad<scalar>::grad
00075 (
00076     const volScalarField& vsf
00077 ) const
00078 {
00079     const fvMesh& mesh = vsf.mesh();
00080 
00081     tmp<volVectorField> tGrad = basicGradScheme_().grad(vsf);
00082 
00083     if (k_ < SMALL)
00084     {
00085         return tGrad;
00086     }
00087 
00088     volVectorField& g = tGrad();
00089 
00090     const unallocLabelList& owner = mesh.owner();
00091     const unallocLabelList& neighbour = mesh.neighbour();
00092 
00093     const volVectorField& C = mesh.C();
00094     const surfaceVectorField& Cf = mesh.Cf();
00095 
00096     // create limiter
00097     scalarField limiter(vsf.internalField().size(), 1.0);
00098 
00099     scalar rk = (1.0/k_ - 1.0);
00100 
00101     forAll(owner, facei)
00102     {
00103         label own = owner[facei];
00104         label nei = neighbour[facei];
00105 
00106         scalar vsfOwn = vsf[own];
00107         scalar vsfNei = vsf[nei];
00108 
00109         scalar maxFace = max(vsfOwn, vsfNei);
00110         scalar minFace = min(vsfOwn, vsfNei);
00111         scalar maxMinFace = rk*(maxFace - minFace);
00112         maxFace += maxMinFace;
00113         minFace -= maxMinFace;
00114 
00115         // owner side
00116         limitFace
00117         (
00118             limiter[own],
00119             maxFace - vsfOwn, minFace - vsfOwn,
00120             (Cf[facei] - C[own]) & g[own]
00121         );
00122 
00123         // neighbour side
00124         limitFace
00125         (
00126             limiter[nei],
00127             maxFace - vsfNei, minFace - vsfNei,
00128             (Cf[facei] - C[nei]) & g[nei]
00129         );
00130     }
00131 
00132     const volScalarField::GeometricBoundaryField& bsf = vsf.boundaryField();
00133 
00134     forAll(bsf, patchi)
00135     {
00136         const fvPatchScalarField& psf = bsf[patchi];
00137 
00138         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00139         const vectorField& pCf = Cf.boundaryField()[patchi];
00140 
00141         if (psf.coupled())
00142         {
00143             scalarField psfNei = psf.patchNeighbourField();
00144 
00145             forAll(pOwner, pFacei)
00146             {
00147                 label own = pOwner[pFacei];
00148 
00149                 scalar vsfOwn = vsf[own];
00150                 scalar vsfNei = psfNei[pFacei];
00151 
00152                 scalar maxFace = max(vsfOwn, vsfNei);
00153                 scalar minFace = min(vsfOwn, vsfNei);
00154                 scalar maxMinFace = rk*(maxFace - minFace);
00155                 maxFace += maxMinFace;
00156                 minFace -= maxMinFace;
00157 
00158                 limitFace
00159                 (
00160                     limiter[own],
00161                     maxFace - vsfOwn, minFace - vsfOwn,
00162                     (pCf[pFacei] - C[own]) & g[own]
00163                 );
00164             }
00165         }
00166         else if (psf.fixesValue())
00167         {
00168             forAll(pOwner, pFacei)
00169             {
00170                 label own = pOwner[pFacei];
00171 
00172                 scalar vsfOwn = vsf[own];
00173                 scalar vsfNei = psf[pFacei];
00174 
00175                 scalar maxFace = max(vsfOwn, vsfNei);
00176                 scalar minFace = min(vsfOwn, vsfNei);
00177                 scalar maxMinFace = rk*(maxFace - minFace);
00178                 maxFace += maxMinFace;
00179                 minFace -= maxMinFace;
00180 
00181                 limitFace
00182                 (
00183                     limiter[own],
00184                     maxFace - vsfOwn, minFace - vsfOwn,
00185                     (pCf[pFacei] - C[own]) & g[own]
00186                 );
00187             }
00188         }
00189     }
00190 
00191     if (fv::debug)
00192     {
00193         Info<< "gradient limiter for: " << vsf.name()
00194             << " max = " << gMax(limiter)
00195             << " min = " << gMin(limiter)
00196             << " average: " << gAverage(limiter) << endl;
00197     }
00198 
00199     g.internalField() *= limiter;
00200     g.correctBoundaryConditions();
00201     gaussGrad<scalar>::correctBoundaryConditions(vsf, g);
00202 
00203     return tGrad;
00204 }
00205 
00206 
00207 template<>
00208 tmp<volTensorField> faceLimitedGrad<vector>::grad
00209 (
00210     const volVectorField& vvf
00211 ) const
00212 {
00213     const fvMesh& mesh = vvf.mesh();
00214 
00215     tmp<volTensorField> tGrad = basicGradScheme_().grad(vvf);
00216 
00217     if (k_ < SMALL)
00218     {
00219         return tGrad;
00220     }
00221 
00222     volTensorField& g = tGrad();
00223 
00224     const unallocLabelList& owner = mesh.owner();
00225     const unallocLabelList& neighbour = mesh.neighbour();
00226 
00227     const volVectorField& C = mesh.C();
00228     const surfaceVectorField& Cf = mesh.Cf();
00229 
00230     // create limiter
00231     scalarField limiter(vvf.internalField().size(), 1.0);
00232 
00233     scalar rk = (1.0/k_ - 1.0);
00234 
00235     forAll(owner, facei)
00236     {
00237         label own = owner[facei];
00238         label nei = neighbour[facei];
00239 
00240         vector vvfOwn = vvf[own];
00241         vector vvfNei = vvf[nei];
00242 
00243         // owner side
00244         vector gradf = (Cf[facei] - C[own]) & g[own];
00245 
00246         scalar vsfOwn = gradf & vvfOwn;
00247         scalar vsfNei = gradf & vvfNei;
00248 
00249         scalar maxFace = max(vsfOwn, vsfNei);
00250         scalar minFace = min(vsfOwn, vsfNei);
00251         scalar maxMinFace = rk*(maxFace - minFace);
00252         maxFace += maxMinFace;
00253         minFace -= maxMinFace;
00254 
00255         limitFace
00256         (
00257             limiter[own],
00258             maxFace - vsfOwn, minFace - vsfOwn,
00259             magSqr(gradf)
00260         );
00261 
00262 
00263         // neighbour side
00264         gradf = (Cf[facei] - C[nei]) & g[nei];
00265 
00266         vsfOwn = gradf & vvfOwn;
00267         vsfNei = gradf & vvfNei;
00268 
00269         maxFace = max(vsfOwn, vsfNei);
00270         minFace = min(vsfOwn, vsfNei);
00271 
00272         limitFace
00273         (
00274             limiter[nei],
00275             maxFace - vsfNei, minFace - vsfNei,
00276             magSqr(gradf)
00277         );
00278     }
00279 
00280 
00281     const volVectorField::GeometricBoundaryField& bvf = vvf.boundaryField();
00282 
00283     forAll(bvf, patchi)
00284     {
00285         const fvPatchVectorField& psf = bvf[patchi];
00286 
00287         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00288         const vectorField& pCf = Cf.boundaryField()[patchi];
00289 
00290         if (psf.coupled())
00291         {
00292             vectorField psfNei = psf.patchNeighbourField();
00293 
00294             forAll(pOwner, pFacei)
00295             {
00296                 label own = pOwner[pFacei];
00297 
00298                 vector vvfOwn = vvf[own];
00299                 vector vvfNei = psfNei[pFacei];
00300 
00301                 vector gradf = (pCf[pFacei] - C[own]) & g[own];
00302 
00303                 scalar vsfOwn = gradf & vvfOwn;
00304                 scalar vsfNei = gradf & vvfNei;
00305 
00306                 scalar maxFace = max(vsfOwn, vsfNei);
00307                 scalar minFace = min(vsfOwn, vsfNei);
00308                 scalar maxMinFace = rk*(maxFace - minFace);
00309                 maxFace += maxMinFace;
00310                 minFace -= maxMinFace;
00311 
00312                 limitFace
00313                 (
00314                     limiter[own],
00315                     maxFace - vsfOwn, minFace - vsfOwn,
00316                     magSqr(gradf)
00317                 );
00318             }
00319         }
00320         else if (psf.fixesValue())
00321         {
00322             forAll(pOwner, pFacei)
00323             {
00324                 label own = pOwner[pFacei];
00325 
00326                 vector vvfOwn = vvf[own];
00327                 vector vvfNei = psf[pFacei];
00328 
00329                 vector gradf = (pCf[pFacei] - C[own]) & g[own];
00330 
00331                 scalar vsfOwn = gradf & vvfOwn;
00332                 scalar vsfNei = gradf & vvfNei;
00333 
00334                 scalar maxFace = max(vsfOwn, vsfNei);
00335                 scalar minFace = min(vsfOwn, vsfNei);
00336                 scalar maxMinFace = rk*(maxFace - minFace);
00337                 maxFace += maxMinFace;
00338                 minFace -= maxMinFace;
00339 
00340                 limitFace
00341                 (
00342                     limiter[own],
00343                     maxFace - vsfOwn, minFace - vsfOwn,
00344                     magSqr(gradf)
00345                 );
00346             }
00347         }
00348     }
00349 
00350     if (fv::debug)
00351     {
00352         Info<< "gradient limiter for: " << vvf.name()
00353             << " max = " << gMax(limiter)
00354             << " min = " << gMin(limiter)
00355             << " average: " << gAverage(limiter) << endl;
00356     }
00357 
00358     g.internalField() *= limiter;
00359     g.correctBoundaryConditions();
00360     gaussGrad<vector>::correctBoundaryConditions(vvf, g);
00361 
00362     return tGrad;
00363 }
00364 
00365 
00366 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00367 
00368 } // End namespace fv
00369 
00370 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00371 
00372 } // End namespace Foam
00373 
00374 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd