leastSquaresGrad.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "leastSquaresGrad.H"
29 #include "leastSquaresVectors.H"
30 #include "gaussGrad.H"
31 #include "fvMesh.H"
32 #include "volMesh.H"
33 #include "surfaceMesh.H"
34 #include "GeometricField.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 template<class Type>
41 <
43  <
47  >
48 >
50 (
51  const GeometricField<Type, fvPatchField, volMesh>& vsf,
52  const word& name
53 ) const
54 {
55  typedef typename outerProduct<vector, Type>::type GradType;
56 
57  const fvMesh& mesh = vsf.mesh();
58 
59  tmp<GeometricField<GradType, fvPatchField, volMesh>> tlsGrad
60  (
61  new GeometricField<GradType, fvPatchField, volMesh>
62  (
63  IOobject
64  (
65  name,
66  vsf.instance(),
67  mesh,
68  IOobject::NO_READ,
69  IOobject::NO_WRITE
70  ),
71  mesh,
72  dimensioned<GradType>(vsf.dimensions()/dimLength, Zero),
73  extrapolatedCalculatedFvPatchField<GradType>::typeName
74  )
75  );
76  GeometricField<GradType, fvPatchField, volMesh>& lsGrad = tlsGrad.ref();
77 
78  // Get reference to least square vectors
79  const leastSquaresVectors& lsv = leastSquaresVectors::New(mesh);
80 
81  const surfaceVectorField& ownLs = lsv.pVectors();
82  const surfaceVectorField& neiLs = lsv.nVectors();
83 
84  const labelUList& own = mesh.owner();
85  const labelUList& nei = mesh.neighbour();
86 
87  forAll(own, facei)
88  {
89  label ownFacei = own[facei];
90  label neiFacei = nei[facei];
91 
92  Type deltaVsf = vsf[neiFacei] - vsf[ownFacei];
93 
94  lsGrad[ownFacei] += ownLs[facei]*deltaVsf;
95  lsGrad[neiFacei] -= neiLs[facei]*deltaVsf;
96  }
97 
98  // Boundary faces
99  forAll(vsf.boundaryField(), patchi)
100  {
101  const fvsPatchVectorField& patchOwnLs = ownLs.boundaryField()[patchi];
102 
103  const labelUList& faceCells =
104  vsf.boundaryField()[patchi].patch().faceCells();
105 
106  if (vsf.boundaryField()[patchi].coupled())
107  {
108  const Field<Type> neiVsf
109  (
110  vsf.boundaryField()[patchi].patchNeighbourField()
111  );
112 
113  forAll(neiVsf, patchFacei)
114  {
115  lsGrad[faceCells[patchFacei]] +=
116  patchOwnLs[patchFacei]
117  *(neiVsf[patchFacei] - vsf[faceCells[patchFacei]]);
118  }
119  }
120  else
121  {
122  const fvPatchField<Type>& patchVsf = vsf.boundaryField()[patchi];
123 
124  forAll(patchVsf, patchFacei)
125  {
126  lsGrad[faceCells[patchFacei]] +=
127  patchOwnLs[patchFacei]
128  *(patchVsf[patchFacei] - vsf[faceCells[patchFacei]]);
129  }
130  }
131  }
132 
133 
134  lsGrad.correctBoundaryConditions();
136 
137  return tlsGrad;
138 }
139 
140 
141 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
Foam::fv::leastSquaresGrad::calcGrad
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > calcGrad(const GeometricField< Type, fvPatchField, volMesh > &vsf, const word &name) const
Return the gradient of the given field to the gradScheme::grad.
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
extrapolatedCalculatedFvPatchField.H
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:50
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
volMesh.H
leastSquaresVectors.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
leastSquaresGrad.H
correctBoundaryConditions
cellMask correctBoundaryConditions()
gaussGrad.H
Foam::fvsPatchVectorField
fvsPatchField< vector > fvsPatchVectorField
Definition: fvsPatchFieldsFwd.H:48
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
surfaceMesh.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
fvMesh.H
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
GeometricField.H
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
Foam::surfaceVectorField
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Definition: surfaceFieldsFwd.H:57
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53