PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
mesh_gen::anonymous_namespace{meshGenerator.cpp} Namespace Reference

Functions

void writeGmshMsh22From2DTriangleMesh (const mesh::Mesh &m, const std::string &path)
 

Function Documentation

◆ writeGmshMsh22From2DTriangleMesh()

void mesh_gen::anonymous_namespace{meshGenerator.cpp}::writeGmshMsh22From2DTriangleMesh ( const mesh::Mesh m,
const std::string &  path 
)

One-shot Gmsh 2.2 ASCII from filled 2D triangle mesh (nodes z=0; matches fillMeshFromActiveGmshModel).

Definition at line 31 of file meshGenerator.cpp.

31 {
33 throw std::runtime_error("writeGmshMsh22From2DTriangleMesh: only triangle meshes are supported.");
34 if (m.getDimension() != 2)
35 throw std::runtime_error("writeGmshMsh22From2DTriangleMesh: dimension must be 2.");
36
37 const auto &nodes = m.getNodes();
38 const auto &enc = m.getElementConnectivities();
39 const size_t n = nodes.size();
40 const size_t ne = enc.size() / 3;
41
42 std::ofstream out(path);
43 if (!out)
44 throw std::runtime_error("writeGmshMsh22From2DTriangleMesh: cannot open " + path);
45
46 out << std::setprecision(17);
47 out << "$MeshFormat\n2.2 0 8\n$EndMeshFormat\n";
48 out << "$Nodes\n" << n << "\n";
49 for (size_t i = 0; i < n; ++i) {
50 const auto &p = nodes[i];
51 out << (i + 1) << " " << p.d_x << " " << p.d_y << " 0\n";
52 }
53 out << "$EndNodes\n";
54 out << "$Elements\n" << ne << "\n";
55 for (size_t e = 0; e < ne; ++e) {
56 const size_t a = enc[3 * e] + 1;
57 const size_t b = enc[3 * e + 1] + 1;
58 const size_t c = enc[3 * e + 2] + 1;
59 out << (e + 1) << " 2 2 0 1 " << a << " " << b << " " << c << "\n";
60 }
61 out << "$EndElements\n";
62}
const std::vector< size_t > & getElementConnectivities() const
Get the reference to element-node connectivity data.
Definition mesh.h:236
const std::vector< util::Point > & getNodes() const
Get the nodes data.
Definition mesh.h:135
size_t getDimension() const
Get the dimension of the domain.
Definition mesh.h:85
size_t getElementType() const
Get the type of element in mesh.
Definition mesh.h:109
static const int vtk_type_triangle
Integer flag for triangle element.

References mesh::Mesh::getDimension(), mesh::Mesh::getElementConnectivities(), mesh::Mesh::getElementType(), mesh::Mesh::getNodes(), util::vtk_type_triangle, and writeGmshMsh22From2DTriangleMesh().

Referenced by writeGmshMsh22From2DTriangleMesh().

Here is the call graph for this function:
Here is the caller graph for this function: