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 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 (
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);
123 
124  return tresult;
125 }
126 
127 
128 template<class Cmpt>
129 void Foam::unzipDiag
130 (
131  const UList<SymmTensor<Cmpt>>& input,
132  Field<Vector<Cmpt>>& result
133 )
134 {
135  const label len = input.size();
136 
137  #ifdef FULLDEBUG
138  if (len != result.size())
139  {
141  << "Components sizes do not match: " << len << " ("
142  << result.size() << ')'
143  << nl
144  << abort(FatalError);
145  }
146  #endif
147 
148  for (label i=0; i < len; ++i)
149  {
150  result[i] = input[i].diag();
151  }
152 }
153 
154 
155 template<class Cmpt>
158 (
159  const Field<SymmTensor<Cmpt>>& input
160 )
161 {
162  auto tresult = tmp<Field<Vector<Cmpt>>>::New(input.size());
163 
164  Foam::unzipDiag(input, tresult.ref());
165 
166  return tresult;
167 }
168 
169 
170 // ************************************************************************* //
Foam::SymmTensor
A templated (3 x 3) symmetric tensor of objects of <T>, effectively containing 6 elements,...
Definition: SymmTensor.H:58
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::Field
Generic templated field type.
Definition: Field.H:63
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
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
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
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
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::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
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::VectorSpace::size
static constexpr direction size() noexcept
The number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpace.H:176