NeoPZ
tpzquadraticquad.cpp
Go to the documentation of this file.
1 
5 #include "tpzquadraticquad.h"
6 #include "pzshapequad.h"
7 #include "tpzgeoblend.h"
8 #include "tpzgeoelmapped.h"
9 
10 #include "pzgeoelrefless.h.h"
11 #include "tpzgeoelrefpattern.h.h"
12 #include "pznoderep.h.h"
13 #include "tpzgeomid.h"
14 
15 #include "pzlog.h"
16 
17 #ifdef LOG4CXX
18 static LoggerPtr logger(Logger::getLogger("pz.specialmaps.quadraticquad"));
19 #endif
20 
21 #ifdef _AUTODIFF
22 #include "fad.h"
23 #endif
24 
25 using namespace pzshape;
26 using namespace pzgeom;
27 using namespace pztopology;
28 
29 template<class T>
30 void TPZQuadraticQuad::TShape(const TPZVec<T> &par,TPZFMatrix<T> &phi,TPZFMatrix<T> &dphi) {
31 
32  T qsi = par[0], eta = par[1];
33 
34  phi(0,0) = -0.25*(-1. + eta)*(-1. + qsi)*(1. + eta + qsi);
35  phi(1,0) = 0.25*(-1. + eta)*(1. + eta - qsi)*(1. + qsi);
36  phi(2,0) = 0.25*( 1. + qsi)*(1. + eta)*(qsi + eta - 1.);
37  phi(3,0) = -0.25*( 1. + eta)*(-1. + eta - qsi)*(-1. + qsi);
38 
39  phi(4,0) = 0.5*(-1. + eta)*(-1. + qsi)*( 1. + qsi);
40  phi(5,0) = -0.5*(-1. + eta)*( 1. + eta)*( 1. + qsi);
41  phi(6,0) = -0.5*( 1. + eta)*(-1. + qsi)*( 1. + qsi);
42  phi(7,0) = 0.5*(-1. + eta)*( 1. + eta)*(-1. + qsi);
43 
44  dphi(0,0) = -0.25*(-1. + eta)*(eta + 2.*qsi);
45  dphi(1,0) = -0.25*(-1. + qsi)*(2.*eta + qsi);
46  dphi(0,1) = 0.25*(-1. + eta)*(eta - 2.*qsi);
47  dphi(1,1) = 0.25*(2.*eta - qsi)*(1. + qsi);
48  dphi(0,2) = 0.25*(1. + eta)*(eta + 2.*qsi);
49  dphi(1,2) = 0.25*(1. + qsi)*(2.*eta + qsi);
50  dphi(0,3) = -0.25*(1. + eta)*(eta - 2.*qsi);
51  dphi(1,3) = -0.25*(2.*eta - qsi)*(-1. + qsi);
52 
53  dphi(0,4) = (-1. + eta)*qsi;
54  dphi(1,4) = 0.5*(-1. + qsi)*(1. + qsi);
55  dphi(0,5) = -0.5*(-1. + eta)*(1. + eta);
56  dphi(1,5) = -eta*(1. + qsi);
57  dphi(0,6) = -(1. + eta)*qsi;
58  dphi(1,6) = -0.5*(-1. + qsi)*(1. + qsi);
59  dphi(0,7) = 0.5*(-1. + eta)*(1. + eta);
60  dphi(1,7) = eta*(-1. + qsi);
61 }
62 
63 
64 template<class T>
65 void TPZQuadraticQuad::X(const TPZFMatrix<REAL> &nodes,TPZVec<T> &loc,TPZVec<T> &x){
66 
67  TPZFNMatrix<4,T> phi(NNodes,1);
68  TPZFNMatrix<8,T> dphi(2,NNodes);
69  TShape(loc,phi,dphi);
70  int space = nodes.Rows();
71 
72  for(int i = 0; i < space; i++) {
73  x[i] = 0.0;
74  for(int j = 0; j < NNodes; j++) {
75  x[i] += phi(j,0)*nodes.GetVal(i,j);
76  }
77  }
78 
79 }
80 
81 template<class T>
82 inline void TPZQuadraticQuad::GradX(const TPZFMatrix<REAL> &nodes,TPZVec<T> &loc, TPZFMatrix<T> &gradx){
83 
84  gradx.Resize(3,2);
85  gradx.Zero();
86  int nrow = nodes.Rows();
87  int ncol = nodes.Cols();
88 #ifdef PZDEBUG
89  if(nrow != 3 || ncol != 8){
90  std::cout << "Objects of incompatible lengths, gradient cannot be computed." << std::endl;
91  std::cout << "nodes matrix must be 3x8." << std::endl;
92  DebugStop();
93  }
94 
95 #endif
96  TPZFNMatrix<3,T> phi(NNodes,1);
97  TPZFNMatrix<6,T> dphi(2,NNodes);
98  TShape(loc,phi,dphi);
99  for(int i = 0; i < NNodes; i++)
100  {
101  for(int j = 0; j < 3; j++)
102  {
103  gradx(j,0) += nodes.GetVal(j,i)*dphi(0,i);
104  gradx(j,1) += nodes.GetVal(j,i)*dphi(1,i);
105  }
106  }
107 
108 }
109 
110 
111 // TPZGeoEl *TPZQuadraticQuad::CreateBCGeoEl(TPZGeoEl *orig,int side,int bc) {
112 
113 // int ns = orig->NSideNodes(side);
114 // TPZManVector<int64_t> nodeindices(ns);
115 // int in;
116 // for(in=0; in<ns; in++)
117 // {
118 // nodeindices[in] = orig->SideNodeIndex(side,in);
119 // }
120 // int64_t index;
121 
122 // TPZGeoMesh *mesh = orig->Mesh();
123 // MElementType type = orig->Type(side);
124 
125 // TPZGeoEl *newel = mesh->CreateGeoBlendElement(type, nodeindices, bc, index);
126 // TPZGeoElSide me(orig,side);
127 // TPZGeoElSide newelside(newel,newel->NSides()-1);
128 
129 // newelside.InsertConnectivity(me);
130 // // newel->Initialize();
131 
132 // return newel;
133 
134 // }
135 
136 
141 // TPZGeoEl *TPZQuadraticQuad::CreateGeoElement(TPZGeoMesh &mesh, MElementType type,
142 // TPZVec<int64_t>& nodeindexes,
143 // int matid,
144 // int64_t& index)
145 // {
146 // return CreateGeoElementMapped(mesh,type,nodeindexes,matid,index);
147 // }
148 
150 /* @param gmesh mesh in which the element should be inserted
151  @param matid material id of the element
152  @param lowercorner (in/out) on input lower corner o the cube where the element should be created, on exit position of the next cube
153  @param size (in) size of space where the element should be created
154  */
155 #include "tpzchangeel.h"
156 
157 void TPZQuadraticQuad::InsertExampleElement(TPZGeoMesh &gmesh, int matid, TPZVec<REAL> &lowercorner, TPZVec<REAL> &size)
158 {
159  TPZManVector<REAL,3> co(3),shift(3),scale(3);
160  TPZManVector<int64_t,4> nodeindexes(NCornerNodes);
161  for (int i=0; i<3; i++) {
162  scale[i] = size[i]/3.;
163  shift[i] = size[i]/2.+lowercorner[i];
164  }
165 
166  for (int i=0; i<NCornerNodes; i++) {
167  ParametricDomainNodeCoord(i, co);
168  co.Resize(3,0.);
169  for (int j=0; j<3; j++) {
170  co[j] = shift[j]+scale[j]*co[j]+(rand()*0.2/RAND_MAX)-0.1;
171  }
172  nodeindexes[i] = gmesh.NodeVec().AllocateNewElement();
173  gmesh.NodeVec()[nodeindexes[i]].Initialize(co, gmesh);
174  }
175  int64_t index;
176  gmesh.CreateGeoElement(EQuadrilateral, nodeindexes, matid, index);
177  TPZGeoEl *gel = gmesh.Element(index);
178  int nsides = gel->NSides();
179  for (int is=0; is<nsides; is++) {
180  gel->SetSideDefined(is);
181  }
182  gel = TPZChangeEl::ChangeToQuadratic(&gmesh, index);
183  for (int node = gel->NCornerNodes(); node < gel->NNodes(); node++) {
185  gel->NodePtr(node)->GetCoordinates(co);
186  for (int i=0; i<3; i++) {
187  co[i] += (0.2*rand())/RAND_MAX - 0.1;
188  }
189  gel->NodePtr(node)->SetCoord(co);
190  }
191 }
192 
193 //void TPZQuadraticQuad::ParametricDomainNodeCoord(int node, TPZVec<REAL> &nodeCoord)
194 //{
195 // if(node > this->NNodes)
196 // {
197 // DebugStop();
198 // }
199 // nodeCoord.Resize(Dimension, 0.);
200 // switch (node) {
201 // case (0):
202 // {
203 // nodeCoord[0] = -1.;
204 // nodeCoord[1] = -1.;
205 // break;
206 // }
207 // case (1):
208 // {
209 // nodeCoord[0] = 1.;
210 // nodeCoord[1] = -1.;
211 // break;
212 // }
213 // case (2):
214 // {
215 // nodeCoord[0] = 1.;
216 // nodeCoord[1] = 1.;
217 // break;
218 // }
219 // case (3):
220 // {
221 // nodeCoord[0] = -1.;
222 // nodeCoord[1] = 1.;
223 // break;
224 // }
225 // case (4):
226 // {
227 // nodeCoord[0] = 0.;
228 // nodeCoord[1] = -1.;
229 // break;
230 // }
231 // case (5):
232 // {
233 // nodeCoord[0] = 1.;
234 // nodeCoord[1] = 0.;
235 // break;
236 // }
237 // case (6):
238 // {
239 // nodeCoord[0] = 0.;
240 // nodeCoord[1] = 1.;
241 // break;
242 // }
243 // case (7):
244 // {
245 // nodeCoord[0] = -1.;
246 // nodeCoord[1] = 0.;
247 // break;
248 // }
249 // default:
250 // {
251 // DebugStop();
252 // break;
253 // }
254 // }
255 //}
256 
258 
259 int TPZQuadraticQuad::ClassId() const{
260  return Hash("TPZQuadraticQuad") ^ pzgeom::TPZNodeRep<8,pztopology::TPZQuadrilateral>::ClassId() << 1;
261 }
262 
264 
265 /*@orlandini : I REALLY dont know why is this here, so I have commented the following lines.
266 If it breaks something, I am sorry.*/
267 //template class pzgeom::TPZNodeRep<8,TPZQuadraticQuad>;
268 
269 namespace pzgeom {
270  template void TPZQuadraticQuad::X(const TPZFMatrix<REAL>&, TPZVec<REAL>&, TPZVec<REAL>&);
271  template void TPZQuadraticQuad::GradX(const TPZFMatrix<REAL> &nodes,TPZVec<REAL> &loc, TPZFMatrix<REAL> &gradx);
272 
273 #ifdef _AUTODIFF
274  template void TPZQuadraticQuad::X(const TPZFMatrix<REAL>&, TPZVec<Fad<REAL> >&, TPZVec<Fad<REAL> >&);
275  template void TPZQuadraticQuad::GradX(const TPZFMatrix<REAL> &nodes,TPZVec<Fad<REAL> > &loc, TPZFMatrix<Fad<REAL> > &gradx);
276 #endif
277 
278 }
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.
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
Contains the TPZQuadraticQuad class which defines a quadrilateral geometric element with quadratic ma...
groups all classes dedicated to the computation of shape functions
Definition: pzshapeextend.h:16
virtual int NCornerNodes() const =0
Returns the number of corner nodes of the element.
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.
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
static TPZGeoEl * ChangeToQuadratic(TPZGeoMesh *Mesh, int64_t ElemIndex)
Turns an linear geoelement to quadratic.
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
Contains the TPZGeoBlend class which implements a blending map from curved boundaries to the interior...
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
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.
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 TPZShapeQuad class which implements the shape functions of a quadrilateral element...
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