1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 "SphericalTensor.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 inline DiagTensor<Cmpt>::DiagTensor()
42 // Construct given VectorSpace
44 inline DiagTensor<Cmpt>::DiagTensor
46 const VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>& vs
49 VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(vs)
53 // Construct given three Cmpts
55 inline DiagTensor<Cmpt>::DiagTensor
68 // Construct from Istream
70 inline DiagTensor<Cmpt>::DiagTensor(Istream& is)
72 VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(is)
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 inline const Cmpt& DiagTensor<Cmpt>::xx() const
85 inline const Cmpt& DiagTensor<Cmpt>::yy() const
91 inline const Cmpt& DiagTensor<Cmpt>::zz() const
98 inline Cmpt& DiagTensor<Cmpt>::xx()
103 template <class Cmpt>
104 inline Cmpt& DiagTensor<Cmpt>::yy()
109 template <class Cmpt>
110 inline Cmpt& DiagTensor<Cmpt>::zz()
116 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
118 template <class Cmpt>
120 operator+(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
124 dt1.xx() + t2.xx(), t2.xy(), t2.xz(),
125 t2.yx(), dt1.yy() + t2.yy(), t2.yz(),
126 t2.zx(), t2.zy(), dt1.zz() + t2.zz()
131 template <class Cmpt>
133 operator+(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
137 t1.xx() + dt2.xx(), t1.xy(), t1.xz(),
138 t1.yx(), t1.yy() + dt2.yy(), t1.yz(),
139 t1.zx(), t1.zy(), t1.zz() + dt2.zz()
144 template <class Cmpt>
146 operator-(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
150 dt1.xx() - t2.xx(), -t2.xy(), -t2.xz(),
151 -t2.yx(), dt1.yy() - t2.yy(), -t2.yz(),
152 -t2.zx(), -t2.zy(), dt1.zz() - t2.zz()
157 template <class Cmpt>
159 operator-(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
163 t1.xx() - dt2.xx(), t1.xy(), t1.xz(),
164 t1.yx(), t1.yy() - dt2.yy(), t1.yz(),
165 t1.zx(), t1.zy(), t1.zz() - dt2.zz()
170 //- Inner-product between two diagonal tensors
171 template <class Cmpt>
172 inline DiagTensor<Cmpt>
173 operator&(const DiagTensor<Cmpt>& dt1, const DiagTensor<Cmpt>& dt2)
175 return DiagTensor<Cmpt>
184 //- Inner-product between a diagonal tensor and a tensor
185 template <class Cmpt>
187 operator&(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
206 //- Inner-product between a tensor and a diagonal tensor
207 template <class Cmpt>
209 operator&(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
228 //- Inner-product between a diagonal tensor and a vector
229 template <class Cmpt>
231 operator&(const DiagTensor<Cmpt>& dt, const Vector<Cmpt>& v)
242 //- Inner-product between a vector and a diagonal tensor
243 template <class Cmpt>
245 operator&(const Vector<Cmpt>& v, const DiagTensor<Cmpt>& dt)
256 //- Division of a scalar by a diagonalTensor
257 template <class Cmpt>
258 inline DiagTensor<Cmpt>
259 operator/(const scalar s, const DiagTensor<Cmpt>& dt)
261 return DiagTensor<Cmpt>(s/dt.xx(), s/dt.yy(), s/dt.zz());
265 //- Division of a vector by a diagonalTensor
266 template <class Cmpt>
268 operator/(const Vector<Cmpt> v, const DiagTensor<Cmpt>& dt)
270 return Vector<Cmpt>(v.x()/dt.xx(), v.y()/dt.yy(), v.z()/dt.zz());
274 //- Return the trace of a diagonal tensor
275 template <class Cmpt>
276 inline Cmpt tr(const DiagTensor<Cmpt>& dt)
278 return dt.xx() + dt.yy() + dt.zz();
282 //- Return the spherical part of a diagonal tensor
283 template <class Cmpt>
284 inline SphericalTensor<Cmpt> sph(const DiagTensor<Cmpt>& dt)
290 //- Return the determinant of a diagonal tensor
291 template <class Cmpt>
292 inline Cmpt det(const DiagTensor<Cmpt>& t)
294 return t.xx()*t.yy()*t.zz();
298 //- Return the inverse of a symmetric tensor
299 template <class Cmpt>
300 inline DiagTensor<Cmpt> inv(const DiagTensor<Cmpt>& dt)
302 return DiagTensor<Cmpt>(1.0/dt.xx(), 1.0/dt.yy(), 1.0/dt.zz());
306 //- Return the diagonal of a tensor as a diagonal tensor
307 template <class Cmpt>
308 inline DiagTensor<Cmpt> diag(const Tensor<Cmpt>& t)
310 return DiagTensor<Cmpt>(t.xx(), t.yy(), t.zz());
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 } // End namespace Foam
318 // ************************************************************************* //