SymmTensor.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) 2019-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::SymmTensor
29
30Description
31 A templated (3 x 3) symmetric tensor of objects of <T>, effectively
32 containing 6 elements, derived from VectorSpace.
33
34SourceFiles
35 SymmTensorI.H
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_SymmTensor_H
40#define Foam_SymmTensor_H
41
42#include "Vector.H"
43#include "SphericalTensor.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50/*---------------------------------------------------------------------------*\
51 Class SymmTensor Declaration
52\*---------------------------------------------------------------------------*/
53
54template<class Cmpt>
55class SymmTensor
56:
57 public VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>
58{
59public:
60
61 // Typedefs
62
63 //- Equivalent type of labels used for valid component indexing
65
66
67 // Member Constants
68
69 //- Rank of SymmTensor is 2
70 static constexpr direction rank = 2;
71
72
73 // Static Data Members
75 static const SymmTensor I;
76
77
78 //- Component labeling enumeration
79 enum components { XX, XY, XZ, YY, YZ, ZZ };
80
81
82 // Generated Methods
83
84 //- Default construct
85 SymmTensor() = default;
86
87 //- Copy construct
88 SymmTensor(const SymmTensor&) = default;
89
90 //- Copy assignment
91 SymmTensor& operator=(const SymmTensor&) = default;
92
93
94 // Constructors
95
96 //- Construct initialized to zero
97 inline SymmTensor(const Foam::zero);
98
99 //- Construct given VectorSpace of the same rank
100 template<class Cmpt2>
101 inline SymmTensor(const VectorSpace<SymmTensor<Cmpt2>, Cmpt2, 6>&);
102
103 //- Construct given SphericalTensor
104 inline SymmTensor(const SphericalTensor<Cmpt>&);
105
106 //- Construct given the three row (or column) vectors
107 inline SymmTensor
108 (
109 const Vector<Cmpt>& x,
110 const Vector<Cmpt>& y,
111 const Vector<Cmpt>& z,
112 const bool transposed = false /* ignored */
113 );
114
115 //- Construct given the six components
116 inline SymmTensor
117 (
118 const Cmpt txx, const Cmpt txy, const Cmpt txz,
119 const Cmpt tyy, const Cmpt tyz,
120 const Cmpt tzz
121 );
122
123 //- Construct from Istream
124 inline explicit SymmTensor(Istream& is);
125
126
127 // Member Functions
128
129 // Component Access
130
131 inline const Cmpt& xx() const;
132 inline const Cmpt& xy() const;
133 inline const Cmpt& xz() const;
134 inline const Cmpt& yx() const;
135 inline const Cmpt& yy() const;
136 inline const Cmpt& yz() const;
137 inline const Cmpt& zx() const;
138 inline const Cmpt& zy() const;
139 inline const Cmpt& zz() const;
140
141 inline Cmpt& xx();
142 inline Cmpt& xy();
143 inline Cmpt& xz();
144 inline Cmpt& yx();
145 inline Cmpt& yy();
146 inline Cmpt& yz();
147 inline Cmpt& zx();
148 inline Cmpt& zy();
149 inline Cmpt& zz();
150
151
152 // Column-vector access
153
154 //- Extract vector for column 0
155 Vector<Cmpt> cx() const { return this->x(); }
156
157 //- Extract vector for column 1
158 Vector<Cmpt> cy() const { return this->y(); }
159
160 //- Extract vector for column 2
161 Vector<Cmpt> cz() const { return this->z(); }
162
163 //- Extract vector for given column: compile-time check of index
164 template<direction Idx>
165 Vector<Cmpt> col() const { return this->row<Idx>(); }
166
167 //- Extract vector for given column (0,1,2): runtime check of index
168 Vector<Cmpt> col(const direction c) const { return this->row(c); }
169
170 //- Set values of given column (0,1,2): runtime check of index
171 void col(const direction c, const Vector<Cmpt>& v) { this->row(c, v); }
172
173 //- Set column values
174 void cols
175 (
176 const Vector<Cmpt>& x,
177 const Vector<Cmpt>& y,
178 const Vector<Cmpt>& z
179 )
180 {
181 this->rows(x, y, z);
182 }
183
184
185 // Row-vector access
186
187 //- Extract vector for row 0
188 inline Vector<Cmpt> x() const;
189
190 //- Extract vector for row 1
191 inline Vector<Cmpt> y() const;
192
193 //- Extract vector for row 2
194 inline Vector<Cmpt> z() const;
195
196 //- Extract vector for given row: compile-time check of index
197 template<direction Row>
198 inline Vector<Cmpt> row() const;
199
200 //- Extract vector for given row (0,1,2): runtime check of index
201 inline Vector<Cmpt> row(const direction r) const;
202
203 //- Set values of given row: compile-time check of index
204 template<direction Idx>
205 inline void row(const Vector<Cmpt>& v);
206
207 //- Set values of given row (0,1,2): runtime check of row
208 inline void row(const direction r, const Vector<Cmpt>& v);
209
210 //- Set row values
211 inline void rows
212 (
213 const Vector<Cmpt>& x,
214 const Vector<Cmpt>& y,
215 const Vector<Cmpt>& z
216 );
217
218
219 // Diagonal access and manipulation
220
221 //- Extract the diagonal as a vector
222 inline Vector<Cmpt> diag() const;
223
224 //- Set values of the diagonal
225 inline void diag(const Vector<Cmpt>& v);
226
227
228 // Tensor Operations
229
230 //- Return non-Hermitian transpose
231 inline const SymmTensor<Cmpt>& T() const;
232
233
234 // Member Operators
235
236 //- Inherit VectorSpace assignment operators
238
239 //- Assign to given SphericalTensor
240 inline void operator=(const SphericalTensor<Cmpt>&);
241};
242
243
244// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
245
246//- Data are contiguous if component type is contiguous
247template<class Cmpt>
248struct is_contiguous<SymmTensor<Cmpt>> : is_contiguous<Cmpt> {};
249
250//- Data are contiguous label if component type is label
251template<class Cmpt>
252struct is_contiguous_label<SymmTensor<Cmpt>> : is_contiguous_label<Cmpt> {};
253
254//- Data are contiguous scalar if component type is scalar
255template<class Cmpt>
257
258
259template<class Cmpt>
260class symmTypeOfRank<Cmpt, 2>
261{
262public:
264 typedef SymmTensor<Cmpt> type;
265};
266
267
268template<class Cmpt>
269class typeOfSolve<SymmTensor<Cmpt>>
270{
271public:
274};
275
276
277// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278
279} // End namespace Foam
280
281// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282
283#include "SymmTensorI.H"
284
285// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286
287#endif
288
289// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 1 element,...
A templated (3 x 3) symmetric tensor of objects of <T>, effectively containing 6 elements,...
Definition: SymmTensor.H:57
const Cmpt & xx() const
Definition: SymmTensorI.H:97
const Cmpt & yx() const
Definition: SymmTensorI.H:115
void rows(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set row values.
Definition: SymmTensorI.H:280
components
Component labeling enumeration.
Definition: SymmTensor.H:78
SymmTensor(const SymmTensor &)=default
Copy construct.
const Cmpt & yz() const
Definition: SymmTensorI.H:127
static const SymmTensor I
Definition: SymmTensor.H:74
Vector< Cmpt > row() const
Extract vector for given row: compile-time check of index.
Vector< Cmpt > z() const
Extract vector for row 2.
Definition: SymmTensorI.H:221
const Cmpt & xz() const
Definition: SymmTensorI.H:109
static constexpr direction rank
Rank of SymmTensor is 2.
Definition: SymmTensor.H:69
void col(const direction c, const Vector< Cmpt > &v)
Set values of given column (0,1,2): runtime check of index.
Definition: SymmTensor.H:170
Vector< Cmpt > cy() const
Extract vector for column 1.
Definition: SymmTensor.H:157
const Cmpt & zz() const
Definition: SymmTensorI.H:145
Vector< Cmpt > cz() const
Extract vector for column 2.
Definition: SymmTensor.H:160
Vector< Cmpt > cx() const
Extract vector for column 0.
Definition: SymmTensor.H:154
Vector< Cmpt > col(const direction c) const
Extract vector for given column (0,1,2): runtime check of index.
Definition: SymmTensor.H:167
const Cmpt & xy() const
Definition: SymmTensorI.H:103
const Cmpt & zx() const
Definition: SymmTensorI.H:133
const Cmpt & zy() const
Definition: SymmTensorI.H:139
const Cmpt & yy() const
Definition: SymmTensorI.H:121
void cols(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set column values.
Definition: SymmTensor.H:174
Vector< Cmpt > y() const
Extract vector for row 1.
Definition: SymmTensorI.H:214
Vector< Cmpt > col() const
Extract vector for given column: compile-time check of index.
Definition: SymmTensor.H:164
Vector< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: SymmTensorI.H:312
SymmTensor & operator=(const SymmTensor &)=default
Copy assignment.
SymmTensor()=default
Default construct.
SymmTensor< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: SymmTensor.H:63
Vector< Cmpt > x() const
Extract vector for row 0.
Definition: SymmTensorI.H:207
const SymmTensor< Cmpt > & T() const
Return non-Hermitian transpose.
Definition: SymmTensorI.H:326
Templated vector space.
Definition: VectorSpace.H:79
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:65
SymmTensor< solveScalar > type
Definition: SymmTensor.H:272
The extended precision type (solveScalar for float)
Definition: products.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.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
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