leastSquareGrad.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) 2020 DLR
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 "leastSquareGrad.H"
29 #include "emptyPolyPatch.H"
30 #include "processorPolyPatch.H"
31 #include "wedgePolyPatch.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 template<class T>
37 (
38  const word& functionName,
39  const labelVector& geomDir
40 )
41 :
42  polyFitter_(functionName,geomDir),
43  geomDir_(geomDir),
44  nDims_(0)
45 {
46  // Compute number of dimensions
47  for (const label dirn : geomDir_)
48  {
49  if (dirn == 1)
50  {
51  ++nDims_;
52  }
53  }
54 }
55 
56 
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58 
59 template<class T>
62 (
63  const List<vector>& positions,
64  const List<T>& listValue
65 )
66 {
67  typedef typename outerProduct<vector, T>::type GradType;
68 
69  List<T> fitData = polyFitter_.fitData
70  (
71  positions,
72  listValue
73  );
74 
75  if (nDims_ == 3)
76  {
77  return GradType(fitData[1],fitData[2],fitData[3]);
78  }
79 
80 
81  label dimCounter = 0;
82 
83  GradType ret(Zero);
84 
85  forAll(geomDir_,i)
86  {
87  if (geomDir_[i] == 1)
88  {
89  ++dimCounter;
90  ret[i] = fitData[dimCounter];
91  }
92  }
93 
94  return ret;
95 }
96 
97 
98 namespace Foam // needed g++ bug
99 {
100  template<>
102  (
103  const List<vector>& positions,
104  const List<vector>& listValue
105  )
106  {
107  typedef tensor GradType;
108 
109  List<vector> fitData = polyFitter_.fitData
110  (
111  positions,
112  listValue
113  );
114 
115  if (nDims_ == 3)
116  {
117  return GradType(fitData[1],fitData[2],fitData[3]);
118  }
119 
120  label dimCounter = 0;
121 
122  GradType ret(Zero);
123 
124  forAll(geomDir_,i)
125  {
126  if (geomDir_[i] == 1)
127  {
128  ++dimCounter;
129  ret.row(i, fitData[dimCounter]);
130  }
131  }
132 
133  return ret;
134  }
135 }
136 
137 
138 template<class T>
141 (
142  const Map<List<vector>>& positions,
143  const Map<List<T>>& listValue
144 )
145 {
146  typedef typename outerProduct<vector, T>::type GradType;
147 
148  Map<GradType> gradMap(positions.capacity());
149 
150  forAllConstIters(positions, iter)
151  {
152  const label key = iter.key();
153  const List<vector>& positions = iter.val();
154 
155  GradType grad(this->grad(positions, listValue[key]));
156 
157  gradMap.insert(key, grad);
158  }
159 
160  return gradMap;
161 }
162 
163 
166 
167 
168 // ************************************************************************* //
Foam::leastSquareGrad
Estimates the gradient with a least square scheme in a cell.
Definition: leastSquareGrad.H:56
Foam::Tensor< scalar >
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::leastSquareGrad::leastSquareGrad
leastSquareGrad(const word &functionName, const labelVector &geomDir)
Construct from components.
Definition: leastSquareGrad.C:37
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
wedgePolyPatch.H
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
leastSquareGrad.H
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::leastSquareGrad::grad
outerProduct< vector, T >::type grad(const List< vector > &positions, const List< T > &listValue)
Return the gradient of the cell.
Definition: leastSquareGrad.C:62
Foam::fac::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:56
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
processorPolyPatch.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
emptyPolyPatch.H
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::Vector< label >
Foam::List< vector >