Tensor2D.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-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::Tensor2D
29 
30 Description
31  A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
32 
33 SourceFiles
34  Tensor2DI.H
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_Tensor2D_H
39 #define Foam_Tensor2D_H
40 
41 #include "Vector2D.H"
42 #include "SphericalTensor2D.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward Declarations
50 template<class Cmpt> class SymmTensor2D;
51 
52 /*---------------------------------------------------------------------------*\
53  Class Tensor2D Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 template<class Cmpt>
57 class Tensor2D
58 :
59  public VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>
60 {
61 public:
62 
63  // Typedefs
64 
65  //- Equivalent type of labels used for valid component indexing
66  typedef Tensor2D<label> labelType;
67 
68 
69  // Member Constants
70 
71  //- Rank of Tensor2D is 2
72  static constexpr direction rank = 2;
73 
74 
75  // Static Data Members
76 
77  static const Tensor2D I;
78 
79 
80  //- Component labeling enumeration
81  enum components { XX, XY, YX, YY };
82 
83 
84  // Generated Methods
85 
86  //- Default construct
87  Tensor2D() = default;
88 
89  //- Copy construct
90  Tensor2D(const Tensor2D&) = default;
91 
92  //- Copy assignment
93  Tensor2D& operator=(const Tensor2D&) = default;
94 
95 
96  // Constructors
97 
98  //- Construct initialized to zero
99  inline Tensor2D(const Foam::zero);
100 
101  //- Construct given VectorSpace
102  inline Tensor2D(const VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>& vs);
103 
104  //- Construct given SymmTensor2D
105  inline Tensor2D(const SymmTensor2D<Cmpt>& st);
106 
107  //- Construct given SphericalTensor2D
108  inline Tensor2D(const SphericalTensor2D<Cmpt>& st);
109 
110  //- Construct given the two row vectors
111  inline Tensor2D
112  (
113  const Vector2D<Cmpt>& x,
114  const Vector2D<Cmpt>& y
115  );
116 
117  //- Construct given the four components
118  inline Tensor2D
119  (
120  const Cmpt txx, const Cmpt txy,
121  const Cmpt tyx, const Cmpt tyy
122  );
123 
124  //- Construct from Istream
125  inline explicit Tensor2D(Istream& is);
126 
127 
128  // Member Functions
129 
130  // Component Access
131 
132  const Cmpt& xx() const noexcept { return this->v_[XX]; }
133  const Cmpt& xy() const noexcept { return this->v_[XY]; }
134  const Cmpt& yx() const noexcept { return this->v_[YX]; }
135  const Cmpt& yy() const noexcept { return this->v_[YY]; }
136 
137  Cmpt& xx() noexcept { return this->v_[XX]; }
138  Cmpt& xy() noexcept { return this->v_[XY]; }
139  Cmpt& yx() noexcept { return this->v_[YX]; }
140  Cmpt& yy() noexcept { return this->v_[YY]; }
141 
142 
143  // Column-vector access
144 
145  //- Extract vector for column 0
146  inline Vector2D<Cmpt> cx() const;
147 
148  //- Extract vector for column 1
149  inline Vector2D<Cmpt> cy() const;
150 
151  //- Extract vector for given column: compile-time check of index
152  template<direction Idx>
153  inline Vector2D<Cmpt> col() const;
155  //- Extract vector for given column (0,1): runtime check of index
156  inline Vector2D<Cmpt> col(const direction c) const;
157 
158  //- Set values of given column: compile-time check of index
159  template<direction Idx>
160  inline void col(const Vector2D<Cmpt>& v);
162  //- Set values of given column (0,1): runtime check of index
163  inline void col(const direction c, const Vector2D<Cmpt>& v);
164 
165  //- Set column values
166  inline void cols(const Vector2D<Cmpt>& x, const Vector2D<Cmpt>& y);
167 
168 
169  // Row-vector access
170 
171  //- Extract vector for row 0
172  inline Vector2D<Cmpt> x() const;
173 
174  //- Extract vector for row 1
175  inline Vector2D<Cmpt> y() const;
176 
177  //- Extract vector for given row: compile-time check of index
178  template<direction Idx>
179  inline Vector2D<Cmpt> row() const;
180 
181  //- Extract vector for given row (0,1): runtime check of index
182  inline Vector2D<Cmpt> row(const direction r) const;
183 
184  //- Set values of given row: compile-time check of index
185  template<direction Idx>
186  inline void row(const Vector2D<Cmpt>& v);
187 
188  //- Set values of given row (0,1): compile-time check of index
189  inline void row(const direction r, const Vector2D<Cmpt>& v);
190 
191  //- Set row values
192  inline void rows(const Vector2D<Cmpt>& x, const Vector2D<Cmpt>& y);
193 
194 
195  // Diagonal access and manipulation
196 
197  //- Extract the diagonal as a vector
198  inline Vector2D<Cmpt> diag() const;
199 
200  //- Set values of the diagonal
201  inline void diag(const Vector2D<Cmpt>& v);
202 
203  //- The L2-norm squared of the diagonal
204  inline scalar diagSqr() const;
205 
206 
207  // Tensor Operations
208 
209  //- Return non-Hermitian transpose
210  inline Tensor2D<Cmpt> T() const;
211 
212  //- The determinate
213  inline Cmpt det() const;
214 
215  //- Return adjunct matrix (transpose of cofactor matrix)
216  inline Tensor2D<Cmpt> adjunct() const;
217 
218  //- Return cofactor matrix (transpose of adjunct matrix)
219  inline Tensor2D<Cmpt> cof() const;
220 
221  //- Return inverse
222  inline Tensor2D<Cmpt> inv() const;
223 
224  //- Inner-product of this with another Tensor2D.
225  inline Tensor2D<Cmpt> inner(const Tensor2D<Cmpt>& t2) const;
226 
227  //- Schur-product of this with another Tensor2D.
228  inline Tensor2D<Cmpt> schur(const Tensor2D<Cmpt>& t2) const;
229 
230 
231  // Member Operators
232 
233  //- Copy assign from SymmTensor2D
234  inline void operator=(const SymmTensor2D<Cmpt>&);
235 
236  //- Copy assign from SphericalTensor2D
237  inline void operator=(const SphericalTensor2D<Cmpt>&);
238 
239 
240  // Housekeeping
241 
242  //- Deprecated(2018-12) Return vector for given row (0,1)
243  // \deprecated(2018-12) use row() method
244  Vector2D<Cmpt> vectorComponent(const direction cmpt) const
245  {
246  return row(cmpt);
247  }
248 };
249 
250 
251 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
252 
253 //- Data are contiguous if component type is contiguous
254 template<class Cmpt>
255 struct is_contiguous<Tensor2D<Cmpt>> : is_contiguous<Cmpt> {};
256 
257 //- Data are contiguous label if component type is label
258 template<class Cmpt>
259 struct is_contiguous_label<Tensor2D<Cmpt>> : is_contiguous_label<Cmpt> {};
260 
261 //- Data are contiguous scalar if component type is scalar
262 template<class Cmpt>
263 struct is_contiguous_scalar<Tensor2D<Cmpt>> : is_contiguous_scalar<Cmpt> {};
264 
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 } // End namespace Foam
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 #include "Tensor2DI.H"
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 #endif
277 
278 // ************************************************************************* //
components
Component labeling enumeration.
Definition: Tensor2D.H:82
Tensor2D< Cmpt > T() const
Return non-Hermitian transpose.
Definition: Tensor2DI.H:296
const Cmpt & xy() const noexcept
Definition: Tensor2D.H:154
uint8_t direction
Definition: direction.H:46
Vector2D< Cmpt > x() const
Extract vector for row 0.
Definition: Tensor2DI.H:91
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Tensor2D< Cmpt > adjunct() const
Return adjunct matrix (transpose of cofactor matrix)
Definition: Tensor2DI.H:314
Tensor2D< Cmpt > schur(const Tensor2D< Cmpt > &t2) const
Schur-product of this with another Tensor2D.
Definition: Tensor2DI.H:350
Templated vector space.
Definition: VectorSpace.H:52
Tensor2D< Cmpt > inv() const
Return inverse.
Definition: Tensor2DI.H:364
Vector2D< Cmpt > col() const
Extract vector for given column: compile-time check of index.
Vector2D< Cmpt > y() const
Extract vector for row 1.
Definition: Tensor2DI.H:97
A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
Definition: Tensor2D.H:52
const Cmpt & yx() const noexcept
Definition: Tensor2D.H:155
scalar diagSqr() const
The L2-norm squared of the diagonal.
Definition: Tensor2DI.H:283
Vector2D< Cmpt > vectorComponent(const direction cmpt) const
Deprecated(2018-12) Return vector for given row (0,1)
Definition: Tensor2D.H:320
Cmpt det() const
The determinate.
Definition: Tensor2DI.H:307
Tensor2D< Cmpt > inner(const Tensor2D< Cmpt > &t2) const
Inner-product of this with another Tensor2D.
Definition: Tensor2DI.H:333
Vector2D< Cmpt > cy() const
Extract vector for column 1.
Definition: Tensor2DI.H:110
void rows(const Vector2D< Cmpt > &x, const Vector2D< Cmpt > &y)
Set row values.
Definition: Tensor2DI.H:222
Vector2D< Cmpt > row() const
Extract vector for given row: compile-time check of index.
Tensor2D & operator=(const Tensor2D &)=default
Copy assignment.
const direction noexcept
Definition: Scalar.H:258
Vector2D< Cmpt > cx() const
Extract vector for column 0.
Definition: Tensor2DI.H:104
static const Tensor2D I
Definition: Tensor2D.H:76
void cols(const Vector2D< Cmpt > &x, const Vector2D< Cmpt > &y)
Set column values.
Definition: Tensor2DI.H:210
Tensor2D()=default
Default construct.
A templated (2 x 2) diagonal tensor of objects of <T>, effectively containing 1 element, derived from VectorSpace.
const Cmpt & xx() const noexcept
Definition: Tensor2D.H:153
const dimensionedScalar c
Speed of light in a vacuum.
A templated (2 x 2) symmetric tensor of objects of <T>, effectively containing 3 elements, derived from VectorSpace.
Definition: SymmTensor2D.H:54
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Templated 2D Vector derived from VectorSpace adding construction from 2 components, element access using x() and y() member functions and the inner-product (dot-product).
Definition: Vector2D.H:51
const Cmpt & yy() const noexcept
Definition: Tensor2D.H:156
Tensor2D< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Tensor2D.H:63
static constexpr direction rank
Rank of Tensor2D is 2.
Definition: Tensor2D.H:71
Vector2D< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: Tensor2DI.H:269
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:81
Namespace for OpenFOAM.
Tensor2D< Cmpt > cof() const
Return cofactor matrix (transpose of adjunct matrix)
Definition: Tensor2DI.H:325