NeoPZ
pzreadtetgen.cpp
Go to the documentation of this file.
1 
6 #include "pzreadtetgen.h"
7 #include "pzgmesh.h"
8 #include "TPZTimer.h"
9 
10 #include <iostream>
11 #include <fstream>
12 
14 
15 }//method
16 
18 
19 }//method
20 
21 TPZGeoMesh * TPZReadTetGen::Process(std::string NodeFileName, std::string FaceFileName, std::string TetraFileName) {
22  TPZGeoMesh * gmesh = new TPZGeoMesh();
23  int64_t nnodes;
24  int64_t nfaces, nvols;
25  bool check;
26 
27  TPZMultiTimer time(4);
28  time.processName(0) = "Reading nodes";
29  time.processName(1) = "Reading faces";
30  time.processName(2) = "Reading tetrahedras";
31  time.processName(3) = "BuildConnectivity";
32 
33  time.start(0);
34  check = this->ProcessNodes(NodeFileName, *gmesh, nnodes);
35  time.stop(0);
36  if (check == false){
37  delete gmesh;
38  return NULL;
39  }
40 
41  time.start(1);
42  check = this->ProcessFaces(FaceFileName, *gmesh, nfaces);
43  time.stop(1);
44  if (check == false){
45  delete gmesh;
46  return NULL;
47  }
48 
49  time.start(2);
50  check = this->ProcessTetra(TetraFileName, *gmesh, nvols);
51  time.stop(2);
52  if (check == false){
53  delete gmesh;
54  return NULL;
55  }
56 
57  time.start(3);
58  gmesh->BuildConnectivity();
59  time.stop(3);
60 
61  std::cout << time << std::endl;
62 
63  return gmesh;
64 
65 }//method
66 
67 bool TPZReadTetGen::ProcessNodes(std::string NodeFileName, TPZGeoMesh &gmesh, int64_t & numbernodes){
68  std::ifstream NodeFile(NodeFileName.c_str());
69  this->fNodeIndices.clear();
70 
71  int64_t ID, index, nnodes, dim, nattributes, BoundMarkers, bcmark;
72  REAL X, Y, Z, attr;
73  TPZManVector<REAL,3> coord(3);
74 
75  NodeFile >> nnodes >> dim >> nattributes >> BoundMarkers;
76  numbernodes = nnodes;
77 
78  if (dim != 3){
79  std::cout << __PRETTY_FUNCTION__ << " - dim must be equal to 3" << std::endl;
80  return false;
81  }//if
82 
83  for(int64_t i = 0; i < nnodes; i++){
84  NodeFile >> ID >> X >> Y >> Z;
85  if (nattributes) NodeFile >> attr;
86  if (BoundMarkers) NodeFile >> bcmark;
87 
88  index = gmesh.NodeVec().AllocateNewElement();
89  coord[0] = X;
90  coord[1] = Y;
91  coord[2] = Z;
92  gmesh.NodeVec()[index].Initialize(ID, coord, gmesh);
93 
94  this->fNodeIndices[ ID ] = index;
95  }//for i
96 
97  return true;
98 
99 }//method
100 
101 bool TPZReadTetGen::ProcessFaces(std::string FaceFileName, TPZGeoMesh &gmesh, int64_t & numberfaces){
102 
103  std::ifstream FaceFile(FaceFileName.c_str());
104 
105  int64_t nfaces, BoundMarker, ID, mat;
106  int64_t NO1, NO2, NO3, index;
108  //TPZGeoEl * gel;
109 
110  FaceFile >> nfaces >> BoundMarker;
111 
112  numberfaces = nfaces;
113 
114  for(int64_t i = 0; i < nfaces; i++){
115  FaceFile >> ID >> NO1 >> NO2 >> NO3;
116  if (BoundMarker) FaceFile >> mat;
117  else mat = -1;
118  nodind[0] = this->fNodeIndices[ NO1 ];
119  nodind[1] = this->fNodeIndices[ NO2 ];
120  nodind[2] = this->fNodeIndices[ NO3 ];
121  /*gel = */gmesh.CreateGeoElement(ETriangle, nodind, mat, index);
122  }//for i
123 
124  return true;
125 
126 }//method
127 
128 bool TPZReadTetGen::ProcessTetra(std::string TetraFileName, TPZGeoMesh &gmesh, int64_t & numbervols){
129  std::ifstream TetraFile(TetraFileName.c_str());
130  int64_t nvols, n, mat, nattr, ID, NO1, NO2, NO3, NO4, index;
132  //TPZGeoEl * gel;
133  TetraFile >> nvols >> n >> nattr;
134 
135  numbervols = nvols;
136 
137  if (n != 4) std::cout << __PRETTY_FUNCTION__ << " - tetrahedra must have only four nodes" << std::endl;
138 
139  for(int64_t i = 0; i < nvols; i++){
140  TetraFile >> ID >> NO1 >> NO2 >> NO3 >> NO4;
141  if (nattr) TetraFile >> mat;
142  else mat = 9;
143  nodind[0] = this->fNodeIndices[ NO1 ];
144  nodind[1] = this->fNodeIndices[ NO2 ];
145  nodind[2] = this->fNodeIndices[ NO3 ];
146  nodind[3] = this->fNodeIndices[ NO4 ];
147  /*gel = */gmesh.CreateGeoElement(ETetraedro, nodind, mat, index);
148 
149  }//for i
150  return true;
151 
152 }//method
int AllocateNewElement()
Makes more room for new elements.
Definition: pzadmchunk.h:184
std::map< int64_t, int64_t > fNodeIndices
Nodes in tetgen are counted from 1 to n as a fortran based code.
Definition: pzreadtetgen.h:57
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
Timing class. Absolutely copied from GNU time. Take a look at
std::string & processName(int i)
Gets the process name (for reporting purposes).
Definition: TPZTimer.h:224
void start(int i)
Turns the timer on.
Definition: TPZTimer.h:236
bool ProcessNodes(std::string NodeFileName, TPZGeoMesh &gmesh, int64_t &numbernodes)
Process nodes.
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
Contains the TPZReadTetGen class which implement the interface between TPZGeoMesh and the files produ...
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
TPZGeoMesh * Process(std::string NodeFileName, std::string FaceFileName, std::string TetraFileName)
Convert tetgen files in a TPZGeoMesh object.
bool ProcessTetra(std::string TetraFileName, TPZGeoMesh &gmesh, int64_t &numbervols)
Process tetrahedras.
void BuildConnectivity()
Build the connectivity of the grid.
Definition: pzgmesh.cpp:967
Controls several timers at once. Utility.
Definition: TPZTimer.h:100
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
void stop(int i)
Turns the timer off, and computes the elapsed time.
Definition: TPZTimer.h:251
bool ProcessFaces(std::string FaceFileName, TPZGeoMesh &gmesh, int64_t &numberfaces)
Process faces.
static int nodind[7][8]