fix consistancy of gradient on coupled patches
[openfoam-extend-OpenFOAM-1.6-ext.git] / src / finiteVolume / interpolation / surfaceInterpolation / limitedSchemes / linearUpwind / linearUpwindV.C
blobff6747a65376284e4fd077692da90f745db94fb1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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     // Note: in order for the patchNeighbourField to be correct on coupled
79     // boundaries, correctBoundaryConditions needs to be called.
80     // The call shall be moved into the library fvc operators
81     gradVf.correctBoundaryConditions(); 
83    forAll(faceFlux, facei)
84    {
85        vector maxCorr;
87        if (faceFlux[facei] > 0.0)
88        {
89            maxCorr =
90                (1.0 - w[facei])
91                *(vf[nei[facei]] - vf[own[facei]]);
93            sfCorr[facei] =
94                (Cf[facei] - C[own[facei]]) & gradVf[own[facei]];
95        }
96        else
97        {
98            maxCorr =
99                w[facei]*(vf[own[facei]] - vf[nei[facei]]);
101            sfCorr[facei] =
102                (Cf[facei] - C[nei[facei]]) & gradVf[nei[facei]];
103        }
105        scalar sfCorrs = magSqr(sfCorr[facei]);
106        scalar maxCorrs = sfCorr[facei] & maxCorr;
108        if (sfCorrs > 0)
109        {
110            if (maxCorrs < 0)
111            {
112                sfCorr[facei] = vector::zero;
113            }
114            else if (sfCorrs > maxCorrs)
115            {
116                sfCorr[facei] *= maxCorrs/(sfCorrs + VSMALL);
117            }
118        }
119        else if (sfCorrs < 0)
120        {
121            if (maxCorrs > 0)
122            {
123                sfCorr[facei] = vector::zero;
124            }
125            else if (sfCorrs < maxCorrs)
126            {
127                sfCorr[facei] *= maxCorrs/(sfCorrs - VSMALL);
128            }
129        }
130    }
132    return tsfCorr;
136 namespace Foam
138     makelimitedSurfaceInterpolationTypeScheme(linearUpwindV, vector)
141 // ************************************************************************* //