Test-tensor.C
Go to the documentation of this file.
1 #include "tensor.H"
2 #include "symmTensor.H"
3 #include "transform.H"
4 #include "stringList.H"
5 #include "IOstreams.H"
6 
7 using namespace Foam;
8 
9 int main()
10 {
11  tensor t1(1, 2, 3, 4, 5, 6, 7, 8, 9);
12  tensor t2(1, 2, 3, 1, 2, 3, 1, 2, 3);
13 
14  tensor t3 = t1 + t2;
15 
16  Info<< t3 << endl;
17 
18  tensor t4(3,-2,1,-2,2,0,1, 0, 4);
19 
20  Info<< inv(t4) << endl;
21  Info<< (inv(t4) & t4) << endl;
22 
23  Info<< t1.x() << t1.y() << t1.z() << endl;
24 
25  tensor t6(1,0,-4,0,5,4,-4,4,3);
26  //tensor t6(1,2,0,2,5,0,0,0,0);
27 
28  Info<< "tensor " << t6 << endl;
29  vector e = eigenValues(t6);
30  Info<< "eigenvalues " << e << endl;
31 
32  tensor ev = eigenVectors(t6);
33  Info<< "eigenvectors " << ev << endl;
34 
35  Info<< "Check determinant " << e.x()*e.y()*e.z() << " " << det(t6) << endl;
36 
37  Info<< "Check eigenvectors "
38  << (eigenVector(t6, e[0]) & t6) << e[0]*eigenVector(t6, e[0]) << " "
39  << (eigenVector(t6, e[1]) & t6) << e[1]*eigenVector(t6, e[1]) << " "
40  << (eigenVector(t6, e[2]) & t6) << e[2]*eigenVector(t6, e[2])
41  << endl;
42 
43  Info<< "Check eigenvalues for symmTensor "
44  << eigenValues(symm(t6)) - eigenValues(tensor(symm(t6))) << endl;
45 
46  Info<< "Check eigenvectors for symmTensor "
47  << eigenVectors(symm(t6)) - eigenVectors(tensor(symm(t6))) << endl;
48 
49  tensor t7(1, 2, 3, 2, 4, 5, 3, 5, 6);
50 
51  Info<< "Check transformation "
52  << (t1 & t7 & t1.T()) << " " << transform(t1, t7) << endl;
53 
54  symmTensor st1(1, 2, 3, 4, 5, 6);
55  symmTensor st2(7, 8, 9, 10, 11, 12);
56 
57  Info<< "Check symmetric transformation "
58  << transform(t1, st1) << endl;
59 
60  Info<< "Check dot product of symmetric tensors "
61  << (st1 & st2) << endl;
62 
63  Info<< "Check inner sqr of a symmetric tensor "
64  << innerSqr(st1) << " " << innerSqr(st1) - (st1 & st1) << endl;
65 
66  Info<< "Check symmetric part of dot product of symmetric tensors "
67  << twoSymm(st1&st2) - ((st1&st2) + (st2&st1)) << endl;
68 
69  tensor sk1 = skew(t6);
70  Info<< "Check dot product of symmetric and skew tensors "
71  << twoSymm(st1&sk1) - ((st1&sk1) - (sk1&st1)) << endl;
72 
73  vector v1(1, 2, 3);
74 
75  Info<< sqr(v1) << endl;
76  Info<< symm(t7) << endl;
77  Info<< twoSymm(t7) << endl;
78  Info<< magSqr(st1) << endl;
79  Info<< mag(st1) << endl;
80 
81  Info<< (symm(t7) && t7) - (0.5*(t7 + t7.T()) && t7) << endl;
82  Info<< (t7 && symm(t7)) - (t7 && 0.5*(t7 + t7.T())) << endl;
83 
84 
85  /*
86  // Lots of awkward eigenvector tests ...
87 
88  tensor T_rand_real
89  (
90  0.9999996423721313, 0.3330855667591095, 0.6646450161933899,
91  0.9745196104049683, 0.0369445420801640, 0.0846728682518005,
92  0.6474838852882385, 0.1617118716239929, 0.2041363865137100
93  );
94  Debug(T_rand_real);
95  vector L_rand_real(eigenValues(T_rand_real));
96  Debug(L_rand_real);
97  tensor U_rand_real(eigenVectors(T_rand_real));
98  Debug(U_rand_real);
99 
100  Info << endl << endl;
101 
102  tensor T_rand_imag
103  (
104  0.8668024539947510, 0.1664607226848602, 0.8925783634185791,
105  0.9126510620117188, 0.7408077120780945, 0.1499115079641342,
106  0.0936608463525772, 0.7615650296211243, 0.8953040242195129
107  );
108  Debug(T_rand_imag);
109  vector L_rand_imag(eigenValues(T_rand_imag));
110  Debug(L_rand_imag);
111  tensor U_rand_imag(eigenVectors(T_rand_imag));
112  Debug(U_rand_imag);
113 
114  Info << endl << endl;
115 
116  tensor T_rand_symm
117  (
118  1.9999992847442627, 1.3076051771640778, 1.3121289014816284,
119  1.3076051771640778, 0.0738890841603279, 0.2463847398757935,
120  1.3121289014816284, 0.2463847398757935, 0.4082727730274200
121  );
122  Debug(T_rand_symm);
123  vector L_rand_symm(eigenValues(T_rand_symm));
124  Debug(L_rand_symm);
125  tensor U_rand_symm(eigenVectors(T_rand_symm));
126  Debug(U_rand_symm);
127 
128  Info << endl << endl;
129 
130  symmTensor T_rand_Symm
131  (
132  1.9999992847442627, 1.3076051771640778, 1.3121289014816284,
133  0.0738890841603279, 0.2463847398757935,
134  0.4082727730274200
135  );
136  Debug(T_rand_Symm);
137  vector L_rand_Symm(eigenValues(T_rand_Symm));
138  Debug(L_rand_Symm);
139  tensor U_rand_Symm(eigenVectors(T_rand_Symm));
140  Debug(U_rand_Symm);
141 
142  Info << endl << endl;
143 
144  tensor T_rand_diag
145  (
146  0.8668024539947510, 0, 0,
147  0, 0.7408077120780945, 0,
148  0, 0, 0.8953040242195129
149  );
150  Debug(T_rand_diag);
151  vector L_rand_diag(eigenValues(T_rand_diag));
152  Debug(L_rand_diag);
153  tensor U_rand_diag(eigenVectors(T_rand_diag));
154  Debug(U_rand_diag);
155 
156  Info << endl << endl;
157 
158  tensor T_repeated
159  (
160  0, 1, 1,
161  1, 0, 1,
162  1, 1, 0
163  );
164  Debug(T_repeated);
165  vector L_repeated(eigenValues(T_repeated));
166  Debug(L_repeated);
167  tensor U_repeated(eigenVectors(T_repeated));
168  Debug(U_repeated);
169 
170  Info << endl << endl;
171 
172  tensor T_repeated_zero
173  (
174  1, 1, 1,
175  1, 1, 1,
176  1, 1, 1
177  );
178  Debug(T_repeated_zero);
179  vector L_repeated_zero(eigenValues(T_repeated_zero));
180  Debug(L_repeated_zero);
181  tensor U_repeated_zero(eigenVectors(T_repeated_zero));
182  Debug(U_repeated_zero);
183 
184  Info << endl << endl;
185 
186  tensor T_triple
187  (
188  2, 0, 0,
189  0, 2, 0,
190  0, 0, 2
191  );
192  Debug(T_triple);
193  vector L_triple(eigenValues(T_triple));
194  Debug(L_triple);
195  tensor U_triple(eigenVectors(T_triple));
196  Debug(U_triple);
197  */
198 
199  return 0;
200 }
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::symm
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:82
Foam::SymmTensor< scalar >
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::skew
dimensionedTensor skew(const dimensionedTensor &dt)
Definition: dimensionedTensor.C:135
Foam::Tensor::y
Vector< Cmpt > y() const
Definition: TensorI.H:128
Foam::eigenVectors
dimensionedTensor eigenVectors(const dimensionedTensor &dt)
Definition: dimensionedTensor.C:157
Foam::tensor
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::innerSqr
dimensionedSymmTensor innerSqr(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:60
tensor.H
Foam::transform
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:465
symmTensor.H
Foam::eigenVector
vector eigenVector(const tensor &, const scalar lambda)
Definition: tensor.C:207
Foam::eigenValues
dimensionedVector eigenValues(const dimensionedTensor &dt)
Definition: dimensionedTensor.C:146
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:71
Foam::Info
messageStream Info
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::Tensor::z
Vector< Cmpt > z() const
Definition: TensorI.H:135
main
int main()
Definition: Test-tensor.C:9
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::Tensor::x
Vector< Cmpt > x() const
Definition: TensorI.H:121
Foam::Vector< scalar >
Foam::det
dimensionedScalar det(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:60
transform.H
3D tensor transformation operations.
Foam::twoSymm
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:93
stringList.H
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::Tensor::T
Tensor< Cmpt > T() const
Transpose.
Definition: TensorI.H:286