[Gmsh] c++ API - Import mesh vertices and elements
Simone GREMMO [531257]
Simone.GREMMO at umons.ac.be
Sat Aug 22 21:02:06 CEST 2015
Hi Ryan,
your code seems to be correct (by the way I am not a great expert of Gmsh source code).
I was thinking that maybe the problem is in the geometry definition: element orientations should be consistent all around the surface (triangle normals should point outward). Maybe some of your elements have opposite orientation and thus volume mesh cannot be generated?
On which geometry are you testing your program? If you have tried to generate the mesh using the GUI and you have succeeded, probably it's because Gmsh makes a check on orientation.
Simone
________________________________
De : rjdurscher at gmail.com [rjdurscher at gmail.com] de la part de Ryan Durscher [dursch at ufl.edu]
Envoyé : samedi 22 août 2015 6.00
À : Simone GREMMO [531257]
Cc : Gmsh; gmsh at geuz.org
Objet : Re: [Gmsh] c++ API - Import mesh vertices and elements
Simone,
Please see below for sample code. I have tried commenting out those line, but it resulted in the same issue. The error I am seeing is :
"Initializing memorypools.
tetrahedron per block: 8188.
Size of a point: 128 bytes.
Size of a tetrahedron: 96 (96) bytes.
Size of a shellface: 216 (216) bytes.
Error: The point set is trivial."
These are tetgen outputs with the "The point set is trivial" being a result of the 0 nodes being input into it. Incidentally if I call refineMesh it properly refines the surface mesh I am inputting into the gmshModel if I comment out the region stuff. From the GUI in order to get a volume mesh I have to use the elementary entities -> add -> volume then select the surface mesh (generated from step *** in the code). This creates a *.geo file which I cant figure out how to replicate though the API. The form of the *.geo file is:
Discrete Face(1) = {};
Surface Loop(3) = {1};
Volume(3) = {3};
Physical Surface(1) = {1};
I have been staring at this for a while now and any help would be greatly appreciated.
Thanks,
Ryan
// Gmsh headers
#include "Gmsh.h"
#include "GModel.h"
#include "GEntity.h"
#include "discreteFace.h"
#include "discreteRegion.h"
#include "MTriangle.h"
#include "MFace.h"
// *verts is a 3*numVerts array of coordinates verts(3*i + 0) = x, verts(3*i + 1) = y, and verts(3*i + 3) = z
// *conn is a 3*numTris array - define the triangles connectivity
int gmsh_Volume_Mesh(int numVerts,
int numTris,
double *verts,
int *conn)
{
// Initialize variables
int i,j;
printf("USING GMSH\n");
GmshInitialize();
GmshSetOption("Mesh","Algorithm",1.);
GmshSetOption("General","Verbosity", 100.);
//Create Gmsh model and set the factory
GModel *modelGmsh = new GModel;
modelGmsh->setFactory("Gmsh");
// Create a discrete face
GFace *interFace = new discreteFace(modelGmsh,1);
// Pack triangle verts into vertex vector
std::vector<MVertex*> vertex;
vertex.resize((int) numVerts);
for (i = 0 ; i < numVerts ; i ++) {
vertex[i] = new MVertex(verts[3*i + 0],
verts[3*i + 1],
verts[3*i + 2],
interFace,
i+1); // Want index to start at 1
// Add vertex to face
interFace->addMeshVertex(vertex[i]);
}
// Pack connectivity of triangles into face
for (i = 0; i < numTris; i++) {
interFace->addTriangle(new MTriangle(vertex[conn[3*i + 0]-1],
vertex[conn[3*i + 1]-1],
vertex[conn[3*i + 2]-1]));/*,
i+1,2));*/
}
printf("Number of elements in face = %d\n",interFace->getNumMeshElements());
// Add face to model
modelGmsh->add(interFace);
// ****** modelGmsh->writeGEO("test.geo");
// ****** modelGmsh->writeMSH("test.msh");
// Create face loop - only 1 surface
std::vector<GFace*> interfaceFace; //in my case the surface is given in one piece only
interfaceFace.push_back(interFace);
std::vector <std::vector<GFace*> > interfaceLoop;
interfaceLoop.push_back(interfaceFace);
// Create a physical region
GRegion *regionInterface = modelGmsh->addVolume(interfaceLoop);
//Add a volume physical entity
regionInterface->addPhysicalEntity(1);
//Add the region to the model
modelGmsh->add(regionInterface);
modelGmsh->writeGEO("test.geo");
modelGmsh->writeMSH("test.msh");
//Mesh the model
//modelGmsh->refineMesh(1); // Refining the surface mesh works fine if I comment out the region stuff
modelGmsh->mesh(3);
/*printf("Num Regions = %d\n",gmshmodel->getNumRegions());
printf("Num Faces = %d\n",gmshmodel->getNumFaces());
printf("Num Edges = %d\n",gmshmodel->getNumEdges());
printf("Num Verts = %d\n",gmshmodel->getNumVertices());*/
delete modelGmsh;
GmshFinalize();
printf("Done meshing\n");
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.geuz.org/pipermail/gmsh/attachments/20150822/ea3bc613/attachment.html>