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-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::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 };
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 inline const Cmpt& xx() const;
133 inline const Cmpt& xy() const;
134 inline const Cmpt& yx() const;
135 inline const Cmpt& yy() const;
136
137 inline Cmpt& xx();
138 inline Cmpt& xy();
139 inline Cmpt& yx();
140 inline Cmpt& 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;
154
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);
161
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
204 // Tensor Operations
205
206 //- Return non-Hermitian transpose
207 inline Tensor2D<Cmpt> T() const;
208
209 //- Inner-product of this with another Tensor2D.
210 inline Tensor2D<Cmpt> inner(const Tensor2D<Cmpt>& t2) const;
211
212 //- Schur-product of this with another Tensor2D.
213 inline Tensor2D<Cmpt> schur(const Tensor2D<Cmpt>& t2) const;
214
215
216 // Member Operators
217
218 //- Copy assign from SymmTensor2D
219 inline void operator=(const SymmTensor2D<Cmpt>&);
220
221 //- Copy assign from SphericalTensor2D
222 inline void operator=(const SphericalTensor2D<Cmpt>&);
223
224
225 // Housekeeping
226
227 //- Deprecated(2018-12) Return vector for given row (0,1)
228 // \deprecated(2018-12) use row() method
230 {
231 return row(cmpt);
232 }
233};
234
235
236// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
237
238//- Data are contiguous if component type is contiguous
239template<class Cmpt>
240struct is_contiguous<Tensor2D<Cmpt>> : is_contiguous<Cmpt> {};
241
242//- Data are contiguous label if component type is label
243template<class Cmpt>
244struct is_contiguous_label<Tensor2D<Cmpt>> : is_contiguous_label<Cmpt> {};
245
246//- Data are contiguous scalar if component type is scalar
247template<class Cmpt>
248struct is_contiguous_scalar<Tensor2D<Cmpt>> : is_contiguous_scalar<Cmpt> {};
249
250
251// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252
253} // End namespace Foam
254
255// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256
257#include "Tensor2DI.H"
258
259// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260
261#endif
262
263// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
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,...
Definition: SymmTensor2D.H:61
A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
Definition: Tensor2D.H:59
const Cmpt & xx() const
Definition: Tensor2DI.H:98
Tensor2D< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Tensor2D.H:65
const Cmpt & yx() const
Definition: Tensor2DI.H:110
components
Component labeling enumeration.
Definition: Tensor2D.H:80
Vector2D< Cmpt > y() const
Extract vector for row 1.
Definition: Tensor2DI.H:154
Vector2D< Cmpt > cy() const
Extract vector for column 1.
Definition: Tensor2DI.H:167
Vector2D< Cmpt > vectorComponent(const direction cmpt) const
Deprecated(2018-12) Return vector for given row (0,1)
Definition: Tensor2D.H:228
void cols(const Vector2D< Cmpt > &x, const Vector2D< Cmpt > &y)
Set column values.
Definition: Tensor2DI.H:267
static const Tensor2D I
Definition: Tensor2D.H:76
Tensor2D()=default
Default construct.
Vector2D< Cmpt > row() const
Extract vector for given row: compile-time check of index.
static constexpr direction rank
Rank of Tensor2D is 2.
Definition: Tensor2D.H:71
Tensor2D< Cmpt > schur(const Tensor2D< Cmpt > &t2) const
Schur-product of this with another Tensor2D.
Definition: Tensor2DI.H:371
Vector2D< Cmpt > x() const
Extract vector for row 0.
Definition: Tensor2DI.H:148
void rows(const Vector2D< Cmpt > &x, const Vector2D< Cmpt > &y)
Set row values.
Definition: Tensor2DI.H:279
Tensor2D & operator=(const Tensor2D &)=default
Copy assignment.
Vector2D< Cmpt > cx() const
Extract vector for column 0.
Definition: Tensor2DI.H:161
Tensor2D(const Tensor2D &)=default
Copy construct.
const Cmpt & xy() const
Definition: Tensor2DI.H:104
Tensor2D< Cmpt > T() const
Return non-Hermitian transpose.
Definition: Tensor2DI.H:342
const Cmpt & yy() const
Definition: Tensor2DI.H:116
Vector2D< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: Tensor2DI.H:326
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:354
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:58
Templated vector space.
Definition: VectorSpace.H:79
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.
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