NLMech  0.1.0
mesh.h
1 // Copyright (c) 2019 Prashant K. Jha
3 // Copyright (c) 2019 Patrick Diehl
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 
9 #ifndef FE_MESH_H
10 #define FE_MESH_H
11 
12 #include "util/point.h" // definition of struct Point3
13 #include <hpx/config.hpp>
14 #include <string>
15 #include <vector>
16 
17 // forward declaration of geometry deck
18 namespace inp {
19 struct MeshDeck;
20 }
21 
30 namespace fe {
31 
49 class Mesh {
50 
51 public:
52 
56  Mesh();
57 
63  explicit Mesh(size_t dim = 0);
64 
75  explicit Mesh(inp::MeshDeck *deck);
76 
86  size_t getDimension() const { return d_dim; };
87 
92  size_t getNumNodes() const { return d_numNodes; };
93 
98  size_t getNumElements() const { return d_enc.size()/d_eNumVertex; };
99 
104  size_t getNumDofs() const { return d_numDofs; };
105 
110  size_t getElementType() const { return d_eType; };
111 
116  double getMeshSize() const { return d_h; };
117 
123  util::Point3 getNode(const size_t &i) const { return d_nodes[i]; };
124 
130  double getNodalVolume(const size_t &i) const { return d_vol[i]; };
131 
136  const std::vector<util::Point3> &getNodes() const { return d_nodes; };
137  std::vector<util::Point3> &getNodes() { return d_nodes; };
138 
143  const std::vector<util::Point3> *getNodesP() const { return &d_nodes; };
144  std::vector<util::Point3> *getNodesP() { return &d_nodes; };
145 
150  const std::vector<uint8_t> *getFixityP() const { return &d_fix; };
151  std::vector<uint8_t> *getFixityP() { return &d_fix; };
152 
157  const std::vector<uint8_t> &getFixity() const { return d_fix; };
158  std::vector<uint8_t> &getFixity() { return d_fix; };
159 
164  const std::vector<double> &getNodalVolumes() const { return d_vol; };
165  std::vector<double> &getNodalVolumes() { return d_vol; };
166 
171  const std::vector<double> *getNodalVolumesP() const { return &d_vol; };
172  std::vector<double> *getNodalVolumesP() { return &d_vol; };
173 
178  const std::vector<size_t> getPrescribedNodes() const {return d_prescribed_nodes;};
179  std::vector<size_t> getPrescribedNodes() {return d_prescribed_nodes;};
180 
185  const std::vector<util::Point3> getPrescribedValues() const {return d_prescribed_values;};
186  std::vector<util::Point3> getPrescribedValues() {return d_prescribed_values;};
187 
194  bool isNodeFree(const size_t &i, const unsigned int &dof) const {
195 
196  // below checks if d_fix has 1st bit (if dof=0), 2nd bit (if dof=1), 3rd
197  // bit (if dof=2) is set to 1 or 0. If set to 1, then it means it is fixed,
198  // and therefore it returns false
199  return !(d_fix[i] >> dof & 1UL);
200  };
201 
216  std::vector<size_t> getElementConnectivity(const size_t &i) const {
217  return std::vector<size_t>(d_enc.begin() + d_eNumVertex * i,
218  d_enc.begin() + d_eNumVertex * i + d_eNumVertex);
219  };
220 
227  std::vector<util::Point3> getElementConnectivityNodes(const size_t
228  &i) const {
229  std::vector<util::Point3> nds;
230  for (size_t k = 0; k < d_eNumVertex; k++)
231  nds.emplace_back(d_nodes[d_enc[d_eNumVertex * i + k]]);
232  return nds;
233  };
234 
239  const std::vector<size_t> &getElementConnectivities() const {
240  return d_enc;
241  };
242  std::vector<size_t> &getElementConnectivities() {
243  return d_enc;
244  };
245 
250  const std::vector<size_t> *getElementConnectivitiesP() const {
251  return &d_enc;
252  };
253  std::vector<size_t> *getElementConnectivitiesP() {
254  return &d_enc;
255  };
256 
261  const std::pair<std::vector<double>, std::vector<double>> &getBoundingBox()
262  const {
263  return d_bbox;
264  };
265 
266 
281  void setMeshData(const size_t &dim, std::vector<util::Point3> &nodes,
282  std::vector<double> &volumes);
283 
288  void setNodes(std::vector<util::Point3> &nodes);
289 
294  void setNodalVolumes(std::vector<double> &volumes);
295 
300  void setFixity(std::vector<uint8_t> &fixity);
301 
308  void setFixity(const size_t &i, const unsigned int &dof, const bool &flag);
309 
314  void setMeshSize(const double &h);
315 
322  void readFromFile(inp::MeshDeck *deck, const std::string &filename);
323 
327  void clearElementData();
328 
340  std::string printStr(int nt = 0, int lvl = 0) const;
341 
349  void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); };
350 
351 private:
373  void createData(const std::string &filename, bool ref_config, bool is_centroid_based, bool has_coupling_data);
374 
379  void nodesAtCentroid();
380 
391  void computeVol();
392 
394  void computeBBox();
395 
402  void computeMeshSize();
403 
412  size_t d_numNodes;
413 
415  size_t d_numElems;
416 
426  size_t d_eType;
427 
441  size_t d_eNumVertex;
442 
444  std::vector<util::Point3> d_nodes;
445 
452  std::vector<size_t> d_enc;
453 
458  std::vector<std::vector<size_t>> d_nec;
459 
468  std::vector<uint8_t> d_fix;
469 
476  std::vector<double> d_vol;
477 
483  std::vector<size_t> d_prescribed_nodes;
484 
485 
491  std::vector<util::Point3> d_prescribed_values;
492 
496  size_t d_dim;
497 
507 
509  std::string d_filename;
510 
512  size_t d_numDofs;
513 
526  std::vector<size_t> d_gMap;
527 
532  std::vector<int> d_gInvMap;
533 
538  std::pair<std::vector<double>, std::vector<double>> d_bbox;
539 
541  double d_h;
542 
545 };
546 
547 } // namespace fe
548 
549 #endif // FE_MESH_H
A class for mesh data.
Definition: mesh.h:49
void setMeshSize(const double &h)
Set the mesh size.
Definition: mesh.cpp:406
const std::vector< size_t > getPrescribedNodes() const
Get the vector of indicies with prescribed values from the couplign method.
Definition: mesh.h:178
double getMeshSize() const
Get the mesh size.
Definition: mesh.h:116
std::vector< double > d_vol
Vector of volume of each node.
Definition: mesh.h:476
std::string d_spatialDiscretization
Tag for spatial discretization type.
Definition: mesh.h:506
const std::vector< uint8_t > & getFixity() const
Get the reference to fixity data.
Definition: mesh.h:157
const std::pair< std::vector< double >, std::vector< double > > & getBoundingBox() const
Get the bounding box of the mesh.
Definition: mesh.h:261
const std::vector< size_t > & getElementConnectivities() const
Get the reference to element-node connectivity data.
Definition: mesh.h:239
const std::vector< util::Point3 > * getNodesP() const
Get the pointer to nodes data.
Definition: mesh.h:143
double d_h
Mesh size.
Definition: mesh.h:541
std::vector< size_t > getElementConnectivity(const size_t &i) const
Get the connectivity of element.
Definition: mesh.h:216
bool d_keepElementConn
Specify if we keep the element connectivity data.
Definition: mesh.h:544
void setNodalVolumes(std::vector< double > &volumes)
Set the nodal volume data of the mesh.
Definition: mesh.cpp:385
const std::vector< double > & getNodalVolumes() const
Get the nodal volume data.
Definition: mesh.h:164
bool isNodeFree(const size_t &i, const unsigned int &dof) const
Return true if node is free.
Definition: mesh.h:194
size_t d_dim
Dimension of the mesh.
Definition: mesh.h:496
void setMeshData(const size_t &dim, std::vector< util::Point3 > &nodes, std::vector< double > &volumes)
Set the mesh data for finite difference simulations.
Definition: mesh.cpp:356
const std::vector< uint8_t > * getFixityP() const
Get the pointer to fixity data.
Definition: mesh.h:150
std::vector< uint8_t > d_fix
Vector of fixity mask of each node.
Definition: mesh.h:468
void computeBBox()
Compute the bounding box
Definition: mesh.cpp:311
double getNodalVolume(const size_t &i) const
Get nodal volume of node i.
Definition: mesh.h:130
void nodesAtCentroid()
Converts standard fem mesh to particle mesh with nodes at the center of element.
Definition: mesh.cpp:448
void readFromFile(inp::MeshDeck *deck, const std::string &filename)
Reads mesh data from the file and populates other data.
Definition: mesh.cpp:414
size_t d_numElems
Number of elements.
Definition: mesh.h:415
void clearElementData()
Clear element-node connectivity data.
Definition: mesh.cpp:408
size_t getElementType() const
Get the type of element in mesh.
Definition: mesh.h:110
const std::vector< util::Point3 > & getNodes() const
Get the nodes data.
Definition: mesh.h:136
const std::vector< double > * getNodalVolumesP() const
Get the pointer to nodal volume data.
Definition: mesh.h:171
std::pair< std::vector< double >, std::vector< double > > d_bbox
Bounding box.
Definition: mesh.h:538
void computeMeshSize()
Compute the mesh size.
Definition: mesh.cpp:326
size_t d_eType
Element type.
Definition: mesh.h:426
const std::vector< size_t > * getElementConnectivitiesP() const
Get the pointer to element-node connectivity data.
Definition: mesh.h:250
std::string d_filename
Filename to read mesh data.
Definition: mesh.h:509
std::vector< util::Point3 > d_prescribed_values
Vector with the values of all nodes with prescribed boundary data.
Definition: mesh.h:491
std::vector< std::vector< size_t > > d_nec
Node-element connectivity data.
Definition: mesh.h:458
std::vector< size_t > d_enc
Element-node connectivity data.
Definition: mesh.h:452
std::vector< util::Point3 > getElementConnectivityNodes(const size_t &i) const
Get the vertices of element.
Definition: mesh.h:227
void createData(const std::string &filename, bool ref_config, bool is_centroid_based, bool has_coupling_data)
Reads mesh data from the file and populates other data.
Definition: mesh.cpp:102
size_t d_numNodes
Number of nodes.
Definition: mesh.h:412
std::vector< util::Point3 > d_nodes
Vector of initial (reference) coordinates of nodes.
Definition: mesh.h:444
size_t d_eNumVertex
Number of vertex per element.
Definition: mesh.h:441
size_t getNumNodes() const
Get the number of nodes.
Definition: mesh.h:92
void print(int nt=0, int lvl=0) const
Prints the information about the instance of the object.
Definition: mesh.h:349
size_t getNumElements() const
Get the number of elements.
Definition: mesh.h:98
std::vector< size_t > d_gMap
Map from global reduced id to default global id.
Definition: mesh.h:526
std::vector< size_t > d_prescribed_nodes
Vector with the indicies of all nodes with prescribed boundary data.
Definition: mesh.h:483
size_t getDimension() const
Get the dimension of the domain.
Definition: mesh.h:86
void setFixity(std::vector< uint8_t > &fixity)
Set nodal fixity masks.
Definition: mesh.cpp:390
const std::vector< util::Point3 > getPrescribedValues() const
Get the vector of values of the prescribed nodes from the couplign method.
Definition: mesh.h:185
void computeVol()
Compute the nodal volume.
Definition: mesh.cpp:231
util::Point3 getNode(const size_t &i) const
Get coordinates of node i.
Definition: mesh.h:123
void setNodes(std::vector< util::Point3 > &nodes)
Set the nodal data of the mesh.
Definition: mesh.cpp:379
Mesh()
Constructor.
std::vector< int > d_gInvMap
Map from global id to reduced global id.
Definition: mesh.h:532
size_t getNumDofs() const
Get the number of dofs.
Definition: mesh.h:104
size_t d_numDofs
Number of dofs = (dimension) times (number of nodes)
Definition: mesh.h:512
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing information about the instance of the object.
Definition: mesh.cpp:428
Collection of methods and data related to finite element and mesh.
Definition: baseElem.h:15
Collection of methods and database related to input.
Definition: main.cpp:21
Structure to read and store mesh related input data.
Definition: meshDeck.h:23
A structure to represent 3d vectors.
Definition: point.h:29