Commit 23ebcf67 authored by Christophe Geuzaine's avatar Christophe Geuzaine

introduce namespaces in the API

parent c0c5f995
Pipeline #844 canceled with stage
in 28 minutes 38 seconds
This diff is collapsed.
This diff is collapsed.
......@@ -21,4 +21,137 @@
%template(PairVector) std::vector<std::pair<int, int> >;
%template(PairVectorVector) std::vector<std::vector<std::pair<int, int> > >;
%rename(initialize) gmsh::initialize;
%rename(finalize) gmsh::finalize;
%rename(open) gmsh::open;
%rename(merge) gmsh::merge;
%rename(write) gmsh::write;
%rename(clear) gmsh::clear;
%rename(optionSetNumber) gmsh::option::setNumber;
%rename(optionGetNumber) gmsh::option::getNumber;
%rename(optionSetString) gmsh::option::setString;
%rename(optionGetString) gmsh::option::getString;
%rename(modelAdd) gmsh::model::add;
%rename(modelRemove) gmsh::model::remove;
%rename(modelList) gmsh::model::list;
%rename(modelSetCurrent) gmsh::model::setCurrent;
%rename(modelGetEntities) gmsh::model::getEntities;
%rename(modelGetPhysicalGroups) gmsh::model::getPhysicalGroups;
%rename(modelGetEntitiesForPhysicalGroup) gmsh::model::getEntitiesForPhysicalGroup;
%rename(modelAddPhysicalGroup) gmsh::model::addPhysicalGroup;
%rename(modelSetPhysicalName) gmsh::model::setPhysicalName;
%rename(modelGetPhysicalName) gmsh::model::getPhysicalName;
%rename(modelGetBoundary) gmsh::model::getBoundary;
%rename(modelGetEntitiesInBoundingBox) gmsh::model::getEntitiesInBoundingBox;
%rename(modelGetBoundingBox) gmsh::model::getBoundingBox;
%rename(modelAddDiscreteEntity) gmsh::model::addDiscreteEntity;
%rename(modelRemoveEntities) gmsh::model::removeEntities;
%rename(modelMeshGenerate) gmsh::model::mesh::generate;
%rename(modelMeshGetLastEntityError) gmsh::model::mesh::getLastEntityError;
%rename(modelMeshGetLastVertexError) gmsh::model::mesh::getLastVertexError;
%rename(modelMeshGetVertices) gmsh::model::mesh::getVertices;
%rename(modelMeshGetElements) gmsh::model::mesh::getElements;
%rename(modelMeshSetVertices) gmsh::model::mesh::setVertices;
%rename(modelMeshSetElements) gmsh::model::mesh::setElements;
%rename(modelMeshGetVertex) gmsh::model::mesh::getVertex;
%rename(modelMeshGetElement) gmsh::model::mesh::getElement;
%rename(modelMeshSetSize) gmsh::model::mesh::setSize;
%rename(modelMeshSetTransfiniteLine) gmsh::model::mesh::setTransfiniteLine;
%rename(modelMeshSetTransfiniteSurface) gmsh::model::mesh::setTransfiniteSurface;
%rename(modelMeshSetTransfiniteVolume) gmsh::model::mesh::setTransfiniteVolume;
%rename(modelMeshSetRecombine) gmsh::model::mesh::setRecombine;
%rename(modelMeshSetSmoothing) gmsh::model::mesh::setSmoothing;
%rename(modelMeshSetReverse) gmsh::model::mesh::setReverse;
%rename(modelMeshEmbed) gmsh::model::mesh::embed;
%rename(modelMeshFieldAdd) gmsh::model::mesh::field::add;
%rename(modelMeshFieldRemove) gmsh::model::mesh::field::remove;
%rename(modelMeshFieldSetNumber) gmsh::model::mesh::field::setNumber;
%rename(modelMeshFieldSetString) gmsh::model::mesh::field::setString;
%rename(modelMeshFieldSetNumbers) gmsh::model::mesh::field::setNumbers;
%rename(modelMeshFieldSetAsBackground) gmsh::model::mesh::field::setAsBackground;
%rename(modelGeoAddPoint) gmsh::model::geo::addPoint;
%rename(modelGeoAddLine) gmsh::model::geo::addLine;
%rename(modelGeoAddCircleArc) gmsh::model::geo::addCircleArc;
%rename(modelGeoAddEllipseArc) gmsh::model::geo::addEllipseArc;
%rename(modelGeoAddSpline) gmsh::model::geo::addSpline;
%rename(modelGeoAddBSpline) gmsh::model::geo::addBSpline;
%rename(modelGeoAddBezier) gmsh::model::geo::addBezier;
%rename(modelGeoAddLineLoop) gmsh::model::geo::addLineLoop;
%rename(modelGeoAddPlaneSurface) gmsh::model::geo::addPlaneSurface;
%rename(modelGeoAddSurfaceFilling) gmsh::model::geo::addSurfaceFilling;
%rename(modelGeoAddSurfaceLoop) gmsh::model::geo::addSurfaceLoop;
%rename(modelGeoAddVolume) gmsh::model::geo::addVolume;
%rename(modelGeoExtrude) gmsh::model::geo::extrude;
%rename(modelGeoRevolve) gmsh::model::geo::revolve;
%rename(modelGeoTwist) gmsh::model::geo::twist;
%rename(modelGeoTranslate) gmsh::model::geo::translate;
%rename(modelGeoRotate) gmsh::model::geo::rotate;
%rename(modelGeoDilate) gmsh::model::geo::dilate;
%rename(modelGeoSymmetry) gmsh::model::geo::symmetry;
%rename(modelGeoCopy) gmsh::model::geo::copy;
%rename(modelGeoRemove) gmsh::model::geo::remove;
%rename(modelGeoRemoveAllDuplicates) gmsh::model::geo::removeAllDuplicates;
%rename(modelGeoSynchronize) gmsh::model::geo::synchronize;
%rename(modelGeoMeshSetTransfiniteLine) gmsh::model::geo::mesh::setTransfiniteLine;
%rename(modelGeoMeshSetTransfiniteSurface) gmsh::model::geo::mesh::setTransfiniteSurface;
%rename(modelGeoMeshSetTransfiniteVolume) gmsh::model::geo::mesh::setTransfiniteVolume;
%rename(modelGeoMeshSetRecombine) gmsh::model::geo::mesh::setRecombine;
%rename(modelGeoMeshSetSmoothing) gmsh::model::geo::mesh::setSmoothing;
%rename(modelGeoMeshSetReverse) gmsh::model::geo::mesh::setReverse;
%rename(modelGeoMeshSetSize) gmsh::model::geo::mesh::setSize;
%rename(modelOccAddPoint) gmsh::model::occ::addPoint;
%rename(modelOccAddLine) gmsh::model::occ::addLine;
%rename(modelOccAddCircleArc) gmsh::model::occ::addCircleArc;
%rename(modelOccAddCircle) gmsh::model::occ::addCircle;
%rename(modelOccAddEllipseArc) gmsh::model::occ::addEllipseArc;
%rename(modelOccAddEllipse) gmsh::model::occ::addEllipse;
%rename(modelOccAddSpline) gmsh::model::occ::addSpline;
%rename(modelOccAddBezier) gmsh::model::occ::addBezier;
%rename(modelOccAddBSpline) gmsh::model::occ::addBSpline;
%rename(modelOccAddWire) gmsh::model::occ::addWire;
%rename(modelOccAddLineLoop) gmsh::model::occ::addLineLoop;
%rename(modelOccAddRectangle) gmsh::model::occ::addRectangle;
%rename(modelOccAddDisk) gmsh::model::occ::addDisk;
%rename(modelOccAddPlaneSurface) gmsh::model::occ::addPlaneSurface;
%rename(modelOccAddSurfaceFilling) gmsh::model::occ::addSurfaceFilling;
%rename(modelOccAddSurfaceLoop) gmsh::model::occ::addSurfaceLoop;
%rename(modelOccAddVolume) gmsh::model::occ::addVolume;
%rename(modelOccAddSphere) gmsh::model::occ::addSphere;
%rename(modelOccAddBox) gmsh::model::occ::addBox;
%rename(modelOccAddCylinder) gmsh::model::occ::addCylinder;
%rename(modelOccAddCone) gmsh::model::occ::addCone;
%rename(modelOccAddWedge) gmsh::model::occ::addWedge;
%rename(modelOccAddTorus) gmsh::model::occ::addTorus;
%rename(modelOccAddThruSections) gmsh::model::occ::addThruSections;
%rename(modelOccAddThickSolid) gmsh::model::occ::addThickSolid;
%rename(modelOccExtrude) gmsh::model::occ::extrude;
%rename(modelOccRevolve) gmsh::model::occ::revolve;
%rename(modelOccAddPipe) gmsh::model::occ::addPipe;
%rename(modelOccFillet) gmsh::model::occ::fillet;
%rename(modelOccBooleanUnion) gmsh::model::occ::booleanUnion;
%rename(modelOccBooleanIntersection) gmsh::model::occ::booleanIntersection;
%rename(modelOccBooleanDifference) gmsh::model::occ::booleanDifference;
%rename(modelOccBooleanFragments) gmsh::model::occ::booleanFragments;
%rename(modelOccTranslate) gmsh::model::occ::translate;
%rename(modelOccRotate) gmsh::model::occ::rotate;
%rename(modelOccDilate) gmsh::model::occ::dilate;
%rename(modelOccSymmetry) gmsh::model::occ::symmetry;
%rename(modelOccCopy) gmsh::model::occ::copy;
%rename(modelOccRemove) gmsh::model::occ::remove;
%rename(modelOccRemoveAllDuplicates) gmsh::model::occ::removeAllDuplicates;
%rename(modelOccImportShapes) gmsh::model::occ::importShapes;
%rename(modelOccSetMeshSize) gmsh::model::occ::setMeshSize;
%rename(modelOccSynchronize) gmsh::model::occ::synchronize;
%rename(viewAdd) gmsh::view::add;
%rename(viewRemove) gmsh::view::remove;
%rename(viewGetIndex) gmsh::view::getIndex;
%rename(viewGetTags) gmsh::view::getTags;
%rename(viewAddModelData) gmsh::view::addModelData;
%rename(viewAddListData) gmsh::view::addListData;
%rename(viewProbe) gmsh::view::probe;
%rename(viewWrite) gmsh::view::write;
%rename(pluginSetNumber) gmsh::plugin::setNumber;
%rename(pluginSetString) gmsh::plugin::setString;
%rename(pluginRun) gmsh::plugin::run;
%include "gmsh.h"
......@@ -4,36 +4,36 @@
int main(int argc, char **argv)
{
gmshInitialize(argc, argv);
gmshOptionSetNumber("General.Terminal", 1);
gmsh::initialize(argc, argv);
gmsh::option::setNumber("General.Terminal", 1);
gmshModelCreate("boolean");
gmsh::model::add("boolean");
// from http://en.wikipedia.org/wiki/Constructive_solid_geometry
gmshOptionSetNumber("Mesh.Algorithm", 6);
gmshOptionSetNumber("Mesh.CharacteristicLengthMin", 0.4);
gmshOptionSetNumber("Mesh.CharacteristicLengthMax", 0.4);
gmsh::option::setNumber("Mesh.Algorithm", 6);
gmsh::option::setNumber("Mesh.CharacteristicLengthMin", 0.4);
gmsh::option::setNumber("Mesh.CharacteristicLengthMax", 0.4);
double R = 1.4, Rs = R*.7, Rt = R*1.25;
std::vector<std::pair<int, int> > ov;
std::vector<std::vector<std::pair<int, int> > > ovv;
gmshModelOccAddBox(-R,-R,-R, 2*R,2*R,2*R, 1);
gmshModelOccAddSphere(0,0,0,Rt, 2);
gmshModelOccBooleanIntersection({{3, 1}}, {{3, 2}}, ov, ovv, 3);
gmshModelOccAddCylinder(-2*R,0,0, 4*R,0,0, Rs, 4);
gmshModelOccAddCylinder(0,-2*R,0, 0,4*R,0, Rs, 5);
gmshModelOccAddCylinder(0,0,-2*R, 0,0,4*R, Rs, 6);
gmshModelOccBooleanUnion({{3, 4}, {3, 5}}, {{3, 6}}, ov, ovv, 7);
gmshModelOccBooleanDifference({{3, 3}}, {{3, 7}}, ov, ovv, 8);
gmsh::model::occ::addBox(-R,-R,-R, 2*R,2*R,2*R, 1);
gmsh::model::occ::addSphere(0,0,0,Rt, 2);
gmsh::model::occ::booleanIntersection({{3, 1}}, {{3, 2}}, ov, ovv, 3);
gmsh::model::occ::addCylinder(-2*R,0,0, 4*R,0,0, Rs, 4);
gmsh::model::occ::addCylinder(0,-2*R,0, 0,4*R,0, Rs, 5);
gmsh::model::occ::addCylinder(0,0,-2*R, 0,0,4*R, Rs, 6);
gmsh::model::occ::booleanUnion({{3, 4}, {3, 5}}, {{3, 6}}, ov, ovv, 7);
gmsh::model::occ::booleanDifference({{3, 3}}, {{3, 7}}, ov, ovv, 8);
gmshModelOccSynchronize();
gmsh::model::occ::synchronize();
gmshModelMesh(3);
gmsh::model::mesh::generate(3);
gmshExport("boolean.msh");
gmsh::write("boolean.msh");
gmshFinalize();
gmsh::finalize();
return 0;
}
# This reimplements gmsh/demos/boolean/boolean.geo in Python.
from gmsh import *
import gmsh
import sys
gmshInitialize(sys.argv)
gmsh.initialize(sys.argv)
gmshOptionSetNumber("General.Terminal", 1)
gmsh.optionSetNumber("General.Terminal", 1)
gmshModelCreate("boolean")
gmsh.modelAdd("boolean")
# from http://en.wikipedia.org/wiki/Constructive_solid_geometry
gmshOptionSetNumber("Mesh.Algorithm", 6);
gmshOptionSetNumber("Mesh.CharacteristicLengthMin", 0.4);
gmshOptionSetNumber("Mesh.CharacteristicLengthMax", 0.4);
gmsh.optionSetNumber("Mesh.Algorithm", 6);
gmsh.optionSetNumber("Mesh.CharacteristicLengthMin", 0.4);
gmsh.optionSetNumber("Mesh.CharacteristicLengthMax", 0.4);
R = 1.4; Rs = R*.7; Rt = R*1.25
ov = PairVector(); ovv = PairVectorVector()
ov = gmsh.PairVector(); ovv = gmsh.PairVectorVector()
gmshModelOccAddBox(-R,-R,-R, 2*R,2*R,2*R, 1)
gmshModelOccAddSphere(0,0,0,Rt, 2)
gmshModelOccBooleanIntersection([(3, 1)], [(3, 2)], ov, ovv, 3)
gmshModelOccAddCylinder(-2*R,0,0, 4*R,0,0, Rs, 4)
gmshModelOccAddCylinder(0,-2*R,0, 0,4*R,0, Rs, 5)
gmshModelOccAddCylinder(0,0,-2*R, 0,0,4*R, Rs, 6)
gmshModelOccBooleanUnion([(3, 4), (3, 5)], [(3, 6)], ov, ovv, 7)
gmshModelOccBooleanDifference([(3, 3)], [(3, 7)], ov, ovv, 8)
gmsh.modelOccAddBox(-R,-R,-R, 2*R,2*R,2*R, 1)
gmsh.modelOccAddSphere(0,0,0,Rt, 2)
gmsh.modelOccBooleanIntersection([(3, 1)], [(3, 2)], ov, ovv, 3)
gmsh.modelOccAddCylinder(-2*R,0,0, 4*R,0,0, Rs, 4)
gmsh.modelOccAddCylinder(0,-2*R,0, 0,4*R,0, Rs, 5)
gmsh.modelOccAddCylinder(0,0,-2*R, 0,0,4*R, Rs, 6)
gmsh.modelOccBooleanUnion([(3, 4), (3, 5)], [(3, 6)], ov, ovv, 7)
gmsh.modelOccBooleanDifference([(3, 3)], [(3, 7)], ov, ovv, 8)
gmshModelOccSynchronize();
gmsh.modelOccSynchronize();
gmshModelMesh(3)
gmsh.modelMeshGenerate(3)
gmshExport("boolean.msh")
gmsh.write("boolean.msh")
gmshFinalize()
gmsh.finalize()
......@@ -2,32 +2,32 @@
int main(int argc, char **argv)
{
gmshInitialize(argc, argv);
gmshOptionSetNumber("General.Terminal", 1);
gmsh::initialize(argc, argv);
gmsh::option::setNumber("General.Terminal", 1);
gmshModelCreate("test");
gmsh::model::add("test");
// add discrete surface with tag 1
gmshModelAddDiscreteEntity(2, 1);
gmsh::model::addDiscreteEntity(2, 1);
// add 4 mesh vertices
gmshModelSetMeshVertices(2, 1,
{1, 2, 3, 4}, // vertex tags: 1, 2, 3, and 4
{0., 0., 0., // coordinates of vertex 1
1., 0., 0., // coordinates of vertex 2
1., 1., 0., // ...
0., 1., 0.});
gmsh::model::mesh::setVertices(2, 1,
{1, 2, 3, 4}, // vertex tags: 1, 2, 3, and 4
{0., 0., 0., // coordinates of vertex 1
1., 0., 0., // coordinates of vertex 2
1., 1., 0., // ...
0., 1., 0.});
// add 2 triangles
gmshModelSetMeshElements(2, 1,
{2}, // single type : 3-node triangle
{{1, 2}}, // triangle tags: 1 and 2
{{1, 2, 3, // triangle 1: vertices 1, 2, 3
1, 3, 4}}); // triangle 2: vertices 1, 3, 4
gmsh::model::mesh::setElements(2, 1,
{2}, // single type : 3-node triangle
{{1, 2}}, // triangle tags: 1 and 2
{{1, 2, 3, // triangle 1: vertices 1, 2, 3
1, 3, 4}}); // triangle 2: vertices 1, 3, 4
// export the mesh ; use explore.cpp to read and examine the mesh
gmshExport("test.msh");
gmsh::write("test.msh");
gmshFinalize();
gmsh::finalize();
return 0;
}
#!/usr/bin/env python
from gmsh import *
import gmsh
import sys
gmshInitialize(sys.argv)
gmshOptionSetNumber("General.Terminal", 1)
gmsh.initialize(sys.argv)
gmsh.optionSetNumber("General.Terminal", 1)
gmshModelCreate("test");
gmsh.modelAdd("test");
# add discrete surface with tag 1
gmshModelAddDiscreteEntity(2, 1)
gmsh.modelAddDiscreteEntity(2, 1)
# add 4 mesh vertices
gmshModelSetMeshVertices(2, 1,
gmsh.modelMeshSetVertices(2, 1,
[1, 2, 3, 4], # vertex tags: 1, 2, 3, and 4
[0., 0., 0., # coordinates of vertex 1
1., 0., 0., # coordinates of vertex 2
......@@ -20,14 +20,14 @@ gmshModelSetMeshVertices(2, 1,
0., 1., 0.])
# add 2 triangles
gmshModelSetMeshElements(2, 1,
gmsh.modelMeshSetElements(2, 1,
[2], # single type : 3-node triangle
[[1, 2]], # triangle tags: 1 and 2
[[1, 2, 3, # triangle 1: vertices 1, 2, 3
1, 3, 4]]) # triangle 2: vertices 1, 3, 4
# export the mesh ; use explore.py to read and examine the mesh
gmshExport("test.msh")
gmsh.write("test.msh")
gmshFinalize()
gmsh.finalize()
......@@ -8,26 +8,25 @@ int main(int argc, char **argv)
return 1;
}
gmshInitialize();
gmshOptionSetNumber("General.Terminal", 1);
gmshOpen(argv[1]);
gmsh::initialize();
gmsh::option::setNumber("General.Terminal", 1);
gmsh::open(argv[1]);
// get all elementary entities in the model
std::vector<std::pair<int, int> > entities;
gmshModelGetEntities(entities);
gmsh::model::getEntities(entities);
for(unsigned int i = 0; i < entities.size(); i++){
// get the mesh vertices for each elementary entity
std::vector<int> vertexTags;
std::vector<double> vertexCoords, vertexParams;
int dim = entities[i].first, tag = entities[i].second;
gmshModelGetMeshVertices(dim, tag, vertexTags, vertexCoords, vertexParams);
gmsh::model::mesh::getVertices(dim, tag, vertexTags, vertexCoords, vertexParams);
// get the mesh elements for each elementary entity
std::vector<int> elemTypes;
std::vector<std::vector<int> > elemTags, elemVertexTags;
gmshModelGetMeshElements(dim, tag, elemTypes, elemTags, elemVertexTags);
gmsh::model::mesh::getElements(dim, tag, elemTypes, elemTags, elemVertexTags);
// report some statistics
int numElem = 0;
......@@ -38,6 +37,6 @@ int main(int argc, char **argv)
<< dim << "," << tag << ")\n";
}
gmshFinalize();
gmsh::finalize();
return 0;
}
#!/usr/bin/env python
from gmsh import *
import gmsh
import sys
if len(sys.argv) < 2:
print "Usage: " + sys.argv[0] + " file.msh [options]"
exit(0)
gmshInitialize()
gmshOptionSetNumber("General.Terminal", 1)
gmshOpen(sys.argv[1])
gmsh.initialize()
gmsh.optionSetNumber("General.Terminal", 1)
gmsh.open(sys.argv[1])
# get all elementary entities in the model
entities = PairVector()
gmshModelGetEntities(entities)
entities = gmsh.PairVector()
gmsh.modelGetEntities(entities)
for e in entities:
# get the mesh vertices for each elementary entity
vertexTags = IntVector()
vertexCoords = DoubleVector(); vertexParams = DoubleVector()
gmshModelGetMeshVertices(e[0], e[1], vertexTags, vertexCoords, vertexParams)
vertexTags = gmsh.IntVector()
vertexCoords = gmsh.DoubleVector(); vertexParams = gmsh.DoubleVector()
gmsh.modelMeshGetVertices(e[0], e[1], vertexTags, vertexCoords, vertexParams)
# get the mesh elements for each elementary entity
elemTypes = IntVector()
elemTags = IntVectorVector(); elemVertexTags = IntVectorVector()
gmshModelGetMeshElements(e[0], e[1], elemTypes, elemTags, elemVertexTags)
elemTypes = gmsh.IntVector()
elemTags = gmsh.IntVectorVector(); elemVertexTags = gmsh.IntVectorVector()
gmsh.modelMeshGetElements(e[0], e[1], elemTypes, elemTags, elemVertexTags)
# report some statistics
numElem = sum(len(i) for i in elemTags)
print str(vertexTags.size()) + " mesh vertices " + str(numElem),\
"mesh elements on entity " + str(e)
gmshFinalize()
gmsh.finalize()
......@@ -8,12 +8,12 @@ int main(int argc, char **argv)
return 1;
}
gmshInitialize();
gmshOptionSetNumber("General.Terminal", 1);
gmshOpen(argv[1]);
gmshModelMesh(3);
gmshExport("test.msh");
gmshFinalize();
gmsh::initialize();
gmsh::option::setNumber("General.Terminal", 1);
gmsh::open(argv[1]);
gmsh::model::mesh::generate(3);
gmsh::write("test.msh");
gmsh::finalize();
return 0;
}
#!/usr/bin/env python
from gmsh import *
import gmsh
import sys
if len(sys.argv) < 2:
print "Usage: " + sys.argv[0] + " file.geo [options]"
exit(0)
gmshInitialize()
gmshOptionSetNumber("General.Terminal", 1)
gmshOpen(sys.argv[1])
gmshModelMesh(3)
gmshExport("test.msh")
gmshFinalize()
gmsh.initialize()
gmsh.optionSetNumber("General.Terminal", 1)
gmsh.open(sys.argv[1])
gmsh.modelMeshGenerate(3)
gmsh.write("test.msh")
gmsh.finalize()
......@@ -2,42 +2,42 @@
int main(int argc, char **argv)
{
gmshInitialize();
gmshOptionSetNumber("General.Terminal", 1);
gmsh::initialize();
gmsh::option::setNumber("General.Terminal", 1);
// Copied from discrete.cpp...
gmshModelCreate("test");
gmshModelAddDiscreteEntity(2, 1);
gmshModelSetMeshVertices(2, 1, {1, 2, 3, 4},
{0., 0., 0.,
1., 0., 0.,
1., 1., 0.,
0., 1., 0.});
gmshModelSetMeshElements(2, 1, {2}, {{1, 2}},
{{1, 2, 3,
1, 3, 4}});
gmsh::model::add("test");
gmsh::model::addDiscreteEntity(2, 1);
gmsh::model::mesh::setVertices(2, 1, {1, 2, 3, 4},
{0., 0., 0.,
1., 0., 0.,
1., 1., 0.,
0., 1., 0.});
gmsh::model::mesh::setElements(2, 1, {2}, {{1, 2}},
{{1, 2, 3,
1, 3, 4}});
// ... end of copy
// create a view with some data
int t = gmshViewCreate("some data");
gmshViewAddModelData(t, "test", "NodeData",
{1, 2, 3, 4},
{{1.},{10.},{20.},{1.}});
int t = gmsh::view::add("some data");
gmsh::view::addModelData(t, "test", "NodeData",
{1, 2, 3, 4},
{{1.},{10.},{20.},{1.}});
// compute the iso-curve at value 11
gmshPluginSetNumber("Isosurface", "Value", 11.);
gmshPluginRun("Isosurface");
gmsh::plugin::setNumber("Isosurface", "Value", 11.);
gmsh::plugin::run("Isosurface");
// delete the source view
gmshViewDelete(t);
gmsh::view::remove(t);
// check how many views the plugin created (a priori, a single one)
std::vector<int> tags;
gmshViewGetTags(tags);
gmsh::view::getTags(tags);
if(tags.size() == 1)
gmshViewExport(tags[0], "iso.msh");
gmsh::view::write(tags[0], "iso.msh");
gmshFinalize();
gmsh::finalize();
return 0;
}
#!/usr/bin/env python
from gmsh import *
import gmsh
import sys
gmshInitialize(sys.argv)
gmshOptionSetNumber("General.Terminal", 1)
gmsh.initialize(sys.argv)
gmsh.optionSetNumber("General.Terminal", 1)
# Copied from discrete.py...
gmshModelCreate("test");
gmshModelAddDiscreteEntity(2, 1)
gmshModelSetMeshVertices(2, 1, [1, 2, 3, 4],
gmsh.modelAdd("test");
gmsh.modelAddDiscreteEntity(2, 1)
gmsh.modelMeshSetVertices(2, 1, [1, 2, 3, 4],
[0., 0., 0.,
1., 0., 0.,
1., 1., 0.,
0., 1., 0.])
gmshModelSetMeshElements(2, 1, [2], [[1, 2]],
gmsh.modelMeshSetElements(2, 1, [2], [[1, 2]],
[[1, 2, 3,
1, 3, 4]])
# ... end of copy
# create a view with some data
t = gmshViewCreate("some data")
gmshViewAddModelData(t, "test", "NodeData",
t = gmsh.viewAdd("some data")
gmsh.viewAddModelData(t, "test", "NodeData",
[1, 2, 3, 4],
[[1.],[10.],[20.],[1.]])
# compute the iso-curve at value 11
gmshPluginSetNumber("Isosurface", "Value", 11.)
gmshPluginRun("Isosurface")
gmsh.pluginSetNumber("Isosurface", "Value", 11.)
gmsh.pluginRun("Isosurface")
# delete the source view
gmshViewDelete(t)
gmsh.viewRemove(t)
# check how many views the plugin created (a priori, a single one)
tags = IntVector()
gmshViewGetTags(tags)
tags = gmsh.IntVector()
gmsh.viewGetTags(tags)
if tags.size() == 1:
gmshViewExport(tags[0], "iso.msh")
gmsh.viewWrite(tags[0], "iso.msh")
gmshFinalize()
gmsh.finalize()
......@@ -10,17 +10,17 @@
int main(int argc, char **argv)
{
// Before using any functions in the C++ API, Gmsh must be initialized.
gmshInitialize();
gmsh::initialize();
// By default Gmsh will not print out any messages: in order to output
// messages on the terminal, just set the standard Gmsh option
// "General.Terminal" (same format and meaning as in .geo files) using
// gmshOptionSetNumber():
gmshOptionSetNumber("General.Terminal", 1);
gmsh::option::setNumber("General.Terminal", 1);
// This creates a new model, named "t1". If gmshModelCreate() is not called, a
// This adds a new model, named "t1". If gmsh::model::add() is not called, a
// new default (unnamed) model will be created on the fly, if necessary.
gmshModelCreate("t1");
gmsh::model::add("t1");
// The C++ API provides direct access to the internal CAD kernels. The
// built-in CAD kernel was used in t1.geo: the corresponding API functions
......@@ -33,35 +33,35 @@ int main(int argc, char **argv)
//
// - the last (optional) argument is the point tag
double lc = 1e-2;
gmshModelGeoAddPoint(0, 0, 0, lc, 1);
gmshModelGeoAddPoint(.1, 0, 0, lc, 2);
gmshModelGeoAddPoint(.1, .3, 0, lc, 3);
gmshModelGeoAddPoint(0, .3, 0, lc, 4);
gmsh::model::geo::addPoint(0, 0, 0, lc, 1);
gmsh::model::geo::addPoint(.1, 0, 0, lc, 2);
gmsh::model::geo::addPoint(.1, .3, 0, lc, 3);
gmsh::model::geo::addPoint(0, .3, 0, lc, 4);
// The API to create lines with the built-in kernel follows the same
// conventions: the first 2 arguments are point tags, the last (optional one)
// is the line tag.
gmshModelGeoAddLine(1, 2, 1);
gmshModelGeoAddLine(3, 2, 2);
gmshModelGeoAddLine(3, 4, 3);
gmshModelGeoAddLine(4, 1, 4);
gmsh::model::geo::addLine(1, 2, 1);
gmsh::model::geo::addLine(3, 2, 2);
gmsh::model::geo::addLine(3, 4, 3);
gmsh::model::geo::addLine(4, 1, 4);
// The philosophy to construct line loops and surfaces is similar: the first
// argument is now a vector of integers.
gmshModelGeoAddLineLoop({4, 1, -2, 3}, 1);
gmshModelGeoAddPlaneSurface({1}, 1);
gmsh::model::geo::addLineLoop({4, 1, -2, 3}, 1);
gmsh::model::geo::addPlaneSurface({1}, 1);
// Physical groups are defined by providing the dimension of the group (0 for
// physical points, 1 for physical lines, 2 for physical surfaces and 3 for
// phsyical volumes) followed by a vector of entity tags. The last (optional)
// argument is the tag of the new group to create.
gmshModelAddPhysicalGroup(0, {1, 2}, 1);
gmshModelAddPhysicalGroup(1, {1, 2}, 2);
gmshModelAddPhysicalGroup(2, {1}, 6);
gmsh::model::addPhysicalGroup(0, {1, 2}, 1);
gmsh::model::addPhysicalGroup(1, {1, 2}, 2);
gmsh::model::addPhysicalGroup(2, {1}, 6);
// Physical names are also defined by providing the dimension and tag of the
// entity.
gmshModelSetPhysicalName(2, 6, "My surface");
gmsh::model::setPhysicalName(2, 6, "My surface");
// Before it can be meshed, the internal CAD representation must be
// synchronized with the Gmsh model, which will create the relevant Gmsh data
......@@ -70,15 +70,15 @@ int main(int argc, char **argv)
// they involve a non trivial amount of processing; so while you could
// synchronize the internal CAD data after every CAD command, it is usually
// better to minimize the number of synchronization points.
gmshModelGeoSynchronize();
gmsh::model::geo::synchronize();
// We can then generate a 2D mesh...
gmshModelMesh(2);
gmsh::model::mesh::generate(2);
// ... and save it to disk
gmshExport("t1.msh");
gmsh::write("t1.msh");
// This should be called at the end:
gmshFinalize();
gmsh::finalize();
return 0;
}