OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

resErrorDiv.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "resErrorDiv.H"
00028 #include "fvc.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 namespace resError
00038 {
00039 
00040 template<class Type>
00041 tmp<errorEstimate<Type> >
00042 div
00043 (
00044     const surfaceScalarField& flux,
00045     const GeometricField<Type, fvPatchField, volMesh>& vf
00046 )
00047 {
00048     const fvMesh& mesh = vf.mesh();
00049 
00050     const scalarField& vols = mesh.V();
00051     const surfaceVectorField& faceCentres = mesh.Cf();
00052     const volVectorField& cellCentres = mesh.C();
00053     const fvPatchList& patches = mesh.boundary();
00054     const unallocLabelList& owner = mesh.owner();
00055     const unallocLabelList& neighbour = mesh.neighbour();
00056 
00057     Field<Type> res(vols.size(), pTraits<Type>::zero);
00058     scalarField aNorm(vols.size(), 0.0);
00059 
00060     // Get sign of flux
00061     const surfaceScalarField signF = pos(flux);
00062 
00063     // Calculate gradient of the solution
00064     GeometricField
00065     <
00066         typename outerProduct<vector, Type>::type, fvPatchField, volMesh
00067     > gradVf = fvc::grad(vf);
00068 
00069     // Internal faces
00070     forAll (owner, faceI)
00071     {
00072         // Calculate the centre of the face
00073         const vector& curFaceCentre = faceCentres[faceI];
00074 
00075         // Owner
00076         vector ownD = curFaceCentre - cellCentres[owner[faceI]];
00077 
00078         // Subtract convection
00079         res[owner[faceI]] -=
00080         (
00081             vf[owner[faceI]]
00082           + (ownD & gradVf[owner[faceI]])
00083         )*flux[faceI];
00084 
00085         aNorm[owner[faceI]] += signF[faceI]*flux[faceI];
00086 
00087         // Neighbour
00088         vector neiD = curFaceCentre - cellCentres[neighbour[faceI]];
00089 
00090         // Subtract convection
00091         res[neighbour[faceI]] +=
00092         (
00093             vf[neighbour[faceI]]
00094           + (neiD & gradVf[neighbour[faceI]])
00095         )*flux[faceI];
00096 
00097         aNorm[neighbour[faceI]] -= (1.0 - signF[faceI])*flux[faceI];
00098     }
00099 
00100     forAll (patches, patchI)
00101     {
00102         const vectorField& patchFaceCentres =
00103             faceCentres.boundaryField()[patchI];
00104 
00105         const scalarField& patchFlux = flux.boundaryField()[patchI];
00106         const scalarField& patchSignFlux = signF.boundaryField()[patchI];
00107 
00108         const labelList& fCells = patches[patchI].faceCells();
00109 
00110         forAll (fCells, faceI)
00111         {
00112             vector d =
00113                 patchFaceCentres[faceI] - cellCentres[fCells[faceI]];
00114 
00115             // Subtract convection
00116             res[fCells[faceI]] -=
00117             (
00118                 vf[fCells[faceI]]
00119               + (d & gradVf[fCells[faceI]])
00120             )*patchFlux[faceI];
00121 
00122             aNorm[fCells[faceI]] += patchSignFlux[faceI]*patchFlux[faceI];
00123         }
00124     }
00125 
00126     res /= vols;
00127     aNorm /= vols;
00128 
00129     return tmp<errorEstimate<Type> >
00130     (
00131         new errorEstimate<Type>
00132         (
00133             vf,
00134             flux.dimensions()*vf.dimensions(),
00135             res,
00136             aNorm
00137         )
00138     );
00139 }
00140 
00141 
00142 template<class Type>
00143 tmp<errorEstimate<Type> >
00144 div
00145 (
00146     const tmp<surfaceScalarField>& tflux,
00147     const GeometricField<Type, fvPatchField, volMesh>& vf
00148 )
00149 {
00150     tmp<errorEstimate<Type> > Div(resError::div(tflux(), vf));
00151     tflux.clear();
00152     return Div;
00153 }
00154 
00155 
00156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00157 
00158 } // End namespace resError
00159 
00160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00161 
00162 } // End namespace Foam
00163 
00164 // ************************************************************************* //
00165 
00166 
00167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00168 
Copyright © 2000-2009 OpenCFD Ltd