1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "SphericalTensorTemplate.H"
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 inline DiagTensor<Cmpt>::DiagTensor()
41 // Construct given VectorSpace
43 inline DiagTensor<Cmpt>::DiagTensor
45 const VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>& vs
48 VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(vs)
52 // Construct given three Cmpts
54 inline DiagTensor<Cmpt>::DiagTensor
67 // Construct from Istream
69 inline DiagTensor<Cmpt>::DiagTensor(Istream& is)
71 VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(is)
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 inline const Cmpt& DiagTensor<Cmpt>::xx() const
84 inline const Cmpt& DiagTensor<Cmpt>::yy() const
90 inline const Cmpt& DiagTensor<Cmpt>::zz() const
97 inline Cmpt& DiagTensor<Cmpt>::xx()
102 template <class Cmpt>
103 inline Cmpt& DiagTensor<Cmpt>::yy()
108 template <class Cmpt>
109 inline Cmpt& DiagTensor<Cmpt>::zz()
115 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
117 template <class Cmpt>
119 operator+(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
123 dt1.xx() + t2.xx(), t2.xy(), t2.xz(),
124 t2.yx(), dt1.yy() + t2.yy(), t2.yz(),
125 t2.zx(), t2.zy(), dt1.zz() + t2.zz()
130 template <class Cmpt>
132 operator+(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
136 t1.xx() + dt2.xx(), t1.xy(), t1.xz(),
137 t1.yx(), t1.yy() + dt2.yy(), t1.yz(),
138 t1.zx(), t1.zy(), t1.zz() + dt2.zz()
143 template <class Cmpt>
145 operator-(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
149 dt1.xx() - t2.xx(), -t2.xy(), -t2.xz(),
150 -t2.yx(), dt1.yy() - t2.yy(), -t2.yz(),
151 -t2.zx(), -t2.zy(), dt1.zz() - t2.zz()
156 template <class Cmpt>
158 operator-(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
162 t1.xx() - dt2.xx(), t1.xy(), t1.xz(),
163 t1.yx(), t1.yy() - dt2.yy(), t1.yz(),
164 t1.zx(), t1.zy(), t1.zz() - dt2.zz()
169 //- Inner-product between two diagonal tensors
170 template <class Cmpt>
171 inline DiagTensor<Cmpt>
172 operator&(const DiagTensor<Cmpt>& dt1, const DiagTensor<Cmpt>& dt2)
174 return DiagTensor<Cmpt>
183 //- Inner-product between a diagonal tensor and a tensor
184 template <class Cmpt>
186 operator&(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
205 //- Inner-product between a tensor and a diagonal tensor
206 template <class Cmpt>
208 operator&(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
227 //- Inner-product between a diagonal tensor and a vector
228 template <class Cmpt>
230 operator&(const DiagTensor<Cmpt>& dt, const Vector<Cmpt>& v)
241 //- Inner-product between a vector and a diagonal tensor
242 template <class Cmpt>
244 operator&(const Vector<Cmpt>& v, const DiagTensor<Cmpt>& dt)
255 //- Division of a scalar by a diagonalTensor
256 template <class Cmpt>
257 inline DiagTensor<Cmpt>
258 operator/(const scalar s, const DiagTensor<Cmpt>& dt)
260 return DiagTensor<Cmpt>(s/dt.xx(), s/dt.yy(), s/dt.zz());
264 //- Division of a vector by a diagonalTensor
265 template <class Cmpt>
267 operator/(const Vector<Cmpt> v, const DiagTensor<Cmpt>& dt)
269 return Vector<Cmpt>(v.x()/dt.xx(), v.y()/dt.yy(), v.z()/dt.zz());
273 //- Return the trace of a diagonal tensor
274 template <class Cmpt>
275 inline Cmpt tr(const DiagTensor<Cmpt>& dt)
277 return dt.xx() + dt.yy() + dt.zz();
281 //- Return the spherical part of a diagonal tensor
282 template <class Cmpt>
283 inline SphericalTensor<Cmpt> sph(const DiagTensor<Cmpt>& dt)
289 //- Return the determinant of a diagonal tensor
290 template <class Cmpt>
291 inline Cmpt det(const DiagTensor<Cmpt>& t)
293 return t.xx()*t.yy()*t.zz();
297 //- Return the inverse of a symmetric tensor
298 template <class Cmpt>
299 inline DiagTensor<Cmpt> inv(const DiagTensor<Cmpt>& dt)
301 return DiagTensor<Cmpt>(1.0/dt.xx(), 1.0/dt.yy(), 1.0/dt.zz());
305 //- Return the diagonal of a tensor as a diagonal tensor
306 template <class Cmpt>
307 inline DiagTensor<Cmpt> diag(const Tensor<Cmpt>& t)
309 return DiagTensor<Cmpt>(t.xx(), t.yy(), t.zz());
314 class innerProduct<DiagTensor<Cmpt>, DiagTensor<Cmpt> >
318 typedef DiagTensor<Cmpt> type;
322 class outerProduct<DiagTensor<Cmpt>, Cmpt>
326 typedef DiagTensor<Cmpt> type;
330 class outerProduct<Cmpt, DiagTensor<Cmpt> >
334 typedef DiagTensor<Cmpt> type;
338 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
340 } // End namespace Foam
342 // ************************************************************************* //