NeoPZ
TPZExtendGridDimension.cpp
Go to the documentation of this file.
1 
7 #include "pzgmesh.h"
8 #include "pzgeoel.h"
9 
10 using namespace std;
11 
12 TPZExtendGridDimension::TPZExtendGridDimension(char *geofile,REAL thickness) : fFineFileMesh(geofile), fEltype(0){
13 
14  fThickness = thickness;
15 }
16 
18 {
19 
20  fFineGeoMesh = finegeomesh;
21  fThickness = thickness;
22 }
24  fFineGeoMesh = finegeomesh;
25  fThickness = thickness;
26 }
27 
29 {
30  // a malha 2D sera extendida para uma malha 3D: logo ela eh plana e conforme
31  // as incidencias devem estar dadas em sentido antihorario - vista superior do plano XY
32  // e as coordenadas sao da forma (x,y,0)
33  // a terceira componente devera ser thickness: altura da malha
34  // os elementos 2D podem ser triangulos ou quadrilateros
35  // si os elementos sao triangulos os elementos 3D serao prismas retos
36  // si os elementos sao quadrilateros os elementos 3D serao hexaedros retos
37  TPZGeoMesh *extendedmesh = new TPZGeoMesh;
38  extendedmesh->SetDimension(fFineGeoMesh->Dimension()+1);
39  int64_t maxid = fFineGeoMesh->CreateUniqueNodeId();
40  int64_t nelem = fFineGeoMesh->ElementVec().NElements(),i,j;
41  TPZGeoNode gnode;
42  int64_t nnodes = fFineGeoMesh->NodeVec().NElements();
43  //o numero de nos sera duplicado
44  extendedmesh->NodeVec().Resize(2*nnodes);
45  TPZVec<REAL> coord(3);
46  int64_t index;
47  //criacao dos nos da malha 3D
48  for(i=0;i<nnodes;i++){
49  gnode = fFineGeoMesh->NodeVec()[i];
50  coord[0] = gnode.Coord(0);
51  coord[1] = gnode.Coord(1);
52  coord[2] = gnode.Coord(2);// = 0.0
53  extendedmesh->NodeVec()[i].Initialize(coord,*extendedmesh);
54  coord[2] = fThickness;
55  extendedmesh->NodeVec()[i+maxid].Initialize(coord,*extendedmesh);
56  }
57  //criacao de elementos da malha 3D
58  TPZGeoEl *gel;
59  TPZVec<int64_t> incidel;
60  for(i=0;i<nelem;i++){
61  gel = fFineGeoMesh->ElementVec()[i];
62  if(!gel) continue;
63  int type = gel->Type();
64  if(type==2) { //triangle
65  incidel.Resize(6);
66  if(fThickness > 0){
67  for(j=0;j<3;j++) incidel[j] = gel->NodeIndex(j);
68  for(j=3;j<6;j++) incidel[j] = incidel[j-3]+maxid;
69  } else if(fThickness < 0){
70  for(j=0;j<3;j++) incidel[j] = gel->NodeIndex(j)+maxid;
71  for(j=3;j<6;j++) incidel[j] = gel->NodeIndex(j-3);
72  }
73  int matind = gel->MaterialId();
74  extendedmesh->CreateGeoElement(EPrisma,incidel,matind,index,fEltype);
75  }
76  if(type==3) { //quadrilateral
77  incidel.Resize(8);
78  if(fThickness > 0){
79  for(j=0;j<4;j++) incidel[j] = gel->NodeIndex(j);
80  for(j=4;j<8;j++) incidel[j] = incidel[j-4]+maxid;
81  } else if(fThickness < 0){
82  for(j=0;j<4;j++) incidel[j] = gel->NodeIndex(j)+maxid;
83  for(j=4;j<8;j++) incidel[j] = gel->NodeIndex(j-4);
84  }
85  int matind = gel->MaterialId();
86  extendedmesh->CreateGeoElement(ECube,incidel,matind,index,fEltype);
87  }
88  }
89  extendedmesh->BuildConnectivity();
90  return extendedmesh;
91 }
92 
94 {
95  // It represents a 3D Linear transformation around the z axis.
96 
97  TPZVec<REAL> iCoords(3,0.0);
98  TPZVec<REAL> iCoordsTr(3,0.0);
99 
100  Tr.Print("Rotation = ");
101 
102  int NumberofGeoNodes = GeoSurface->NNodes();
103  for (int inode = 0; inode < NumberofGeoNodes; inode++)
104  {
105  TPZGeoNode GeoNode = GeoSurface->NodeVec()[inode];
106  GeoNode.GetCoordinates(iCoords);
107  // Apply rotation
108  iCoordsTr[0] = Tr(0,0)*iCoords[0]+Tr(0,1)*iCoords[1]+Tr(0,2)*iCoords[2];
109  iCoordsTr[1] = Tr(1,0)*iCoords[0]+Tr(1,1)*iCoords[1]+Tr(1,2)*iCoords[2];
110  iCoordsTr[2] = Tr(2,0)*iCoords[0]+Tr(2,1)*iCoords[1]+Tr(2,2)*iCoords[2];
111  GeoNode.SetCoord(iCoordsTr);
112  GeoSurface->NodeVec()[inode] = GeoNode;
113  }
114 }
115 
116 TPZGeoMesh *TPZExtendGridDimension::ExtendedMesh(int naumentedlayers,int matidbottom,int matidtop){
117  if(naumentedlayers < 1) // returns the same geometric mesh
118  return fFineGeoMesh.operator->();
119 
120  // a malha 2D sera extendida para uma malha 3D: logo ela eh plana e conforme
121  // as incidencias devem estar dadas em sentido antihorario - vista superior do plano XY
122  // e as coordenadas sao da forma (x,y,0)
123  // a terceira componente devera ser thickness: altura da malha
124  // os elementos 2D podem ser triangulos ou quadrilateros
125  // se os elementos sao triangulos os elementos 3D serao prismas retos
126  // se os elementos sao quadrilateros os elementos 3D serao hexaedros retos
127 
128  TPZGeoMesh *extendedmesh = new TPZGeoMesh;
129  extendedmesh->SetDimension(fFineGeoMesh->Dimension()+1);
130  int64_t maxid = fFineGeoMesh->CreateUniqueNodeId();
131  int64_t nelem = fFineGeoMesh->ElementVec().NElements();
132  int64_t i,j,k;
133  TPZGeoNode gnode;
134  int64_t nnodes = fFineGeoMesh->NodeVec().NElements();
135 
136  //o numero de nos sera duplicado
137  extendedmesh->NodeVec().Resize((naumentedlayers+1)*nnodes);
138  TPZVec<REAL> coord(3);
139  int64_t index;
140 
141  //criacao dos nos da malha 3D
142  for(i=0;i<nnodes;i++) {
143  gnode = fFineGeoMesh->NodeVec()[i];
144  coord[0] = gnode.Coord(0);
145  coord[1] = gnode.Coord(1);
146  coord[2] = gnode.Coord(2);// = 0.0
147  extendedmesh->NodeVec()[i].Initialize(coord,*extendedmesh);
148  for(j=0;j<naumentedlayers;j++) {
149  coord[2] += fThickness;
150  extendedmesh->NodeVec()[i+(j+1)*maxid].Initialize(coord,*extendedmesh);
151  }
152  }
153  //criacao de elementos da malha 3D
154  TPZGeoEl *gel;
155  TPZVec<int64_t> incidelorig;
156  TPZVec<int64_t> incidel;
157  int matind;
158  for(i=0;i<nelem;i++) {
159  gel = fFineGeoMesh->ElementVec()[i];
160  if(!gel) continue;
161  // evitar criacao de malha multiescala, pega so elementos sem os filhos (dac 2014 09 17)
162  if(gel->HasSubElement() == true)
163  {
164  continue;
165  }
166  int type = gel->Type();
167  if(type==ETriangle || type==EQuadrilateral) {//triangle
168  nnodes = gel->NNodes();
169  incidelorig.Resize(nnodes);
170  for(j=0;j<nnodes;j++)
171  incidelorig[j] = gel->NodeIndex(j);
172  incidel.Resize(2*nnodes);
173  for(k=0;k<naumentedlayers;k++) {
174  if(fThickness > 0) {
175  for(j=0;j<nnodes;j++) incidel[j] = incidelorig[j];
176  for(j=nnodes;j<2*nnodes;j++) incidel[j] = incidel[j-nnodes]+maxid;
177  // initial indexes of the nodes must to be update, upper triangle
178  for(j=0;j<nnodes;j++) incidelorig[j] = incidel[j+nnodes];
179  } else if(fThickness < 0) {
180  for(j=0;j<nnodes;j++) incidel[j] = incidelorig[j]+maxid;
181  for(j=nnodes;j<2*nnodes;j++) incidel[j] = incidelorig[j-nnodes];
182  // initial indexes of the nodes must to be update, lower triangle
183  for(j=0;j<nnodes;j++) incidelorig[j] = incidel[j];
184  }
185  matind = gel->MaterialId();
186  if(type==ETriangle) gel = extendedmesh->CreateGeoElement(EPrisma,incidel,matind,index,fEltype);
187  else gel = extendedmesh->CreateGeoElement(ECube,incidel,matind,index,fEltype);
188  }
189  }
190  // When the geometric element has boundary condition
191  else {
192  if(gel->MaterialId() != 0) {
193  nnodes = gel->NNodes();
194  incidelorig.Resize(nnodes);
195  for(j=0;j<nnodes;j++) incidelorig[j] = gel->NodeIndex(j);
196  incidel.Resize(2*nnodes);
197  for(k=0;k<naumentedlayers;k++) {
198  if(fThickness > 0) {
199  for(j=0;j<nnodes;j++) incidel[j] = incidelorig[j];
200  for(j=nnodes;j<2*nnodes;j++) incidel[j] = incidel[j-nnodes]+maxid;
201  if (nnodes > 1)
202  {
203  // reordena os indices
204  int64_t a = incidel[3];
205  incidel[3] = incidel[2];
206  incidel[2] = a;
207  }
208  // initial indexes of the nodes must to be update, upper triangle
209  for(j=0;j<nnodes;j++) incidelorig[j] = incidel[j+nnodes];
210  } else if(fThickness < 0) {
211  for(j=0;j<nnodes;j++) incidel[j] = incidelorig[j]+maxid;
212  for(j=nnodes;j<2*nnodes;j++) incidel[j] = incidelorig[j-nnodes];
213  // initial indexes of the nodes must to be update, lower triangle
214  for(j=0;j<nnodes;j++) incidelorig[j] = incidel[j];
215  }
216  matind = gel->MaterialId();
217  if(nnodes==1) gel = extendedmesh->CreateGeoElement(EOned,incidel,matind,index,fEltype);
218  else gel = extendedmesh->CreateGeoElement(EQuadrilateral,incidel,matind,index,fEltype);
219  }
220  }
221  }
222  }
223  // Inserting all the elements of the original two-dimensional mesh as bc elements (bottom bc)
224  if(matidbottom != 0) {
225  for(i=0;i<nelem;i++) {
226  gel = fFineGeoMesh->ElementVec()[i];
227  if(!gel || gel->MaterialId() < 0) continue;
228  if(gel->HasSubElement() == true)
229  {
230  continue;
231  }
232  nnodes = gel->NNodes();
233  incidelorig.Resize(nnodes);
234  for(j=0;j<nnodes;j++)
235  incidelorig[j] = gel->NodeIndex(j);
236  if(nnodes==3)
237  {
238  gel = extendedmesh->CreateGeoElement(ETriangle,incidelorig,matidbottom,index,fEltype);
239  }
240  else if(nnodes==4)
241  {
242  gel = extendedmesh->CreateGeoElement(EQuadrilateral,incidelorig,matidbottom,index,fEltype);
243  }
244  }
245  }
246  // Inserting all the elements on last layer inserted as bc elements (top bc)
247  if(matidtop != 0) {
248  for(i=0;i<nelem;i++) {
249  gel = fFineGeoMesh->ElementVec()[i];
250  if(!gel || gel->MaterialId() < 0) continue;
251  if(gel->HasSubElement() == true)
252  {
253  continue;
254  }
255  nnodes = gel->NNodes();
256  incidelorig.Resize(nnodes);
257  for(j=0;j<nnodes;j++)
258  incidelorig[j] = gel->NodeIndex(j)+(naumentedlayers*maxid);
259  if(nnodes==3){
260  gel = extendedmesh->CreateGeoElement(ETriangle,incidelorig,matidtop,index,fEltype);
261  }
262  else if(nnodes == 4)
263  {
264  gel = extendedmesh->CreateGeoElement(EQuadrilateral,incidelorig,matidtop,index,fEltype);
265  }
266  }
267  }
268  extendedmesh->BuildConnectivity();
269  return extendedmesh;
270 }
271 
273 
274  fFineGeoMesh->Print(out);
275 }
void SetCoord(const TPZVec< REAL > &x)
Sets all coordinates into the current node. It gets the dim values from x.
Definition: pzgnode.cpp:60
int64_t CreateUniqueNodeId()
Returns ++fNodeMaxId.
Definition: pzgmesh.h:114
int MaterialId() const
Returns the material index of the element.
Definition: pzgeoel.h:250
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
void PrintGeneratedMesh(std::ostream &out=std::cout)
Prints the generated mesh.
REAL Coord(int i) const
Returns i-th coordinate of the current node.
Definition: pzgnode.h:99
static void DeformMesh(TPZFMatrix< REAL > &Tr, TPZGeoMesh *GeoSurface)
Apply transformation to a given geomesh.
TPZAutoPointer< TPZGeoMesh > fFineGeoMesh
Fine geometric mesh generated by the NeoPZ.
TPZExtendGridDimension(char *geofile, REAL thickness)
Constructor using filename with gmesh data and thickness.
int64_t NElements() const
Access method to query the number of elements of the vector.
virtual int64_t NodeIndex(int i) const =0
Returns the index of the ith node the index is the location of the node in the nodevector of the mesh...
void SetDimension(int dim)
Set Dimension.
Definition: pzgmesh.h:285
int fEltype
type of element to be generated =1 -> RefPattern =0 -> Uniform Refinement
TPZGeoMesh * ExtendedMesh()
It reads the mesh since the archive of entrance finemesh, or since the fFineGeoMesh passed in the con...
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
void Resize(const int newsize)
Increase the size of the chunk vector.
Definition: pzadmchunk.h:280
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
virtual void Print(std::ostream &out=std::cout) const
Print the information of the grid to an ostream.
Definition: pzgmesh.cpp:130
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
int64_t NNodes() const
Number of nodes of the mesh.
Definition: pzgmesh.h:126
virtual MElementType Type() const =0
Returns the element type acording to pzeltype.h.
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
Contains the TPZExtendGridDimension class which generates a three dimensional mesh as an extension of...
virtual int HasSubElement() const =0
Return 1 if the element has subelements.
virtual int NNodes() const =0
Returns the number of nodes of the element.
REAL fThickness
Thickness of the mesh (+ or -)
void BuildConnectivity()
Build the connectivity of the grid.
Definition: pzgmesh.cpp:967
int Dimension()
Get Dimension.
Definition: pzgmesh.h:291
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
Definition: pzeltype.h:61
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
void GetCoordinates(TPZVec< REAL > &co)
Fill the coordinates of the node.
Definition: pzgnode.cpp:83
Definition: pzeltype.h:55
TPZAdmChunkVector< TPZGeoEl * > & ElementVec()
Methods for handling pzlists.
Definition: pzgmesh.h:138