[Gmsh] Accessing data from mesh file

128 at gmx.us 128 at gmx.us
Sun Nov 27 15:06:38 CET 2016


Hi,

I'm trying to read in GMSH files using the API. I'm unable to figure out how to access the mesh data from GMSH class structures.

#include <iostream>
#include <cstdio>

#include "GModel.h"

using namespace std;

int main(int argc, char **argv){
	unsigned int i=0, ele=0, nodes=0;
	GModel *m = new GModel();
	m->readMSH("cv.msh");

	/*
	Is this necessary? As in, won't node numbers be always continuous? (no missing indices)
	*/
	m->indexMeshVertices(true, 0, true);

	nodes = m->getNumMeshVertices();
	printf("No. of vertices \t%d\n", nodes);
	ele = m->getNumMeshElements();
	printf("No. of elements \t%d\n", ele); // this works.  prints the exact sum of all the elements

	m->writeMSH("test.msh");

	for(i=0; i<nodes; i++){
		printf("node loop to get coordinates");
	}

	for(i=0; i<ele; i++){
		printf("element loop to access all the elements and tag_ids");
	}

	delete m;
}


Many thanks



More information about the gmsh mailing list