NeoPZ
TPZGMSHReadMesh.cpp
Go to the documentation of this file.
1 
6 #include "TPZGMSHReadMesh.h"
7 #include "pzgeoel.h"
8 #include "pzgeoelside.h"
9 #include "pzvec.h"
10 #include "pzgmesh.h"
11 
13  fGeoMesh = gmesh;
14 }
15 
16 void TPZGMSHReadMesh::ReadMesh2D(const char *meshfile,TPZStack<TPZGeoEl *> &elemlist,TPZStack<TPZGeoElSide> &elembclist) {
17 
18  //o GMSH pode não retornar os nós sequencialmente
19  //nesse casso deveram ser resequenciados
20  TPZStack<int64_t> Indexes;
21  Resequence(Indexes,meshfile);
22  std::ifstream mesh(meshfile);
23  char title[256];
24  int64_t nnodes,number;
25  mesh >> title;//$NOD
26  mesh >> nnodes;
27  fGeoMesh->NodeVec().Resize(nnodes);
28  TPZVec<REAL> coord(3);
29  int64_t i;
30  for(i=0;i<nnodes;i++){
31  mesh >> number;
32  mesh >> coord[0] >> coord[1] >> coord[2];
33  fGeoMesh->NodeVec()[i].Initialize(coord,*fGeoMesh);
34  }
35  mesh >> title;//$ENDNOD
36  mesh >> title;//$ELM
37  int64_t numelem;
38  mesh >> numelem;
39  TPZVec<int64_t> nodes;
40  nodes.Resize(4);
41  int64_t index;
42  int64_t numb,fgt1,nmat,fgt2,nvert,no1,no2,no3,no4;
43  for(i=0;i<numelem;i++){
44  mesh >> numb >> fgt1 >> nmat >> fgt2 >> nvert;
45  mesh >> no1 >> no2;
46  nodes[0] = Indexes[no1-1];//no1-1;
47  nodes[1] = Indexes[no2-1];//no2-1;
48  if(nvert == 2){//só elementos de contorno
49  nodes.Resize(2);
50  elembclist.Push(TPZGeoElSide(fGeoMesh->CreateGeoElement(EOned,nodes,1,index),-nmat));
51  continue;
52  }
53  if(nvert == 3){//só elementos de volume
54  nodes.Resize(3);
55  mesh >> no3;
56  nodes[2] = Indexes[no3-1];//no3-1;
57  elemlist.Push(fGeoMesh->CreateGeoElement(ETriangle,nodes,1,index));
58  }
59  if(nvert == 4){//só elementos de volume
60  nodes.Resize(4);
61  mesh >> no3 >> no4;
62  nodes[2] = Indexes[no3-1];//no3-1;
63  nodes[3] = Indexes[no4-1];//no4-1;
64  elemlist.Push(fGeoMesh->CreateGeoElement(EQuadrilateral,nodes,1,index));
65  }
66  }
67  mesh >> title;//$ENDELM
68  mesh.close();
69 }
70 
72 
73  std::ifstream mesh(meshfile);
74  char title[256];
75  int64_t nnodes,number;
76  mesh >> title;//$NOD
77  mesh >> nnodes;
78  fGeoMesh->NodeVec().Resize(nnodes);
79  TPZVec<REAL> coord(3);
80  int64_t i;
81  for(i=0;i<nnodes;i++){
82  mesh >> number;
83  mesh >> coord[0] >> coord[1] >> coord[2];
84  fGeoMesh->NodeVec()[i].Initialize(coord,*fGeoMesh);
85  }
86  mesh >> title;//$ENDNOD
87  mesh >> title;//$ELM
88  int64_t numelem;
89  mesh >> numelem;
90  TPZVec<int64_t> nodes;
91  nodes.Resize(3);
92  int64_t index;
93  int64_t numb,fgt1,nmat,fgt2,nvert,no1,no2,no3,no4;
94  for(i=0;i<numelem;i++){
95  mesh >> numb >> fgt1 >> nmat >> fgt2 >> nvert;
96  mesh >> no1;
97  mesh >> no2;
98  nodes[0] = no1-1;
99  nodes[1] = no2-1;
100  if(nvert == 2){//só elementos de contorno
101  nodes.Resize(2);
102  elembclist.Push(TPZGeoElSide(fGeoMesh->CreateGeoElement(EOned,nodes,1,index),-nmat));
103  continue;
104  }
105  if(nvert == 3){//só elementos de volume
106  nodes.Resize(3);
107  mesh >> no3;
108  nodes[2] = no3-1;
109  elemlist.Push(fGeoMesh->CreateGeoElement(ETriangle,nodes,1,index));
110  }
111  if(nvert == 4){//só elementos de volume
112  nodes.Resize(4);
113  mesh >> no3 >> no4;
114  nodes[2] = no3-1;
115  nodes[3] = no4-1;
116  elemlist.Push(fGeoMesh->CreateGeoElement(EQuadrilateral,nodes,1,index));
117  }
118  }
119  mesh >> title;//$ENDELM
120  mesh.close();
121 }
122 
124 
125  //o GMSH pode não retornar os nós sequencialmente
126  //nesse casso deveram ser resequenciados
127  TPZStack<int64_t> Indexes;
128  Resequence(Indexes,meshfile);
129  std::ifstream mesh(meshfile);
130  char title[256];
131  int64_t nnodes,number;
132  mesh >> title;//$NOD
133  mesh >> nnodes;
134  fGeoMesh->NodeVec().Resize(nnodes);
135  TPZVec<REAL> coord(3);
136  int64_t i;
137  for(i=0;i<nnodes;i++){
138  mesh >> number;
139  mesh >> coord[0] >> coord[1] >> coord[2];
140  fGeoMesh->NodeVec()[i].Initialize(coord,*fGeoMesh);
141  }
142  mesh >> title;//$ENDNOD
143  mesh >> title;//$ELM
144  int64_t numelem;
145  mesh >> numelem;
146  TPZVec<int64_t> nodes;
147  nodes.Resize(3);
148  int64_t index;
149  int64_t numb,fgt1,nmat,fgt2,nvert;
150  TPZVec<int64_t> nos(8);//máximo do cubo
151  for(i=0;i<numelem;i++){
152  mesh >> numb >> fgt1 >> nmat >> fgt2 >> nvert;
153  for(i=0;i<nvert;i++) mesh >> nos[i];
154  if(nvert == 3){//triângulos
155  for(i=0;i<nvert;i++) nodes[i] = Indexes[nos[i]-1];//nos[i]-1;
156  nodes.Resize(3);
157  elembclist.Push(TPZGeoElSide(fGeoMesh->CreateGeoElement(ETriangle,nodes,1,index),-nmat));
158  continue;
159  } else if(nvert == 4 && fgt1 != 4){//quadrilateros
160  nodes.Resize(4);
161  for(i=0;i<nvert;i++) nodes[i] = Indexes[nos[i]-1];//nos[i]-1;
162  elembclist.Push(TPZGeoElSide(fGeoMesh->CreateGeoElement(EQuadrilateral,nodes,1,index),-nmat));
163  continue;
164  } else if(nvert == 4 && fgt1 == 4){//tetraedros
165  nodes.Resize(4);
166  for(i=0;i<nvert;i++) nodes[i] = Indexes[nos[i]-1];//nos[i]-1;
167  elemlist.Push(fGeoMesh->CreateGeoElement(ETetraedro,nodes,1,index));
168  continue;
169  } else if(nvert == 8){//hexaedros
170  nodes.Resize(8);
171  for(i=0;i<nvert;i++) nodes[i] = Indexes[nos[i]-1];//nos[i]-1;
172  elemlist.Push(fGeoMesh->CreateGeoElement(ECube,nodes,1,index));
173  continue;
174  }
175  }
176  mesh >> title;//$ENDELM
177  mesh.close();
178 }
179 
180 void TPZGMSHReadMesh::Resequence(TPZStack<int64_t> &Indexes,const char *meshfile){
181 
182  std::ifstream mesh(meshfile);
183  char title[256];
184  int64_t nnod,pos;
185  mesh >> title;//$NOD
186  mesh >> nnod;
187  int64_t index = 0,i;
188  REAL no1,no2,no3;
189  for(i=0;i<nnod;i++){
190  index++;
191  mesh >> pos >> no1 >> no2 >> no3;
192  if(index == pos){
193  Indexes.Push(i);//Indexes[index] = i
194  } else {
195  while( index < pos ){
196  Indexes.Push(-1);//Indexes[index] = i
197  index++;
198  }
199  Indexes.Push(i);//index = pos //Indexes[index] = i
200  }
201  }
202  mesh.close();
203 }
204 
205 void TPZGMSHReadMesh::PrintGeoMesh(std::ostream &out){
206 
207  fGeoMesh->Print(out);
208  std::cout << "TPZGMSHReadMesh::PrintGeoMesh the geometric mesh of the NeoPZ was printed\n";
209 }
void ReadMesh2D2(char *meshfile, TPZStack< TPZGeoEl *> &elemlist, TPZStack< TPZGeoElSide > &elembclist)
Contains declaration of TPZGeoElSide class which represents an element and its side, and TPZGeoElSideIndex class which represents an TPZGeoElSide index.
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
TPZGeoMesh * fGeoMesh
defined geometric mesh in the NeoPZ
Templated vector implementation.
void Resequence(TPZStack< int64_t > &Indexes, const char *meshfile)
Rearranges the nodal numeration given by the GMSH of sequential form.
TPZGMSHReadMesh(TPZGeoMesh *gmesh)
Utility class which represents an element with its side. The Geometric approximation classes Geometry...
Definition: pzgeoelside.h:83
Contains the TPZGMSHReadMesh class which manages the manipulation of geometric meshes.
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...
void PrintGeoMesh(std::ostream &out=std::cout)
void Push(const T object)
Pushes a copy of the object on the stack.
Definition: pzstack.h:80
virtual void Print(std::ostream &out=std::cout) const
Print the information of the grid to an ostream.
Definition: pzgmesh.cpp:130
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
void ReadMesh3D(char *meshfile, TPZStack< TPZGeoEl *> &elemlist, TPZStack< TPZGeoElSide > &elembclist)
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
This class implements a stack object. Utility.
Definition: pzcheckmesh.h:14
Definition: pzeltype.h:61
Definition: pzeltype.h:55
void ReadMesh2D(const char *meshfile, TPZStack< TPZGeoEl *> &elemlist, TPZStack< TPZGeoElSide > &elembclist)