FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

faceMDLimitedGrads.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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023     
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "faceMDLimitedGrad.H"
00027 #include <finiteVolume/cellMDLimitedGrad.H>
00028 #include <finiteVolume/gaussGrad.H>
00029 #include <finiteVolume/fvMesh.H>
00030 #include <finiteVolume/volMesh.H>
00031 #include <finiteVolume/surfaceMesh.H>
00032 #include <finiteVolume/volFields.H>
00033 #include <finiteVolume/fixedValueFvPatchFields.H>
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 
00042 namespace fv
00043 {
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 makeFvGradScheme(faceMDLimitedGrad)
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 // FaceLimited scalar gradient
00052 template<>
00053 tmp<volVectorField> faceMDLimitedGrad<scalar>::grad
00054 (
00055     const volScalarField& vsf
00056 ) const
00057 {
00058     const fvMesh& mesh = vsf.mesh();
00059 
00060     tmp<volVectorField> tGrad = basicGradScheme_().grad(vsf);
00061 
00062     if (k_ < SMALL)
00063     {
00064         return tGrad;
00065     }
00066 
00067     volVectorField& g = tGrad();
00068 
00069     const unallocLabelList& owner = mesh.owner();
00070     const unallocLabelList& neighbour = mesh.neighbour();
00071 
00072     const volVectorField& C = mesh.C();
00073     const surfaceVectorField& Cf = mesh.Cf();
00074 
00075     scalar rk = (1.0/k_ - 1.0);
00076 
00077     forAll(owner, facei)
00078     {
00079         label own = owner[facei];
00080         label nei = neighbour[facei];
00081 
00082         scalar vsfOwn = vsf[own];
00083         scalar vsfNei = vsf[nei];
00084 
00085         scalar maxFace = max(vsfOwn, vsfNei);
00086         scalar minFace = min(vsfOwn, vsfNei);
00087 
00088         if (k_ < 1.0)
00089         {
00090             scalar maxMinFace = rk*(maxFace - minFace);
00091             maxFace += maxMinFace;
00092             minFace -= maxMinFace;
00093         }
00094 
00095         // owner side
00096         cellMDLimitedGrad<scalar>::limitFace
00097         (
00098             g[own],
00099             maxFace - vsfOwn,
00100             minFace - vsfOwn,
00101             Cf[facei] - C[own]
00102         );
00103 
00104         // neighbour side
00105         cellMDLimitedGrad<scalar>::limitFace
00106         (
00107             g[nei],
00108             maxFace - vsfNei,
00109             minFace - vsfNei,
00110             Cf[facei] - C[nei]
00111         );
00112     }
00113 
00114     const volScalarField::GeometricBoundaryField& bsf = vsf.boundaryField();
00115 
00116     forAll(bsf, patchi)
00117     {
00118         const fvPatchScalarField& psf = bsf[patchi];
00119 
00120         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00121         const vectorField& pCf = Cf.boundaryField()[patchi];
00122 
00123         if (psf.coupled())
00124         {
00125             scalarField psfNei = psf.patchNeighbourField();
00126 
00127             forAll(pOwner, pFacei)
00128             {
00129                 label own = pOwner[pFacei];
00130 
00131                 scalar vsfOwn = vsf[own];
00132                 scalar vsfNei = psfNei[pFacei];
00133 
00134                 scalar maxFace = max(vsfOwn, vsfNei);
00135                 scalar minFace = min(vsfOwn, vsfNei);
00136 
00137                 if (k_ < 1.0)
00138                 {
00139                     scalar maxMinFace = rk*(maxFace - minFace);
00140                     maxFace += maxMinFace;
00141                     minFace -= maxMinFace;
00142                 }
00143 
00144                 cellMDLimitedGrad<scalar>::limitFace
00145                 (
00146                     g[own],
00147                     maxFace - vsfOwn,
00148                     minFace - vsfOwn,
00149                     pCf[pFacei] - C[own]
00150                 );
00151             }
00152         }
00153         else if (psf.fixesValue())
00154         {
00155             forAll(pOwner, pFacei)
00156             {
00157                 label own = pOwner[pFacei];
00158 
00159                 scalar vsfOwn = vsf[own];
00160                 scalar vsfNei = psf[pFacei];
00161 
00162                 scalar maxFace = max(vsfOwn, vsfNei);
00163                 scalar minFace = min(vsfOwn, vsfNei);
00164 
00165                 if (k_ < 1.0)
00166                 {
00167                     scalar maxMinFace = rk*(maxFace - minFace);
00168                     maxFace += maxMinFace;
00169                     minFace -= maxMinFace;
00170                 }
00171 
00172                 cellMDLimitedGrad<scalar>::limitFace
00173                 (
00174                     g[own],
00175                     maxFace - vsfOwn,
00176                     minFace - vsfOwn,
00177                     pCf[pFacei] - C[own]
00178                 );
00179             }
00180         }
00181     }
00182 
00183     g.correctBoundaryConditions();
00184     gaussGrad<scalar>::correctBoundaryConditions(vsf, g);
00185 
00186     return tGrad;
00187 }
00188 
00189 
00190 template<>
00191 tmp<volTensorField> faceMDLimitedGrad<vector>::grad
00192 (
00193     const volVectorField& vvf
00194 ) const
00195 {
00196     const fvMesh& mesh = vvf.mesh();
00197 
00198     tmp<volTensorField> tGrad = basicGradScheme_().grad(vvf);
00199 
00200     if (k_ < SMALL)
00201     {
00202         return tGrad;
00203     }
00204 
00205     volTensorField& g = tGrad();
00206 
00207     const unallocLabelList& owner = mesh.owner();
00208     const unallocLabelList& neighbour = mesh.neighbour();
00209 
00210     const volVectorField& C = mesh.C();
00211     const surfaceVectorField& Cf = mesh.Cf();
00212 
00213     scalar rk = (1.0/k_ - 1.0);
00214 
00215     forAll(owner, facei)
00216     {
00217         label own = owner[facei];
00218         label nei = neighbour[facei];
00219 
00220         vector vvfOwn = vvf[own];
00221         vector vvfNei = vvf[nei];
00222 
00223         vector maxFace = max(vvfOwn, vvfNei);
00224         vector minFace = min(vvfOwn, vvfNei);
00225 
00226         if (k_ < 1.0)
00227         {
00228             vector maxMinFace = rk*(maxFace - minFace);
00229             maxFace += maxMinFace;
00230             minFace -= maxMinFace;
00231         }
00232 
00233         // owner side
00234         cellMDLimitedGrad<vector>::limitFace
00235         (
00236             g[own],
00237             maxFace - vvfOwn,
00238             minFace - vvfOwn,
00239             Cf[facei] - C[nei]
00240         );
00241 
00242 
00243         // neighbour side
00244         cellMDLimitedGrad<vector>::limitFace
00245         (
00246             g[nei],
00247             maxFace - vvfNei,
00248             minFace - vvfNei,
00249             Cf[facei] - C[nei]
00250         );
00251     }
00252 
00253 
00254     const volVectorField::GeometricBoundaryField& bvf = vvf.boundaryField();
00255 
00256     forAll(bvf, patchi)
00257     {
00258         const fvPatchVectorField& psf = bvf[patchi];
00259 
00260         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00261         const vectorField& pCf = Cf.boundaryField()[patchi];
00262 
00263         if (psf.coupled())
00264         {
00265             vectorField psfNei = psf.patchNeighbourField();
00266 
00267             forAll(pOwner, pFacei)
00268             {
00269                 label own = pOwner[pFacei];
00270 
00271                 vector vvfOwn = vvf[own];
00272                 vector vvfNei = psfNei[pFacei];
00273 
00274                 vector maxFace = max(vvfOwn, vvfNei);
00275                 vector minFace = min(vvfOwn, vvfNei);
00276 
00277                 if (k_ < 1.0)
00278                 {
00279                     vector maxMinFace = rk*(maxFace - minFace);
00280                     maxFace += maxMinFace;
00281                     minFace -= maxMinFace;
00282                 }
00283 
00284                 cellMDLimitedGrad<vector>::limitFace
00285                 (
00286                     g[own],
00287                     maxFace - vvfOwn, minFace - vvfOwn,
00288                     pCf[pFacei] - C[own]
00289                 );
00290             }
00291         }
00292         else if (psf.fixesValue())
00293         {
00294             forAll(pOwner, pFacei)
00295             {
00296                 label own = pOwner[pFacei];
00297 
00298                 vector vvfOwn = vvf[own];
00299                 vector vvfNei = psf[pFacei];
00300 
00301                 vector maxFace = max(vvfOwn, vvfNei);
00302                 vector minFace = min(vvfOwn, vvfNei);
00303 
00304                 if (k_ < 1.0)
00305                 {
00306                     vector maxMinFace = rk*(maxFace - minFace);
00307                     maxFace += maxMinFace;
00308                     minFace -= maxMinFace;
00309                 }
00310 
00311                 cellMDLimitedGrad<vector>::limitFace
00312                 (
00313                     g[own],
00314                     maxFace - vvfOwn,
00315                     minFace - vvfOwn,
00316                     pCf[pFacei] - C[own]
00317                 );
00318             }
00319         }
00320     }
00321 
00322     g.correctBoundaryConditions();
00323     gaussGrad<vector>::correctBoundaryConditions(vvf, g);
00324 
00325     return tGrad;
00326 }
00327 
00328 
00329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00330 
00331 } // End namespace fv
00332 
00333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00334 
00335 } // End namespace Foam
00336 
00337 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines