NeoPZ
pzreadmeshhr.cpp
Go to the documentation of this file.
1 
6 #include "pzreadmeshhr.h"
7 
8 #include "pzgeoel.h"
9 #include "pzgmesh.h"
10 #include "pzcmesh.h"
11 #include "pzelasmat.h"
12 #include "pzmat2dlin.h"
13 #include "pzpoisson3d.h"
14 #include "pzbndcond.h"
15 #include "pzcompel.h"
16 #include "pzlog.h"
17 
18 #include <iostream>
19 #include <sstream>
20 
21 #ifdef LOG4CXX
22 static LoggerPtr logger(Logger::getLogger("pz.pre.tpzmeshreaderhr"));
23 #endif
24 
25 TPZReadMeshHR::TPZReadMeshHR(const char* infInputFile): TPZReadMesh(infInputFile)
26 {}
27 
29 {}
30 
32 {
33  std::string numberOf;
34  TPZGeoMesh *gmesh = readGeoMesh();
35  TPZCompMesh *cmesh = new TPZCompMesh (gmesh);
36  removeComents (numberOf);
37  int nmat = atoi (numberOf.c_str());
38  ReadMaterials(nmat,*cmesh);
39  removeComents (numberOf);
40  int nbcs = atoi (numberOf.c_str());
41  ReadBCs(nbcs,*cmesh);
42  cmesh->AutoBuild();
43  return cmesh;
44 }
45 
46 void TPZReadMeshHR::removeComents (std::string &NumberOf)
47 {
48  if (!fInputFile) return;
49  while (fInputFile)
50  {
51  char buf[512];
52  fInputFile.getline(buf,512);
53  std::string aux (buf);
54  int pos = aux.find (":");
55  if ((pos > -1 && pos < (int)aux.size()) || !aux.size()) continue; //encontrou um coment�io na linha
56  NumberOf = aux;
57  break;
58  }
59 }
60 
61 void TPZReadMeshHR::ReadNodes (int64_t NNos, TPZGeoMesh & GMesh)
62 {
63  int64_t i, id;
64  int c;
65  TPZVec <REAL> coord(3,0.);
66  for (i=0;i<NNos;i++)
67  {
68  fInputFile >> id;
69  for (c=0;c<3;c++) fInputFile >> coord[c];
70  int64_t index = GMesh.NodeVec().AllocateNewElement();
71  GMesh.NodeVec()[index] = TPZGeoNode(id,coord,GMesh);
72  }
73 }
74 
75 void TPZReadMeshHR::ReadElements (int64_t NElem, TPZGeoMesh & GMesh)
76 {
77  int64_t i, c, id;
78  int type,matid;
79  for (i=0;i<NElem;i++)
80  {
81  fInputFile >> id >> type >> matid;
82  int nnos = -1;
83  MElementType etype;
84  switch (type)
85  {
86  case (0):
87  nnos = 1;
88  etype = EPoint;
89  break;
90  case (1):
91  nnos = 2;
92  etype = EOned;
93  break;
94  case (2):
95  nnos = 3;
96  etype = ETriangle;
97  break;
98  case (3):
99  nnos = 4;
100  etype = EQuadrilateral;
101  break;
102  case (4):
103  nnos = 4;
104  etype = ETetraedro;
105  break;
106  case (5):
107  nnos = 5;
108  etype = EPiramide;
109  break;
110  case (6):
111  nnos = 6;
112  etype = EPrisma;
113  break;
114  case (7):
115  nnos = 8;
116  etype = ECube;
117  break;
118  default:
119  std::stringstream sout;
120 #ifndef WINDOWS
121  sout << __PRETTY_FUNCTION__;
122 #endif
123  sout << "Nao sei que elemento " << type << " eh esse indicado para o elemento " << id;
124 #ifdef LOG4CXX
125  LOGPZ_WARN (logger,sout.str().c_str());
126 #else
127  std::cout << sout.str().c_str() << std::endl;
128 #endif
129  continue;
130  }
131  TPZVec<int64_t> corneridx(nnos,-1);
132  int64_t id, idx;
133  for (c=0;c<nnos;c++)
134  {
135  fInputFile >> id;
136  idx = GetNodeIndex(&GMesh,id);
137  corneridx [c] = idx;
138  }
139  GMesh.CreateGeoElement(etype,corneridx,matid,id,1);
140  }
141 }
142 
143 void TPZReadMeshHR::ReadMaterials(int NMat, TPZCompMesh & CMesh) {
144  int i;
145  int id, classId;
146  for (i = 0; i < NMat; i++) {
147  fInputFile >> id >> classId;
148  if (classId == ClassIdOrHash<TPZElasticityMaterial>()) {
149  double e, nu, px, py;
150  fInputFile >> e >> nu >> px >> py;
151  TPZMaterial * mat = new TPZElasticityMaterial(id, e, nu, px, py, 0);
152  CMesh.InsertMaterialObject(mat);
153  break;
154  } else if (classId == ClassIdOrHash<TPZMat2dLin>()) {
155  TPZMat2dLin *mat2d = new TPZMat2dLin(id);
156  int nstate;
157  fInputFile >> nstate;
158 
159  int ist, jst;
160  TPZFMatrix<STATE> xk(nstate, nstate, 1.), xc(nstate, nstate, 0.), xf(nstate, 1, 0.);
161  //xk
162  for (ist = 0; ist < nstate; ist++) {
163  fInputFile >> xf(ist, 0);
164  }
165  //xc
166  for (ist = 0; ist < nstate; ist++) {
167  for (jst = 0; jst < nstate; jst++) {
168  fInputFile >> xc(ist, jst);
169  }
170  }
171  //xf
172  for (ist = 0; ist < nstate; ist++) {
173  for (jst = 0; jst < nstate; jst++) {
174  fInputFile >> xk(ist, jst);
175  }
176  }
177  mat2d->SetMaterial(xk, xc, xf);
178  TPZMaterial * mat = mat2d;
179  CMesh.InsertMaterialObject(mat);
180  break;
181  } else if (classId == ClassIdOrHash<TPZMatPoisson3d>()) {
182  TPZMatPoisson3d *mat3d = new TPZMatPoisson3d(id, 3);
183  int nstate;
184  fInputFile >> nstate;
185  int ist;
186  REAL diff, conv;
187  TPZVec<REAL> dir(3, 0.);
188  fInputFile >> diff >> conv;
189  for (ist = 0; ist < 3; ist++) {
190  fInputFile >> dir[ist];
191  }
192  mat3d->SetParameters(diff, conv, dir);
193  TPZMaterial * mat = mat3d;
194  CMesh.InsertMaterialObject(mat);
195  break;
196  } else {
197  std::stringstream sout;
198  sout << "Could not identify material of type: " << classId
199  << " check material identifier for material " << i;
200 #ifdef LOG4CXX
201  LOGPZ_FATAL(logger, sout.str().c_str());
202 #endif
203  std::cout << sout.str().c_str() << std::endl;
204  DebugStop();
205  break;
206  }
207  }
208 }
209 
210 void TPZReadMeshHR::ReadBCs (int NMat, TPZCompMesh & CMesh)
211 {
212  int i;
213  int id, type;
214  if(!CMesh.MaterialVec().size())
215  {
216  std::stringstream sout;
217 #ifndef WINDOWS
218  sout << __PRETTY_FUNCTION__ << " no materials " << std::endl;
219 #endif
220  sout << "\tN� encontrei material na malha!";
221 #ifdef LOG4CXX
222  LOGPZ_ERROR (logger, sout.str().c_str());
223 #else
224  std::cout << sout.str().c_str() << std::endl;
225 #endif
226  return;
227  }
228  std::map<int, TPZMaterial * >::iterator matit = CMesh.MaterialVec().begin();
229  TPZMaterial * mat = matit->second;
230  if(!mat)
231  {
232  std::cout << " empty material " << std::endl;
233  return;
234  }
235 
236 
237  for (i=0;i<NMat;i++)
238  {
239  fInputFile >> id >> type;
240  TPZFMatrix<STATE> val1(3,3,0.),val2(3,1,0.);
241  fInputFile >> val1 (0,0) >> val1(0,1) >> val1(0,2)
242  >> val1 (1,0) >> val1(1,1) >> val1(1,2)
243  >> val1 (2,0) >> val1(2,1) >> val1(2,2);
244  fInputFile >> val2(0,0) >> val2(1,0) >> val2(2,0);
245  TPZMaterial * bnd;
246  bnd = mat->CreateBC (mat,id,type,val1,val2);
247  CMesh.InsertMaterialObject(bnd);
248  }
249 }
250 
251 int64_t TPZReadMeshHR::GetNodeIndex(TPZGeoMesh *GMesh,int64_t Id)
252 {
253  TPZAdmChunkVector<TPZGeoNode> nodeVec = GMesh->NodeVec();
254  int64_t vid,index,size = nodeVec.NElements();
255  if (Id < size) index = Id;
256  else index = size - 1;
257  vid = nodeVec[index].Id();
258  if (vid == Id) return index;
259 
260  int64_t i;
261  for (i=index-1;i>-1;i--)
262  {
263  vid = nodeVec[i].Id();
264  if (vid == Id) return i;
265  }
266  std::stringstream sout;
267 #ifndef WINDOWS
268  sout << __PRETTY_FUNCTION__;
269 #endif
270  sout << " N�" << Id << " n� encontrado!";
271 #ifdef LOG4CXX
272  LOGPZ_WARN (logger, sout.str().c_str());
273 #else
274  std::cout << sout.str().c_str() << std::endl;
275 #endif
276 
277  return -1;
278 }
279 
281 {
282  TPZGeoMesh *gmesh = new TPZGeoMesh;
283  std::string numberOf;
284  removeComents (numberOf);
285  int64_t nnos = atoi (numberOf.c_str());
286  ReadNodes (nnos, *gmesh);
287  removeComents (numberOf);
288  int64_t nelem = atoi (numberOf.c_str());
289  ReadElements(nelem, *gmesh);
290  gmesh->BuildConnectivity();
291  return gmesh;
292 }
int AllocateNewElement()
Makes more room for new elements.
Definition: pzadmchunk.h:184
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 void ReadBCs(int NMat, TPZCompMesh &CMesh)
Read the boundary conditions.
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
virtual ~TPZReadMeshHR()
Default Destructor.
TPZReadMeshHR(const char *inFile)
Default Constructor.
virtual void ReadNodes(int64_t NNos, TPZGeoMesh &GMesh)
Read the nodes data.
Contains declaration of TPZCompEl class which defines the interface of a computational element...
Virtual class that implements the interface for build a computational mesh from a file...
Definition: pzreadmesh.h:24
int64_t NElements() const
Access method to query the number of elements of the vector.
#define LOGPZ_WARN(A, B)
Define log for warnings.
Definition: pzlog.h:91
Contains the TPZMatPoisson3d class.
virtual void ReadElements(int64_t NElem, TPZGeoMesh &GMesh)
Read the elements data.
#define LOGPZ_FATAL(A, B)
Define log for fatal errors (cout)
Definition: pzlog.h:95
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
void removeComents(std::string &NumberOf)
Remove the coments and return the integer parameter of the first line without comment token...
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
virtual void SetParameters(STATE diff, REAL conv, TPZVec< REAL > &convdir)
Definition: pzpoisson3d.cpp:78
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
TPZGeoMesh * readGeoMesh()
Contains the TPZElasticityMaterial class which implements a two dimensional elastic material in plane...
virtual TPZCompMesh * ReadMesh()
Read and return the mesh from a given file.
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
virtual void AutoBuild(const std::set< int > *MaterialIDs)
Creates the computational elements, and the degree of freedom nodes.
Definition: pzcmesh.cpp:308
Contains the TPZMat2dLin class which implements a bi-dimensional linear problem.
#define LOGPZ_ERROR(A, B)
Define log for errors (cout)
Definition: pzlog.h:93
Contains declaration of TPZCompMesh class which is a repository for computational elements...
void SetMaterial(TPZFMatrix< STATE > &xkin, TPZFMatrix< STATE > &xcin, TPZFMatrix< STATE > &xfin)
Definition: pzmat2dlin.h:44
virtual void ReadMaterials(int NMat, TPZCompMesh &CMesh)
Read the material data.
std::map< int,TPZMaterial *> & MaterialVec()
Returns a reference to the material pointers vector.
Definition: pzcmesh.h:203
void BuildConnectivity()
Build the connectivity of the grid.
Definition: pzgmesh.cpp:967
virtual TPZBndCond * CreateBC(TPZMaterial *reference, int id, int typ, TPZFMatrix< STATE > &val1, TPZFMatrix< STATE > &val2)
Creates an object TPZBndCond derived of TPZMaterial.
int InsertMaterialObject(TPZMaterial *mat)
Insert a material object in the datastructure.
Definition: pzcmesh.cpp:287
DESCRIBE PLEASE.
Definition: pzpoisson3d.h:26
Contains the TPZReadMeshHR class which reads a mesh in a "human readable" format. ...
Implements a geometric node in the pz environment. Geometry.
Definition: pzgnode.h:31
int64_t GetNodeIndex(TPZGeoMesh *GMesh, int64_t Id)
Translate a node id to a node index.
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
MElementType
Define the element types.
Definition: pzeltype.h:52
Implements a bi-dimensional linear problem.
Definition: pzmat2dlin.h:22
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
Definition: pzeltype.h:61
This class implements a two dimensional elastic material in plane stress or strain.
Definition: pzelasmat.h:19
Definition: pzeltype.h:55
std::ifstream fInputFile
Input file.
Definition: pzreadmesh.h:41