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 -------------------------------------------------------------------------------
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::SymmTensor
29 
30 Description
31  A templated (3 x 3) symmetric tensor of objects of <T>, effectively
32  containing 6 elements, derived from VectorSpace.
33 
34 SourceFiles
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 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class SymmTensor Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 template<class Cmpt>
55 class SymmTensor
56 :
57  public VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>
58 {
59 public:
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
74 
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  const Cmpt& xx() const noexcept { return this->v_[XX]; }
132  const Cmpt& xy() const noexcept { return this->v_[XY]; }
133  const Cmpt& xz() const noexcept { return this->v_[XZ]; }
134  const Cmpt& yx() const noexcept { return this->v_[XY]; }
135  const Cmpt& yy() const noexcept { return this->v_[YY]; }
136  const Cmpt& yz() const noexcept { return this->v_[YZ]; }
137  const Cmpt& zx() const noexcept { return this->v_[XZ]; }
138  const Cmpt& zy() const noexcept { return this->v_[YZ]; }
139  const Cmpt& zz() const noexcept { return this->v_[ZZ]; }
140 
141  Cmpt& xx() noexcept { return this->v_[XX]; }
142  Cmpt& xy() noexcept { return this->v_[XY]; }
143  Cmpt& xz() noexcept { return this->v_[XZ]; }
144  Cmpt& yx() noexcept { return this->v_[XY]; }
145  Cmpt& yy() noexcept { return this->v_[YY]; }
146  Cmpt& yz() noexcept { return this->v_[YZ]; }
147  Cmpt& zx() noexcept { return this->v_[XZ]; }
148  Cmpt& zy() noexcept { return this->v_[YZ]; }
149  Cmpt& zz() noexcept { return this->v_[ZZ]; }
152  // Column-vector access
154  //- Extract vector for column 0
155  Vector<Cmpt> cx() const { return this->x(); }
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(); }
163  //- Extract vector for given column: compile-time check of index
164  template<direction Idx>
165  Vector<Cmpt> col() const { return this->row<Idx>(); }
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
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;
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;
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
247 template<class Cmpt>
248 struct is_contiguous<SymmTensor<Cmpt>> : is_contiguous<Cmpt> {};
249 
250 //- Data are contiguous label if component type is label
251 template<class Cmpt>
252 struct is_contiguous_label<SymmTensor<Cmpt>> : is_contiguous_label<Cmpt> {};
253 
254 //- Data are contiguous scalar if component type is scalar
255 template<class Cmpt>
256 struct is_contiguous_scalar<SymmTensor<Cmpt>> : is_contiguous_scalar<Cmpt> {};
257 
258 
259 template<class Cmpt>
260 class symmTypeOfRank<Cmpt, 2>
261 {
262 public:
263 
264  typedef SymmTensor<Cmpt> type;
265 };
266 
267 
268 template<class Cmpt>
269 class typeOfSolve<SymmTensor<Cmpt>>
270 {
271 public:
272 
273  typedef SymmTensor<solveScalar> type;
274 };
275 
276 
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 
279 } // End namespace Foam
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 #include "SymmTensorI.H"
284 
285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286 
287 #endif
288 
289 // ************************************************************************* //
Vector< Cmpt > x() const
Extract vector for row 0.
Definition: SymmTensorI.H:90
const Cmpt & xz() const noexcept
Definition: SymmTensor.H:152
components
Component labeling enumeration.
Definition: SymmTensor.H:80
uint8_t direction
Definition: direction.H:46
Vector< Cmpt > cx() const
Extract vector for column 0.
Definition: SymmTensor.H:176
A templated (3 x 3) symmetric tensor of objects of <T>, effectively containing 6 elements, derived from VectorSpace.
Definition: SymmTensor.H:50
static constexpr direction rank
Rank of SymmTensor is 2.
Definition: SymmTensor.H:69
SymmTensor< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: SymmTensor.H:61
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Templated vector space.
Definition: VectorSpace.H:52
const Cmpt & zz() const noexcept
Definition: SymmTensor.H:158
Vector< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: SymmTensorI.H:195
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 1 element, derived from VectorSpace.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:752
static const SymmTensor I
Definition: SymmTensor.H:74
const Cmpt & zy() const noexcept
Definition: SymmTensor.H:157
Vector< Cmpt > y() const
Extract vector for row 1.
Definition: SymmTensorI.H:97
Vector< Cmpt > cy() const
Extract vector for column 1.
Definition: SymmTensor.H:181
const Cmpt & xx() const noexcept
Definition: SymmTensor.H:150
SymmTensor & operator=(const SymmTensor &)=default
Copy assignment.
Templated 3D Vector derived from VectorSpace adding construction from 3 components, element access using x(), y() and z() member functions and the inner-product (dot-product) and cross-product operators.
Definition: Vector.H:58
const direction noexcept
Definition: Scalar.H:258
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
Vector< Cmpt > cz() const
Extract vector for column 2.
Definition: SymmTensor.H:186
Vector< Cmpt > col() const
Extract vector for given column: compile-time check of index.
Definition: SymmTensor.H:192
const SymmTensor< Cmpt > & T() const
Return non-Hermitian transpose.
Definition: SymmTensorI.H:209
const Cmpt & yy() const noexcept
Definition: SymmTensor.H:154
A template class to specify that a data type can be considered as being contiguous in memory...
Definition: contiguous.H:71
void cols(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set column values.
Definition: SymmTensor.H:208
const dimensionedScalar c
Speed of light in a vacuum.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:58
const Cmpt & zx() const noexcept
Definition: SymmTensor.H:156
const Cmpt & yx() const noexcept
Definition: SymmTensor.H:153
Vector< Cmpt > row() const
Extract vector for given row: compile-time check of index.
const Cmpt & xy() const noexcept
Definition: SymmTensor.H:151
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:81
void rows(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set row values.
Definition: SymmTensorI.H:163
Namespace for OpenFOAM.
Vector< Cmpt > z() const
Extract vector for row 2.
Definition: SymmTensorI.H:104
const Cmpt & yz() const noexcept
Definition: SymmTensor.H:155
SymmTensor()=default
Default construct.