1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 "resErrorDiv.H"
28 #include <finiteVolume/fvc.H>
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 tmp<errorEstimate<Type> >
44 const surfaceScalarField& flux,
45 const GeometricField<Type, fvPatchField, volMesh>& vf
48 const fvMesh& mesh = vf.mesh();
50 const scalarField& vols = mesh.V();
51 const surfaceVectorField& faceCentres = mesh.Cf();
52 const volVectorField& cellCentres = mesh.C();
53 const fvPatchList& patches = mesh.boundary();
54 const unallocLabelList& owner = mesh.owner();
55 const unallocLabelList& neighbour = mesh.neighbour();
57 Field<Type> res(vols.size(), pTraits<Type>::zero);
58 scalarField aNorm(vols.size(), 0.0);
61 const surfaceScalarField signF = pos(flux);
63 // Calculate gradient of the solution
66 typename outerProduct<vector, Type>::type, fvPatchField, volMesh
67 > gradVf = fvc::grad(vf);
72 // Calculate the centre of the face
73 const vector& curFaceCentre = faceCentres[faceI];
76 vector ownD = curFaceCentre - cellCentres[owner[faceI]];
78 // Subtract convection
82 + (ownD & gradVf[owner[faceI]])
85 aNorm[owner[faceI]] += signF[faceI]*flux[faceI];
88 vector neiD = curFaceCentre - cellCentres[neighbour[faceI]];
90 // Subtract convection
91 res[neighbour[faceI]] +=
94 + (neiD & gradVf[neighbour[faceI]])
97 aNorm[neighbour[faceI]] -= (1.0 - signF[faceI])*flux[faceI];
100 forAll (patches, patchI)
102 const vectorField& patchFaceCentres =
103 faceCentres.boundaryField()[patchI];
105 const scalarField& patchFlux = flux.boundaryField()[patchI];
106 const scalarField& patchSignFlux = signF.boundaryField()[patchI];
108 const labelList& fCells = patches[patchI].faceCells();
110 forAll (fCells, faceI)
113 patchFaceCentres[faceI] - cellCentres[fCells[faceI]];
115 // Subtract convection
116 res[fCells[faceI]] -=
119 + (d & gradVf[fCells[faceI]])
122 aNorm[fCells[faceI]] += patchSignFlux[faceI]*patchFlux[faceI];
129 return tmp<errorEstimate<Type> >
131 new errorEstimate<Type>
134 flux.dimensions()*vf.dimensions(),
143 tmp<errorEstimate<Type> >
146 const tmp<surfaceScalarField>& tflux,
147 const GeometricField<Type, fvPatchField, volMesh>& vf
150 tmp<errorEstimate<Type> > Div(resError::div(tflux(), vf));
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 } // End namespace resError
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 } // End namespace Foam
164 // ************************************************************************* //
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //