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-2019 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  Templated 2D tensor derived from VectorSpace adding construction from
32  4 components, element access using xx(), xy(), yx() and yy() member
33  functions and the iner-product (dot-product) and outer-product of two
34  Vector2Ds (tensor-product) operators.
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 
65 public:
66 
67  //- Equivalent type of labels used for valid component indexing
68  typedef Tensor2D<label> labelType;
69 
70 
71  // Member constants
72 
73  //- Rank of Tensor2D is 2
74  static constexpr direction rank = 2;
75 
76 
77  // Static data members
78 
79  static const Tensor2D I;
80 
81 
82  //- Component labeling enumeration
83  enum components { XX, XY, YX, YY };
84 
85  // Generated Methods
86 
87  //- Construct null
88  Tensor2D() = default;
89 
90 
91  // Constructors
92 
93  //- Construct initialized to zero
94  inline Tensor2D(const Foam::zero);
95 
96  //- Construct given VectorSpace
97  inline Tensor2D(const VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>& vs);
98 
99  //- Construct given SymmTensor2D
100  inline Tensor2D(const SymmTensor2D<Cmpt>& st);
101 
102  //- Construct given SphericalTensor2D
103  inline Tensor2D(const SphericalTensor2D<Cmpt>& st);
104 
105  //- Construct given the two row vectors
106  inline Tensor2D
107  (
108  const Vector2D<Cmpt>& x,
109  const Vector2D<Cmpt>& y
110  );
111 
112  //- Construct given the four components
113  inline Tensor2D
114  (
115  const Cmpt txx, const Cmpt txy,
116  const Cmpt tyx, const Cmpt tyy
117  );
118 
119  //- Construct from Istream
120  inline Tensor2D(Istream&);
121 
122 
123  // Member Functions
124 
125  // Component access
126 
127  inline const Cmpt& xx() const;
128  inline const Cmpt& xy() const;
129  inline const Cmpt& yx() const;
130  inline const Cmpt& yy() const;
131 
132  inline Cmpt& xx();
133  inline Cmpt& xy();
134  inline Cmpt& yx();
135  inline Cmpt& yy();
136 
137 
138  // Column-vector access.
139 
140  //- Extract vector for column 0
141  inline Vector2D<Cmpt> cx() const;
142 
143  //- Extract vector for column 1
144  inline Vector2D<Cmpt> cy() const;
145 
146  //- Extract vector for given column.
147  // Compile-time check of column index.
148  template<direction Col>
149  inline Vector2D<Cmpt> col() const;
150 
151  //- Extract vector for given column (0,1).
152  // Runtime check of column index.
153  inline Vector2D<Cmpt> col(const direction c) const;
154 
155  //- Set values of given column
156  // Compile-time check of column index.
157  template<direction Col>
158  inline void col(const Vector2D<Cmpt>& v);
159 
160  //- Set values of given column (0,1)
161  // Runtime check of column index.
162  inline void col(const direction c, const Vector2D<Cmpt>& v);
163 
164  //- Set column values
165  inline void cols(const Vector2D<Cmpt>& x, const Vector2D<Cmpt>& y);
166 
167 
168  // Row-vector access.
169 
170  //- Extract vector for row 0
171  inline Vector2D<Cmpt> x() const;
172 
173  //- Extract vector for row 1
174  inline Vector2D<Cmpt> y() const;
175 
176  //- Extract vector for given row.
177  // Compile-time check of row index.
178  template<direction Row>
179  inline Vector2D<Cmpt> row() const;
180 
181  //- Extract vector for given row (0,1)
182  // Runtime check of row index.
183  inline Vector2D<Cmpt> row(const direction r) const;
184 
185  //- Set values of given row
186  // Compile-time check of row index.
187  template<direction Row>
188  inline void row(const Vector2D<Cmpt>& v);
189 
190  //- Set values of given row (0,1)
191  // Runtime check of row index.
192  inline void row(const direction r, const Vector2D<Cmpt>& v);
193 
194  //- Set row values
195  inline void rows(const Vector2D<Cmpt>& x, const Vector2D<Cmpt>& y);
196 
197 
198  // Diagonal access.
199 
200  //- Extract the diagonal as a vector
201  inline Vector2D<Cmpt> diag() const;
202 
203  //- Set values of the diagonal
204  inline void diag(const Vector2D<Cmpt>& v);
205 
206 
207  // Tensor Operations
208 
209  //- Return transpose
210  inline Tensor2D<Cmpt> T() const;
211 
212  //- Inner-product of this with another Tensor2D.
213  inline Tensor2D<Cmpt> inner(const Tensor2D<Cmpt>& t2) const;
214 
215  //- Schur-product of this with another Tensor2D.
216  inline Tensor2D<Cmpt> schur(const Tensor2D<Cmpt>& t2) const;
217 
218 
219  // Member Operators
220 
221  //- Copy assign from SymmTensor2D
222  inline void operator=(const SymmTensor2D<Cmpt>&);
223 
224  //- Copy assign from SphericalTensor2D
225  inline void operator=(const SphericalTensor2D<Cmpt>&);
226 
227 
228  // Housekeeping
229 
230  //- Deprecated(2018-12) Return vector for given row (0,1)
231  // \deprecated(2018-12) use row() method
232  Vector2D<Cmpt> vectorComponent(const direction cmpt) const
233  {
234  return row(cmpt);
235  }
236 };
237 
238 
239 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
240 
241 //- Data are contiguous if component type is contiguous
242 template<class Cmpt>
243 struct is_contiguous<Tensor2D<Cmpt>> : is_contiguous<Cmpt> {};
244 
245 //- Data are contiguous label if component type is label
246 template<class Cmpt>
247 struct is_contiguous_label<Tensor2D<Cmpt>> : is_contiguous_label<Cmpt> {};
248 
249 //- Data are contiguous scalar if component type is scalar
250 template<class Cmpt>
251 struct is_contiguous_scalar<Tensor2D<Cmpt>> : is_contiguous_scalar<Cmpt> {};
252 
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 } // End namespace Foam
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 #include "Tensor2DI.H"
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 #endif
265 
266 // ************************************************************************* //
Foam::Tensor2D::cx
Vector2D< Cmpt > cx() const
Extract vector for column 0.
Definition: Tensor2DI.H:163
Foam::Tensor2D::YX
Definition: Tensor2D.H:82
Foam::Tensor2D::cy
Vector2D< Cmpt > cy() const
Extract vector for column 1.
Definition: Tensor2DI.H:169
Foam::Tensor2D::Tensor2D
Tensor2D()=default
Construct null.
Foam::Tensor2D::cols
void cols(const Vector2D< Cmpt > &x, const Vector2D< Cmpt > &y)
Set column values.
Definition: Tensor2DI.H:269
Foam::Tensor2D::inner
Tensor2D< Cmpt > inner(const Tensor2D< Cmpt > &t2) const
Inner-product of this with another Tensor2D.
Definition: Tensor2DI.H:358
Foam::Tensor2D::row
Vector2D< Cmpt > row() const
Extract vector for given row.
Foam::Tensor2D::yy
const Cmpt & yy() const
Definition: Tensor2DI.H:118
Foam::SymmTensor2D
Templated 2D symmetric tensor derived from VectorSpace adding construction from 4 components,...
Definition: SymmTensor2D.H:57
Foam::Tensor2D::xy
const Cmpt & xy() const
Definition: Tensor2DI.H:106
Foam::Tensor2D::XX
Definition: Tensor2D.H:82
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:78
Foam::Tensor2D::rank
static constexpr direction rank
Rank of Tensor2D is 2.
Definition: Tensor2D.H:73
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
Templated 2D tensor derived from VectorSpace adding construction from 4 components,...
Definition: Tensor2D.H:59
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::Tensor2D::YY
Definition: Tensor2D.H:82
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:67
Foam::Tensor2D::XY
Definition: Tensor2D.H:82
Foam::Tensor2D::diag
Vector2D< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: Tensor2DI.H:330
Foam::Tensor2D::components
components
Component labeling enumeration.
Definition: Tensor2D.H:82
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:150
Foam::Tensor2D::T
Tensor2D< Cmpt > T() const
Return transpose.
Definition: Tensor2DI.H:346
Foam::Tensor2D::y
Vector2D< Cmpt > y() const
Extract vector for row 1.
Definition: Tensor2DI.H:156
Foam::Tensor2D::schur
Tensor2D< Cmpt > schur(const Tensor2D< Cmpt > &t2) const
Schur-product of this with another Tensor2D.
Definition: Tensor2DI.H:375
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::Tensor2D::operator=
void operator=(const SymmTensor2D< Cmpt > &)
Copy assign from SymmTensor2D.
Definition: Tensor2DI.H:390
Foam::Tensor2D::xx
const Cmpt & xx() const
Definition: Tensor2DI.H:100
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:281
Foam::Tensor2D::yx
const Cmpt & yx() const
Definition: Tensor2DI.H:112
Foam::Tensor2D::vectorComponent
Vector2D< Cmpt > vectorComponent(const direction cmpt) const
Deprecated(2018-12) Return vector for given row (0,1)
Definition: Tensor2D.H:231
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
Templated 2D sphericalTensor derived from VectorSpace adding construction from 1 component,...
Definition: SphericalTensor2D.H:55
Tensor2DI.H
Foam::zero
A class representing the concept of 0 (zero), which can be used to avoid manipulating objects that ar...
Definition: zero.H:61