muMECH  1.0
transformTensors.cpp
Go to the documentation of this file.
1 //********************************************************************************************************
2 // code: ### ### ##### #### ## ##
3 // ## ## ######## ## ## ## ## ##
4 // ## ## ## ## ## ### ## ######
5 // ## ## ## ## ## ## ## ## ##
6 // ##### ## ## ##### #### ## ##
7 // ##
8 //
9 // name: transformTensors.cpp
10 // author(s): Jan Novak, Ladislav Svoboda
11 // language: C, C++
12 // license: This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 //********************************************************************************************************
26 
27 #include <math.h>
28 #include "macros.h"
29 #include "transformTensors.h"
30 #include "matrixOperations.h"
31 #include "elementaryFunctions.h"
32 #include "problem.h"
33 
34 
35 namespace mumech {
36 
38 void TransformTensors :: give_T (double *T, const double *eullerAngles, EullerRotations flag, InclusionGeometry inclGeometry)
39 {
40  switch ( inclGeometry ) {
41  case IS_ELLIPSOID :
42  case IS_OBLATE_SPHEROID :
43  case IS_PROLATE_SPHEROID :
44  //case IS_ELLIPTIC_CYLINDER :
45  //case IS_CYLINDER :
46  //case IS_PENNY :
47  //case IS_FLAT_ELLIPSOID :
48  TransformTensors::give_T_3d (T, eullerAngles, flag);
49  break;
50  case IS_SPHERE :
51  giveUnitMatrix3x3(T); //unit matrix, not used furthermore anyway (hopefully)
52  break;
53  case IS_CIRCLE :
54  giveUnitMatrix2x2(T); //unit matrix, not used furthermore anyway (hopefully)
55  break;
56  case IS_ELLIPSE :
57  T[0] = cos(eullerAngles[0]); T[1] = sin(eullerAngles[0]);
58  T[2] = -T[1]; T[3] = T[0];
59  break;
60  default:
61  _errorr2( "Unsupported shape of inclusion \"%s\"", IST_e2s (inclGeometry));
62  }
63 
64  return ;
65 }
66 
68 void TransformTensors :: give_Te (double *Te, const double *T, InclusionGeometry inclGeometry)
69 {
70  switch ( inclGeometry ) {
71  case IS_ELLIPSOID :
72  case IS_OBLATE_SPHEROID :
73  case IS_PROLATE_SPHEROID :
74  //case IS_ELLIPTIC_CYLINDER :
75  //case IS_CYLINDER :
76  //case IS_PENNY :
77  //case IS_FLAT_ELLIPSOID :
79  break;
80  case IS_SPHERE :
81  MatrixOperations::giveUnitSMatrixFull_3d (Te); // unit matrix, not used furthermore anyway (hopefully)
82  break;
83  case IS_CIRCLE :
84  MatrixOperations::giveUnitSMatrixFull_2d (Te); // unit matrix, not used furthermore anyway (hopefully)
85  break;
86  case IS_ELLIPSE :
87  // first row
88  Te[0] = SQR( T[0] );
89  Te[1] = SQR( T[1] );
90  Te[2] = 2.0 * T[0] * T[1];
91 
92  // second row
93  Te[3] = SQR( T[2] );
94  Te[4] = SQR( T[3] );
95  Te[5] = 2.0 * T[2] * T[3];
96 
97  // third row
98  Te[6] = T[0] * T[2];
99  Te[7] = T[1] * T[3];
100  Te[8] = T[0] * T[3] + T[1] * T[2];
101 
102  break;
103  default:
104  _errorr2( "Unsupported shape of inclusion \"%s\"", IST_e2s (inclGeometry));
105  }
106 }//end of function: give_Te( )
107 
109 void TransformTensors :: give_TInv (double *TInv, const double *T, InclusionGeometry inclGeometry)
110 {
111  switch ( inclGeometry ) {
112 
113  case IS_ELLIPSOID :
114  //case IS_ELLIPTIC_CYLINDER :
115  //case IS_CYLINDER :
116  //case IS_PENNY :
117  //case IS_FLAT_ELLIPSOID :
118  case IS_OBLATE_SPHEROID :
119  case IS_PROLATE_SPHEROID : giveTransposedMatrix (T, TInv, 3); break;
120  case IS_ELLIPSE : giveTransposedMatrix (T, TInv, 2); break;
121 
122  // unit matrix, not used furthermore anyway (hopefully)
123  case IS_SPHERE : giveUnitMatrix3x3(TInv); break;
124  case IS_CIRCLE : giveUnitMatrix2x2(TInv); break;
125 
126  default: _errorr2( "Unsupported shape of inclusion \"%s\"", IST_e2s (inclGeometry));
127  }
128 
129  return ;
130 }
131 
133 void TransformTensors :: give_TeInv (double *TeInv, const double *Te, InclusionGeometry inclGeometry)
134 {
135  switch ( inclGeometry ) {
136  case IS_ELLIPSOID :
137  case IS_OBLATE_SPHEROID :
138  case IS_PROLATE_SPHEROID :
139  //case IS_ELLIPTIC_CYLINDER :
140  //case IS_CYLINDER :
141  //case IS_PENNY :
142  //case IS_FLAT_ELLIPSOID :
143  // ALTERNATIVE - more consumption then "transposition plus some 2.0 multiplication"
144  // this->Te( TeInv, TInv );
145 
146  giveTransposedMatrix (Te, TeInv, 6);
147 
148  int i, j;
149 
150  for (i=0; i<3; i++)
151  for (j=3; j<6; j++)
152  TeInv[i*6+j] *= 2.0;
153 
154  for (i=3; i<6; i++)
155  for (j=0; j<3; j++)
156  TeInv[i*6+j] /= 2.0;
157 
158  break;
159 
160  case IS_ELLIPSE :
161  giveTransposedMatrix (Te, TeInv, 3);
162 
163  TeInv[2] *= 2.0; TeInv[5] *= 2.0;
164  TeInv[6] /= 2.0; TeInv[7] /= 2.0;
165 
166  break;
167 
168  case IS_SPHERE :
169  MatrixOperations::giveUnitSMatrixFull_3d (TeInv); // unit matrix, not used furthermore anyway (hopefully)
170  break;
171  case IS_CIRCLE :
172  MatrixOperations::giveUnitSMatrixFull_2d (TeInv); // unit matrix, not used furthermore anyway (hopefully)
173  break;
174  default:
175  _errorr2( "Unsupported shape of inclusion \"%s\"", IST_e2s (inclGeometry));
176  }
177 
178  return ;
179 }//end of function: give_TeInv( )
180 
181 
183 void TransformTensors :: give_T_3d (double T[9], const double eullerAngles[3], EullerRotations flag)
184 {
185  double phi = eullerAngles[0], nu = eullerAngles[1], psi = eullerAngles[2];
186  double c1 = cos( phi ), c2 = cos( nu ), c3 = cos( psi );
187  double s1 = sin( phi ), s2 = sin( nu ), s3 = sin( psi );
188 
189  switch( flag ){
190  case _XZX_:
191  //1st row
192  T[0] = c2;
193  T[1] = c1 * s2;
194  T[2] = s1 * s2;
195  //2nd row
196  T[3] = -c3 * s2;
197  T[4] = c1 * c2 * c3 - s1 * s3;
198  T[5] = c2 * c3 * s1 + c1 * s3;
199  //3rd row
200  T[6] = s2 * s3;
201  T[7] = -c3 * s1 - c1 * c2 * s3;
202  T[8] = c1 * c3 - c2 * s1 * s3;
203  break;
204  case _XYX_:
205  //1st row
206  T[0] = c2;
207  T[1] = s1 * s2;
208  T[2] = -c1 * s2;
209  //2nd row
210  T[3] = s2 * s3;
211  T[4] = c1 * c3 - c2 * s1 * s3;
212  T[5] = c3 * s1 + c1 * c2 * s3;
213  //3rd row
214  T[6] = c3 * s2;
215  T[7] = -c2 * c3 * s1 - c1 * s3;
216  T[8] = c1 * c2 * c3 - s1 * s3;
217  break;
218  case _YXY_:
219  //1st row
220  T[0] = c1 * c3 - c2 * s1 * s3;
221  T[1] = s2 * s3;
222  T[2] = -c3 * s1 - c1 * c2 * s3;
223  //2nd row
224  T[3] = s1 * s2;
225  T[4] = c2;
226  T[5] = c1 * s2;
227  //3rd row
228  T[6] = c2 * c3 * s1 + c1 * s3;
229  T[7] = -c3 * s2;
230  T[8] = c1 * c2 * c3 - s1 * s3;
231  break;
232  case _YZY_:
233  //1st row
234  T[0] = c1 * c2 * c3 - s1 * s3;
235  T[1] = c3 * s2;
236  T[2] = -c2 * c3 * s1 - c1 * s3;
237  //2nd row
238  T[3] = -c1 * s2;
239  T[4] = c2;
240  T[5] = s1 * s2;
241  //3rd row
242  T[6] = c3 * s1 + c1 * c2 * s3;
243  T[7] = s2 * s3;
244  T[8] = c1 * c3 - c2 * s1 * s3;
245  break;
246  case _ZYZ_:
247  //1st row
248  T[0] = c1 * c2 * c3 - s1 * s3;
249  T[1] = c2 * c3 * s1 + c1 * s3;
250  T[2] = -c3 * s2;
251  //2nd row
252  T[3] = -c3 * s1 - c1 * c2 * s3;
253  T[4] = c1 * c3 - c2 * s1 * s3;
254  T[5] = s2 * s3;
255  //3rd row
256  T[6] = c1 * s2;
257  T[7] = s1 * s2;
258  T[8] = c2;
259  break;
260  case _ZXZ_:
261  //1st row
262  T[0] = c1 * c3 - c2 * s1 * s3;
263  T[1] = c3 * s1 + c1 * c2 * s3;
264  T[2] = s2 * s3;
265  //2nd row
266  T[3] = -c2 * c3 * s1 - c1 * s3;
267  T[4] = c1 * c2 * c3 - s1 * s3;
268  T[5] = c3 * s2;
269  //3rd row
270  T[6] = s1 * s2;
271  T[7] = -c1 * s2;
272  T[8] = c2;
273  break;
274  case _XZY_:
275  //1st row
276  T[0] = c2 * c3;
277  T[1] = c1 * c3 * s2 + s1 * s3;
278  T[2] = c3 * s1 * s2 - c1 * s3;
279  //2nd row
280  T[3] = -s2;
281  T[4] = c1 * c2;
282  T[5] = c2 * s1;
283  //3rd row
284  T[6] = c2 * s3;
285  T[7] = -c3 * s1 + c1 * s2 * s3;
286  T[8] = c1 * c3 + s1 * s2 * s3;
287  break;
288  case _XYZ_:
289  //1st row
290  T[0] = c2 * c3;
291  T[1] = c3 * s1 * s2 + c1 * s3;
292  T[2] = -c1 * c3 * s2 + s1 * s3;
293  //2nd row
294  T[3] = -c2 * s3;
295  T[4] = c1 * c3 - s1 * s2 * s3;
296  T[5] = c3 * s1 + c1 * s2 * s3;
297  //3rd row
298  T[6] = s2;
299  T[7] = -c2 * s1;
300  T[8] = c1 * c2;
301  break;
302  case _YXZ_:
303  //1st row
304  T[0] = c1 * c3 + s1 * s2 * s3;
305  T[1] = c2 * s3;
306  T[2] = -c3 * s1 + c1 * s2 * s3;
307  //2nd row
308  T[3] = c3 * s1 * s2 - c1 * s3;
309  T[4] = c2 * c3;
310  T[5] = c1 * c3 * s2 + s1 * s3;
311  //3rd row
312  T[6] = c2 * s1;
313  T[7] = -s2;
314  T[8] = c1 * c2;
315  break;
316  case _YZX_:
317  //1st row
318  T[0] = c1 * c2;
319  T[1] = s2;
320  T[2] = -c2 * s1;
321  //2nd row
322  T[3] = -c1 * c3 * s2 + s1 * s3;
323  T[4] = c2 * c3;
324  T[5] = c3 * s1 * s2 + c1 * s3;
325  //3rd row
326  T[6] = c3 * s1 + c1 * s2 * s3;
327  T[7] = -c2 * s3;
328  T[8] = c1 * c3 - s1 * s2 * s3;
329  break;
330  case _ZYX_:
331  //1st row
332  T[0] = c1 * c2;
333  T[1] = c2 * s1;
334  T[2] = -s2;
335  //2nd row
336  T[3] = -c3 * s1 + c1 * s2 * s3;
337  T[4] = c1 * c3 + s1 * s2 * s3;
338  T[5] = c2 * s3;
339  //3rd row
340  T[6] = c1 * c3 * s2 + s1 * s3;
341  T[7] = c3 * s1 * s2 - c1 * s3;
342  T[8] = c2 * c3;
343  break;
344  case _ZXY_:
345  //1st row
346  T[0] = c1 * c3 - s1 * s2 * s3;
347  T[1] = c3 * s1 + c1 * s2 * s3;
348  T[2] = -c2 * s3;
349  //2nd row
350  T[3] = -c2 * s1;
351  T[4] = c1 * c2;
352  T[5] = s2;
353  //3rd row
354  T[6] = c3 * s1 * s2 + c1 * s3;
355  T[7] = -c1 * c3 * s2 + s1 * s3;
356  T[8] = c2 * c3;
357  break;
358  default:
359  _errorr( "T: Invalid successive rotations of coordinate system");
360  break;
361  }//end of switch: flag
362 
363  return ;
364 }//end of function: give_T_3d( )
365 
366 
367 #define _T( i, j ) T[( i - 1 ) * 3 + ( j - 1 )]
368 
370 void TransformTensors :: give_Te_3d (double Te[36], const double T[9])
371 {
372  //1st row
373  Te[0] = SQR( _T( 1, 1 ) );
374  Te[1] = SQR( _T( 1, 2 ) );
375  Te[2] = SQR( _T( 1, 3 ) );
376  //T[3] <-> T[5] in TNTV_THEORETICAL_FEEP notation
377  Te[5] = 2. * _T( 1, 1 ) * _T( 1, 3 );//s_13 transform
378  Te[4] = 2. * _T( 1, 2 ) * _T( 1, 3 );//s_23 transform
379  Te[3] = 2. * _T( 1, 1 ) * _T( 1, 2 );//s_12 transform
380 
381  //2nd row
382  Te[6] = SQR( _T( 2, 1 ) );
383  Te[7] = SQR( _T( 2, 2 ) );
384  Te[8] = SQR( _T( 2, 3 ) );
385  //T[9] <-> T[11] in TNTV_THEORETICAL_FEEP notation
386  Te[11] = 2. * _T( 2, 1 ) * _T( 2, 3 );//s_13 transform
387  Te[10] = 2. * _T( 2, 2 ) * _T( 2, 3 );//s_23 transform
388  Te[9] = 2. * _T( 2, 1 ) * _T( 2, 2 );//s_12 transform
389 
390  //3rd row
391  Te[12] = SQR( _T( 3, 1 ) );
392  Te[13] = SQR( _T( 3, 2 ) );
393  Te[14] = SQR( _T( 3, 3 ) );
394  //T[15] <-> T[17] in TNTV_THEORETICAL_FEEP notation
395  Te[17] = 2. * _T( 3, 1 ) * _T( 3, 3 );//s_13 transform
396  Te[16] = 2. * _T( 3, 2 ) * _T( 3, 3 );//s_23 transform
397  Te[15] = 2. * _T( 3, 1 ) * _T( 3, 2 );//s_12 transform
398 
399  //4th row (in TNTV_THEORETICAL_FEEP notation 4th row <-> 6th row)
400  Te[18] = _T( 2, 1 ) * _T( 1, 1 );
401  Te[19] = _T( 2, 2 ) * _T( 1, 2 );
402  Te[20] = _T( 2, 3 ) * _T( 1, 3 );
403  //T[21] <-> T[23] in TNTV_THEORETICAL_FEEP notation
404  Te[23] = _T( 2, 3 ) * _T( 1, 1 ) + _T( 2, 1 ) * _T( 1, 3 );//s_13 transform
405  Te[22] = _T( 2, 3 ) * _T( 1, 2 ) + _T( 2, 2 ) * _T( 1, 3 );//s_23 transform
406  Te[21] = _T( 1, 1 ) * _T( 2, 2 ) + _T( 2, 1 ) * _T( 1, 2 );//s_12 transform
407 
408  //5th row
409  Te[24] = _T( 3, 1 ) * _T( 2, 1 );
410  Te[25] = _T( 3, 2 ) * _T( 2, 2 );
411  Te[26] = _T( 3, 3 ) * _T( 2, 3 );
412  //T[33] <-> T[35] in TNTV_THEORETICAL_FEEP notation
413  Te[29] = _T( 3, 3 ) * _T( 2, 1 ) + _T( 3, 1 ) * _T( 2, 3 );//s_13 transform
414  Te[28] = _T( 3, 2 ) * _T( 2, 3 ) + _T( 3, 3 ) * _T( 2, 2 );//s_23 transform
415  Te[27] = _T( 3, 1 ) * _T( 2, 2 ) + _T( 3, 2 ) * _T( 2, 1 );//s_12 transform
416 
417  //6th row (in TNTV_THEORETICAL_FEEP notation 6th row <-> 4th row)
418  Te[30] = _T( 3, 1 ) * _T( 1, 1 );
419  Te[31] = _T( 3, 2 ) * _T( 1, 2 );
420  Te[32] = _T( 3, 3 ) * _T( 1, 3 );
421  //T[27] <-> T[29] in TNTV_THEORETICAL_FEEP notation
422  Te[35] = _T( 3, 3 ) * _T( 1, 1 ) + _T( 3, 1 ) * _T( 1, 3 );//s_13 transform
423  Te[34] = _T( 3, 2 ) * _T( 1, 3 ) + _T( 3, 3 ) * _T( 1, 2 );//s_23 transform
424  Te[33] = _T( 3, 2 ) * _T( 1, 1 ) + _T( 3, 1 ) * _T( 1, 2 );//s_12 transform
425 
426  return ;
427 }//end of function: give_Te_3d( )
428 
429 
430 
431 } // end of namespace mumech
432 
433 /*end of file*/
EullerRotations
Definition: types.h:661
const char * IST_e2s(InclusionGeometry ig)
Inclusion shapes&#39; type - enum to string.
Definition: types.h:174
#define _T(i, j)
void giveUnitSMatrixFull_2d(double *m)
Function sets reduced 2d SMatrix to unit matrix.
void give_Te(double *Te, const double *T, InclusionGeometry inclGeometry)
Function calculates the transformation matrix for strain/stress tensors saved in vectors with TNTV_TH...
Namespace MatrixOperations.
void give_Te_3d(double Te[36], const double T[9])
void giveUnitMatrix3x3(double *m)
Function sets 3X3 matrix to unit matrix.
The header file of usefull macros.
#define _errorr2(_1, _2)
Definition: gelib.h:154
Collection of the functions of basic manipulations, some of them can be used instead of their counter...
void give_T_3d(double T[9], const double eullerAngles[3], EullerRotations flag)
void give_TeInv(double *TeInv, const double *Te, InclusionGeometry inclGeometry)
Function calculates the inverse of transformation matrix for strain/stress tensors saved in vectors w...
void give_T(double *T, const double *eullerAngles, EullerRotations flag, InclusionGeometry inclGeometry)
Function calculates the transformation matrix from given Euller angles.
#define SQR(a)
Definition: macros.h:97
#define _errorr(_1)
Definition: gelib.h:160
InclusionGeometry
Inclusion shapes&#39; type.
Definition: types.h:161
void give_TInv(double *TInv, const double *T, InclusionGeometry inclGeometry)
Function calculates the inverse of transformation matrix for vectors.
void giveUnitSMatrixFull_3d(double *m)
Function sets reduced 3d SMatrix to unit matrix.
void giveUnitMatrix2x2(double *m)
Function sets 3x3 matrix to unit matrix.
Class Problem.
void giveTransposedMatrix(const double *mtrx, double *T_mtrx, int n)
Function gives the trasposition of a matrix saved in row-by-row C arrangement.
Namespace TransformTensors.