leastSquaresFaGrad.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) 2016-2017 Wikki Ltd
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 "leastSquaresFaGrad.H"
29 #include "leastSquaresFaVectors.H"
30 #include "gaussFaGrad.H"
31 #include "faMesh.H"
32 #include "areaFaMesh.H"
33 #include "edgeFaMesh.H"
34 #include "GeometricField.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace fa
45 {
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 template<class Type>
50 tmp
51 <
52  GeometricField
53  <
54  typename outerProduct<vector, Type>::type, faPatchField, areaMesh
55  >
56 >
58 (
59  const GeometricField<Type, faPatchField, areaMesh>& vsf
60 ) const
61 {
62  typedef typename outerProduct<vector, Type>::type GradType;
63 
64  const faMesh& mesh = vsf.mesh();
65 
66  tmp<GeometricField<GradType, faPatchField, areaMesh>> tlsGrad
67  (
68  new GeometricField<GradType, faPatchField, areaMesh>
69  (
70  IOobject
71  (
72  "grad(" + vsf.name() + ')',
73  vsf.instance(),
74  vsf.db(),
77  ),
78  mesh,
79  dimensioned<GradType>(vsf.dimensions()/dimLength, Zero),
80  zeroGradientFaPatchField<GradType>::typeName
81  )
82  );
83  GeometricField<GradType, faPatchField, areaMesh>& lsGrad = tlsGrad.ref();
84 
85  // Get reference to least square vectors
86  const leastSquaresFaVectors& lsv = leastSquaresFaVectors::New(mesh);
87 
88  const edgeVectorField& ownLs = lsv.pVectors();
89  const edgeVectorField& neiLs = lsv.nVectors();
90 
91  const labelUList& own = mesh.owner();
92  const labelUList& nei = mesh.neighbour();
93 
94  forAll(own, edgei)
95  {
96  label ownEdgeI = own[edgei];
97  label neiEdgeI = nei[edgei];
98 
99  Type deltaVsf = vsf[neiEdgeI] - vsf[ownEdgeI];
100 
101  lsGrad[ownEdgeI] += ownLs[edgei]*deltaVsf;
102  lsGrad[neiEdgeI] -= neiLs[edgei]*deltaVsf;
103  }
104 
105  // Boundary edges
106  forAll(vsf.boundaryField(), patchi)
107  {
108  const faePatchVectorField& patchOwnLs = ownLs.boundaryField()[patchi];
109 
110  const labelUList& edgeFaces =
111  lsGrad.boundaryField()[patchi].patch().edgeFaces();
112 
113  if (vsf.boundaryField()[patchi].coupled())
114  {
115  Field<Type> neiVsf
116  (
117  vsf.boundaryField()[patchi].patchNeighbourField()
118  );
119 
120  forAll(neiVsf, patchEdgeI)
121  {
122  lsGrad[edgeFaces[patchEdgeI]] +=
123  patchOwnLs[patchEdgeI]
124  *(neiVsf[patchEdgeI] - vsf[edgeFaces[patchEdgeI]]);
125  }
126  }
127  else
128  {
129  const faPatchField<Type>& patchVsf = vsf.boundaryField()[patchi];
130 
131  forAll(patchVsf, patchEdgeI)
132  {
133  lsGrad[edgeFaces[patchEdgeI]] +=
134  patchOwnLs[patchEdgeI]
135  *(patchVsf[patchEdgeI] - vsf[edgeFaces[patchEdgeI]]);
136  }
137  }
138  }
139 
140  // Remove component of gradient normal to surface (area)
141  lsGrad.correctBoundaryConditions();
142 
144 
145  return tlsGrad;
146 }
147 
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 } // End namespace fa
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 } // End namespace Foam
156 
157 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
leastSquaresFaGrad.H
gaussFaGrad.H
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::edgeVectorField
GeometricField< vector, faePatchField, edgeMesh > edgeVectorField
Definition: edgeFieldsFwd.H:57
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
zeroGradientFaPatchField.H
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
Foam::MeshObject< faMesh, Foam::MoveableMeshObject, leastSquaresFaVectors >::New
static const leastSquaresFaVectors & New(const faMesh &mesh, Args &&... args)
Get existing or create a new MeshObject.
Definition: MeshObject.C:48
faMesh.H
Foam::faePatchVectorField
faePatchField< vector > faePatchVectorField
Definition: faePatchFieldsFwd.H:47
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
leastSquaresFaVectors.H
edgeFaMesh.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fa::gaussGrad::correctBoundaryConditions
static void correctBoundaryConditions(const GeometricField< Type, faPatchField, areaMesh > &, GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh > &)
Correct the boundary values of the gradient using the patchField.
Definition: gaussFaGrad.C:82
GeometricField.H
areaFaMesh.H
Foam::fa::leastSquaresFaGrad::grad
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh > > grad(const GeometricField< Type, faPatchField, areaMesh > &) const
Calculate and return the grad of the given field.
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
Foam::IOobject::NO_READ
Definition: IOobject.H:123