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

fvcSurfaceIntegrate.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 "fvcSurfaceIntegrate.H"
00028 #include "fvMesh.H"
00029 #include "zeroGradientFvPatchFields.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 namespace fvc
00039 {
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00042 
00043 template<class Type>
00044 void surfaceIntegrate
00045 (
00046     Field<Type>& ivf,
00047     const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf
00048 )
00049 {
00050     const fvMesh& mesh = ssf.mesh();
00051 
00052     const unallocLabelList& owner = mesh.owner();
00053     const unallocLabelList& neighbour = mesh.neighbour();
00054 
00055     const Field<Type>& issf = ssf;
00056 
00057     forAll(owner, facei)
00058     {
00059         ivf[owner[facei]] += issf[facei];
00060         ivf[neighbour[facei]] -= issf[facei];
00061     }
00062 
00063     forAll(mesh.boundary(), patchi)
00064     {
00065         const unallocLabelList& pFaceCells =
00066             mesh.boundary()[patchi].faceCells();
00067 
00068         const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];
00069 
00070         forAll(mesh.boundary()[patchi], facei)
00071         {
00072             ivf[pFaceCells[facei]] += pssf[facei];
00073         }
00074     }
00075 
00076     ivf /= mesh.V();
00077 }
00078 
00079 
00080 template<class Type>
00081 tmp<GeometricField<Type, fvPatchField, volMesh> >
00082 surfaceIntegrate
00083 (
00084     const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf
00085 )
00086 {
00087     const fvMesh& mesh = ssf.mesh();
00088 
00089     tmp<GeometricField<Type, fvPatchField, volMesh> > tvf
00090     (
00091         new GeometricField<Type, fvPatchField, volMesh>
00092         (
00093             IOobject
00094             (
00095                 "surfaceIntegrate("+ssf.name()+')',
00096                 ssf.instance(),
00097                 mesh,
00098                 IOobject::NO_READ,
00099                 IOobject::NO_WRITE
00100             ),
00101             mesh,
00102             dimensioned<Type>
00103             (
00104                 "0",
00105                 ssf.dimensions()/dimVol,
00106                 pTraits<Type>::zero
00107             ),
00108             zeroGradientFvPatchField<Type>::typeName
00109         )
00110     );
00111     GeometricField<Type, fvPatchField, volMesh>& vf = tvf();
00112 
00113     surfaceIntegrate(vf.internalField(), ssf);
00114     vf.correctBoundaryConditions();
00115 
00116     return tvf;
00117 }
00118 
00119 
00120 template<class Type>
00121 tmp<GeometricField<Type, fvPatchField, volMesh> >
00122 surfaceIntegrate
00123 (
00124     const tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >& tssf
00125 )
00126 {
00127     tmp<GeometricField<Type, fvPatchField, volMesh> > tvf
00128     (
00129         fvc::surfaceIntegrate(tssf())
00130     );
00131     tssf.clear();
00132     return tvf;
00133 }
00134 
00135 
00136 template<class Type>
00137 tmp<GeometricField<Type, fvPatchField, volMesh> >
00138 surfaceSum
00139 (
00140     const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf
00141 )
00142 {
00143     const fvMesh& mesh = ssf.mesh();
00144 
00145     tmp<GeometricField<Type, fvPatchField, volMesh> > tvf
00146     (
00147         new GeometricField<Type, fvPatchField, volMesh>
00148         (
00149             IOobject
00150             (
00151                 "surfaceSum("+ssf.name()+')',
00152                 ssf.instance(),
00153                 mesh,
00154                 IOobject::NO_READ,
00155                 IOobject::NO_WRITE
00156             ),
00157             mesh,
00158             dimensioned<Type>("0", ssf.dimensions(), pTraits<Type>::zero),
00159             zeroGradientFvPatchField<Type>::typeName
00160         )
00161     );
00162     GeometricField<Type, fvPatchField, volMesh>& vf = tvf();
00163 
00164     const unallocLabelList& owner = mesh.owner();
00165     const unallocLabelList& neighbour = mesh.neighbour();
00166 
00167     forAll(owner, facei)
00168     {
00169         vf[owner[facei]] += ssf[facei];
00170         vf[neighbour[facei]] += ssf[facei];
00171     }
00172 
00173     forAll(mesh.boundary(), patchi)
00174     {
00175         const unallocLabelList& pFaceCells =
00176             mesh.boundary()[patchi].faceCells();
00177 
00178         const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];
00179 
00180         forAll(mesh.boundary()[patchi], facei)
00181         {
00182             vf[pFaceCells[facei]] += pssf[facei];
00183         }
00184     }
00185 
00186     vf.correctBoundaryConditions();
00187 
00188     return tvf;
00189 }
00190 
00191 
00192 template<class Type>
00193 tmp<GeometricField<Type, fvPatchField, volMesh> > surfaceSum
00194 (
00195     const tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >& tssf
00196 )
00197 {
00198     tmp<GeometricField<Type, fvPatchField, volMesh> > tvf = surfaceSum(tssf());
00199     tssf.clear();
00200     return tvf;
00201 }
00202 
00203 
00204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00205 
00206 } // End namespace fvc
00207 
00208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00209 
00210 } // End namespace Foam
00211 
00212 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd