OpenFOAM logo
Open Source CFD Toolkit

SphericalTensorI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00028 
00029 namespace Foam
00030 {
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 // Construct null
00035 template <class Cmpt>
00036 inline SphericalTensor<Cmpt>::SphericalTensor()
00037 {}
00038 
00039 
00040 // Construct given VectorSpace
00041 template <class Cmpt>
00042 inline SphericalTensor<Cmpt>::SphericalTensor
00043 (
00044     const VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>& vs
00045 )
00046 :
00047     VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>(vs)
00048 {}
00049 
00050 
00051 // Construct given three Cmpts
00052 template <class Cmpt>
00053 inline SphericalTensor<Cmpt>::SphericalTensor(const Cmpt& stii)
00054 {
00055     this->v_[II] = stii;
00056 }
00057 
00058 
00059 // Construct from Istream
00060 template <class Cmpt>
00061 inline SphericalTensor<Cmpt>::SphericalTensor(Istream& is)
00062 :
00063     VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>(is)
00064 {}
00065 
00066 
00067 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00068 
00069 template <class Cmpt>
00070 inline const Cmpt&  SphericalTensor<Cmpt>::ii() const
00071 {
00072     return this->v_[II];
00073 }
00074 
00075 
00076 template <class Cmpt>
00077 inline Cmpt& SphericalTensor<Cmpt>::ii()
00078 {
00079     return this->v_[II];
00080 }
00081 
00082 
00083 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
00084 
00085 template <class Cmpt>
00086 inline Tensor<Cmpt>
00087 operator+(const SphericalTensor<Cmpt>& st1, const Tensor<Cmpt>& t2)
00088 {
00089     return Tensor<Cmpt>
00090     (
00091         st1.ii() + t2.xx(), t2.xy(),            t2.xz(),
00092         t2.yx(),            st1.ii() + t2.yy(), t2.yz(),
00093         t2.zx(),            t2.zy(),            st1.ii() + t2.zz()
00094     );
00095 }
00096 
00097 
00098 template <class Cmpt>
00099 inline Tensor<Cmpt>
00100 operator+(const Tensor<Cmpt>& t1, const SphericalTensor<Cmpt>& st2)
00101 {
00102     return Tensor<Cmpt>
00103     (
00104         t1.xx() + st2.ii(), t1.xy(),            t1.xz(),
00105         t1.yx(),            t1.yy() + st2.ii(), t1.yz(),
00106         t1.zx(),            t1.zy(),            t1.zz() + st2.ii()
00107     );
00108 }
00109 
00110 
00111 template <class Cmpt>
00112 inline Tensor<Cmpt>
00113 operator-(const SphericalTensor<Cmpt>& st1, const Tensor<Cmpt>& t2)
00114 {
00115     return Tensor<Cmpt>
00116     (
00117         st1.ii() - t2.xx(), -t2.xy(),            -t2.xz(),
00118        -t2.yx(),             st1.ii() - t2.yy(), -t2.yz(),
00119        -t2.zx(),            -t2.zy(),             st1.ii() - t2.zz()
00120     );
00121 }
00122 
00123 
00124 template <class Cmpt>
00125 inline Tensor<Cmpt>
00126 operator-(const Tensor<Cmpt>& t1, const SphericalTensor<Cmpt>& st2)
00127 {
00128     return Tensor<Cmpt>
00129     (
00130         t1.xx() - st2.ii(), t1.xy(),            t1.xz(),
00131         t1.yx(),            t1.yy() - st2.ii(), t1.yz(),
00132         t1.zx(),            t1.zy(),            t1.zz() - st2.ii()
00133     );
00134 }
00135 
00136 
00137 //- Inner-product between two spherical tensors
00138 template <class Cmpt>
00139 inline SphericalTensor<Cmpt>
00140 operator&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
00141 {
00142     return SphericalTensor<Cmpt>(st1.ii()*st2.ii());
00143 }
00144 
00145 
00146 //- Inner-product between a spherical tensor and a tensor
00147 template <class Cmpt>
00148 inline Tensor<Cmpt>
00149 operator&(const SphericalTensor<Cmpt>& st1, const Tensor<Cmpt>& t2)
00150 {
00151     return Tensor<Cmpt>
00152     (
00153         st1.ii()*t2.xx(),
00154         st1.ii()*t2.xy(),
00155         st1.ii()*t2.xz(),
00156 
00157                           st1.ii()*t2.yx(),
00158                           st1.ii()*t2.yy(),
00159                           st1.ii()*t2.yz(),
00160 
00161                                             st1.ii()*t2.zx(),
00162                                             st1.ii()*t2.zy(),
00163                                             st1.ii()*t2.zz()
00164     );
00165 }
00166 
00167 
00168 //- Inner-product between a tensor and a spherical tensor
00169 template <class Cmpt>
00170 inline Tensor<Cmpt>
00171 operator&(const Tensor<Cmpt>& t1, const SphericalTensor<Cmpt>& st2)
00172 {
00173     return Tensor<Cmpt>
00174     (
00175         t1.xx()*st2.ii(),
00176                           t1.xy()*st2.ii(),
00177                                             t1.xz()*st2.ii(),
00178 
00179         t1.yx()*st2.ii(),
00180                           t1.yy()*st2.ii(),
00181                                             t1.yz()*st2.ii(),
00182 
00183         t1.zx()*st2.ii(),
00184                           t1.zy()*st2.ii(),
00185                                             t1.zz()*st2.ii()
00186     );
00187 }
00188 
00189 
00190 //- Inner-product between a spherical tensor and a vector
00191 template <class Cmpt>
00192 inline Vector<Cmpt>
00193 operator&(const SphericalTensor<Cmpt>& st, const Vector<Cmpt>& v)
00194 {
00195     return Vector<Cmpt>
00196     (
00197         st.ii()*v.x(),
00198                        st.ii()*v.y(),
00199                                       st.ii()*v.z()
00200     );
00201 }
00202 
00203 
00204 //- Inner-product between a vector and a spherical tensor
00205 template <class Cmpt>
00206 inline Vector<Cmpt>
00207 operator&(const Vector<Cmpt>& v, const SphericalTensor<Cmpt>& st)
00208 {
00209     return Vector<Cmpt>
00210     (
00211         v.x()*st.ii(),
00212                        v.y()*st.ii(),
00213                                       v.z()*st.ii()
00214     );
00215 }
00216 
00217 
00218 //- Division of a scalar by a sphericalTensor
00219 template <class Cmpt>
00220 inline SphericalTensor<Cmpt>
00221 operator/(const scalar s, const SphericalTensor<Cmpt>& st)
00222 {
00223     return SphericalTensor<Cmpt>(s/st.ii());
00224 }
00225 
00226 
00227 //- Return the trace of a spherical tensor
00228 template <class Cmpt>
00229 inline scalar tr(const SphericalTensor<Cmpt>& st)
00230 {
00231     return 3*st.ii();
00232 }
00233 
00234 
00235 //- Return the determinant of a spherical tensor
00236 template <class Cmpt>
00237 inline scalar det(const SphericalTensor<Cmpt>& st)
00238 {
00239     return st.ii()*st.ii()*st.ii();
00240 }
00241 
00242 
00243 //- Return the inverse of a symmetric tensor
00244 template <class Cmpt>
00245 inline SphericalTensor<Cmpt> inv(const SphericalTensor<Cmpt>& st)
00246 {
00247     return SphericalTensor<Cmpt>(1.0/st.ii()); 
00248 }
00249 
00250 
00251 //- Return the deviatoric part of a tensor
00252 template <class Cmpt>
00253 inline Tensor<Cmpt> dev(const Tensor<Cmpt>& t)
00254 {
00255     return t - SphericalTensor<Cmpt>::oneThirdI*tr(t);
00256 }
00257 
00258 
00259 //- Return the deviatoric part of a tensor
00260 template <class Cmpt>
00261 inline Tensor<Cmpt> dev2(const Tensor<Cmpt>& t)
00262 {
00263     return t - SphericalTensor<Cmpt>::twoThirdsI*tr(t);
00264 }
00265 
00266 
00267 template<class Cmpt>
00268 class typeOfSum<SphericalTensor<Cmpt>, Tensor<Cmpt> >
00269 {
00270 public:
00271 
00272     typedef Tensor<Cmpt> type;
00273 };
00274 
00275 template<class Cmpt>
00276 class typeOfSum<Tensor<Cmpt>, SphericalTensor<Cmpt> >
00277 {
00278 public:
00279 
00280     typedef Tensor<Cmpt> type;
00281 };
00282 
00283 
00284 template<class Cmpt>
00285 class outerProduct<SphericalTensor<Cmpt>, Cmpt>
00286 {
00287 public:
00288 
00289     typedef SphericalTensor<Cmpt> type;
00290 };
00291 
00292 template<class Cmpt>
00293 class outerProduct<Cmpt, SphericalTensor<Cmpt> >
00294 {
00295 public:
00296 
00297     typedef SphericalTensor<Cmpt> type;
00298 };
00299 
00300 
00301 template<class Cmpt>
00302 class innerProduct<SphericalTensor<Cmpt>, SphericalTensor<Cmpt> >
00303 {
00304 public:
00305 
00306     typedef SphericalTensor<Cmpt> type;
00307 };
00308 
00309 template<class Cmpt>
00310 class innerProduct<SphericalTensor<Cmpt>, Tensor<Cmpt> >
00311 {
00312 public:
00313 
00314     typedef Tensor<Cmpt> type;
00315 };
00316 
00317 template<class Cmpt>
00318 class innerProduct<Tensor<Cmpt>, SphericalTensor<Cmpt> >
00319 {
00320 public:
00321 
00322     typedef Tensor<Cmpt> type;
00323 };
00324 
00325 template<class Cmpt>
00326 class innerProduct<SphericalTensor<Cmpt>, Vector<Cmpt> >
00327 {
00328 public:
00329 
00330     typedef Vector<Cmpt> type;
00331 };
00332 
00333 template<class Cmpt>
00334 class innerProduct<Vector<Cmpt>, SphericalTensor<Cmpt> >
00335 {
00336 public:
00337 
00338     typedef Vector<Cmpt> type;
00339 };
00340 
00341 
00342 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00343 
00344 } // End namespace Foam
00345 
00346 // ************************************************************************* //
For further information go to www.openfoam.org