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 "extendedLeastSquaresGrad.H"
28 #include "extendedLeastSquaresVectors.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 extendedLeastSquaresGrad<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 extendedLeastSquaresVectors& lsv = extendedLeastSquaresVectors::New
96 const surfaceVectorField& ownLs = lsv.pVectors();
97 const surfaceVectorField& neiLs = lsv.nVectors();
99 const unallocLabelList& owner = mesh.owner();
100 const unallocLabelList& neighbour = mesh.neighbour();
104 label own = owner[facei];
105 label nei = neighbour[facei];
107 Type deltaVsf = vsf[nei] - vsf[own];
109 lsGrad[own] += ownLs[facei]*deltaVsf;
110 lsGrad[nei] -= neiLs[facei]*deltaVsf;
114 forAll(vsf.boundaryField(), patchi)
116 const fvsPatchVectorField& patchOwnLs = ownLs.boundaryField()[patchi];
118 const unallocLabelList& faceCells =
119 lsGrad.boundaryField()[patchi].patch().faceCells();
121 if (vsf.boundaryField()[patchi].coupled())
124 vsf.boundaryField()[patchi].patchNeighbourField();
126 forAll(neiVsf, patchFaceI)
128 lsGrad[faceCells[patchFaceI]] +=
129 patchOwnLs[patchFaceI]
130 *(neiVsf[patchFaceI] - vsf[faceCells[patchFaceI]]);
135 const fvPatchField<Type>& patchVsf = vsf.boundaryField()[patchi];
137 forAll(patchVsf, patchFaceI)
139 lsGrad[faceCells[patchFaceI]] +=
140 patchOwnLs[patchFaceI]
141 *(patchVsf[patchFaceI] - vsf[faceCells[patchFaceI]]);
147 const List<labelPair>& additionalCells = lsv.additionalCells();
148 const vectorField& additionalVectors = lsv.additionalVectors();
150 forAll(additionalCells, i)
152 lsGrad[additionalCells[i][0]] +=
154 *(vsf[additionalCells[i][1]] - vsf[additionalCells[i][0]]);
158 lsGrad.correctBoundaryConditions();
159 gaussGrad<Type>::correctBoundaryConditions(vsf, lsGrad);
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 } // End namespace fv
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 } // End namespace Foam
173 // ************************************************************************* //