initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / interpolation / surfaceInterpolation / limitedSchemes / linearUpwind / linearUpwindV.C
blobdb4a31c5519d82e739745e09e46e736c8f1ab170
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "linearUpwindV.H"
28 #include "fvMesh.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 template<class Type>
35 Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
36 Foam::linearUpwindV<Type>::correction
38     const GeometricField<Type, fvPatchField, volMesh>& vf
39 ) const
41    const fvMesh& mesh = this->mesh();
43    tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsfCorr
44    (
45        new GeometricField<Type, fvsPatchField, surfaceMesh>
46        (
47            IOobject
48            (
49                vf.name(),
50                mesh.time().timeName(),
51                mesh
52            ),
53            mesh,
54            dimensioned<Type>
55            (
56                vf.name(),
57                vf.dimensions(),
58                pTraits<Type>::zero
59            )
60        )
61    );
63    GeometricField<Type, fvsPatchField, surfaceMesh>& sfCorr = tsfCorr();
65    const surfaceScalarField& faceFlux = this->faceFlux_;
66    const surfaceScalarField& w = mesh.weights();
68    const labelList& own = mesh.owner();
69    const labelList& nei = mesh.neighbour();
71    const vectorField& C = mesh.C();
72    const vectorField& Cf = mesh.Cf();
74    GeometricField
75        <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
76        gradVf = gradScheme_().grad(vf);
78    forAll(faceFlux, facei)
79    {
80        vector maxCorr;
82        if (faceFlux[facei] > 0.0)
83        {
84            maxCorr =
85                (1.0 - w[facei])
86                *(vf[nei[facei]] - vf[own[facei]]);
88            sfCorr[facei] =
89                (Cf[facei] - C[own[facei]]) & gradVf[own[facei]];
90        }
91        else
92        {
93            maxCorr =
94                w[facei]*(vf[own[facei]] - vf[nei[facei]]);
96            sfCorr[facei] =
97                (Cf[facei] - C[nei[facei]]) & gradVf[nei[facei]];
98        }
100        scalar sfCorrs = magSqr(sfCorr[facei]);
101        scalar maxCorrs = sfCorr[facei] & maxCorr;
103        if (sfCorrs > 0)
104        {
105            if (maxCorrs < 0)
106            {
107                sfCorr[facei] = vector::zero;
108            }
109            else if (sfCorrs > maxCorrs)
110            {
111                sfCorr[facei] *= maxCorrs/(sfCorrs + VSMALL);
112            }
113        }
114        else if (sfCorrs < 0)
115        {
116            if (maxCorrs > 0)
117            {
118                sfCorr[facei] = vector::zero;
119            }
120            else if (sfCorrs < maxCorrs)
121            {
122                sfCorr[facei] *= maxCorrs/(sfCorrs - VSMALL);
123            }
124        }
125    }
127    return tsfCorr;
131 namespace Foam
133     makelimitedSurfaceInterpolationTypeScheme(linearUpwindV, vector)
136 // ************************************************************************* //