NeoPZ
TPZHWTools.h
Go to the documentation of this file.
1 /*
2  * File: TPZHaighWestergaardTools.h
3  * Author: quinelato
4  *
5  * Created on August 15, 2017, 4:28 PM
6  */
7 
8 #ifndef TPZHWTOOLS_H
9 #define TPZHWTOOLS_H
10 
11 #include "pzreal.h"
12 #include "pzvec.h"
13 #include "pzfmatrix.h"
14 #include <math.h>
15 
16 
20 class TPZHWTools {
21 public:
22 
28  static void FromHWCylToHWCart(const TPZVec<REAL> &HWCylCoords, TPZVec<REAL> &HWCart) {
29  HWCart[0] = HWCylCoords[0];
30  HWCart[1] = HWCylCoords[1] * cos(HWCylCoords[2]);
31  HWCart[2] = HWCylCoords[1] * sin(HWCylCoords[2]);
32  }
33 
39  static void FromPrincipalToHWCyl(const TPZVec<REAL> &PrincipalCoords, TPZVec<REAL> &HWCyl) {
40  TPZManVector<REAL,3> cart(3);
41  FromPrincipalToHWCart(PrincipalCoords, cart);
42  HWCyl[0] = cart[0]; // xi
43  HWCyl[1] = sqrt(cart[1] * cart[1] + cart[2] * cart[2]); // rho
44  HWCyl[2] = atan2(cart[2], cart[1]); // beta
45  }
46 
52  static void FromPrincipalToHWCart(const TPZVec<REAL> &PrincipalCoords, TPZVec<REAL> &HWCart) {
53  TPZFNMatrix<9, REAL> Rot(3, 3, 0.);
54 // HWCart.Resize(3, 0.); @omar::time_profiling
55  GetRotMatrix(Rot);
56 // Rot.Multiply(temp, cart); @omar::time_profiling
57  HWCart[0] = Rot(0,0) * PrincipalCoords[0] + Rot(0,1) * PrincipalCoords[1] + Rot(0,2) * PrincipalCoords[2];
58  HWCart[1] = Rot(1,0) * PrincipalCoords[0] + Rot(1,1) * PrincipalCoords[1] + Rot(1,2) * PrincipalCoords[2];
59  HWCart[2] = Rot(2,0) * PrincipalCoords[0] + Rot(2,1) * PrincipalCoords[1] + Rot(2,2) * PrincipalCoords[2];
60  }
61 
67  static void FromHWCylToPrincipal(const TPZVec<REAL> &HWCylCoords, TPZVec<REAL> &PrincipalCoords) {
68  const REAL tempWithXi = (1. / sqrt(3.)) * HWCylCoords[0];
69  const REAL tempWithRho = sqrt(2. / 3.) * HWCylCoords[1];
70  PrincipalCoords[0] = tempWithXi + tempWithRho * cos(HWCylCoords[2]);
71  PrincipalCoords[1] = tempWithXi + tempWithRho * cos(HWCylCoords[2]-(2. * M_PI / 3.));
72  PrincipalCoords[2] = tempWithXi + tempWithRho * cos(HWCylCoords[2]+(2. * M_PI / 3.));
73  }
74 
79 
80 #ifdef PZDEBUG
81  if ((A.Rows() != 2 && A.Cols() != 2) || (Ainv.Rows() != 2 && Ainv.Cols() != 2)) {
82  DebugStop();
83  }
84 #endif
85  Ainv(0,0)= A(1,1)/(-(A(0,1)*A(1,0)) + A(0,0)*A(1,1));
86  Ainv(0,1)= -(A(0,1)/(-(A(0,1)*A(1,0)) + A(0,0)*A(1,1)));
87  Ainv(1,0)= -(A(1,0)/(-(A(0,1)*A(1,0)) + A(0,0)*A(1,1)));
88  Ainv(1,1)= A(0,0)/(-(A(0,1)*A(1,0)) + A(0,0)*A(1,1));
89  }
94 
95 #ifdef PZDEBUG
96  if ((A.Rows() != 3 && A.Cols() != 3) || (Ainv.Rows() != 3 && Ainv.Cols() != 3)) {
97  DebugStop();
98  }
99 #endif
100  Ainv(0,0)= (A(1,2)*A(2,1) - A(1,1)*A(2,2))/(A(0,2)*A(1,1)*A(2,0) - A(0,1)*A(1,2)*A(2,0) - A(0,2)*A(1,0)*A(2,1) + A(0,0)*A(1,2)*A(2,1) + A(0,1)*A(1,0)*A(2,2) - A(0,0)*A(1,1)*A(2,2));
101  Ainv(0,1)= (A(0,2)*A(2,1) - A(0,1)*A(2,2))/(-(A(0,2)*A(1,1)*A(2,0)) + A(0,1)*A(1,2)*A(2,0) + A(0,2)*A(1,0)*A(2,1) - A(0,0)*A(1,2)*A(2,1) - A(0,1)*A(1,0)*A(2,2) + A(0,0)*A(1,1)*A(2,2));
102  Ainv(0,2)= (A(0,2)*A(1,1) - A(0,1)*A(1,2))/(A(0,2)*A(1,1)*A(2,0) - A(0,1)*A(1,2)*A(2,0) - A(0,2)*A(1,0)*A(2,1) + A(0,0)*A(1,2)*A(2,1) + A(0,1)*A(1,0)*A(2,2) - A(0,0)*A(1,1)*A(2,2));
103  Ainv(1,0)= (A(1,2)*A(2,0) - A(1,0)*A(2,2))/(-(A(0,2)*A(1,1)*A(2,0)) + A(0,1)*A(1,2)*A(2,0) + A(0,2)*A(1,0)*A(2,1) - A(0,0)*A(1,2)*A(2,1) - A(0,1)*A(1,0)*A(2,2) + A(0,0)*A(1,1)*A(2,2));
104  Ainv(1,1)= (A(0,2)*A(2,0) - A(0,0)*A(2,2))/(A(0,2)*A(1,1)*A(2,0) - A(0,1)*A(1,2)*A(2,0) - A(0,2)*A(1,0)*A(2,1) + A(0,0)*A(1,2)*A(2,1) + A(0,1)*A(1,0)*A(2,2) - A(0,0)*A(1,1)*A(2,2));
105  Ainv(1,2)= (A(0,2)*A(1,0) - A(0,0)*A(1,2))/(-(A(0,2)*A(1,1)*A(2,0)) + A(0,1)*A(1,2)*A(2,0) + A(0,2)*A(1,0)*A(2,1) - A(0,0)*A(1,2)*A(2,1) - A(0,1)*A(1,0)*A(2,2) + A(0,0)*A(1,1)*A(2,2));
106  Ainv(2,0)= (A(1,1)*A(2,0) - A(1,0)*A(2,1))/(A(0,2)*A(1,1)*A(2,0) - A(0,1)*A(1,2)*A(2,0) - A(0,2)*A(1,0)*A(2,1) + A(0,0)*A(1,2)*A(2,1) + A(0,1)*A(1,0)*A(2,2) - A(0,0)*A(1,1)*A(2,2));
107  Ainv(2,1)= (A(0,1)*A(2,0) - A(0,0)*A(2,1))/(-(A(0,2)*A(1,1)*A(2,0)) + A(0,1)*A(1,2)*A(2,0) + A(0,2)*A(1,0)*A(2,1) - A(0,0)*A(1,2)*A(2,1) - A(0,1)*A(1,0)*A(2,2) + A(0,0)*A(1,1)*A(2,2));
108  Ainv(2,2)= (A(0,1)*A(1,0) - A(0,0)*A(1,1))/(A(0,2)*A(1,1)*A(2,0) - A(0,1)*A(1,2)*A(2,0) - A(0,2)*A(1,0)*A(2,1) + A(0,0)*A(1,2)*A(2,1) + A(0,1)*A(1,0)*A(2,2) - A(0,0)*A(1,1)*A(2,2));
109 
110  }
111 
113  static void GetRotMatrix(TPZFMatrix<REAL> &Rot) {
114  const REAL SQRT1_3 = 1. / sqrt(3.);
115  const REAL SQRT1_6 = 1. / sqrt(6.);
116  // Rot.Resize(3, 3); // omar::time_profiling
117  Rot(0, 0) = SQRT1_3;
118  Rot(0, 1) = SQRT1_3;
119  Rot(0, 2) = SQRT1_3;
120  Rot(1, 0) = M_SQRT2*SQRT1_3;
121  Rot(1, 1) = -SQRT1_6;
122  Rot(1, 2) = -SQRT1_6;
123  Rot(2, 0) = 0;
124  Rot(2, 1) = M_SQRT1_2;
125  Rot(2, 2) = -M_SQRT1_2;
126  }
127 
129  static void GetRotInvMatrix(TPZFMatrix<REAL> &RotInv) {
130  TPZFMatrix<REAL> Rot(3,3);
131  GetRotMatrix(Rot);
132  A3x3Inverse(Rot, RotInv);
133  }
134 
135 public:
136 
137  TPZHWTools();
138 
139  TPZHWTools(const TPZHWTools& orig);
140 
141  virtual ~TPZHWTools();
142 
143 };
144 
145 #endif /* TPZHAIGHWESTERGAARDTOOLS_H */
146 
TPZFlopCounter atan2(const TPZFlopCounter &val1, const TPZFlopCounter &val2)
Returns the arc tangent in radians and increments the counter of the Arc Tangent. ATAN2 returns the ...
Definition: pzreal.h:544
static void FromPrincipalToHWCyl(const TPZVec< REAL > &PrincipalCoords, TPZVec< REAL > &HWCyl)
Definition: TPZHWTools.h:39
Templated vector implementation.
static void GetRotInvMatrix(TPZFMatrix< REAL > &RotInv)
Computes the inverse of the rotation matrix.
Definition: TPZHWTools.h:129
virtual ~TPZHWTools()
Definition: TPZHWTools.cpp:22
static void FromHWCylToHWCart(const TPZVec< REAL > &HWCylCoords, TPZVec< REAL > &HWCart)
Definition: TPZHWTools.h:28
sin
Definition: fadfunc.h:63
static void A2x2Inverse(TPZFMatrix< REAL > &A, TPZFMatrix< REAL > &Ainv)
Definition: TPZHWTools.h:78
static void GetRotMatrix(TPZFMatrix< REAL > &Rot)
Computes the rotation matrix.
Definition: TPZHWTools.h:113
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
static void A3x3Inverse(TPZFMatrix< REAL > &A, TPZFMatrix< REAL > &Ainv)
Definition: TPZHWTools.h:93
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
static void FromHWCylToPrincipal(const TPZVec< REAL > &HWCylCoords, TPZVec< REAL > &PrincipalCoords)
Definition: TPZHWTools.h:67
static void FromPrincipalToHWCart(const TPZVec< REAL > &PrincipalCoords, TPZVec< REAL > &HWCart)
Definition: TPZHWTools.h:52
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
TPZFlopCounter cos(const TPZFlopCounter &orig)
Returns the cosine in radians and increments the counter of the Cosine.
Definition: pzreal.h:514