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