NeoPZ
pzaxestools.h
Go to the documentation of this file.
1 
6 #ifndef AXESTOOLS
7 #define AXESTOOLS
8 
9 #include "pzfmatrix.h"
10 #include "pzerror.h"
11 
17 template<class TVar>
18 class TPZAxesTools {
19 public:
24 
29  static void VerifyAxes(const TPZFMatrix<TVar> &axes) {
30 #ifdef PZDEBUG
31 // const double tol = 1.e-8;
32  bool check = true;
33  for(int i = 0; i < axes.Rows(); i++){
34  for(int j = 0; j < axes.Rows(); j++) {
35  if(i == j) continue;
36  TVar sum = 0.;
37  for(int k = 0; k < axes.Cols(); k++){
38  sum += axes.GetVal(i,k)*axes.GetVal(j,k);
39  }//k
40  if(!IsZero(sum)){
41  check = false;
42  }//if
43  }//for j
44  }//for i
45 
46  if(check == false){
47  PZError << "\nError at " << __PRETTY_FUNCTION__;
48  axes.Print(", axes = ", PZError);
49  PZError << "\n";
50  }
51 #endif
52  }
53 
61  static void Axes2XYZ(const TPZFMatrix<TVar> &dudaxes, TPZFMatrix<TVar> &dudx, const TPZFMatrix<REAL> &axesv, bool colMajor = true){
62  TPZFNMatrix<9,TVar> axes(axesv.Rows(),axesv.Cols());
63  for (int r=0; r<axes.Rows(); r++) {
64  for (int c=0; c<axes.Cols(); c++) {
65  axes(r,c) = axesv.GetVal(r,c);
66  }
67  }
68 #ifdef PZDEBUG
70 #endif
71  if( colMajor ){
72  TPZFNMatrix<9,TVar> axesT;
73  axes.Transpose(&axesT);
74  if(dudx.Rows() != axesT.Rows() || dudx.Cols() != dudaxes.Cols())
75  {
76  dudx.Redim(axesT.Rows(), dudaxes.Cols());
77  }
78  dudx.Zero();
79  axesT.Multiply(dudaxes,dudx);
80  }
81  else{
82  dudx.Resize(dudaxes.Rows(), axes.Cols());
83  dudx.Zero();
84  dudaxes.Multiply(axes,dudx);
85  }
86  }
87 
95  static void XYZ2Axes(TPZFMatrix<TVar> &dudaxes, const TPZFMatrix<TVar> &dudx, const TPZFMatrix<REAL> &axes, bool colMajor = true){
97  if( colMajor ){
98  dudaxes.Resize(axes.Rows(), dudx.Cols());
99  dudaxes.Zero();
100  axes.Multiply(dudx,dudaxes);
101  }
102  else{
103  TPZFNMatrix<9,TVar> axesT;
104  axes.Transpose(&axesT);
105  dudaxes.Resize(dudx.Rows(), axesT.Cols());
106  dudaxes.Zero();
107  dudx.Multiply(axesT,dudaxes);
108  }
109  }
110 
111  static TVar ComputeDetjac(TPZFMatrix<TVar> &gradx){
112 
113  int dim = gradx.Cols();
114  TVar detjac =0.;
115 
116  if(dim==1){
117  detjac = gradx(0,0);
118  }else if(dim==2){
119  detjac = gradx(0,0)*gradx(1,1) - gradx(0,1)*gradx(1,0);
120 
121  }else if(dim==3){
122  detjac = gradx(0,0)*gradx(1,1)*gradx(2,2) + gradx(0,1)*gradx(1,2)*gradx(2,0) + gradx(0,2)*gradx(1,0)*gradx(2,1) - gradx(0,2)*gradx(1,1)*gradx(2,0) - gradx(0,0)*gradx(1,2)*gradx(2,1) - gradx(0,1)*gradx(1,0)*gradx(2,2);
123 
124  }else{
125  DebugStop();
126  }
127  return detjac;
128  }
129 
130 
133  {
134  int nc = jac.Rows();
135  gradx.Redim(3, jac.Rows());
136  for (int i=0; i<3; i++) {
137  for (int j=0; j<nc; j++) {
138  for (int k=0; k<nc; k++) {
139  gradx(i,j) += axes(k,i)*jac(k,j);
140  }
141  }
142  }
143  }
144 
146  static int main(){
147  TPZFMatrix<> axes(2,3,0.);
148  axes(0,0) = sqrt(2.)/2.;
149  axes(0,1) = 0.;
150  axes(0,2) = sqrt(2.)/2.;
151  axes(1,0) = 0.;
152  axes(1,1) = 1.;
153  axes(1,2) = 0.;
154  TPZFMatrix<> dudaxes(2,1);
155  dudaxes(0,0) = 0.3;
156  dudaxes(1,0) = 0.7;
157  TPZFMatrix<> dudx;
158  dudaxes.Print("dudaxes=",std::cout);
159  TPZAxesTools::Axes2XYZ(dudaxes,dudx,axes);
160  dudx.Print("dudx=",std::cout);
161  TPZAxesTools::XYZ2Axes(dudaxes,dudx,axes);
162  dudaxes.Print("dudaxes=",std::cout);
163  return 1;
164  }
165 
166 };
167 
168 #endif
TPZAxesTools()
simple constructor
Definition: pzaxestools.h:21
bool IsZero(long double a)
Returns if the value a is close Zero as the allowable tolerance.
Definition: pzreal.h:668
static void VerifyAxes(const TPZFMatrix< TVar > &axes)
Verify whether parameter axes is an orthogonal normalized matrix.
Definition: pzaxestools.h:29
static void Axes2XYZ(const TPZFMatrix< TVar > &dudaxes, TPZFMatrix< TVar > &dudx, const TPZFMatrix< REAL > &axesv, bool colMajor=true)
Makes the basis transformation from axes basis to euclidian basis.
Definition: pzaxestools.h:61
static void ComputeGradX(TPZFMatrix< TVar > &jac, TPZFMatrix< TVar > &axes, TPZFMatrix< TVar > &gradx)
Compute GradX as a function of jac and axes.
Definition: pzaxestools.h:132
Defines PZError.
static int main()
Definition: pzaxestools.h:146
~TPZAxesTools()
destructor
Definition: pzaxestools.h:23
static TVar ComputeDetjac(TPZFMatrix< TVar > &gradx)
Definition: pzaxestools.h:111
static void XYZ2Axes(TPZFMatrix< TVar > &dudaxes, const TPZFMatrix< TVar > &dudx, const TPZFMatrix< REAL > &axes, bool colMajor=true)
Makes the basis transformation from euclidian basis to axes basis.
Definition: pzaxestools.h:95
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
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
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
Implements method to verify whether axes is an orthogonal normalizes matrix and to transformation fro...
Definition: pzaxestools.h:18
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
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
virtual void Multiply(const TPZFMatrix< TVar > &A, TPZFMatrix< TVar > &res, int opt=0) const
It mutiplies itself by TPZMatrix<TVar>A putting the result in res.
Definition: pzmatrix.cpp:1916
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
Definition: pzfmatrix.cpp:1016
const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
Definition: pzfmatrix.h:566
void Transpose(TPZMatrix< TVar > *const T) const override
It makes *T the transpose of current matrix.
Definition: pzfmatrix.cpp:1073
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15