1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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 "linearUpwind.H"
29 #include "zeroGradientFvPatchField.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
35 Foam::linearUpwind<Type>::correction
37 const GeometricField<Type, fvPatchField, volMesh>& vf
40 const fvMesh& mesh = this->mesh();
42 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsfCorr
44 new GeometricField<Type, fvsPatchField, surfaceMesh>
48 "linearUpwindCorrection(" + vf.name() + ')',
49 mesh.time().timeName(),
56 dimensioned<Type>(vf.name(), vf.dimensions(), pTraits<Type>::zero)
60 GeometricField<Type, fvsPatchField, surfaceMesh>& sfCorr = tsfCorr();
62 const surfaceScalarField& faceFlux = this->faceFlux_;
64 const labelList& owner = mesh.owner();
65 const labelList& neighbour = mesh.neighbour();
67 const volVectorField& C = mesh.C();
68 const surfaceVectorField& Cf = mesh.Cf();
71 <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
72 gradVf = gradScheme_().grad(vf);
74 // Note: in order for the patchNeighbourField to be correct on coupled
75 // boundaries, correctBoundaryConditions needs to be called.
76 // The call shall be moved into the library fvc operators
77 gradVf.correctBoundaryConditions();
79 forAll(faceFlux, facei)
81 if (faceFlux[facei] > 0)
83 label own = owner[facei];
84 sfCorr[facei] = (Cf[facei] - C[own]) & gradVf[own];
88 label nei = neighbour[facei];
89 sfCorr[facei] = (Cf[facei] - C[nei]) & gradVf[nei];
94 typename GeometricField<Type, fvsPatchField, surfaceMesh>::
95 GeometricBoundaryField& bSfCorr = sfCorr.boundaryField();
97 forAll(bSfCorr, patchi)
99 fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
101 if (pSfCorr.coupled())
103 const fvPatch& p = mesh.boundary()[patchi];
105 const unallocLabelList& pOwner = p.faceCells();
107 const vectorField& pCf = Cf.boundaryField()[patchi];
109 const scalarField& pFaceFlux = faceFlux.boundaryField()[patchi];
111 Field<typename outerProduct<vector, Type>::type> pGradVfNei =
112 gradVf.boundaryField()[patchi].patchNeighbourField();
114 // Build the d-vectors
115 // Better version of d-vectors: Zeljko Tukovic, 25/Apr/2010
116 vectorField pd = p.delta();
118 forAll(pOwner, facei)
120 label own = pOwner[facei];
122 if (pFaceFlux[facei] > 0)
124 pSfCorr[facei] = (pCf[facei] - C[own]) & gradVf[own];
129 (pCf[facei] - pd[facei] - C[own]) & pGradVfNei[facei];
141 //makelimitedSurfaceInterpolationScheme(linearUpwind)
142 makelimitedSurfaceInterpolationTypeScheme(linearUpwind, scalar)
143 makelimitedSurfaceInterpolationTypeScheme(linearUpwind, vector)
146 // ************************************************************************* //