initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / primitives / DiagTensor / DiagTensorI.H
blob5aedd18ebadff7830ac081ed568c653554be65d9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 // Construct null
37 template <class Cmpt>
38 inline DiagTensor<Cmpt>::DiagTensor()
42 // Construct given VectorSpace
43 template <class Cmpt>
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
54 template <class Cmpt>
55 inline DiagTensor<Cmpt>::DiagTensor
57     const Cmpt& vxx,
58     const Cmpt& vyy,
59     const Cmpt& vzz
62     this->v_[XX] = vxx;
63     this->v_[YY] = vyy;
64     this->v_[ZZ] = vzz;
68 // Construct from Istream
69 template <class Cmpt>
70 inline DiagTensor<Cmpt>::DiagTensor(Istream& is)
72     VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(is)
76 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
78 template <class Cmpt>
79 inline const Cmpt&  DiagTensor<Cmpt>::xx() const
81     return this->v_[XX];
84 template <class Cmpt>
85 inline const Cmpt&  DiagTensor<Cmpt>::yy() const
87     return this->v_[YY];
90 template <class Cmpt>
91 inline const Cmpt&  DiagTensor<Cmpt>::zz() const
93     return this->v_[ZZ];
97 template <class Cmpt>
98 inline Cmpt& DiagTensor<Cmpt>::xx()
100     return this->v_[XX];
103 template <class Cmpt>
104 inline Cmpt& DiagTensor<Cmpt>::yy()
106     return this->v_[YY];
109 template <class Cmpt>
110 inline Cmpt& DiagTensor<Cmpt>::zz()
112     return this->v_[ZZ];
116 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
118 template <class Cmpt>
119 inline Tensor<Cmpt>
120 operator+(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
122     return Tensor<Cmpt>
123     (
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()
127     );
131 template <class Cmpt>
132 inline Tensor<Cmpt>
133 operator+(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
135     return Tensor<Cmpt>
136     (
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()
140     );
144 template <class Cmpt>
145 inline Tensor<Cmpt>
146 operator-(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
148     return Tensor<Cmpt>
149     (
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()
153     );
157 template <class Cmpt>
158 inline Tensor<Cmpt>
159 operator-(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
161     return Tensor<Cmpt>
162     (
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()
166     );
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>
176     (
177         dt1.xx()*dt2.xx(),
178         dt1.yy()*dt2.yy(),
179         dt1.zz()*dt2.zz()
180     );
184 //- Inner-product between a diagonal tensor and a tensor
185 template <class Cmpt>
186 inline Tensor<Cmpt>
187 operator&(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
189     return Tensor<Cmpt>
190     (
191         dt1.xx()*t2.xx(),
192         dt1.xx()*t2.xy(),
193         dt1.xx()*t2.xz(),
195                           dt1.yy()*t2.yx(),
196                           dt1.yy()*t2.yy(),
197                           dt1.yy()*t2.yz(),
199                                             dt1.zz()*t2.zx(),
200                                             dt1.zz()*t2.zy(),
201                                             dt1.zz()*t2.zz()
202     );
206 //- Inner-product between a tensor and a diagonal tensor
207 template <class Cmpt>
208 inline Tensor<Cmpt>
209 operator&(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
211     return Tensor<Cmpt>
212     (
213         t1.xx()*dt2.xx(),
214                           t1.xy()*dt2.yy(),
215                                             t1.xz()*dt2.zz(),
217         t1.yx()*dt2.xx(),
218                           t1.yy()*dt2.yy(),
219                                             t1.yz()*dt2.zz(),
221         t1.zx()*dt2.xx(),
222                           t1.zy()*dt2.yy(),
223                                             t1.zz()*dt2.zz()
224     );
228 //- Inner-product between a diagonal tensor and a vector
229 template <class Cmpt>
230 inline Vector<Cmpt>
231 operator&(const DiagTensor<Cmpt>& dt, const Vector<Cmpt>& v)
233     return Vector<Cmpt>
234     (
235         dt.xx()*v.x(),
236                        dt.yy()*v.y(),
237                                       dt.zz()*v.z()
238     );
242 //- Inner-product between a vector and a diagonal tensor
243 template <class Cmpt>
244 inline Vector<Cmpt>
245 operator&(const Vector<Cmpt>& v, const DiagTensor<Cmpt>& dt)
247     return Vector<Cmpt>
248     (
249         v.x()*dt.xx(),
250                        v.y()*dt.yy(),
251                                       v.z()*dt.zz()
252     );
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>
267 inline Vector<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)
286     return 0.5*tr(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 // ************************************************************************* //