1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "extendedLeastSquaresGrad.H"
27 #include "extendedLeastSquaresVectors.H"
28 #include "gaussGrad.H"
31 #include "surfaceMesh.H"
32 #include "GeometricField.H"
33 #include "zeroGradientFvPatchField.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 typename Foam::outerProduct<Foam::vector, Type>::type,
47 Foam::fv::extendedLeastSquaresGrad<Type>::calcGrad
49 const GeometricField<Type, fvPatchField, volMesh>& vsf,
53 typedef typename outerProduct<vector, Type>::type GradType;
55 const fvMesh& mesh = vsf.mesh();
57 tmp<GeometricField<GradType, fvPatchField, volMesh> > tlsGrad
59 new GeometricField<GradType, fvPatchField, volMesh>
73 vsf.dimensions()/dimLength,
74 pTraits<GradType>::zero
76 zeroGradientFvPatchField<GradType>::typeName
79 GeometricField<GradType, fvPatchField, volMesh>& lsGrad = tlsGrad();
81 // Get reference to least square vectors
82 const extendedLeastSquaresVectors& lsv = extendedLeastSquaresVectors::New
88 const surfaceVectorField& ownLs = lsv.pVectors();
89 const surfaceVectorField& neiLs = lsv.nVectors();
91 const labelUList& owner = mesh.owner();
92 const labelUList& neighbour = mesh.neighbour();
96 label own = owner[facei];
97 label nei = neighbour[facei];
99 Type deltaVsf = vsf[nei] - vsf[own];
101 lsGrad[own] += ownLs[facei]*deltaVsf;
102 lsGrad[nei] -= neiLs[facei]*deltaVsf;
106 forAll(vsf.boundaryField(), patchi)
108 const fvsPatchVectorField& patchOwnLs = ownLs.boundaryField()[patchi];
110 const labelUList& faceCells =
111 lsGrad.boundaryField()[patchi].patch().faceCells();
113 if (vsf.boundaryField()[patchi].coupled())
115 const Field<Type> neiVsf
117 vsf.boundaryField()[patchi].patchNeighbourField()
120 forAll(neiVsf, patchFaceI)
122 lsGrad[faceCells[patchFaceI]] +=
123 patchOwnLs[patchFaceI]
124 *(neiVsf[patchFaceI] - vsf[faceCells[patchFaceI]]);
129 const fvPatchField<Type>& patchVsf = vsf.boundaryField()[patchi];
131 forAll(patchVsf, patchFaceI)
133 lsGrad[faceCells[patchFaceI]] +=
134 patchOwnLs[patchFaceI]
135 *(patchVsf[patchFaceI] - vsf[faceCells[patchFaceI]]);
141 const List<labelPair>& additionalCells = lsv.additionalCells();
142 const vectorField& additionalVectors = lsv.additionalVectors();
144 forAll(additionalCells, i)
146 lsGrad[additionalCells[i][0]] +=
148 *(vsf[additionalCells[i][1]] - vsf[additionalCells[i][0]]);
152 lsGrad.correctBoundaryConditions();
153 gaussGrad<Type>::correctBoundaryConditions(vsf, lsGrad);
159 // ************************************************************************* //