Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::SymmTensor
29
30Description
31 A templated (3 x 3) symmetric tensor of objects of <T>, effectively
32 containing 6 elements, derived from VectorSpace.
33
34SourceFiles
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
47namespace Foam
48{
49
50/*---------------------------------------------------------------------------*\
51 Class SymmTensor Declaration
52\*---------------------------------------------------------------------------*/
53
54template<class Cmpt>
55class SymmTensor
56:
57 public VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>
58{
59public:
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
75 static const SymmTensor I;
76
77
78 //- Component labeling enumeration
79 enum components { XX, XY, XZ, YY, YZ, ZZ };
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
94 // Constructors
95
96 //- Construct initialized to zero
97 inline SymmTensor(Foam::zero);
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
118 const Cmpt txx, const Cmpt txy, const Cmpt txz,
119 const Cmpt tyy, const Cmpt tyz,
120 const Cmpt tzz
121 );
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 (
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;
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 // Characteristics
238
239 //- Is identity tensor?
240 inline bool is_identity(const scalar tol = ROOTVSMALL) const;
241
242
243 // Tensor Operations
245 //- Return non-Hermitian transpose
246 const SymmTensor<Cmpt>& T() const noexcept { return *this; }
247
248 //- The determinate
249 inline Cmpt det() const;
251 //- The 2D determinant by excluding given direction
252 inline Cmpt det2D(const direction excludeCmpt) const;
253
254 //- Return adjunct matrix (transpose of cofactor matrix)
255 inline SymmTensor<Cmpt> adjunct() const;
256
257 //- Return cofactor matrix (transpose of adjunct matrix)
258 inline SymmTensor<Cmpt> cof() const;
259
260 //- Return 2D adjunct matrix by excluding given direction
261 inline SymmTensor<Cmpt> adjunct2D(const direction excludeCmpt) const;
262
263 //- Return inverse
264 inline SymmTensor<Cmpt> inv() const;
265
266 //- Return inverse, with (ad hoc) failsafe handling of 2D tensors
267 inline SymmTensor<Cmpt> safeInv() const;
268
269 //- Return inverse of 2D tensor (by excluding given direction)
270 inline SymmTensor<Cmpt> inv2D(const direction excludeCmpt) const;
271
272
273 // Member Operators
274
275 //- Inherit VectorSpace assignment operators
277
278 //- Assign to given SphericalTensor
279 inline void operator=(const SphericalTensor<Cmpt>&);
280};
281
282
283// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
284
285//- Data are contiguous if component type is contiguous
286template<class Cmpt>
287struct is_contiguous<SymmTensor<Cmpt>> : is_contiguous<Cmpt> {};
289//- Data are contiguous label if component type is label
290template<class Cmpt>
291struct is_contiguous_label<SymmTensor<Cmpt>> : is_contiguous_label<Cmpt> {};
292
293//- Data are contiguous scalar if component type is scalar
294template<class Cmpt>
296
297
298template<class Cmpt>
299class symmTypeOfRank<Cmpt, 2>
300{
301public:
302
303 typedef SymmTensor<Cmpt> type;
304};
305
306
307template<class Cmpt>
308class typeOfSolve<SymmTensor<Cmpt>>
310public:
311
313};
315
316// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317
318} // End namespace Foam
320// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321
322#include "SymmTensorI.H"
323
324// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325
326#endif
327
328// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 1 element,...
A templated (3 x 3) symmetric tensor of objects of <T>, effectively containing 6 elements,...
Definition SymmTensor.H:53
void diag(const Vector< Cmpt > &v)
Set values of the diagonal.
Cmpt & xy() noexcept
Definition SymmTensor.H:161
scalar diagSqr() const
The L2-norm squared of the diagonal.
void row(const Vector< Cmpt > &v)
Set values of given row: compile-time check of index.
bool is_identity(const scalar tol=ROOTVSMALL) const
Is identity tensor?
SymmTensor(Foam::zero)
Construct initialized to zero.
Definition SymmTensorI.H:27
SymmTensor< Cmpt > adjunct() const
Return adjunct matrix (transpose of cofactor matrix).
Cmpt & yz() noexcept
Definition SymmTensor.H:165
SymmTensor< Cmpt > inv2D(const direction excludeCmpt) const
Return inverse of 2D tensor (by excluding given direction).
const Cmpt & yy() const noexcept
Definition SymmTensor.H:154
const SymmTensor< Cmpt > & T() const noexcept
Return non-Hermitian transpose.
Definition SymmTensor.H:309
void addDiag(const Vector< Cmpt > &v)
Add to the diagonal.
void rows(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set row values.
components
Component labeling enumeration.
Definition SymmTensor.H:80
SymmTensor(const SymmTensor &)=default
Copy construct.
Cmpt & zx() noexcept
Definition SymmTensor.H:166
Cmpt det2D(const direction excludeCmpt) const
The 2D determinant by excluding given direction.
void row(const direction r, const Vector< Cmpt > &v)
Set values of given row (0,1,2): runtime check of row.
Vector< Cmpt > row() const
Extract vector for given row: compile-time check of index.
void subtractDiag(const Vector< Cmpt > &v)
Subtract from the diagonal.
SymmTensor< Cmpt > cof() const
Return cofactor matrix (transpose of adjunct matrix).
Vector< scalar > z() const
Cmpt & zy() noexcept
Definition SymmTensor.H:167
static constexpr direction rank
Definition SymmTensor.H:69
const Cmpt & zy() const noexcept
Definition SymmTensor.H:157
const Cmpt & yx() const noexcept
Definition SymmTensor.H:153
void col(const direction c, const Vector< Cmpt > &v)
Set values of given column (0,1,2): runtime check of index.
Definition SymmTensor.H:202
Cmpt & xx() noexcept
Definition SymmTensor.H:160
Vector< Cmpt > cy() const
Extract vector for column 1.
Definition SymmTensor.H:181
Cmpt & zz() noexcept
Definition SymmTensor.H:168
SymmTensor(Istream &is)
Construct from Istream.
Definition SymmTensorI.H:81
Vector< Cmpt > cz() const
Extract vector for column 2.
Definition SymmTensor.H:186
SymmTensor< Cmpt > adjunct2D(const direction excludeCmpt) const
Return 2D adjunct matrix by excluding given direction.
SymmTensor(const Cmpt txx, const Cmpt txy, const Cmpt txz, const Cmpt tyy, const Cmpt tyz, const Cmpt tzz)
Construct given the six components.
Definition SymmTensorI.H:68
SymmTensor(const SphericalTensor< Cmpt > &)
Construct given SphericalTensor.
Definition SymmTensorI.H:45
Cmpt det() const
The determinate.
Vector< Cmpt > cx() const
Extract vector for column 0.
Definition SymmTensor.H:176
Vector< Cmpt > col(const direction c) const
Extract vector for given column (0,1,2): runtime check of index.
Definition SymmTensor.H:197
Cmpt & yx() noexcept
Definition SymmTensor.H:163
Vector< Cmpt > row(const direction r) const
Extract vector for given row (0,1,2): runtime check of index.
SymmTensor(const VectorSpace< SymmTensor< Cmpt2 >, Cmpt2, 6 > &)
Construct given VectorSpace of the same rank.
Definition SymmTensorI.H:36
void cols(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set column values.
Definition SymmTensor.H:208
SymmTensor(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z, const bool transposed=false)
Construct given the three row (or column) vectors.
Definition SymmTensorI.H:55
Vector< scalar > y() const
const Cmpt & xx() const noexcept
Definition SymmTensor.H:150
Cmpt & xz() noexcept
Definition SymmTensor.H:162
SymmTensor< Cmpt > safeInv() const
Return inverse, with (ad hoc) failsafe handling of 2D tensors.
Vector< Cmpt > col() const
Extract vector for given column: compile-time check of index.
Definition SymmTensor.H:192
static const SymmTensor I
Definition SymmTensor.H:74
const Cmpt & yz() const noexcept
Definition SymmTensor.H:155
void operator=(const SphericalTensor< Cmpt > &)
Assign to given SphericalTensor.
Vector< Cmpt > diag() const
Extract the diagonal as a vector.
SymmTensor< Cmpt > inv() const
Return inverse.
const Cmpt & zz() const noexcept
Definition SymmTensor.H:158
const Cmpt & xy() const noexcept
Definition SymmTensor.H:151
SymmTensor & operator=(const SymmTensor &)=default
Copy assignment.
Cmpt & yy() noexcept
Definition SymmTensor.H:164
SymmTensor()=default
Default construct.
SymmTensor< label > labelType
Definition SymmTensor.H:61
const Cmpt & xz() const noexcept
Definition SymmTensor.H:152
const Cmpt & zx() const noexcept
Definition SymmTensor.H:156
Vector< scalar > x() const
Cmpt v_[Ncmpts]
The components of this vector space.
Definition VectorSpace.H:81
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition Vector.H:61
SymmTensor< solveScalar > type
Definition SymmTensor.H:401
The extended precision type (solveScalar for float).
Definition products.H:81
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
Namespace for OpenFOAM.
uint8_t direction
Definition direction.H:49
const direction noexcept
Definition scalarImpl.H:265
A template class to specify if a data type is composed solely of Foam::label elements.
Definition contiguous.H:82
A template class to specify if a data type is composed solely of Foam::scalar elements.
Definition contiguous.H:87
A template class to specify that a data type can be considered as being contiguous in memory.
Definition contiguous.H:70