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-------------------------------------------------------------------------------
10License
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
35template<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
59template<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
98namespace 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
138template<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// ************************************************************************* //
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
Computes the gradient of an input field.
Definition: grad.H:157
Estimates the gradient with a least square scheme in a cell.
type
Volume classification types.
Definition: volumeType.H:66
A class for handling words, derived from Foam::string.
Definition: word.H:68
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278