[Gmsh] Implementing loop direction in C++
Mikhail Artemiev
artemiev.mikhail at ngs.ru
Wed Jun 27 06:36:31 CEST 2012
Hi Tolga,
this is a code that solves your problem (based on code
written by Takuya OSHIMA
http://www.geuz.org/pipermail/gmsh/2011/006803.html):
#include "Gmsh.h"
#include "GModel.h"
#include "MElement.h"
#include "MVertex.h"
#include <iostream>
int main(int argc, char **argv)
{
GmshInitialize(argc, argv);
GModel *m = new GModel;
GmshSetOption("General", "Terminal", 1.);
GmshSetOption("General", "Verbosity", 99.);
const double cl1 = 0.1;
GVertex *gv1 = m->addVertex(0.0, 0.0, 0.0, cl1);
GVertex *gv2 = m->addVertex(1.0, 0.0, 0.0, cl1);
GVertex *gv3 = m->addVertex(0.0, -1.0, 0.0, cl1);
GVertex *gv4 = m->addVertex(0.0, 0.0, 1.0, cl1);
GEdge *ge1 = m->addLine(gv1, gv2);
GEdge *ge2 = m->addLine(gv1, gv3);
GEdge *ge3 = m->addLine(gv1, gv4);
GEdge *ge4 = m->addLine(gv2, gv3);
GEdge *ge5 = m->addLine(gv2, gv4);
GEdge *ge6 = m->addLine(gv3, gv4);
std::vector<std::vector<GEdge *> > lineLoop1(1);
lineLoop1[0].push_back(ge1);
lineLoop1[0].push_back(ge2);
lineLoop1[0].push_back(ge4);
std::vector<std::vector<GEdge *> > lineLoop2(1);
lineLoop2[0].push_back(ge1);
lineLoop2[0].push_back(ge3);
lineLoop2[0].push_back(ge5);
std::vector<std::vector<GEdge *> > lineLoop3(1);
lineLoop3[0].push_back(ge2);
lineLoop3[0].push_back(ge3);
lineLoop3[0].push_back(ge6);
std::vector<std::vector<GEdge *> > lineLoop4(1);
lineLoop4[0].push_back(ge4);
lineLoop4[0].push_back(ge5);
lineLoop4[0].push_back(ge6);
GFace *gf1 = m->addPlanarFace(lineLoop1);
GFace *gf2 = m->addPlanarFace(lineLoop2);
GFace *gf3 = m->addPlanarFace(lineLoop3);
GFace *gf4 = m->addPlanarFace(lineLoop4);
std::vector<std::vector<GFace *> > faceLoop1(1);
faceLoop1[0].push_back(gf1);
faceLoop1[0].push_back(gf2);
faceLoop1[0].push_back(gf3);
faceLoop1[0].push_back(gf4);
GRegion *gr1 = m->addVolume(faceLoop1);
m->writeGEO("test.geo");
m->mesh(3);
m->writeMSH("test.msh");
GmshFinalize();
return 0;
}
Look at "test.geo" to see how Gmsh defines line loops
(some lines have "-" direction automatically).
Hope this helps.
The code was tested with Gmsh 2.6.0 library.
Mikhail Artemiev