NeoPZ
pzgeotriangle.cpp
Go to the documentation of this file.
1 
6 #include "pzgeotriangle.h"
7 #include "pzfmatrix.h"
8 #include "pzgeoel.h"
9 #include "pzshapetriang.h"
10 #include "pzgmesh.h"
11 #include "tpzgeoelrefpattern.h"
12 
13 #include "pzlog.h"
14 #ifdef _AUTODIFF
15 #include "fad.h"
16 #endif
17 
18 #ifdef LOG4CXX
19 static log4cxx::LoggerPtr logger(Logger::getLogger("pz.geom.pzgeotriangle"));
20 #endif
21 
22 using namespace pzshape;
23 using namespace std;
24 
25 namespace pzgeom {
26 
27  const REAL tol = pzgeom_TPZNodeRep_tol;
28 
29 
30  void TPZGeoTriangle::Jacobian(const TPZFMatrix<REAL> & coord, TPZVec<REAL> &param,TPZFMatrix<REAL> &jacobian,TPZFMatrix<REAL> &axes,REAL &detjac,TPZFMatrix<REAL> &jacinv){
31 
32  int spacedim = coord.Rows();
33  jacobian.Resize(2,2); axes.Resize(2,3); jacinv.Resize(2,2);
34  TPZFNMatrix<3> phi(3,1);
35  TPZFNMatrix<6> dphi(2,3),axest(3,2);
36  jacobian.Zero();
37  Shape(param,phi,dphi);
38  TPZFNMatrix<6> VecMatrix(3,2,0.);
39  for(int i = 0; i < 3; i++) {
40  for(int j = 0; j < spacedim; j++) {
41  VecMatrix(j,0) += coord.GetVal(j,i)*dphi(0,i);
42  VecMatrix(j,1) += coord.GetVal(j,i)*dphi(1,i);
43  }
44  }
45  VecMatrix.GramSchmidt(axest,jacobian);
46  axest.Transpose(&axes);
47  detjac = jacobian(0,0)*jacobian(1,1)-jacobian(1,0)*jacobian(0,1);
48  REAL maxjac = 0.;
49  for (int i=0; i<2; i++) {
50  for (int j=0; j<2; j++) {
51  maxjac = Max(maxjac,fabs(jacobian(i,j)));
52  }
53  }
54  if(IsZero(maxjac) || IsZero(detjac/(maxjac*maxjac)))
55  {
56 #ifdef PZDEBUG
57  std::stringstream sout;
58  sout << "Singular Jacobian " << detjac;
59  LOGPZ_ERROR(logger, sout.str())
60 #endif
61  detjac = ZeroTolerance();
62  }
63 
64  jacinv(0,0) = jacobian(1,1)/detjac;
65  jacinv(1,1) = jacobian(0,0)/detjac;
66  jacinv(0,1) = -jacobian(0,1)/detjac;
67  jacinv(1,0) = -jacobian(1,0)/detjac;
68  }
69 
70 
71  void TPZGeoTriangle::VectorialProduct(TPZVec<REAL> &v1, TPZVec<REAL> &v2,TPZVec<REAL> &result){
72  if(v1.NElements()!=3||v2.NElements()!=3)
73  {
74  cout << " o tamanho do vetores eh diferente de 3"<< endl;
75  }
76  REAL x1=v1[0], y1=v1[1],z1=v1[2];
77  REAL x2=v2[0], y2=v2[1],z2=v2[2];
78  result.Resize(v1.NElements());
79  result[0]=y1*z2-z1*y2;
80  result[1]=z1*x2-x1*z2;
81  result[2]=x1*y2-y1*x2;
82  }
83 
84  void TPZGeoTriangle::ComputeNormal(TPZVec<REAL> &p1, TPZVec<REAL> &p2,TPZVec<REAL> &p3,TPZVec<REAL> &result){
85  TPZVec<REAL> v1(3);
86  TPZVec<REAL> v2(3);
87  TPZVec<REAL> normal(3);
88  v1[0]=p1[0]-p2[0];
89  v1[1]=p1[1]-p2[1];
90  v1[2]=p1[2]-p2[2];
91  v2[0]=p2[0]-p3[0];
92  v2[1]=p2[1]-p3[1];
93  v2[2]=p2[2]-p3[2];
94  VectorialProduct(v1,v2,normal);
95  VectorialProduct(v1,normal,result);
96  }
97 
98  // TPZGeoEl *TPZGeoTriangle::CreateBCGeoEl(TPZGeoEl *orig,int side,int bc) {
99  // if(side==6) {
100  // TPZManVector<int64_t> nodes(3);
101  // int i;
102  // for (i=0;i<3;i++){
103  // nodes[i] = orig->SideNodeIndex(side,i);
104  // }
105  // int64_t index;
106  // TPZGeoEl *gel = orig->Mesh()->CreateGeoElement(ETriangle,nodes,bc,index);
107  // int iside;
108  // for (iside = 0; iside <6; iside++){
109  // TPZGeoElSide(gel,iside).SetConnectivity(TPZGeoElSide(orig,TPZShapeTriang::ContainedSideLocId(side,iside)));
110  // }
111  // TPZGeoElSide(gel,6).SetConnectivity(TPZGeoElSide(orig,side));
112  // return gel;
113  // }
114  // else if(side>-1 && side<3) {
115  // TPZManVector<int64_t> nodeindexes(1);
116  // nodeindexes[0] = orig->SideNodeIndex(side,0);
117  // int64_t index;
118  // TPZGeoEl *gel = orig->CreateGeoElement(EPoint,nodeindexes,bc,index);
119  // TPZGeoElSide(gel,0).SetConnectivity(TPZGeoElSide(orig,side));
120  // return gel;
121  // }
122  // else if(side > 2 && side < 6) {
123  // TPZManVector<int64_t> nodes(2);
124  // nodes[0] = orig->SideNodeIndex(side,0);
125  // nodes[1] = orig->SideNodeIndex(side,1);
126  // int64_t index;
127  // TPZGeoEl *gel = orig->CreateGeoElement(EOned,nodes,bc,index);
128  // TPZGeoElSide(gel,0).SetConnectivity(TPZGeoElSide(orig,TPZShapeTriang::ContainedSideLocId(side,0)));
129  // TPZGeoElSide(gel,1).SetConnectivity(TPZGeoElSide(orig,TPZShapeTriang::ContainedSideLocId(side,1)));
130  // TPZGeoElSide(gel,2).SetConnectivity(TPZGeoElSide(orig,side));
131  // return gel;
132  // }
133  // else PZError << "TPZGeoTriangle::CreateBCGeoEl has no bc.\n";
134  // return 0;
135  // }
136 
138  // TPZGeoEl *TPZGeoTriangle::CreateGeoElement(TPZGeoMesh &mesh, MElementType type,
139  // TPZVec<int64_t>& nodeindexes,
140  // int matid,
141  // int64_t& index)
142  // {
143  // return CreateGeoElementPattern(mesh,type,nodeindexes,matid,index);
144  // }
145 
147  /* @param gmesh mesh in which the element should be inserted
148  @param matid material id of the element
149  @param lowercorner (in/out) on input lower corner o the cube where the element should be created, on exit position of the next cube
150  @param size (in) size of space where the element should be created
151  */
152  void TPZGeoTriangle::InsertExampleElement(TPZGeoMesh &gmesh, int matid, TPZVec<REAL> &lowercorner, TPZVec<REAL> &size)
153  {
154  TPZManVector<REAL,3> co(3),shift(3),scale(3);
155  TPZManVector<int64_t,3> nodeindexes(3);
156  for (int i=0; i<3; i++) {
157  scale[i] = size[i]/3.;
158  shift[i] = 1./2.+lowercorner[i];
159  }
160 
161  for (int i=0; i<NCornerNodes; i++) {
162  ParametricDomainNodeCoord(i, co);
163  for (int j=0; j<co.size(); j++) {
164  co[j] = shift[j]+scale[j]*co[j]+(rand()*0.2/RAND_MAX)-0.1;
165  }
166  nodeindexes[i] = gmesh.NodeVec().AllocateNewElement();
167  gmesh.NodeVec()[nodeindexes[i]].Initialize(co, gmesh);
168  }
169  int64_t index;
170  gmesh.CreateGeoElement(ETriangle, nodeindexes, matid, index);
171  }
172 
173  int TPZGeoTriangle::ClassId() const{
174  return Hash("TPZGeoTriangle") ^ TPZNodeRep<3, pztopology::TPZTriangle>::ClassId() << 1;
175  }
176 
177  void TPZGeoTriangle::Read(TPZStream& buf, void* context) {
179  }
180 
181  void TPZGeoTriangle::Write(TPZStream& buf, int withclassid) const {
183  }
184 
185 
186 
187 
188 };
189 
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
bool IsZero(long double a)
Returns if the value a is close Zero as the allowable tolerance.
Definition: pzreal.h:668
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
void GramSchmidt(TPZFMatrix< TVar > &Orthog, TPZFMatrix< TVar > &TransfToOrthog)
This method implements a Gram Schimidt method. this = Orthog.TransfToOrthog.
Definition: pzfmatrix.cpp:341
virtual TPZGeoEl * CreateGeoElement(MElementType type, TPZVec< int64_t > &cornerindexes, int matid, int64_t &index, int reftype=1)
Generic method for creating a geometric element. Putting this method centrally facilitates the modifi...
Definition: pzgmesh.cpp:1296
groups all classes dedicated to the computation of shape functions
Definition: pzshapeextend.h:16
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
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
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
static const double tol
Definition: pzgeoprism.cpp:23
const T & Max(const T &a, const T &b)
Returns the maximum value between a and b.
Definition: pzreal.h:724
Contains TPZMatrixclass which implements full matrix (using column major representation).
const double pzgeom_TPZNodeRep_tol
Initializing tolerance to TPZNodeRep.
Definition: pznoderep.h:32
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
void Shape(TPZVec< REAL > &pt, TPZVec< int > orders, TPZVec< TPZTransform< REAL > > &transvec, TPZFMatrix< REAL > &phi, TPZFMatrix< REAL > &dphi)
Contains declaration of TPZGeoElRefPattern class which implements a generic geometric element which i...
REAL co[8][3]
Coordinates of the eight nodes.
#define LOGPZ_ERROR(A, B)
Define log for errors (cout)
Definition: pzlog.h:93
Implements ... Geometry Topology.
Definition: pznoderep.h:40
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
Definition: pzfmatrix.cpp:1016
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
Groups all classes which model the geometry.
Definition: pzgeopoint.cpp:18
REAL ZeroTolerance()
Returns the tolerance to Zero value. Actually: .
Definition: pzreal.h:633
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
Contains TPZShapeTriang class which implements the shape functions of a triangular element...
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716