PeriDEM 0.3.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 - 2026 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 <string>
18#include <vector>
19
20// forward declaration of geometry deck
21namespace inp {
22struct MeshDeck;
23struct ModelDeck;
24}
25
34namespace mesh {
35
53class Mesh {
54
55public:
61 explicit Mesh(size_t dim = 0);
62
74 explicit Mesh(const inp::MeshDeck *meshDeck, const inp::ModelDeck *modelDeck);
75
85 size_t getDimension() const { return d_dim; };
86
91 size_t getNumNodes() const { return d_numNodes; };
92
97 size_t getNumElements() const { return d_enc.size()/d_eNumVertex; };
98
103 size_t getNumDofs() const { return d_numDofs; };
104
109 size_t getElementType() const { return d_eType; };
110
115 double getMeshSize() const { return d_h; };
116
122 util::Point getNode(const size_t &i) const { return d_nodes[i]; };
123
129 double getNodalVolume(const size_t &i) const { return d_vol[i]; };
130
135 const std::vector<util::Point> &getNodes() const { return d_nodes; };
136
138 std::vector<util::Point> &getNodes() { return d_nodes; };
139
144 const std::vector<util::Point> *getNodesP() const { return &d_nodes; };
145
147 std::vector<util::Point> *getNodesP() { return &d_nodes; };
148
153 const std::vector<uint8_t> *getFixityP() const { return &d_fix; };
154
156 std::vector<uint8_t> *getFixityP() { return &d_fix; };
157
162 const std::vector<uint8_t> &getFixity() const { return d_fix; };
163
165 std::vector<uint8_t> &getFixity() { return d_fix; };
166
171 const std::vector<double> &getNodalVolumes() const { return d_vol; };
172
174 std::vector<double> &getNodalVolumes() { return d_vol; };
175
180 const std::vector<double> *getNodalVolumesP() const { return &d_vol; };
181
183 std::vector<double> *getNodalVolumesP() { return &d_vol; };
184
191 bool isNodeFree(const size_t &i, const unsigned int &dof) const {
192
193 // below checks if d_fix has 1st bit (if dof=0), 2nd bit (if dof=1), 3rd
194 // bit (if dof=2) is set to 1 or 0. If set to 1, then it means it is fixed,
195 // and therefore it returns false
196 return !(d_fix[i] >> dof & 1UL);
197 };
198
213 std::vector<size_t> getElementConnectivity(const size_t &i) const {
214 return std::vector<size_t>(d_enc.begin() + d_eNumVertex * i,
215 d_enc.begin() + d_eNumVertex * i + d_eNumVertex);
216 };
217
224 std::vector<util::Point> getElementConnectivityNodes(const size_t
225 &i) const {
226 std::vector<util::Point> nds;
227 for (size_t k = 0; k < d_eNumVertex; k++)
228 nds.emplace_back(d_nodes[d_enc[d_eNumVertex * i + k]]);
229 return nds;
230 };
231
236 const std::vector<size_t> &getElementConnectivities() const {
237 return d_enc;
238 };
239
241 std::vector<size_t> &getElementConnectivities() {
242 return d_enc;
243 };
244
249 const std::vector<size_t> *getElementConnectivitiesP() const {
250 return &d_enc;
251 };
252
254 std::vector<size_t> *getElementConnectivitiesP() {
255 return &d_enc;
256 };
257
262 const std::pair<std::vector<double>, std::vector<double>> &getBoundingBox()
263 const {
264 return d_bbox;
265 };
266
268 std::pair<std::vector<double>, std::vector<double>> &getBoundingBox() {
269 return d_bbox;
270 };
271
285 void setFixity(const size_t &i, const unsigned int &dof, const bool &flag);
286
290 void clearElementData();
291
301 std::string printStr(int nt = 0, int lvl = 0) const;
302
309 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); };
310
311public:
332 void createData(const std::string &filename, bool ref_config = false);
333
340 void loadFromTriangleElements2D(std::vector<util::Point> nodes,
341 std::vector<size_t> enc,
342 const inp::MeshDeck *meshDeck,
343 const inp::ModelDeck *modelDeck);
344
348 void loadFromTetraElements3D(std::vector<util::Point> nodes,
349 std::vector<size_t> enc,
350 const inp::MeshDeck *meshDeck,
351 const inp::ModelDeck *modelDeck);
352
364 bool readElementData(const std::string &filename);
365
376 void computeVol();
377
382 void setZCoordinateZero();
383
385 void computeBBox();
386
393 void computeMeshSize();
394
404
407
417 size_t d_eType;
418
433
435 std::vector<util::Point> d_nodes;
436
443 std::vector<size_t> d_enc;
444
449 std::vector<std::vector<size_t>> d_nec;
450
459 std::vector<uint8_t> d_fix;
460
467 std::vector<double> d_vol;
468
477 size_t d_nPart;
478
482 std::string d_partitionMethod;
483
491 std::vector<size_t> d_nodePartition;
492
496 size_t d_dim;
497
507
509 std::string d_filename;
510
513
516
518 size_t d_numDofs;
519
532 std::vector<size_t> d_gMap;
533
538 std::vector<int> d_gInvMap;
539
541 std::pair<std::vector<double>, std::vector<double>> d_bbox;
542
544 double d_h;
545
546private:
552 void finalizeMeshDerivedFieldsFromCurrentNodes(bool compute_vol_from_elements,
553 const std::string &volume_error_note);
554};
555
556} // namespace mesh
557
558#endif // FE_MESH_H
A class for mesh data.
Definition mesh.h:53
std::vector< size_t > getElementConnectivity(const size_t &i) const
Get the connectivity of element.
Definition mesh.h:213
bool d_needEncData
Flag that indicates whether we need enc data (set by input mesh deck in constructor)
Definition mesh.h:512
void clearElementData()
Clear element-node connectivity data.
Definition mesh.cpp:489
bool isNodeFree(const size_t &i, const unsigned int &dof) const
Return true if node is free.
Definition mesh.h:191
size_t getNumDofs() const
Get the number of dofs.
Definition mesh.h:103
const std::vector< uint8_t > * getFixityP() const
Get the pointer to fixity data.
Definition mesh.h:153
const std::vector< size_t > * getElementConnectivitiesP() const
Get the pointer to element-node connectivity data.
Definition mesh.h:249
std::string d_filename
Filename to read mesh data.
Definition mesh.h:509
size_t getNumNodes() const
Get the number of nodes.
Definition mesh.h:91
const std::vector< double > * getNodalVolumesP() const
Get the pointer to nodal volume data.
Definition mesh.h:180
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition mesh.cpp:497
std::pair< std::vector< double >, std::vector< double > > & getBoundingBox()
Get the bounding box of the mesh.
Definition mesh.h:268
std::vector< util::Point > getElementConnectivityNodes(const size_t &i) const
Get the vertices of element.
Definition mesh.h:224
const std::vector< size_t > & getElementConnectivities() const
Get the reference to element-node connectivity data.
Definition mesh.h:236
std::vector< size_t > d_enc
Element-node connectivity data.
Definition mesh.h:443
std::vector< size_t > d_nodePartition
Node partition information. For each node i, d_nodePartition[i] specifies the partition number,...
Definition mesh.h:491
const std::vector< double > & getNodalVolumes() const
Get the nodal volume data.
Definition mesh.h:171
std::pair< std::vector< double >, std::vector< double > > d_bbox
Bounding box.
Definition mesh.h:541
std::vector< util::Point > d_nodes
Vector of initial (reference) coordinates of nodes.
Definition mesh.h:435
util::Point getNode(const size_t &i) const
Get coordinates of node i.
Definition mesh.h:122
const std::vector< uint8_t > & getFixity() const
Get the reference to fixity data.
Definition mesh.h:162
bool d_encDataPopulated
Flag that indicates whether element-node connectivity data is read from file.
Definition mesh.h:515
size_t d_numElems
Number of elements.
Definition mesh.h:406
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:287
void computeMeshSize()
Compute the mesh size.
Definition mesh.cpp:446
std::vector< util::Point > & getNodes()
Get the nodes data.
Definition mesh.h:138
size_t d_eType
Element type.
Definition mesh.h:417
size_t d_numNodes
Number of nodes.
Definition mesh.h:403
size_t d_dim
Dimension of the mesh.
Definition mesh.h:496
std::vector< double > * getNodalVolumesP()
Get the pointer to nodal volume data.
Definition mesh.h:183
std::string d_spatialDiscretization
Tag for spatial discretization type.
Definition mesh.h:506
const std::vector< util::Point > & getNodes() const
Get the nodes data.
Definition mesh.h:135
const std::pair< std::vector< double >, std::vector< double > > & getBoundingBox() const
Get the bounding box of the mesh.
Definition mesh.h:262
double getMeshSize() const
Get the mesh size.
Definition mesh.h:115
size_t d_nPart
Number of partitions.
Definition mesh.h:477
std::vector< int > d_gInvMap
Map from global id to reduced global id.
Definition mesh.h:538
void finalizeMeshDerivedFieldsFromCurrentNodes(bool compute_vol_from_elements, const std::string &volume_error_note)
After nodes, enc, nec, and dof-related fields are set: 2D z clear, bbox, optional nodal volume,...
Definition mesh.cpp:252
std::vector< size_t > * getElementConnectivitiesP()
Get the pointer to element-node connectivity data.
Definition mesh.h:254
std::vector< double > & getNodalVolumes()
Get the nodal volume data.
Definition mesh.h:174
size_t getDimension() const
Get the dimension of the domain.
Definition mesh.h:85
void setZCoordinateZero()
For , set on all reference nodes (x–y plane). Call before computeBBox() when nodes may carry numeric...
Definition mesh.cpp:418
std::vector< uint8_t > d_fix
Vector of fixity mask of each node.
Definition mesh.h:459
size_t d_numDofs
Number of dofs = (dimension) times (number of nodes)
Definition mesh.h:518
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:478
void computeVol()
Compute the nodal volume.
Definition mesh.cpp:340
size_t getElementType() const
Get the type of element in mesh.
Definition mesh.h:109
const std::vector< util::Point > * getNodesP() const
Get the pointer to nodes data.
Definition mesh.h:144
std::vector< double > d_vol
Vector of volume of each node.
Definition mesh.h:467
std::vector< uint8_t > * getFixityP()
Get the pointer to fixity data.
Definition mesh.h:156
void loadFromTetraElements3D(std::vector< util::Point > nodes, std::vector< size_t > enc, const inp::MeshDeck *meshDeck, const inp::ModelDeck *modelDeck)
Populate mesh from 3D tetrahedron data (0-based node indices in enc) without reading a file.
Definition mesh.cpp:214
void loadFromTriangleElements2D(std::vector< util::Point > nodes, std::vector< size_t > enc, const inp::MeshDeck *meshDeck, const inp::ModelDeck *modelDeck)
Populate mesh from 2D triangle data (0-based node indices in enc) without reading a file.
Definition mesh.cpp:176
void computeBBox()
Compute the bounding box from d_nodes (after setZCoordinateZero() for 2D if applicable).
Definition mesh.cpp:425
double getNodalVolume(const size_t &i) const
Get nodal volume of node i.
Definition mesh.h:129
std::string d_partitionMethod
Partitioning method. It could be either empty string or "metis_recursive" or "metis_kway".
Definition mesh.h:482
size_t d_eNumVertex
Number of vertex per element.
Definition mesh.h:432
size_t getNumElements() const
Get the number of elements.
Definition mesh.h:97
void print(int nt=0, int lvl=0) const
Prints the information about the object.
Definition mesh.h:309
std::vector< util::Point > * getNodesP()
Get the pointer to nodes data.
Definition mesh.h:147
void createData(const std::string &filename, bool ref_config=false)
Reads mesh data from the file and populates other data.
Definition mesh.cpp:71
std::vector< size_t > & getElementConnectivities()
Get the reference to element-node connectivity data.
Definition mesh.h:241
std::vector< std::vector< size_t > > d_nec
Node-element connectivity data.
Definition mesh.h:449
std::vector< size_t > d_gMap
Map from global reduced id to default global id.
Definition mesh.h:532
double d_h
Characteristic mesh spacing (minimum nodal distance); always from computeMeshSize() after nodes exist...
Definition mesh.h:544
std::vector< uint8_t > & getFixity()
Get the reference to fixity data.
Definition mesh.h:165
Collection of methods and database related to input.
Definition pairForce.h:20
Collection of methods and data related to finite element and mesh.
Definition mesh.cpp:29
Structure to read and store mesh related input data.
Definition meshDeck.h:28
Structure to read and store model related input data.
Definition modelDeck.h:27
A structure to represent 3d vectors.
Definition point.h:30