tensorFieldTemplates.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 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<Tensor<Cmpt>>& result,
34  const UList<Cmpt>& xx, const UList<Cmpt>& xy, const UList<Cmpt>& xz,
35  const UList<Cmpt>& yx, const UList<Cmpt>& yy, const UList<Cmpt>& yz,
36  const UList<Cmpt>& zx, const UList<Cmpt>& zy, const UList<Cmpt>& zz
37 )
38 {
39  typedef Tensor<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 != yx.size() || len != yy.size() || len != yz.size()
48  || len != zx.size() || len != zy.size() || len != zz.size()
49  )
50  {
52  << "Components sizes do not match: " << len << " ("
53  << xx.size() << ' ' << xy.size() << ' ' << xz.size() << ' '
54  << yx.size() << ' ' << yy.size() << ' ' << yz.size() << ' '
55  << zx.size() << ' ' << zy.size() << ' ' << 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[i], yy[i], yz[i],
67  zx[i], zy[i], zz[i]
68  );
69  }
70 }
71 
72 
73 template<class Cmpt>
74 void Foam::unzip
75 (
76  const UList<Tensor<Cmpt>>& input,
77  Field<Cmpt>& xx, Field<Cmpt>& xy, Field<Cmpt>& xz,
78  Field<Cmpt>& yx, Field<Cmpt>& yy, Field<Cmpt>& yz,
79  Field<Cmpt>& zx, Field<Cmpt>& zy, 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 != yx.size() || len != yy.size() || len != yz.size()
89  || len != zx.size() || len != zy.size() || len != zz.size()
90  )
91  {
93  << "Components sizes do not match: " << len << " ("
94  << xx.size() << ' ' << xy.size() << ' ' << xz.size() << ' '
95  << yx.size() << ' ' << yy.size() << ' ' << yz.size() << ' '
96  << zx.size() << ' ' << zy.size() << ' ' << 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  yx[i] = input[i].yx(); yy[i] = input[i].yy(); yz[i] = input[i].yz();
106  zx[i] = input[i].zx(); zy[i] = input[i].zy(); 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>& yx, const Field<Cmpt>& yy, const Field<Cmpt>& yz,
117  const Field<Cmpt>& zx, const Field<Cmpt>& zy, const Field<Cmpt>& zz
118 )
119 {
120  auto tresult = tmp<Field<Tensor<Cmpt>>>::New(xx.size());
121 
122  Foam::zip(tresult.ref(), xx, xy, xz, yx, yy, yz, zx, zy, zz);
123 
124  return tresult;
125 }
126 
127 
128 template<class Cmpt>
129 void Foam::zipRows
130 (
131  Field<Tensor<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  result[i].rows(x[i], y[i], z[i]);
153  }
154 }
155 
156 
157 template<class Cmpt>
158 void Foam::zipCols
159 (
160  Field<Tensor<Cmpt>>& result,
161  const UList<Vector<Cmpt>>& x,
162  const UList<Vector<Cmpt>>& y,
163  const UList<Vector<Cmpt>>& z
164 )
165 {
166  const label len = result.size();
167 
168  #ifdef FULLDEBUG
169  if (len != x.size() || len != y.size() || len != z.size())
170  {
172  << "Components sizes do not match: " << len << " ("
173  << x.size() << ' ' << y.size() << ' ' << z.size() << ')'
174  << nl
175  << abort(FatalError);
176  }
177  #endif
178 
179  for (label i=0; i < len; ++i)
180  {
181  result[i].cols(x[i], y[i], z[i]);
182  }
183 }
184 
185 
186 template<class Cmpt>
187 void Foam::unzipRows
188 (
189  const UList<Tensor<Cmpt>>& input,
190  Field<Vector<Cmpt>>& x,
191  Field<Vector<Cmpt>>& y,
192  Field<Vector<Cmpt>>& z
193 )
194 {
195  const label len = input.size();
196 
197  #ifdef FULLDEBUG
198  if (len != x.size() || len != y.size() || len != z.size())
199  {
201  << "Components sizes do not match: " << len << " ("
202  << x.size() << ' ' << y.size() << ' ' << z.size() << ')'
203  << nl
204  << abort(FatalError);
205  }
206  #endif
207 
208  for (label i=0; i < len; ++i)
209  {
210  x[i] = input[i].x();
211  y[i] = input[i].y();
212  z[i] = input[i].z();
213  }
214 }
215 
216 
217 template<class Cmpt>
218 void Foam::unzipCols
219 (
220  const UList<Tensor<Cmpt>>& input,
221  Field<Vector<Cmpt>>& x,
222  Field<Vector<Cmpt>>& y,
223  Field<Vector<Cmpt>>& z
224 )
225 {
226  const label len = input.size();
227 
228  #ifdef FULLDEBUG
229  if (len != x.size() || len != y.size() || len != z.size())
230  {
232  << "Components sizes do not match: " << len << " ("
233  << x.size() << ' ' << y.size() << ' ' << z.size() << ')'
234  << nl
235  << abort(FatalError);
236  }
237  #endif
238 
239  for (label i=0; i < len; ++i)
240  {
241  x[i] = input[i].cx();
242  y[i] = input[i].cy();
243  z[i] = input[i].cz();
244  }
245 }
246 
247 
248 template<class Cmpt>
249 void Foam::unzipRow
250 (
251  const UList<Tensor<Cmpt>>& input,
252  const vector::components cmpt,
253  Field<Vector<Cmpt>>& result
254 )
255 {
256  const label len = input.size();
257 
258  #ifdef FULLDEBUG
259  if (len != result.size())
260  {
262  << "Components sizes do not match: " << len << " ("
263  << result.size() << ')'
264  << nl
265  << abort(FatalError);
266  }
267  #endif
268 
269  switch (cmpt)
270  {
271  case vector::components::X :
272  {
273  for (label i=0; i < len; ++i)
274  {
275  result[i] = input[i].x();
276  }
277  }
278  break;
279 
280  case vector::components::Y :
281  {
282  for (label i=0; i < len; ++i)
283  {
284  result[i] = input[i].y();
285  }
286  }
287  break;
288 
289  case vector::components::Z :
290  {
291  for (label i=0; i < len; ++i)
292  {
293  result[i] = input[i].z();
294  }
295  }
296  break;
297  }
298 }
299 
300 
301 template<class Cmpt>
302 void Foam::unzipCol
303 (
304  const UList<Tensor<Cmpt>>& input,
305  const vector::components cmpt,
306  Field<Vector<Cmpt>>& result
307 )
308 {
309  const label len = input.size();
310 
311  #ifdef FULLDEBUG
312  if (len != result.size())
313  {
315  << "Components sizes do not match: " << len << " ("
316  << result.size() << ')'
317  << nl
318  << abort(FatalError);
319  }
320  #endif
321 
322  switch (cmpt)
323  {
324  case vector::components::X :
325  {
326  for (label i=0; i < len; ++i)
327  {
328  result[i] = input[i].cx();
329  }
330  }
331  break;
332 
333  case vector::components::Y :
334  {
335  for (label i=0; i < len; ++i)
336  {
337  result[i] = input[i].cy();
338  }
339  }
340  break;
341 
342  case vector::components::Z :
343  {
344  for (label i=0; i < len; ++i)
345  {
346  result[i] = input[i].cz();
347  }
348  }
349  break;
350  }
351 }
352 
353 
354 template<class Cmpt>
355 void Foam::unzipDiag
356 (
357  const UList<Tensor<Cmpt>>& input,
358  Field<Vector<Cmpt>>& result
359 )
360 {
361  const label len = input.size();
362 
363  #ifdef FULLDEBUG
364  if (len != result.size())
365  {
367  << "Components sizes do not match: " << len << " ("
368  << result.size() << ')'
369  << nl
370  << abort(FatalError);
371  }
372  #endif
373 
374  for (label i=0; i < len; ++i)
375  {
376  result[i] = input[i].diag();
377  }
378 }
379 
380 
381 template<class Cmpt>
384 (
385  const Field<Tensor<Cmpt>>& input,
386  const vector::components cmpt
387 )
388 {
389  auto tresult = tmp<Field<Vector<Cmpt>>>::New(input.size());
390 
391  Foam::unzipRow(input, cmpt, tresult.ref());
392 
393  return tresult;
394 }
395 
396 
397 template<class Cmpt>
400 (
401  const Field<Tensor<Cmpt>>& input,
402  const vector::components cmpt
403 )
404 {
405  auto tresult = tmp<Field<Vector<Cmpt>>>::New(input.size());
406 
407  Foam::unzipCol(input, cmpt, tresult.ref());
408 
409  return tresult;
410 }
411 
412 
413 template<class Cmpt>
416 (
417  const Field<Tensor<Cmpt>>& input
418 )
419 {
420  auto tresult = tmp<Field<Vector<Cmpt>>>::New(input.size());
421 
422  Foam::unzipDiag(input, tresult.ref());
423 
424  return tresult;
425 }
426 
427 
428 // ************************************************************************* //
Foam::Tensor
A templated (3 x 3) tensor of objects of <T> derived from MatrixSpace.
Definition: complexI.H:275
Foam::zipCols
void zipCols(FieldField< Field, Tensor< Cmpt >> &result, const FieldField< Field, Vector< Cmpt >> &x, const FieldField< Field, Vector< Cmpt >> &y, const FieldField< Field, Vector< Cmpt >> &z)
Zip together tensor field from column components.
Definition: tensorFieldField.C:113
Foam::unzipRows
void unzipRows(const FieldField< Field, Tensor< Cmpt >> &input, FieldField< Field, Vector< Cmpt >> &x, FieldField< Field, Vector< Cmpt >> &y, FieldField< Field, Vector< Cmpt >> &z)
Extract tensor field field rows.
Definition: tensorFieldField.C:129
Foam::unzip
void unzip(const FieldField< Field, SphericalTensor< Cmpt >> &input, FieldField< Field, Cmpt > &ii)
Unzip sphericalTensor field field into components.
Definition: sphericalTensorFieldField.C:55
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::unzipRow
void unzipRow(const FieldField< Field, Tensor< Cmpt >> &input, const vector::components cmpt, FieldField< Field, Vector< Cmpt >> &result)
Extract a tensor field field row (x,y,z) == (0,1,2)
Definition: tensorFieldField.C:161
Foam::zipRows
void zipRows(FieldField< Field, Tensor< Cmpt >> &result, const FieldField< Field, Vector< Cmpt >> &x, const FieldField< Field, Vector< Cmpt >> &y, const FieldField< Field, Vector< Cmpt >> &z)
Zip together tensor field field from row components.
Definition: tensorFieldField.C:97
Foam::unzipCols
void unzipCols(const FieldField< Field, Tensor< Cmpt >> &input, FieldField< Field, Vector< Cmpt >> &x, FieldField< Field, Vector< Cmpt >> &y, FieldField< Field, Vector< Cmpt >> &z)
Extract tensor field field columns.
Definition: tensorFieldField.C:145
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Y
PtrList< volScalarField > & Y
Definition: createFieldRefs.H:7
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::unzipCol
void unzipCol(const FieldField< Field, Tensor< Cmpt >> &input, const vector::components cmpt, FieldField< Field, Vector< Cmpt >> &result)
Extract a tensor field field column (x,y,z) == (0,1,2)
Definition: tensorFieldField.C:176
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:62
Foam::UList
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:103
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::zip
void zip(FieldField< Field, SphericalTensor< Cmpt >> &result, const FieldField< Field, Cmpt > &ii)
Zip together sphericalTensor field field from components.
Definition: sphericalTensorFieldField.C:41
Foam::unzipDiag
void unzipDiag(const FieldField< Field, SymmTensor< Cmpt >> &input, FieldField< Field, Vector< Cmpt >> &result)
Extract a symmTensor field field diagonal.
Definition: symmTensorFieldField.C:91
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
y
scalar y
Definition: LISASMDCalcMethod1.H:14