OpenFOAM logo
Open Source CFD Toolkit

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