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

linearUpwindV.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 "linearUpwindV.H"
00027 #include <finiteVolume/fvMesh.H>
00028 #include <finiteVolume/volFields.H>
00029 #include <finiteVolume/surfaceFields.H>
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 template<class Type>
00034 Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
00035 Foam::linearUpwindV<Type>::correction
00036 (
00037     const GeometricField<Type, fvPatchField, volMesh>& vf
00038 ) const
00039 {
00040    const fvMesh& mesh = this->mesh();
00041 
00042    tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsfCorr
00043    (
00044        new GeometricField<Type, fvsPatchField, surfaceMesh>
00045        (
00046            IOobject
00047            (
00048                vf.name(),
00049                mesh.time().timeName(),
00050                mesh
00051            ),
00052            mesh,
00053            dimensioned<Type>
00054            (
00055                vf.name(),
00056                vf.dimensions(),
00057                pTraits<Type>::zero
00058            )
00059        )
00060    );
00061 
00062    GeometricField<Type, fvsPatchField, surfaceMesh>& sfCorr = tsfCorr();
00063 
00064    const surfaceScalarField& faceFlux = this->faceFlux_;
00065    const surfaceScalarField& w = mesh.weights();
00066 
00067    const labelList& own = mesh.owner();
00068    const labelList& nei = mesh.neighbour();
00069 
00070    const vectorField& C = mesh.C();
00071    const vectorField& Cf = mesh.Cf();
00072 
00073    GeometricField
00074        <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
00075        gradVf = gradScheme_().grad(vf);
00076 
00077    forAll(faceFlux, facei)
00078    {
00079        vector maxCorr;
00080 
00081        if (faceFlux[facei] > 0.0)
00082        {
00083            maxCorr =
00084                (1.0 - w[facei])
00085                *(vf[nei[facei]] - vf[own[facei]]);
00086 
00087            sfCorr[facei] =
00088                (Cf[facei] - C[own[facei]]) & gradVf[own[facei]];
00089        }
00090        else
00091        {
00092            maxCorr =
00093                w[facei]*(vf[own[facei]] - vf[nei[facei]]);
00094 
00095            sfCorr[facei] =
00096                (Cf[facei] - C[nei[facei]]) & gradVf[nei[facei]];
00097        }
00098 
00099        scalar sfCorrs = magSqr(sfCorr[facei]);
00100        scalar maxCorrs = sfCorr[facei] & maxCorr;
00101 
00102        if (sfCorrs > 0)
00103        {
00104            if (maxCorrs < 0)
00105            {
00106                sfCorr[facei] = vector::zero;
00107            }
00108            else if (sfCorrs > maxCorrs)
00109            {
00110                sfCorr[facei] *= maxCorrs/(sfCorrs + VSMALL);
00111            }
00112        }
00113        else if (sfCorrs < 0)
00114        {
00115            if (maxCorrs > 0)
00116            {
00117                sfCorr[facei] = vector::zero;
00118            }
00119            else if (sfCorrs < maxCorrs)
00120            {
00121                sfCorr[facei] *= maxCorrs/(sfCorrs - VSMALL);
00122            }
00123        }
00124    }
00125 
00126    return tsfCorr;
00127 }
00128 
00129 
00130 namespace Foam
00131 {
00132     makelimitedSurfaceInterpolationTypeScheme(linearUpwindV, vector)
00133 }
00134 
00135 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines