Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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::Tensor2D
29
30Description
31 A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
32
33SourceFiles
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
46namespace Foam
47{
48
49// Forward Declarations
50template<class Cmpt> class SymmTensor2D;
51
52/*---------------------------------------------------------------------------*\
53 Class Tensor2D Declaration
54\*---------------------------------------------------------------------------*/
55
56template<class Cmpt>
57class Tensor2D
58:
59 public VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>
60{
61public:
62
63 // Typedefs
64
65 //- Equivalent type of labels used for valid component indexing
67
68
69 // Member Constants
70
71 //- Rank of Tensor2D is 2
72 static constexpr direction rank = 2;
73
74
75 // Static Data Members
77 static const Tensor2D I;
78
79
80 //- Component labeling enumeration
81 enum components { XX, XY, YX, YY };
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
96 // Constructors
97
98 //- Construct initialized to zero
99 inline Tensor2D(Foam::zero);
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
109
110 //- Construct given the two row vectors
111 inline Tensor2D
112 (
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 );
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;
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
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;
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;
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
242 //- Deprecated(2018-12) Return vector for given row (0,1)
243 // \deprecated(2018-12) use row() method
244 FOAM_DEPRECATED_FOR(2018-12, "row()")
245 Vector2D<Cmpt> vectorComponent(const direction cmpt) const
246 {
247 return row(cmpt);
248 }
250
251
252// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
253
254//- Data are contiguous if component type is contiguous
255template<class Cmpt>
256struct is_contiguous<Tensor2D<Cmpt>> : is_contiguous<Cmpt> {};
257
258//- Data are contiguous label if component type is label
259template<class Cmpt>
260struct is_contiguous_label<Tensor2D<Cmpt>> : is_contiguous_label<Cmpt> {};
261
262//- Data are contiguous scalar if component type is scalar
263template<class Cmpt>
264struct is_contiguous_scalar<Tensor2D<Cmpt>> : is_contiguous_scalar<Cmpt> {};
265
266
267// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268
269} // End namespace Foam
270
271// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273#include "Tensor2DI.H"
274
275// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276
277#endif
278
279// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A templated (2 x 2) diagonal tensor of objects of <T>, effectively containing 1 element,...
A templated (2 x 2) symmetric tensor of objects of <T>, effectively containing 3 elements,...
A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
Definition Tensor2D.H:55
Cmpt & xy() noexcept
Definition Tensor2D.H:159
scalar diagSqr() const
The L2-norm squared of the diagonal.
Definition Tensor2DI.H:283
Vector2D< Cmpt > col(const direction c) const
Extract vector for given column (0,1): runtime check of index.
Definition Tensor2DI.H:129
Tensor2D< label > labelType
Definition Tensor2D.H:63
Tensor2D(Foam::zero)
Construct initialized to zero.
Definition Tensor2DI.H:25
const Cmpt & yy() const noexcept
Definition Tensor2D.H:156
static const Tensor2D I
Definition Tensor2D.H:76
Tensor2D(const Vector2D< Cmpt > &x, const Vector2D< Cmpt > &y)
Construct given the two row vectors.
Definition Tensor2DI.H:59
Vector2D< Cmpt > row(const direction r) const
Extract vector for given row (0,1): runtime check of index.
Definition Tensor2DI.H:157
void row(const direction r, const Vector2D< Cmpt > &v)
Set values of given row (0,1): compile-time check of index.
Definition Tensor2DI.H:252
Tensor2D(const SphericalTensor2D< Cmpt > &st)
Construct given SphericalTensor2D.
Definition Tensor2DI.H:50
components
Component labeling enumeration.
Definition Tensor2D.H:82
void col(const Vector2D< Cmpt > &v)
Set values of given column: compile-time check of index.
Definition Tensor2DI.H:174
Tensor2D< Cmpt > adjunct() const
Return adjunct matrix (transpose of cofactor matrix).
Definition Tensor2DI.H:314
void col(const direction c, const Vector2D< Cmpt > &v)
Set values of given column (0,1): runtime check of index.
Definition Tensor2DI.H:234
Vector2D< scalar > y() const
Vector2D< Cmpt > cy() const
Extract vector for column 1.
Definition Tensor2DI.H:110
Vector2D< scalar > vectorComponent(const direction cmpt) const
Definition Tensor2D.H:321
void cols(const Vector2D< Cmpt > &x, const Vector2D< Cmpt > &y)
Set column values.
Definition Tensor2DI.H:210
Tensor2D()=default
Default construct.
Vector2D< Cmpt > row() const
Extract vector for given row: compile-time check of index.
static constexpr direction rank
Definition Tensor2D.H:71
Tensor2D< Cmpt > schur(const Tensor2D< Cmpt > &t2) const
Schur-product of this with another Tensor2D.
Definition Tensor2DI.H:350
const Cmpt & yx() const noexcept
Definition Tensor2D.H:155
Cmpt & xx() noexcept
Definition Tensor2D.H:158
Tensor2D< Cmpt > cof() const
Return cofactor matrix (transpose of adjunct matrix).
Definition Tensor2DI.H:325
Vector2D< scalar > x() const
void rows(const Vector2D< Cmpt > &x, const Vector2D< Cmpt > &y)
Set row values.
Definition Tensor2DI.H:222
Tensor2D & operator=(const Tensor2D &)=default
Copy assignment.
Cmpt det() const
The determinate.
Definition Tensor2DI.H:307
Vector2D< Cmpt > cx() const
Extract vector for column 0.
Definition Tensor2DI.H:104
Tensor2D(const Tensor2D &)=default
Copy construct.
void diag(const Vector2D< Cmpt > &v)
Set values of the diagonal.
Definition Tensor2DI.H:276
Cmpt & yx() noexcept
Definition Tensor2D.H:160
Tensor2D< Cmpt > T() const
Return non-Hermitian transpose.
Definition Tensor2DI.H:296
Tensor2D(const Cmpt txx, const Cmpt txy, const Cmpt tyx, const Cmpt tyy)
Construct given the four components.
Definition Tensor2DI.H:71
Tensor2D(Istream &is)
Construct from Istream.
Definition Tensor2DI.H:82
Tensor2D< Cmpt > inv() const
Return inverse.
Definition Tensor2DI.H:364
void operator=(const SymmTensor2D< Cmpt > &)
Copy assign from SymmTensor2D.
Definition Tensor2DI.H:385
const Cmpt & xx() const noexcept
Definition Tensor2D.H:153
Tensor2D(const SymmTensor2D< Cmpt > &st)
Construct given SymmTensor2D.
Definition Tensor2DI.H:42
void operator=(const SphericalTensor2D< Cmpt > &)
Copy assign from SphericalTensor2D.
Definition Tensor2DI.H:393
Tensor2D(const VectorSpace< Tensor2D< Cmpt >, Cmpt, 4 > &vs)
Construct given VectorSpace.
Definition Tensor2DI.H:33
Vector2D< Cmpt > diag() const
Extract the diagonal as a vector.
Definition Tensor2DI.H:269
void row(const Vector2D< Cmpt > &v)
Set values of given row: compile-time check of index.
Definition Tensor2DI.H:193
const Cmpt & xy() const noexcept
Definition Tensor2D.H:154
Cmpt & yy() noexcept
Definition Tensor2D.H:161
Vector2D< Cmpt > col() const
Extract vector for given column: compile-time check of index.
Tensor2D< Cmpt > inner(const Tensor2D< Cmpt > &t2) const
Inner-product of this with another Tensor2D.
Definition Tensor2DI.H:333
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition Vector2D.H:54
Cmpt v_[Ncmpts]
The components of this vector space.
Definition VectorSpace.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
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition stdFoam.H:43
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