NeoPZ
TPZGeoMeshBuilder.cpp
Go to the documentation of this file.
1 //
2 // TPZGeoMeshBuilder.cpp
3 // pz
4 //
5 // Created by Omar DurĂ¡n on 2/12/19.
6 //
7 
8 #include "TPZGeoMeshBuilder.h"
9 
10 void TPZGeoMeshBuilder::InsertNodes(TPZGeoMesh * gmesh, std::vector<std::size_t> & node_identifiers, std::vector<double> & coord) {
11 
12  int64_t n_nodes = node_identifiers.size();
13  gmesh->NodeVec().Resize(n_nodes);
14  gmesh->SetMaxNodeId(n_nodes-1);
15 
16  int64_t node_id;
17  REAL nodecoordX,nodecoordY,nodecoordZ;
18 
20  TPZGeoNode node_obj;
21  for (int64_t inode = 0; inode < n_nodes; inode++) {
22 
23  node_id = node_identifiers[inode]-1; // because pz is zero based.
24  int pos = inode*3; // because the model is dwell in R3
25  nodecoordX = coord[pos];
26  nodecoordY = coord[pos+1];
27  nodecoordZ = coord[pos+2];
28 
29 
30  node_obj.SetNodeId(node_id);
31  node_obj.SetCoord(0,nodecoordX);
32  node_obj.SetCoord(1,nodecoordY);
33  node_obj.SetCoord(2,nodecoordZ);
34  gmesh->NodeVec()[node_id] = node_obj;
35  }
36 }
37 
38 void TPZGeoMeshBuilder::InsertElement(TPZGeoMesh * gmesh, int & physical_identifier, int & el_type, int & el_identifier, std::vector<int> & node_identifiers){
39 
41  int n_nodes = node_identifiers.size();
42  Topology.Resize(n_nodes, 0);
43  for (int k_node = 0; k_node<n_nodes; k_node++) {
44  Topology[k_node] = node_identifiers[k_node]-1;
45  }
46 
47  el_identifier--;
48  switch (el_type) {
49  case 1:
50  { // Line
51  new TPZGeoElRefPattern< pzgeom::TPZGeoLinear> (el_identifier, Topology, physical_identifier, *gmesh);
52  }
53  break;
54  case 2:
55  {
56  // Triangle
57  new TPZGeoElRefPattern< pzgeom::TPZGeoTriangle> (el_identifier, Topology, physical_identifier, *gmesh);
58 
59  }
60  break;
61  case 3:
62  {
63  // Quadrilateral
64  new TPZGeoElRefPattern< pzgeom::TPZGeoQuad> (el_identifier, Topology, physical_identifier, *gmesh);
65 
66  }
67  break;
68  case 4:
69  {
70  // Tetrahedron
71  new TPZGeoElRefPattern< pzgeom::TPZGeoTetrahedra> (el_identifier, Topology, physical_identifier, *gmesh);
72 
73  }
74  break;
75  case 5:
76  {
77  // Hexahedra
78  new TPZGeoElRefPattern< pzgeom::TPZGeoCube> (el_identifier, Topology, physical_identifier, *gmesh);
79  }
80  break;
81  case 6:
82  {
83  // Prism
84  new TPZGeoElRefPattern< pzgeom::TPZGeoPrism> (el_identifier, Topology, physical_identifier, *gmesh);
85  }
86  break;
87  case 7:
88  {
89  // Pyramid
90  new TPZGeoElRefPattern< pzgeom::TPZGeoPyramid> (el_identifier, Topology, physical_identifier, *gmesh);
91  }
92  break;
93  case 8:
94  {
95  // Quadratic Line
96  new TPZGeoElRefPattern< pzgeom::TPZQuadraticLine> (el_identifier, Topology, physical_identifier, *gmesh);
97  }
98  break;
99  case 9:
100  {
101  // Triangle
102  new TPZGeoElRefPattern< pzgeom::TPZQuadraticTrig> (el_identifier, Topology, physical_identifier, *gmesh);
103  }
104  break;
105  case 10:
106  {
107  // Quadrilateral
108  new TPZGeoElRefPattern< pzgeom::TPZQuadraticQuad> (el_identifier, Topology, physical_identifier, *gmesh);
109  }
110  break;
111  case 11:
112  {
113  // Tetrahedron
114  new TPZGeoElRefPattern< pzgeom::TPZQuadraticTetra> (el_identifier, Topology, physical_identifier, *gmesh);
115 
116  }
117  break;
118  case 12:
119  {
120  // Hexahedra
121  new TPZGeoElRefPattern< pzgeom::TPZQuadraticCube> (el_identifier, Topology, physical_identifier, *gmesh);
122  }
123  break;
124  case 13:
125  {
126  // Prism
127  new TPZGeoElRefPattern< pzgeom::TPZQuadraticPrism> (el_identifier, Topology, physical_identifier, *gmesh);
128  }
129  break;
130  case 15:{
131  // Point
132  new TPZGeoElement< pzgeom::TPZGeoPoint, pzrefine::TPZRefPoint> (el_identifier, Topology, physical_identifier, *gmesh);
133  }
134  break;
135  default:
136  {
137  std::cout << "Element not impelemented." << std::endl;
138  DebugStop();
139  }
140  break;
141  }
142 
143 }
144 
146 
147  int n_nodes;
148  switch (el_type) {
149  case 1:
150  { // Line
151  n_nodes = 2;
152  }
153  break;
154  case 2:
155  {
156  // Triangle
157  n_nodes = 3;
158  }
159  break;
160  case 3:
161  {
162  // Quadrilateral
163  n_nodes = 4;
164  }
165  break;
166  case 4:
167  {
168  // Tetrahedron
169  n_nodes = 4;
170  }
171  break;
172  case 5:
173  {
174  // Hexahedra
175  n_nodes = 8;
176  }
177  break;
178  case 6:
179  {
180  // Prism
181  n_nodes = 6;
182  }
183  break;
184  case 7:
185  {
186  // Pyramid
187  n_nodes = 5;
188  }
189  break;
190  case 8:
191  {
192  // Quadratic Line
193  n_nodes = 3;
194  }
195  break;
196  case 9:
197  {
198  // Quadratic Triangle
199  n_nodes = 6;
200  }
201  break;
202  case 10:
203  {
204  // Quadratic Quadrilateral
205  n_nodes = 8;
206  }
207  break;
208  case 11:
209  {
210  // Quadratic Tetrahedron
211  n_nodes = 10;
212 
213  }
214  break;
215  case 12:
216  {
217  // Quadratic Hexahedra
218  n_nodes = 20;
219  }
220  break;
221  case 13:
222  {
223  // Quadratic Prism
224  n_nodes = 15;
225  }
226  break;
227  case 15:{
228  // Point
229  n_nodes = 1;
230  }
231  break;
232  default:
233  {
234  std::cout << "Element not impelemented." << std::endl;
235  n_nodes = 0;
236  DebugStop();
237  }
238  break;
239  }
240 
241  return n_nodes;
242 }
243 
244 void TPZGeoMeshBuilder::PrintGeometry(TPZGeoMesh * gmesh, std::string & name){
245 
246  std::stringstream text_name;
247  std::stringstream vtk_name;
248  text_name << name.c_str() << ".txt";
249  vtk_name << name.c_str() << ".vtk";
250  std::ofstream textfile(text_name.str().c_str());
251  gmesh->Print(textfile);
252  std::ofstream vtkfile(vtk_name.str().c_str());
253  TPZVTKGeoMesh::PrintGMeshVTK(gmesh, vtkfile, true);
254 }
static void InsertElement(TPZGeoMesh *gmesh, int &physical_identifier, int &el_type, int &el_identifier, std::vector< int > &node_identifiers)
void SetCoord(const TPZVec< REAL > &x)
Sets all coordinates into the current node. It gets the dim values from x.
Definition: pzgnode.cpp:60
Implements a vector class which allows to use external storage provided by the user. Utility.
Definition: pzquad.h:16
Implements a generic geometric element with a uniform refinement pattern. Geometry.
Definition: TPZGeoElement.h:22
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
static void InsertNodes(TPZGeoMesh *gmesh, std::vector< std::size_t > &node_identifiers, std::vector< double > &coord)
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
void Resize(const int newsize)
Increase the size of the chunk vector.
Definition: pzadmchunk.h:280
void SetMaxNodeId(int64_t id)
Used in patch meshes.
Definition: pzgmesh.h:120
virtual void Print(std::ostream &out=std::cout) const
Print the information of the grid to an ostream.
Definition: pzgmesh.cpp:130
Implements a generic geometric element which is refined according to a generic refinement pattern...
Definition: pzgmesh.h:35
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
static void PrintGeometry(TPZGeoMesh *gmesh, std::string &name)
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
static void PrintGMeshVTK(TPZGeoMesh *gmesh, std::ofstream &file, bool matColor=true)
Default constructor for graphical mesh with VTK format.
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
static int GetNumberofNodes(int &el_type)
void SetNodeId(int id)
Definition: pzgnode.h:73