FreeFOAM The Cross-Platform CFD Toolkit
Tensor2DI_.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 
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27 
28 namespace Foam
29 {
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template <class Cmpt>
35 {}
36 
37 
38 template <class Cmpt>
40 :
41  VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(vs)
42 {}
43 
44 
45 template <class Cmpt>
47 {
48  this->v_[XX] = st.ii(); this->v_[XY] = 0;
49  this->v_[YX] = 0; this->v_[YY] = st.ii();
50 }
51 
52 
53 template <class Cmpt>
55 (
56  const Vector2D<Cmpt>& x,
57  const Vector2D<Cmpt>& y
58 )
59 {
60  this->v_[XX] = x.x(); this->v_[XY] = x.y();
61  this->v_[YX] = y.x(); this->v_[YY] = y.y();
62 }
63 
64 
65 template <class Cmpt>
67 (
68  const Cmpt txx, const Cmpt txy,
69  const Cmpt tyx, const Cmpt tyy
70 )
71 {
72  this->v_[XX] = txx; this->v_[XY] = txy;
73  this->v_[YX] = tyx; this->v_[YY] = tyy;
74 }
75 
76 
77 template <class Cmpt>
79 :
80  VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(is)
81 {}
82 
83 
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 
86 template <class Cmpt>
87 inline const Vector2D<Cmpt> Tensor2D<Cmpt>::x() const
88 {
89  return Vector2D<Cmpt>(this->v_[XX], this->v_[XY]);
90 }
91 
92 template <class Cmpt>
93 inline const Vector2D<Cmpt> Tensor2D<Cmpt>::y() const
94 {
95  return Vector2D<Cmpt>(this->v_[YX], this->v_[YY]);
96 }
97 
98 
99 template <class Cmpt>
100 inline const Cmpt& Tensor2D<Cmpt>::xx() const
101 {
102  return this->v_[XX];
103 }
104 
105 template <class Cmpt>
106 inline const Cmpt& Tensor2D<Cmpt>::xy() const
107 {
108  return this->v_[XY];
109 }
110 
111 template <class Cmpt>
112 inline const Cmpt& Tensor2D<Cmpt>::yx() const
113 {
114  return this->v_[YX];
115 }
116 
117 template <class Cmpt>
118 inline const Cmpt& Tensor2D<Cmpt>::yy() const
119 {
120  return this->v_[YY];
121 }
122 
123 
124 template <class Cmpt>
125 inline Cmpt& Tensor2D<Cmpt>::xx()
126 {
127  return this->v_[XX];
128 }
129 
130 template <class Cmpt>
131 inline Cmpt& Tensor2D<Cmpt>::xy()
132 {
133  return this->v_[XY];
134 }
135 
136 template <class Cmpt>
137 inline Cmpt& Tensor2D<Cmpt>::yx()
138 {
139  return this->v_[YX];
140 }
141 
142 template <class Cmpt>
143 inline Cmpt& Tensor2D<Cmpt>::yy()
144 {
145  return this->v_[YY];
146 }
147 
148 
149 template <class Cmpt>
151 {
152  return Tensor2D<Cmpt>
153  (
154  xx(), yx(),
155  xy(), yy()
156  );
157 }
158 
159 
160 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
161 
162 template <class Cmpt>
164 {
165  this->v_[XX] = st.ii(); this->v_[XY] = 0;
166  this->v_[YX] = 0; this->v_[YY] = st.ii();
167 }
168 
169 
170 
171 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
172 
173 //- Inner-product between two tensors
174 template <class Cmpt>
177 {
178  return Tensor2D<Cmpt>
179  (
180  t1.xx()*t2.xx() + t1.xy()*t2.yx(),
181  t1.xx()*t2.xy() + t1.xy()*t2.yy(),
182 
183  t1.yx()*t2.xx() + t1.yy()*t2.yx(),
184  t1.yx()*t2.xy() + t1.yy()*t2.yy()
185  );
186 }
187 
188 //- Inner-product between a tensor and a vector
189 template <class Cmpt>
190 inline typename innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >::type
192 {
193  return Vector2D<Cmpt>
194  (
195  t.xx()*v.x() + t.xy()*v.y(),
196  t.yx()*v.x() + t.yy()*v.y()
197  );
198 }
199 
200 //- Inner-product between a vector and a tensor
201 template <class Cmpt>
202 inline typename innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >::type
204 {
205  return Vector2D<Cmpt>
206  (
207  v.x()*t.xx() + v.y()*t.yx(),
208  v.x()*t.xy() + v.y()*t.yy()
209  );
210 }
211 
212 //- Outer-product between two vectors
213 template <class Cmpt>
214 inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
216 {
217  return Tensor2D<Cmpt>
218  (
219  v1.x()*v2.x(), v1.x()*v2.y(),
220  v1.y()*v2.x(), v1.y()*v2.y()
221  );
222 }
223 
224 
225 //- Return the trace of a tensor
226 template <class Cmpt>
227 inline Cmpt tr(const Tensor2D<Cmpt>& t)
228 {
229  return t.xx() + t.yy();
230 }
231 
232 
233 //- Return the spherical part of a tensor
234 template <class Cmpt>
236 {
237  return 0.5*tr(t);
238 }
239 
240 
241 //- Return the symmetric part of a tensor
242 template <class Cmpt>
244 {
245  return Tensor2D<Cmpt>
246  (
247  t.xx(), 0.5*(t.xy() + t.yx()),
248  0.5*(t.yx() + t.xy()), t.yy()
249  );
250 }
251 
252 //- Return the twice the symmetric part of a tensor
253 template <class Cmpt>
255 {
256  return Tensor2D<Cmpt>
257  (
258  t.xx() + t.xx(), t.xy() + t.yx(),
259  t.yx() + t.xy(), t.yy() + t.yy()
260  );
261 }
262 
263 //- Return the skew-symmetric part of a tensor
264 template <class Cmpt>
266 {
267  return Tensor2D<Cmpt>
268  (
269  0.0, 0.5*(t.xy() - t.yx()),
270  0.5*(t.yx() - t.xy()), 0.0
271  );
272 }
273 
274 
275 //- Return the deviatoric part of a tensor
276 template <class Cmpt>
278 {
280 }
281 
282 
283 //- Return the deviatoric part of a tensor
284 template <class Cmpt>
286 {
288 }
289 
290 
291 //- Return the determinant of a tensor
292 template <class Cmpt>
293 inline Cmpt det(const Tensor2D<Cmpt>& t)
294 {
295  return(t.xx()*t.yy() - t.xy()*t.yx());
296 }
297 
298 
299 //- Return the cofactor tensor of a tensor
300 template <class Cmpt>
302 {
303  return Tensor2D<Cmpt>
304  (
305  t.yy(), -t.xy(),
306  -t.yx(), t.xx()
307  );
308 }
309 
310 
311 //- Return the inverse of a tensor given the determinant
312 template <class Cmpt>
313 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t, const Cmpt dett)
314 {
315  return cof(t)/dett;
316 }
317 
318 
319 //- Return the inverse of a tensor
320 template <class Cmpt>
322 {
323  return inv(t, det(t));
324 }
325 
326 
327 //- Return the 1st invariant of a tensor
328 template <class Cmpt>
329 inline Cmpt invariantI(const Tensor2D<Cmpt>& t)
330 {
331  return tr(t);
332 }
333 
334 
335 //- Return the 2nd invariant of a tensor
336 template <class Cmpt>
337 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
338 {
339  return
340  (
341  0.5*sqr(tr(t))
342  - 0.5*
343  (
344  t.xx()*t.xx() + t.xy()*t.xy()
345  + t.yx()*t.yx() + t.yy()*t.yy()
346  )
347  );
348 }
349 
350 
351 //- Return the 3rd invariant of a tensor
352 template <class Cmpt>
353 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
354 {
355  return det(t);
356 }
357 
358 
359 
360 
361 template <class Cmpt>
362 inline Tensor2D<Cmpt>
364 {
365  return Tensor2D<Cmpt>
366  (
367  st1.ii() + t2.xx(), t2.xy(),
368  t2.yx(), st1.ii() + t2.yy()
369  );
370 }
371 
372 
373 template <class Cmpt>
374 inline Tensor2D<Cmpt>
376 {
377  return Tensor2D<Cmpt>
378  (
379  t1.xx() + st2.ii(), t1.xy(),
380  t1.yx(), t1.yy() + st2.ii()
381  );
382 }
383 
384 
385 template <class Cmpt>
386 inline Tensor2D<Cmpt>
388 {
389  return Tensor2D<Cmpt>
390  (
391  st1.ii() - t2.xx(), -t2.xy(),
392  -t2.yx(), st1.ii() - t2.yy()
393  );
394 }
395 
396 
397 template <class Cmpt>
398 inline Tensor2D<Cmpt>
400 {
401  return Tensor2D<Cmpt>
402  (
403  t1.xx() - st2.ii(), t1.xy(),
404  t1.yx(), t1.yy() - st2.ii()
405  );
406 }
407 
408 
409 //- Inner-product between a spherical tensor and a tensor
410 template <class Cmpt>
411 inline Tensor2D<Cmpt>
413 {
414  return Tensor2D<Cmpt>
415  (
416  st1.ii()*t2.xx(),
417  st1.ii()*t2.xy(),
418  st1.ii()*t2.yx(),
419  st1.ii()*t2.yy()
420  );
421 }
422 
423 
424 //- Inner-product between a tensor and a spherical tensor
425 template <class Cmpt>
426 inline Tensor2D<Cmpt>
428 {
429  return Tensor2D<Cmpt>
430  (
431  t1.xx()*st2.ii(),
432  t1.xy()*st2.ii(),
433 
434  t1.yx()*st2.ii(),
435  t1.yy()*st2.ii()
436  );
437 }
438 
439 
440 //- Double-dot-product between a spherical tensor and a tensor
441 template <class Cmpt>
442 inline Cmpt
444 {
445  return(st1.ii()*t2.xx() + st1.ii()*t2.yy());
446 }
447 
448 
449 //- Double-dot-product between a tensor and a spherical tensor
450 template <class Cmpt>
451 inline Cmpt
453 {
454  return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
455 }
456 
457 
458 template<class Cmpt>
460 {
461 public:
462 
464 };
465 
466 template<class Cmpt>
468 {
469 public:
470 
472 };
473 
474 
475 template<class Cmpt>
476 class innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >
477 {
478 public:
479 
481 };
482 
483 template<class Cmpt>
485 {
486 public:
487 
489 };
490 
491 template<class Cmpt>
493 {
494 public:
495 
497 };
498 
499 template<class Cmpt>
500 class innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >
501 {
502 public:
503 
505 };
506 
507 template<class Cmpt>
508 class innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >
509 {
510 public:
511 
513 };
514 
515 
516 
517 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
518 
519 } // End namespace Foam
520 
521 // ************************ vim: set sw=4 sts=4 et: ************************ //