NeoPZ
tpzquadratictetra.cpp
Go to the documentation of this file.
1 
5 #include "tpzquadratictetra.h"
6 #include "pzshapetetra.h"
7 #include "tpzgeoelmapped.h"
8 
9 #include "pzlog.h"
10 
11 #include "tpzgeomid.h"
12 
13 #ifdef LOG4CXX
14 static LoggerPtr logger(Logger::getLogger("pz.specialmaps.quadratictetra"));
15 #endif
16 
17 #ifdef _AUTODIFF
18 #include "fad.h"
19 #endif
20 
21 using namespace pzgeom;
22 using namespace pztopology;
23 using namespace pzshape;
24 using namespace std;
25 
27 {
28 }
29 
30 template<class T>
32 {
33  T qsi = par[0], eta = par[1], zeta = par[2];
34 
35  phi(0,0) = (zeta + eta + qsi -1.) * (2.*zeta + 2.*eta + 2.*qsi - 1.);
36 // phi(0,0) = (qsi + eta + zeta -1.) * (2.*qsi + 2.*eta + 2.*zeta - 1.);
37 // phi(0,0) = 2.*qsi*qsi + 2.*eta*eta + 2.*zeta*zeta + 4.*qsi*eta + 4.*qsi*zeta + 4.*eta*zeta - 3.*qsi - 3.*eta - 3.*zeta + 1.;
38  phi(1,0) = qsi * (2.*qsi - 1.);
39  phi(2,0) = eta * (2.*eta - 1.);
40  phi(3,0) = zeta * (2.*zeta - 1.);
41  phi(4,0) = -4.*qsi * (qsi + eta + zeta -1.);
42  phi(5,0) = 4.*qsi * eta;
43  phi(6,0) = -4.*eta * (qsi + eta + zeta -1.);
44  phi(7,0) = -4.*zeta * (qsi + eta + zeta -1.);
45  phi(8,0) = 4.*qsi * zeta;
46  phi(9,0) = 4.*eta * zeta;
47 
48  dphi(0,0) = -3. + 4.*qsi + 4.*eta + 4.*zeta;
49  dphi(1,0) = -3. + 4.*qsi + 4.*eta + 4.*zeta;
50  dphi(2,0) = -3. + 4.*qsi + 4.*eta + 4.*zeta;
51  dphi(0,1) = -1. + 4.*qsi;
52  dphi(1,1) = 0.;
53  dphi(2,1) = 0.;
54  dphi(0,2) = 0.;
55  dphi(1,2) = -1. + 4.*eta;
56  dphi(2,2) = 0.;
57  dphi(0,3) = 0.;
58  dphi(1,3) = 0.;
59  dphi(2,3) = -1. + 4.*zeta;
60  dphi(0,4) = -4.*(2.*qsi + eta + zeta - 1.);
61  dphi(1,4) = -4.*qsi;
62  dphi(2,4) = -4.*qsi;
63  dphi(0,5) = 4.*eta;
64  dphi(1,5) = 4.*qsi;
65  dphi(2,5) = 0.;
66  dphi(0,6) = -4.*eta;
67  dphi(1,6) = -4.*(qsi + eta + zeta - 1.)-4.*eta;
68  dphi(2,6) = -4.*eta;
69  dphi(0,7) = -4.*zeta;
70  dphi(1,7) = -4.*zeta;
71  dphi(2,7) = -4.*(qsi + eta + zeta - 1.)-4.*zeta;
72  dphi(0,8) = 4.*zeta;
73  dphi(1,8) = 0.;
74  dphi(2,8) = 4.*qsi;
75  dphi(0,9) = 0.;
76  dphi(1,9) = 4.*zeta;
77  dphi(2,9) = 4.*eta;
78 }
79 
80 
81 template<class T>
83 
84  TPZFNMatrix<10,T> phi(NNodes,1);
85  TPZFNMatrix<30,T> dphi(3,NNodes);
86  TShape(loc,phi,dphi);
87  int space = nodes.Rows();
88  for (int i=0; i<3; i++) {
89  x[i] = 0.;
90  }
91  for(int j = 0; j < NNodes; j++) {
92  for(int i = 0; i < space; i++) {
93  x[i] += phi(j,0)*nodes.GetVal(i,j);
94  }
95  }
96 }
97 
98 template<class T>
100 
101  gradx.Resize(3,3);
102  gradx.Zero();
103  int nrow = nodes.Rows();
104  int ncol = nodes.Cols();
105 #ifdef PZDEBUG
106  if(nrow != 3 || ncol != 10){
107  std::cout << "Objects of incompatible lengths, gradient cannot be computed." << std::endl;
108  std::cout << "nodes matrix must be 3x10." << std::endl;
109  DebugStop();
110  }
111 
112 #endif
113  TPZFNMatrix<10,T> phi(NNodes,1);
114  TPZFNMatrix<30,T> dphi(3,NNodes);
115  TShape(loc,phi,dphi);
116  for(int i = 0; i < NNodes; i++)
117  {
118  for(int j = 0; j < 3; j++)
119  {
120  gradx(j,0) += nodes.GetVal(j,i)*dphi(0,i);
121  gradx(j,1) += nodes.GetVal(j,i)*dphi(1,i);
122  gradx(j,2) += nodes.GetVal(j,i)*dphi(2,i);
123  }
124  }
125 
126 }
127 
128 
129 // TPZGeoEl *TPZQuadraticTetra::CreateBCGeoEl(TPZGeoEl *orig,int side,int bc)
130 // {
131 // if(side < 0 || side > 14) { cout << "TPZGeoTetrahedra::CreateBCCompEl with bad side = " << side << "not implemented\n"; return 0; }
132 // if(side == 14) { cout << "TPZGeoTetrahedra::CreateBCCompEl with side = 14 not implemented\n"; return 0; }
133 // if(side < 4)
134 // {
135 // TPZManVector<int64_t> nodeindexes(1);
136 // nodeindexes[0] = orig->NodeIndex(side);
137 // int64_t index;
138 // TPZGeoEl *gel = orig->Mesh()->CreateGeoElement(EPoint,nodeindexes,bc,index);
139 // TPZGeoElSide(gel,0).SetConnectivity(TPZGeoElSide(orig,side));
140 // return gel;
141 // }
142 
143 // else if (side > 3 && side < 10)
144 // {// side = 4 a 9 : lados
145 // TPZManVector<int64_t> nodes(2);
146 // nodes[0] = orig->SideNodeIndex(side,0);
147 // nodes[1] = orig->SideNodeIndex(side,1);
148 // int64_t index;
149 // TPZGeoEl *gel = orig->Mesh()->CreateGeoElement(EOned,nodes,bc,index);
150 // TPZGeoElSide(gel,0).SetConnectivity(TPZGeoElSide(orig,TPZShapeTetra::ContainedSideLocId(side,0)));
151 // TPZGeoElSide(gel,1).SetConnectivity(TPZGeoElSide(orig,TPZShapeTetra::ContainedSideLocId(side,1)));
152 // TPZGeoElSide(gel,2).SetConnectivity(TPZGeoElSide(orig,side));
153 // return gel;
154 // }
155 
156 // else if (side > 9)
157 // {//side = 10 a 13 : faces
158 // TPZManVector<int64_t> nodes(3); int in;
159 
160 // for (in=0;in<3;in++) nodes[in] = orig->SideNodeIndex(side,in);
161 // int64_t index;
162 // TPZGeoEl *gel = orig->Mesh()->CreateGeoElement(ETriangle,nodes,bc,index);
163 
164 // for (in=0;in<6;in++) TPZGeoElSide(gel,in).SetConnectivity(TPZGeoElSide(orig,TPZShapeTetra::ContainedSideLocId(side,in)));
165 // TPZGeoElSide(gel,6).SetConnectivity(TPZGeoElSide(orig,side));
166 // return gel;
167 // }
168 // else PZError << "TPZGeoTetrahedra::CreateBCGeoEl. Side = " << side << endl;
169 // return 0;
170 // }
171 
172 
173 // /**
174 // * Creates a geometric element according to the type of the father element
175 // */
176 
177 // TPZGeoEl *TPZQuadraticTetra::CreateGeoElement(TPZGeoMesh &mesh, MElementType type,
178 // TPZVec<int64_t>& nodeindexes,
179 // int matid,
180 // int64_t& index)
181 // {
182 // return CreateGeoElementMapped(mesh,type,nodeindexes,matid,index);
183 // }
184 
186 /* @param gmesh mesh in which the element should be inserted
187  @param matid material id of the element
188  @param lowercorner (in/out) on input lower corner o the cube where the element should be created, on exit position of the next cube
189  @param size (in) size of space where the element should be created
190  */
191 #include "tpzchangeel.h"
192 
194 {
195  TPZManVector<REAL,3> co(3),shift(3),scale(3);
196  TPZManVector<int64_t,4> nodeindexes(NCornerNodes);
197  for (int i=0; i<3; i++) {
198  scale[i] = size[i]/3.;
199  shift[i] = size[i]/2.+lowercorner[i];
200  }
201 
202  for (int i=0; i<NCornerNodes; i++) {
203  ParametricDomainNodeCoord(i, co);
204  co.Resize(3,0.);
205  for (int j=0; j<3; j++) {
206  co[j] = shift[j]+scale[j]*co[j]+(rand()*0.2/RAND_MAX)-0.1;
207  }
208  nodeindexes[i] = gmesh.NodeVec().AllocateNewElement();
209  gmesh.NodeVec()[nodeindexes[i]].Initialize(co, gmesh);
210  }
211  int64_t index;
212  gmesh.CreateGeoElement(ETetraedro, nodeindexes, matid, index);
213  TPZGeoEl *gel = gmesh.Element(index);
214  int nsides = gel->NSides();
215  for (int is=0; is<nsides; is++) {
216  gel->SetSideDefined(is);
217  }
218  gel = TPZChangeEl::ChangeToQuadratic(&gmesh, index);
219  for (int node = gel->NCornerNodes(); node < gel->NNodes(); node++) {
221  gel->NodePtr(node)->GetCoordinates(co);
222  for (int i=0; i<3; i++) {
223  co[i] += (0.2*rand())/RAND_MAX - 0.1;
224  }
225  gel->NodePtr(node)->SetCoord(co);
226  }
227 }
228 
230  return Hash("TPZQuadraticTetra") ^ TPZNodeRep<10,pztopology::TPZTetrahedron>::ClassId() << 1;
231 }
232 
233 #include "pzgeoelrefless.h.h"
234 #include "tpzgeoelrefpattern.h.h"
235 #include "pznoderep.h.h"
236 
238 
240 /*@orlandini : I REALLY dont know why is this here, so I have commented the following lines.
241 If it breaks something, I am sorry.*/
242 //template class pzgeom::TPZNodeRep<10,TPZQuadraticTetra>;
243 
244 namespace pzgeom {
246  template void TPZQuadraticTetra::GradX(const TPZFMatrix<REAL> &nodes,TPZVec<REAL> &loc, TPZFMatrix<REAL> &gradx);
247 
248 #ifdef _AUTODIFF
250  template void TPZQuadraticTetra::GradX(const TPZFMatrix<REAL> &nodes,TPZVec<Fad<REAL> > &loc, TPZFMatrix<Fad<REAL> > &gradx);
251 #endif
252 
253 }
virtual ~TPZQuadraticTetra()
Destructor.
Contains TPZShapeTetra class which implements the shape functions of a tetrahedral element...
int AllocateNewElement()
Makes more room for new elements.
Definition: pzadmchunk.h:184
void SetCoord(const TPZVec< REAL > &x)
Sets all coordinates into the current node. It gets the dim values from x.
Definition: pzgnode.cpp:60
TPZGeoNode * NodePtr(int i) const
Returns a pointer to the ith node of the element.
Definition: pzgeoel.cpp:2566
Contains the TPZChangeEl class. It is a special map.
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.
static void X(const TPZFMatrix< REAL > &coord, TPZVec< T > &par, TPZVec< T > &result)
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
static void GradX(const TPZFMatrix< REAL > &nodes, TPZVec< T > &loc, TPZFMatrix< T > &gradx)
Compute gradient of X mapping from element nodes and local parametric coordinates.
virtual int NCornerNodes() const =0
Returns the number of corner nodes of the element.
int ClassId() const override
Define the class id associated with the class.
Definition: fad.h:54
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
virtual int NSides() const =0
Returns the number of connectivities of the element.
static void TShape(const TPZVec< T > &param, TPZFMatrix< T > &phi, TPZFMatrix< T > &dphi)
Contains declaration of TPZGeoElMapped class which implements a geometric element using its ancestral...
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
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
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
TPZGeoEl * Element(int64_t iel)
Definition: pzgmesh.h:139
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
REAL co[8][3]
Coordinates of the eight nodes.
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
static void InsertExampleElement(TPZGeoMesh &gmesh, int matid, TPZVec< REAL > &lowercorner, TPZVec< REAL > &size)
Creates a geometric element according to the type of the father element.
virtual int NNodes() const =0
Returns the number of nodes of the element.
virtual void SetSideDefined(int side)=0
Flags the side as defined, this means no neighbouring element was found.
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
Contains the implementation of the TPZNodeRep methods.
static TPZGeoEl * ChangeToQuadratic(TPZGeoMesh *Mesh, int64_t ElemIndex)
Turns an linear geoelement to quadratic.
Definition: tpzchangeel.cpp:45
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 implementation of the TPZGeoElRefPattern methods.
void GetCoordinates(TPZVec< REAL > &co)
Fill the coordinates of the node.
Definition: pzgnode.cpp:83
Groups all classes which model the geometry.
Definition: pzgeopoint.cpp:18
Contains the TPZQuadraticTetra class which defines a tetrahedral geometric element with quadratic map...
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
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
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716