OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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