NeoPZ
tpzarc3d.cpp
Go to the documentation of this file.
1 
5 #include "tpzarc3d.h"
6 #include "pzshapelinear.h"
7 
8 #include "pzfmatrix.h"
9 #include "pzvec.h"
10 #include "pzvec_extras.h"
11 #include "pzgmesh.h"
12 #include "pzgeoel.h"
13 #include "pznoderep.h"
14 #include "pzgnode.h"
15 #include "pzreal.h"
16 #include "tpzgeoelmapped.h"
17 #include <math.h>
18 
19 using namespace std;
20 using namespace pzgeom;
21 using namespace pztopology;
22 using namespace pzshape;
23 
24 
25 void TPZArc3D::ComputeAtributes(TPZFMatrix<REAL> &coord)
26 {
27 #ifdef PZDEBUG
28 
29  double CrossX, CrossY, CrossZ;
30  try
31  {
32  CrossX = fabs(-(coord(1,1)*coord(2,0)) + coord(1,2)*coord(2,0) + coord(1,0)*coord(2,1) - coord(1,2)*coord(2,1) - coord(1,0)*coord(2,2) + coord(1,1)*coord(2,2));
33  CrossY = fabs(coord(0,1)*coord(2,0) - coord(0,2)*coord(2,0) - coord(0,0)*coord(2,1) + coord(0,2)*coord(2,1) + coord(0,0)*coord(2,2) - coord(0,1)*coord(2,2));
34  CrossZ = fabs(-(coord(0,1)*coord(1,0)) + coord(0,2)*coord(1,0) + coord(0,0)*coord(1,1) - coord(0,2)*coord(1,1) - coord(0,0)*coord(1,2) + coord(0,1)*coord(1,2));
35  }
36  catch(...){
37  std::cout << "Arc3D element with nodes coordinates non initialized!!!\n";
38  DebugStop();
39  }
40 
42  if(CrossX <= 1.E-6 && CrossY <= 1.E-6 && CrossZ <= 1.E-6)
43  {
44  cout << "The 3 given points that define an TPZArc3D are co-linear!\n";
45  cout << "Method aborted!";
46 
47  DebugStop();
48  }
49 #endif
50 
52  TPZFNMatrix<9> IBaseCnCP(3,3,0.), NotUsedHere(3,3,0.);
53  fIBaseCn.Resize(3,3); fICnBase.Resize(3,3); fCenter3D.Resize(3);
54  for(int i = 0; i < 3; i++)
55  {
56  IBaseCnCP(i,0) = coord(i,0) - coord(i,2);
57  IBaseCnCP(i,1) = coord(i,1) - coord(i,2);
58  }
59 
61  IBaseCnCP(0,2) = -coord(1,1)*coord(2,0) + coord(1,2)*coord(2,0) + coord(1,0)*coord(2,1) - coord(1,2)*coord(2,1) - coord(1,0)*coord(2,2) + coord(1,1)*coord(2,2);
62  IBaseCnCP(1,2) = coord(0,1)*coord(2,0) - coord(0,2)*coord(2,0) - coord(0,0)*coord(2,1) + coord(0,2)*coord(2,1) + coord(0,0)*coord(2,2) - coord(0,1)*coord(2,2);
63  IBaseCnCP(2,2) = -coord(0,1)*coord(1,0) + coord(0,2)*coord(1,0) + coord(0,0)*coord(1,1) - coord(0,2)*coord(1,1) - coord(0,0)*coord(1,2) + coord(0,1)*coord(1,2);
64 
65  TPZFNMatrix<9> axest(IBaseCnCP.Rows(),IBaseCnCP.Cols());
66  IBaseCnCP.GramSchmidt(axest,NotUsedHere);
67 
68  fIBaseCn = axest;
69  axest.Transpose(&fICnBase);
70 
72  // fIBaseCn = fICnBase; fIBaseCn.Transpose();
73 
74  double Xa, Ya, Xb, Yb;
75  ComputeR2Points(coord,Xa,Ya,Xb,Yb);
76 
78  fXcenter = Xa/2.;
79  fYcenter = (-Xa*Xb + Xb*Xb + Yb*Yb) / (2.*Yb);
80 
82  TPZVec<REAL> Temp(3,0.);
83  Temp[0] = fXcenter; Temp[1] = fYcenter; Temp[2] = 0.; double temp = 0.;
84  for(int i = 0; i < 3; i++)
85  {
86  for(int j = 0; j < 3; j++) temp += fIBaseCn(i,j)*Temp[j];
87  fCenter3D[i] = temp + coord(i,2);
88  temp = 0.;
89  }
90 
92  fRadius = sqrt( fXcenter*fXcenter + fYcenter*fYcenter );
93 
95  finitialVector.Resize(2,0.);
96  finitialVector[0] = Xa - fXcenter; finitialVector[1] = Ya - fYcenter;
97 
98 
99 
100 #ifdef PZDEBUG2
101 
102  TPZFNMatrix<9,REAL> nodes=coord;
103  TPZManVector<REAL,1> loc(1,0.0);
104  TPZManVector<REAL,3> result(3.);
105 
106  REAL resultlocminus1, resultloc0,resultlocplus1;
107 
108  loc[0] = -1.;
109  X(nodes,loc,result);
110  for (int i=0; i<3; i++) {
111  result[i] -= nodes(i,0);
112  }
113  resultlocminus1 = Norm(result);
114 
115  //cout << result << endl;
116 
117  loc[0] = 1.;
118  X(nodes,loc,result);
119  for (int i=0; i<3; i++) {
120  result[i] -= nodes(i,1);
121  }
122  resultlocplus1 = Norm(result);
123 
124  //cout << result << endl;
125  loc[0] = 0.;
126  X(nodes,loc,result);
127  for (int i=0; i<3; i++) {
128  result[i] -= nodes(i,2);
129  }
130  resultloc0 = Norm(result);
131  //cout << result << endl;
132 
133 
134  // testes
136  if(resultlocminus1 >= 1.E-6 ) // loc = -1 ponto da esquerda do arco
137  {
138  cout << "Method aborted!";
139 
140  DebugStop();
141  }
142  if(resultlocplus1 >= 1.E-6) // loc = 1 ponto da direita do arco
143  {
144  cout << "Method aborted!";
145 
146  DebugStop();
147  }
148  if(resultloc0 >= 1.E-6) // loc = 0 ponto do centro do arco
149  {
150 
151  cout << "Method aborted!";
152 
153  DebugStop();
154  }
155 #endif
156 
157 }
158 
159 
161 void TPZArc3D::ComputeR2Points(TPZFMatrix<REAL> &coord, double &xa, double &ya, double &xb, double &yb)
162 {
164  TPZManVector<REAL,3> Axe(3,0.), Temp(3,0.);
165  int i, j;
166  for(i = 0; i < 3; i++) Axe[i] = coord(i,0) - coord(i,2);
167  for(i = 0; i < 3; i++)
168  {
169  for(j = 0; j < 3; j++) Temp[i] += fICnBase(i,j)*Axe[j];
170  }
171  xa = Temp[0]; ya = Temp[1];
172  Temp.Fill(0.);
173 
175  for(i = 0; i < 3; i++) Axe[i] = coord(i,1) - coord(i,2);
176  for(i = 0; i < 3; i++)
177  {
178  for(j = 0; j < 3; j++) Temp[i] += fICnBase(i,j)*Axe[j];
179  }
180  xb = Temp[0]; yb = Temp[1];
181 
182  fAngle = ArcAngle(coord,xa, ya, xb, yb);
183 }
184 
187 double TPZArc3D::ArcAngle(TPZFMatrix<REAL> &coord, double xa, double ya, double xb, double yb) const
188 {
189  REAL Xcenter, Ycenter, arcAngle, sinBig, cosBig;
190 
192  Xcenter = xa/2.;
193  Ycenter = (-xa*xb + xb*xb + yb*yb) / (2.*yb);
194 
195  cosBig = (xb-Xcenter)*(xa-Xcenter)+(yb-Ycenter)*(ya-Ycenter);
196  sinBig = (xa-Xcenter)*(yb-Ycenter)-(xb-Xcenter)*(ya-Ycenter);
197  arcAngle = -atan2(sinBig, cosBig);
198 
199  REAL cosMid = (0.-Xcenter)*(xa-Xcenter)+(0.-Ycenter)*(0.-Ycenter);
200  REAL sinMid = (xa-Xcenter)*(0.-Ycenter)-(0.-Xcenter)*(ya-Ycenter);
201  REAL arcMid = -atan2(sinMid, cosMid);
202 
203  if (0. <= arcMid && arcMid <= arcAngle) {
204  return arcAngle;
205  }
206  if (arcMid <= 0. && arcAngle <= arcMid)
207  {
208  return arcAngle;
209  }
210  if (arcAngle > 0) {
211  arcAngle -= 2.*M_PI;
212  }
213  else
214  {
215  arcAngle += 2.*M_PI;
216  }
217 #ifdef PZDEBUG
218  if(arcAngle < 0.) DebugStop();
220 #endif
221  return arcAngle;
222 
223  //old code (still here until above code be totally validated)
224  REAL cos, Angle1, Angle2, Angle3;
225 
227  cos = (-((xa - Xcenter)*Xcenter) - (ya - Ycenter)*Ycenter) /
228  (sqrt((xa - Xcenter)*(xa - Xcenter) + (ya - Ycenter)*(ya - Ycenter))*sqrt(Xcenter*Xcenter + Ycenter*Ycenter));
229  Angle1 = acos(cos);
230 
232  cos = (-((xb - Xcenter)*Xcenter) - (yb - Ycenter)*Ycenter) /
233  (sqrt((xb - Xcenter)*(xb - Xcenter) + (yb - Ycenter)*(yb - Ycenter))*sqrt(Xcenter*Xcenter + Ycenter*Ycenter));
234  Angle2 = acos(cos);
235 
237  cos = ((xa - Xcenter)*(xb - Xcenter) + (ya - Ycenter)*(yb - Ycenter)) /
238  (sqrt((xa - Xcenter)*(xa - Xcenter) + (ya - Ycenter)*(ya - Ycenter))*sqrt((xb - Xcenter)*(xb - Xcenter) + (yb - Ycenter)*(yb - Ycenter)));
239  Angle3 = acos(cos);
240 
244  if( fabs(Angle3/(Angle1 + Angle2)) >= 1. )
245  {
246  arcAngle = Angle3;
247  }
248  else
249  {
250  arcAngle = (2.*M_PI - Angle3);
251  }
252 
253  return arcAngle;
254 }
255 
256 
257 //void TPZArc3D::Jacobian(TPZFMatrix<REAL> &coord, TPZVec<REAL> &par, TPZFMatrix<REAL> &jacobian, TPZFMatrix<REAL> &axes, REAL &detjac, TPZFMatrix<REAL> &jacinv) const
258 //{
259 // jacobian.Resize(1,1); axes.Resize(1,3); jacinv.Resize(1,1);
260 // jacobian(0,0) = fAngle * fRadius/2.; jacinv(0,0) = 1./jacobian(0,0); detjac = jacobian(0,0);
261 //
262 // /** Computing Axes */
263 // TPZManVector< REAL > Vpc(3), Vpa(3), Vpb(3), Vt(3), OUTv(3);
264 //
265 // TPZManVector< REAL > middle(1, 0.);
266 // X(coord,middle,OUTv);
267 //
268 // /** Vector From MappedPoint to Ini */
269 // Vpa[0] = coord(0,0) - OUTv[0]; Vpa[1] = coord(1,0) - OUTv[1]; Vpa[2] = coord(2,0) - OUTv[2];
270 //
271 // /** Vector From MappedPoint to Fin */
272 // Vpb[0] = coord(0,1) - OUTv[0]; Vpb[1] = coord(1,1) - OUTv[1]; Vpb[2] = coord(2,1) - OUTv[2];
273 //
274 // X(coord,par,OUTv);
275 //
276 // /** Vector From MappedPoint to Center */
277 // Vpc[0] = fCenter3D[0] - OUTv[0]; Vpc[1] = fCenter3D[1] - OUTv[1]; Vpc[2] = fCenter3D[2] - OUTv[2];
278 //
279 // /** Tangent Vector From Point in the Arc */
280 // Vt[0] = Vpa[1]*Vpb[0]*Vpc[1] - Vpa[0]*Vpb[1]*Vpc[1] + Vpa[2]*Vpb[0]*Vpc[2] - Vpa[0]*Vpb[2]*Vpc[2];
281 // Vt[1] = -Vpa[1]*Vpb[0]*Vpc[0] + Vpa[0]*Vpb[1]*Vpc[0] + Vpa[2]*Vpb[1]*Vpc[2] - Vpa[1]*Vpb[2]*Vpc[2];
282 // Vt[2] = -Vpa[2]*Vpb[0]*Vpc[0] + Vpa[0]*Vpb[2]*Vpc[0] - Vpa[2]*Vpb[1]*Vpc[1] + Vpa[1]*Vpb[2]*Vpc[1];
283 //
284 // double Vtnorm = 0.;
285 // for(int i = 0; i < 3; i++)
286 // {
287 // if( fabs(Vt[i]) < 1.E-12 ) Vt[i] = 0.;
288 // Vtnorm += Vt[i]*Vt[i];
289 // }
290 // if(Vtnorm < 0.) DebugStop();
291 // if(sqrt(Vtnorm) < 1e-16) DebugStop();
292 // for(int j = 0; j < 3; j++) axes(0,j) = Vt[j]/sqrt(Vtnorm);
293 //}
294 //
295 
296 // TPZGeoEl *TPZArc3D::CreateBCGeoEl(TPZGeoEl *orig, int side,int bc)
297 // {
298 // if(side==2)
299 // {
300 // TPZManVector<int64_t> nodes(3);
301 // nodes[0] = orig->SideNodeIndex(side,0); nodes[1] = orig->SideNodeIndex(side,1); nodes[2] = orig->SideNodeIndex(side,2);
302 // int64_t index;
303 // // this is wrong : it should either create a blend element or an arc3d element
304 // DebugStop();
305 // TPZGeoEl *gel = orig->Mesh()->CreateGeoElement(EOned,nodes,bc,index);
306 // TPZGeoElSide(gel,0).SetConnectivity(TPZGeoElSide(orig,TPZShapeLinear::ContainedSideLocId(side,0)));
307 // TPZGeoElSide(gel,1).SetConnectivity(TPZGeoElSide(orig,TPZShapeLinear::ContainedSideLocId(side,1)));
308 // TPZGeoElSide(gel,2).SetConnectivity(TPZGeoElSide(orig,side));
309 // return gel;
310 // }
311 
312 // else if(side==0 || side==1)
313 // {
314 // TPZManVector<int64_t> nodeindexes(1);
315 // nodeindexes[0] = orig->SideNodeIndex(side,0);
316 // int64_t index;
317 // TPZGeoEl *gel = orig->Mesh()->CreateGeoElement(EPoint,nodeindexes,bc,index);
318 // TPZGeoElSide(gel,0).SetConnectivity(TPZGeoElSide(orig,side));
319 // return gel;
320 // }
321 
322 // else PZError << "\nTPZGeoLinear::CreateBCGeoEl. Side = " << side << endl;
323 // return 0;
324 // }
325 
326 
331 // TPZGeoEl *TPZArc3D::CreateGeoElement(TPZGeoMesh &mesh, MElementType type,
332 // TPZVec<int64_t>& nodeindexes,
333 // int matid,
334 // int64_t& index)
335 // {
336 // return CreateGeoElementMapped(mesh,type,nodeindexes,matid,index);
337 // }
338 
339 void TPZArc3D::InsertExampleElement(TPZGeoMesh &gmesh, int matid, TPZVec<REAL> &lowercorner, TPZVec<REAL> &size)
340 {
341  REAL coords[3][3] = {
342  {1,0,0},
343  {0,1,0},
344  {M_SQRT1_2,M_SQRT1_2,0}
345  };
346  size[0] = 1.;
347  size[1] = 1.;
348 
349  TPZManVector<int64_t,3> indexes(3);
350  for (int i=0; i<3; i++) {
351  TPZManVector<REAL,3> cods(3,0.);
352  for (int j=0; j<3; j++) {
353  cods[j] = lowercorner[j]+coords[i][j];
354  }
355  indexes[i] = gmesh.NodeVec().AllocateNewElement();
356  gmesh.NodeVec()[indexes[i]].Initialize(cods, gmesh);
357  }
358  TPZGeoElRefPattern<TPZArc3D> *gel = new TPZGeoElRefPattern<TPZArc3D>(indexes,matid,gmesh);
359 // gel->Geom().Initialize(gel);
360 }
361 
362 //void TPZArc3D::ParametricDomainNodeCoord(int node, TPZVec<REAL> &nodeCoord)
363 //{
364 // if(node > this->NNodes)
365 // {
366 // DebugStop();
367 // }
368 // nodeCoord.Resize(Dimension, 0.);
369 // switch (node) {
370 // case (0):
371 // {
372 // nodeCoord[0] = -1.;
373 // break;
374 // }
375 // case (1):
376 // {
377 // nodeCoord[0] = 1.;
378 // break;
379 // }
380 // case (2):
381 // {
382 // nodeCoord[0] = 0.;
383 // break;
384 // }
385 // default:
386 // {
387 // DebugStop();
388 // break;
389 // }
390 // }
391 //}
392 
393 int TPZArc3D::ClassId() const{
394  return Hash("TPZArc3D") ^ pzgeom::TPZNodeRep<3,pztopology::TPZLine>::ClassId() << 1;
395 }
396 template class
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
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
int AllocateNewElement()
Makes more room for new elements.
Definition: pzadmchunk.h:184
Implements a vector class which allows to use external storage provided by the user. Utility.
Definition: pzquad.h:16
void GramSchmidt(TPZFMatrix< TVar > &Orthog, TPZFMatrix< TVar > &TransfToOrthog)
This method implements a Gram Schimidt method. this = Orthog.TransfToOrthog.
Definition: pzfmatrix.cpp:341
Contains declaration of TPZGeoNode class which defines a geometrical node.
Templated vector implementation.
groups all classes dedicated to the computation of shape functions
Definition: pzshapeextend.h:16
Contains TPZShapeLinear class which implements the shape functions of a linear one-dimensional elemen...
Contains declaration of TPZGeoElMapped class which implements a geometric element using its ancestral...
expr_ expr_ expr_ expr_ acos
Definition: tfadfunc.h:75
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
Groups all classes defining the structure of the master element.
Definition: PrismExtend.cpp:15
Implements a generic geometric element which is refined according to a generic refinement pattern...
Definition: pzgmesh.h:35
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
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
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
Contains the TPZNodeRep class which implements ... Clase intermediaria que guarda.
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
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
Contains the TPZArc3D class which implements three dimensional arc.
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
void Fill(const T &copy, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Definition: pzvec.h:460
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
Extra utilities for TPZVec. Implementations of the saxpy, sscal, sdot, intercept, max and min functio...
Groups all classes which model the geometry.
Definition: pzgeopoint.cpp:18
TPZFlopCounter cos(const TPZFlopCounter &orig)
Returns the cosine in radians and increments the counter of the Cosine.
Definition: pzreal.h:514
int ClassId() const override
Definition: pznoderep.h:151
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150