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

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