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

cellLimitedGrads.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 "cellLimitedGrad.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(cellLimitedGrad)
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 template<>
00052 inline void cellLimitedGrad<scalar>::limitFace
00053 (
00054     scalar& limiter,
00055     const scalar& maxDelta,
00056     const scalar& minDelta,
00057     const scalar& extrapolate
00058 )
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 template<class Type>
00071 inline void cellLimitedGrad<Type>::limitFace
00072 (
00073     Type& limiter,
00074     const Type& maxDelta,
00075     const Type& minDelta,
00076     const Type& extrapolate
00077 )
00078 {
00079     for(direction cmpt=0; cmpt<Type::nComponents; cmpt++)
00080     {
00081         cellLimitedGrad<scalar>::limitFace
00082         (
00083             limiter.component(cmpt),
00084             maxDelta.component(cmpt),
00085             minDelta.component(cmpt),
00086             extrapolate.component(cmpt)
00087         );
00088     }
00089 }
00090 
00091 
00092 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00093 
00094 template<>
00095 tmp<volVectorField> cellLimitedGrad<scalar>::grad
00096 (
00097     const volScalarField& vsf
00098 ) const
00099 {
00100     const fvMesh& mesh = vsf.mesh();
00101 
00102     tmp<volVectorField> tGrad = basicGradScheme_().grad(vsf);
00103 
00104     if (k_ < SMALL)
00105     {
00106         return tGrad;
00107     }
00108 
00109     volVectorField& g = tGrad();
00110 
00111     const unallocLabelList& owner = mesh.owner();
00112     const unallocLabelList& neighbour = mesh.neighbour();
00113 
00114     const volVectorField& C = mesh.C();
00115     const surfaceVectorField& Cf = mesh.Cf();
00116 
00117     scalarField maxVsf(vsf.internalField());
00118     scalarField minVsf(vsf.internalField());
00119 
00120     forAll(owner, facei)
00121     {
00122         label own = owner[facei];
00123         label nei = neighbour[facei];
00124 
00125         scalar vsfOwn = vsf[own];
00126         scalar vsfNei = vsf[nei];
00127 
00128         maxVsf[own] = max(maxVsf[own], vsfNei);
00129         minVsf[own] = min(minVsf[own], vsfNei);
00130 
00131         maxVsf[nei] = max(maxVsf[nei], vsfOwn);
00132         minVsf[nei] = min(minVsf[nei], vsfOwn);
00133     }
00134 
00135 
00136     const volScalarField::GeometricBoundaryField& bsf = vsf.boundaryField();
00137 
00138     forAll(bsf, patchi)
00139     {
00140         const fvPatchScalarField& psf = bsf[patchi];
00141 
00142         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00143 
00144         if (psf.coupled())
00145         {
00146             scalarField psfNei = psf.patchNeighbourField();
00147 
00148             forAll(pOwner, pFacei)
00149             {
00150                 label own = pOwner[pFacei];
00151                 scalar vsfNei = psfNei[pFacei];
00152 
00153                 maxVsf[own] = max(maxVsf[own], vsfNei);
00154                 minVsf[own] = min(minVsf[own], vsfNei);
00155             }
00156         }
00157         else
00158         {
00159             forAll(pOwner, pFacei)
00160             {
00161                 label own = pOwner[pFacei];
00162                 scalar vsfNei = psf[pFacei];
00163 
00164                 maxVsf[own] = max(maxVsf[own], vsfNei);
00165                 minVsf[own] = min(minVsf[own], vsfNei);
00166             }
00167         }
00168     }
00169 
00170     maxVsf -= vsf;
00171     minVsf -= vsf;
00172 
00173     if (k_ < 1.0)
00174     {
00175         scalarField maxMinVsf = (1.0/k_ - 1.0)*(maxVsf - minVsf);
00176         maxVsf += maxMinVsf;
00177         minVsf -= maxMinVsf;
00178 
00179         //maxVsf *= 1.0/k_;
00180         //minVsf *= 1.0/k_;
00181     }
00182 
00183 
00184     // create limiter
00185     scalarField limiter(vsf.internalField().size(), 1.0);
00186 
00187     forAll(owner, facei)
00188     {
00189         label own = owner[facei];
00190         label nei = neighbour[facei];
00191 
00192         // owner side
00193         limitFace
00194         (
00195             limiter[own],
00196             maxVsf[own],
00197             minVsf[own],
00198             (Cf[facei] - C[own]) & g[own]
00199         );
00200 
00201         // neighbour side
00202         limitFace
00203         (
00204             limiter[nei],
00205             maxVsf[nei],
00206             minVsf[nei],
00207             (Cf[facei] - C[nei]) & g[nei]
00208         );
00209     }
00210 
00211     forAll(bsf, patchi)
00212     {
00213         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00214         const vectorField& pCf = Cf.boundaryField()[patchi];
00215 
00216         forAll(pOwner, pFacei)
00217         {
00218             label own = pOwner[pFacei];
00219 
00220             limitFace
00221             (
00222                 limiter[own],
00223                 maxVsf[own],
00224                 minVsf[own],
00225                 (pCf[pFacei] - C[own]) & g[own]
00226             );
00227         }
00228     }
00229 
00230     if (fv::debug)
00231     {
00232         Info<< "gradient limiter for: " << vsf.name()
00233             << " max = " << gMax(limiter)
00234             << " min = " << gMin(limiter)
00235             << " average: " << gAverage(limiter) << endl;
00236     }
00237 
00238     g.internalField() *= limiter;
00239     g.correctBoundaryConditions();
00240     gaussGrad<scalar>::correctBoundaryConditions(vsf, g);
00241 
00242     return tGrad;
00243 }
00244 
00245 
00246 template<>
00247 tmp<volTensorField> cellLimitedGrad<vector>::grad
00248 (
00249     const volVectorField& vsf
00250 ) const
00251 {
00252     const fvMesh& mesh = vsf.mesh();
00253 
00254     tmp<volTensorField> tGrad = basicGradScheme_().grad(vsf);
00255 
00256     if (k_ < SMALL)
00257     {
00258         return tGrad;
00259     }
00260 
00261     volTensorField& g = tGrad();
00262 
00263     const unallocLabelList& owner = mesh.owner();
00264     const unallocLabelList& neighbour = mesh.neighbour();
00265 
00266     const volVectorField& C = mesh.C();
00267     const surfaceVectorField& Cf = mesh.Cf();
00268 
00269     vectorField maxVsf(vsf.internalField());
00270     vectorField minVsf(vsf.internalField());
00271 
00272     forAll(owner, facei)
00273     {
00274         label own = owner[facei];
00275         label nei = neighbour[facei];
00276 
00277         const vector& vsfOwn = vsf[own];
00278         const vector& vsfNei = vsf[nei];
00279 
00280         maxVsf[own] = max(maxVsf[own], vsfNei);
00281         minVsf[own] = min(minVsf[own], vsfNei);
00282 
00283         maxVsf[nei] = max(maxVsf[nei], vsfOwn);
00284         minVsf[nei] = min(minVsf[nei], vsfOwn);
00285     }
00286 
00287 
00288     const volVectorField::GeometricBoundaryField& bsf = vsf.boundaryField();
00289 
00290     forAll(bsf, patchi)
00291     {
00292         const fvPatchVectorField& psf = bsf[patchi];
00293         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00294 
00295         if (psf.coupled())
00296         {
00297             vectorField psfNei = psf.patchNeighbourField();
00298 
00299             forAll(pOwner, pFacei)
00300             {
00301                 label own = pOwner[pFacei];
00302                 const vector& vsfNei = psfNei[pFacei];
00303 
00304                 maxVsf[own] = max(maxVsf[own], vsfNei);
00305                 minVsf[own] = min(minVsf[own], vsfNei);
00306             }
00307         }
00308         else
00309         {
00310             forAll(pOwner, pFacei)
00311             {
00312                 label own = pOwner[pFacei];
00313                 const vector& vsfNei = psf[pFacei];
00314 
00315                 maxVsf[own] = max(maxVsf[own], vsfNei);
00316                 minVsf[own] = min(minVsf[own], vsfNei);
00317             }
00318         }
00319     }
00320 
00321     maxVsf -= vsf;
00322     minVsf -= vsf;
00323 
00324     if (k_ < 1.0)
00325     {
00326         vectorField maxMinVsf = (1.0/k_ - 1.0)*(maxVsf - minVsf);
00327         maxVsf += maxMinVsf;
00328         minVsf -= maxMinVsf;
00329 
00330         //maxVsf *= 1.0/k_;
00331         //minVsf *= 1.0/k_;
00332     }
00333 
00334 
00335     // create limiter
00336     vectorField limiter(vsf.internalField().size(), vector::one);
00337 
00338     forAll(owner, facei)
00339     {
00340         label own = owner[facei];
00341         label nei = neighbour[facei];
00342 
00343         // owner side
00344         limitFace
00345         (
00346             limiter[own],
00347             maxVsf[own],
00348             minVsf[own],
00349             (Cf[facei] - C[own]) & g[own]
00350         );
00351 
00352         // neighbour side
00353         limitFace
00354         (
00355             limiter[nei],
00356             maxVsf[nei],
00357             minVsf[nei],
00358             (Cf[facei] - C[nei]) & g[nei]
00359         );
00360     }
00361 
00362     forAll(bsf, patchi)
00363     {
00364         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00365         const vectorField& pCf = Cf.boundaryField()[patchi];
00366 
00367         forAll(pOwner, pFacei)
00368         {
00369             label own = pOwner[pFacei];
00370 
00371             limitFace
00372             (
00373                 limiter[own],
00374                 maxVsf[own],
00375                 minVsf[own],
00376                 ((pCf[pFacei] - C[own]) & g[own])
00377             );
00378         }
00379     }
00380 
00381     if (fv::debug)
00382     {
00383         Info<< "gradient limiter for: " << vsf.name()
00384             << " max = " << gMax(limiter)
00385             << " min = " << gMin(limiter)
00386             << " average: " << gAverage(limiter) << endl;
00387     }
00388 
00389     tensorField& gIf = g.internalField();
00390 
00391     forAll(gIf, celli)
00392     {
00393         gIf[celli].x() = cmptMultiply(limiter[celli], gIf[celli].x());
00394         gIf[celli].y() = cmptMultiply(limiter[celli], gIf[celli].y());
00395         gIf[celli].z() = cmptMultiply(limiter[celli], gIf[celli].z());
00396     }
00397 
00398     g.correctBoundaryConditions();
00399     gaussGrad<vector>::correctBoundaryConditions(vsf, g);
00400 
00401     return tGrad;
00402 }
00403 
00404 
00405 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00406 
00407 } // End namespace fv
00408 
00409 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00410 
00411 } // End namespace Foam
00412 
00413 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd