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

extendedLeastSquaresGrad.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 "extendedLeastSquaresGrad.H"
00028 #include "extendedLeastSquaresVectors.H"
00029 #include "gaussGrad.H"
00030 #include "fvMesh.H"
00031 #include "volMesh.H"
00032 #include "surfaceMesh.H"
00033 #include "GeometricField.H"
00034 #include "zeroGradientFvPatchField.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00042 
00043 namespace fv
00044 {
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 template<class Type>
00049 tmp
00050 <
00051     GeometricField
00052     <
00053         typename outerProduct<vector, Type>::type, fvPatchField, volMesh
00054     >
00055 >
00056 extendedLeastSquaresGrad<Type>::grad
00057 (
00058     const GeometricField<Type, fvPatchField, volMesh>& vsf
00059 ) const
00060 {
00061     typedef typename outerProduct<vector, Type>::type GradType;
00062 
00063     const fvMesh& mesh = vsf.mesh();
00064 
00065     tmp<GeometricField<GradType, fvPatchField, volMesh> > tlsGrad
00066     (
00067         new GeometricField<GradType, fvPatchField, volMesh>
00068         (
00069             IOobject
00070             (
00071                 "grad("+vsf.name()+')',
00072                 vsf.instance(),
00073                 mesh,
00074                 IOobject::NO_READ,
00075                 IOobject::NO_WRITE
00076             ),
00077             mesh,
00078             dimensioned<GradType>
00079             (
00080                 "zero",
00081                 vsf.dimensions()/dimLength,
00082                 pTraits<GradType>::zero
00083             ),
00084             zeroGradientFvPatchField<GradType>::typeName
00085         )
00086     );
00087     GeometricField<GradType, fvPatchField, volMesh>& lsGrad = tlsGrad();
00088 
00089     // Get reference to least square vectors
00090     const extendedLeastSquaresVectors& lsv = extendedLeastSquaresVectors::New
00091     (
00092         mesh,
00093         minDet_
00094     );
00095 
00096     const surfaceVectorField& ownLs = lsv.pVectors();
00097     const surfaceVectorField& neiLs = lsv.nVectors();
00098 
00099     const unallocLabelList& owner = mesh.owner();
00100     const unallocLabelList& neighbour = mesh.neighbour();
00101 
00102     forAll(owner, facei)
00103     {
00104         label own = owner[facei];
00105         label nei = neighbour[facei];
00106 
00107         Type deltaVsf = vsf[nei] - vsf[own];
00108 
00109         lsGrad[own] += ownLs[facei]*deltaVsf;
00110         lsGrad[nei] -= neiLs[facei]*deltaVsf;
00111     }
00112 
00113     // Boundary faces
00114     forAll(vsf.boundaryField(), patchi)
00115     {
00116         const fvsPatchVectorField& patchOwnLs = ownLs.boundaryField()[patchi];
00117 
00118         const unallocLabelList& faceCells =
00119             lsGrad.boundaryField()[patchi].patch().faceCells();
00120 
00121         if (vsf.boundaryField()[patchi].coupled())
00122         {
00123             Field<Type> neiVsf = 
00124                 vsf.boundaryField()[patchi].patchNeighbourField();
00125 
00126             forAll(neiVsf, patchFaceI)
00127             {
00128                 lsGrad[faceCells[patchFaceI]] +=
00129                     patchOwnLs[patchFaceI]
00130                    *(neiVsf[patchFaceI] - vsf[faceCells[patchFaceI]]);
00131             }
00132         }
00133         else
00134         {
00135             const fvPatchField<Type>& patchVsf = vsf.boundaryField()[patchi];
00136 
00137             forAll(patchVsf, patchFaceI)
00138             {
00139                 lsGrad[faceCells[patchFaceI]] +=
00140                      patchOwnLs[patchFaceI]
00141                     *(patchVsf[patchFaceI] - vsf[faceCells[patchFaceI]]);
00142             }
00143         }
00144     }
00145 
00146 
00147     const List<labelPair>& additionalCells = lsv.additionalCells();
00148     const vectorField& additionalVectors = lsv.additionalVectors();
00149 
00150     forAll(additionalCells, i)
00151     {
00152         lsGrad[additionalCells[i][0]] +=
00153             additionalVectors[i]
00154            *(vsf[additionalCells[i][1]] - vsf[additionalCells[i][0]]);
00155     }
00156 
00157 
00158     lsGrad.correctBoundaryConditions();
00159     gaussGrad<Type>::correctBoundaryConditions(vsf, lsGrad);
00160 
00161     return tlsGrad;
00162 }
00163 
00164 
00165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00166 
00167 } // End namespace fv
00168 
00169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00170 
00171 } // End namespace Foam
00172 
00173 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd