1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Residual error estimate for the fv convection operators.
27 \*---------------------------------------------------------------------------*/
29 #include "resErrorDiv.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 tmp<errorEstimate<Type> >
46 const surfaceScalarField& flux,
47 const GeometricField<Type, fvPatchField, volMesh>& vf
50 const fvMesh& mesh = vf.mesh();
52 const scalarField& vols = mesh.V();
53 const surfaceVectorField& faceCentres = mesh.Cf();
54 const volVectorField& cellCentres = mesh.C();
55 const fvPatchList& patches = mesh.boundary();
56 const unallocLabelList& owner = mesh.owner();
57 const unallocLabelList& neighbour = mesh.neighbour();
59 Field<Type> res(vols.size(), pTraits<Type>::zero);
60 scalarField aNorm(vols.size(), 0.0);
63 const surfaceScalarField signF = pos(flux);
65 // Calculate gradient of the solution
68 typename outerProduct<vector, Type>::type, fvPatchField, volMesh
69 > gradVf = fvc::grad(vf);
74 // Calculate the centre of the face
75 const vector& curFaceCentre = faceCentres[faceI];
78 vector ownD = curFaceCentre - cellCentres[owner[faceI]];
80 // Subtract convection
84 + (ownD & gradVf[owner[faceI]])
87 aNorm[owner[faceI]] += signF[faceI]*flux[faceI];
90 vector neiD = curFaceCentre - cellCentres[neighbour[faceI]];
92 // Subtract convection
93 res[neighbour[faceI]] +=
96 + (neiD & gradVf[neighbour[faceI]])
99 aNorm[neighbour[faceI]] -= (1.0 - signF[faceI])*flux[faceI];
102 forAll (patches, patchI)
104 const vectorField& patchFaceCentres =
105 faceCentres.boundaryField()[patchI];
107 const scalarField& patchFlux = flux.boundaryField()[patchI];
108 const scalarField& patchSignFlux = signF.boundaryField()[patchI];
110 const labelList& fCells = patches[patchI].faceCells();
112 forAll (fCells, faceI)
115 patchFaceCentres[faceI] - cellCentres[fCells[faceI]];
117 // Subtract convection
118 res[fCells[faceI]] -=
121 + (d & gradVf[fCells[faceI]])
124 aNorm[fCells[faceI]] += patchSignFlux[faceI]*patchFlux[faceI];
131 return tmp<errorEstimate<Type> >
133 new errorEstimate<Type>
136 flux.dimensions()*vf.dimensions(),
145 tmp<errorEstimate<Type> >
148 const tmp<surfaceScalarField>& tflux,
149 const GeometricField<Type, fvPatchField, volMesh>& vf
152 tmp<errorEstimate<Type> > Div(resError::div(tflux(), vf));
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 } // End namespace resError
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 } // End namespace Foam
166 // ************************************************************************* //
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //