initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / primitives / SphericalTensor / SphericalTensorI.H
blob0459aedecf2f2f192ece94d9154031d266fcf87d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "Vector.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 // Construct null
37 template <class Cmpt>
38 inline SphericalTensor<Cmpt>::SphericalTensor()
42 // Construct given VectorSpace
43 template <class Cmpt>
44 inline SphericalTensor<Cmpt>::SphericalTensor
46     const VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>& vs
49     VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>(vs)
53 // Construct given three Cmpts
54 template <class Cmpt>
55 inline SphericalTensor<Cmpt>::SphericalTensor(const Cmpt& stii)
57     this->v_[II] = stii;
61 // Construct from Istream
62 template <class Cmpt>
63 inline SphericalTensor<Cmpt>::SphericalTensor(Istream& is)
65     VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>(is)
69 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
71 template <class Cmpt>
72 inline const Cmpt&  SphericalTensor<Cmpt>::ii() const
74     return this->v_[II];
78 template <class Cmpt>
79 inline Cmpt& SphericalTensor<Cmpt>::ii()
81     return this->v_[II];
85 template <class Cmpt>
86 inline const SphericalTensor<Cmpt>& SphericalTensor<Cmpt>::T() const
88     return *this;
92 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
94 //- Inner-product between two spherical tensors
95 template <class Cmpt>
96 inline SphericalTensor<Cmpt>
97 operator&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
99     return SphericalTensor<Cmpt>(st1.ii()*st2.ii());
103 //- Inner-product between a spherical tensor and a vector
104 template <class Cmpt>
105 inline Vector<Cmpt>
106 operator&(const SphericalTensor<Cmpt>& st, const Vector<Cmpt>& v)
108     return Vector<Cmpt>
109     (
110         st.ii()*v.x(),
111                        st.ii()*v.y(),
112                                       st.ii()*v.z()
113     );
117 //- Inner-product between a vector and a spherical tensor
118 template <class Cmpt>
119 inline Vector<Cmpt>
120 operator&(const Vector<Cmpt>& v, const SphericalTensor<Cmpt>& st)
122     return Vector<Cmpt>
123     (
124         v.x()*st.ii(),
125                        v.y()*st.ii(),
126                                       v.z()*st.ii()
127     );
131 //- Double-dot-product between a spherical tensor and a spherical tensor
132 template <class Cmpt>
133 inline Cmpt
134 operator&&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
136     return 3*st1.ii()*st2.ii();
140 //- Division of a scalar by a sphericalTensor
141 template <class Cmpt>
142 inline SphericalTensor<Cmpt>
143 operator/(const scalar s, const SphericalTensor<Cmpt>& st)
145     return SphericalTensor<Cmpt>(s/st.ii());
149 template <class Cmpt>
150 inline Cmpt magSqr(const SphericalTensor<Cmpt>& st)
152     return 3*magSqr(st.ii());
156 //- Return the trace of a spherical tensor
157 template <class Cmpt>
158 inline Cmpt tr(const SphericalTensor<Cmpt>& st)
160     return 3*st.ii();
164 //- Return the spherical part of a spherical tensor, i.e. itself
165 template <class Cmpt>
166 inline SphericalTensor<Cmpt> sph(const SphericalTensor<Cmpt>& st)
168     return st;
172 //- Return the determinant of a spherical tensor
173 template <class Cmpt>
174 inline Cmpt det(const SphericalTensor<Cmpt>& st)
176     return st.ii()*st.ii()*st.ii();
180 //- Return the inverse of a spherical tensor
181 template <class Cmpt>
182 inline SphericalTensor<Cmpt> inv(const SphericalTensor<Cmpt>& st)
184     return SphericalTensor<Cmpt>(1.0/st.ii());
188 template<class Cmpt>
189 class outerProduct<SphericalTensor<Cmpt>, Cmpt>
191 public:
193     typedef SphericalTensor<Cmpt> type;
196 template<class Cmpt>
197 class outerProduct<Cmpt, SphericalTensor<Cmpt> >
199 public:
201     typedef SphericalTensor<Cmpt> type;
205 template<class Cmpt>
206 class innerProduct<SphericalTensor<Cmpt>, SphericalTensor<Cmpt> >
208 public:
210     typedef SphericalTensor<Cmpt> type;
214 template<class Cmpt>
215 class innerProduct<SphericalTensor<Cmpt>, Vector<Cmpt> >
217 public:
219     typedef Vector<Cmpt> type;
222 template<class Cmpt>
223 class innerProduct<Vector<Cmpt>, SphericalTensor<Cmpt> >
225 public:
227     typedef Vector<Cmpt> type;
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233 } // End namespace Foam
235 // ************************************************************************* //