AtilaCalculatorSoftware  2.3.4
C++ Interface for Atila fem resources files
mesh.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Project: AtilaCalculatorSoftware
4  File: mesh.h
5 
6  Copyright (c) 2020
7  All rights reserved.
8 
9 =========================================================================*/
10 #ifndef ATILACALCULATORSOFTWARE_MESH_H
11 #define ATILACALCULATORSOFTWARE_MESH_H
12 
13 #include "core/utilities.h"
14 #include "logger/logger.h"
15 
16 #include <algorithm>
17 #include <cmath>
18 #include <cstring>
19 #include <gidpost.h>
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <tuple>
24 #include <vector>
25 #include <zlib.h>
26 
27 #define DIM(x) x == 3 ? GiD_3D : GiD_2D
28 
29 // --------------------------------------------------------------------------------------
30 // NODE
31 // --------------------------------------------------------------------------------------
32 
38 class Node {
39  public:
44  Node(unsigned int id, const float* coord);
45 
52  Node(unsigned int id, float x, float y, float z);
53 
57  unsigned int getId() const;
58 
62  const float* getCoords();
63 
67  float getX();
68 
72  float getY();
73 
77  float getZ();
78 
79  private:
83  const unsigned int id;
84 
88  float coord[3];
89 };
90 
91 // --------------------------------------------------------------------------------------
92 // MESH
93 // --------------------------------------------------------------------------------------
94 
99 class Mesh {
100  public:
105  Mesh(gzFile file, dataFields fields);
106 
110  std::string getName();
111 
115  std::string getElementName();
116 
120  GiD_ElementType getElementType();
121 
125  unsigned int getDimCount() const;
126 
130  unsigned int getNodeCount() const;
131 
135  unsigned int getElementCount() const;
136 
140  std::vector<Node> getNodes();
141 
146  std::tuple<int&, int*> getElement(const unsigned int& id) const;
147 
148  // /**
149  // * @brief Write the mesh into a currently open PostResultFile
150  // * @return The state of the GiD Post Mesh closure
151  // */
152  // const int toPostGid();
153 
160  static GiD_ElementType getGiDElementType(const char* element);
161 
165  static size_t maxNodeCount;
166 
170  const static std::map<std::string, GiD_ElementType> GiD_ElementTypeEncoding;
171 
172  private:
178  void readCoordinates(gzFile& file, char buffer[GZ_BUFFER_SIZE]);
179 
185  void readElements(gzFile& file, char buffer[GZ_BUFFER_SIZE]);
186 
190  std::string name;
191 
195  std::string elementName;
196 
200  GiD_ElementType elementType;
201 
205  unsigned int dimCount;
206 
210  unsigned int nodeCount;
211 
215  unsigned int elementCount;
216 
220  std::vector<Node> nodes;
221 
225  int* elements;
226 
231 };
232 
233 #endif // ATILACALCULATORSOFTWARE_MESH_H
const unsigned int id
ID of the Node.
Definition: mesh.h:83
float coord[3]
Space coordinates of the node.
Definition: mesh.h:88
unsigned int getId() const
Definition: mesh.cpp:32
Point in 3D space representation, part of a Mesh.
Definition: mesh.h:38
std::vector< Node > nodes
Nodes that constitutes the mesh.
Definition: mesh.h:220
Representation of a mesh, all of its nodes and elements.
Definition: mesh.h:99
float getY()
Definition: mesh.cpp:36
std::string name
Name of the mesh.
Definition: mesh.h:190
float getZ()
Definition: mesh.cpp:37
unsigned int elementCount
Number of elements in the mesh.
Definition: mesh.h:215
int * elements
Elements of the mesh.
Definition: mesh.h:225
float getX()
Definition: mesh.cpp:35
std::string elementName
String encoded element type of the mesh.
Definition: mesh.h:195
const float * getCoords()
Definition: mesh.cpp:34
#define GZ_BUFFER_SIZE
Buffer size for gzread uses.
Definition: utilities.h:26
Node(unsigned int id, const float *coord)
Definition: mesh.cpp:16
int * elementsConnectivity
Connectivity of the elements.
Definition: mesh.h:230
unsigned int nodeCount
Number of nodes which constitutes the mesh.
Definition: mesh.h:210
static size_t maxNodeCount
Biggest number of node encountered in the mesh.
Definition: mesh.h:165
static const std::map< std::string, GiD_ElementType > GiD_ElementTypeEncoding
Map of all recognized GiD_ElementType according to their string encoded value.
Definition: mesh.h:170
GiD_ElementType elementType
Element type of the mesh.
Definition: mesh.h:200
char dataFields[10][40]
Definition: utilities.h:76
unsigned int dimCount
Number of dimensions of the object (2 or 3)
Definition: mesh.h:205