NeoPZ
pzgeom_utility.h
Go to the documentation of this file.
1 //
2 // pzgeom_utility.h
3 // AcoplamentoH1Hdiv
4 //
5 // Created by Philippe Devloo on 31/08/19.
6 //
7 
8 #ifndef pzgeom_utility_h
9 #define pzgeom_utility_h
10 
11 #include <stdio.h>
12 class TPZGeoMesh;
13 class TPZGeoElSide;
14 #include "pzgeoel.h"
15 #include "pzgnode.h"
16 
17 #include "tpzpoint.h"
18 #include "tpzline.h"
19 #include "tpztriangle.h"
20 #include "tpzquadrilateral.h"
21 #include "tpzpyramid.h"
22 #include "tpztetrahedron.h"
23 #include "tpzcube.h"
24 #include "tpzprism.h"
25 
26 #include "TPZGeoLinear.h"
27 #include "pzgeoquad.h"
28 #include "pzgeotriangle.h"
29 #include "pzgeopoint.h"
30 #include "pzgeoprism.h"
31 #include "TPZGeoCube.h"
32 #include "pzgeotetrahedra.h"
33 #include "pzgeopyramid.h"
34 
35 
37 template<class Topology>
38 bool IsInSideParametricDomain(int side, const TPZVec<REAL> &pt, REAL tol);
39 
40 //#ifdef _AUTODIFF
41 //template<typename T,
42 //typename std::enable_if<std::is_same<T,Fad<REAL>>::value>::type* = nullptr>
43 //inline bool IsInSideParametricDomain(int side, const TPZVec<T> &pt, REAL tol){
44 // TPZVec<REAL> qsiReal(pt.size(),-1);
45 // for(int i = 0; i < qsiReal.size(); i++) qsiReal[i] = pt[i].val();
46 // return IsInSideParametricDomain(side,qsiReal,tol);
47 //}
48 //#endif
49 
50 
51 //template<class Topology, class T>
52 //void GetSideShapeFunction(int side, TPZVec<T> &qsiSide, TPZFMatrix<T> &phi,TPZFMatrix<T> &dphi );
53 
54 
61 template<class Topology>
63  const int nsides = Topology::NSides;
64  if(Topology::IsInParametricDomain(qsi,0.)){
65  qsiInDomain = qsi;
66  return nsides-1;
67  }//if
68 
69  int winnerSide = -1;
70  REAL winnerDistance = 1e12;
71  TPZManVector<REAL,3> pt1(qsi.NElements()), pt2(qsi.NElements());
72  for(int is = 0; is < nsides-1; is++){
73 
75  TPZTransform<> T1 = Topology::SideToSideTransform(nsides-1, is);
76  pt1.Resize(Topology::SideDimension(is));
77  T1.Apply(qsi,pt1);
78 
80  bool IsInSideDomain = IsInSideParametricDomain<Topology>(is,pt1,0.);
81  if(!IsInSideDomain) continue;
82 
84  TPZTransform<> T2 = Topology::SideToSideTransform(is,nsides-1);
85  T2.Apply(pt1,pt2);
86 
88  REAL distance = 0.;
89  for(int i = 0; i < qsi.NElements(); i++){
90  REAL val = qsi[i]-pt2[i];
91  distance += val*val;
92  }//i
93  distance = sqrt(distance);
94 
96  if(distance < winnerDistance){
97  winnerDistance = distance;
98  winnerSide = is;
99  qsiInDomain = pt2;
100  }
101  }//for is
102 
103  return winnerSide;
104 
105 }//method
106 
107 // project the point towards the center of the element
108 // find the intersecting side
109 template<class Topology>
111  const int nsides = Topology::NSides;
112  const int dim = Topology::Dimension;
113 
114  qsiInDomain.Resize(dim);
115 
116  if(Topology::IsInParametricDomain(qsi,0.))
117  {
118  qsiInDomain = qsi;
119  return nsides-1;
120  }
121 
122  REAL tol = 1.e-10;
123 
125  TPZVec<REAL> OutPt(qsi), InnPt(dim);
126  Topology::CenterPoint(nsides-1,InnPt);
127 
128  REAL dist = 0.;
129  for(int c = 0; c < dim; c++)
130  {
131  dist += (InnPt[c] - OutPt[c])*(InnPt[c] - OutPt[c]);
132  }
133  dist = sqrt(dist);
134 
135  while(dist > tol)
136  {
137  for(int c = 0; c < dim; c++)
138  {
139  qsiInDomain[c] = (InnPt[c] + OutPt[c])/2.;
140  }
141  if(Topology::IsInParametricDomain(qsiInDomain,0.))
142  {
143  InnPt = qsiInDomain;
144  }
145  else
146  {
147  OutPt = qsiInDomain;
148  }
149  dist = 0.;
150  for(int c = 0; c < dim; c++)
151  {
152  dist += (InnPt[c] - OutPt[c])*(InnPt[c] - OutPt[c]);
153  }
154  dist = sqrt(dist);
155  }
156 
158  int winnerSide = -1;
159  TPZManVector<REAL,3> pt1(dim), pt2(dim);
160  for(int is = 0; is < nsides-1; is++)
161  {
163  TPZTransform<> T1 = Topology::SideToSideTransform(nsides-1, is);
164  T1.Apply(qsiInDomain,pt1);
165 
167  TPZTransform<> T2 = Topology::SideToSideTransform(is,nsides-1);
168  T2.Apply(pt1,pt2);
169 
171  dist = 0.;
172  for(int c = 0; c < dim; c++)
173  {
174  dist += (qsiInDomain[c]-pt2[c]) * (qsiInDomain[c]-pt2[c]);
175  }//i
176  dist = sqrt(dist);
177 
179  if(dist < tol)
180  {
181  winnerSide = is;
182  qsiInDomain = pt2;
183  break;
184  }
185  }//for is
186 
187  return winnerSide;
188 
189 }//method
190 
191 #ifdef _AUTODIFF
192 
193 template<class Topology>
194 inline void GetSideShapeFunction(int side, TPZVec<Fad<REAL> > &qsiSide, TPZFMatrix<Fad<REAL> > &phi,TPZFMatrix<Fad<REAL> > &dphi ){
195  MElementType sideType = Topology::Type(side);
196 #ifdef PZDEBUG
197  std::stringstream sout;
198  REAL tol = 1e-12;
199  TPZManVector<REAL,3> qsi(qsiSide.size());
200  for (int i=0; i<qsi.size(); i++) {
201  qsi[i] = qsiSide[i].val();
202  }
203  if(!IsInSideParametricDomain<Topology>(side,qsi,tol)){
204  sout<<"The method expects the coordinates in the side's parametric domain. Exiting..."<<std::endl;
205  PZError << "\n" << sout.str() << "\n";
206  DebugStop();
207  }
208 #endif
209  switch (sideType){
210  case EPoint:
211  return pzgeom::TPZGeoPoint::TShape(qsiSide,phi,dphi);
212  case EOned:
213  return pzgeom::TPZGeoLinear::TShape(qsiSide,phi,dphi);
214  case ETriangle:
215  return pzgeom::TPZGeoTriangle::TShape(qsiSide,phi,dphi);
216  case EQuadrilateral:
217  return pzgeom::TPZGeoQuad::TShape(qsiSide,phi,dphi);
218  case ETetraedro:
219  return pzgeom::TPZGeoTetrahedra::TShape(qsiSide,phi,dphi);
220  case EPiramide:
221  return pzgeom::TPZGeoPyramid::TShape(qsiSide,phi,dphi);
222  case EPrisma:
223  return pzgeom::TPZGeoPrism::TShape(qsiSide,phi,dphi);
224  case ECube:
225  return pzgeom::TPZGeoCube::TShape(qsiSide,phi,dphi);
226  default:{
227  std::stringstream sout;
228  sout<<"Could not find associated shape function to the side. Details are as follows:"<<std::endl;
229  sout<<"Element is of type "<<MElementType_Name(Topology::Type())<<std::endl;
230  sout<<"Side\t"<<side<<" is of type\t"<< MElementType_Name(sideType)<<std::endl;
231  PZError<<std::endl<<sout.str()<<std::endl;
232  DebugStop();
233  }
234  }
235 }
236 #endif
237 
238 template<class Topology>
239 inline void GetSideShapeFunction(int side, TPZVec<REAL> &qsiSide, TPZFMatrix<REAL> &phi,TPZFMatrix<REAL> &dphi ){
240  MElementType sideType = Topology::Type(side);
241 #ifdef PZDEBUG
242  std::stringstream sout;
243  REAL tol = pztopology::GetTolerance();
244  if(!IsInSideParametricDomain<Topology>(side,qsiSide,tol)){
245  sout<<"The method expects the coordinates in the side's parametric domain. Exiting..."<<std::endl;
246  DebugStop();
247  }
248 #endif
249  switch (sideType){
250  case EPoint:
251  return pzgeom::TPZGeoPoint::TShape(qsiSide,phi,dphi);
252  case EOned:
253  return pzgeom::TPZGeoLinear::TShape(qsiSide,phi,dphi);
254  case ETriangle:
255  return pzgeom::TPZGeoTriangle::TShape(qsiSide,phi,dphi);
256  case EQuadrilateral:
257  return pzgeom::TPZGeoQuad::TShape(qsiSide,phi,dphi);
258  case ETetraedro:
259  return pzgeom::TPZGeoTetrahedra::TShape(qsiSide,phi,dphi);
260  case EPiramide:
261  return pzgeom::TPZGeoPyramid::TShape(qsiSide,phi,dphi);
262  case EPrisma:
263  return pzgeom::TPZGeoPrism::TShape(qsiSide,phi,dphi);
264  case ECube:
265  return pzgeom::TPZGeoCube::TShape(qsiSide,phi,dphi);
266  default:{
267  std::stringstream sout;
268  sout<<"Could not find associated shape function to the side. Details are as follows:"<<std::endl;
269  sout<<"Element is of type "<<MElementType_Name(Topology::Type())<<std::endl;
270  sout<<"Side\t"<<side<<" is of type\t"<< MElementType_Name(sideType)<<std::endl;
271  PZError<<std::endl<<sout.str()<<std::endl;
272  DebugStop();
273  }
274  }
275 }
276 
277 template<class Topology>
278 inline bool IsInSideParametricDomain(int side, const TPZVec<REAL> &pt, REAL tol){
279  MElementType type = Topology::Type(side);
280  switch(type){
281  case EPoint:
283  case EOned:
285  case ETriangle:
287  case EQuadrilateral:
289 
290  case ETetraedro:
292 
293  case EPiramide:
295 
296  case EPrisma:
298 
299  case ECube:
301 
302  default:
303  std::stringstream sout;
304  sout << "Fatal error at " << __PRETTY_FUNCTION__ << " - Element type " << type << " not found";
305  PZError << "\n" << sout.str() << "\n";
306  DebugStop();
307  return false;
308  break;
309  }//case
310 
311  return false;
312 }//method
313 
314 
315 #endif /* pzgeom_utility_h */
static bool IsInParametricDomain(const TPZVec< REAL > &pt, REAL tol=pztopology::gTolerance)
Verifies if the parametric point pt is in the element parametric domain.
static void TShape(const TPZVec< T > &loc, TPZFMatrix< T > &phi, TPZFMatrix< T > &dphi)
Compute the shape being used to construct the x mapping from local parametric coordinates.
Definition: tpzpoint.cpp:19
static bool IsInParametricDomain(const TPZVec< REAL > &pt, REAL tol=pztopology::gTolerance)
Verifies if the parametric point pt is in the element parametric domain.
Definition: tpzprism.cpp:991
static bool IsInParametricDomain(const TPZVec< REAL > &pt, REAL tol=pztopology::gTolerance)
Verifies if the parametric point pt is in the element parametric domain.
static bool IsInParametricDomain(const TPZVec< REAL > &pt, REAL tol=pztopology::gTolerance)
Verifies if the parametric point pt is in the element parametric domain.
Definition: tpzpyramid.cpp:952
static void TShape(const TPZVec< T > &loc, TPZFMatrix< T > &phi, TPZFMatrix< T > &dphi)
Compute the shape being used to construct the x mapping from local parametric coordinates.
Definition: tpztriangle.cpp:27
Contains declaration of TPZGeoNode class which defines a geometrical node.
static bool IsInParametricDomain(const TPZVec< REAL > &pt, REAL tol=pztopology::gTolerance)
Verifies if the parametric point pt is in the element parametric domain.
Definition: tpzline.cpp:154
int ProjectInParametricDomain(TPZVec< REAL > &qsi, TPZVec< REAL > &qsiInDomain)
Projects point pt (in parametric coordinate system) in the element parametric domain.
Contains the TPZPoint class which defines the topology of a point.
std::string MElementType_Name(MElementType elType)
Returns the name of the element type.
Definition: pzeltype.h:127
Utility class which represents an element with its side. The Geometric approximation classes Geometry...
Definition: pzgeoelside.h:83
Definition: fad.h:54
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
Contains the TPZTriangle class which defines the topology of a triangle.
Contains the TPZTetrahedron class which defines the topology of the tetrahedron element.
int ProjectBissectionInParametricDomain(TPZVec< REAL > &qsi, TPZVec< REAL > &qsiInDomain)
static void TShape(const TPZVec< T > &loc, TPZFMatrix< T > &phi, TPZFMatrix< T > &dphi)
Compute the shape being used to construct the x mapping from local parametric coordinates.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Definition: pzvec.h:373
static const double tol
Definition: pzgeoprism.cpp:23
Contains the TPZGeoTetrahedra class which implements the geometry of a tetrahedral element...
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
Contains the TPZQuadrilateral class which defines the topology of a quadrilateral element...
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 TShape(const TPZVec< T > &loc, TPZFMatrix< T > &phi, TPZFMatrix< T > &dphi)
Compute the shape being used to construct the x mapping from local parametric coordinates.
Definition: tpzprism.cpp:348
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
static void TShape(const TPZVec< T > &loc, TPZFMatrix< T > &phi, TPZFMatrix< T > &dphi)
Compute the shape being used to construct the x mapping from local parametric coordinates.
Definition: tpzcube.cpp:429
Contains the TPZGeoCube class which implements the geometry of hexahedra element. ...
Contains the TPZPyramid class which defines the topology of a pyramid element.
Contains the TPZGeoPoint class which implements the geometry of a point element or 0-D element...
static bool IsInParametricDomain(const TPZVec< REAL > &pt, REAL tol=pztopology::gTolerance)
Verifies if the parametric point pt is in the element parametric domain.
Definition: tpzcube.cpp:1000
static void TShape(const TPZVec< T > &loc, TPZFMatrix< T > &phi, TPZFMatrix< T > &dphi)
Compute the shape being used to construct the x mapping from local parametric coordinates.
Definition: tpzline.cpp:69
REAL dist(TPZVec< T1 > &vec1, TPZVec< T1 > &vec2)
Definition: pzvec_extras.h:124
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
MElementType
Define the element types.
Definition: pzeltype.h:52
void GetSideShapeFunction(int side, TPZVec< REAL > &qsiSide, TPZFMatrix< REAL > &phi, TPZFMatrix< REAL > &dphi)
static void TShape(const TPZVec< T > &loc, TPZFMatrix< T > &phi, TPZFMatrix< T > &dphi)
Compute the shape being used to construct the x mapping from local parametric coordinates.
Definition: pzeltype.h:61
static void TShape(const TPZVec< T > &loc, TPZFMatrix< T > &phi, TPZFMatrix< T > &dphi)
Compute the shape being used to construct the x mapping from local parametric coordinates.
Definition: tpzpyramid.cpp:302
static bool IsInParametricDomain(const TPZVec< REAL > &pt, REAL tol=pztopology::gTolerance)
Verifies if the parametric point pt is in the element parametric domain.
Contains the TPZGeoPyramid class which implements the geometry of pyramid element.
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
Implements an affine transformation between points in parameter space. Topology Utility.
Definition: pzmganalysis.h:14
static bool IsInParametricDomain(const TPZVec< REAL > &pt, REAL tol=1e-6)
Verifies if the parametric point pt is in the element parametric domain.
Definition: tpzpoint.h:127
Contains the TPZGeoPrism class which implements the geometry of a prism element.
Contains the TPZCube class which defines the topology of the hexahedron element.
Contains the TPZLine class which defines the topology of a line element.
Definition: pzeltype.h:55
Contains the TPZPrism class which defines the topology of a Prism.
void Apply(TPZVec< T > &vectorin, TPZVec< T > &vectorout)
Transforms the vector.
Definition: pztrnsform.cpp:121
bool IsInSideParametricDomain(int side, const TPZVec< REAL > &pt, REAL tol)
Verifies if pt (in parametric domain of the side) is within boundaries.
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15