Tensor.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::Tensor
26 
27 Description
28  Templated 3D tensor derived from MatrixSpace adding construction from
29  9 components, element access using xx(), xy() etc. member functions and
30  the inner-product (dot-product) and outer-product of two Vectors
31  (tensor-product) operators.
32 
33 SourceFiles
34  TensorI.H
35 
36 See also
37  Foam::MatrixSpace
38  Foam::Vector
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Tensor_H
43 #define Tensor_H
44 
45 #include "MatrixSpace.H"
46 #include "Vector.H"
47 #include "SphericalTensor.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 template<class Cmpt>
55 class SymmTensor;
56 
57 template<class Cmpt>
58 class DiagTensor;
59 
60 /*---------------------------------------------------------------------------*\
61  Class Tensor Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 template<class Cmpt>
65 class Tensor
66 :
67  public MatrixSpace<Tensor<Cmpt>, Cmpt, 3, 3>
68 {
69 
70 public:
71 
72  //- Equivalent type of labels used for valid component indexing
73  typedef Tensor<label> labelType;
74 
75 
76  // Member constants
77 
78  //- Rank of Tensor is 2
79  static const direction rank = 2;
80 
81 
82  // Static Data Members
83 
84  static const Tensor I;
85 
86 
87  //- Component labeling enumeration
88  enum components { XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ };
89 
90 
91  // Constructors
92 
93  //- Construct null
94  inline Tensor();
95 
96  //- Construct initialized to zero
97  inline Tensor(const Foam::zero);
98 
99  //- Construct given MatrixSpace of the same rank
100  template<class Cmpt2>
101  inline Tensor(const MatrixSpace<Tensor<Cmpt2>, Cmpt2, 3, 3>&);
102 
103  //- Construct given VectorSpace of the same rank
104  template<class Cmpt2>
105  inline Tensor(const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>&);
106 
107  //- Construct given SphericalTensor
108  inline Tensor(const SphericalTensor<Cmpt>&);
109 
110  //- Construct given SymmTensor
111  inline Tensor(const SymmTensor<Cmpt>&);
112 
113  //- Construct given DiagTensor
114  inline Tensor(const DiagTensor<Cmpt>&);
115 
116  //- Construct given triad
117  inline Tensor(const Vector<Vector<Cmpt>>&);
118 
119  //- Construct given the three vector components
120  inline Tensor
121  (
122  const Vector<Cmpt>& x,
123  const Vector<Cmpt>& y,
124  const Vector<Cmpt>& z
125  );
126 
127  //- Construct given the nine components
128  inline Tensor
129  (
130  const Cmpt txx, const Cmpt txy, const Cmpt txz,
131  const Cmpt tyx, const Cmpt tyy, const Cmpt tyz,
132  const Cmpt tzx, const Cmpt tzy, const Cmpt tzz
133  );
134 
135  //- Construct from a block of another matrix space
136  template
137  <
138  template<class, direction, direction> class Block2,
139  direction BRowStart,
140  direction BColStart
141  >
142  Tensor
143  (
144  const Block2<Tensor<Cmpt>, BRowStart, BColStart>& block
145  );
146 
147  //- Construct from Istream
148  inline Tensor(Istream&);
149 
150 
151  // Member Functions
152 
153  // Component access
154 
155  inline const Cmpt& xx() const;
156  inline const Cmpt& xy() const;
157  inline const Cmpt& xz() const;
158  inline const Cmpt& yx() const;
159  inline const Cmpt& yy() const;
160  inline const Cmpt& yz() const;
161  inline const Cmpt& zx() const;
162  inline const Cmpt& zy() const;
163  inline const Cmpt& zz() const;
164 
165  inline Cmpt& xx();
166  inline Cmpt& xy();
167  inline Cmpt& xz();
168  inline Cmpt& yx();
169  inline Cmpt& yy();
170  inline Cmpt& yz();
171  inline Cmpt& zx();
172  inline Cmpt& zy();
173  inline Cmpt& zz();
174 
175  // Row-vector access.
176 
177  inline Vector<Cmpt> x() const;
178  inline Vector<Cmpt> y() const;
179  inline Vector<Cmpt> z() const;
180  inline Vector<Cmpt> vectorComponent(const direction) const;
181 
182  //- Return transpose
183  inline Tensor<Cmpt> T() const;
184 
185  //- Return inverse
186  inline Tensor<Cmpt> inv() const;
187 
188 
189  // Member Operators
190 
191  //- Inner-product with a Tensor
192  inline void operator&=(const Tensor<Cmpt>&);
193 
194  //- Inherit MatrixSpace assignment operators
196 
197  //- Assign to an equivalent vector space
198  template<class Cmpt2>
199  inline void operator=(const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>&);
200 
201  //- Assign to a SphericalTensor
202  inline void operator=(const SphericalTensor<Cmpt>&);
203 
204  //- Assign to a SymmTensor
205  inline void operator=(const SymmTensor<Cmpt>&);
206 
207  //- Assign to a DiagTensor
208  inline void operator=(const DiagTensor<Cmpt>&);
209 
210  //- Assign to a triad
211  inline void operator=(const Vector<Vector<Cmpt>>&);
212 };
213 
214 
215 template<class Cmpt>
216 class typeOfRank<Cmpt, 2>
217 {
218 public:
220  typedef Tensor<Cmpt> type;
221 };
222 
223 
224 template<class Cmpt>
225 class typeOfTranspose<Cmpt, Tensor<Cmpt>>
226 {
227 public:
229  typedef Tensor<Cmpt> type;
230 };
231 
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 } // End namespace Foam
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 // Include inline implementations
240 #include "TensorI.H"
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 #endif
245 
246 // ************************************************************************* //
const Cmpt & yx() const
Definition: TensorI.H:184
const Cmpt & zy() const
Definition: TensorI.H:212
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components...
Definition: SymmTensor.H:53
const Cmpt & xz() const
Definition: TensorI.H:177
void operator &=(const Tensor< Cmpt > &)
Inner-product with a Tensor.
uint8_t direction
Definition: direction.H:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Tensor< Cmpt > T() const
Return transpose.
Definition: TensorI.H:331
Vector< Cmpt > x() const
Definition: TensorI.H:289
const Cmpt & yy() const
Definition: TensorI.H:191
const Cmpt & xx() const
Definition: TensorI.H:163
const Cmpt & yz() const
Definition: TensorI.H:198
Templated vector space.
Definition: VectorSpace.H:53
static const direction rank
Rank of Tensor is 2.
Definition: Tensor.H:78
Vector< Cmpt > y() const
Definition: TensorI.H:296
Templated matrix space.
Definition: MatrixSpace.H:55
components
Component labeling enumeration.
Definition: Tensor.H:87
Tensor()
Construct null.
Definition: TensorI.H:32
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component, element access using th ii() member function and the inner-product (dot-product) and outer-product operators.
Vector< Cmpt > z() const
Definition: TensorI.H:303
void operator=(const VectorSpace< Tensor< Cmpt2 >, Cmpt2, 9 > &)
Assign to an equivalent vector space.
Definition: TensorI.H:370
Templated 3D DiagTensor derived from VectorSpace.
Definition: DiagTensor.H:53
Abstract template class to provide the transpose form of a form.
Definition: products.H:58
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:63
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:57
static const Tensor I
Definition: Tensor.H:83
Tensor< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Tensor.H:72
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
const Cmpt & zx() const
Definition: TensorI.H:205
Tensor< Cmpt > inv() const
Return inverse.
Definition: TensorI.H:652
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
Vector< Cmpt > vectorComponent(const direction) const
Definition: TensorI.H:311
Templated 3D tensor derived from MatrixSpace adding construction from 9 components, element access using xx(), xy() etc. member functions and the inner-product (dot-product) and outer-product of two Vectors (tensor-product) operators.
Definition: complexI.H:215
const Cmpt & xy() const
Definition: TensorI.H:170
const Cmpt & zz() const
Definition: TensorI.H:219
Namespace for OpenFOAM.