FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

gaussGrad.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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023     
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "gaussGrad.H"
00027 #include <finiteVolume/zeroGradientFvPatchField.H>
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 namespace fv
00037 {
00038 
00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00040 
00041 template<class Type>
00042 tmp
00043 <
00044     GeometricField
00045     <
00046         typename outerProduct<vector, Type>::type, fvPatchField, volMesh
00047     >
00048 >
00049 gaussGrad<Type>::grad
00050 (
00051     const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf
00052 )
00053 {
00054     typedef typename outerProduct<vector, Type>::type GradType;
00055 
00056     const fvMesh& mesh = ssf.mesh();
00057 
00058     tmp<GeometricField<GradType, fvPatchField, volMesh> > tgGrad
00059     (
00060         new GeometricField<GradType, fvPatchField, volMesh>
00061         (
00062             IOobject
00063             (
00064                 "grad("+ssf.name()+')',
00065                 ssf.instance(),
00066                 mesh,
00067                 IOobject::NO_READ,
00068                 IOobject::NO_WRITE
00069             ),
00070             mesh,
00071             dimensioned<GradType>
00072             (
00073                 "0",
00074                 ssf.dimensions()/dimLength,
00075                 pTraits<GradType>::zero
00076             ),
00077             zeroGradientFvPatchField<GradType>::typeName
00078         )
00079     );
00080     GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad();
00081 
00082     const unallocLabelList& owner = mesh.owner();
00083     const unallocLabelList& neighbour = mesh.neighbour();
00084     const vectorField& Sf = mesh.Sf();
00085 
00086     Field<GradType>& igGrad = gGrad;
00087     const Field<Type>& issf = ssf;
00088 
00089     forAll(owner, facei)
00090     {
00091         GradType Sfssf = Sf[facei]*issf[facei];
00092 
00093         igGrad[owner[facei]] += Sfssf;
00094         igGrad[neighbour[facei]] -= Sfssf;
00095     }
00096 
00097     forAll(mesh.boundary(), patchi)
00098     {
00099         const unallocLabelList& pFaceCells =
00100             mesh.boundary()[patchi].faceCells();
00101 
00102         const vectorField& pSf = mesh.Sf().boundaryField()[patchi];
00103 
00104         const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];
00105 
00106         forAll(mesh.boundary()[patchi], facei)
00107         {
00108             igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei];
00109         }
00110     }
00111 
00112     igGrad /= mesh.V();
00113 
00114     gGrad.correctBoundaryConditions();
00115 
00116     return tgGrad;
00117 }
00118 
00119 
00120 template<class Type>
00121 tmp
00122 <
00123     GeometricField
00124     <
00125         typename outerProduct<vector, Type>::type, fvPatchField, volMesh
00126     >
00127 >
00128 gaussGrad<Type>::grad
00129 (
00130     const GeometricField<Type, fvPatchField, volMesh>& vsf
00131 ) const
00132 {
00133     typedef typename outerProduct<vector, Type>::type GradType;
00134 
00135     tmp<GeometricField<GradType, fvPatchField, volMesh> > tgGrad
00136     (
00137         grad(tinterpScheme_().interpolate(vsf))
00138     );
00139     GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad();
00140 
00141     gGrad.rename("grad(" + vsf.name() + ')');
00142     correctBoundaryConditions(vsf, gGrad);
00143 
00144     return tgGrad;
00145 }
00146 
00147 
00148 template<class Type>
00149 void gaussGrad<Type>::correctBoundaryConditions
00150 (
00151     const GeometricField<Type, fvPatchField, volMesh>& vsf,
00152     GeometricField
00153     <
00154         typename outerProduct<vector, Type>::type, fvPatchField, volMesh
00155     >& gGrad
00156 )
00157 {
00158     forAll(vsf.boundaryField(), patchi)
00159     {
00160         if (!vsf.boundaryField()[patchi].coupled())
00161         {
00162             vectorField n =
00163                 vsf.mesh().Sf().boundaryField()[patchi]
00164                /vsf.mesh().magSf().boundaryField()[patchi];
00165 
00166             gGrad.boundaryField()[patchi] += n *
00167             (
00168                 vsf.boundaryField()[patchi].snGrad()
00169               - (n & gGrad.boundaryField()[patchi])
00170             );
00171         }
00172      }
00173 }
00174 
00175 
00176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00177 
00178 } // End namespace fv
00179 
00180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00181 
00182 } // End namespace Foam
00183 
00184 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines