FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

DiagTensorI_.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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/SphericalTensor_.H>
00027 
00028 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00029 
00030 namespace Foam
00031 {
00032 
00033 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00034 
00035 // Construct null
00036 template <class Cmpt>
00037 inline DiagTensor<Cmpt>::DiagTensor()
00038 {}
00039 
00040 
00041 // Construct given VectorSpace
00042 template <class Cmpt>
00043 inline DiagTensor<Cmpt>::DiagTensor
00044 (
00045     const VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>& vs
00046 )
00047 :
00048     VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(vs)
00049 {}
00050 
00051 
00052 // Construct given three Cmpts
00053 template <class Cmpt>
00054 inline DiagTensor<Cmpt>::DiagTensor
00055 (
00056     const Cmpt& vxx,
00057     const Cmpt& vyy,
00058     const Cmpt& vzz
00059 )
00060 {
00061     this->v_[XX] = vxx;
00062     this->v_[YY] = vyy;
00063     this->v_[ZZ] = vzz;
00064 }
00065 
00066 
00067 // Construct from Istream
00068 template <class Cmpt>
00069 inline DiagTensor<Cmpt>::DiagTensor(Istream& is)
00070 :
00071     VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(is)
00072 {}
00073 
00074 
00075 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00076 
00077 template <class Cmpt>
00078 inline const Cmpt&  DiagTensor<Cmpt>::xx() const
00079 {
00080     return this->v_[XX];
00081 }
00082 
00083 template <class Cmpt>
00084 inline const Cmpt&  DiagTensor<Cmpt>::yy() const
00085 {
00086     return this->v_[YY];
00087 }
00088 
00089 template <class Cmpt>
00090 inline const Cmpt&  DiagTensor<Cmpt>::zz() const
00091 {
00092     return this->v_[ZZ];
00093 }
00094 
00095 
00096 template <class Cmpt>
00097 inline Cmpt& DiagTensor<Cmpt>::xx()
00098 {
00099     return this->v_[XX];
00100 }
00101 
00102 template <class Cmpt>
00103 inline Cmpt& DiagTensor<Cmpt>::yy()
00104 {
00105     return this->v_[YY];
00106 }
00107 
00108 template <class Cmpt>
00109 inline Cmpt& DiagTensor<Cmpt>::zz()
00110 {
00111     return this->v_[ZZ];
00112 }
00113 
00114 
00115 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
00116 
00117 template <class Cmpt>
00118 inline Tensor<Cmpt>
00119 operator+(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
00120 {
00121     return Tensor<Cmpt>
00122     (
00123         dt1.xx() + t2.xx(), t2.xy(),            t2.xz(),
00124         t2.yx(),            dt1.yy() + t2.yy(), t2.yz(),
00125         t2.zx(),            t2.zy(),            dt1.zz() + t2.zz()
00126     );
00127 }
00128 
00129 
00130 template <class Cmpt>
00131 inline Tensor<Cmpt>
00132 operator+(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
00133 {
00134     return Tensor<Cmpt>
00135     (
00136         t1.xx() + dt2.xx(), t1.xy(),            t1.xz(),
00137         t1.yx(),            t1.yy() + dt2.yy(), t1.yz(),
00138         t1.zx(),            t1.zy(),            t1.zz() + dt2.zz()
00139     );
00140 }
00141 
00142 
00143 template <class Cmpt>
00144 inline Tensor<Cmpt>
00145 operator-(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
00146 {
00147     return Tensor<Cmpt>
00148     (
00149         dt1.xx() - t2.xx(), -t2.xy(),            -t2.xz(),
00150        -t2.yx(),             dt1.yy() - t2.yy(), -t2.yz(),
00151        -t2.zx(),            -t2.zy(),             dt1.zz() - t2.zz()
00152     );
00153 }
00154 
00155 
00156 template <class Cmpt>
00157 inline Tensor<Cmpt>
00158 operator-(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
00159 {
00160     return Tensor<Cmpt>
00161     (
00162         t1.xx() - dt2.xx(), t1.xy(),            t1.xz(),
00163         t1.yx(),            t1.yy() - dt2.yy(), t1.yz(),
00164         t1.zx(),            t1.zy(),            t1.zz() - dt2.zz()
00165     );
00166 }
00167 
00168 
00169 //- Inner-product between two diagonal tensors
00170 template <class Cmpt>
00171 inline DiagTensor<Cmpt>
00172 operator&(const DiagTensor<Cmpt>& dt1, const DiagTensor<Cmpt>& dt2)
00173 {
00174     return DiagTensor<Cmpt>
00175     (
00176         dt1.xx()*dt2.xx(),
00177         dt1.yy()*dt2.yy(),
00178         dt1.zz()*dt2.zz()
00179     );
00180 }
00181 
00182 
00183 //- Inner-product between a diagonal tensor and a tensor
00184 template <class Cmpt>
00185 inline Tensor<Cmpt>
00186 operator&(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
00187 {
00188     return Tensor<Cmpt>
00189     (
00190         dt1.xx()*t2.xx(),
00191         dt1.xx()*t2.xy(),
00192         dt1.xx()*t2.xz(),
00193 
00194                           dt1.yy()*t2.yx(),
00195                           dt1.yy()*t2.yy(),
00196                           dt1.yy()*t2.yz(),
00197 
00198                                             dt1.zz()*t2.zx(),
00199                                             dt1.zz()*t2.zy(),
00200                                             dt1.zz()*t2.zz()
00201     );
00202 }
00203 
00204 
00205 //- Inner-product between a tensor and a diagonal tensor
00206 template <class Cmpt>
00207 inline Tensor<Cmpt>
00208 operator&(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
00209 {
00210     return Tensor<Cmpt>
00211     (
00212         t1.xx()*dt2.xx(),
00213                           t1.xy()*dt2.yy(),
00214                                             t1.xz()*dt2.zz(),
00215 
00216         t1.yx()*dt2.xx(),
00217                           t1.yy()*dt2.yy(),
00218                                             t1.yz()*dt2.zz(),
00219 
00220         t1.zx()*dt2.xx(),
00221                           t1.zy()*dt2.yy(),
00222                                             t1.zz()*dt2.zz()
00223     );
00224 }
00225 
00226 
00227 //- Inner-product between a diagonal tensor and a vector
00228 template <class Cmpt>
00229 inline Vector<Cmpt>
00230 operator&(const DiagTensor<Cmpt>& dt, const Vector<Cmpt>& v)
00231 {
00232     return Vector<Cmpt>
00233     (
00234         dt.xx()*v.x(),
00235                        dt.yy()*v.y(),
00236                                       dt.zz()*v.z()
00237     );
00238 }
00239 
00240 
00241 //- Inner-product between a vector and a diagonal tensor
00242 template <class Cmpt>
00243 inline Vector<Cmpt>
00244 operator&(const Vector<Cmpt>& v, const DiagTensor<Cmpt>& dt)
00245 {
00246     return Vector<Cmpt>
00247     (
00248         v.x()*dt.xx(),
00249                        v.y()*dt.yy(),
00250                                       v.z()*dt.zz()
00251     );
00252 }
00253 
00254 
00255 //- Division of a scalar by a diagonalTensor
00256 template <class Cmpt>
00257 inline DiagTensor<Cmpt>
00258 operator/(const scalar s, const DiagTensor<Cmpt>& dt)
00259 {
00260     return DiagTensor<Cmpt>(s/dt.xx(), s/dt.yy(), s/dt.zz());
00261 }
00262 
00263 
00264 //- Division of a vector by a diagonalTensor
00265 template <class Cmpt>
00266 inline Vector<Cmpt>
00267 operator/(const Vector<Cmpt> v, const DiagTensor<Cmpt>& dt)
00268 {
00269     return Vector<Cmpt>(v.x()/dt.xx(), v.y()/dt.yy(), v.z()/dt.zz());
00270 }
00271 
00272 
00273 //- Return the trace of a diagonal tensor
00274 template <class Cmpt>
00275 inline Cmpt tr(const DiagTensor<Cmpt>& dt)
00276 {
00277     return dt.xx() + dt.yy() + dt.zz();
00278 }
00279 
00280 
00281 //- Return the spherical part of a diagonal tensor
00282 template <class Cmpt>
00283 inline SphericalTensor<Cmpt> sph(const DiagTensor<Cmpt>& dt)
00284 {
00285     return 0.5*tr(dt);
00286 }
00287 
00288 
00289 //- Return the determinant of a diagonal tensor
00290 template <class Cmpt>
00291 inline Cmpt det(const DiagTensor<Cmpt>& t)
00292 {
00293     return t.xx()*t.yy()*t.zz();
00294 }
00295 
00296 
00297 //- Return the inverse of a symmetric tensor
00298 template <class Cmpt>
00299 inline DiagTensor<Cmpt> inv(const DiagTensor<Cmpt>& dt)
00300 {
00301     return DiagTensor<Cmpt>(1.0/dt.xx(), 1.0/dt.yy(), 1.0/dt.zz()); 
00302 }
00303 
00304 
00305 //- Return the diagonal of a tensor as a diagonal tensor
00306 template <class Cmpt>
00307 inline DiagTensor<Cmpt> diag(const Tensor<Cmpt>& t)
00308 {
00309     return DiagTensor<Cmpt>(t.xx(), t.yy(), t.zz());
00310 }
00311 
00312 
00313 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00314 
00315 } // End namespace Foam
00316 
00317 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines