Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / primitives / Tensor / Tensor.H
blobf3c54622267e9ef5ffaba77aa21a05737ff1e7e5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 Class
25     Foam::Tensor
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.
33 SourceFiles
34     TensorI.H
36 \*---------------------------------------------------------------------------*/
38 #ifndef Tensor_H
39 #define Tensor_H
41 #include "Vector.H"
42 #include "SphericalTensor.H"
43 #include "SymmTensor.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 namespace Foam
50 /*---------------------------------------------------------------------------*\
51                            Class Tensor Declaration
52 \*---------------------------------------------------------------------------*/
54 template <class Cmpt>
55 class Tensor
57     public VectorSpace<Tensor<Cmpt>, Cmpt, 9>
60 public:
62     //- Equivalent type of labels used for valid component indexing
63     typedef Tensor<label> labelType;
66     // Member constants
68         enum
69         {
70             rank = 2 // Rank of Tensor is 2
71         };
74     // Static data members
76         static const char* const typeName;
77         static const char* componentNames[];
79         static const Tensor zero;
80         static const Tensor one;
81         static const Tensor max;
82         static const Tensor min;
85     //- Component labeling enumeration
86     enum components { XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ };
89     // Constructors
91         //- Construct null
92         inline Tensor();
94         //- Construct given VectorSpace
95         inline Tensor(const VectorSpace<Tensor<Cmpt>, Cmpt, 9>&);
97         //- Construct given SphericalTensor
98         inline Tensor(const SphericalTensor<Cmpt>&);
100         //- Construct given SymmTensor
101         inline Tensor(const SymmTensor<Cmpt>&);
103         //- Construct given the three vector components
104         inline Tensor
105         (
106             const Vector<Cmpt>& x,
107             const Vector<Cmpt>& y,
108             const Vector<Cmpt>& z
109         );
111         //- Construct given the nine components
112         inline Tensor
113         (
114             const Cmpt txx, const Cmpt txy, const Cmpt txz,
115             const Cmpt tyx, const Cmpt tyy, const Cmpt tyz,
116             const Cmpt tzx, const Cmpt tzy, const Cmpt tzz
117         );
119         //- Construct from Istream
120         Tensor(Istream&);
123     // Member Functions
125         // Access
127             inline const Cmpt& xx() const;
128             inline const Cmpt& xy() const;
129             inline const Cmpt& xz() const;
130             inline const Cmpt& yx() const;
131             inline const Cmpt& yy() const;
132             inline const Cmpt& yz() const;
133             inline const Cmpt& zx() const;
134             inline const Cmpt& zy() const;
135             inline const Cmpt& zz() const;
137             inline Cmpt& xx();
138             inline Cmpt& xy();
139             inline Cmpt& xz();
140             inline Cmpt& yx();
141             inline Cmpt& yy();
142             inline Cmpt& yz();
143             inline Cmpt& zx();
144             inline Cmpt& zy();
145             inline Cmpt& zz();
147             // Access vector components.
148             // Note: returning const only to find out lhs usage
150             inline const Vector<Cmpt> x() const;
151             inline const Vector<Cmpt> y() const;
152             inline const Vector<Cmpt> z() const;
154         //- Transpose
155         inline Tensor<Cmpt> T() const;
158     // Member Operators
160         //- Assign to a SphericalTensor
161         inline void operator=(const SphericalTensor<Cmpt>&);
163         //- Assign to a SymmTensor
164         inline void operator=(const SymmTensor<Cmpt>&);
168 template<class Cmpt>
169 class typeOfRank<Cmpt, 2>
171 public:
173     typedef Tensor<Cmpt> type;
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 } // End namespace Foam
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 // Include inline implementations
184 #include "TensorI.H"
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 #endif
190 // ************************************************************************* //