SymmTensor.H
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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::SymmTensor
29 
30 Description
31  A templated (3 x 3) symmetric tensor of objects of <T>, effectively
32  containing 6 elements, derived from VectorSpace.
33 
34 SourceFiles
35  SymmTensorI.H
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_SymmTensor_H
40 #define Foam_SymmTensor_H
41 
42 #include "Vector.H"
43 #include "SphericalTensor.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class SymmTensor Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 template<class Cmpt>
55 class SymmTensor
56 :
57  public VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>
58 {
59 public:
60 
61  // Typedefs
62 
63  //- Equivalent type of labels used for valid component indexing
65 
66 
67  // Member Constants
68 
69  //- Rank of SymmTensor is 2
70  static constexpr direction rank = 2;
71 
72 
73  // Static Data Members
74 
75  static const SymmTensor I;
76 
77 
78  //- Component labeling enumeration
79  enum components { XX, XY, XZ, YY, YZ, ZZ };
80 
81 
82  // Generated Methods
83 
84  //- Default construct
85  SymmTensor() = default;
86 
87  //- Copy construct
88  SymmTensor(const SymmTensor&) = default;
89 
90  //- Copy assignment
91  SymmTensor& operator=(const SymmTensor&) = default;
92 
93 
94  // Constructors
95 
96  //- Construct initialized to zero
97  inline SymmTensor(const Foam::zero);
98 
99  //- Construct given VectorSpace of the same rank
100  template<class Cmpt2>
101  inline SymmTensor(const VectorSpace<SymmTensor<Cmpt2>, Cmpt2, 6>&);
102 
103  //- Construct given SphericalTensor
104  inline SymmTensor(const SphericalTensor<Cmpt>&);
105 
106  //- Construct given the three row (or column) vectors
107  inline SymmTensor
108  (
109  const Vector<Cmpt>& x,
110  const Vector<Cmpt>& y,
111  const Vector<Cmpt>& z,
112  const bool transposed = false /* ignored */
113  );
114 
115  //- Construct given the six components
116  inline SymmTensor
117  (
118  const Cmpt txx, const Cmpt txy, const Cmpt txz,
119  const Cmpt tyy, const Cmpt tyz,
120  const Cmpt tzz
121  );
122 
123  //- Construct from Istream
124  inline explicit SymmTensor(Istream& is);
125 
126 
127  // Member Functions
128 
129  // Component Access
130 
131  const Cmpt& xx() const noexcept { return this->v_[XX]; }
132  const Cmpt& xy() const noexcept { return this->v_[XY]; }
133  const Cmpt& xz() const noexcept { return this->v_[XZ]; }
134  const Cmpt& yx() const noexcept { return this->v_[XY]; }
135  const Cmpt& yy() const noexcept { return this->v_[YY]; }
136  const Cmpt& yz() const noexcept { return this->v_[YZ]; }
137  const Cmpt& zx() const noexcept { return this->v_[XZ]; }
138  const Cmpt& zy() const noexcept { return this->v_[YZ]; }
139  const Cmpt& zz() const noexcept { return this->v_[ZZ]; }
140 
141  Cmpt& xx() noexcept { return this->v_[XX]; }
142  Cmpt& xy() noexcept { return this->v_[XY]; }
143  Cmpt& xz() noexcept { return this->v_[XZ]; }
144  Cmpt& yx() noexcept { return this->v_[XY]; }
145  Cmpt& yy() noexcept { return this->v_[YY]; }
146  Cmpt& yz() noexcept { return this->v_[YZ]; }
147  Cmpt& zx() noexcept { return this->v_[XZ]; }
148  Cmpt& zy() noexcept { return this->v_[YZ]; }
149  Cmpt& zz() noexcept { return this->v_[ZZ]; }
152  // Column-vector access
154  //- Extract vector for column 0
155  Vector<Cmpt> cx() const { return this->x(); }
157  //- Extract vector for column 1
158  Vector<Cmpt> cy() const { return this->y(); }
159 
160  //- Extract vector for column 2
161  Vector<Cmpt> cz() const { return this->z(); }
163  //- Extract vector for given column: compile-time check of index
164  template<direction Idx>
165  Vector<Cmpt> col() const { return this->row<Idx>(); }
167  //- Extract vector for given column (0,1,2): runtime check of index
168  Vector<Cmpt> col(const direction c) const { return this->row(c); }
169 
170  //- Set values of given column (0,1,2): runtime check of index
171  void col(const direction c, const Vector<Cmpt>& v) { this->row(c, v); }
172 
173  //- Set column values
174  void cols
175  (
176  const Vector<Cmpt>& x,
177  const Vector<Cmpt>& y,
178  const Vector<Cmpt>& z
179  )
180  {
181  this->rows(x, y, z);
182  }
183 
184 
185  // Row-vector access
187  //- Extract vector for row 0
188  inline Vector<Cmpt> x() const;
189 
190  //- Extract vector for row 1
191  inline Vector<Cmpt> y() const;
193  //- Extract vector for row 2
194  inline Vector<Cmpt> z() const;
195 
196  //- Extract vector for given row: compile-time check of index
197  template<direction Row>
198  inline Vector<Cmpt> row() const;
199 
200  //- Extract vector for given row (0,1,2): runtime check of index
201  inline Vector<Cmpt> row(const direction r) const;
203  //- Set values of given row: compile-time check of index
204  template<direction Idx>
205  inline void row(const Vector<Cmpt>& v);
206 
207  //- Set values of given row (0,1,2): runtime check of row
208  inline void row(const direction r, const Vector<Cmpt>& v);
209 
210  //- Set row values
211  inline void rows
212  (
213  const Vector<Cmpt>& x,
214  const Vector<Cmpt>& y,
215  const Vector<Cmpt>& z
216  );
217 
218 
219  // Diagonal access and manipulation
220 
221  //- Extract the diagonal as a vector
222  inline Vector<Cmpt> diag() const;
223 
224  //- Set values of the diagonal
225  inline void diag(const Vector<Cmpt>& v);
226 
227  //- Add to the diagonal
228  inline void addDiag(const Vector<Cmpt>& v);
229 
230  //- Subtract from the diagonal
231  inline void subtractDiag(const Vector<Cmpt>& v);
232 
233  //- The L2-norm squared of the diagonal
234  inline scalar diagSqr() const;
235 
236 
237  // Tensor Operations
238 
239  //- Return non-Hermitian transpose
240  const SymmTensor<Cmpt>& T() const noexcept { return *this; }
241 
242  //- The determinate
243  inline Cmpt det() const;
244 
245  //- The 2D determinant by excluding given direction
246  inline Cmpt det2D(const direction excludeCmpt) const;
247 
248  //- Return adjunct matrix (transpose of cofactor matrix)
249  inline SymmTensor<Cmpt> adjunct() const;
250 
251  //- Return cofactor matrix (transpose of adjunct matrix)
252  inline SymmTensor<Cmpt> cof() const;
253 
254  //- Return 2D adjunct matrix by excluding given direction
255  inline SymmTensor<Cmpt> adjunct2D(const direction excludeCmpt) const;
256 
257  //- Return inverse
258  inline SymmTensor<Cmpt> inv() const;
259 
260  //- Return inverse, with (ad hoc) failsafe handling of 2D tensors
261  inline SymmTensor<Cmpt> safeInv() const;
262 
263  //- Return inverse of 2D tensor (by excluding given direction)
264  inline SymmTensor<Cmpt> inv2D(const direction excludeCmpt) const;
265 
266 
267  // Member Operators
268 
269  //- Inherit VectorSpace assignment operators
271 
272  //- Assign to given SphericalTensor
273  inline void operator=(const SphericalTensor<Cmpt>&);
274 };
275 
276 
277 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
278 
279 //- Data are contiguous if component type is contiguous
280 template<class Cmpt>
281 struct is_contiguous<SymmTensor<Cmpt>> : is_contiguous<Cmpt> {};
282 
283 //- Data are contiguous label if component type is label
284 template<class Cmpt>
285 struct is_contiguous_label<SymmTensor<Cmpt>> : is_contiguous_label<Cmpt> {};
286 
287 //- Data are contiguous scalar if component type is scalar
288 template<class Cmpt>
289 struct is_contiguous_scalar<SymmTensor<Cmpt>> : is_contiguous_scalar<Cmpt> {};
290 
291 
292 template<class Cmpt>
293 class symmTypeOfRank<Cmpt, 2>
294 {
295 public:
296 
297  typedef SymmTensor<Cmpt> type;
298 };
299 
300 
301 template<class Cmpt>
302 class typeOfSolve<SymmTensor<Cmpt>>
303 {
304 public:
305 
307 };
308 
309 
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 
312 } // End namespace Foam
313 
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
315 
316 #include "SymmTensorI.H"
317 
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 
320 #endif
321 
322 // ************************************************************************* //
Vector< Cmpt > x() const
Extract vector for row 0.
Definition: SymmTensorI.H:90
const Cmpt & xz() const noexcept
Definition: SymmTensor.H:152
components
Component labeling enumeration.
Definition: SymmTensor.H:80
uint8_t direction
Definition: direction.H:46
Vector< Cmpt > cx() const
Extract vector for column 0.
Definition: SymmTensor.H:176
A templated (3 x 3) symmetric tensor of objects of <T>, effectively containing 6 elements, derived from VectorSpace.
Definition: SymmTensor.H:50
static constexpr direction rank
Rank of SymmTensor is 2.
Definition: SymmTensor.H:69
SymmTensor< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: SymmTensor.H:61
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Templated vector space.
Definition: VectorSpace.H:52
SymmTensor< Cmpt > safeInv() const
Return inverse, with (ad hoc) failsafe handling of 2D tensors.
Definition: SymmTensorI.H:361
Cmpt det() const
The determinate.
Definition: SymmTensorI.H:235
const Cmpt & zz() const noexcept
Definition: SymmTensor.H:158
SymmTensor< Cmpt > adjunct() const
Return adjunct matrix (transpose of cofactor matrix)
Definition: SymmTensorI.H:268
void subtractDiag(const Vector< Cmpt > &v)
Subtract from the diagonal.
Definition: SymmTensorI.H:216
Vector< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: SymmTensorI.H:195
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 1 element, derived from VectorSpace.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
static const SymmTensor I
Definition: SymmTensor.H:74
const Cmpt & zy() const noexcept
Definition: SymmTensor.H:157
SymmTensor< Cmpt > inv2D(const direction excludeCmpt) const
Return inverse of 2D tensor (by excluding given direction)
Definition: SymmTensorI.H:329
The extended precision type (solveScalar for float)
Definition: products.H:80
scalar diagSqr() const
The L2-norm squared of the diagonal.
Definition: SymmTensorI.H:223
Vector< Cmpt > y() const
Extract vector for row 1.
Definition: SymmTensorI.H:97
SymmTensor< Cmpt > adjunct2D(const direction excludeCmpt) const
Return 2D adjunct matrix by excluding given direction.
Definition: SymmTensorI.H:290
SymmTensor< Cmpt > cof() const
Return cofactor matrix (transpose of adjunct matrix)
Definition: SymmTensorI.H:281
Vector< Cmpt > cy() const
Extract vector for column 1.
Definition: SymmTensor.H:181
const Cmpt & xx() const noexcept
Definition: SymmTensor.H:150
SymmTensor & operator=(const SymmTensor &)=default
Copy assignment.
Templated 3D Vector derived from VectorSpace adding construction from 3 components, element access using x(), y() and z() member functions and the inner-product (dot-product) and cross-product operators.
Definition: Vector.H:58
const direction noexcept
Definition: Scalar.H:258
Cmpt det2D(const direction excludeCmpt) const
The 2D determinant by excluding given direction.
Definition: SymmTensorI.H:247
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
const SymmTensor< Cmpt > & T() const noexcept
Return non-Hermitian transpose.
Definition: SymmTensor.H:301
Vector< Cmpt > cz() const
Extract vector for column 2.
Definition: SymmTensor.H:186
Vector< Cmpt > col() const
Extract vector for given column: compile-time check of index.
Definition: SymmTensor.H:192
void addDiag(const Vector< Cmpt > &v)
Add to the diagonal.
Definition: SymmTensorI.H:209
const Cmpt & yy() const noexcept
Definition: SymmTensor.H:154
void cols(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set column values.
Definition: SymmTensor.H:208
const dimensionedScalar c
Speed of light in a vacuum.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
const Cmpt & zx() const noexcept
Definition: SymmTensor.H:156
SymmTensor< Cmpt > inv() const
Return inverse.
Definition: SymmTensorI.H:341
const Cmpt & yx() const noexcept
Definition: SymmTensor.H:153
Vector< Cmpt > row() const
Extract vector for given row: compile-time check of index.
const Cmpt & xy() const noexcept
Definition: SymmTensor.H:151
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:81
void rows(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set row values.
Definition: SymmTensorI.H:163
Namespace for OpenFOAM.
Vector< Cmpt > z() const
Extract vector for row 2.
Definition: SymmTensorI.H:104
const Cmpt & yz() const noexcept
Definition: SymmTensor.H:155
SymmTensor()=default
Default construct.