<div dir="ltr"><div><div>Simone, <br><br>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 :<br><br>"Initializing memorypools.<br> tetrahedron per block: 8188.<br> Size of a point: 128 bytes.<br> Size of a tetrahedron: 96 (96) bytes.<br> Size of a shellface: 216 (216) bytes.<br>Error: The point set is trivial."<br><br></div><div>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:<br><br>Discrete Face(1) = {};<br>Surface Loop(3) = {1};<br>Volume(3) = {3};<br>Physical Surface(1) = {1};<br><br></div><div>I have been staring at this for a while now and any help would be greatly appreciated.<br><br></div><div>Thanks, <br></div><div>Ryan <br></div><div><br><br>// Gmsh headers<br>#include "Gmsh.h"<br>#include "GModel.h"<br>#include "GEntity.h"<br>#include "discreteFace.h"<br>#include "discreteRegion.h"<br>#include "MTriangle.h"<br>#include "MFace.h"<br><br></div>// *verts is a 3*numVerts array of coordinates verts(3*i + 0) = x, verts(3*i + 1) = y, and verts(3*i + 3) = z<br></div>// *conn is a 3*numTris array - define the triangles connectivity <br><div><div> <div><div><div>int gmsh_Volume_Mesh(int numVerts,<br> int numTris,<br> double *verts,<br> int *conn)<br>{<br> // Initialize variables<br> int i,j;<br> <br> printf("USING GMSH\n");<br><br> GmshInitialize();<br> GmshSetOption("Mesh","Algorithm",1.);<br> GmshSetOption("General","Verbosity", 100.);<br><br> //Create Gmsh model and set the factory<br> GModel *modelGmsh = new GModel;<br> modelGmsh->setFactory("Gmsh");<br><br> // Create a discrete face<br> GFace *interFace = new discreteFace(modelGmsh,1);<br><br> // Pack triangle verts into vertex vector<br> std::vector<MVertex*> vertex;<br> vertex.resize((int) numVerts);<br> for (i = 0 ; i < numVerts ; i ++) {<br><br> vertex[i] = new MVertex(verts[3*i + 0],<br> verts[3*i + 1],<br> verts[3*i + 2],<br> interFace,<br> i+1); // Want index to start at 1<br> // Add vertex to face<br> interFace->addMeshVertex(vertex[i]);<br> }<br><br> // Pack connectivity of triangles into face<br> for (i = 0; i < numTris; i++) {<br> interFace->addTriangle(new MTriangle(vertex[conn[3*i + 0]-1],<br> vertex[conn[3*i + 1]-1],<br> vertex[conn[3*i + 2]-1]));/*,<br> i+1,2));*/<br> }<br><br> printf("Number of elements in face = %d\n",interFace->getNumMeshElements());<br><br> // Add face to model<br> modelGmsh->add(interFace);<br><br> // ****** modelGmsh->writeGEO("test.geo");<br> // ****** modelGmsh->writeMSH("test.msh");<br><br> // Create face loop - only 1 surface<br> std::vector<GFace*> interfaceFace; //in my case the surface is given in one piece only<br> interfaceFace.push_back(interFace);<br> std::vector <std::vector<GFace*> > interfaceLoop;<br> interfaceLoop.push_back(interfaceFace);<br><br> // Create a physical region<br> GRegion *regionInterface = modelGmsh->addVolume(interfaceLoop);<br><br> //Add a volume physical entity<br> regionInterface->addPhysicalEntity(1);<br><br> //Add the region to the model<br> modelGmsh->add(regionInterface);<br><br> modelGmsh->writeGEO("test.geo");<br> modelGmsh->writeMSH("test.msh");<br><br> //Mesh the model<br> //modelGmsh->refineMesh(1); // Refining the surface mesh works fine if I comment out the region stuff<br> modelGmsh->mesh(3);<br><br> /*printf("Num Regions = %d\n",gmshmodel->getNumRegions());<br> printf("Num Faces = %d\n",gmshmodel->getNumFaces());<br> printf("Num Edges = %d\n",gmshmodel->getNumEdges());<br> printf("Num Verts = %d\n",gmshmodel->getNumVertices());*/<br><br> delete modelGmsh;<br><br> GmshFinalize();<br><br> printf("Done meshing\n");<br>}<br></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 21, 2015 at 11:15 PM, Simone GREMMO [531257] <span dir="ltr"><<a href="mailto:Simone.GREMMO@umons.ac.be" target="_blank">Simone.GREMMO@umons.ac.be</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div style="direction:ltr;font-family:Tahoma;color:#000000;font-size:10pt">Hi Ryan,<br>
I used the addPhysicalEntity(1) so that when saving the mesh, it will write to file the volume mesh and not the surfaces used to bound the volume.<br>
As far as I could understand the addPhysicalEntity should not interfere with the mesh generation, but can used to save in the msh just a part of the mesh: so maybe you generate the mesh, but do not write to file. Is it possible?<br>
Have you tried to comment the lines <br>
<span lang="fr-BE"><font face="Calibri,sans-serif" size="2"><span style="font-size:11pt"><font color="#1F497D"><span lang="en-GB">regionInterface->addPhysicalEntity(1);</span></font></span></font></span><br>
<span lang="fr-BE"><font face="Calibri,sans-serif" size="2"><span style="font-size:11pt"><font color="#1F497D"><span lang="en-GB">modelGmsh->add(regionInterface);</span></font></span></font></span><br>
and see if in the resulting msh file you get something different?<br>
<br>
Can you copy the relevant lines of your code? It may be easier to understand your problem.<br>
<br>
Simone<br>
<br>
<br>
<div style="font-family:Times New Roman;color:#000000;font-size:16px">
<hr>
<div style="direction:ltr"><font color="#000000" face="Tahoma" size="2"><b>De :</b> <a href="mailto:rjdurscher@gmail.com" target="_blank">rjdurscher@gmail.com</a> [<a href="mailto:rjdurscher@gmail.com" target="_blank">rjdurscher@gmail.com</a>]<br>
<b>Envoyé :</b> samedi 22 août 2015 1.37<br>
<b>À :</b> Gmsh<br>
<b>Cc :</b> <a href="mailto:gmsh@geuz.org" target="_blank">gmsh@geuz.org</a>; Simone GREMMO [531257]<br>
<b>Objet :</b> Re: [Gmsh] c++ API - Import mesh vertices and elements<br>
</font><br>
</div>
<div></div>
<div>
<div dir="ltr">Hi Simone, <br>
<br>
I am trying to implement the same thing you describe here in my code with Gmsh. I have followed your code below exactly however I am unable to generate the volume mesh. Outputting a *.msh file (model->writeMSH()) at various stages the problem seems to come
about during "<span style="color:#1f497d" lang="EN-GB">regionInterface->addPhysicalEntity(1);</span><span style="color:#1f497d" lang="EN-GB">"
<span style="color:rgb(0,0,0)">in which the previously defined surface mesh now disappears (according the *.msh file). Any help would be greatly appreciated. I am currently using the latest version of Gmsh (2.10.1). Furthermore any additional code you could
share regarding your second post (meshing between two surface) would be greatly appreciated.
<br>
<br>
Thanks, <br>
Ryan <br>
</span> </span><span style="color:#1f497d" lang="EN-GB"></span> <br>
<br>
On Monday, February 9, 2015 at 6:41:49 AM UTC-5, Simone GREMMO [531257] wrote:
<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="FR-BE">
<div>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">Dear all,</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">I think I have partially solved my problem. Here is the code that I have written and let me to create the volume mesh (Thanks to Mikhail for his suggestion in this answer:
<a href="http://geuz.org/pipermail/gmsh/2015/009536.html" rel="nofollow" target="_blank">
http://geuz.org/pipermail/gmsh/2015/009536.html</a>):</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">GmshInitialize();</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> GmshSetOption("Mesh","Algorithm",1.);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> //Create Gmsh model and set the factory</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> GModel *modelGmsh = new GModel;</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> modelGmsh->setFactory("Gmsh");</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> //GFace is defined by a mesh and not through GVertex and GEdge</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> GFace *interfaceGmsh = new discreteFace(modelGmsh,1);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> //Function that loops over mesh vertices and elements and import them in a gmsh structure [see at the bottom of the main function]</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> importSurfaceMeshintoGmsh(interface, interfaceGmsh);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> modelGmsh->add(interfaceGmsh);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> //Using the previously defined surface, define a surface loop, used to enclose a volume</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> std::vector<GFace*> interfaceFace; //in my case the surface is given in one piece only</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> interfaceFace.push_back(interfaceGmsh);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> std::vector <std::vector<GFace*> > interfaceLoop;</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> interfaceLoop.push_back(interfaceFace);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> //Add the volume enclose by the surface loop to the model and create the related GRegion</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> GRegion *regionInterface = modelGmsh->addVolume(interfaceLoop);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> //Add a volume physical entity</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> regionInterface->addPhysicalEntity(1);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> //Add the region to the model</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> modelGmsh->add(regionInterface);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> //Mesh the model</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> modelGmsh->mesh(3);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> modelGmsh->writeGEO("/home/simoneg/Hexpress-Hybrid_projects/IncludeGmsh-HH/TESTGMSHAPI_keyword/interfaceVertGmsh.geo");</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> modelGmsh->writeMSH("/home/simoneg/Hexpress-Hybrid_projects/IncludeGmsh-HH/TESTGMSHAPI_keyword/interfaceVertGmsh.msh");</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> delete modelGmsh;</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">GmshFinalize();</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">//Function to import the mesh in a Gmsh structure</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">//inMesh is the input mesh, created with another tool</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">//gmshMesh is the structure containing the inMesh, but that can be used by Gmsh to generate the volume mesh</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">bool importSurfaceMeshintoGmsh(const My_Mesh &inMesh, GFace *gmshMesh)</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">{</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> My_int numNodes = inMesh.numVerticies(); //get the number of vertices from the inMesh</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> My_int numCells = inMesh.numCells(); ////get the number of elements from the inMesh</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> //Get all the vertices from the mesh</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> std::vector<MVertex*> mv;</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> mv.resize((int)numNodes);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> for (MC_Index nodeCounter = 0; nodeCounter < numNodes; nodeCounter++)</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> {</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> My_Coord3D coordHH = inMesh.vertex(nodeCounter); //a 3 dimensions vector with the vertex coordinates</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> mv[nodeCounter] = new MVertex((double)coordHH[0], (double)coordHH[1], (double)coordHH[2],gmshMesh, nodeCounter+1);</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> gmshMesh->addMeshVertex(mv[nodeCounter]); //add the vertex to the mesh</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> }</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> //Get all the elements from the mesh</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> for (My_int cellCounter = 0; cellCounter < numCells; cellCounter++)</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> {</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> My_int numVertCell = inMesh.numElems(cellCounter); //for element #cellCounter, get the number of vertices</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> switch (numVertCell)</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> {</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> case 3: //triangle</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> gmshMesh->addTriangle(new MTriangle(mv[inMesh.elem(cellCounter,0)], //extract the vertexID for element #cellCounter</span></p>
<p class="MsoNormal" style="margin-left:70.8pt;text-indent:35.4pt"><span style="color:#1f497d" lang="EN-GB"> mv[inMesh.elem(cellCounter,1)],
</span></p>
<p class="MsoNormal" style="margin-left:141.6pt"><span style="color:#1f497d" lang="EN-GB"> mv[inMesh.elem(cellCounter,2)]));</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> break;</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> case 4: //quadrangle</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> gmshMesh->addQuadrangle(new MQuadrangle(mv[inMesh. elem(cellCounter,0)],</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> mv[inMesh. elem(cellCounter,1)],</span></p>
<p class="MsoNormal" style="margin-left:177.0pt"><span style="color:#1f497d" lang="EN-GB"> mv[inMesh. elem(cellCounter,2)],</span></p>
<p class="MsoNormal" style="margin-left:177.0pt"><span style="color:#1f497d" lang="EN-GB"> mv[inMesh. elem(cellCounter,3)]));</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> break;</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> default:</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> return false;
</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> break;</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> }</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> }</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> return true;</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">}</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">This code generates a mesh in a volume without any hole inside. Does anyone know how to add a hole inside the volume and mesh the region between the two surfaces?</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">The .geo commands looks like:</span></p>
<p class="MsoNormal"><b><span style="color:#1f497d" lang="EN-GB">Merge "interfaceMesh.msh";</span></b></p>
<p class="MsoNormal"><b><span style="color:#1f497d" lang="EN-GB">Surface Loop(3) = {1};</span></b></p>
<p class="MsoNormal"><b><span style="color:#1f497d" lang="EN-GB">Merge "envelopeMovingMesh.msh";</span></b></p>
<p class="MsoNormal"><b><span style="color:#1f497d" lang="EN-GB">Surface Loop(4) = {2};</span></b></p>
<p class="MsoNormal"><b><span style="color:#1f497d" lang="EN-GB">Volume(1) = {3,4};</span></b></p>
<p class="MsoNormal"><b><span style="color:#1f497d" lang="EN-GB">Physical Volume(1) = {5};</span></b></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">Thanks for your help.</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">Simone</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">Dear all,</span></p>
<p class="MsoNormal"><span lang="EN-GB">I have included Gmsh as library in my c++ program and I need to use it to mesh a volume region bounded by a surface mesh: in my program I have defined a surface mesh and I need to import its vertices and elements into
a gmsh structure to be able to create a volume mesh starting from this surface.</span></p>
<p class="MsoNormal"><span lang="EN-GB">Steps to do so, as far as I can understand, are:</span></p>
<p><span lang="EN-GB"><span>-<span style="font:7.0pt "Times New Roman"">
</span></span></span><span lang="EN-GB">Declare a GModel* that will contain the surface</span></p>
<p><span lang="EN-GB"><span>-<span style="font:7.0pt "Times New Roman"">
</span></span></span><span lang="EN-GB">Add a GFace* into the GModel</span></p>
<p><span lang="EN-GB"><span>-<span style="font:7.0pt "Times New Roman"">
</span></span></span><span lang="EN-GB">Add vertices and cells to the GFace* (get them from the mesh created in my program). Actually define a mesh for this GFace object</span></p>
<p><span lang="EN-GB"><span>-<span style="font:7.0pt "Times New Roman"">
</span></span></span><span lang="EN-GB">Create the volume mesh</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">Is this correct? Does anyone have any suggestion on how to write this portion of code?</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">PS I have already looked at the example in utils/api_demos/mainSimple.cpp and have adapted it to my case, but I would rather avoid reading/writing files to transfer meshes between the my program and gmsh to avoid performance
issues.</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">Simone</span></p>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><pre><span style="FONT-FAMILY:arial,helvetica,sans-serif"><font size="2">Durscher, Ryan J<br><br><a href="mailto:dursch@ufl.edu" target="_blank">dursch@ufl.edu</a></font></span></pre></div>
</div>