Tensor.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) 2018-2022 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::Tensor
29
30Description
31 A templated (3 x 3) tensor of objects of <T> derived from MatrixSpace.
32
33SourceFiles
34 TensorI.H
35
36See also
37 Foam::MatrixSpace
38 Foam::Vector
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef Foam_Tensor_H
43#define Foam_Tensor_H
44
45#include "MatrixSpace.H"
46#include "Vector.H"
47#include "SphericalTensor.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53
54// Forward Declarations
55template<class Cmpt> class SymmTensor;
56
57/*---------------------------------------------------------------------------*\
58 Class Tensor Declaration
59\*---------------------------------------------------------------------------*/
60
61template<class Cmpt>
62class Tensor
63:
64 public MatrixSpace<Tensor<Cmpt>, Cmpt, 3, 3>
65{
66public:
67
68 // Typedefs
69
70 //- Equivalent type of labels used for valid component indexing
72
73
74 // Member Constants
75
76 //- Rank of Tensor is 2
77 static constexpr direction rank = 2;
78
79
80 // Static Data Members
82 static const Tensor I;
83
84
85 //- Component labeling enumeration
86 enum components { XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ };
87
88
89 // Generated Methods
90
91 //- Default construct
92 Tensor() = default;
93
94 //- Copy construct
95 Tensor(const Tensor&) = default;
96
97 //- Copy assignment
98 Tensor& operator=(const Tensor&) = default;
99
100
101 // Constructors
102
103 //- Construct initialized to zero
104 inline Tensor(const Foam::zero);
105
106 //- Construct given MatrixSpace of the same rank
107 template<class Cmpt2>
108 inline Tensor(const MatrixSpace<Tensor<Cmpt2>, Cmpt2, 3, 3>& vs);
109
110 //- Construct given VectorSpace of the same rank
111 template<class Cmpt2>
112 inline Tensor(const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>& vs);
113
114 //- Construct given SphericalTensor
115 inline Tensor(const SphericalTensor<Cmpt>& st);
116
117 //- Construct given SymmTensor
118 inline Tensor(const SymmTensor<Cmpt>& st);
119
120 //- Construct given triad of row vectors,
121 //- optionally treated as transposed (ie, column vectors)
122 inline Tensor
123 (
124 const Vector<Vector<Cmpt>>& vecs,
125 const bool transposed = false
126 );
127
128 //- Construct given the three row vectors,
129 //- optionally treated as transposed (ie, column vectors)
130 inline Tensor
131 (
132 const Vector<Cmpt>& x,
133 const Vector<Cmpt>& y,
134 const Vector<Cmpt>& z,
135 const bool transposed = false
136 );
137
138 //- Construct given the nine components
139 inline Tensor
140 (
141 const Cmpt txx, const Cmpt txy, const Cmpt txz,
142 const Cmpt tyx, const Cmpt tyy, const Cmpt tyz,
143 const Cmpt tzx, const Cmpt tzy, const Cmpt tzz
144 );
145
146 //- Construct from a block of another matrix space
147 template
148 <
149 template<class, direction, direction> class Block2,
150 direction BRowStart,
151 direction BColStart
152 >
153 Tensor
154 (
155 const Block2<Tensor<Cmpt>, BRowStart, BColStart>& block
156 );
157
158 //- Construct from Istream
159 inline explicit Tensor(Istream& is);
160
161
162 // Member Functions
163
164 // Component access
165
166 inline const Cmpt& xx() const;
167 inline const Cmpt& xy() const;
168 inline const Cmpt& xz() const;
169 inline const Cmpt& yx() const;
170 inline const Cmpt& yy() const;
171 inline const Cmpt& yz() const;
172 inline const Cmpt& zx() const;
173 inline const Cmpt& zy() const;
174 inline const Cmpt& zz() const;
175
176 inline Cmpt& xx();
177 inline Cmpt& xy();
178 inline Cmpt& xz();
179 inline Cmpt& yx();
180 inline Cmpt& yy();
181 inline Cmpt& yz();
182 inline Cmpt& zx();
183 inline Cmpt& zy();
184 inline Cmpt& zz();
185
186
187 // Column-vector access
188
189 //- Extract vector for column 0
190 inline Vector<Cmpt> cx() const;
191
192 //- Extract vector for column 1
193 inline Vector<Cmpt> cy() const;
194
195 //- Extract vector for column 2
196 inline Vector<Cmpt> cz() const;
197
198 //- Extract vector for given column: compile-time check of index
199 template<direction Idx>
200 inline Vector<Cmpt> col() const;
201
202 //- Extract vector for given column (0,1,2): runtime check of index
203 inline Vector<Cmpt> col(const direction c) const;
204
205 //- Set values of given column: compile-time check of index
206 template<direction Idx>
207 inline void col(const Vector<Cmpt>& v);
208
209 //- Set values of given column (0,1,2): runtime check of index
210 inline void col(const direction c, const Vector<Cmpt>& v);
211
212 //- Set column values
213 inline void cols
214 (
215 const Vector<Cmpt>& x,
216 const Vector<Cmpt>& y,
217 const Vector<Cmpt>& z
218 );
219
220
221 // Row-vector access
222
223 //- Extract vector for row 0
224 inline Vector<Cmpt> x() const;
225
226 //- Extract vector for row 1
227 inline Vector<Cmpt> y() const;
228
229 //- Extract vector for row 2
230 inline Vector<Cmpt> z() const;
231
232 //- Extract vector for given row: compile-time check of index
233 template<direction Idx>
234 inline Vector<Cmpt> row() const;
235
236 //- Extract vector for given row (0,1,2): runtime check of index
237 inline Vector<Cmpt> row(const direction r) const;
238
239 //- Set values of given row: compile-time check of index
240 template<direction Idx>
241 inline void row(const Vector<Cmpt>& v);
242
243 //- Set values of given row (0,1,2): runtime check of row
244 inline void row(const direction r, const Vector<Cmpt>& v);
245
246 //- Set row values
247 inline void rows
248 (
249 const Vector<Cmpt>& x,
250 const Vector<Cmpt>& y,
251 const Vector<Cmpt>& z
252 );
253
254
255 // Diagonal access and manipulation
256
257 //- Extract the diagonal as a vector
258 inline Vector<Cmpt> diag() const;
259
260 //- Set values of the diagonal
261 inline void diag(const Vector<Cmpt>& v);
262
263
264 // Characteristics
265
266 //- Is identity tensor?
267 inline bool is_identity(const scalar tol = ROOTVSMALL) const;
268
269
270 // Tensor Operations
271
272 //- Return non-Hermitian transpose
273 inline Tensor<Cmpt> T() const;
274
275 //- Return inverse
276 inline Tensor<Cmpt> inv() const;
277
278 //- Inner-product of this with another Tensor.
279 inline Tensor<Cmpt> inner(const Tensor<Cmpt>& t2) const;
280
281 //- Schur-product of this with another Tensor.
282 inline Tensor<Cmpt> schur(const Tensor<Cmpt>& t2) const;
283
284
285 // Member Operators
286
287 //- Assign inner-product of this with another Tensor.
288 inline void operator&=(const Tensor<Cmpt>& t);
289
290 //- Inherit MatrixSpace assignment operators
292
293 //- Assign to an equivalent vector space
294 template<class Cmpt2>
295 inline void operator=(const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>&);
296
297 //- Assign to a SphericalTensor
298 inline void operator=(const SphericalTensor<Cmpt>&);
299
300 //- Assign to a SymmTensor
301 inline void operator=(const SymmTensor<Cmpt>&);
302
303 //- Assign to a triad of row vectors
304 inline void operator=(const Vector<Vector<Cmpt>>&);
305
306
307 // Housekeeping
308
309 //- Deprecated(2018-12) Return vector for given row (0,1)
310 // \deprecated(2018-12) use row() method
311 Vector<Cmpt> vectorComponent(const direction cmpt) const
312 {
313 return row(cmpt);
314 }
315};
316
317
318// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
319
320//- Data are contiguous if component type is contiguous
321template<class Cmpt>
322struct is_contiguous<Tensor<Cmpt>> : is_contiguous<Cmpt> {};
323
324//- Data are contiguous label if component type is label
325template<class Cmpt>
326struct is_contiguous_label<Tensor<Cmpt>> : is_contiguous_label<Cmpt> {};
327
328//- Data are contiguous scalar if component type is scalar
329template<class Cmpt>
330struct is_contiguous_scalar<Tensor<Cmpt>> : is_contiguous_scalar<Cmpt> {};
331
332
333template<class Cmpt>
334class typeOfRank<Cmpt, 2>
335{
336public:
338 typedef Tensor<Cmpt> type;
339};
340
341
342template<class Cmpt>
343class typeOfTranspose<Cmpt, Tensor<Cmpt>>
344{
345public:
347 typedef Tensor<Cmpt> type;
348};
349
350
351template<class Cmpt>
352class typeOfSolve<Tensor<Cmpt>>
353{
354public:
357};
358
359
360// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361
362} // End namespace Foam
363
364// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365
366// Include inline implementations
367#include "TensorI.H"
368
369// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370
371#endif
372
373// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
Templated matrix space.
Definition: MatrixSpace.H:61
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:57
A templated (3 x 3) tensor of objects of <T> derived from MatrixSpace.
Definition: Tensor.H:64
bool is_identity(const scalar tol=ROOTVSMALL) const
Is identity tensor?
Definition: TensorI.H:509
Tensor< Cmpt > T() const
Return non-Hermitian transpose.
Definition: TensorI.H:526
const Cmpt & xx() const
Definition: TensorI.H:153
const Cmpt & yx() const
Definition: TensorI.H:174
static const Tensor I
Definition: Tensor.H:81
void rows(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set row values.
Definition: TensorI.H:444
components
Component labeling enumeration.
Definition: Tensor.H:85
Tensor< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Tensor.H:70
void operator&=(const Tensor< Cmpt > &t)
Assign inner-product of this with another Tensor.
Definition: TensorI.H:578
Tensor & operator=(const Tensor &)=default
Copy assignment.
const Cmpt & yz() const
Definition: TensorI.H:188
Vector< Cmpt > row() const
Extract vector for given row: compile-time check of index.
Vector< Cmpt > z() const
Extract vector for row 2.
Definition: TensorI.H:293
const Cmpt & xz() const
Definition: TensorI.H:167
Vector< Cmpt > cz() const
Extract vector for column 2.
Definition: TensorI.H:314
static constexpr direction rank
Rank of Tensor is 2.
Definition: Tensor.H:76
Tensor(const Tensor &)=default
Copy construct.
Tensor< Cmpt > inner(const Tensor< Cmpt > &t2) const
Inner-product of this with another Tensor.
Definition: TensorI.H:539
const Cmpt & zz() const
Definition: TensorI.H:209
Tensor< Cmpt > inv() const
Return inverse.
Definition: TensorI.H:782
const Cmpt & xy() const
Definition: TensorI.H:160
Vector< Cmpt > cx() const
Extract vector for column 0.
Definition: TensorI.H:300
Vector< Cmpt > cy() const
Extract vector for column 1.
Definition: TensorI.H:307
const Cmpt & zx() const
Definition: TensorI.H:195
const Cmpt & zy() const
Definition: TensorI.H:202
const Cmpt & yy() const
Definition: TensorI.H:181
void cols(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set column values.
Definition: TensorI.H:430
Vector< Cmpt > y() const
Extract vector for row 1.
Definition: TensorI.H:286
Vector< Cmpt > col() const
Extract vector for given column: compile-time check of index.
Vector< Cmpt > vectorComponent(const direction cmpt) const
Deprecated(2018-12) Return vector for given row (0,1)
Definition: Tensor.H:310
Tensor()=default
Default construct.
Tensor< Cmpt > schur(const Tensor< Cmpt > &t2) const
Schur-product of this with another Tensor.
Definition: TensorI.H:562
Vector< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: TensorI.H:495
Vector< Cmpt > x() const
Extract vector for row 0.
Definition: TensorI.H:279
Templated vector space.
Definition: VectorSpace.H:79
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:65
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:61
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
Tensor< Cmpt > type
Definition: Tensor.H:337
Tensor< solveScalar > type
Definition: Tensor.H:355
The extended precision type (solveScalar for float)
Definition: products.H:79
Abstract template class to provide the transpose form of a form.
Definition: products.H:63
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
uint8_t direction
Definition: direction.H:56
A template class to specify if a data type is composed solely of Foam::label elements.
Definition: contiguous.H:86
A template class to specify if a data type is composed solely of Foam::scalar elements.
Definition: contiguous.H:94
A template class to specify that a data type can be considered as being contiguous in memory.
Definition: contiguous.H:78