Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
primitives
SymmTensor
SymmTensorI_.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
#include <
OpenFOAM/Vector_.H
>
27
#include <
OpenFOAM/Tensor_.H
>
28
29
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30
31
namespace
Foam
32
{
33
34
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35
36
template
<
class
Cmpt>
37
inline
SymmTensor<Cmpt>::SymmTensor
()
38
{}
39
40
41
template
<
class
Cmpt>
42
inline
SymmTensor<Cmpt>::SymmTensor
43
(
44
const
VectorSpace
<
SymmTensor<Cmpt>
, Cmpt, 6>& vs
45
)
46
:
47
VectorSpace<SymmTensor<Cmpt>
, Cmpt, 6>(vs)
48
{}
49
50
51
template
<
class
Cmpt>
52
inline
SymmTensor<Cmpt>::SymmTensor
(
const
SphericalTensor<Cmpt>
& st)
53
{
54
this->v_[XX] = st.
ii
(); this->v_[XY] = 0; this->v_[XZ] = 0;
55
this->v_[YY] = st.
ii
(); this->v_[YZ] = 0;
56
this->v_[ZZ] = st.
ii
();
57
}
58
59
60
template
<
class
Cmpt>
61
inline
SymmTensor<Cmpt>::SymmTensor
62
(
63
const
Cmpt txx,
const
Cmpt txy,
const
Cmpt txz,
64
const
Cmpt tyy,
const
Cmpt tyz,
65
const
Cmpt tzz
66
)
67
{
68
this->v_[XX] = txx; this->v_[XY] = txy; this->v_[XZ] = txz;
69
this->v_[YY] = tyy; this->v_[YZ] = tyz;
70
this->v_[ZZ] = tzz;
71
}
72
73
74
template
<
class
Cmpt>
75
inline
SymmTensor<Cmpt>::SymmTensor
(
Istream
& is)
76
:
77
VectorSpace
<
SymmTensor
<Cmpt>, Cmpt, 6>(is)
78
{}
79
80
81
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82
83
template
<
class
Cmpt>
84
inline
const
Cmpt&
SymmTensor<Cmpt>::xx
()
const
85
{
86
return
this->v_[XX];
87
}
88
89
template
<
class
Cmpt>
90
inline
const
Cmpt&
SymmTensor<Cmpt>::xy
()
const
91
{
92
return
this->v_[XY];
93
}
94
95
template
<
class
Cmpt>
96
inline
const
Cmpt&
SymmTensor<Cmpt>::xz
()
const
97
{
98
return
this->v_[XZ];
99
}
100
101
template
<
class
Cmpt>
102
inline
const
Cmpt&
SymmTensor<Cmpt>::yy
()
const
103
{
104
return
this->v_[YY];
105
}
106
107
template
<
class
Cmpt>
108
inline
const
Cmpt&
SymmTensor<Cmpt>::yz
()
const
109
{
110
return
this->v_[YZ];
111
}
112
113
template
<
class
Cmpt>
114
inline
const
Cmpt&
SymmTensor<Cmpt>::zz
()
const
115
{
116
return
this->v_[ZZ];
117
}
118
119
120
template
<
class
Cmpt>
121
inline
Cmpt&
SymmTensor<Cmpt>::xx
()
122
{
123
return
this->v_[XX];
124
}
125
126
template
<
class
Cmpt>
127
inline
Cmpt&
SymmTensor<Cmpt>::xy
()
128
{
129
return
this->v_[XY];
130
}
131
132
template
<
class
Cmpt>
133
inline
Cmpt&
SymmTensor<Cmpt>::xz
()
134
{
135
return
this->v_[XZ];
136
}
137
138
template
<
class
Cmpt>
139
inline
Cmpt&
SymmTensor<Cmpt>::yy
()
140
{
141
return
this->v_[YY];
142
}
143
144
template
<
class
Cmpt>
145
inline
Cmpt&
SymmTensor<Cmpt>::yz
()
146
{
147
return
this->v_[YZ];
148
}
149
150
template
<
class
Cmpt>
151
inline
Cmpt&
SymmTensor<Cmpt>::zz
()
152
{
153
return
this->v_[ZZ];
154
}
155
156
157
template
<
class
Cmpt>
158
inline
const
SymmTensor<Cmpt>
&
SymmTensor<Cmpt>::T
()
const
159
{
160
return
*
this
;
161
}
162
163
164
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165
166
template
<
class
Cmpt>
167
inline
void
SymmTensor<Cmpt>::operator=
(
const
SphericalTensor<Cmpt>
& st)
168
{
169
this->v_[XX] = st.
ii
(); this->v_[XY] = 0; this->v_[XZ] = 0;
170
this->v_[YY] = st.
ii
(); this->v_[YZ] = 0;
171
this->v_[ZZ] = st.
ii
();
172
}
173
174
175
176
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
177
178
//- Hodge Dual operator (tensor -> vector)
179
template
<
class
Cmpt>
180
inline
Vector<Cmpt>
operator*
(
const
SymmTensor<Cmpt>
& st)
181
{
182
return
Vector<Cmpt>
(st.
yz
(), -st.
xz
(), st.
xy
());
183
}
184
185
186
//- Inner-product between two symmetric tensors
187
template
<
class
Cmpt>
188
inline
Tensor<Cmpt>
189
operator&
(
const
SymmTensor<Cmpt>
& st1,
const
SymmTensor<Cmpt>
& st2)
190
{
191
return
Tensor<Cmpt>
192
(
193
st1.
xx
()*st2.
xx
() + st1.
xy
()*st2.
xy
() + st1.
xz
()*st2.
xz
(),
194
st1.
xx
()*st2.
xy
() + st1.
xy
()*st2.
yy
() + st1.
xz
()*st2.
yz
(),
195
st1.
xx
()*st2.
xz
() + st1.
xy
()*st2.
yz
() + st1.
xz
()*st2.
zz
(),
196
197
st1.
xy
()*st2.
xx
() + st1.
yy
()*st2.
xy
() + st1.
yz
()*st2.
xz
(),
198
st1.
xy
()*st2.
xy
() + st1.
yy
()*st2.
yy
() + st1.
yz
()*st2.
yz
(),
199
st1.
xy
()*st2.
xz
() + st1.
yy
()*st2.
yz
() + st1.
yz
()*st2.
zz
(),
200
201
st1.
xz
()*st2.
xx
() + st1.
yz
()*st2.
xy
() + st1.
zz
()*st2.
xz
(),
202
st1.
xz
()*st2.
xy
() + st1.
yz
()*st2.
yy
() + st1.
zz
()*st2.
yz
(),
203
st1.
xz
()*st2.
xz
() + st1.
yz
()*st2.
yz
() + st1.
zz
()*st2.
zz
()
204
);
205
}
206
207
208
//- Double-dot-product between a symmetric tensor and a symmetric tensor
209
template
<
class
Cmpt>
210
inline
Cmpt
211
operator&&
(
const
SymmTensor<Cmpt>
& st1,
const
SymmTensor<Cmpt>
& st2)
212
{
213
return
214
(
215
st1.
xx
()*st2.
xx
() + 2*st1.
xy
()*st2.
xy
() + 2*st1.
xz
()*st2.
xz
()
216
+ st1.
yy
()*st2.
yy
() + 2*st1.
yz
()*st2.
yz
()
217
+ st1.
zz
()*st2.
zz
()
218
);
219
}
220
221
222
//- Inner-product between a symmetric tensor and a vector
223
template
<
class
Cmpt>
224
inline
Vector<Cmpt>
225
operator&
(
const
SymmTensor<Cmpt>
& st,
const
Vector<Cmpt>
& v)
226
{
227
return
Vector<Cmpt>
228
(
229
st.
xx
()*v.
x
() + st.
xy
()*v.
y
() + st.
xz
()*v.
z
(),
230
st.
xy
()*v.
x
() + st.
yy
()*v.
y
() + st.
yz
()*v.
z
(),
231
st.
xz
()*v.
x
() + st.
yz
()*v.
y
() + st.
zz
()*v.
z
()
232
);
233
}
234
235
236
//- Inner-product between a vector and a symmetric tensor
237
template
<
class
Cmpt>
238
inline
Vector<Cmpt>
239
operator&
(
const
Vector<Cmpt>
& v,
const
SymmTensor<Cmpt>
& st)
240
{
241
return
Vector<Cmpt>
242
(
243
v.
x
()*st.
xx
() + v.
y
()*st.
xy
() + v.
z
()*st.
xz
(),
244
v.
x
()*st.
xy
() + v.
y
()*st.
yy
() + v.
z
()*st.
yz
(),
245
v.
x
()*st.
xz
() + v.
y
()*st.
yz
() + v.
z
()*st.
zz
()
246
);
247
}
248
249
250
template
<
class
Cmpt>
251
inline
Cmpt
magSqr
(
const
SymmTensor<Cmpt>
& st)
252
{
253
return
254
(
255
magSqr
(st.
xx
()) + 2*
magSqr
(st.
xy
()) + 2*
magSqr
(st.
xz
())
256
+
magSqr
(st.
yy
()) + 2*
magSqr
(st.
yz
())
257
+
magSqr
(st.
zz
())
258
);
259
}
260
261
262
//- Return the trace of a symmetric tensor
263
template
<
class
Cmpt>
264
inline
Cmpt
tr
(
const
SymmTensor<Cmpt>
& st)
265
{
266
return
st.
xx
() + st.
yy
() + st.
zz
();
267
}
268
269
270
//- Return the spherical part of a symmetric tensor
271
template
<
class
Cmpt>
272
inline
SphericalTensor<Cmpt>
sph
(
const
SymmTensor<Cmpt>
& st)
273
{
274
return
(1.0/3.0)*
tr
(st);
275
}
276
277
278
//- Return the symmetric part of a symmetric tensor, i.e. itself
279
template
<
class
Cmpt>
280
inline
const
SymmTensor<Cmpt>
&
symm
(
const
SymmTensor<Cmpt>
& st)
281
{
282
return
st;
283
}
284
285
286
//- Return twice the symmetric part of a symmetric tensor
287
template
<
class
Cmpt>
288
inline
SymmTensor<Cmpt>
twoSymm
(
const
SymmTensor<Cmpt>
& st)
289
{
290
return
2*st;
291
}
292
293
294
//- Return the deviatoric part of a symmetric tensor
295
template
<
class
Cmpt>
296
inline
SymmTensor<Cmpt>
dev
(
const
SymmTensor<Cmpt>
& st)
297
{
298
return
st -
SphericalTensor<Cmpt>::oneThirdI
*
tr
(st);
299
}
300
301
302
//- Return the deviatoric part of a symmetric tensor
303
template
<
class
Cmpt>
304
inline
SymmTensor<Cmpt>
dev2
(
const
SymmTensor<Cmpt>
& st)
305
{
306
return
st -
SphericalTensor<Cmpt>::twoThirdsI
*
tr
(st);
307
}
308
309
310
//- Return the determinant of a symmetric tensor
311
template
<
class
Cmpt>
312
inline
Cmpt
det
(
const
SymmTensor<Cmpt>
& st)
313
{
314
return
315
(
316
st.
xx
()*st.
yy
()*st.
zz
() + st.
xy
()*st.
yz
()*st.
xz
()
317
+ st.
xz
()*st.
xy
()*st.
yz
() - st.
xx
()*st.
yz
()*st.
yz
()
318
- st.
xy
()*st.
xy
()*st.
zz
() - st.
xz
()*st.
yy
()*st.
xz
()
319
);
320
}
321
322
323
//- Return the cofactor symmetric tensor of a symmetric tensor
324
template
<
class
Cmpt>
325
inline
SymmTensor<Cmpt>
cof
(
const
SymmTensor<Cmpt>
& st)
326
{
327
return
SymmTensor<Cmpt>
328
(
329
st.
yy
()*st.
zz
() - st.
yz
()*st.
yz
(),
330
st.
xz
()*st.
yz
() - st.
xy
()*st.
zz
(),
331
st.
xy
()*st.
yz
() - st.
xz
()*st.
yy
(),
332
333
st.
xx
()*st.
zz
() - st.
xz
()*st.
xz
(),
334
st.
xy
()*st.
xz
() - st.
xx
()*st.
yz
(),
335
336
st.
xx
()*st.
yy
() - st.
xy
()*st.
xy
()
337
);
338
}
339
340
341
//- Return the inverse of a symmetric tensor give the determinant
342
template
<
class
Cmpt>
343
inline
SymmTensor<Cmpt>
inv
(
const
SymmTensor<Cmpt>
& st,
const
Cmpt detst)
344
{
345
return
SymmTensor<Cmpt>
346
(
347
st.
yy
()*st.
zz
() - st.
yz
()*st.
yz
(),
348
st.
xz
()*st.
yz
() - st.
xy
()*st.
zz
(),
349
st.
xy
()*st.
yz
() - st.
xz
()*st.
yy
(),
350
351
st.
xx
()*st.
zz
() - st.
xz
()*st.
xz
(),
352
st.
xy
()*st.
xz
() - st.
xx
()*st.
yz
(),
353
354
st.
xx
()*st.
yy
() - st.
xy
()*st.
xy
()
355
)/detst;
356
}
357
358
359
//- Return the inverse of a symmetric tensor
360
template
<
class
Cmpt>
361
inline
SymmTensor<Cmpt>
inv
(
const
SymmTensor<Cmpt>
& st)
362
{
363
return
inv
(st,
det
(st));
364
}
365
366
367
//- Return the 1st invariant of a symmetric tensor
368
template
<
class
Cmpt>
369
inline
Cmpt
invariantI
(
const
SymmTensor<Cmpt>
& st)
370
{
371
return
tr
(st);
372
}
373
374
375
//- Return the 2nd invariant of a symmetric tensor
376
template
<
class
Cmpt>
377
inline
Cmpt
invariantII
(
const
SymmTensor<Cmpt>
& st)
378
{
379
return
380
(
381
0.5*
sqr
(
tr
(st))
382
- 0.5*
383
(
384
st.
xx
()*st.
xx
() + st.
xy
()*st.
xy
() + st.
xz
()*st.
xz
()
385
+ st.
xy
()*st.
xy
() + st.
yy
()*st.
yy
() + st.
yz
()*st.
yz
()
386
+ st.
xz
()*st.
xz
() + st.
yz
()*st.
yz
() + st.
zz
()*st.
zz
()
387
)
388
);
389
}
390
391
392
//- Return the 3rd invariant of a symmetric tensor
393
template
<
class
Cmpt>
394
inline
Cmpt
invariantIII
(
const
SymmTensor<Cmpt>
& st)
395
{
396
return
det
(st);
397
}
398
399
400
template
<
class
Cmpt>
401
inline
SymmTensor<Cmpt>
402
operator+
(
const
SphericalTensor<Cmpt>
& spt1,
const
SymmTensor<Cmpt>
& st2)
403
{
404
return
SymmTensor<Cmpt>
405
(
406
spt1.
ii
() + st2.
xx
(), st2.
xy
(), st2.
xz
(),
407
spt1.
ii
() + st2.
yy
(), st2.
yz
(),
408
spt1.
ii
() + st2.
zz
()
409
);
410
}
411
412
413
template
<
class
Cmpt>
414
inline
SymmTensor<Cmpt>
415
operator+
(
const
SymmTensor<Cmpt>
& st1,
const
SphericalTensor<Cmpt>
& spt2)
416
{
417
return
SymmTensor<Cmpt>
418
(
419
st1.
xx
() + spt2.
ii
(), st1.
xy
(), st1.
xz
(),
420
st1.
yy
() + spt2.
ii
(), st1.
yz
(),
421
st1.
zz
() + spt2.
ii
()
422
);
423
}
424
425
426
template
<
class
Cmpt>
427
inline
SymmTensor<Cmpt>
428
operator-
(
const
SphericalTensor<Cmpt>
& spt1,
const
SymmTensor<Cmpt>
& st2)
429
{
430
return
SymmTensor<Cmpt>
431
(
432
spt1.
ii
() - st2.
xx
(), -st2.
xy
(), -st2.
xz
(),
433
spt1.
ii
() - st2.
yy
(), -st2.
yz
(),
434
spt1.
ii
() - st2.
zz
()
435
);
436
}
437
438
439
template
<
class
Cmpt>
440
inline
SymmTensor<Cmpt>
441
operator-
(
const
SymmTensor<Cmpt>
& st1,
const
SphericalTensor<Cmpt>
& spt2)
442
{
443
return
SymmTensor<Cmpt>
444
(
445
st1.
xx
() - spt2.
ii
(), st1.
xy
(), st1.
xz
(),
446
st1.
yy
() - spt2.
ii
(), st1.
yz
(),
447
st1.
zz
() - spt2.
ii
()
448
);
449
}
450
451
452
//- Inner-product between a spherical symmetric tensor and a symmetric tensor
453
template
<
class
Cmpt>
454
inline
SymmTensor<Cmpt>
455
operator&
(
const
SphericalTensor<Cmpt>
& spt1,
const
SymmTensor<Cmpt>
& st2)
456
{
457
return
SymmTensor<Cmpt>
458
(
459
spt1.
ii
()*st2.
xx
(), spt1.
ii
()*st2.
xy
(), spt1.
ii
()*st2.
xz
(),
460
spt1.
ii
()*st2.
yy
(), spt1.
ii
()*st2.
yz
(),
461
spt1.
ii
()*st2.
zz
()
462
);
463
}
464
465
466
//- Inner-product between a tensor and a spherical tensor
467
template
<
class
Cmpt>
468
inline
SymmTensor<Cmpt>
469
operator&
(
const
SymmTensor<Cmpt>
& st1,
const
SphericalTensor<Cmpt>
& spt2)
470
{
471
return
SymmTensor<Cmpt>
472
(
473
st1.
xx
()*spt2.
ii
(), st1.
xy
()*spt2.
ii
(), st1.
xz
()*spt2.
ii
(),
474
st1.
yy
()*spt2.
ii
(), st1.
yz
()*spt2.
ii
(),
475
st1.
zz
()*spt2.
ii
()
476
);
477
}
478
479
480
//- Double-dot-product between a spherical tensor and a symmetric tensor
481
template
<
class
Cmpt>
482
inline
Cmpt
483
operator&&
(
const
SphericalTensor<Cmpt>
& spt1,
const
SymmTensor<Cmpt>
& st2)
484
{
485
return
(spt1.
ii
()*st2.
xx
() + spt1.
ii
()*st2.
yy
() + spt1.
ii
()*st2.
zz
());
486
}
487
488
489
//- Double-dot-product between a tensor and a spherical tensor
490
template
<
class
Cmpt>
491
inline
Cmpt
492
operator&&
(
const
SymmTensor<Cmpt>
& st1,
const
SphericalTensor<Cmpt>
& spt2)
493
{
494
return
(st1.
xx
()*spt2.
ii
() + st1.
yy
()*spt2.
ii
() + st1.
zz
()*spt2.
ii
());
495
}
496
497
498
template
<
class
Cmpt>
499
inline
SymmTensor<Cmpt>
sqr
(
const
Vector<Cmpt>
& v)
500
{
501
return
SymmTensor<Cmpt>
502
(
503
v.
x
()*v.
x
(), v.
x
()*v.
y
(), v.
x
()*v.
z
(),
504
v.
y
()*v.
y
(), v.
y
()*v.
z
(),
505
v.
z
()*v.
z
()
506
);
507
}
508
509
510
template
<
class
Cmpt>
511
class
outerProduct
<
SymmTensor
<Cmpt>, Cmpt>
512
{
513
public
:
514
515
typedef
SymmTensor<Cmpt>
type
;
516
};
517
518
template
<
class
Cmpt>
519
class
outerProduct
<Cmpt,
SymmTensor
<Cmpt> >
520
{
521
public
:
522
523
typedef
SymmTensor<Cmpt>
type
;
524
};
525
526
template
<
class
Cmpt>
527
class
innerProduct
<
SymmTensor
<Cmpt>,
SymmTensor
<Cmpt> >
528
{
529
public
:
530
531
typedef
SymmTensor<Cmpt>
type
;
532
};
533
534
template
<
class
Cmpt>
535
class
innerProduct
<
SymmTensor
<Cmpt>,
Vector
<Cmpt> >
536
{
537
public
:
538
539
typedef
Vector<Cmpt>
type
;
540
};
541
542
template
<
class
Cmpt>
543
class
innerProduct
<
Vector
<Cmpt>,
SymmTensor
<Cmpt> >
544
{
545
public
:
546
547
typedef
Vector<Cmpt>
type
;
548
};
549
550
551
template
<
class
Cmpt>
552
class
typeOfSum
<
SphericalTensor
<Cmpt>,
SymmTensor
<Cmpt> >
553
{
554
public
:
555
556
typedef
SymmTensor<Cmpt>
type
;
557
};
558
559
template
<
class
Cmpt>
560
class
typeOfSum
<
SymmTensor
<Cmpt>,
SphericalTensor
<Cmpt> >
561
{
562
public
:
563
564
typedef
SymmTensor<Cmpt>
type
;
565
};
566
567
template
<
class
Cmpt>
568
class
innerProduct
<
SphericalTensor
<Cmpt>,
SymmTensor
<Cmpt> >
569
{
570
public
:
571
572
typedef
SymmTensor<Cmpt>
type
;
573
};
574
575
template
<
class
Cmpt>
576
class
innerProduct
<
SymmTensor
<Cmpt>,
SphericalTensor
<Cmpt> >
577
{
578
public
:
579
580
typedef
SymmTensor<Cmpt>
type
;
581
};
582
583
584
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
585
586
}
// End namespace Foam
587
588
// ************************ vim: set sw=4 sts=4 et: ************************ //