FreeFOAM The Cross-Platform CFD Toolkit
DiagTensorI_.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 // Construct null
36 template <class Cmpt>
38 {}
39 
40 
41 // Construct given VectorSpace
42 template <class Cmpt>
44 (
45  const VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>& vs
46 )
47 :
48  VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(vs)
49 {}
50 
51 
52 // Construct given three Cmpts
53 template <class Cmpt>
55 (
56  const Cmpt& vxx,
57  const Cmpt& vyy,
58  const Cmpt& vzz
59 )
60 {
61  this->v_[XX] = vxx;
62  this->v_[YY] = vyy;
63  this->v_[ZZ] = vzz;
64 }
65 
66 
67 // Construct from Istream
68 template <class Cmpt>
70 :
71  VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(is)
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
77 template <class Cmpt>
78 inline const Cmpt& DiagTensor<Cmpt>::xx() const
79 {
80  return this->v_[XX];
81 }
82 
83 template <class Cmpt>
84 inline const Cmpt& DiagTensor<Cmpt>::yy() const
85 {
86  return this->v_[YY];
87 }
88 
89 template <class Cmpt>
90 inline const Cmpt& DiagTensor<Cmpt>::zz() const
91 {
92  return this->v_[ZZ];
93 }
94 
95 
96 template <class Cmpt>
97 inline Cmpt& DiagTensor<Cmpt>::xx()
98 {
99  return this->v_[XX];
100 }
101 
102 template <class Cmpt>
103 inline Cmpt& DiagTensor<Cmpt>::yy()
104 {
105  return this->v_[YY];
106 }
107 
108 template <class Cmpt>
109 inline Cmpt& DiagTensor<Cmpt>::zz()
110 {
111  return this->v_[ZZ];
112 }
113 
114 
115 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
116 
117 template <class Cmpt>
118 inline Tensor<Cmpt>
120 {
121  return Tensor<Cmpt>
122  (
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()
126  );
127 }
128 
129 
130 template <class Cmpt>
131 inline Tensor<Cmpt>
133 {
134  return Tensor<Cmpt>
135  (
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()
139  );
140 }
141 
142 
143 template <class Cmpt>
144 inline Tensor<Cmpt>
146 {
147  return Tensor<Cmpt>
148  (
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()
152  );
153 }
154 
155 
156 template <class Cmpt>
157 inline Tensor<Cmpt>
159 {
160  return Tensor<Cmpt>
161  (
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()
165  );
166 }
167 
168 
169 //- Inner-product between two diagonal tensors
170 template <class Cmpt>
171 inline DiagTensor<Cmpt>
173 {
174  return DiagTensor<Cmpt>
175  (
176  dt1.xx()*dt2.xx(),
177  dt1.yy()*dt2.yy(),
178  dt1.zz()*dt2.zz()
179  );
180 }
181 
182 
183 //- Inner-product between a diagonal tensor and a tensor
184 template <class Cmpt>
185 inline Tensor<Cmpt>
187 {
188  return Tensor<Cmpt>
189  (
190  dt1.xx()*t2.xx(),
191  dt1.xx()*t2.xy(),
192  dt1.xx()*t2.xz(),
193 
194  dt1.yy()*t2.yx(),
195  dt1.yy()*t2.yy(),
196  dt1.yy()*t2.yz(),
197 
198  dt1.zz()*t2.zx(),
199  dt1.zz()*t2.zy(),
200  dt1.zz()*t2.zz()
201  );
202 }
203 
204 
205 //- Inner-product between a tensor and a diagonal tensor
206 template <class Cmpt>
207 inline Tensor<Cmpt>
209 {
210  return Tensor<Cmpt>
211  (
212  t1.xx()*dt2.xx(),
213  t1.xy()*dt2.yy(),
214  t1.xz()*dt2.zz(),
215 
216  t1.yx()*dt2.xx(),
217  t1.yy()*dt2.yy(),
218  t1.yz()*dt2.zz(),
219 
220  t1.zx()*dt2.xx(),
221  t1.zy()*dt2.yy(),
222  t1.zz()*dt2.zz()
223  );
224 }
225 
226 
227 //- Inner-product between a diagonal tensor and a vector
228 template <class Cmpt>
229 inline Vector<Cmpt>
231 {
232  return Vector<Cmpt>
233  (
234  dt.xx()*v.x(),
235  dt.yy()*v.y(),
236  dt.zz()*v.z()
237  );
238 }
239 
240 
241 //- Inner-product between a vector and a diagonal tensor
242 template <class Cmpt>
243 inline Vector<Cmpt>
245 {
246  return Vector<Cmpt>
247  (
248  v.x()*dt.xx(),
249  v.y()*dt.yy(),
250  v.z()*dt.zz()
251  );
252 }
253 
254 
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)
259 {
260  return DiagTensor<Cmpt>(s/dt.xx(), s/dt.yy(), s/dt.zz());
261 }
262 
263 
264 //- Division of a vector by a diagonalTensor
265 template <class Cmpt>
266 inline Vector<Cmpt>
268 {
269  return Vector<Cmpt>(v.x()/dt.xx(), v.y()/dt.yy(), v.z()/dt.zz());
270 }
271 
272 
273 //- Return the trace of a diagonal tensor
274 template <class Cmpt>
275 inline Cmpt tr(const DiagTensor<Cmpt>& dt)
276 {
277  return dt.xx() + dt.yy() + dt.zz();
278 }
279 
280 
281 //- Return the spherical part of a diagonal tensor
282 template <class Cmpt>
284 {
285  return 0.5*tr(dt);
286 }
287 
288 
289 //- Return the determinant of a diagonal tensor
290 template <class Cmpt>
291 inline Cmpt det(const DiagTensor<Cmpt>& t)
292 {
293  return t.xx()*t.yy()*t.zz();
294 }
295 
296 
297 //- Return the inverse of a symmetric tensor
298 template <class Cmpt>
300 {
301  return DiagTensor<Cmpt>(1.0/dt.xx(), 1.0/dt.yy(), 1.0/dt.zz());
302 }
303 
304 
305 //- Return the diagonal of a tensor as a diagonal tensor
306 template <class Cmpt>
308 {
309  return DiagTensor<Cmpt>(t.xx(), t.yy(), t.zz());
310 }
311 
312 
313 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
314 
315 } // End namespace Foam
316 
317 // ************************ vim: set sw=4 sts=4 et: ************************ //