<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<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 tabindex="-1">
<div style="direction: ltr;" id="divRpF780276"><font face="Tahoma" color="#000000" size="2"><b>De :</b> rjdurscher@gmail.com [rjdurscher@gmail.com]<br>
<b>Envoyé :</b> samedi 22 août 2015 1.37<br>
<b>À :</b> Gmsh<br>
<b>Cc :</b> gmsh@geuz.org; 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-><wbr>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/<wbr>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","<wbr>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(<wbr>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(<wbr>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(<wbr>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(<wbr>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-><wbr>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(<wbr>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/<wbr>simoneg/Hexpress-Hybrid_<wbr>projects/IncludeGmsh-HH/<wbr>TESTGMSHAPI_keyword/<wbr>interfaceVertGmsh.geo");</span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">    modelGmsh->writeMSH("/home/<wbr>simoneg/Hexpress-Hybrid_<wbr>projects/IncludeGmsh-HH/<wbr>TESTGMSHAPI_keyword/<wbr>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(<wbr>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[<wbr>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(<wbr>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">                                        <wbr>         mv[inMesh.elem(<wbr>cellCounter,1)], 
</span></p>
<p class="MsoNormal" style="margin-left:141.6pt"><span style="color:#1f497d" lang="EN-GB">                              <wbr>   mv[inMesh.elem(cellCounter,<wbr>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">                                                             <wbr>                              <wbr>                     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>
</body>
</html>