Tensor.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 | Copyright (C) 2011-2013 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 VectorSpace 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 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Tensor_H
39 #define Tensor_H
40 
41 #include "Vector.H"
42 #include "SphericalTensor.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 template<class Cmpt>
50 class SymmTensor;
51 
52 /*---------------------------------------------------------------------------*\
53  Class Tensor Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 template<class Cmpt>
57 class Tensor
58 :
59  public VectorSpace<Tensor<Cmpt>, Cmpt, 9>
60 {
61 
62 public:
63 
64  //- Equivalent type of labels used for valid component indexing
65  typedef Tensor<label> labelType;
66 
67 
68  // Member constants
69 
70  enum
71  {
72  rank = 2 // Rank of Tensor is 2
73  };
74 
75 
76  // Static data members
77 
78  static const char* const typeName;
79  static const char* componentNames[];
80 
81  static const Tensor zero;
82  static const Tensor one;
83  static const Tensor max;
84  static const Tensor min;
85  static const Tensor I;
86 
87 
88  //- Component labeling enumeration
89  enum components { XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ };
90 
91 
92  // Constructors
93 
94  //- Construct null
95  inline Tensor();
96 
97  //- Construct given VectorSpace of the same rank
98  template<class Cmpt2>
99  inline Tensor(const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>&);
100 
101  //- Construct given SphericalTensor
102  inline Tensor(const SphericalTensor<Cmpt>&);
103 
104  //- Construct given SymmTensor
105  inline Tensor(const SymmTensor<Cmpt>&);
106 
107  //- Construct given triad
108  inline Tensor(const Vector<Vector<Cmpt> >&);
109 
110  //- Construct given the three vector components
111  inline Tensor
112  (
113  const Vector<Cmpt>& x,
114  const Vector<Cmpt>& y,
115  const Vector<Cmpt>& z
116  );
117 
118  //- Construct given the nine components
119  inline Tensor
120  (
121  const Cmpt txx, const Cmpt txy, const Cmpt txz,
122  const Cmpt tyx, const Cmpt tyy, const Cmpt tyz,
123  const Cmpt tzx, const Cmpt tzy, const Cmpt tzz
124  );
125 
126  //- Construct from Istream
127  Tensor(Istream&);
128 
129 
130  // Member Functions
131 
132  // Access
133 
134  inline const Cmpt& xx() const;
135  inline const Cmpt& xy() const;
136  inline const Cmpt& xz() const;
137  inline const Cmpt& yx() const;
138  inline const Cmpt& yy() const;
139  inline const Cmpt& yz() const;
140  inline const Cmpt& zx() const;
141  inline const Cmpt& zy() const;
142  inline const Cmpt& zz() const;
143 
144  inline Cmpt& xx();
145  inline Cmpt& xy();
146  inline Cmpt& xz();
147  inline Cmpt& yx();
148  inline Cmpt& yy();
149  inline Cmpt& yz();
150  inline Cmpt& zx();
151  inline Cmpt& zy();
152  inline Cmpt& zz();
153 
154  // Access vector components.
155 
156  inline Vector<Cmpt> x() const;
157  inline Vector<Cmpt> y() const;
158  inline Vector<Cmpt> z() const;
159  inline Vector<Cmpt> vectorComponent(const direction) const;
160 
161  //- Transpose
162  inline Tensor<Cmpt> T() const;
163 
164 
165  // Member Operators
166 
167  //- Assign to a SphericalTensor
168  inline void operator=(const SphericalTensor<Cmpt>&);
169 
170  //- Assign to a SymmTensor
171  inline void operator=(const SymmTensor<Cmpt>&);
172 
173  //- Assign to a triad
174  inline void operator=(const Vector<Vector<Cmpt> >&);
175 };
176 
177 
178 template<class Cmpt>
179 class typeOfRank<Cmpt, 2>
180 {
181 public:
182 
183  typedef Tensor<Cmpt> type;
184 };
185 
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 } // End namespace Foam
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 // Include inline implementations
194 #include "TensorI.H"
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 #endif
199 
200 // ************************************************************************* //
Foam::Tensor::min
static const Tensor min
Definition: Tensor.H:83
Foam::Tensor::componentNames
static const char * componentNames[]
Definition: Tensor.H:78
Foam::Tensor::max
static const Tensor max
Definition: Tensor.H:82
Foam::Tensor::YX
@ YX
Definition: Tensor.H:88
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::Tensor::ZZ
@ ZZ
Definition: Tensor.H:88
Foam::SymmTensor
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components,...
Definition: SymmTensor.H:53
Foam::Tensor::zx
const Cmpt & zx() const
Definition: TensorI.H:202
Foam::Tensor::rank
@ rank
Definition: Tensor.H:71
Foam::Tensor::y
Vector< Cmpt > y() const
Definition: TensorI.H:128
Foam::Tensor::operator=
void operator=(const SphericalTensor< Cmpt > &)
Assign to a SphericalTensor.
Vector.H
Foam::Tensor::yx
const Cmpt & yx() const
Definition: TensorI.H:181
Foam::Tensor::typeName
static const char *const typeName
Definition: Tensor.H:77
Foam::Tensor::labelType
Tensor< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Tensor.H:64
Foam::Tensor::xz
const Cmpt & xz() const
Definition: TensorI.H:174
Foam::Tensor::I
static const Tensor I
Definition: Tensor.H:84
SphericalTensor.H
Foam::Tensor::yz
const Cmpt & yz() const
Definition: TensorI.H:195
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:52
Foam::Tensor::ZY
@ ZY
Definition: Tensor.H:88
Foam::Tensor::zy
const Cmpt & zy() const
Definition: TensorI.H:209
Foam::Tensor::yy
const Cmpt & yy() const
Definition: TensorI.H:188
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Tensor::zz
const Cmpt & zz() const
Definition: TensorI.H:216
Foam::Tensor::XZ
@ XZ
Definition: Tensor.H:88
TensorI.H
Foam::Tensor::vectorComponent
Vector< Cmpt > vectorComponent(const direction) const
Definition: TensorI.H:142
Foam::Tensor::YZ
@ YZ
Definition: Tensor.H:88
Foam::Tensor::YY
@ YY
Definition: Tensor.H:88
Foam::Tensor::xy
const Cmpt & xy() const
Definition: TensorI.H:167
Foam::Tensor::XY
@ XY
Definition: Tensor.H:88
Foam::Tensor::zero
static const Tensor zero
Definition: Tensor.H:80
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Tensor::z
Vector< Cmpt > z() const
Definition: TensorI.H:135
Foam::SphericalTensor
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component,...
Definition: SphericalTensor.H:51
Foam::typeOfRank
Definition: products.H:45
Foam::Tensor::xx
const Cmpt & xx() const
Definition: TensorI.H:160
Foam::Tensor::Tensor
Tensor()
Construct null.
Foam::Tensor::x
Vector< Cmpt > x() const
Definition: TensorI.H:121
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:57
Foam::typeOfRank< Cmpt, 2 >::type
Tensor< Cmpt > type
Definition: Tensor.H:182
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::Tensor< scalar >::components
components
Component labeling enumeration.
Definition: Tensor.H:88
Foam::Tensor::XX
@ XX
Definition: Tensor.H:88
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::Tensor::ZX
@ ZX
Definition: Tensor.H:88
Foam::Tensor::one
static const Tensor one
Definition: Tensor.H:81
Foam::Tensor::T
Tensor< Cmpt > T() const
Transpose.
Definition: TensorI.H:286