NeoPZ
TPZReadGIDGrid.cpp
Go to the documentation of this file.
1 
6 #include "TPZReadGIDGrid.h"
7 #include "pzgmesh.h"
8 #include "pzgeoelside.h"
9 #include "pzgeopoint.h"
10 #include "TPZGeoLinear.h"
11 #include "TPZGeoCube.h"
12 #include "pzgeotetrahedra.h"
13 #include "tpzcube.h"
14 #include "tpzgeoblend.h"
15 
16 #include "pzgeoelside.h"
17 #include "tpzgeoblend.h"
18 #include <tpzarc3d.h>
19 
20 #include "TPZRefPattern.h"
21 #include "tpzgeoelrefpattern.h"
22 
23 #include "TPZVTKGeoMesh.h"
24 #include <pzgengrid.h>
25 
26 #include <iostream>
27 #include <fstream>
28 
30  MatNumber = 0;
31  BCNumber = 0;
33  fDimensionlessL = 1.0;
34 }//method
35 
37 
38 }//method
39 
41 {
42  // File to read Dump file generated by GID
43 
44  std::string FileName;
45  std::string stringTemp;
46  FileName = FiletoRead;
47 
48  // Definitions
49  int nMats = 0;
50  int64_t numnodes=0;
51  int64_t numelements=0;
52  int64_t elements3DT=0;
53  int64_t elements3DH=0;
54  int64_t elements2DT=0;
55  int64_t elements2DQ=0;
56  int64_t elements1D=0;
57  int64_t elements0D=0;
58 
59  // Scanning for total Number of Nodes and differents Dimension Elements
60  int64_t NumEntitiestoRead;
61  TPZStack <std::string> SentinelString;
62  {
63 
64  // reading a general mesh information by filter
65  std::ifstream read (FileName.c_str());
66  if (!read.is_open()) return 0;
67  std::string FlagString;
68  int flag = -1;
69  while(read)
70  {
71  char buf[1024];
72  read.getline(buf, 1024);
73  std::string str(buf);
74  flag = str.find("---");
75 
76  if (flag >= 0)
77  {
78  if(str != "--- ELEMENTS ---" && str != "--- ELEMENTS ---\r")
79  {
80  SentinelString.push_back(str);
81  }
82  }
83  if(str == "LINEAR" || str == "LINEAR\r" )
84  {
85  SentinelString.push_back(str);
86  }
87  if(str == "TRIANGLE" || str == "TRIANGLE\r")
88  {
89  SentinelString.push_back(str);
90  }
91  if(str == "QUADRILATERAL" || str == "QUADRILATERAL\r")
92  {
93  SentinelString.push_back(str);
94  }
95  if(str == "TETRAHEDRA" || str == "TETRAHEDRA\r")
96  {
97  SentinelString.push_back(str);
98  }
99  if(str == "HEXAHEDRA" || str == "HEXAHEDRA\r")
100  {
101  SentinelString.push_back(str);
102  }
103 
104  }
105 
106  FlagString = "EndReading";
107  SentinelString.push_back(FlagString);
108  }
109 
110  NumEntitiestoRead = SentinelString.size();
111  TPZStack <int> GeneralData(NumEntitiestoRead,0);
112  TPZStack <int> DataToProcess(NumEntitiestoRead,-1);
113 
114  {
115  // reading a general mesh information by filter
116  std::ifstream read (FileName.c_str());
117  std::string FlagString;
118  int64_t cont = 0;
119 
120  while(read)
121  {
122  char buf[1024];
123  read.getline(buf, 1024);
124  std::string str(buf);
125 
126  // Reading General Data
127  if(str == SentinelString[cont])
128  {
129  FlagString = str;
130  }
131  if(SentinelString[cont] == "" || SentinelString[cont] == "\r")
132  {
133  cont++;
134  }
135 
136  if(SentinelString[cont] == "EndReading")
137  {
138  break;
139  }
140 
141  if( (str != "" || str != "\r") && FlagString == SentinelString[cont])
142  {
143  // Data scaning
144  while (read) {
145  char buftemp[1024];
146  read.getline(buftemp, 1024);
147  std::string strtemp(buftemp);
148  GeneralData[cont]++;
149  if(strtemp == "" || strtemp == "\r")
150  {
151  FlagString = "";
152  GeneralData[cont]--;
153  cont++;
154 // std::cout << "Scanning General Data -> done!" << std::endl;
155  break;
156  }
157  }
158 
159  }
160 
161 
162  }
163  }
164 
165  for (int64_t i = 0 ; i < NumEntitiestoRead; i++ )
166  {
167  if(SentinelString[i] == "--- USED MATERIALS ---" || SentinelString[i] == "--- USED MATERIALS ---\r")
168  {
169  nMats=GeneralData[i];
170  DataToProcess[i]=0;
171  }
172  if(SentinelString[i] == "--- CONDITIONS OVER NODES ---" || SentinelString[i] == "--- CONDITIONS OVER NODES ---\r")
173  {
174  if(GeneralData[i] !=0)
175  {
176  GeneralData[i]--;
177  elements0D=GeneralData[i];
178  }
179  else
180  {
181 
182  }
183 
184  DataToProcess[i]=1;
185  }
186  if(SentinelString[i] == "--- NODES ---" || SentinelString[i] == "--- NODES ---\r")
187  {
188  numnodes=GeneralData[i];
189  DataToProcess[i]=2;
190  }
191  if(SentinelString[i] == "LINEAR" || SentinelString[i] == "LINEAR\r")
192  {
193  elements1D=GeneralData[i];
194  DataToProcess[i]=3;
195  }
196  if(SentinelString[i] == "TRIANGLE" || SentinelString[i] == "TRIANGLE\r")
197  {
198  elements2DT=GeneralData[i];
199  DataToProcess[i]=4;
200  }
201  if(SentinelString[i] == "QUADRILATERAL" || SentinelString[i] == "QUADRILATERAL\r")
202  {
203  elements2DQ=GeneralData[i];
204  DataToProcess[i]=5;
205  }
206  if(SentinelString[i] == "TETRAHEDRA" || SentinelString[i] == "TETRAHEDRA\r")
207  {
208  elements3DT=GeneralData[i];
209  DataToProcess[i]=6;
210  }
211  if(SentinelString[i] == "HEXAHEDRA" || SentinelString[i] == "HEXAHEDRA\r")
212  {
213  elements3DH=GeneralData[i];
214  DataToProcess[i]=7;
215  }
216 
217  }
218 
219  numelements=elements3DT+elements3DH+elements2DT+elements2DQ+elements1D+elements0D;
220 
221  // Mesh Creation
222 
223  TPZGeoMesh * gmesh = new TPZGeoMesh;
224  gmesh -> NodeVec().Resize(numnodes);
225  // needed for node insertion
226  const int64_t Tnodes = numnodes;
227  TPZVec <TPZGeoNode> Node(Tnodes);
228  int64_t nodeId;
229  double nodecoordX , nodecoordY , nodecoordZ ;
230  int64_t elementId = 0;
231  int matElId = 0;
232  int Layerid = 0;
233  int ContMats = 0;
234  int64_t ContNode = 0;
235  int64_t ContPoint = 0;
236  int64_t ContLine = 0;
237  int64_t ContTrian = 0;
238  int64_t ContQuad = 0;
239  int64_t ContTet = 0;
240  int64_t ContHex = 0;
241 
242  TPZManVector <int64_t> TopolPoint(1);
243  TPZManVector <int64_t> TopolLine(2);
244  TPZManVector <int64_t> TopolTriangle(3);
245  TPZManVector <int64_t> TopolQuad(4);
246  TPZManVector <int64_t> TopolTet(4);
247  TPZManVector <int64_t> TopolHex(8);
248 
249  {
250 
251  // reading a general mesh information by filter
252  std::ifstream read (FileName.c_str());
253  std::string FlagString;
254  int64_t cont = 0;
255  int dim = 0;
256  int flag = 0;
257  while(read)
258  {
259  char buf[1024];
260  read.getline(buf, 1024);
261  std::string str(buf);
262  std::string strtemp="InitialState";
263 
264  // Reading General Data
265  if(str == SentinelString[cont])
266  {
267  FlagString = str;
268  }
269 
270  if(SentinelString[cont] == "" || SentinelString[cont] == "\r")
271  {
272  cont++;
273  }
274 
275  if(SentinelString[cont] == "EndReading")
276  {
277  break;
278  }
279 
280  if( (str != "" || str != "\r" )&& FlagString == SentinelString[cont])
281  {
282  // Data scaning
283  while (read) {
284 
285  switch (DataToProcess[cont]) {
286  case 0:
287  {
288  //"--- USED MATERIALS ---"
289  if (GeneralData[cont] != 0)
290  {
291  MaterialDataV MatTemp;
292  read.getline(buf, 1024);
293  int64_t spacecont = 0;
294  char *p=buf, *q;
295  while (p)
296  {
297  q = strchr(p,' ');
298  if(!q)
299  {
300  if (p)
301  {
302  MatTemp.fProperties.push_back(atof(p));
303  }
304  break;
305  }
306  *q = 0;
307  if(spacecont==0)
308  {
309  MatTemp.fMatID = atoi(p);
310  }
311  else if(spacecont==1)
312  {
313  MatTemp.fMaterial = p;
314  if(*p=='D' || *p=='d')
315  {
316  MatNumber++;
317  }
318  else
319  {
320  BCNumber++;
321  }
322 
323  }
324  else
325  {
326  MatTemp.fProperties.push_back(atof(p));
327 
328  }
329 
330  p = q+1;
331  while(q && *p==' ')
332  p++;
333  spacecont++;
334  }
335 
336 
337  if (MatTemp.fMaterial[0]=='D' || MatTemp.fMaterial[0]=='d')
338  {
339  fMaterialDataVec.Push(MatTemp);
340  }
341  else
342  {
343  fBCMaterialDataVec.Push(MatTemp);
344  }
345 
346  ContMats++;
347  }
348  if(ContMats == nMats)
349  {
350  strtemp = "";
351  }
352  }
353  break;
354  case 1:
355  {
356  //"--- CONDITIONS OVER NODES ---"
357  // 0D Elements
358  if (GeneralData[cont] != 0)
359  {
360  if(flag == 0)
361  {
362  read.getline(buf, 1024);
363  flag++;
364  }
365  int MatID;
366  read >> TopolPoint[0]; //node 1
367  read >> MatID; //Material identity
368  read.getline(buf, 1024);
369  TopolPoint[0]--;
370  ContPoint++;
371  new TPZGeoElRefPattern < pzgeom::TPZGeoPoint > (numelements - elements0D + ContPoint, TopolPoint, MatID,*gmesh);
372 
373  }
374  if(ContPoint == elements0D)
375  {
376  strtemp = "";
377  }
378  }
379  break;
380  case 2:
381  {
382  if (GeneralData[cont] != 0)
383  {
384  //"--- NODES ---"
385 
386  if (!dim)
387  {
388  read.getline(buf, 1024);
389  int64_t spacecont = 0;
390  char *p=buf, *q;
391  while (p) {
392  q = strchr(p,' ');
393  if(!q)
394  {
395  break;
396  }
397  *q = 0;
398  if(spacecont==0) nodeId = atoi(p);
399  else if(spacecont==1) Layerid = atoi(p);
400  else if(spacecont==2) nodecoordX = atof(p);
401  else if(spacecont==3) nodecoordY = atof(p);
402  p = q+1;
403  while(q && *p==' ')
404  p++;
405  spacecont++;
406  }
407  if (spacecont == 3)
408  {
409  dim = 2;
410  fProblemDimension = dim;
411  nodecoordY = atof(p);
412  nodecoordZ = 0.0;
413  }
414  else
415  {
416  dim = 3;
417  fProblemDimension = dim;
418  nodecoordZ = atof(p);
419  }
420 
421  }
422  else
423  {
424  read >> nodeId;
425  read >> Layerid;
426  read >> nodecoordX;
427  read >> nodecoordY;
428  if (dim == 2) {
429  nodecoordZ = 0.0;
430  }
431  else
432  {
433  read >> nodecoordZ;
434  }
435  }
436  int64_t nodeid = gmesh->CreateUniqueNodeId();
437  Node[nodeId-1].SetNodeId(nodeid);
438  Node[nodeId-1].SetCoord(0,nodecoordX/fDimensionlessL);
439  Node[nodeId-1].SetCoord(1,nodecoordY/fDimensionlessL);
440  Node[nodeId-1].SetCoord(2,nodecoordZ/fDimensionlessL);
441  gmesh->NodeVec()[nodeid] = Node[nodeId-1];
442  ContNode++;
443  }
444  if(ContNode == numnodes)
445  {
446  strtemp = "";
447  }
448  }
449  break;
450  case 3:
451  {
452  //"LINEAR"
453  if (GeneralData[cont] != 0)
454  {
455  read >> elementId;
456  read >> matElId; // Material ID
457  read >> Layerid;
458  read >> TopolLine[0]; //node 2
459  read >> TopolLine[1]; //node 3
460  elementId--;
461  TopolLine[0]--;
462  TopolLine[1]--;
463  new TPZGeoElRefPattern< pzgeom::TPZGeoLinear > (elementId,TopolLine,matElId,*gmesh);
464  ContLine++;
465  }
466  if(ContLine == elements1D)
467  {
468  strtemp = "";
469  }
470  }
471  break;
472  case 4:
473  {
474  if (GeneralData[cont] != 0)
475  {
476  //"TRIANGLE"
477  read >> elementId;
478  read >> matElId; // Material ID
479  read >> Layerid;
480  read >> TopolTriangle[0]; //node 1
481  read >> TopolTriangle[1]; //node 2
482  read >> TopolTriangle[2]; //node 3
483  elementId--;
484  TopolTriangle[0]--;
485  TopolTriangle[1]--;
486  TopolTriangle[2]--;
487  new TPZGeoElRefPattern< pzgeom::TPZGeoTriangle> (elementId, TopolTriangle, matElId, *gmesh);
488  ContTrian++;
489  }
490  if(ContTrian == elements2DT)
491  {
492  strtemp = "";
493  }
494  }
495  break;
496  case 5:
497  {
498  //"QUADRILATERAL"
499  if (GeneralData[cont] != 0)
500  {
501  read >> elementId;
502  read >> matElId; // Material ID
503  read >> Layerid;
504  read >> TopolQuad[0]; //node 1
505  read >> TopolQuad[1]; //node 2
506  read >> TopolQuad[2]; //node 3
507  read >> TopolQuad[3]; //node 4
508  elementId--;
509  TopolQuad[0]--;
510  TopolQuad[1]--;
511  TopolQuad[2]--;
512  TopolQuad[3]--;
513  new TPZGeoElRefPattern< pzgeom::TPZGeoQuad> (elementId, TopolQuad, matElId, *gmesh);
514  ContQuad++;
515  }
516  if(ContQuad == elements2DQ)
517  {
518  strtemp = "";
519  }
520  }
521  break;
522  case 6:
523  {
524  //"TETRAHEDRA"
525  if (GeneralData[cont] != 0)
526  {
527  read >> elementId;
528  read >> matElId; // Material ID
529  read >> Layerid;
530  read >> TopolTet[0]; //node 1
531  read >> TopolTet[1]; //node 2
532  read >> TopolTet[2]; //node 3
533  read >> TopolTet[3]; //node 4
534  elementId--;
535  TopolTet[0]--;
536  TopolTet[1]--;
537  TopolTet[2]--;
538  TopolTet[3]--;
539  new TPZGeoElRefPattern< pzgeom::TPZGeoTetrahedra> (elementId, TopolTet, matElId, *gmesh);
540  ContTet++;
541  }
542  if(ContTet == elements3DT)
543  {
544  strtemp = "";
545  }
546  }
547  break;
548  case 7:
549  {
550  //"HEXAHEDRA"
551  if (GeneralData[cont] != 0)
552  {
553  read >> elementId;
554  read >> matElId; // Material ID
555  read >> Layerid;
556  read >> TopolHex[0]; //node 1
557  read >> TopolHex[1]; //node 2
558  read >> TopolHex[2]; //node 3
559  read >> TopolHex[3]; //node 4
560  read >> TopolHex[4]; //node 5
561  read >> TopolHex[5]; //node 6
562  read >> TopolHex[6]; //node 7
563  read >> TopolHex[7]; //node 8
564  elementId--;
565  TopolHex[0]--;
566  TopolHex[1]--;
567  TopolHex[2]--;
568  TopolHex[3]--;
569  TopolHex[4]--;
570  TopolHex[5]--;
571  TopolHex[6]--;
572  TopolHex[7]--;
573  new TPZGeoElRefPattern< pzgeom::TPZGeoCube > (elementId, TopolHex, matElId, *gmesh);
574  ContHex++;
575  }
576  if(ContHex == elements3DH)
577  {
578  strtemp = "";
579  }
580  }
581  break;
582  default:
583  {
584  strtemp = "";
585  }
586  break;
587  }
588 
589  if(strtemp == "" || strtemp == "\r")
590  {
591  FlagString = "";
592  cont++;
593  break;
594  }
595  }
596 
597  }
598 
599 
600  }
601  }
602 
603  std::cout << "Read General Mesh Data -> done!" << std::endl;
604  gmesh->BuildConnectivity();
605  std::cout << "Geometric Mesh Connectivity -> done!" << std::endl;
606  return gmesh;
607 
608 }// End Method
609 
610 void TPZReadGIDGrid::SetfDimensionlessL(REAL fDimensionlessLValue)
611 {
612  fDimensionlessL = fDimensionlessLValue;
613 }
int64_t CreateUniqueNodeId()
Returns ++fNodeMaxId.
Definition: pzgmesh.h:114
Contains declaration of TPZGeoElSide class which represents an element and its side, and TPZGeoElSideIndex class which represents an TPZGeoElSide index.
Contains the TPZReadGIDGrid class which implement the interface between TPZGeoMesh and the files in d...
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
void SetfDimensionlessL(REAL fDimensionlessLValue)
Max domain dimension for dimensionless geometry.
int BCNumber
Number of Boundary Conditions.
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
void Push(const T object)
Pushes a copy of the object on the stack.
Definition: pzstack.h:80
TPZStack< MaterialDataV > fMaterialDataVec
MaterialVec.
Implements a generic geometric element which is refined according to a generic refinement pattern...
Definition: pzgmesh.h:35
Contains the TPZGeoBlend class which implements a blending map from curved boundaries to the interior...
Contains the TPZGeoTetrahedra class which implements the geometry of a tetrahedral element...
def read(filename)
Definition: stats.py:13
std::string fMaterial
int fProblemDimension
Mesh Dimension.
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
Contains the TPZGenGrid class which implements the generation of a multilayered geometric grid (two-d...
Contains declaration of TPZGeoElRefPattern class which implements a generic geometric element which i...
Contains the TPZRefPattern class which defines the topology of the current refinement pattern to a me...
TPZGeoMesh * GeometricGIDMesh(std::string FiletoRead)
Convert GID Dump files in a TPZGeoMesh object.
Contains the TPZGeoCube class which implements the geometry of hexahedra element. ...
Contains the TPZGeoPoint class which implements the geometry of a point element or 0-D element...
void BuildConnectivity()
Build the connectivity of the grid.
Definition: pzgmesh.cpp:967
Contains the TPZArc3D class which implements three dimensional arc.
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
TPZStack< REAL > fProperties
TPZStack< MaterialDataV > fBCMaterialDataVec
Contains the TPZCube class which defines the topology of the hexahedron element.
int MatNumber
Number of Materials.
Contains the TPZVTKGeoMesh class which implements the graphical mesh to VTK environment to geometric ...
void push_back(const T object)
Definition: pzstack.h:48
REAL fDimensionlessL
Mesh Dimension.