I am using the gmsh C++ API as a part of a larger optimization project. All I need gmsh for is to mesh some polygons at every iteration in order to conduct a finite element analysis.
According to the tutorials, once a mesh instance is generated, it can be save to a .msh
file with the write()
method, e.g.:
gmsh::initialize();
// ...
// Geometry definition
// ...
gmsh::model::mesh::generate(2);
gmsh::write("myfile.msh");
And in the .msh
file I can see all the nodes, elements, and other information.
Now, as I mentioned above, I only need gmsh's output to conduct some analysis with some functions that I've already written, and to which I only need to feed a std::vector
or Eigen::Vector
containing the nodes and the vectors.
One (inefficient) way to do so is, of course, to export the .msh
file and then parse it to create a std::vector
out of the nodal information. I am looking for a way to just access the nodes and elements so that I can store them in a std::vector
(or Eigen::Vector
) directly.
Is there a way to avoid dumping everything to a local file? I know I could reverse engineer this operation by going through the write()
method and looking at how the nodal information is saved to a file, but:
- I feel like there must be some API function that serves exactly this purpose
- I'd rather avoid going through the huge source files to figure out this information myself, since I need this software to be completed as soon as possible