PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
mesh.h
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2024 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#ifndef FE_MESH_H
12#define FE_MESH_H
13
14#include "util/point.h" // definition of struct Point
15#include <cstdint> // uint8_t type
16#include <cstring> // string and size_t type
17#include <vector>
18
19// forward declaration of geometry deck
20namespace inp {
21struct MeshDeck;
22}
23
32namespace fe {
33
51class Mesh {
52
53public:
59 explicit Mesh(size_t dim = 0);
60
71 explicit Mesh(inp::MeshDeck *deck);
72
82 size_t getDimension() const { return d_dim; };
83
88 size_t getNumNodes() const { return d_numNodes; };
89
94 size_t getNumElements() const { return d_enc.size()/d_eNumVertex; };
95
100 size_t getNumDofs() const { return d_numDofs; };
101
106 size_t getElementType() const { return d_eType; };
107
112 double getMeshSize() const { return d_h; };
113
119 util::Point getNode(const size_t &i) const { return d_nodes[i]; };
120
126 double getNodalVolume(const size_t &i) const { return d_vol[i]; };
127
132 const std::vector<util::Point> &getNodes() const { return d_nodes; };
133
135 std::vector<util::Point> &getNodes() { return d_nodes; };
136
141 const std::vector<util::Point> *getNodesP() const { return &d_nodes; };
142
144 std::vector<util::Point> *getNodesP() { return &d_nodes; };
145
150 const std::vector<uint8_t> *getFixityP() const { return &d_fix; };
151
153 std::vector<uint8_t> *getFixityP() { return &d_fix; };
154
159 const std::vector<uint8_t> &getFixity() const { return d_fix; };
160
162 std::vector<uint8_t> &getFixity() { return d_fix; };
163
168 const std::vector<double> &getNodalVolumes() const { return d_vol; };
169
171 std::vector<double> &getNodalVolumes() { return d_vol; };
172
177 const std::vector<double> *getNodalVolumesP() const { return &d_vol; };
178
180 std::vector<double> *getNodalVolumesP() { return &d_vol; };
181
188 bool isNodeFree(const size_t &i, const unsigned int &dof) const {
189
190 // below checks if d_fix has 1st bit (if dof=0), 2nd bit (if dof=1), 3rd
191 // bit (if dof=2) is set to 1 or 0. If set to 1, then it means it is fixed,
192 // and therefore it returns false
193 return !(d_fix[i] >> dof & 1UL);
194 };
195
210 std::vector<size_t> getElementConnectivity(const size_t &i) const {
211 return std::vector<size_t>(d_enc.begin() + d_eNumVertex * i,
212 d_enc.begin() + d_eNumVertex * i + d_eNumVertex);
213 };
214
221 std::vector<util::Point> getElementConnectivityNodes(const size_t
222 &i) const {
223 std::vector<util::Point> nds;
224 for (size_t k = 0; k < d_eNumVertex; k++)
225 nds.emplace_back(d_nodes[d_enc[d_eNumVertex * i + k]]);
226 return nds;
227 };
228
233 const std::vector<size_t> &getElementConnectivities() const {
234 return d_enc;
235 };
236
238 std::vector<size_t> &getElementConnectivities() {
239 return d_enc;
240 };
241
246 const std::vector<size_t> *getElementConnectivitiesP() const {
247 return &d_enc;
248 };
249
251 std::vector<size_t> *getElementConnectivitiesP() {
252 return &d_enc;
253 };
254
259 const std::pair<std::vector<double>, std::vector<double>> &getBoundingBox()
260 const {
261 return d_bbox;
262 };
263
265 std::pair<std::vector<double>, std::vector<double>> &getBoundingBox() {
266 return d_bbox;
267 };
268
282 void setFixity(const size_t &i, const unsigned int &dof, const bool &flag);
283
287 void clearElementData();
288
298 std::string printStr(int nt = 0, int lvl = 0) const;
299
306 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); };
307
308public:
329 void createData(const std::string &filename, bool ref_config = false);
330
342 bool readElementData(const std::string &filename);
343
354 void computeVol();
355
357 void computeBBox();
358
365 void computeMeshSize();
366
376
379
389 size_t d_eType;
390
405
407 std::vector<util::Point> d_nodes;
408
415 std::vector<size_t> d_enc;
416
421 std::vector<std::vector<size_t>> d_nec;
422
431 std::vector<uint8_t> d_fix;
432
439 std::vector<double> d_vol;
440
449 size_t d_nPart;
450
454 std::string d_partitionMethod;
455
463 std::vector<size_t> d_nodePartition;
464
468 size_t d_dim;
469
479
481 std::string d_filename;
482
485
488
490 size_t d_numDofs;
491
504 std::vector<size_t> d_gMap;
505
510 std::vector<int> d_gInvMap;
511
513 std::pair<std::vector<double>, std::vector<double>> d_bbox;
514
516 double d_h;
517};
518
519} // namespace fe
520
521#endif // FE_MESH_H
A class for mesh data.
Definition mesh.h:51
std::vector< util::Point > d_nodes
Vector of initial (reference) coordinates of nodes.
Definition mesh.h:407
double getMeshSize() const
Get the mesh size.
Definition mesh.h:112
std::vector< double > d_vol
Vector of volume of each node.
Definition mesh.h:439
std::vector< size_t > & getElementConnectivities()
Get the reference to element-node connectivity data.
Definition mesh.h:238
std::string d_spatialDiscretization
Tag for spatial discretization type.
Definition mesh.h:478
const std::pair< std::vector< double >, std::vector< double > > & getBoundingBox() const
Get the bounding box of the mesh.
Definition mesh.h:259
std::vector< uint8_t > & getFixity()
Get the reference to fixity data.
Definition mesh.h:162
double d_h
Mesh size.
Definition mesh.h:516
std::vector< size_t > d_nodePartition
Node partition information. For each node i, d_nodePartition[i] specifies the partition number,...
Definition mesh.h:463
const std::vector< uint8_t > & getFixity() const
Get the reference to fixity data.
Definition mesh.h:159
bool readElementData(const std::string &filename)
Reads element-node connectivity data from file. This function is meant for cases when mesh was create...
Definition mesh.cpp:203
std::vector< util::Point > & getNodes()
Get the nodes data.
Definition mesh.h:135
bool isNodeFree(const size_t &i, const unsigned int &dof) const
Return true if node is free.
Definition mesh.h:188
size_t d_nPart
Number of partitions.
Definition mesh.h:449
const std::vector< double > * getNodalVolumesP() const
Get the pointer to nodal volume data.
Definition mesh.h:177
size_t d_dim
Dimension of the mesh.
Definition mesh.h:468
std::vector< double > * getNodalVolumesP()
Get the pointer to nodal volume data.
Definition mesh.h:180
const std::vector< util::Point > & getNodes() const
Get the nodes data.
Definition mesh.h:132
std::vector< uint8_t > d_fix
Vector of fixity mask of each node.
Definition mesh.h:431
void computeBBox()
Compute the bounding box
Definition mesh.cpp:332
double getNodalVolume(const size_t &i) const
Get nodal volume of node i.
Definition mesh.h:126
std::vector< util::Point > getElementConnectivityNodes(const size_t &i) const
Get the vertices of element.
Definition mesh.h:221
size_t d_numElems
Number of elements.
Definition mesh.h:378
void clearElementData()
Clear element-node connectivity data.
Definition mesh.cpp:396
size_t getElementType() const
Get the type of element in mesh.
Definition mesh.h:106
util::Point getNode(const size_t &i) const
Get coordinates of node i.
Definition mesh.h:119
std::pair< std::vector< double >, std::vector< double > > d_bbox
Bounding box.
Definition mesh.h:513
void computeMeshSize()
Compute the mesh size.
Definition mesh.cpp:353
size_t d_eType
Element type.
Definition mesh.h:389
std::string d_partitionMethod
Partitioning method. It could be either empty string or "metis_recursive" or "metis_kway".
Definition mesh.h:454
std::string d_filename
Filename to read mesh data.
Definition mesh.h:481
std::vector< double > & getNodalVolumes()
Get the nodal volume data.
Definition mesh.h:171
std::vector< uint8_t > * getFixityP()
Get the pointer to fixity data.
Definition mesh.h:153
std::vector< std::vector< size_t > > d_nec
Node-element connectivity data.
Definition mesh.h:421
std::vector< size_t > d_enc
Element-node connectivity data.
Definition mesh.h:415
bool d_encDataPopulated
Flag that indicates whether element-node connectivity data is read from file.
Definition mesh.h:487
std::vector< size_t > * getElementConnectivitiesP()
Get the pointer to element-node connectivity data.
Definition mesh.h:251
std::vector< size_t > getElementConnectivity(const size_t &i) const
Get the connectivity of element.
Definition mesh.h:210
const std::vector< size_t > & getElementConnectivities() const
Get the reference to element-node connectivity data.
Definition mesh.h:233
std::pair< std::vector< double >, std::vector< double > > & getBoundingBox()
Get the bounding box of the mesh.
Definition mesh.h:265
size_t d_numNodes
Number of nodes.
Definition mesh.h:375
size_t d_eNumVertex
Number of vertex per element.
Definition mesh.h:404
size_t getNumNodes() const
Get the number of nodes.
Definition mesh.h:88
bool d_needEncData
Flag that indicates whether we need enc data (set by input mesh deck in constructor)
Definition mesh.h:484
void print(int nt=0, int lvl=0) const
Prints the information about the object.
Definition mesh.h:306
const std::vector< util::Point > * getNodesP() const
Get the pointer to nodes data.
Definition mesh.h:141
size_t getNumElements() const
Get the number of elements.
Definition mesh.h:94
std::vector< size_t > d_gMap
Map from global reduced id to default global id.
Definition mesh.h:504
void setFixity(const size_t &i, const unsigned int &dof, const bool &flag)
Set the fixity to free (0) or fixed (1)
Definition mesh.cpp:385
const std::vector< size_t > * getElementConnectivitiesP() const
Get the pointer to element-node connectivity data.
Definition mesh.h:246
std::vector< util::Point > * getNodesP()
Get the pointer to nodes data.
Definition mesh.h:144
size_t getDimension() const
Get the dimension of the domain.
Definition mesh.h:82
const std::vector< double > & getNodalVolumes() const
Get the nodal volume data.
Definition mesh.h:168
void computeVol()
Compute the nodal volume.
Definition mesh.cpp:250
const std::vector< uint8_t > * getFixityP() const
Get the pointer to fixity data.
Definition mesh.h:150
std::vector< int > d_gInvMap
Map from global id to reduced global id.
Definition mesh.h:510
size_t getNumDofs() const
Get the number of dofs.
Definition mesh.h:100
void createData(const std::string &filename, bool ref_config=false)
Reads mesh data from the file and populates other data.
Definition mesh.cpp:67
size_t d_numDofs
Number of dofs = (dimension) times (number of nodes)
Definition mesh.h:490
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition mesh.cpp:404
Collection of methods and data related to finite element and mesh.
Definition baseElem.h:17
Collection of methods and database related to input.
Definition mesh.h:20
Structure to read and store mesh related input data.
Definition meshDeck.h:26
A structure to represent 3d vectors.
Definition point.h:30