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-2022 OpenCFD Ltd.
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// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
29
30template<class Cmpt>
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
73template<class Cmpt>
75(
76 const UList<Tensor<Cmpt>>& input,
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
111template<class Cmpt>
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
128template<class Cmpt>
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
157template<class Cmpt>
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
186template<class Cmpt>
188(
189 const UList<Tensor<Cmpt>>& input,
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
217template<class Cmpt>
219(
220 const UList<Tensor<Cmpt>>& input,
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
248template<class Cmpt>
250(
251 const UList<Tensor<Cmpt>>& input,
252 const direction idx,
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 (idx)
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
301template<class Cmpt>
303(
304 const UList<Tensor<Cmpt>>& input,
305 const direction idx,
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 (idx)
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
354template<class Cmpt>
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
381template<class Cmpt>
384(
385 const Field<Tensor<Cmpt>>& input,
386 const direction idx
387)
388{
389 auto tresult = tmp<Field<Vector<Cmpt>>>::New(input.size());
390
391 Foam::unzipRow(input, idx, tresult.ref());
392
393 return tresult;
394}
395
396
397template<class Cmpt>
400(
401 const Field<Tensor<Cmpt>>& input,
402 const direction idx
403)
404{
405 auto tresult = tmp<Field<Vector<Cmpt>>>::New(input.size());
406
407 Foam::unzipCol(input, idx, tresult.ref());
408
409 return tresult;
410}
411
412
413template<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// ************************************************************************* //
scalar y
Generic templated field type.
Definition: Field.H:82
A templated (3 x 3) tensor of objects of <T> derived from MatrixSpace.
Definition: Tensor.H:64
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
static constexpr direction size() noexcept
The number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpace.H:176
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:65
A class for managing temporary objects.
Definition: tmp.H:65
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
void zipCols(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 from column components.
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 unzipDiag(const FieldField< Field, SymmTensor< Cmpt > > &input, FieldField< Field, Vector< Cmpt > > &result)
Extract a symmTensor field field diagonal.
void unzipCol(const FieldField< Field, SymmTensor< Cmpt > > &input, const direction idx, FieldField< Field, Vector< Cmpt > > &result)
Extract a symmTensor field field column (x,y,z) == (0,1,2)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
uint8_t direction
Definition: direction.H:56
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 unzip(const FieldField< Field, SphericalTensor< Cmpt > > &input, FieldField< Field, Cmpt > &ii)
Unzip sphericalTensor field field into components.
error FatalError
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 unzipCols(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 columns.
void zip(FieldField< Field, SphericalTensor< Cmpt > > &result, const FieldField< Field, Cmpt > &ii)
Zip together sphericalTensor field field from components.
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53