NeoPZ
tpzquadraticline.cpp
Go to the documentation of this file.
1 
5 #include "tpzquadraticline.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 
14 #include "tpzgeomid.h"
15 
16 #include "pzlog.h"
17 
18 #ifdef LOG4CXX
19 static LoggerPtr logger(Logger::getLogger("pz.specialmaps.quadraticline"));
20 #endif
21 
22 #ifdef _AUTODIFF
23 #include "fad.h"
24 #endif
25 
26 using namespace pzshape;
27 using namespace pzgeom;
28 using namespace pztopology;
29 
30 
31 template<class T>
32 void TPZQuadraticLine::TShape(const TPZVec<T> &loc,TPZFMatrix<T> &phi,TPZFMatrix<T> &dphi) {
33 
34  T qsi = loc[0];
35 
36  phi(0,0) = -qsi*(1.-qsi)/2.;
37  phi(1,0) = +qsi*(1.+qsi)/2.;
38  phi(2,0) = (1.-qsi)*(1.+qsi);
39 
40  dphi(0,0) = qsi-0.5;
41  dphi(0,1) = qsi+0.5;
42  dphi(0,2) = -2.*qsi;
43 }
44 
45 template<class T>
46 void TPZQuadraticLine::X(const TPZFMatrix<REAL> & coord, TPZVec<T> & loc,TPZVec<T> &result) {
47  TPZFNMatrix<9,T> phi(NNodes,1);
48  TPZFNMatrix<16,T> dphi(1,NNodes);
49  TShape(loc,phi,dphi);
50 
51  for(int i = 0; i < 3; i++){
52  result[i] = 0.0;
53  for(int j = 0; j < NNodes; j++) result[i] += phi(j,0)*coord.GetVal(i,j);
54  }
55 }
56 
57 template<class T>
58 void TPZQuadraticLine::GradX(const TPZFMatrix<REAL> &nodes,TPZVec<T> &loc, TPZFMatrix<T> &gradx){
59 
60  gradx.Resize(3,1);
61  gradx.Zero();
62  int nrow = nodes.Rows();
63  int ncol = nodes.Cols();
64 #ifdef PZDEBUG
65  if(nrow != 3 || ncol != 3){
66  std::cout << "Objects of incompatible lengths, gradient cannot be computed." << std::endl;
67  std::cout << "nodes matrix must be 3x3." << std::endl;
68  DebugStop();
69  }
70 
71 #endif
72  TPZFNMatrix<3,T> phi(NNodes,1);
73  TPZFNMatrix<6,T> dphi(2,NNodes);
74  TShape(loc,phi,dphi);
75  for(int i = 0; i < NNodes; i++)
76  {
77  for(int j = 0; j < 3; j++)
78  {
79  gradx(j,0) += nodes.GetVal(j,i)*dphi(0,i);
80 
81  }
82 
83  }
84 
85 }
86 
87 
88 // TPZGeoEl *TPZQuadraticLine::CreateBCGeoEl(TPZGeoEl *orig,int side,int bc) {
89 
90 // int ns = orig->NSideNodes(side);
91 // TPZManVector<int64_t> nodeindices(ns);
92 // int in;
93 // for(in=0; in<ns; in++)
94 // {
95 // nodeindices[in] = orig->SideNodeIndex(side,in);
96 // }
97 // int64_t index;
98 
99 // TPZGeoMesh *mesh = orig->Mesh();
100 // MElementType type = orig->Type(side);
101 
102 // TPZGeoEl *newel = mesh->CreateGeoBlendElement(type, nodeindices, bc, index);
103 // TPZGeoElSide me(orig,side);
104 // TPZGeoElSide newelside(newel,newel->NSides()-1);
105 
106 // newelside.InsertConnectivity(me);
107 // newel->Initialize();
108 
109 // return newel;
110 // }
111 
112 #include "tpzgeoelmapped.h"
117 // TPZGeoEl *TPZQuadraticLine::CreateGeoElement(TPZGeoMesh &mesh, MElementType type,
118 // TPZVec<int64_t>& nodeindexes,
119 // int matid,
120 // int64_t& index)
121 // {
122 // return CreateGeoElementMapped(mesh,type,nodeindexes,matid,index);
123 // }
124 
125 //void TPZQuadraticLine::ParametricDomainNodeCoord(int node, TPZVec<REAL> &nodeCoord)
126 //{
127 // if(node > this->NNodes)
128 // {
129 // DebugStop();
130 // }
131 // nodeCoord.Resize(Dimension, 0.);
132 // switch (node) {
133 // case (0):
134 // {
135 // nodeCoord[0] = -1.;
136 // break;
137 // }
138 // case (1):
139 // {
140 // nodeCoord[0] = 1.;
141 // break;
142 // }
143 // case (2):
144 // {
145 // nodeCoord[0] = 0.;
146 // break;
147 // }
148 // default:
149 // {
150 // DebugStop();
151 // break;
152 // }
153 // }
154 //}
156 /* @param gmesh mesh in which the element should be inserted
157  @param matid material id of the element
158  @param lowercorner (in/out) on input lower corner o the cube where the element should be created, on exit position of the next cube
159  @param size (in) size of space where the element should be created
160  */
161 #include "tpzchangeel.h"
162 
163 void TPZQuadraticLine::InsertExampleElement(TPZGeoMesh &gmesh, int matid, TPZVec<REAL> &lowercorner, TPZVec<REAL> &size)
164 {
165  TPZManVector<REAL,3> co(3),shift(3),scale(3);
166  TPZManVector<int64_t,3> nodeindexes(2);
167  for (int i=0; i<3; i++) {
168  scale[i] = size[i]/3.;
169  shift[i] = 1./2.+lowercorner[i];
170  }
171 
172  for (int i=0; i<NCornerNodes; i++) {
173  ParametricDomainNodeCoord(i, co);
174  int j;
175  for (j=0; j<co.size(); j++) {
176  co[j] = shift[j]+scale[j]*co[j]+(rand()*0.2/RAND_MAX)-0.1;
177  }
178  co.Resize(3);
179  for (; j<3; j++) {
180  co[j] = shift[j]+(rand()*0.2/RAND_MAX)-0.1;
181  }
182  nodeindexes[i] = gmesh.NodeVec().AllocateNewElement();
183  gmesh.NodeVec()[nodeindexes[i]].Initialize(co, gmesh);
184  }
185  int64_t index;
186  gmesh.CreateGeoElement(EOned, nodeindexes, matid, index);
187  TPZGeoEl *gel = gmesh.Element(index);
188  int nsides = gel->NSides();
189  for (int is = 0; is<nsides; is++) {
190  gel->SetSideDefined(is);
191  }
192 
193  gel = TPZChangeEl::ChangeToQuadratic(&gmesh,index);
194  TPZGeoNode *nodeptr = gel->NodePtr(2);
195  for (int i=0; i<3; i++) {
196  co[i] = lowercorner[i]+size[i]/2.;
197  }
198  gel->NodePtr(2)->SetCoord(co);
199 }
200 
201 
203 
204 int TPZQuadraticLine::ClassId() const{
205  return Hash("TPZQuadraticLine") ^ TPZNodeRep<3,pztopology::TPZLine>::ClassId() << 1;
206 }
207 
209 /*@orlandini : I REALLY dont know why is this here, so I have commented the following lines.
210 If it breaks something, I am sorry.*/
211 //template class pzgeom::TPZNodeRep<3,TPZQuadraticLine>;
212 
213 namespace pzgeom {
214  template void TPZQuadraticLine::X(const TPZFMatrix<REAL>&, TPZVec<REAL>&, TPZVec<REAL>&);
215  template void TPZQuadraticLine::GradX(const TPZFMatrix<REAL> &nodes,TPZVec<REAL> &loc, TPZFMatrix<REAL> &gradx);
216 
217 #ifdef _AUTODIFF
218  template void TPZQuadraticLine::X(const TPZFMatrix<REAL>&, TPZVec<Fad<REAL> >&, TPZVec<Fad<REAL> >&);
219  template void TPZQuadraticLine::GradX(const TPZFMatrix<REAL> &nodes,TPZVec<Fad<REAL> > &loc, TPZFMatrix<Fad<REAL> > &gradx);
220 #endif
221 
222 }
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
groups all classes dedicated to the computation of shape functions
Definition: pzshapeextend.h:16
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.
Contains the TPZQuadraticLine class which defines a linear geometric element with quadratic map...
Implements ... Geometry Topology.
Definition: pznoderep.h:40
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
virtual void SetSideDefined(int side)=0
Flags the side as defined, this means no neighbouring element was found.
Implements a geometric node in the pz environment. Geometry.
Definition: pzgnode.h:31
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.
Definition: pzeltype.h:55
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
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150