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