1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "leastSquaresGrad.H"
28 #include "leastSquaresVectors.H"
29 #include "gaussGrad.H"
32 #include "surfaceMesh.H"
33 #include "GeometricField.H"
34 #include "zeroGradientFvPatchField.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 typename outerProduct<vector, Type>::type, fvPatchField, volMesh
56 leastSquaresGrad<Type>::grad
58 const GeometricField<Type, fvPatchField, volMesh>& vsf
61 typedef typename outerProduct<vector, Type>::type GradType;
63 const fvMesh& mesh = vsf.mesh();
65 tmp<GeometricField<GradType, fvPatchField, volMesh> > tlsGrad
67 new GeometricField<GradType, fvPatchField, volMesh>
71 "grad("+vsf.name()+')',
81 vsf.dimensions()/dimLength,
82 pTraits<GradType>::zero
84 zeroGradientFvPatchField<GradType>::typeName
87 GeometricField<GradType, fvPatchField, volMesh>& lsGrad = tlsGrad();
89 // Get reference to least square vectors
90 const leastSquaresVectors& lsv = leastSquaresVectors::New(mesh);
92 const surfaceVectorField& ownLs = lsv.pVectors();
93 const surfaceVectorField& neiLs = lsv.nVectors();
95 const unallocLabelList& own = mesh.owner();
96 const unallocLabelList& nei = mesh.neighbour();
100 register label ownFaceI = own[facei];
101 register label neiFaceI = nei[facei];
103 Type deltaVsf = vsf[neiFaceI] - vsf[ownFaceI];
105 lsGrad[ownFaceI] += ownLs[facei]*deltaVsf;
106 lsGrad[neiFaceI] -= neiLs[facei]*deltaVsf;
110 forAll(vsf.boundaryField(), patchi)
112 const fvsPatchVectorField& patchOwnLs = ownLs.boundaryField()[patchi];
114 const unallocLabelList& faceCells =
115 lsGrad.boundaryField()[patchi].patch().faceCells();
117 if (vsf.boundaryField()[patchi].coupled())
120 vsf.boundaryField()[patchi].patchNeighbourField();
122 forAll(neiVsf, patchFaceI)
124 lsGrad[faceCells[patchFaceI]] +=
125 patchOwnLs[patchFaceI]
126 *(neiVsf[patchFaceI] - vsf[faceCells[patchFaceI]]);
131 const fvPatchField<Type>& patchVsf = vsf.boundaryField()[patchi];
133 forAll(patchVsf, patchFaceI)
135 lsGrad[faceCells[patchFaceI]] +=
136 patchOwnLs[patchFaceI]
137 *(patchVsf[patchFaceI] - vsf[faceCells[patchFaceI]]);
143 lsGrad.correctBoundaryConditions();
144 gaussGrad<Type>::correctBoundaryConditions(vsf, lsGrad);
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 } // End namespace fv
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 } // End namespace Foam
158 // ************************************************************************* //