NeoPZ
pztrnsform.cpp
Go to the documentation of this file.
1 
6 #include "pztrnsform.h"
7 #include "pzvec.h"
8 
9 #ifdef _AUTODIFF
10 #include "fad.h"
11 #endif
12 
13 using namespace std;
14 
15 template<class T>
17 fMult(dim,dim,0.), fSum(dim,1,0.) {
18  fRow = dim;
19  fCol = dim;
20  fMult.Zero();
21  fSum.Zero();
22  int d;
23 
24  for(d=0; d<dim; d++) {
25  fMult(d,d) = 1.;
26  }
27 
28 }
29 
30 template<class T>
32 fMult(0,0,0.), fSum(0,1,0.) {
33  fRow = 0;
34  fCol = 0;
35 }
36 
37 
38 
39 template<class T>
40 TPZTransform<T>::TPZTransform(int row,int col) : fMult(row,col,0.), fSum(row,1,0.) {
41  fRow = row;
42  fCol = col;
43  fMult.Zero();
44  fSum.Zero();
45  int d;
46  if (fRow == fCol) {
47  for(d=0; d<fRow; d++) {
48  fMult(d,d) = 1.;
49  }
50  }
51 }
52 
53 template<class T>
55 fSum(t.fSum)
56 {
57  fRow = t.fRow;
58  fCol = t.fCol;
59 }
60 
61 template<class T>
63 {
64  fRow = cp.fRow;
65  fCol = cp.fCol;
67  fSum.Resize(fRow,1);
68  for (int i=0; i<fRow; i++) {
69  fSum(i,0) = cp.fSum.GetVal(i,0);
70  for (int j=0; j<fCol; j++) {
71  fMult(i,j) = cp.fMult.GetVal(i,j);
72  }
73  }
74 }
75 
76 
77 
78 template<class T>
80  fRow = 0;
81  fCol = 0;
82  fMult.Resize(0,0);
83  fSum.Resize(0,0);
84 }
85 
86 template<class T>
88  fMult = t.fMult;
89  fSum = t.fSum;
90  fRow = t.fRow;
91  fCol = t.fCol;
92  return *this;
93 }
94 
95 template<class T>
97  fRow = mult.Rows();
98  fCol = mult.Cols();
99 
100 #ifdef PZDEBUG
101 
102  if ((sum.Cols()!=1)||(sum.Rows()!=mult.Rows())) {
103  DebugStop();
104  }
105 
106 #endif
107  fMult = mult;
108  fSum = sum;
109 }
110 
111 template<class T>
113  TPZTransform<T> res(fRow,right.fCol);
114  fMult.Multiply(right.fMult,res.fMult);
115  fMult.Multiply(right.fSum,res.fSum);
116  res.fSum += fSum;
117  return res;
118 }
119 
120 template<class T>
122 #ifdef PZDEBUG
123 
124 
125  if(fCol != in.size() || fRow != out.size())
126  {
127  DebugStop();
128  }
129 #endif
130  int i,j;
131  for(i=0; i<fRow; i++) {
132  out[i] = fSum(i,0);
133  for(j=0; j<fCol; j++) {
134  out[i] += fMult(i,j)*in[j];
135  }
136  }
137 }
138 
139 template<class T>
141  int i,j;
142  out << "{";
143  for(j=0; j<3; j++) {
144  if(j) out << ',';
145  out << "{";
146  for(i=0; i<3; i++) {
147  if(i) out << ',';
148  if(i<fRow && j < fCol) out << fMult(i,j);
149  else out << -99;
150  }
151  out << '}';
152  }
153  out << ",{";
154  for(i=0; i<3; i++) {
155  if(i) out << ',';
156  if(i<fRow) out << fSum(i,0);
157  else out << -99;
158  }
159  out << "}}";
160 }
161 #include <math.h>
162 template<class T>
164 
165  if(fCol != t.fCol || fRow != t.fRow)
166  return 1;
167  int i,j;
168  for(i=0;i<fRow;i++){
169  T check = fSum(i,0) - t.fSum(i,0);
170  if(fabs(check) > tol) return 1;
171  for(j=0;j<fCol;j++){
172  T check = fMult(i,j) - t.fMult(i,j);
173  if(fabs(check) > tol) return 1;
174  }
175  }
176  return 0;
177 }
178 
179 template class TPZTransform<REAL>;
180 #ifdef _AUTODIFF
181 template class TPZTransform<Fad<REAL> >;
182 #endif
~TPZTransform()
Default destructor.
Definition: pztrnsform.cpp:79
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
Definition: tfadfunc.h:140
Templated vector implementation.
void CopyFrom(const TPZTransform< REAL > &cp)
Create a copy form a real transformation.
Definition: pztrnsform.cpp:62
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
int fRow
Number of rows of the matrix associated with the transformation.
Definition: pztrnsform.h:25
int fCol
Number of columns of the matrix associated with the transformation.
Definition: pztrnsform.h:27
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
static const double tol
Definition: pzgeoprism.cpp:23
int CompareTransform(TPZTransform< T > &t, REAL tol=1.e-6)
Compare the current transformation with t transformation considering a given tolerance.
Definition: pztrnsform.cpp:163
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
TPZTransform()
Default constructor.
Definition: pztrnsform.cpp:31
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
string res
Definition: test.py:151
void PrintInputForm(std::ostream &out)
Definition: pztrnsform.cpp:140
TPZTransform< T > Multiply(TPZTransform< T > &right)
Multiply the transformation object (to the right) with right (Multiplying matrices) ...
Definition: pztrnsform.cpp:112
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
TPZTransform< T > & operator=(const TPZTransform< T > &t)
Overloading equal operator for transformation.
Definition: pztrnsform.cpp:87
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
Definition: pzfmatrix.cpp:1016
Contains the TPZTransform<> class which implements an affine transformation between points in paramet...
Implements an affine transformation between points in parameter space. Topology Utility.
Definition: pzmganalysis.h:14
void SetMatrix(TPZFMatrix< T > &mult, TPZFMatrix< T > &sum)
Sets the transformation matrices.
Definition: pztrnsform.cpp:96
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
TPZFNMatrix< 3, T > fSum
Matrix used by sums.
Definition: pztrnsform.h:31
TPZFNMatrix< 9, T > fMult
Matrix used by multiplications.
Definition: pztrnsform.h:29
void Apply(TPZVec< T > &vectorin, TPZVec< T > &vectorout)
Transforms the vector.
Definition: pztrnsform.cpp:121