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-2019 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 /*---------------------------------------------------------------------------*\
58  Class Tensor Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class Cmpt>
62 class Tensor
63 :
64  public MatrixSpace<Tensor<Cmpt>, Cmpt, 3, 3>
65 {
66 
67 public:
68 
69  //- Equivalent type of labels used for valid component indexing
70  typedef Tensor<label> labelType;
71 
72 
73  // Member constants
74 
75  //- Rank of Tensor is 2
76  static const direction rank = 2;
77 
78 
79  // Static Data Members
80 
81  static const Tensor I;
82 
83 
84  //- Component labeling enumeration
85  enum components { XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ };
86 
87 
88  // Constructors
89 
90  //- Construct null
91  inline Tensor();
92 
93  //- Construct initialized to zero
94  inline Tensor(const Foam::zero);
95 
96  //- Construct given MatrixSpace of the same rank
97  template<class Cmpt2>
98  inline Tensor(const MatrixSpace<Tensor<Cmpt2>, Cmpt2, 3, 3>&);
99 
100  //- Construct given VectorSpace of the same rank
101  template<class Cmpt2>
102  inline Tensor(const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>&);
103 
104  //- Construct given SphericalTensor
105  inline Tensor(const SphericalTensor<Cmpt>&);
106 
107  //- Construct given SymmTensor
108  inline Tensor(const SymmTensor<Cmpt>&);
109 
110  //- Construct given triad
111  inline Tensor(const Vector<Vector<Cmpt>>&);
112 
113  //- Construct given the three vector components
114  inline Tensor
115  (
116  const Vector<Cmpt>& x,
117  const Vector<Cmpt>& y,
118  const Vector<Cmpt>& z
119  );
120 
121  //- Construct given the nine components
122  inline Tensor
123  (
124  const Cmpt txx, const Cmpt txy, const Cmpt txz,
125  const Cmpt tyx, const Cmpt tyy, const Cmpt tyz,
126  const Cmpt tzx, const Cmpt tzy, const Cmpt tzz
127  );
128 
129  //- Construct from a block of another matrix space
130  template
131  <
132  template<class, direction, direction> class Block2,
133  direction BRowStart,
134  direction BColStart
135  >
136  Tensor
137  (
138  const Block2<Tensor<Cmpt>, BRowStart, BColStart>& block
139  );
140 
141  //- Construct from Istream
142  inline Tensor(Istream&);
143 
144 
145  // Member Functions
146 
147  // Component access
148 
149  inline const Cmpt& xx() const;
150  inline const Cmpt& xy() const;
151  inline const Cmpt& xz() const;
152  inline const Cmpt& yx() const;
153  inline const Cmpt& yy() const;
154  inline const Cmpt& yz() const;
155  inline const Cmpt& zx() const;
156  inline const Cmpt& zy() const;
157  inline const Cmpt& zz() const;
158 
159  inline Cmpt& xx();
160  inline Cmpt& xy();
161  inline Cmpt& xz();
162  inline Cmpt& yx();
163  inline Cmpt& yy();
164  inline Cmpt& yz();
165  inline Cmpt& zx();
166  inline Cmpt& zy();
167  inline Cmpt& zz();
168 
169  // Row-vector access.
170 
171  inline Vector<Cmpt> x() const;
172  inline Vector<Cmpt> y() const;
173  inline Vector<Cmpt> z() const;
174  inline Vector<Cmpt> vectorComponent(const direction) const;
175 
176  //- Return transpose
177  inline Tensor<Cmpt> T() const;
178 
179  //- Return inverse
180  inline Tensor<Cmpt> inv() const;
181 
182 
183  // Member Operators
184 
185  //- Inner-product with a Tensor
186  inline void operator&=(const Tensor<Cmpt>&);
187 
188  //- Inherit MatrixSpace assignment operators
190 
191  //- Assign to an equivalent vector space
192  template<class Cmpt2>
193  inline void operator=(const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>&);
194 
195  //- Assign to a SphericalTensor
196  inline void operator=(const SphericalTensor<Cmpt>&);
197 
198  //- Assign to a SymmTensor
199  inline void operator=(const SymmTensor<Cmpt>&);
200 
201  //- Assign to a triad
202  inline void operator=(const Vector<Vector<Cmpt>>&);
203 };
204 
205 
206 template<class Cmpt>
207 class typeOfRank<Cmpt, 2>
208 {
209 public:
211  typedef Tensor<Cmpt> type;
212 };
213 
214 
215 template<class Cmpt>
216 class typeOfTranspose<Cmpt, Tensor<Cmpt>>
217 {
218 public:
220  typedef Tensor<Cmpt> type;
221 };
222 
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 } // End namespace Foam
227 
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 
230 // Include inline implementations
231 #include "TensorI.H"
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 #endif
236 
237 // ************************************************************************* //
const Cmpt & yx() const
Definition: TensorI.H:174
const Cmpt & zy() const
Definition: TensorI.H:202
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components...
Definition: SymmTensor.H:53
const Cmpt & xz() const
Definition: TensorI.H:167
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:321
Vector< Cmpt > x() const
Definition: TensorI.H:279
const Cmpt & yy() const
Definition: TensorI.H:181
const Cmpt & xx() const
Definition: TensorI.H:153
const Cmpt & yz() const
Definition: TensorI.H:188
Templated vector space.
Definition: VectorSpace.H:53
static const direction rank
Rank of Tensor is 2.
Definition: Tensor.H:75
Vector< Cmpt > y() const
Definition: TensorI.H:286
Templated matrix space.
Definition: MatrixSpace.H:55
components
Component labeling enumeration.
Definition: Tensor.H:84
Tensor()
Construct null.
Definition: TensorI.H:31
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:293
void operator=(const VectorSpace< Tensor< Cmpt2 >, Cmpt2, 9 > &)
Assign to an equivalent vector space.
Definition: TensorI.H:360
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:80
Tensor< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Tensor.H:69
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
const Cmpt & zx() const
Definition: TensorI.H:195
Tensor< Cmpt > inv() const
Return inverse.
Definition: TensorI.H:642
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:301
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:160
const Cmpt & zz() const
Definition: TensorI.H:209
Namespace for OpenFOAM.