symmTensorFieldTemplates.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) 2019-2022 OpenCFD 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 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
29 
30 template<class Cmpt>
31 void Foam::zip
32 (
33  Field<SymmTensor<Cmpt>>& result,
34  const UList<Cmpt>& xx, const UList<Cmpt>& xy, const UList<Cmpt>& xz,
35  const UList<Cmpt>& yy, const UList<Cmpt>& yz,
36  const UList<Cmpt>& zz
37 )
38 {
39  typedef SymmTensor<Cmpt> value_type;
40 
41  const label len = result.size();
42 
43  #ifdef FULLDEBUG
44  if
45  (
46  len != xx.size() || len != xy.size() || len != xz.size()
47  || len != yy.size() || len != yz.size()
48  || len != zz.size()
49  )
50  {
52  << "Components sizes do not match: " << len << " ("
53  << xx.size() << ' ' << xy.size() << ' ' << xz.size() << ' '
54  << yy.size() << ' ' << yz.size() << ' '
55  << zz.size() << ')'
56  << nl
57  << abort(FatalError);
58  }
59  #endif
60 
61  for (label i=0; i < len; ++i)
62  {
63  result[i] = value_type
64  (
65  xx[i], xy[i], xz[i],
66  /*yx*/ yy[i], yz[i],
67  /*zx zy */ zz[i]
68  );
69  }
70 }
71 
72 
73 template<class Cmpt>
74 void Foam::unzip
75 (
76  const UList<SymmTensor<Cmpt>>& input,
77  Field<Cmpt>& xx, Field<Cmpt>& xy, Field<Cmpt>& xz,
78  Field<Cmpt>& yy, Field<Cmpt>& yz,
79  Field<Cmpt>& zz
80 )
81 {
82  const label len = input.size();
83 
84  #ifdef FULLDEBUG
85  if
86  (
87  len != xx.size() || len != xy.size() || len != xz.size()
88  || len != yy.size() || len != yz.size()
89  || len != zz.size()
90  )
91  {
93  << "Components sizes do not match: " << len << " ("
94  << xx.size() << ' ' << xy.size() << ' ' << xz.size() << ' '
95  << yy.size() << ' ' << yz.size() << ' '
96  << zz.size() << ')'
97  << nl
98  << abort(FatalError);
99  }
100  #endif
101 
102  for (label i=0; i < len; ++i)
103  {
104  xx[i] = input[i].xx(); xy[i] = input[i].xy(); xz[i] = input[i].xz();
105  yy[i] = input[i].yy(); yz[i] = input[i].yz();
106  zz[i] = input[i].zz();
107  }
108 }
109 
110 
111 template<class Cmpt>
113 Foam::zip
114 (
115  const Field<Cmpt>& xx, const Field<Cmpt>& xy, const Field<Cmpt>& xz,
116  const Field<Cmpt>& yy, const Field<Cmpt>& yz,
117  const Field<Cmpt>& zz
118 )
119 {
120  auto tresult = tmp<Field<SymmTensor<Cmpt>>>::New(xx.size());
121 
122  Foam::zip(tresult.ref(), xx, xy, xz, yy, yz, zz);
124  return tresult;
125 }
126 
127 
128 template<class Cmpt>
129 void Foam::zipRows
130 (
131  Field<SymmTensor<Cmpt>>& result,
132  const UList<Vector<Cmpt>>& x,
133  const UList<Vector<Cmpt>>& y,
134  const UList<Vector<Cmpt>>& z
135 )
136 {
137  const label len = result.size();
138 
139  #ifdef FULLDEBUG
140  if (len != x.size() || len != y.size() || len != z.size())
141  {
143  << "Components sizes do not match: " << len << " ("
144  << x.size() << ' ' << y.size() << ' ' << z.size() << ')'
145  << nl
146  << abort(FatalError);
147  }
148  #endif
149 
150  for (label i=0; i < len; ++i)
151  {
152  // Like symmTensor::rows() but removed redundancy
153 
154  result[i].xx() = x[i].x();
155  result[i].xy() = x[i].y();
156  result[i].xz() = x[i].z();
157 
158  result[i].yy() = y[i].y();
159  result[i].yz() = y[i].z();
160 
161  result[i].zz() = z[i].z();
162  }
163 }
164 
165 
166 template<class Cmpt>
167 void Foam::unzipRows
168 (
169  const UList<SymmTensor<Cmpt>>& input,
170  Field<Vector<Cmpt>>& x,
171  Field<Vector<Cmpt>>& y,
172  Field<Vector<Cmpt>>& z
173 )
174 {
175  const label len = input.size();
176 
177  #ifdef FULLDEBUG
178  if (len != x.size() || len != y.size() || len != z.size())
179  {
181  << "Components sizes do not match: " << len << " ("
182  << x.size() << ' ' << y.size() << ' ' << z.size() << ')'
183  << nl
184  << abort(FatalError);
185  }
186  #endif
187 
188  for (label i=0; i < len; ++i)
189  {
190  x[i] = input[i].x();
191  y[i] = input[i].y();
192  z[i] = input[i].z();
193  }
194 }
195 
196 
197 template<class Cmpt>
198 void Foam::unzipRow
199 (
200  const UList<SymmTensor<Cmpt>>& input,
201  const direction idx,
202  Field<Vector<Cmpt>>& result
203 )
204 {
205  const label len = input.size();
206 
207  #ifdef FULLDEBUG
208  if (len != result.size())
209  {
211  << "Components sizes do not match: " << len << " ("
212  << result.size() << ')'
213  << nl
214  << abort(FatalError);
215  }
216  #endif
217 
218  switch (idx)
219  {
220  case vector::components::X :
221  {
222  for (label i=0; i < len; ++i)
223  {
224  result[i] = input[i].x();
225  }
226  }
227  break;
228 
229  case vector::components::Y :
230  {
231  for (label i=0; i < len; ++i)
232  {
233  result[i] = input[i].y();
234  }
235  }
236  break;
237 
238  case vector::components::Z :
239  {
240  for (label i=0; i < len; ++i)
241  {
242  result[i] = input[i].z();
243  }
244  }
245  break;
246  }
247 }
248 
249 
250 template<class Cmpt>
251 void Foam::unzipDiag
252 (
253  const UList<SymmTensor<Cmpt>>& input,
254  Field<Vector<Cmpt>>& result
255 )
256 {
257  const label len = input.size();
258 
259  #ifdef FULLDEBUG
260  if (len != result.size())
261  {
263  << "Components sizes do not match: " << len << " ("
264  << result.size() << ')'
265  << nl
266  << abort(FatalError);
267  }
268  #endif
269 
270  for (label i=0; i < len; ++i)
271  {
272  result[i] = input[i].diag();
273  }
274 }
275 
276 
277 template<class Cmpt>
280 (
281  const Field<SymmTensor<Cmpt>>& input,
282  const direction idx
283 )
284 {
285  auto tresult = tmp<Field<Vector<Cmpt>>>::New(input.size());
286 
287  Foam::unzipRow(input, idx, tresult.ref());
288 
289  return tresult;
290 }
291 
292 
293 template<class Cmpt>
296 (
297  const Field<SymmTensor<Cmpt>>& input
298 )
299 {
300  auto tresult = tmp<Field<Vector<Cmpt>>>::New(input.size());
301 
302  Foam::unzipDiag(input, tresult.ref());
303 
304  return tresult;
305 }
306 
307 
308 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
uint8_t direction
Definition: direction.H:46
A templated (3 x 3) symmetric tensor of objects of <T>, effectively containing 6 elements, derived from VectorSpace.
Definition: SymmTensor.H:50
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
void zip(FieldField< Field, SphericalTensor< Cmpt >> &result, const FieldField< Field, Cmpt > &ii)
Zip together sphericalTensor field field from components.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
void unzipRow(const FieldField< Field, SymmTensor< Cmpt >> &input, const direction idx, FieldField< Field, Vector< Cmpt >> &result)
Extract a symmTensor field field row (x,y,z) == (0,1,2)
void unzipRows(const FieldField< Field, SymmTensor< Cmpt >> &input, FieldField< Field, Vector< Cmpt >> &x, FieldField< Field, Vector< Cmpt >> &y, FieldField< Field, Vector< Cmpt >> &z)
Extract symmTensor field field rows.
void zipRows(FieldField< Field, SymmTensor< Cmpt >> &result, const FieldField< Field, Vector< Cmpt >> &x, const FieldField< Field, Vector< Cmpt >> &y, const FieldField< Field, Vector< Cmpt >> &z)
Zip together symmTensor field field from row components.
void unzip(const FieldField< Field, SphericalTensor< Cmpt >> &input, FieldField< Field, Cmpt > &ii)
Unzip sphericalTensor field field into components.
void unzipDiag(const FieldField< Field, SymmTensor< Cmpt >> &input, FieldField< Field, Vector< Cmpt >> &result)
Extract a symmTensor field field diagonal.
scalar y
Generic templated field type.
Definition: Field.H:62
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:33
errorManip< error > abort(error &err)
Definition: errorManip.H:139
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
static constexpr direction size() noexcept
The number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpace.H:206
PtrList< volScalarField > & Y
A class for managing temporary objects.
Definition: HashPtrTable.H:50