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  Copyright (C) 2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "leastSquaresFaGrad.H"
30 #include "leastSquaresFaVectors.H"
31 #include "gaussFaGrad.H"
32 #include "faMesh.H"
33 #include "areaFaMesh.H"
34 #include "edgeFaMesh.H"
35 #include "GeometricField.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace fa
46 {
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 template<class Type>
50 tmp
51 <
52  GeometricField
53  <
55  faPatchField,
56  areaMesh
57  >
58 >
60 (
61  const GeometricField<Type, faPatchField, areaMesh>& vsf,
62  const word& name
63 ) const
64 {
65  typedef typename outerProduct<vector, Type>::type GradType;
66 
67  const faMesh& mesh = vsf.mesh();
68 
69  tmp<GeometricField<GradType, faPatchField, areaMesh>> tlsGrad
70  (
71  new GeometricField<GradType, faPatchField, areaMesh>
72  (
73  IOobject
74  (
75  name,
76  vsf.instance(),
77  vsf.db(),
80  ),
81  mesh,
82  dimensioned<GradType>(vsf.dimensions()/dimLength, Zero),
84  )
85  );
86  GeometricField<GradType, faPatchField, areaMesh>& lsGrad = tlsGrad.ref();
87 
88  // Get reference to least square vectors
89  const leastSquaresFaVectors& lsv = leastSquaresFaVectors::New(mesh);
90 
91  const edgeVectorField& ownLs = lsv.pVectors();
92  const edgeVectorField& neiLs = lsv.nVectors();
93 
94  const labelUList& own = mesh.owner();
95  const labelUList& nei = mesh.neighbour();
96 
97  forAll(own, edgei)
98  {
99  label ownEdgeI = own[edgei];
100  label neiEdgeI = nei[edgei];
101 
102  Type deltaVsf = vsf[neiEdgeI] - vsf[ownEdgeI];
103 
104  lsGrad[ownEdgeI] += ownLs[edgei]*deltaVsf;
105  lsGrad[neiEdgeI] -= neiLs[edgei]*deltaVsf;
106  }
107 
108  // Boundary edges
109  forAll(vsf.boundaryField(), patchi)
110  {
111  const faePatchVectorField& patchOwnLs = ownLs.boundaryField()[patchi];
112 
113  const labelUList& edgeFaces =
114  lsGrad.boundaryField()[patchi].patch().edgeFaces();
115 
116  if (vsf.boundaryField()[patchi].coupled())
117  {
118  Field<Type> neiVsf
119  (
120  vsf.boundaryField()[patchi].patchNeighbourField()
121  );
122 
123  forAll(neiVsf, patchEdgeI)
124  {
125  lsGrad[edgeFaces[patchEdgeI]] +=
126  patchOwnLs[patchEdgeI]
127  *(neiVsf[patchEdgeI] - vsf[edgeFaces[patchEdgeI]]);
128  }
129  }
130  else
131  {
132  const faPatchField<Type>& patchVsf = vsf.boundaryField()[patchi];
133 
134  forAll(patchVsf, patchEdgeI)
135  {
136  lsGrad[edgeFaces[patchEdgeI]] +=
137  patchOwnLs[patchEdgeI]
138  *(patchVsf[patchEdgeI] - vsf[edgeFaces[patchEdgeI]]);
139  }
140  }
141  }
142 
143  // Remove component of gradient normal to surface (area)
144  lsGrad.correctBoundaryConditions();
145 
147 
148  return tlsGrad;
149 }
150 
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 } // End namespace fa
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 } // End namespace Foam
159 
160 // ************************************************************************* //
static const leastSquaresFaVectors & New(const faMesh &mesh, Args &&... args)
Get existing or create a new MeshObject. Registered with typeName.
Definition: MeshObject.C:53
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
Ignore writing from objectRegistry::writeObject()
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Definition: faPatchField.H:191
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
GeometricField< vector, faePatchField, edgeMesh > edgeVectorField
Definition: edgeFieldsFwd.H:58
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
Nothing to be read.
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:110
faePatchField< vector > faePatchVectorField
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh > > calcGrad(const GeometricField< Type, faPatchField, areaMesh > &vsf, const word &name) const
Return the gradient of the given field to the gradScheme::grad for optional caching.
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127