From 23ebcf679a298a0864022953d92b1c71ba6f214b Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 24 Nov 2017 13:56:12 +0100
Subject: [PATCH] introduce namespaces in the API

---
 Common/gmsh.cpp        |  881 ++++++++++-----------
 Common/gmsh.h          | 1645 ++++++++++++++++++++--------------------
 Common/gmsh.i          |  133 ++++
 demos/api/boolean.cpp  |   36 +-
 demos/api/boolean.py   |   40 +-
 demos/api/discrete.cpp |   34 +-
 demos/api/discrete.py  |   18 +-
 demos/api/explore.cpp  |   15 +-
 demos/api/explore.py   |   26 +-
 demos/api/open.cpp     |   12 +-
 demos/api/open.py      |   14 +-
 demos/api/plugin.cpp   |   44 +-
 demos/api/plugin.py    |   32 +-
 demos/api/t1.cpp       |   44 +-
 demos/api/t1.py        |   44 +-
 demos/api/t10.cpp      |  103 +--
 demos/api/t10.py       |  112 +--
 demos/api/t16.cpp      |   38 +-
 demos/api/t16.py       |   42 +-
 demos/api/t2.cpp       |  131 ++--
 demos/api/t2.py        |  132 ++--
 demos/api/t3.cpp       |   53 +-
 demos/api/t3.py        |   54 +-
 demos/api/t4.cpp       |  126 +--
 demos/api/t4.py        |  124 +--
 demos/api/t5.cpp       |  212 +++---
 demos/api/t5.py        |  186 ++---
 demos/api/t6.cpp       |  109 +--
 demos/api/t6.py        |  106 +--
 demos/api/view.cpp     |   39 +-
 demos/api/view.py      |   22 +-
 demos/api/viewlist.cpp |   12 +-
 demos/api/viewlist.py  |   14 +-
 33 files changed, 2413 insertions(+), 2220 deletions(-)

diff --git a/Common/gmsh.cpp b/Common/gmsh.cpp
index 7c58348468..bffea8b6ab 100644
--- a/Common/gmsh.cpp
+++ b/Common/gmsh.cpp
@@ -61,7 +61,7 @@ static bool _isInitialized()
 
 // gmsh
 
-void gmshInitialize(int argc, char **argv)
+void gmsh::initialize(int argc, char **argv)
 {
   if(_initialized){
     Msg::Error("Gmsh has aleady been initialized");
@@ -74,7 +74,7 @@ void gmshInitialize(int argc, char **argv)
   throw -1;
 }
 
-void gmshFinalize()
+void gmsh::finalize()
 {
   if(!_isInitialized()){ throw -1; }
   if(GmshFinalize()){
@@ -85,35 +85,35 @@ void gmshFinalize()
   throw 1;
 }
 
-void gmshOpen(const std::string &fileName)
+void gmsh::open(const std::string &fileName)
 {
   if(!_isInitialized()){ throw -1; }
   if(GmshOpenProject(fileName)) return;
   throw 1;
 }
 
-void gmshMerge(const std::string &fileName)
+void gmsh::merge(const std::string &fileName)
 {
   if(!_isInitialized()){ throw -1; }
   if(GmshMergeFile(fileName)) return;
   throw 1;
 }
 
-void gmshExport(const std::string &fileName)
+void gmsh::write(const std::string &fileName)
 {
   if(!_isInitialized()){ throw -1; }
   if(GmshWriteFile(fileName)) return;
   throw 1;
 }
 
-void gmshClear()
+void gmsh::clear()
 {
   if(!_isInitialized()){ throw -1; }
   if(GmshClearProject()) return;
   throw 1;
 }
 
-// gmshOption
+// gmsh::option
 
 static void _splitOptionName(const std::string &fullName, std::string &category,
                              std::string &name, int &index)
@@ -140,7 +140,7 @@ static void _splitOptionName(const std::string &fullName, std::string &category,
              name.c_str(), index);
 }
 
-void gmshOptionSetNumber(const std::string &name, const double value)
+void gmsh::option::setNumber(const std::string &name, const double value)
 {
   if(!_isInitialized()){ throw -1; }
   std::string c, n;
@@ -150,7 +150,7 @@ void gmshOptionSetNumber(const std::string &name, const double value)
   throw 1;
 }
 
-void gmshOptionGetNumber(const std::string &name, double &value)
+void gmsh::option::getNumber(const std::string &name, double &value)
 {
   if(!_isInitialized()){ throw -1; }
   std::string c, n;
@@ -160,7 +160,7 @@ void gmshOptionGetNumber(const std::string &name, double &value)
   throw 1;
 }
 
-void gmshOptionSetString(const std::string &name, const std::string &value)
+void gmsh::option::setString(const std::string &name, const std::string &value)
 {
   if(!_isInitialized()){ throw -1; }
   std::string c, n;
@@ -170,7 +170,7 @@ void gmshOptionSetString(const std::string &name, const std::string &value)
   throw 1;
 }
 
-void gmshOptionGetString(const std::string &name, std::string &value)
+void gmsh::option::getString(const std::string &name, std::string &value)
 {
   if(!_isInitialized()){ throw -1; }
   std::string c, n;
@@ -180,16 +180,16 @@ void gmshOptionGetString(const std::string &name, std::string &value)
   throw 1;
 }
 
-// gmshModel
+// gmsh::model
 
-void gmshModelCreate(const std::string &name)
+void gmsh::model::add(const std::string &name)
 {
   if(!_isInitialized()){ throw -1; }
   GModel *m = new GModel(name);
   if(!m){ throw 1; }
 }
 
-void gmshModelDelete()
+void gmsh::model::remove()
 {
   if(!_isInitialized()){ throw -1; }
   GModel *m = GModel::current();
@@ -197,14 +197,14 @@ void gmshModelDelete()
   delete m;
 }
 
-void gmshModelList(std::vector<std::string> &names)
+void gmsh::model::list(std::vector<std::string> &names)
 {
   if(!_isInitialized()){ throw -1; }
   for(unsigned int i = 0; i < GModel::list.size(); i++)
     names.push_back(GModel::list[i]->getName());
 }
 
-void gmshModelSetCurrent(const std::string &name)
+void gmsh::model::setCurrent(const std::string &name)
 {
   if(!_isInitialized()){ throw -1; }
   GModel *m = GModel::findByName(name);
@@ -212,7 +212,7 @@ void gmshModelSetCurrent(const std::string &name)
   GModel::setCurrent(m);
 }
 
-void gmshModelGetEntities(vector_pair &dimTags, const int dim)
+void gmsh::model::getEntities(vector_pair &dimTags, const int dim)
 {
   if(!_isInitialized()){ throw -1; }
   dimTags.clear();
@@ -222,7 +222,7 @@ void gmshModelGetEntities(vector_pair &dimTags, const int dim)
     dimTags.push_back(std::pair<int, int>(entities[i]->dim(), entities[i]->tag()));
 }
 
-void gmshModelGetPhysicalGroups(vector_pair &dimTags, const int dim)
+void gmsh::model::getPhysicalGroups(vector_pair &dimTags, const int dim)
 {
   if(!_isInitialized()){ throw -1; }
   dimTags.clear();
@@ -237,8 +237,8 @@ void gmshModelGetPhysicalGroups(vector_pair &dimTags, const int dim)
   }
 }
 
-void gmshModelGetEntitiesForPhysicalGroup(const int dim, const int tag,
-                                          std::vector<int> &tags)
+void gmsh::model::getEntitiesForPhysicalGroup(const int dim, const int tag,
+                                              std::vector<int> &tags)
 {
   if(!_isInitialized()){ throw -1; }
   tags.clear();
@@ -251,8 +251,8 @@ void gmshModelGetEntitiesForPhysicalGroup(const int dim, const int tag,
   }
 }
 
-int gmshModelAddPhysicalGroup(const int dim, const std::vector<int> &tags,
-                              const int tag)
+int gmsh::model::addPhysicalGroup(const int dim, const std::vector<int> &tags,
+                                  const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -266,22 +266,22 @@ int gmshModelAddPhysicalGroup(const int dim, const std::vector<int> &tags,
   return outTag;
 }
 
-void gmshModelSetPhysicalName(const int dim, const int tag,
-                              const std::string &name)
+void gmsh::model::setPhysicalName(const int dim, const int tag,
+                                  const std::string &name)
 {
   if(!_isInitialized()){ throw -1; }
   GModel::current()->setPhysicalName(name, dim, tag);
 }
 
-void gmshModelGetPhysicalName(const int dim, const int tag, std::string &name)
+void gmsh::model::getPhysicalName(const int dim, const int tag, std::string &name)
 {
   if(!_isInitialized()){ throw -1; }
   name = GModel::current()->getPhysicalName(dim, tag);
 }
 
-void gmshModelGetBoundary(const vector_pair &dimTags, vector_pair &outDimTags,
-                          const bool combined, const bool oriented,
-                          const bool recursive)
+void gmsh::model::getBoundary(const vector_pair &dimTags, vector_pair &outDimTags,
+                              const bool combined, const bool oriented,
+                              const bool recursive)
 {
   if(!_isInitialized()){ throw -1; }
   outDimTags.clear();
@@ -291,10 +291,10 @@ void gmshModelGetBoundary(const vector_pair &dimTags, vector_pair &outDimTags,
   }
 }
 
-void gmshModelGetEntitiesInBoundingBox(const double xmin, const double ymin,
-                                       const double zmin, const double xmax,
-                                       const double ymax, const double zmax,
-                                       vector_pair &dimTags, const int dim)
+void gmsh::model::getEntitiesInBoundingBox(const double xmin, const double ymin,
+                                           const double zmin, const double xmax,
+                                           const double ymax, const double zmax,
+                                           vector_pair &dimTags, const int dim)
 {
   if(!_isInitialized()){ throw -1; }
   dimTags.clear();
@@ -318,9 +318,9 @@ static std::string _entityName(int dim, int tag)
   return stream.str();
 }
 
-void gmshModelGetBoundingBox(const int dim, const int tag, double &xmin,
-                             double &ymin, double &zmin, double &xmax,
-                             double &ymax, double &zmax)
+void gmsh::model::getBoundingBox(const int dim, const int tag, double &xmin,
+                                 double &ymin, double &zmin, double &xmax,
+                                 double &ymax, double &zmax)
 {
   if(!_isInitialized()){ throw -1; }
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
@@ -338,8 +338,8 @@ void gmshModelGetBoundingBox(const int dim, const int tag, double &xmin,
   zmax = box.max().z();
 }
 
-int gmshModelAddDiscreteEntity(const int dim, const int tag,
-                               const std::vector<int> &boundary)
+int gmsh::model::addDiscreteEntity(const int dim, const int tag,
+                                   const std::vector<int> &boundary)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -380,13 +380,15 @@ int gmshModelAddDiscreteEntity(const int dim, const int tag,
   return outTag;
 }
 
-void gmshModelRemove(const vector_pair &dimTags, const bool recursive)
+void gmsh::model::removeEntities(const vector_pair &dimTags, const bool recursive)
 {
   if(!_isInitialized()){ throw -1; }
   GModel::current()->remove(dimTags, recursive);
 }
 
-void gmshModelMesh(int dim)
+// gmsh::model::mesh
+
+void gmsh::model::mesh::generate(int dim)
 {
   if(!_isInitialized()){ throw -1; }
   GModel *m = GModel::current();
@@ -394,7 +396,7 @@ void gmshModelMesh(int dim)
   m->mesh(dim);
 }
 
-void gmshModelGetLastMeshEntityError(vector_pair &dimTags)
+void gmsh::model::mesh::getLastEntityError(vector_pair &dimTags)
 {
   if(!_isInitialized()){ throw -1; }
   std::vector<GEntity*> e = GModel::current()->getLastMeshEntityError();
@@ -403,7 +405,7 @@ void gmshModelGetLastMeshEntityError(vector_pair &dimTags)
     dimTags.push_back(std::pair<int, int>(e[i]->dim(), e[i]->tag()));
 }
 
-void gmshModelGetLastMeshVertexError(std::vector<int> &vertexTags)
+void gmsh::model::mesh::getLastVertexError(std::vector<int> &vertexTags)
 {
   if(!_isInitialized()){ throw -1; }
   std::vector<MVertex*> v = GModel::current()->getLastMeshVertexError();
@@ -412,10 +414,10 @@ void gmshModelGetLastMeshVertexError(std::vector<int> &vertexTags)
     vertexTags.push_back(v[i]->getNum());
 }
 
-void gmshModelGetMeshVertices(const int dim, const int tag,
-                              std::vector<int> &vertexTags,
-                              std::vector<double> &coord,
-                              std::vector<double> &parametricCoord)
+void gmsh::model::mesh::getVertices(const int dim, const int tag,
+                                    std::vector<int> &vertexTags,
+                                    std::vector<double> &coord,
+                                    std::vector<double> &parametricCoord)
 {
   if(!_isInitialized()){ throw -1; }
   vertexTags.clear();
@@ -456,10 +458,10 @@ static void _addElementInfo(const std::vector<T*> &ele,
   }
 }
 
-void gmshModelGetMeshElements(const int dim, const int tag,
-                              std::vector<int> &types,
-                              std::vector<std::vector<int> > &elementTags,
-                              std::vector<std::vector<int> > &vertexTags)
+void gmsh::model::mesh::getElements(const int dim, const int tag,
+                                    std::vector<int> &types,
+                                    std::vector<std::vector<int> > &elementTags,
+                                    std::vector<std::vector<int> > &vertexTags)
 {
   if(!_isInitialized()){ throw -1; }
   types.clear();
@@ -494,10 +496,10 @@ void gmshModelGetMeshElements(const int dim, const int tag,
   }
 }
 
-void gmshModelSetMeshVertices(const int dim, const int tag,
-                              const std::vector<int> &vertexTags,
-                              const std::vector<double> &coord,
-                              const std::vector<double> &parametricCoord)
+void gmsh::model::mesh::setVertices(const int dim, const int tag,
+                                    const std::vector<int> &vertexTags,
+                                    const std::vector<double> &coord,
+                                    const std::vector<double> &parametricCoord)
 {
   if(!_isInitialized()){ throw -1; }
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
@@ -550,10 +552,10 @@ static void _addElements(int dim, int tag, const std::vector<MElement*> &src,
     dst.push_back(static_cast<T*>(src[i]));
 }
 
-void gmshModelSetMeshElements(const int dim, const int tag,
-                              const std::vector<int> &types,
-                              const std::vector<std::vector<int> > &elementTags,
-                              const std::vector<std::vector<int> > &vertexTags)
+void gmsh::model::mesh::setElements(const int dim, const int tag,
+                                    const std::vector<int> &types,
+                                    const std::vector<std::vector<int> > &elementTags,
+                                    const std::vector<std::vector<int> > &vertexTags)
 {
   if(!_isInitialized()){ throw -1; }
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
@@ -636,9 +638,9 @@ void gmshModelSetMeshElements(const int dim, const int tag,
   }
 }
 
-void gmshModelGetMeshVertex(const int vertexTag,
-                            std::vector<double> &coord,
-                            std::vector<double> &parametricCoord)
+void gmsh::model::mesh::getVertex(const int vertexTag,
+                                  std::vector<double> &coord,
+                                  std::vector<double> &parametricCoord)
 {
   if(!_isInitialized()){ throw -1; }
   MVertex *v = GModel::current()->getMeshVertexByTag(vertexTag);
@@ -658,8 +660,8 @@ void gmshModelGetMeshVertex(const int vertexTag,
     parametricCoord.push_back(u);
 }
 
-void gmshModelGetMeshElement(const int elementTag, int &type,
-                             std::vector<int> &vertexTags)
+void gmsh::model::mesh::getElement(const int elementTag, int &type,
+                                   std::vector<int> &vertexTags)
 {
   if(!_isInitialized()){ throw -1; }
   MElement *e = GModel::current()->getMeshElementByTag(elementTag);
@@ -679,7 +681,7 @@ void gmshModelGetMeshElement(const int elementTag, int &type,
   }
 }
 
-void gmshModelSetMeshSize(const vector_pair &dimTags, const double size)
+void gmsh::model::mesh::setSize(const vector_pair &dimTags, const double size)
 {
   if(!_isInitialized()){ throw -1; }
   for(unsigned int i = 0; i < dimTags.size(); i++){
@@ -691,8 +693,9 @@ void gmshModelSetMeshSize(const vector_pair &dimTags, const double size)
   }
 }
 
-void gmshModelSetTransfiniteLine(const int tag, const int numVertices,
-                                 const std::string &type, const double coef)
+void gmsh::model::mesh::setTransfiniteLine(const int tag, const int numVertices,
+                                           const std::string &type,
+                                           const double coef)
 {
   if(!_isInitialized()){ throw -1; }
   GEdge *ge = GModel::current()->getEdgeByTag(tag);
@@ -711,9 +714,9 @@ void gmshModelSetTransfiniteLine(const int tag, const int numVertices,
   if(coef < 0) ge->meshAttributes.typeTransfinite *= -1;
 }
 
-void gmshModelSetTransfiniteSurface(const int tag,
-                                    const std::string &arrangement,
-                                    const std::vector<int> &cornerTags)
+void gmsh::model::mesh::setTransfiniteSurface(const int tag,
+                                              const std::string &arrangement,
+                                              const std::vector<int> &cornerTags)
 {
   if(!_isInitialized()){ throw -1; }
   GFace *gf = GModel::current()->getFaceByTag(tag);
@@ -738,8 +741,8 @@ void gmshModelSetTransfiniteSurface(const int tag,
   }
 }
 
-void gmshModelSetTransfiniteVolume(const int tag,
-                                   const std::vector<int> &cornerTags)
+void gmsh::model::mesh::setTransfiniteVolume(const int tag,
+                                             const std::vector<int> &cornerTags)
 {
   if(!_isInitialized()){ throw -1; }
   GRegion *gr = GModel::current()->getRegionByTag(tag);
@@ -757,7 +760,7 @@ void gmshModelSetTransfiniteVolume(const int tag,
   }
 }
 
-void gmshModelSetRecombine(const int dim, const int tag)
+void gmsh::model::mesh::setRecombine(const int dim, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   if(dim != 2){ throw 2; }
@@ -770,7 +773,7 @@ void gmshModelSetRecombine(const int dim, const int tag)
   gf->meshAttributes.recombineAngle = 45.;
 }
 
-void gmshModelSetSmoothing(const int dim, const int tag, const int val)
+void gmsh::model::mesh::setSmoothing(const int dim, const int tag, const int val)
 {
   if(!_isInitialized()){ throw -1; }
   if(dim != 2){ throw 2; }
@@ -782,7 +785,7 @@ void gmshModelSetSmoothing(const int dim, const int tag, const int val)
   gf->meshAttributes.transfiniteSmoothing = val;
 }
 
-void gmshModelSetReverseMesh(const int dim, const int tag, const bool val)
+void gmsh::model::mesh::setReverse(const int dim, const int tag, const bool val)
 {
   if(!_isInitialized()){ throw -1; }
   if(dim == 1){
@@ -803,8 +806,8 @@ void gmshModelSetReverseMesh(const int dim, const int tag, const bool val)
   }
 }
 
-void gmshModelEmbed(const int dim, const std::vector<int> &tags,
-                    const int inDim, const int inTag)
+void gmsh::model::mesh::embed(const int dim, const std::vector<int> &tags,
+                              const int inDim, const int inTag)
 {
   if(!_isInitialized()){ throw -1; }
   if(inDim == 2){
@@ -867,10 +870,141 @@ void gmshModelEmbed(const int dim, const std::vector<int> &tags,
   }
 }
 
-// gmshModelGeo
+// gmsh::model::mesh::field
 
-int gmshModelGeoAddPoint(const double x, const double y, const double z,
-                         const double meshSize, const int tag)
+int gmsh::model::mesh::field::add(const std::string &type, const int tag)
+{
+  if(!_isInitialized()){ throw -1; }
+  int outTag = tag;
+#if defined(HAVE_MESH)
+  if(outTag < 0){
+    outTag = GModel::current()->getFields()->newId();
+  }
+  if(!GModel::current()->getFields()->newField(tag, type)){
+    Msg::Error("Cannot add Field %i of type '%s'", tag, type.c_str());
+    throw 1;
+  }
+#else
+  Msg::Error("Fields require the mesh module");
+  throw -1;
+#endif
+  return outTag;
+}
+
+void gmsh::model::mesh::field::remove(const int tag)
+{
+  if(!_isInitialized()){ throw -1; }
+#if defined(HAVE_MESH)
+  GModel::current()->getFields()->deleteField(tag);
+#else
+  Msg::Error("Fields require the mesh module");
+  throw -1;
+#endif
+}
+
+#if defined(HAVE_MESH)
+static FieldOption *_getFieldOption(const int tag, const std::string &option)
+{
+  Field *field = GModel::current()->getFields()->get(tag);
+  if(!field){
+    Msg::Error("No field with id %i", tag);
+    return 0;
+  }
+  FieldOption *o = field->options[option];
+  if(!o){
+    Msg::Error("Unknown option '%s' in field %i of type '%s'", option.c_str(),
+               tag, field->getName());
+    return 0;
+  }
+  return o;
+}
+#endif
+
+void gmsh::model::mesh::field::setNumber(const int tag, const std::string &option,
+                                         const double value)
+{
+  if(!_isInitialized()){ throw -1; }
+#if defined(HAVE_MESH)
+  FieldOption *o = _getFieldOption(tag, option);
+  if(!o){ throw 1; }
+  try { o->numericalValue(value); }
+  catch(...){
+    Msg::Error("Cannot set numerical value to option '%s' in field %i",
+               option.c_str(), tag);
+    throw 1;
+  }
+#else
+  Msg::Error("Fields require the mesh module");
+  throw -1;
+#endif
+}
+
+void gmsh::model::mesh::field::setString(const int tag, const std::string &option,
+                                         const std::string &value)
+{
+  if(!_isInitialized()){ throw -1; }
+#if defined(HAVE_MESH)
+  FieldOption *o = _getFieldOption(tag, option);
+  if(!o){ throw 1; }
+  try { o->string(value); }
+  catch(...){
+    Msg::Error("Cannot set string value to option '%s' in field %i",
+               option.c_str(), tag);
+    throw 1;
+  }
+#else
+  Msg::Error("Fields require the mesh module");
+  throw -1;
+#endif
+}
+
+void gmsh::model::mesh::field::setNumbers(const int tag, const std::string &option,
+                                          const std::vector<double> &value)
+{
+  if(!_isInitialized()){ throw -1; }
+#if defined(HAVE_MESH)
+  FieldOption *o = _getFieldOption(tag, option);
+  if(!o){ throw 1; }
+  try {
+    if(o->getType() == FIELD_OPTION_LIST) {
+      std::list<int> vl;
+      for(unsigned int i = 0; i < value.size(); i++)
+        vl.push_back((int)value[i]);
+      o->list(vl);
+    }
+    else{
+      std::list<double> vl;
+      for(unsigned int i = 0; i < value.size(); i++)
+        vl.push_back(value[i]);
+      o->listdouble(vl);
+    }
+  }
+  catch(...){
+    Msg::Error("Cannot set numeric values to option '%s' in field %i",
+               option.c_str(), tag);
+    throw 1;
+  }
+#else
+  Msg::Error("Fields require the mesh module");
+  throw -1;
+#endif
+}
+
+void gmsh::model::mesh::field::setAsBackground(const int tag)
+{
+  if(!_isInitialized()){ throw -1; }
+#if defined(HAVE_MESH)
+  GModel::current()->getFields()->setBackgroundFieldId(tag);
+#else
+  Msg::Error("Fields require the mesh module");
+  throw -1;
+#endif
+}
+
+// gmsh::model::geo
+
+int gmsh::model::geo::addPoint(const double x, const double y, const double z,
+                               const double meshSize, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -884,7 +1018,7 @@ int gmshModelGeoAddPoint(const double x, const double y, const double z,
   return outTag;
 }
 
-int gmshModelGeoAddLine(const int startTag, const int endTag, const int tag)
+int gmsh::model::geo::addLine(const int startTag, const int endTag, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -894,9 +1028,9 @@ int gmshModelGeoAddLine(const int startTag, const int endTag, const int tag)
   return outTag;
 }
 
-int gmshModelGeoAddCircleArc(const int startTag, const int centerTag,
-                             const int endTag, const int tag, const double nx,
-                             const double ny, const double nz)
+int gmsh::model::geo::addCircleArc(const int startTag, const int centerTag,
+                                   const int endTag, const int tag, const double nx,
+                                   const double ny, const double nz)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -907,10 +1041,10 @@ int gmshModelGeoAddCircleArc(const int startTag, const int centerTag,
   return outTag;
 }
 
-int gmshModelGeoAddEllipseArc(const int startTag, const int centerTag,
-                              const int majorTag, const int endTag,
-                              const int tag, const double nx, const double ny,
-                              const double nz)
+int gmsh::model::geo::addEllipseArc(const int startTag, const int centerTag,
+                                    const int majorTag, const int endTag,
+                                    const int tag, const double nx, const double ny,
+                                    const double nz)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -921,7 +1055,8 @@ int gmshModelGeoAddEllipseArc(const int startTag, const int centerTag,
   return outTag;
 }
 
-int gmshModelGeoAddSpline(const std::vector<int> &vertexTags, const int tag)
+int gmsh::model::geo::addSpline(const std::vector<int> &vertexTags,
+                                const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -931,7 +1066,8 @@ int gmshModelGeoAddSpline(const std::vector<int> &vertexTags, const int tag)
   return outTag;
 }
 
-int gmshModelGeoAddBSpline(const std::vector<int> &vertexTags, const int tag)
+int gmsh::model::geo::addBSpline(const std::vector<int> &vertexTags,
+                                 const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -941,7 +1077,8 @@ int gmshModelGeoAddBSpline(const std::vector<int> &vertexTags, const int tag)
   return outTag;
 }
 
-int gmshModelGeoAddBezier(const std::vector<int> &vertexTags, const int tag)
+int gmsh::model::geo::addBezier(const std::vector<int> &vertexTags,
+                                const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -951,7 +1088,8 @@ int gmshModelGeoAddBezier(const std::vector<int> &vertexTags, const int tag)
   return outTag;
 }
 
-int gmshModelGeoAddLineLoop(const std::vector<int> &edgeTags, const int tag)
+int gmsh::model::geo::addLineLoop(const std::vector<int> &edgeTags,
+                                  const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -961,7 +1099,8 @@ int gmshModelGeoAddLineLoop(const std::vector<int> &edgeTags, const int tag)
   return outTag;
 }
 
-int gmshModelGeoAddPlaneSurface(const std::vector<int> &wireTags, const int tag)
+int gmsh::model::geo::addPlaneSurface(const std::vector<int> &wireTags,
+                                      const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -971,8 +1110,9 @@ int gmshModelGeoAddPlaneSurface(const std::vector<int> &wireTags, const int tag)
   return outTag;
 }
 
-int gmshModelGeoAddSurfaceFilling(const std::vector<int> &wireTags, const int tag,
-                                  const int sphereCenterTag)
+int gmsh::model::geo::addSurfaceFilling(const std::vector<int> &wireTags,
+                                        const int tag,
+                                        const int sphereCenterTag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -983,7 +1123,8 @@ int gmshModelGeoAddSurfaceFilling(const std::vector<int> &wireTags, const int ta
   return outTag;
 }
 
-int gmshModelGeoAddSurfaceLoop(const std::vector<int> &faceTags, const int tag)
+int gmsh::model::geo::addSurfaceLoop(const std::vector<int> &faceTags,
+                                     const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -993,7 +1134,7 @@ int gmshModelGeoAddSurfaceLoop(const std::vector<int> &faceTags, const int tag)
   return outTag;
 }
 
-int gmshModelGeoAddVolume(const std::vector<int> &shellTags, const int tag)
+int gmsh::model::geo::addVolume(const std::vector<int> &shellTags, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   int outTag = tag;
@@ -1025,12 +1166,12 @@ static ExtrudeParams *_getExtrudeParams(const std::vector<int> &numElements,
   return e;
 }
 
-void gmshModelGeoExtrude(const vector_pair &dimTags,
-                         const double dx, const double dy, const double dz,
-                         vector_pair &outDimTags,
-                         const std::vector<int> &numElements,
-                         const std::vector<double> &heights,
-                         const bool recombine)
+void gmsh::model::geo::extrude(const vector_pair &dimTags,
+                               const double dx, const double dy, const double dz,
+                               vector_pair &outDimTags,
+                               const std::vector<int> &numElements,
+                               const std::vector<double> &heights,
+                               const bool recombine)
 {
   if(!_isInitialized()){ throw -1; }
   outDimTags.clear();
@@ -1041,14 +1182,14 @@ void gmshModelGeoExtrude(const vector_pair &dimTags,
   }
 }
 
-void gmshModelGeoRevolve(const vector_pair &dimTags,
-                         const double x, const double y, const double z,
-                         const double ax, const double ay, const double az,
-                         const double angle,
-                         vector_pair &outDimTags,
-                         const std::vector<int> &numElements,
-                         const std::vector<double> &heights,
-                         const bool recombine)
+void gmsh::model::geo::revolve(const vector_pair &dimTags,
+                               const double x, const double y, const double z,
+                               const double ax, const double ay, const double az,
+                               const double angle,
+                               vector_pair &outDimTags,
+                               const std::vector<int> &numElements,
+                               const std::vector<double> &heights,
+                               const bool recombine)
 {
   if(!_isInitialized()){ throw -1; }
   outDimTags.clear();
@@ -1059,15 +1200,15 @@ void gmshModelGeoRevolve(const vector_pair &dimTags,
   }
 }
 
-void gmshModelGeoTwist(const vector_pair &dimTags,
-                       const double x, const double y, const double z,
-                       const double dx, const double dy, const double dz,
-                       const double ax, const double ay, const double az,
-                       const double angle,
-                       vector_pair &outDimTags,
-                       const std::vector<int> &numElements,
-                       const std::vector<double> &heights,
-                       const bool recombine)
+void gmsh::model::geo::twist(const vector_pair &dimTags,
+                             const double x, const double y, const double z,
+                             const double dx, const double dy, const double dz,
+                             const double ax, const double ay, const double az,
+                             const double angle,
+                             vector_pair &outDimTags,
+                             const std::vector<int> &numElements,
+                             const std::vector<double> &heights,
+                             const bool recombine)
 {
   if(!_isInitialized()){ throw -1; }
   outDimTags.clear();
@@ -1078,8 +1219,8 @@ void gmshModelGeoTwist(const vector_pair &dimTags,
   }
 }
 
-void gmshModelGeoTranslate(const vector_pair &dimTags, const double dx,
-                           const double dy, const double dz)
+void gmsh::model::geo::translate(const vector_pair &dimTags, const double dx,
+                                 const double dy, const double dz)
 {
   if(!_isInitialized()){ throw -1; }
   if(!GModel::current()->getGEOInternals()->translate(dimTags, dx, dy, dz)){
@@ -1087,9 +1228,9 @@ void gmshModelGeoTranslate(const vector_pair &dimTags, const double dx,
   }
 }
 
-void gmshModelGeoRotate(const vector_pair &dimTags, const double x,
-                        const double y, const double z, const double ax,
-                        const double ay, const double az, const double angle)
+void gmsh::model::geo::rotate(const vector_pair &dimTags, const double x,
+                              const double y, const double z, const double ax,
+                              const double ay, const double az, const double angle)
 {
   if(!_isInitialized()){ throw -1; }
   if(!GModel::current()->getGEOInternals()->rotate
@@ -1098,9 +1239,9 @@ void gmshModelGeoRotate(const vector_pair &dimTags, const double x,
   }
 }
 
-void gmshModelGeoDilate(const vector_pair &dimTags, const double x,
-                        const double y, const double z, const double a,
-                        const double b, const double c)
+void gmsh::model::geo::dilate(const vector_pair &dimTags, const double x,
+                              const double y, const double z, const double a,
+                              const double b, const double c)
 {
   if(!_isInitialized()){ throw -1; }
   if(!GModel::current()->getGEOInternals()->dilate
@@ -1109,8 +1250,8 @@ void gmshModelGeoDilate(const vector_pair &dimTags, const double x,
   }
 }
 
-void gmshModelGeoSymmetry(const vector_pair &dimTags, const double a,
-                          const double b, const double c, const double d)
+void gmsh::model::geo::symmetry(const vector_pair &dimTags, const double a,
+                                const double b, const double c, const double d)
 {
   if(!_isInitialized()){ throw -1; }
   if(!GModel::current()->getGEOInternals()->symmetry
@@ -1119,7 +1260,7 @@ void gmshModelGeoSymmetry(const vector_pair &dimTags, const double a,
   }
 }
 
-void gmshModelGeoCopy(const vector_pair &dimTags, vector_pair &outDimTags)
+void gmsh::model::geo::copy(const vector_pair &dimTags, vector_pair &outDimTags)
 {
   if(!_isInitialized()){ throw -1; }
   outDimTags.clear();
@@ -1128,7 +1269,7 @@ void gmshModelGeoCopy(const vector_pair &dimTags, vector_pair &outDimTags)
   }
 }
 
-void gmshModelGeoRemove(const vector_pair &dimTags, const bool recursive)
+void gmsh::model::geo::remove(const vector_pair &dimTags, const bool recursive)
 {
   if(!_isInitialized()){ throw -1; }
   if(!GModel::current()->getGEOInternals()->remove(dimTags, recursive)){
@@ -1136,15 +1277,23 @@ void gmshModelGeoRemove(const vector_pair &dimTags, const bool recursive)
   }
 }
 
-void gmshModelGeoRemoveAllDuplicates()
+void gmsh::model::geo::removeAllDuplicates()
 {
   if(!_isInitialized()){ throw -1; }
   GModel::current()->getGEOInternals()->removeAllDuplicates();
 }
 
-void gmshModelGeoSetTransfiniteLine(const int tag, const int nPoints,
-                                    const std::string &type,
-                                    const double coef)
+void gmsh::model::geo::synchronize()
+{
+  if(!_isInitialized()){ throw -1; }
+  GModel::current()->getGEOInternals()->synchronize(GModel::current());
+}
+
+// gmsh::model::geo::mesh
+
+void gmsh::model::geo::mesh::setTransfiniteLine(const int tag, const int nPoints,
+                                                const std::string &type,
+                                                const double coef)
 {
   if(!_isInitialized()){ throw -1; }
   int t =
@@ -1157,9 +1306,9 @@ void gmshModelGeoSetTransfiniteLine(const int tag, const int nPoints,
   GModel::current()->getGEOInternals()->setTransfiniteLine(tag, nPoints, t, c);
 }
 
-void gmshModelGeoSetTransfiniteSurface(const int tag,
-                                       const std::string &arrangement,
-                                       const std::vector<int> &cornerTags)
+void gmsh::model::geo::mesh::setTransfiniteSurface(const int tag,
+                                                   const std::string &arrangement,
+                                                   const std::vector<int> &cornerTags)
 {
   if(!_isInitialized()){ throw -1; }
   int t =
@@ -1172,33 +1321,34 @@ void gmshModelGeoSetTransfiniteSurface(const int tag,
   GModel::current()->getGEOInternals()->setTransfiniteSurface(tag, t, cornerTags);
 }
 
-void gmshModelGeoSetTransfiniteVolume(const int tag,
-                                      const std::vector<int> &cornerTags)
+void gmsh::model::geo::mesh::setTransfiniteVolume(const int tag,
+                                                  const std::vector<int> &cornerTags)
 {
   if(!_isInitialized()){ throw -1; }
   GModel::current()->getGEOInternals()->setTransfiniteVolume(tag, cornerTags);
 }
 
-void gmshModelGeoSetRecombine(const int dim, const int tag, const double angle)
+void gmsh::model::geo::mesh::setRecombine(const int dim, const int tag,
+                                          const double angle)
 {
   if(!_isInitialized()){ throw -1; }
   GModel::current()->getGEOInternals()->setRecombine(dim, tag, angle);
 }
 
-void gmshModelGeoSetSmoothing(const int dim, const int tag, const int val)
+void gmsh::model::geo::mesh::setSmoothing(const int dim, const int tag, const int val)
 {
   if(!_isInitialized()){ throw -1; }
   if(dim != 2){ throw 2; }
   GModel::current()->getGEOInternals()->setSmoothing(tag, val);
 }
 
-void gmshModelGeoSetReverseMesh(const int dim, const int tag, const bool val)
+void gmsh::model::geo::mesh::setReverse(const int dim, const int tag, const bool val)
 {
   if(!_isInitialized()){ throw -1; }
   GModel::current()->getGEOInternals()->setReverseMesh(dim, tag, val);
 }
 
-void gmshModelGeoSetMeshSize(const vector_pair &dimTags, const double size)
+void gmsh::model::geo::mesh::setSize(const vector_pair &dimTags, const double size)
 {
   if(!_isInitialized()){ throw -1; }
   for(unsigned int i = 0; i < dimTags.size(); i++){
@@ -1207,21 +1357,15 @@ void gmshModelGeoSetMeshSize(const vector_pair &dimTags, const double size)
   }
 }
 
-void gmshModelGeoSynchronize()
-{
-  if(!_isInitialized()){ throw -1; }
-  GModel::current()->getGEOInternals()->synchronize(GModel::current());
-}
-
-// gmshModelOcc
+// gmsh::model::occ
 
 static void _createOcc()
 {
   if(!GModel::current()->getOCCInternals()) GModel::current()->createOCCInternals();
 }
 
-int gmshModelOccAddPoint(const double x, const double y, const double z,
-                         const double meshSize, const int tag)
+int gmsh::model::occ::addPoint(const double x, const double y, const double z,
+                               const double meshSize, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1232,7 +1376,7 @@ int gmshModelOccAddPoint(const double x, const double y, const double z,
   return outTag;
 }
 
-int gmshModelOccAddLine(const int startTag, const int endTag, const int tag)
+int gmsh::model::occ::addLine(const int startTag, const int endTag, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1243,8 +1387,8 @@ int gmshModelOccAddLine(const int startTag, const int endTag, const int tag)
   return outTag;
 }
 
-int gmshModelOccAddCircleArc(const int startTag, const int centerTag,
-                             const int endTag, const int tag)
+int gmsh::model::occ::addCircleArc(const int startTag, const int centerTag,
+                                   const int endTag, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1256,9 +1400,9 @@ int gmshModelOccAddCircleArc(const int startTag, const int centerTag,
   return outTag;
 }
 
-int gmshModelOccAddCircle(const double x, const double y, const double z,
-                          const double r, const int tag,
-                          const double angle1, const double angle2)
+int gmsh::model::occ::addCircle(const double x, const double y, const double z,
+                                const double r, const int tag,
+                                const double angle1, const double angle2)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1270,8 +1414,8 @@ int gmshModelOccAddCircle(const double x, const double y, const double z,
   return outTag;
 }
 
-int gmshModelOccAddEllipseArc(const int startTag, const int centerTag,
-                              const int endTag, const int tag)
+int gmsh::model::occ::addEllipseArc(const int startTag, const int centerTag,
+                                    const int endTag, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1283,10 +1427,10 @@ int gmshModelOccAddEllipseArc(const int startTag, const int centerTag,
   return outTag;
 }
 
-int gmshModelOccAddEllipse(const double x, const double y, const double z,
-                           const double r1, const double r2,
-                           const int tag,
-                           const double angle1, const double angle2)
+int gmsh::model::occ::addEllipse(const double x, const double y, const double z,
+                                 const double r1, const double r2,
+                                 const int tag,
+                                 const double angle1, const double angle2)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1298,7 +1442,7 @@ int gmshModelOccAddEllipse(const double x, const double y, const double z,
   return outTag;
 }
 
-int gmshModelOccAddSpline(const std::vector<int> &vertexTags, const int tag)
+int gmsh::model::occ::addSpline(const std::vector<int> &vertexTags, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1309,7 +1453,7 @@ int gmshModelOccAddSpline(const std::vector<int> &vertexTags, const int tag)
   return outTag;
 }
 
-int gmshModelOccAddBezier(const std::vector<int> &vertexTags, const int tag)
+int gmsh::model::occ::addBezier(const std::vector<int> &vertexTags, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1320,7 +1464,7 @@ int gmshModelOccAddBezier(const std::vector<int> &vertexTags, const int tag)
   return outTag;
 }
 
-int gmshModelOccAddBSpline(const std::vector<int> &vertexTags, const int tag)
+int gmsh::model::occ::addBSpline(const std::vector<int> &vertexTags, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1331,8 +1475,8 @@ int gmshModelOccAddBSpline(const std::vector<int> &vertexTags, const int tag)
   return outTag;
 }
 
-int gmshModelOccAddWire(const std::vector<int> &edgeTags, const int tag,
-                        const bool checkClosed)
+int gmsh::model::occ::addWire(const std::vector<int> &edgeTags, const int tag,
+                              const bool checkClosed)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1344,7 +1488,7 @@ int gmshModelOccAddWire(const std::vector<int> &edgeTags, const int tag,
   return outTag;
 }
 
-int gmshModelOccAddLineLoop(const std::vector<int> &edgeTags, const int tag)
+int gmsh::model::occ::addLineLoop(const std::vector<int> &edgeTags, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1355,9 +1499,9 @@ int gmshModelOccAddLineLoop(const std::vector<int> &edgeTags, const int tag)
   return outTag;
 }
 
-int gmshModelOccAddRectangle(const double x, const double y, const double z,
-                             const double dx, const double dy, const int tag,
-                             const double roundedRadius)
+int gmsh::model::occ::addRectangle(const double x, const double y, const double z,
+                                   const double dx, const double dy, const int tag,
+                                   const double roundedRadius)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1369,8 +1513,8 @@ int gmshModelOccAddRectangle(const double x, const double y, const double z,
   return outTag;
 }
 
-int gmshModelOccAddDisk(const double xc, const double yc, const double zc,
-                        const double rx, const double ry, const int tag)
+int gmsh::model::occ::addDisk(const double xc, const double yc, const double zc,
+                              const double rx, const double ry, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1382,7 +1526,8 @@ int gmshModelOccAddDisk(const double xc, const double yc, const double zc,
   return outTag;
 }
 
-int gmshModelOccAddPlaneSurface(const std::vector<int> &wireTags, const int tag)
+int gmsh::model::occ::addPlaneSurface(const std::vector<int> &wireTags,
+                                      const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1393,7 +1538,7 @@ int gmshModelOccAddPlaneSurface(const std::vector<int> &wireTags, const int tag)
   return outTag;
 }
 
-int gmshModelOccAddSurfaceFilling(const int wireTag, const int tag)
+int gmsh::model::occ::addSurfaceFilling(const int wireTag, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1404,7 +1549,8 @@ int gmshModelOccAddSurfaceFilling(const int wireTag, const int tag)
   return outTag;
 }
 
-int gmshModelOccAddSurfaceLoop(const std::vector<int> &faceTags, const int tag)
+int gmsh::model::occ::addSurfaceLoop(const std::vector<int> &faceTags,
+                                     const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1415,7 +1561,7 @@ int gmshModelOccAddSurfaceLoop(const std::vector<int> &faceTags, const int tag)
   return outTag;
 }
 
-int gmshModelOccAddVolume(const std::vector<int> &shellTags, const int tag)
+int gmsh::model::occ::addVolume(const std::vector<int> &shellTags, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1426,10 +1572,10 @@ int gmshModelOccAddVolume(const std::vector<int> &shellTags, const int tag)
   return outTag;
 }
 
-int gmshModelOccAddSphere(const double xc, const double yc, const double zc,
-                          const double radius, const int tag,
-                          const double angle1, const double angle2,
-                          const double angle3)
+int gmsh::model::occ::addSphere(const double xc, const double yc, const double zc,
+                                const double radius, const int tag,
+                                const double angle1, const double angle2,
+                                const double angle3)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1441,9 +1587,9 @@ int gmshModelOccAddSphere(const double xc, const double yc, const double zc,
   return outTag;
 }
 
-int gmshModelOccAddBox(const double x, const double y, const double z,
-                       const double dx, const double dy, const double dz,
-                       const int tag)
+int gmsh::model::occ::addBox(const double x, const double y, const double z,
+                             const double dx, const double dy, const double dz,
+                             const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1455,9 +1601,9 @@ int gmshModelOccAddBox(const double x, const double y, const double z,
   return outTag;
 }
 
-int gmshModelOccAddCylinder(const double x, const double y, const double z,
-                            const double dx, const double dy, const double dz,
-                            const double r, const int tag, const double angle)
+int gmsh::model::occ::addCylinder(const double x, const double y, const double z,
+                                  const double dx, const double dy, const double dz,
+                                  const double r, const int tag, const double angle)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1469,10 +1615,10 @@ int gmshModelOccAddCylinder(const double x, const double y, const double z,
   return outTag;
 }
 
-int gmshModelOccAddCone(const double x, const double y, const double z,
-                        const double dx, const double dy, const double dz,
-                        const double r1, const double r2, const int tag,
-                        const double angle)
+int gmsh::model::occ::addCone(const double x, const double y, const double z,
+                              const double dx, const double dy, const double dz,
+                              const double r1, const double r2, const int tag,
+                              const double angle)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1484,9 +1630,9 @@ int gmshModelOccAddCone(const double x, const double y, const double z,
   return outTag;
 }
 
-int gmshModelOccAddWedge(const double x, const double y, const double z,
-                         const double dx, const double dy, const double dz,
-                         const int tag, const double ltx)
+int gmsh::model::occ::addWedge(const double x, const double y, const double z,
+                               const double dx, const double dy, const double dz,
+                               const int tag, const double ltx)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1498,9 +1644,9 @@ int gmshModelOccAddWedge(const double x, const double y, const double z,
   return outTag;
 }
 
-int gmshModelOccAddTorus(const double x, const double y, const double z,
-                         const double r1, const double r2, const int tag,
-                         const double angle)
+int gmsh::model::occ::addTorus(const double x, const double y, const double z,
+                               const double r1, const double r2, const int tag,
+                               const double angle)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1512,10 +1658,10 @@ int gmshModelOccAddTorus(const double x, const double y, const double z,
   return outTag;
 }
 
-int gmshModelOccAddThruSections(const std::vector<int> &wireTags,
-                                vector_pair &outDimTags,
-                                const int tag, const bool makeSolid,
-                                const bool makeRuled)
+int gmsh::model::occ::addThruSections(const std::vector<int> &wireTags,
+                                      vector_pair &outDimTags,
+                                      const int tag, const bool makeSolid,
+                                      const bool makeRuled)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1528,10 +1674,10 @@ int gmshModelOccAddThruSections(const std::vector<int> &wireTags,
   return outTag;
 }
 
-int addThickSolid(const int solidTag,
-                  const std::vector<int> &excludeFaceTags,
-                  const double offset, vector_pair &outDimTags,
-                  const int tag)
+int gmsh::model::occ::addThickSolid(const int solidTag,
+                                    const std::vector<int> &excludeFaceTags,
+                                    const double offset, vector_pair &outDimTags,
+                                    const int tag)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1544,12 +1690,12 @@ int addThickSolid(const int solidTag,
   return outTag;
 }
 
-void gmshModelOccExtrude(const vector_pair &dimTags,
-                         const double dx, const double dy, const double dz,
-                         vector_pair &outDimTags,
-                         const std::vector<int> &numElements,
-                         const std::vector<double> &heights,
-                         const bool recombine)
+void gmsh::model::occ::extrude(const vector_pair &dimTags,
+                               const double dx, const double dy, const double dz,
+                               vector_pair &outDimTags,
+                               const std::vector<int> &numElements,
+                               const std::vector<double> &heights,
+                               const bool recombine)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1561,13 +1707,13 @@ void gmshModelOccExtrude(const vector_pair &dimTags,
   }
 }
 
-void gmshModelOccRevolve(const vector_pair &dimTags,
-                         const double x, const double y, const double z,
-                         const double ax, const double ay, const double az,
-                         const double angle, vector_pair &outDimTags,
-                         const std::vector<int> &numElements,
-                         const std::vector<double> &heights,
-                         const bool recombine)
+void gmsh::model::occ::revolve(const vector_pair &dimTags,
+                               const double x, const double y, const double z,
+                               const double ax, const double ay, const double az,
+                               const double angle, vector_pair &outDimTags,
+                               const std::vector<int> &numElements,
+                               const std::vector<double> &heights,
+                               const bool recombine)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1579,8 +1725,8 @@ void gmshModelOccRevolve(const vector_pair &dimTags,
   }
 }
 
-void gmshModelOccAddPipe(const vector_pair &dimTags, const int wireTag,
-                         vector_pair &outDimTags)
+void gmsh::model::occ::addPipe(const vector_pair &dimTags, const int wireTag,
+                               vector_pair &outDimTags)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1591,10 +1737,10 @@ void gmshModelOccAddPipe(const vector_pair &dimTags, const int wireTag,
   }
 }
 
-void gmshModelOccFillet(const std::vector<int> &regionTags,
-                        const std::vector<int> &edgeTags,
-                        const double radius, vector_pair &outDimTags,
-                        const bool removeRegion)
+void gmsh::model::occ::fillet(const std::vector<int> &regionTags,
+                              const std::vector<int> &edgeTags,
+                              const double radius, vector_pair &outDimTags,
+                              const bool removeRegion)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1605,13 +1751,13 @@ void gmshModelOccFillet(const std::vector<int> &regionTags,
   }
 }
 
-int gmshModelOccBooleanUnion(const vector_pair &objectDimTags,
-                             const vector_pair &toolDimTags,
-                             vector_pair &outDimTags,
-                             std::vector<vector_pair > &outDimTagsMap,
-                             const int tag,
-                             const bool removeObject,
-                             const bool removeTool)
+int gmsh::model::occ::booleanUnion(const vector_pair &objectDimTags,
+                                   const vector_pair &toolDimTags,
+                                   vector_pair &outDimTags,
+                                   std::vector<vector_pair > &outDimTagsMap,
+                                   const int tag,
+                                   const bool removeObject,
+                                   const bool removeTool)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1626,13 +1772,13 @@ int gmshModelOccBooleanUnion(const vector_pair &objectDimTags,
   return outTag;
 }
 
-int gmshModelOccBooleanIntersection(const vector_pair &objectDimTags,
-                                    const vector_pair &toolDimTags,
-                                    vector_pair &outDimTags,
-                                    std::vector<vector_pair> &outDimTagsMap,
-                                    const int tag,
-                                    const bool removeObject,
-                                    const bool removeTool)
+int gmsh::model::occ::booleanIntersection(const vector_pair &objectDimTags,
+                                          const vector_pair &toolDimTags,
+                                          vector_pair &outDimTags,
+                                          std::vector<vector_pair> &outDimTagsMap,
+                                          const int tag,
+                                          const bool removeObject,
+                                          const bool removeTool)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1647,13 +1793,13 @@ int gmshModelOccBooleanIntersection(const vector_pair &objectDimTags,
   return outTag;
 }
 
-int gmshModelOccBooleanDifference(const vector_pair &objectDimTags,
-                                  const vector_pair &toolDimTags,
-                                  vector_pair &outDimTags,
-                                  std::vector<vector_pair> &outDimTagsMap,
-                                  const int tag,
-                                  const bool removeObject,
-                                  const bool removeTool)
+int gmsh::model::occ::booleanDifference(const vector_pair &objectDimTags,
+                                        const vector_pair &toolDimTags,
+                                        vector_pair &outDimTags,
+                                        std::vector<vector_pair> &outDimTagsMap,
+                                        const int tag,
+                                        const bool removeObject,
+                                        const bool removeTool)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1668,13 +1814,13 @@ int gmshModelOccBooleanDifference(const vector_pair &objectDimTags,
   return outTag;
 }
 
-int gmshModelOccBooleanFragments(const vector_pair &objectDimTags,
-                                 const vector_pair &toolDimTags,
-                                 vector_pair &outDimTags,
-                                 std::vector<vector_pair> &outDimTagsMap,
-                                 const int tag,
-                                 const bool removeObject,
-                                 const bool removeTool)
+int gmsh::model::occ::booleanFragments(const vector_pair &objectDimTags,
+                                       const vector_pair &toolDimTags,
+                                       vector_pair &outDimTags,
+                                       std::vector<vector_pair> &outDimTagsMap,
+                                       const int tag,
+                                       const bool removeObject,
+                                       const bool removeTool)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1689,8 +1835,8 @@ int gmshModelOccBooleanFragments(const vector_pair &objectDimTags,
   return outTag;
 }
 
-void gmshModelOccTranslate(const vector_pair &dimTags, const double dx,
-                           const double dy, const double dz)
+void gmsh::model::occ::translate(const vector_pair &dimTags, const double dx,
+                                 const double dy, const double dz)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1699,9 +1845,9 @@ void gmshModelOccTranslate(const vector_pair &dimTags, const double dx,
   }
 }
 
-void gmshModelOccRotate(const vector_pair &dimTags, const double x,
-                        const double y, const double z, const double ax,
-                        const double ay, const double az, const double angle)
+void gmsh::model::occ::rotate(const vector_pair &dimTags, const double x,
+                              const double y, const double z, const double ax,
+                              const double ay, const double az, const double angle)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1711,9 +1857,9 @@ void gmshModelOccRotate(const vector_pair &dimTags, const double x,
   }
 }
 
-void gmshModelOccDilate(const vector_pair &dimTags, const double x,
-                        const double y, const double z, const double a,
-                        const double b, const double c)
+void gmsh::model::occ::dilate(const vector_pair &dimTags, const double x,
+                              const double y, const double z, const double a,
+                              const double b, const double c)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1723,8 +1869,8 @@ void gmshModelOccDilate(const vector_pair &dimTags, const double x,
   }
 }
 
-void gmshModelOccSymmetry(const vector_pair &dimTags, const double a,
-                          const double b, const double c, const double d)
+void gmsh::model::occ::symmetry(const vector_pair &dimTags, const double a,
+                                const double b, const double c, const double d)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1733,7 +1879,7 @@ void gmshModelOccSymmetry(const vector_pair &dimTags, const double a,
   }
 }
 
-void gmshModelOccCopy(const vector_pair &dimTags, vector_pair &outDimTags)
+void gmsh::model::occ::copy(const vector_pair &dimTags, vector_pair &outDimTags)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1743,7 +1889,7 @@ void gmshModelOccCopy(const vector_pair &dimTags, vector_pair &outDimTags)
   }
 }
 
-void gmshModelOccRemove(const vector_pair &dimTags, const bool recursive)
+void gmsh::model::occ::remove(const vector_pair &dimTags, const bool recursive)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1752,17 +1898,17 @@ void gmshModelOccRemove(const vector_pair &dimTags, const bool recursive)
   }
 }
 
-void gmshModelOccRemoveAllDuplicates()
+void gmsh::model::occ::removeAllDuplicates()
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
   GModel::current()->getOCCInternals()->removeAllDuplicates();
 }
 
-void gmshModelOccImportShapes(const std::string &fileName,
-                              vector_pair &outDimTags,
-                              const bool highestDimOnly,
-                              const std::string &format)
+void gmsh::model::occ::importShapes(const std::string &fileName,
+                                    vector_pair &outDimTags,
+                                    const bool highestDimOnly,
+                                    const std::string &format)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1773,7 +1919,7 @@ void gmshModelOccImportShapes(const std::string &fileName,
   }
 }
 
-void gmshModelOccSetMeshSize(const vector_pair &dimTags, const double size)
+void gmsh::model::occ::setMeshSize(const vector_pair &dimTags, const double size)
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
@@ -1783,147 +1929,16 @@ void gmshModelOccSetMeshSize(const vector_pair &dimTags, const double size)
   }
 }
 
-void gmshModelOccSynchronize()
+void gmsh::model::occ::synchronize()
 {
   if(!_isInitialized()){ throw -1; }
   _createOcc();
   GModel::current()->getOCCInternals()->synchronize(GModel::current());
 }
 
-// gmshModelField
-
-int gmshModelFieldCreate(const std::string &type, const int tag)
-{
-  if(!_isInitialized()){ throw -1; }
-  int outTag = tag;
-#if defined(HAVE_MESH)
-  if(outTag < 0){
-    outTag = GModel::current()->getFields()->newId();
-  }
-  if(!GModel::current()->getFields()->newField(tag, type)){
-    Msg::Error("Cannot create Field %i of type '%s'", tag, type.c_str());
-    throw 1;
-  }
-#else
-  Msg::Error("Fields require the mesh module");
-  throw -1;
-#endif
-  return outTag;
-}
-
-void gmshModelFieldDelete(const int tag)
-{
-  if(!_isInitialized()){ throw -1; }
-#if defined(HAVE_MESH)
-  GModel::current()->getFields()->deleteField(tag);
-#else
-  Msg::Error("Fields require the mesh module");
-  throw -1;
-#endif
-}
-
-#if defined(HAVE_MESH)
-static FieldOption *_getFieldOption(const int tag, const std::string &option)
-{
-  Field *field = GModel::current()->getFields()->get(tag);
-  if(!field){
-    Msg::Error("No field with id %i", tag);
-    return 0;
-  }
-  FieldOption *o = field->options[option];
-  if(!o){
-    Msg::Error("Unknown option '%s' in field %i of type '%s'", option.c_str(),
-               tag, field->getName());
-    return 0;
-  }
-  return o;
-}
-#endif
+// gmsh::view
 
-void gmshModelFieldSetNumber(const int tag, const std::string &option,
-                             const double value)
-{
-  if(!_isInitialized()){ throw -1; }
-#if defined(HAVE_MESH)
-  FieldOption *o = _getFieldOption(tag, option);
-  if(!o){ throw 1; }
-  try { o->numericalValue(value); }
-  catch(...){
-    Msg::Error("Cannot set numerical value to option '%s' in field %i",
-               option.c_str(), tag);
-    throw 1;
-  }
-#else
-  Msg::Error("Fields require the mesh module");
-  throw -1;
-#endif
-}
-
-void gmshModelFieldSetString(const int tag, const std::string &option,
-                             const std::string &value)
-{
-  if(!_isInitialized()){ throw -1; }
-#if defined(HAVE_MESH)
-  FieldOption *o = _getFieldOption(tag, option);
-  if(!o){ throw 1; }
-  try { o->string(value); }
-  catch(...){
-    Msg::Error("Cannot set string value to option '%s' in field %i",
-               option.c_str(), tag);
-    throw 1;
-  }
-#else
-  Msg::Error("Fields require the mesh module");
-  throw -1;
-#endif
-}
-
-void gmshModelFieldSetNumbers(const int tag, const std::string &option,
-                              const std::vector<double> &value)
-{
-  if(!_isInitialized()){ throw -1; }
-#if defined(HAVE_MESH)
-  FieldOption *o = _getFieldOption(tag, option);
-  if(!o){ throw 1; }
-  try {
-    if(o->getType() == FIELD_OPTION_LIST) {
-      std::list<int> vl;
-      for(unsigned int i = 0; i < value.size(); i++)
-        vl.push_back((int)value[i]);
-      o->list(vl);
-    }
-    else{
-      std::list<double> vl;
-      for(unsigned int i = 0; i < value.size(); i++)
-        vl.push_back(value[i]);
-      o->listdouble(vl);
-    }
-  }
-  catch(...){
-    Msg::Error("Cannot set numeric values to option '%s' in field %i",
-               option.c_str(), tag);
-    throw 1;
-  }
-#else
-  Msg::Error("Fields require the mesh module");
-  throw -1;
-#endif
-}
-
-void gmshModelFieldSetAsBackground(const int tag)
-{
-  if(!_isInitialized()){ throw -1; }
-#if defined(HAVE_MESH)
-  GModel::current()->getFields()->setBackgroundFieldId(tag);
-#else
-  Msg::Error("Fields require the mesh module");
-  throw -1;
-#endif
-}
-
-// gmshView
-
-int gmshViewCreate(const std::string &name, const int tag)
+int gmsh::view::add(const std::string &name, const int tag)
 {
   if(!_isInitialized()){ throw -1; }
 #if defined(HAVE_POST)
@@ -1936,7 +1951,7 @@ int gmshViewCreate(const std::string &name, const int tag)
 #endif
 }
 
-void gmshViewDelete(const int tag)
+void gmsh::view::remove(const int tag)
 {
   if(!_isInitialized()){ throw -1; }
 #if defined(HAVE_POST)
@@ -1952,7 +1967,7 @@ void gmshViewDelete(const int tag)
 #endif
 }
 
-int gmshViewGetIndex(const int tag)
+int gmsh::view::getIndex(const int tag)
 {
   if(!_isInitialized()){ throw -1; }
 #if defined(HAVE_POST)
@@ -1968,7 +1983,7 @@ int gmshViewGetIndex(const int tag)
 #endif
 }
 
-void gmshViewGetTags(std::vector<int> &tags)
+void gmsh::view::getTags(std::vector<int> &tags)
 {
   if(!_isInitialized()){ throw -1; }
 #if defined(HAVE_POST)
@@ -1981,12 +1996,12 @@ void gmshViewGetTags(std::vector<int> &tags)
 #endif
 }
 
-void gmshViewAddModelData(const int tag, const std::string &modelName,
-                          const std::string &dataType,
-                          const std::vector<int> &tags,
-                          const std::vector<std::vector<double> > &data,
-                          const int step, const int time,
-                          const int numComponents, const int partition)
+void gmsh::view::addModelData(const int tag, const std::string &modelName,
+                              const std::string &dataType,
+                              const std::vector<int> &tags,
+                              const std::vector<std::vector<double> > &data,
+                              const int step, const int time,
+                              const int numComponents, const int partition)
 {
   if(!_isInitialized()){ throw -1; }
 #if defined(HAVE_POST)
@@ -2021,7 +2036,7 @@ void gmshViewAddModelData(const int tag, const std::string &modelName,
     else if(dataType == "Beam")
       type = PViewDataGModel::BeamData;
     else{
-      Msg::Error("Unknown type of view to create '%s'", dataType.c_str());
+      Msg::Error("Unknown type of view to add '%s'", dataType.c_str());
       throw 2;
     }
     d = new PViewDataGModel(type);
@@ -2040,8 +2055,8 @@ void gmshViewAddModelData(const int tag, const std::string &modelName,
 #endif
 }
 
-void gmshViewAddListData(const int tag, const std::string &type, const int numEle,
-                         const std::vector<double> &data)
+void gmsh::view::addListData(const int tag, const std::string &type,
+                             const int numEle, const std::vector<double> &data)
 {
   if(!_isInitialized()){ throw -1; }
 #if defined(HAVE_POST)
@@ -2076,13 +2091,13 @@ void gmshViewAddListData(const int tag, const std::string &type, const int numEl
 #endif
 }
 
-void gmshViewProbe(const int tag, const double x, const double y,
-                   const double z, std::vector<double> &value,
-                   const int step, const int numComp,
-                   const bool gradient, const double tolerance,
-                   const std::vector<double> xElemCoord,
-                   const std::vector<double> yElemCoord,
-                   const std::vector<double> zElemCoord)
+void gmsh::view::probe(const int tag, const double x, const double y,
+                       const double z, std::vector<double> &value,
+                       const int step, const int numComp,
+                       const bool gradient, const double tolerance,
+                       const std::vector<double> xElemCoord,
+                       const std::vector<double> yElemCoord,
+                       const std::vector<double> zElemCoord)
 {
   if(!_isInitialized()){ throw -1; }
 #if defined(HAVE_POST)
@@ -2138,8 +2153,8 @@ void gmshViewProbe(const int tag, const double x, const double y,
 #endif
 }
 
-void gmshViewExport(const int tag, const std::string &fileName,
-                    const bool append)
+void gmsh::view::write(const int tag, const std::string &fileName,
+                       const bool append)
 {
   if(!_isInitialized()){ throw -1; }
 #if defined(HAVE_POST)
@@ -2155,10 +2170,10 @@ void gmshViewExport(const int tag, const std::string &fileName,
 #endif
 }
 
-// gmshPlugin
+// gmsh::plugin
 
-void gmshPluginSetNumber(const std::string &name, const std::string &option,
-                         const double value)
+void gmsh::plugin::setNumber(const std::string &name, const std::string &option,
+                             const double value)
 {
 #if defined(HAVE_PLUGINS)
   try {
@@ -2174,8 +2189,8 @@ void gmshPluginSetNumber(const std::string &name, const std::string &option,
 #endif
 }
 
-void gmshPluginSetString(const std::string &name, const std::string &option,
-                         const std::string &value)
+void gmsh::plugin::setString(const std::string &name, const std::string &option,
+                             const std::string &value)
 {
 #if defined(HAVE_PLUGINS)
   try {
@@ -2191,7 +2206,7 @@ void gmshPluginSetString(const std::string &name, const std::string &option,
 #endif
 }
 
-void gmshPluginRun(const std::string &name)
+void gmsh::plugin::run(const std::string &name)
 {
 #if defined(HAVE_PLUGINS)
   try {
diff --git a/Common/gmsh.h b/Common/gmsh.h
index 314bf525be..594ecb6bd3 100644
--- a/Common/gmsh.h
+++ b/Common/gmsh.h
@@ -32,826 +32,855 @@
 #define GMSH_API
 #endif
 
-// A geometrical entity in the Gmsh API is represented by two integers: its
-// dimension (dim = 0, 1, 2 or 3) and its tag (its unique, strictly positive
-// identifier). When dealing with multiple geometrical entities of possibly
-// different dimensions, the entities are packed as a vector of (dim, tag)
-// integer pairs.
-typedef std::vector<std::pair<int, int> > vector_pair;
-
-// -----------------------------------------------------------------------------
-// Module gmsh: top-level functions
-// -----------------------------------------------------------------------------
-
-// Initializes Gmsh. This must be called before any call to the other functions
-// in the API. If argc and argv are provided, they will be handled in the same
-// way as the command line arguments in the Gmsh app.
-GMSH_API void gmshInitialize(int argc = 0, char **argv = 0);
-
-// Finalizes Gmsh. This must be called when you are done using the Gmsh API.
-GMSH_API void gmshFinalize();
-
-// Opens a file and creates one (or more) new model(s). Equivalent to the
-// `File->Open' menu in the Gmsh app. Handling of the file depends on its
-// extension and/or its contents.
-GMSH_API void gmshOpen(const std::string &fileName);
-
-// Merges a file. Equivalent to the `File->Merge' menu in the Gmsh app. Handling
-// of the file depends on its extension and/or its contents.
-GMSH_API void gmshMerge(const std::string &fileName);
-
-// Exports a file. The export format is determined by the file extension.
-GMSH_API void gmshExport(const std::string &fileName);
-
-// Clears all loaded models and post-processing data, and creates a new empty
-// model.
-GMSH_API void gmshClear();
-
-// -----------------------------------------------------------------------------
-// Module gmshOption: global option handling functions
-// -----------------------------------------------------------------------------
-
-// Sets a numerical option to `value'. `name' is of the form "category.option"
-// or "category[num].option". Available categories and options are listed in the
-// Gmsh reference manual.
-GMSH_API void gmshOptionSetNumber(const std::string &name, const double value);
-
-// Gets the `value' of a numerical option.
-GMSH_API void gmshOptionGetNumber(const std::string &name, double &value);
-
-// Sets a string option to `value'.
-GMSH_API void gmshOptionSetString(const std::string &name,
-                                  const std::string &value);
-
-// Gets the `value' of a string option.
-GMSH_API void gmshOptionGetString(const std::string &name, std::string &value);
-
-// -----------------------------------------------------------------------------
-// Module gmshModel: per-model functions
-// -----------------------------------------------------------------------------
-
-// Creates a new model, with name `name', and sets it as the current model.
-GMSH_API void gmshModelCreate(const std::string &name);
-
-// Deletes the current model.
-GMSH_API void gmshModelDelete();
-
-// Lists the names of all models.
-GMSH_API void gmshModelList(std::vector<std::string> &names);
-
-// Sets the current model to the model with name `name'. If several models have
-// the same name, selects the one that was created first.
-GMSH_API void gmshModelSetCurrent(const std::string &name);
-
-// Gets all the (elementary) geometrical entities in the current model. If `dim'
-// is >= 0, returns only the entities of the specified dimension (e.g. points if
-// `dim' == 0). The entities are returned as a vector of (dim, tag) integer
-// pairs.
-GMSH_API void gmshModelGetEntities(vector_pair &dimTags, const int dim = -1);
-
-// Gets all the physical groups in the current model. If `dim' is >= 0, returns
-// only the entities of the specified dimension (e.g. physical points if `dim'
-// == 0). The entities are returned as a vector of (dim, tag) integer pairs.
-GMSH_API void gmshModelGetPhysicalGroups(vector_pair &dimTags,
-                                         const int dim = -1);
-
-// Gets the tags of all the (elementary) geometrical entities making up the
-// physical group of dimension `dim' and tag `tag'.
-GMSH_API void gmshModelGetEntitiesForPhysicalGroup(const int dim, const int tag,
-                                                   std::vector<int> &tags);
-
-// Adds a physical group of dimension `dim', grouping the elementary entities
-// with tags `tags'. The function returns the tag of the physical group, equal
-// to `tag' if `tag' is positive, or a new tag if `tag' < 0.
-GMSH_API int gmshModelAddPhysicalGroup(const int dim,
-                                       const std::vector<int> &tags,
-                                       int tag = -1);
-
-// Sets the name of the physical group of dimension `dim' and tag `tag'.
-GMSH_API void gmshModelSetPhysicalName(const int dim, const int tag,
-                                       const std::string &name);
-
-// Gets the name of the physical group of dimension `dim' and tag `tag'.
-GMSH_API void gmshModelGetPhysicalName(const int dim, const int tag,
-                                       std::string &name);
-
-// Gets the boundary of the geometrical entities `dimTags'. Returns in
-// `outDimTags' the boundary of the individual entities (if `combined' is false)
-// or the boundary of the combined geometrical shape formed by all input
-// entities (if `combined' is true). Returns tags multiplied by the sign of the
-// boundary entity if `oriented' is true. Applies the boundary operator
-// recursively down to dimension 0 (i.e. to points) if `recursive' is true.
-GMSH_API void gmshModelGetBoundary(const vector_pair &dimTags,
-                                   vector_pair &outDimTags,
-                                   const bool combined = true,
-                                   const bool oriented = true,
-                                   const bool recursive = false);
-
-// Gets the (elementary) geometrical entities in the bounding box defined by the
-// two points (xmin, ymin, zmin) and (xmax, ymax, zmax). If `dim' is >= 0,
-// returns only the entities of the specified dimension (e.g. points if `dim' ==
-// 0).
-GMSH_API void gmshModelGetEntitiesInBoundingBox(const double xmin,
-                                                const double ymin,
-                                                const double zmin,
-                                                const double xmax,
-                                                const double ymax,
-                                                const double zmax,
-                                                vector_pair &tags,
-                                                const int dim = -1);
-
-// Gets the bounding box (xmin, ymin, zmin), (xmax, ymax, zmax) of the
-// geometrical entity of dimension `dim' and tag `tag'.
-GMSH_API void gmshModelGetBoundingBox(const int dim, const int tag, double &xmin,
-                                      double &ymin, double &zmin, double &xmax,
-                                      double &ymax, double &zmax);
-
-// Adds a discrete geometrical entity (defined by a mesh) of dimension `dim' in
-// the current model. The function returns the tag of the new discrete entity,
-// equal to `tag' if `tag' is positive, or a new tag if `tag' < 0. `boundary'
-// specifies the tags of the entities on the boundary of the discrete entity, if
-// any. Specyfing `boundary' allows Gmsh to construct the topology of the
-// overall model.
-GMSH_API int gmshModelAddDiscreteEntity(const int dim,
-                                        const int tag = -1,
-                                        const std::vector<int> &boundary =
-                                        std::vector<int>());
-
-// Removes the entities `dimTags' of the current model. If `recursive' is true,
-// remove all the entities on their boundaries, down to dimension 0.
-GMSH_API void gmshModelRemove(const vector_pair &dimTags,
-                              const bool recursive = false);
+namespace gmsh { // Top-level functions
 
-// Generates a mesh of the current model, up to dimension `dim' (0, 1, 2 or 3).
-GMSH_API void gmshModelMesh(const int dim);
-
-// Gets the last entities (if any) where a meshing error occurred. Currently
-// only populated by the new 3D meshing algorithms.
-GMSH_API void gmshModelGetLastMeshEntityError(vector_pair &dimTags);
-
-// Gets the last mesh vertices (if any) where a meshing error
-// occurred. Currently only populated by the new 3D meshing algorithms.
-GMSH_API void gmshModelGetLastMeshVertexError(std::vector<int> &vertexTags);
-
-// Gets the mesh vertices of the entity of dimension `dim' and `tag'
-// tag. `vertextags' contains the vertex tags (their unique, strictly positive
-// identification numbers). `coord` is a vector of length `3 *
-// vertexTags.size()' that contains the (x, y, z) coordinates of the vertices,
-// concatenated. `parametricCoord` contains the parametric coordinates of the
-// vertices, if available. The length of `parametricCoord` can be 0 or `dim *
-// vertexTags.size()'.
-GMSH_API void gmshModelGetMeshVertices(const int dim, const int tag,
-                                       std::vector<int> &vertexTags,
-                                       std::vector<double> &coord,
-                                       std::vector<double> &parametricCoord);
-
-// Gets the mesh elements of the entity of dimension `dim' and `tag'
-// tag. `types' contains the MSH types of the elements (e.g. `2' for 3-node
-// triangles: see the Gmsh reference manual). `elementTags' is a vector of
-// length `types.size()'; each entry is a vector containing the tags (unique,
-// strictly positive identifiers) of the elements of the corresponding
-// type. `vertexTags' is also a vector of length `types.size()'; each entry is a
-// vector of length equal to the number of elements of the given type times the
-// number of vertices for this type of element, that contains the vertex tags of
-// all the elements of the given type, concatenated.
-GMSH_API void gmshModelGetMeshElements(const int dim, const int tag,
-                                       std::vector<int> &types,
-                                       std::vector<std::vector<int> > &elementTags,
-                                       std::vector<std::vector<int> > &vertexTags);
-
-// Sets the mesh vertices in the geometrical entity of dimension `dim' and tag
-// `tag'. `vertextags' contains the vertex tags (their unique, strictly positive
-// identification numbers). `coord` is a vector of length `3 *
-// vertexTags.size()' that contains the (x, y, z) coordinates of the vertices,
-// concatenated. The optional `parametricCoord` vector contains the parametric
-// coordinates of the vertices, if any. The length of `parametricCoord` can be 0
-// or `dim * vertexTags.size()'.
-GMSH_API void gmshModelSetMeshVertices(const int dim, const int tag,
-                                       const std::vector<int> &vertexTags,
-                                       const std::vector<double> &coord,
-                                       const std::vector<double> &parametricCoord =
-                                       std::vector<double>());
-
-// Sets the mesh elements of the entity of dimension `dim' and `tag'
-// tag. `types' contains the MSH types of the elements (e.g. `2' for 3-node
-// triangles: see the Gmsh reference manual). `elementTags' is a vector of
-// length `types.size()'; each entry is a vector containing the tags (unique,
-// strictly positive identifiers) of the elements of the corresponding
-// type. `vertexTags' is also a vector of length `types.size()'; each entry is a
-// vector of length equal to the number of elements of the give type times the
-// number of vertices per element, that contains the vertex tags of all the
-// elements of the given type, concatenated.
-GMSH_API void gmshModelSetMeshElements(const int dim, const int tag,
-                                       const std::vector<int> &types,
-                                       const std::vector<std::vector<int> > &elementTags,
-                                       const std::vector<std::vector<int> > &vertexTags);
-
-// Gets the coordinates and the parametric coordinates (if any) of the mesh
-// vertex with tag `tag'. This is a useful by inefficient way of accessing mesh
-// vertex data, as it relies on a cache stored in the model. For large meshes
-// all the vertices in the model should be numbered in a continuous sequence of
-// tags from 1 to N to maintain reasonnable performance (in this case the
-// internal cache is based on a vector; otherwise it uses a map).
-GMSH_API void gmshModelGetMeshVertex(const int vertexTag,
-                                     std::vector<double> &coord,
-                                     std::vector<double> &parametricCoord);
-
-// Gets the type and vertex tags of the mesh element with tag `tag'. This is a
-// useful but inefficient way of accessing mesh element data, as it relies on a
-// cache stored in the model. For large meshes all the elements in the model
-// should be numbered in a continuous sequence of tags from 1 to N to maintain
-// reasonnable performance (in this case the internal cache is based on a
-// vector; otherwise it uses a map).
-GMSH_API void gmshModelGetMeshElement(const int elementTag, int &type,
-                                      std::vector<int> &vertexTags);
-
-// Sets a mesh size constraint on the geometrical entities `dimTags'. Currently
-// only entities of dimension 0 (points) are handled.
-GMSH_API void gmshModelSetMeshSize(const vector_pair &dimTags, const double size);
-
-// Sets a transfinite meshing constraint on the line `tag', with `numVertices'
-// mesh vertices distributed according to `type' and `coef'. Currently supported
-// types are "Progression" (geometrical progression with power `coef') and
-// "Bump" (refinement toward both extreminties of the line).
-GMSH_API void gmshModelSetTransfiniteLine(const int tag, const int numVertices,
-                                          const std::string &type = "Progression",
-                                          const double coef = 1.);
-
-// Sets a transfinite meshing constraint on the surface `tag'. `arrangement'
-// describes the arrangement of the triangles when the surface is not flagged as
-// recombined: currently supported values are "Left", "Right", "AlternateLeft"
-// and "AlternateRight". `cornerTags' can be used to specify the (3 or 4)
-// corners of the transfinite interpolation explicitly; specifying the corners
-// explicitly is mandatory if the surface has more that 3 or 4 points on its
-// boundary.
-GMSH_API void gmshModelSetTransfiniteSurface(const int tag,
-                                             const std::string &arrangement = "Left",
-                                             const std::vector<int> &cornerTags =
-                                             std::vector<int>());
-
-// Sets a transfinite meshing constraint on the surface `tag'. `cornerTags' can
-// be used to specify the (6 or 8) corners of the transfinite interpolation
-// explicitly.
-GMSH_API void gmshModelSetTransfiniteVolume(const int tag,
-                                            const std::vector<int> &cornerTags =
-                                            std::vector<int>());
-
-// Sets a recombination meshing constraint on the geometrical entity of
-// dimension `dim' and tag `tag'. Currently only entities of dimension 2 (to
-// recombine triangles into quadrangles) are supported.
-GMSH_API void gmshModelSetRecombine(const int dim, const int tag);
-
-// Sets a smoothing meshing constraint on the geometrical entity of dimension
-// `dim' and tag `tag'. `val' iterations of a Laplace smoother are applied.
-GMSH_API void gmshModelSetSmoothing(const int dim, const int tag, const int val);
-
-// Sets a reverse meshing constraint on the geometrical entity of dimension
-// `dim' and tag `tag'. If `val' is true, the mesh orientation will be reversed
-// with respect to the natural mesh orientation (i.e. the orientation consistent
-// with the orientation of the geometrical entity). If `val' is false, the mesh
-// is left as-is.
-GMSH_API void gmshModelSetReverseMesh(const int dim, const int tag,
-                                      const bool val = true);
-
-// Emebds the geometrical entities of dimension `dim' and tags `tags' in the
-// (inDim, inTag) geometrical entity. `inDim' must be strictly greater than
-// `dim'.
-GMSH_API void gmshModelEmbed(const int dim, const std::vector<int> &tags,
-                             const int inDim, const int inTag);
-
-// -----------------------------------------------------------------------------
-// Module gmshModelGeo: internal per-model GEO CAD kernel functions
-// -----------------------------------------------------------------------------
-
-// Adds a geometrical point in the internal GEO CAD representation, at
-// coordinates (x, y, z). If `meshSize' is > 0, adds a meshing constraint at
-// that point. If `tag' is positive, sets the tag explicitly; otherwise a new
-// tag is selected automatically. Returns the tag of the point. (Note that the
-// point will be added in the current model only after gmshModelGeoSynchronize()
-// is called. This behavior holds for all the entities created in the
-// gmshModelGeo module.)
-GMSH_API int gmshModelGeoAddPoint(const double x, const double y, const double z,
-                                  const double meshSize = 0., const int tag = -1);
-
-// Adds a straight line segment between the two points with tags `startTag' and
-// `endTag'. If `tag' is positive, sets the tag explicitly; otherwise a new tag
-// is selected automatically. Returns the tag of the line.
-GMSH_API int gmshModelGeoAddLine(const int startTag, const int endTag,
-                                 const int tag = -1);
+  // A geometrical entity in the Gmsh API is represented by two integers: its
+  // dimension (dim = 0, 1, 2 or 3) and its tag (its unique, strictly positive
+  // identifier). When dealing with multiple geometrical entities of possibly
+  // different dimensions, the entities are packed as a vector of (dim, tag)
+  // integer pairs.
+  typedef std::vector<std::pair<int, int> > vector_pair;
+
+  // Initializes Gmsh. This must be called before any call to the other
+  // functions in the API. If argc and argv are provided, they will be handled
+  // in the same way as the command line arguments in the Gmsh app.
+  GMSH_API void initialize(int argc = 0, char **argv = 0);
+
+  // Finalizes Gmsh. This must be called when you are done using the Gmsh API.
+  GMSH_API void finalize();
+
+  // Opens a file and adds one (or more) new model(s). Equivalent to the
+  // `File->Open' menu in the Gmsh app. Handling of the file depends on its
+  // extension and/or its contents.
+  GMSH_API void open(const std::string &fileName);
+
+  // Merges a file. Equivalent to the `File->Merge' menu in the Gmsh
+  // app. Handling of the file depends on its extension and/or its contents.
+  GMSH_API void merge(const std::string &fileName);
+
+  // Writes a file. The export format is determined by the file extension.
+  GMSH_API void write(const std::string &fileName);
+
+  // Clears all loaded models and post-processing data, and adds a new empty
+  // model.
+  GMSH_API void clear();
+
+  namespace option { // Global option handling functions
+
+    // Sets a numerical option to `value'. `name' is of the form
+    // "category.option" or "category[num].option". Available categories and
+    // options are listed in the Gmsh reference manual.
+    GMSH_API void setNumber(const std::string &name, const double value);
+
+    // Gets the `value' of a numerical option.
+    GMSH_API void getNumber(const std::string &name, double &value);
+
+    // Sets a string option to `value'.
+    GMSH_API void setString(const std::string &name,
+                            const std::string &value);
+
+    // Gets the `value' of a string option.
+    GMSH_API void getString(const std::string &name, std::string &value);
+
+  } // namespace option
+
+  namespace model { // Per-model functions
+
+    // Adds a new model, with name `name', and sets it as the current model.
+    GMSH_API void add(const std::string &name);
+
+    // Removes the current model.
+    GMSH_API void remove();
+
+    // Lists the names of all models.
+    GMSH_API void list(std::vector<std::string> &names);
+
+    // Sets the current model to the model with name `name'. If several models
+    // have the same name, selects the one that was added first.
+    GMSH_API void setCurrent(const std::string &name);
+
+    // Gets all the (elementary) geometrical entities in the current model. If
+    // `dim' is >= 0, returns only the entities of the specified dimension
+    // (e.g. points if `dim' == 0). The entities are returned as a vector of
+    // (dim, tag) integer pairs.
+    GMSH_API void getEntities(vector_pair &dimTags, const int dim = -1);
+
+    // Gets all the physical groups in the current model. If `dim' is >= 0,
+    // returns only the entities of the specified dimension (e.g. physical
+    // points if `dim' == 0). The entities are returned as a vector of (dim,
+    // tag) integer pairs.
+    GMSH_API void getPhysicalGroups(vector_pair &dimTags,
+                                    const int dim = -1);
+
+    // Gets the tags of all the (elementary) geometrical entities making up the
+    // physical group of dimension `dim' and tag `tag'.
+    GMSH_API void getEntitiesForPhysicalGroup(const int dim, const int tag,
+                                              std::vector<int> &tags);
+
+    // Adds a physical group of dimension `dim', grouping the elementary
+    // entities with tags `tags'. The function returns the tag of the physical
+    // group, equal to `tag' if `tag' is positive, or a new tag if `tag' < 0.
+    GMSH_API int addPhysicalGroup(const int dim,
+                                  const std::vector<int> &tags,
+                                  int tag = -1);
+
+    // Sets the name of the physical group of dimension `dim' and tag `tag'.
+    GMSH_API void setPhysicalName(const int dim, const int tag,
+                                  const std::string &name);
+
+    // Gets the name of the physical group of dimension `dim' and tag `tag'.
+    GMSH_API void getPhysicalName(const int dim, const int tag,
+                                  std::string &name);
+
+    // Gets the boundary of the geometrical entities `dimTags'. Returns in
+    // `outDimTags' the boundary of the individual entities (if `combined' is
+    // false) or the boundary of the combined geometrical shape formed by all
+    // input entities (if `combined' is true). Returns tags multiplied by the
+    // sign of the boundary entity if `oriented' is true. Applies the boundary
+    // operator recursively down to dimension 0 (i.e. to points) if `recursive'
+    // is true.
+    GMSH_API void getBoundary(const vector_pair &dimTags,
+                              vector_pair &outDimTags,
+                              const bool combined = true,
+                              const bool oriented = true,
+                              const bool recursive = false);
 
-// Adds a circle arc (stricly smaller than Pi) between the two points with tags
-// `startTag' and `endTag', with center `centertag'. If `tag' is positive, sets
-// the tag explicitly; otherwise a new tag is selected automatically. If (`nx',
-// `ny', `nz') != (0,0,0), explicitely sets the plane of the circle arc. Returns
-// the tag of the circle arc.
-GMSH_API int gmshModelGeoAddCircleArc(const int startTag, const int centerTag,
-                                      const int endTag, const int tag = -1,
-                                      const double nx = 0., const double ny = 0.,
-                                      const double nz = 0.);
-
-// Adds an ellipse arc (stricly smaller than Pi) between the two points
-// `startTag' and `endTag', with center `centertag' and major axis point
-// `majorTag'. If `tag' is positive, sets the tag explicitly; otherwise a new
-// tag is selected automatically. If (`nx', `ny', `nz') != (0,0,0), explicitely
-// sets the plane of the circle arc. Returns the tag of the ellipse arc.
-GMSH_API int gmshModelGeoAddEllipseArc(const int startTag, const int centerTag,
-                                       const int majorTag, const int endTag,
-                                       const int tag = -1, const double nx = 0.,
-                                       const double ny = 0., const double nz = 0.);
-
-// Adds a spline curve going through `vertexTags' points. If `tag' is positive,
-// sets the tag explicitly; otherwise a new tag is selected automatically.
-// Returns the tag of the spline curve.
-GMSH_API int gmshModelGeoAddSpline(const std::vector<int> &vertexTags,
-                                   const int tag = -1);
+    // Gets the (elementary) geometrical entities in the bounding box defined by the
+    // two points (xmin, ymin, zmin) and (xmax, ymax, zmax). If `dim' is >= 0,
+    // returns only the entities of the specified dimension (e.g. points if `dim' ==
+    // 0).
+    GMSH_API void getEntitiesInBoundingBox(const double xmin,
+                                           const double ymin,
+                                           const double zmin,
+                                           const double xmax,
+                                           const double ymax,
+                                           const double zmax,
+                                           vector_pair &tags,
+                                           const int dim = -1);
+
+    // Gets the bounding box (xmin, ymin, zmin), (xmax, ymax, zmax) of the
+    // geometrical entity of dimension `dim' and tag `tag'.
+    GMSH_API void getBoundingBox(const int dim, const int tag, double &xmin,
+                                 double &ymin, double &zmin, double &xmax,
+                                 double &ymax, double &zmax);
+
+    // Adds a discrete geometrical entity (defined by a mesh) of dimension `dim'
+    // in the current model. The function returns the tag of the new discrete
+    // entity, equal to `tag' if `tag' is positive, or a new tag if `tag' <
+    // 0. `boundary' specifies the tags of the entities on the boundary of the
+    // discrete entity, if any. Specyfing `boundary' allows Gmsh to construct
+    // the topology of the overall model.
+    GMSH_API int addDiscreteEntity(const int dim,
+                                   const int tag = -1,
+                                   const std::vector<int> &boundary =
+                                   std::vector<int>());
 
-// Adds a b-spline curve with `vertexTags' control points. If `tag' is positive,
-// sets the tag explicitly; otherwise a new tag is selected automatically.
-// Returns the tag of the b-spline curve.
-GMSH_API int gmshModelGeoAddBSpline(const std::vector<int> &vertexTags,
-                                    const int tag = -1);
+    // Removes the entities `dimTags' of the current model. If `recursive' is true,
+    // remove all the entities on their boundaries, down to dimension 0.
+    GMSH_API void removeEntities(const vector_pair &dimTags,
+                                 const bool recursive = false);
 
-// Adds a Bezier curve with `vertexTags' control points. If `tag' is positive,
-// sets the tag explicitly; otherwise a new tag is selected automatically.
-// Returns the tag of the Bezier curve.
-GMSH_API int gmshModelGeoAddBezier(const std::vector<int> &vertexTags,
-                                   const int tag = -1);
+    namespace mesh { // Per-model meshing functions
+
+      // Generates a mesh of the current model, up to dimension `dim' (0, 1, 2
+      // or 3).
+      GMSH_API void generate(const int dim);
+
+      // Gets the last entities (if any) where a meshing error
+      // occurred. Currently only populated by the new 3D meshing algorithms.
+      GMSH_API void getLastEntityError(vector_pair &dimTags);
+
+      // Gets the last mesh vertices (if any) where a meshing error
+      // occurred. Currently only populated by the new 3D meshing algorithms.
+      GMSH_API void getLastVertexError(std::vector<int> &vertexTags);
+
+      // Gets the mesh vertices of the entity of dimension `dim' and `tag'
+      // tag. `vertextags' contains the vertex tags (their unique, strictly
+      // positive identification numbers). `coord` is a vector of length `3 *
+      // vertexTags.size()' that contains the (x, y, z) coordinates of the
+      // vertices, concatenated. `parametricCoord` contains the parametric
+      // coordinates of the vertices, if available. The length of
+      // `parametricCoord` can be 0 or `dim * vertexTags.size()'.
+      GMSH_API void getVertices(const int dim, const int tag,
+                                std::vector<int> &vertexTags,
+                                std::vector<double> &coord,
+                                std::vector<double> &parametricCoord);
+
+      // Gets the mesh elements of the entity of dimension `dim' and `tag'
+      // tag. `types' contains the MSH types of the elements (e.g. `2' for
+      // 3-node triangles: see the Gmsh reference manual). `elementTags' is a
+      // vector of length `types.size()'; each entry is a vector containing the
+      // tags (unique, strictly positive identifiers) of the elements of the
+      // corresponding type. `vertexTags' is also a vector of length
+      // `types.size()'; each entry is a vector of length equal to the number of
+      // elements of the given type times the number of vertices for this type
+      // of element, that contains the vertex tags of all the elements of the
+      // given type, concatenated.
+      GMSH_API void getElements(const int dim, const int tag,
+                                std::vector<int> &types,
+                                std::vector<std::vector<int> > &elementTags,
+                                std::vector<std::vector<int> > &vertexTags);
+
+      // Sets the mesh vertices in the geometrical entity of dimension `dim' and
+      // tag `tag'. `vertextags' contains the vertex tags (their unique,
+      // strictly positive identification numbers). `coord` is a vector of
+      // length `3 * vertexTags.size()' that contains the (x, y, z) coordinates
+      // of the vertices, concatenated. The optional `parametricCoord` vector
+      // contains the parametric coordinates of the vertices, if any. The length
+      // of `parametricCoord` can be 0 or `dim * vertexTags.size()'.
+      GMSH_API void setVertices(const int dim, const int tag,
+                                const std::vector<int> &vertexTags,
+                                const std::vector<double> &coord,
+                                const std::vector<double> &parametricCoord =
+                                std::vector<double>());
+
+      // Sets the mesh elements of the entity of dimension `dim' and `tag'
+      // tag. `types' contains the MSH types of the elements (e.g. `2' for
+      // 3-node triangles: see the Gmsh reference manual). `elementTags' is a
+      // vector of length `types.size()'; each entry is a vector containing the
+      // tags (unique, strictly positive identifiers) of the elements of the
+      // corresponding type. `vertexTags' is also a vector of length
+      // `types.size()'; each entry is a vector of length equal to the number of
+      // elements of the give type times the number of vertices per element,
+      // that contains the vertex tags of all the elements of the given type,
+      // concatenated.
+      GMSH_API void setElements(const int dim, const int tag,
+                                const std::vector<int> &types,
+                                const std::vector<std::vector<int> > &elementTags,
+                                const std::vector<std::vector<int> > &vertexTags);
+
+      // Gets the coordinates and the parametric coordinates (if any) of the
+      // mesh vertex with tag `tag'. This is a useful by inefficient way of
+      // accessing mesh vertex data, as it relies on a cache stored in the
+      // model. For large meshes all the vertices in the model should be
+      // numbered in a continuous sequence of tags from 1 to N to maintain
+      // reasonnable performance (in this case the internal cache is based on a
+      // vector; otherwise it uses a map).
+      GMSH_API void getVertex(const int vertexTag,
+                              std::vector<double> &coord,
+                              std::vector<double> &parametricCoord);
+
+      // Gets the type and vertex tags of the mesh element with tag `tag'. This
+      // is a useful but inefficient way of accessing mesh element data, as it
+      // relies on a cache stored in the model. For large meshes all the
+      // elements in the model should be numbered in a continuous sequence of
+      // tags from 1 to N to maintain reasonnable performance (in this case the
+      // internal cache is based on a vector; otherwise it uses a map).
+      GMSH_API void getElement(const int elementTag, int &type,
+                               std::vector<int> &vertexTags);
+
+      // Sets a mesh size constraint on the geometrical entities
+      // `dimTags'. Currently only entities of dimension 0 (points) are handled.
+      GMSH_API void setSize(const vector_pair &dimTags, const double size);
+
+      // Sets a transfinite meshing constraint on the line `tag', with
+      // `numVertices' mesh vertices distributed according to `type' and
+      // `coef'. Currently supported types are "Progression" (geometrical
+      // progression with power `coef') and "Bump" (refinement toward both
+      // extreminties of the line).
+      GMSH_API void setTransfiniteLine(const int tag, const int numVertices,
+                                       const std::string &type = "Progression",
+                                       const double coef = 1.);
+
+      // Sets a transfinite meshing constraint on the surface
+      // `tag'. `arrangement' describes the arrangement of the triangles when
+      // the surface is not flagged as recombined: currently supported values
+      // are "Left", "Right", "AlternateLeft" and "AlternateRight". `cornerTags'
+      // can be used to specify the (3 or 4) corners of the transfinite
+      // interpolation explicitly; specifying the corners explicitly is
+      // mandatory if the surface has more that 3 or 4 points on its boundary.
+      GMSH_API void setTransfiniteSurface(const int tag,
+                                          const std::string &arrangement = "Left",
+                                          const std::vector<int> &cornerTags =
+                                          std::vector<int>());
+
+      // Sets a transfinite meshing constraint on the surface
+      // `tag'. `cornerTags' can be used to specify the (6 or 8) corners of the
+      // transfinite interpolation explicitly.
+      GMSH_API void setTransfiniteVolume(const int tag,
+                                         const std::vector<int> &cornerTags =
+                                         std::vector<int>());
+
+      // Sets a recombination meshing constraint on the geometrical entity of
+      // dimension `dim' and tag `tag'. Currently only entities of dimension 2
+      // (to recombine triangles into quadrangles) are supported.
+      GMSH_API void setRecombine(const int dim, const int tag);
+
+      // Sets a smoothing meshing constraint on the geometrical entity of
+      // dimension `dim' and tag `tag'. `val' iterations of a Laplace smoother
+      // are applied.
+      GMSH_API void setSmoothing(const int dim, const int tag, const int val);
+
+      // Sets a reverse meshing constraint on the geometrical entity of
+      // dimension `dim' and tag `tag'. If `val' is true, the mesh orientation
+      // will be reversed with respect to the natural mesh orientation (i.e. the
+      // orientation consistent with the orientation of the geometrical
+      // entity). If `val' is false, the mesh is left as-is.
+      GMSH_API void setReverse(const int dim, const int tag,
+                               const bool val = true);
+
+      // Emebds the geometrical entities of dimension `dim' and tags `tags' in
+      // the (inDim, inTag) geometrical entity. `inDim' must be strictly greater
+      // than `dim'.
+      GMSH_API void embed(const int dim, const std::vector<int> &tags,
+                          const int inDim, const int inTag);
+
+      namespace field { // Per-model mesh size field functions
+
+        // Adds a new mesh size field of type `type'. If `tag' is positive,
+        // assign the tag explcitly; otherwise a new tag is assigned
+        // automatically. Returns the field tag.
+        GMSH_API int add(const std::string &type, const int tag = -1);
+
+        // Removes the field with tag `tag'.
+        GMSH_API void remove(const int tag);
+
+        // Sets the numerical option `option' to value `value' for field `tag'.
+        GMSH_API void setNumber(const int tag, const std::string &option,
+                                const double value);
+
+        // Sets the string option `option' to value `value' for field `tag'.
+        GMSH_API void setString(const int tag, const std::string &option,
+                                const std::string &value);
+
+        // Sets the numerical list option `option' to value `value' for field
+        // `tag'.
+        GMSH_API void setNumbers(const int tag, const std::string &option,
+                                 const std::vector<double> &value);
+
+        // Sets the field `tag' as background mesh size field.
+        GMSH_API void setAsBackground(const int tag);
+
+      } // namespace field
+
+    } // namespace mesh
+
+    namespace geo { // Internal per-model GEO CAD kernel functions
+
+      // Adds a geometrical point in the internal GEO CAD representation, at
+      // coordinates (x, y, z). If `meshSize' is > 0, adds a meshing constraint
+      // at that point. If `tag' is positive, sets the tag explicitly; otherwise
+      // a new tag is selected automatically. Returns the tag of the
+      // point. (Note that the point will be added in the current model only
+      // after gmshModelGeoSynchronize() is called. This behavior holds for all
+      // the entities added in the gmshModelGeo module.)
+      GMSH_API int addPoint(const double x, const double y, const double z,
+                            const double meshSize = 0., const int tag = -1);
+
+      // Adds a straight line segment between the two points with tags
+      // `startTag' and `endTag'. If `tag' is positive, sets the tag explicitly;
+      // otherwise a new tag is selected automatically. Returns the tag of the
+      // line.
+      GMSH_API int addLine(const int startTag, const int endTag,
+                           const int tag = -1);
 
-// Adds a line loop (a closed wire) formed by `edgeTags'. `edgeTags' should
-// contain (signed) tags of geometrical enties of dimension 1 forming a closed
-// loop: a negative tag signifies that the underlying edge is considered with
-// reversed orientation. If `tag' is positive, sets the tag explicitly;
-// otherwise a new tag is selected automatically. Returns the tag of the line
-// loop.
-GMSH_API int gmshModelGeoAddLineLoop(const std::vector<int> &edgeTags,
-                                     const int tag = -1);
-
-// Adds a plane surface defined by one or more line loops `wireTags'. The first
-// line loop defines the exterior contour; additional line loop define holes. If
-// `tag' is positive, sets the tag explicitly; otherwise a new tag is selected
-// automatically. Returns the tag of the surface.
-GMSH_API int gmshModelGeoAddPlaneSurface(const std::vector<int> &wireTags,
-                                         const int tag = -1);
-
-// Adds a surface filling the line loops in `wireTags'. Currently only a single
-// line loop is supported; this line loop should be composed by 3 or 4 edges
-// only. If `tag' is positive, sets the tag explicitly; otherwise a new tag is
-// selected automatically. Returns the tag of the surface.
-GMSH_API int gmshModelGeoAddSurfaceFilling(const std::vector<int> &wireTags,
-                                           const int tag = -1,
-                                           const int sphereCenterTag = -1);
-
-// Adds a surface loop (a closed shell) formed by `faceTags'.  If `tag' is
-// positive, sets the tag explicitly; otherwise a new tag is selected
-// automatically. Returns the tag of the surface loop.
-GMSH_API int gmshModelGeoAddSurfaceLoop(const std::vector<int> &faceTags,
-                                        const int tag = -1);
-
-// Adds a volume defined by one or more surface loops `shellTags'. The first
-// surface loop defines the exterior boundary; additional surface loop define
-// holes. If `tag' is positive, sets the tag explicitly; otherwise a new tag is
-// selected automatically. Returns the tag of the volume.
-GMSH_API int gmshModelGeoAddVolume(const std::vector<int> &shellTags,
+      // Adds a circle arc (stricly smaller than Pi) between the two points with
+      // tags `startTag' and `endTag', with center `centertag'. If `tag' is
+      // positive, sets the tag explicitly; otherwise a new tag is selected
+      // automatically. If (`nx', `ny', `nz') != (0,0,0), explicitely sets the
+      // plane of the circle arc. Returns the tag of the circle arc.
+      GMSH_API int addCircleArc(const int startTag, const int centerTag,
+                                const int endTag, const int tag = -1,
+                                const double nx = 0., const double ny = 0.,
+                                const double nz = 0.);
+
+      // Adds an ellipse arc (stricly smaller than Pi) between the two points
+      // `startTag' and `endTag', with center `centertag' and major axis point
+      // `majorTag'. If `tag' is positive, sets the tag explicitly; otherwise a
+      // new tag is selected automatically. If (`nx', `ny', `nz') != (0,0,0),
+      // explicitely sets the plane of the circle arc. Returns the tag of the
+      // ellipse arc.
+      GMSH_API int addEllipseArc(const int startTag, const int centerTag,
+                                 const int majorTag, const int endTag,
+                                 const int tag = -1, const double nx = 0.,
+                                 const double ny = 0., const double nz = 0.);
+
+      // Adds a spline curve going through `vertexTags' points. If `tag' is
+      // positive, sets the tag explicitly; otherwise a new tag is selected
+      // automatically.  Returns the tag of the spline curve.
+      GMSH_API int addSpline(const std::vector<int> &vertexTags,
+                             const int tag = -1);
+
+      // Adds a b-spline curve with `vertexTags' control points. If `tag' is
+      // positive, sets the tag explicitly; otherwise a new tag is selected
+      // automatically.  Returns the tag of the b-spline curve.
+      GMSH_API int addBSpline(const std::vector<int> &vertexTags,
+                              const int tag = -1);
+
+      // Adds a Bezier curve with `vertexTags' control points. If `tag' is
+      // positive, sets the tag explicitly; otherwise a new tag is selected
+      // automatically.  Returns the tag of the Bezier curve.
+      GMSH_API int addBezier(const std::vector<int> &vertexTags,
+                             const int tag = -1);
+
+      // Adds a line loop (a closed wire) formed by `edgeTags'. `edgeTags'
+      // should contain (signed) tags of geometrical enties of dimension 1
+      // forming a closed loop: a negative tag signifies that the underlying
+      // edge is considered with reversed orientation. If `tag' is positive,
+      // sets the tag explicitly; otherwise a new tag is selected
+      // automatically. Returns the tag of the line loop.
+      GMSH_API int addLineLoop(const std::vector<int> &edgeTags,
+                               const int tag = -1);
+
+      // Adds a plane surface defined by one or more line loops `wireTags'. The
+      // first line loop defines the exterior contour; additional line loop
+      // define holes. If `tag' is positive, sets the tag explicitly; otherwise
+      // a new tag is selected automatically. Returns the tag of the surface.
+      GMSH_API int addPlaneSurface(const std::vector<int> &wireTags,
                                    const int tag = -1);
 
-// Extrudes the geometrical entities in `dimTags' by translation along (`dx',
-// `dy', `dz'). Returns extruded entities in `outDimTags'. If `numElements' is
-// not empty, also extrude the mesh: the entries in `numElements' give the
-// number of elements in each layer. If `height' is not empty, it provides the
-// (cummulative) height of the different layers, normalized to 1.
-GMSH_API void gmshModelGeoExtrude(const vector_pair &dimTags,
-                                  const double dx, const double dy, const double dz,
-                                  vector_pair &outDimTags,
-                                  const std::vector<int> &numElements =
-                                  std::vector<int>(),
-                                  const std::vector<double> &heights =
-                                  std::vector<double>(),
-                                  const bool recombine = false);
-
-// Extrudes the geometrical entities in `dimTags' by rotation of `angle' radians
-// around the axis of revolution defined by the point (`x', `y', `z') and the
-// direction (`ax', `ay', `az'). Returns extruded entities in `outDimTags'. If
-// `numElements' is not empty, also extrude the mesh: the entries in
-// `numElements' give the number of elements in each layer. If `height' is not
-// empty, it provides the (cummulative) height of the different layers,
-// normalized to 1.
-GMSH_API void gmshModelGeoRevolve(const vector_pair &dimTags,
-                                  const double x, const double y, const double z,
-                                  const double ax, const double ay,
-                                  const double az, const double angle,
-                                  vector_pair &outDimTags,
-                                  const std::vector<int> &numElements =
-                                  std::vector<int>(),
-                                  const std::vector<double> &heights =
-                                  std::vector<double>(),
-                                  const bool recombine = false);
-
-// Extrudes the geometrical entities in `dimTags' by a combined translation and
-// rotation of `angle' radians, along (`dx', `dy', `dz') and around the axis of
-// revolution defined by the point (`x', `y', `z') and the direction (`ax',
-// `ay', `az'). Returns extruded entities in `outDimTags'. If `numElements' is
-// not empty, also extrude the mesh: the entries in `numElements' give the
-// number of elements in each layer. If `height' is not empty, it provides the
-// (cummulative) height of the different layers, normalized to 1.
-GMSH_API void gmshModelGeoTwist(const vector_pair &dimTags,
-                                const double x, const double y, const double z,
-                                const double dx, const double dy, const double dz,
-                                const double ax, const double ay, const double az,
-                                const double angle,
-                                vector_pair &outDimTags,
-                                const std::vector<int> &numElements =
-                                std::vector<int>(),
-                                const std::vector<double> &heights =
-                                std::vector<double>(),
-                                const bool recombine = false);
-
-// Translates the geometrical entities in `dimTags' along (`dx', `dy', `dz').
-GMSH_API void gmshModelGeoTranslate(const vector_pair &dimTags, const double dx,
-                                    const double dy, const double dz);
-
-// Rotates the geometrical entities in `dimTags' of `angle' radians around the
-// axis of revolution defined by the point (`x', `y', `z') and the direction
-// (`ax', `ay', `az').
-GMSH_API void gmshModelGeoRotate(const vector_pair &dimTags, const double x,
-                                 const double y, const double z, const double ax,
-                                 const double ay, const double az,
-                                 const double angle);
-
-
-// Scales the geometrical entities in `dimTag' by factors `a', `b' and `c' along
-// the three coordinate axes; use (`x', `y', `z') as the center of the
-// homothetic transformation.
-GMSH_API void gmshModelGeoDilate(const vector_pair &dimTags, const double x,
-                                 const double y, const double z, const double a,
-                                 const double b, const double c);
-
-// Applies a symmetry transformation to the geometrical entities in `dimTag',
-// with respect to the plane of equation `a' * x + `b' * y + `c' * z + `d' = 0.
-GMSH_API void gmshModelGeoSymmetry(const vector_pair &dimTags, const double a,
-                                   const double b, const double c, const double d);
-
-// Copies the entities in `dimTags'; the new entities are returned in
-// `outDimTags'.
-GMSH_API void gmshModelGeoCopy(const vector_pair &dimTags, vector_pair &outDimTags);
-
-// Removes the entities `dimTags'. If `recursive' is true, remove all the
-// entities on their boundaries, down to dimension 0.
-GMSH_API void gmshModelGeoRemove(const vector_pair &dimTags,
-                                 const bool recursive = false);
+      // Adds a surface filling the line loops in `wireTags'. Currently only a
+      // single line loop is supported; this line loop should be composed by 3
+      // or 4 edges only. If `tag' is positive, sets the tag explicitly;
+      // otherwise a new tag is selected automatically. Returns the tag of the
+      // surface.
+      GMSH_API int addSurfaceFilling(const std::vector<int> &wireTags,
+                                     const int tag = -1,
+                                     const int sphereCenterTag = -1);
+
+      // Adds a surface loop (a closed shell) formed by `faceTags'.  If `tag' is
+      // positive, sets the tag explicitly; otherwise a new tag is selected
+      // automatically. Returns the tag of the surface loop.
+      GMSH_API int addSurfaceLoop(const std::vector<int> &faceTags,
+                                  const int tag = -1);
+
+      // Adds a volume defined by one or more surface loops `shellTags'. The
+      // first surface loop defines the exterior boundary; additional surface
+      // loop define holes. If `tag' is positive, sets the tag explicitly;
+      // otherwise a new tag is selected automatically. Returns the tag of the
+      // volume.
+      GMSH_API int addVolume(const std::vector<int> &shellTags,
+                             const int tag = -1);
+
+      // Extrudes the geometrical entities in `dimTags' by translation along
+      // (`dx', `dy', `dz'). Returns extruded entities in `outDimTags'. If
+      // `numElements' is not empty, also extrude the mesh: the entries in
+      // `numElements' give the number of elements in each layer. If `height' is
+      // not empty, it provides the (cummulative) height of the different
+      // layers, normalized to 1.
+      GMSH_API void extrude(const vector_pair &dimTags,
+                            const double dx, const double dy, const double dz,
+                            vector_pair &outDimTags,
+                            const std::vector<int> &numElements =
+                            std::vector<int>(),
+                            const std::vector<double> &heights =
+                            std::vector<double>(),
+                            const bool recombine = false);
+
+      // Extrudes the geometrical entities in `dimTags' by rotation of `angle'
+      // radians around the axis of revolution defined by the point (`x', `y',
+      // `z') and the direction (`ax', `ay', `az'). Returns extruded entities in
+      // `outDimTags'. If `numElements' is not empty, also extrude the mesh: the
+      // entries in `numElements' give the number of elements in each layer. If
+      // `height' is not empty, it provides the (cummulative) height of the
+      // different layers, normalized to 1.
+      GMSH_API void revolve(const vector_pair &dimTags,
+                            const double x, const double y, const double z,
+                            const double ax, const double ay,
+                            const double az, const double angle,
+                            vector_pair &outDimTags,
+                            const std::vector<int> &numElements =
+                            std::vector<int>(),
+                            const std::vector<double> &heights =
+                            std::vector<double>(),
+                            const bool recombine = false);
+
+      // Extrudes the geometrical entities in `dimTags' by a combined
+      // translation and rotation of `angle' radians, along (`dx', `dy', `dz')
+      // and around the axis of revolution defined by the point (`x', `y', `z')
+      // and the direction (`ax', `ay', `az'). Returns extruded entities in
+      // `outDimTags'. If `numElements' is not empty, also extrude the mesh: the
+      // entries in `numElements' give the number of elements in each layer. If
+      // `height' is not empty, it provides the (cummulative) height of the
+      // different layers, normalized to 1.
+      GMSH_API void twist(const vector_pair &dimTags,
+                          const double x, const double y, const double z,
+                          const double dx, const double dy, const double dz,
+                          const double ax, const double ay, const double az,
+                          const double angle,
+                          vector_pair &outDimTags,
+                          const std::vector<int> &numElements =
+                          std::vector<int>(),
+                          const std::vector<double> &heights =
+                          std::vector<double>(),
+                          const bool recombine = false);
+
+      // Translates the geometrical entities in `dimTags' along (`dx', `dy',
+      // `dz').
+      GMSH_API void translate(const vector_pair &dimTags, const double dx,
+                              const double dy, const double dz);
+
+      // Rotates the geometrical entities in `dimTags' of `angle' radians around
+      // the axis of revolution defined by the point (`x', `y', `z') and the
+      // direction (`ax', `ay', `az').
+      GMSH_API void rotate(const vector_pair &dimTags, const double x,
+                           const double y, const double z, const double ax,
+                           const double ay, const double az,
+                           const double angle);
+
+
+      // Scales the geometrical entities in `dimTag' by factors `a', `b' and `c'
+      // along the three coordinate axes; use (`x', `y', `z') as the center of
+      // the homothetic transformation.
+      GMSH_API void dilate(const vector_pair &dimTags, const double x,
+                           const double y, const double z, const double a,
+                           const double b, const double c);
+
+      // Applies a symmetry transformation to the geometrical entities in
+      // `dimTag', with respect to the plane of equation `a' * x + `b' * y + `c'
+      // * z + `d' = 0.
+      GMSH_API void symmetry(const vector_pair &dimTags, const double a,
+                             const double b, const double c, const double d);
+
+      // Copies the entities in `dimTags'; the new entities are returned in
+      // `outDimTags'.
+      GMSH_API void copy(const vector_pair &dimTags, vector_pair &outDimTags);
+
+      // Removes the entities `dimTags'. If `recursive' is true, remove all the
+      // entities on their boundaries, down to dimension 0.
+      GMSH_API void remove(const vector_pair &dimTags,
+                           const bool recursive = false);
+
+      // Remove all duplicate entities (different entities at the same
+      // geometrical location).
+      GMSH_API void removeAllDuplicates();
+
+      // Synchronize the internal GEO CAD representation with the current Gmsh
+      // model. This can be called at any time, but since it involves a non
+      // trivial amount of processing, the number of synchronization points
+      // should normally be minimized.
+      GMSH_API void synchronize();
+
+      namespace mesh { // geo-specific meshing constraints
+
+        // Sets a mesh size constraint on the geometrical entities
+        // `dimTags'. Currently only entities of dimension 0 (points) are
+        // handled.
+        GMSH_API void setSize(const vector_pair &dimTags, const double size);
+
+        // Sets a transfinite meshing constraint on the line `tag', with
+        // `numVertices' mesh vertices distributed according to `type' and
+        // `coef'. Currently supported types are "Progression" (geometrical
+        // progression with power `coef') and "Bump" (refinement toward both
+        // extreminties of the line).
+        GMSH_API void setTransfiniteLine(const int tag, const int nPoints,
+                                         const std::string &type = "Progression",
+                                         const double coef = 1.);
+
+        // Sets a transfinite meshing constraint on the surface
+        // `tag'. `arrangement' describes the arrangement of the triangles when
+        // the surface is not flagged as recombined: currently supported values
+        // are "Left", "Right", "AlternateLeft" and
+        // "AlternateRight". `cornerTags' can be used to specify the (3 or 4)
+        // corners of the transfinite interpolation explicitly; specifying the
+        // corners explicitly is mandatory if the surface has more that 3 or 4
+        // points on its boundary.
+        GMSH_API void setTransfiniteSurface(const int tag,
+                                            const std::string &arrangement = "Left",
+                                            const std::vector<int> &cornerTags =
+                                            std::vector<int>());
 
-// Remove all duplicate entities (different entities at the same geometrical
-// location).
-GMSH_API void gmshModelGeoRemoveAllDuplicates();
-
-
-// Sets a mesh size constraint on the geometrical entities `dimTags'. Currently
-// only entities of dimension 0 (points) are handled.
-GMSH_API void gmshModelGeoSetMeshSize(const vector_pair &dimTags, const double size);
-
-// Sets a transfinite meshing constraint on the line `tag', with `numVertices'
-// mesh vertices distributed according to `type' and `coef'. Currently supported
-// types are "Progression" (geometrical progression with power `coef') and
-// "Bump" (refinement toward both extreminties of the line).
-GMSH_API void gmshModelGeoSetTransfiniteLine(const int tag, const int nPoints,
-                                             const std::string &type = "Progression",
-                                             const double coef = 1.);
-
-// Sets a transfinite meshing constraint on the surface `tag'. `arrangement'
-// describes the arrangement of the triangles when the surface is not flagged as
-// recombined: currently supported values are "Left", "Right", "AlternateLeft"
-// and "AlternateRight". `cornerTags' can be used to specify the (3 or 4)
-// corners of the transfinite interpolation explicitly; specifying the corners
-// explicitly is mandatory if the surface has more that 3 or 4 points on its
-// boundary.
-GMSH_API void gmshModelGeoSetTransfiniteSurface(const int tag,
-                                                const std::string &arrangement = "Left",
-                                                const std::vector<int> &cornerTags =
-                                                std::vector<int>());
-
-// Sets a transfinite meshing constraint on the surface `tag'. `cornerTags' can
-// be used to specify the (6 or 8) corners of the transfinite interpolation
-// explicitly.
-GMSH_API void gmshModelGeoSetTransfiniteVolume(const int tag,
-                                               const std::vector<int> &cornerTags =
-                                               std::vector<int>());
-
-// Sets a recombination meshing constraint on the geometrical entity of
-// dimension `dim' and tag `tag'. Currently only entities of dimension 2 (to
-// recombine triangles into quadrangles) are supported.
-GMSH_API void gmshModelGeoSetRecombine(const int dim, const int tag,
-                                       const double angle = 45.);
-
-// Sets a smoothing meshing constraint on the geometrical entity of dimension
-// `dim' and tag `tag'. `val' iterations of a Laplace smoother are applied.
-GMSH_API void gmshModelGeoSetSmoothing(const int dim, const int tag,
-                                       const int val);
-
-// Sets a reverse meshing constraint on the geometrical entity of dimension
-// `dim' and tag `tag'. If `val' is true, the mesh orientation will be reversed
-// with respect to the natural mesh orientation (i.e. the orientation consistent
-// with the orientation of the geometrical entity). If `val' is false, the mesh
-// is left as-is.
-GMSH_API void gmshModelGeoSetReverseMesh(const int dim, const int tag,
-                                         const bool val = true);
-
-// Synchronize the internal GEO CAD representation with the current Gmsh
-// model. This can be called at any time, but since it involves a non trivial
-// amount of processing, the number of synchronization points should normally be
-// minimized.
-GMSH_API void gmshModelGeoSynchronize();
-
-// -----------------------------------------------------------------------------
-// Module gmshModelOcc: internal per-model OpenCASCADE CAD kernel functions
-// -----------------------------------------------------------------------------
-
-// Adds a geometrical point in the internal OpenCASCADE CAD representation, at
-// coordinates (x, y, z). If `meshSize' is > 0, adds a meshing constraint at
-// that point. If `tag' is positive, sets the tag explicitly; otherwise a new
-// tag is selected automatically. Returns the tag of the point. (Note that the
-// point will be added in the current model only after gmshModelGeoSynchronize()
-// is called. This behavior holds for all the entities created in the
-// gmshModelOcc module.)
-GMSH_API int gmshModelOccAddPoint(const double x, const double y, const double z,
-                                  const double meshSize = 0., const int tag = -1);
-
-// Adds a straight line segment between the two points with tags `startTag' and
-// `endTag'. If `tag' is positive, sets the tag explicitly; otherwise a new tag
-// is selected automatically. Returns the tag of the line.
-GMSH_API int gmshModelOccAddLine(const int startTag, const int endTag,
-                                 const int tag = -1);
+        // Sets a transfinite meshing constraint on the surface
+        // `tag'. `cornerTags' can be used to specify the (6 or 8) corners of the
+        // transfinite interpolation explicitly.
+        GMSH_API void setTransfiniteVolume(const int tag,
+                                           const std::vector<int> &cornerTags =
+                                           std::vector<int>());
+
+        // Sets a recombination meshing constraint on the geometrical entity of
+        // dimension `dim' and tag `tag'. Currently only entities of dimension 2
+        // (to recombine triangles into quadrangles) are supported.
+        GMSH_API void setRecombine(const int dim, const int tag,
+                                   const double angle = 45.);
+
+        // Sets a smoothing meshing constraint on the geometrical entity of
+        // dimension `dim' and tag `tag'. `val' iterations of a Laplace smoother
+        // are applied.
+        GMSH_API void setSmoothing(const int dim, const int tag,
+                                   const int val);
+
+        // Sets a reverse meshing constraint on the geometrical entity of
+        // dimension `dim' and tag `tag'. If `val' is true, the mesh orientation
+        // will be reversed with respect to the natural mesh orientation (i.e. the
+        // orientation consistent with the orientation of the geometrical
+        // entity). If `val' is false, the mesh is left as-is.
+        GMSH_API void setReverse(const int dim, const int tag,
+                                 const bool val = true);
+
+      } // namespace mesh
+
+    } // namespace geo
+
+    namespace occ { // Internal per-model OpenCASCADE CAD kernel functions
+
+      // Adds a geometrical point in the internal OpenCASCADE CAD
+      // representation, at coordinates (x, y, z). If `meshSize' is > 0, adds a
+      // meshing constraint at that point. If `tag' is positive, sets the tag
+      // explicitly; otherwise a new tag is selected automatically. Returns the
+      // tag of the point. (Note that the point will be added in the current
+      // model only after gmshModelGeoSynchronize() is called. This behavior
+      // holds for all the entities added in the gmshModelOcc module.)
+      GMSH_API int addPoint(const double x, const double y, const double z,
+                            const double meshSize = 0., const int tag = -1);
+
+      // Adds a straight line segment between the two points with tags
+      // `startTag' and `endTag'. If `tag' is positive, sets the tag explicitly;
+      // otherwise a new tag is selected automatically. Returns the tag of the
+      // line.
+      GMSH_API int addLine(const int startTag, const int endTag,
+                           const int tag = -1);
 
-// Adds a circle arc between the two points with tags `startTag' and `endTag',
-// with center `centertag'. If `tag' is positive, sets the tag explicitly;
-// otherwise a new tag is selected automatically. Returns the tag of the circle
-// arc.
-GMSH_API int gmshModelOccAddCircleArc(const int startTag, const int centerTag,
-                                      const int endTag, const int tag = -1);
-
-// Adds a circle of center (`x', `y', `z') and radius `r'. If `tag' is positive,
-// sets the tag explicitly; otherwise a new tag is selected
-// automatically. `angle1' and `angle2' allow to create a circle arc. Returns
-// the tag of the circle.
-GMSH_API int gmshModelOccAddCircle(const double x, const double y, const double z,
-                                   const double r, const int tag = -1,
-                                   const double angle1 = 0.,
-                                   const double angle2 = 2*M_PI);
-
-GMSH_API int gmshModelOccAddEllipseArc(const int startTag, const int centerTag,
-                                       const int endTag, const int tag = -1);
-GMSH_API int gmshModelOccAddEllipse(const double x, const double y, const double z,
-                                    const double r1, const double r2,
-                                    const int tag = -1,
-                                    const double angle1 = 0.,
-                                    const double angle2 = 2*M_PI);
-GMSH_API int gmshModelOccAddSpline(const std::vector<int> &vertexTags,
-                                   const int tag = -1);
-GMSH_API int gmshModelOccAddBezier(const std::vector<int> &vertexTags,
-                                   const int tag = -1);
-GMSH_API int gmshModelOccAddBSpline(const std::vector<int> &vertexTags,
-                                    const int tag = -1);
-GMSH_API int gmshModelOccAddWire(const std::vector<int> &edgeTags,
-                                 const int tag = -1,
-                                 const bool checkClosed = false);
-GMSH_API int gmshModelOccAddLineLoop(const std::vector<int> &edgeTags,
-                                     const int tag = -1);
-GMSH_API int gmshModelOccAddRectangle(const double x, const double y,
-                                      const double z, const double dx,
-                                      const double dy,
-                                      const int tag = -1,
-                                      const double roundedRadius = 0.);
-GMSH_API int gmshModelOccAddDisk(const double xc, const double yc,
-                                 const double zc, const double rx,
-                                 const double ry, const int tag = -1);
-GMSH_API int gmshModelOccAddPlaneSurface(const std::vector<int> &wireTags,
-                                         const int tag = -1);
-GMSH_API int gmshModelOccAddSurfaceFilling(int wireTag, const int tag = -1);
-GMSH_API int gmshModelOccAddSurfaceLoop(const std::vector<int> &faceTags,
-                                        const int tag = -1);
-GMSH_API int gmshModelOccAddVolume(const std::vector<int> &shellTags,
+      // Adds a circle arc between the two points with tags `startTag' and
+      // `endTag', with center `centertag'. If `tag' is positive, sets the tag
+      // explicitly; otherwise a new tag is selected automatically. Returns the
+      // tag of the circle arc.
+      GMSH_API int addCircleArc(const int startTag, const int centerTag,
+                                const int endTag, const int tag = -1);
+
+      // Adds a circle of center (`x', `y', `z') and radius `r'. If `tag' is
+      // positive, sets the tag explicitly; otherwise a new tag is selected
+      // automatically. `angle1' and `angle2' allow to add a circle
+      // arc. Returns the tag of the circle.
+      GMSH_API int addCircle(const double x, const double y, const double z,
+                             const double r, const int tag = -1,
+                             const double angle1 = 0.,
+                             const double angle2 = 2*M_PI);
+
+      GMSH_API int addEllipseArc(const int startTag, const int centerTag,
+                                             const int endTag, const int tag = -1);
+      GMSH_API int addEllipse(const double x, const double y, const double z,
+                              const double r1, const double r2,
+                              const int tag = -1,
+                              const double angle1 = 0.,
+                              const double angle2 = 2*M_PI);
+      GMSH_API int addSpline(const std::vector<int> &vertexTags,
+                             const int tag = -1);
+      GMSH_API int addBezier(const std::vector<int> &vertexTags,
+                             const int tag = -1);
+      GMSH_API int addBSpline(const std::vector<int> &vertexTags,
+                              const int tag = -1);
+      GMSH_API int addWire(const std::vector<int> &edgeTags,
+                           const int tag = -1,
+                           const bool checkClosed = false);
+      GMSH_API int addLineLoop(const std::vector<int> &edgeTags,
+                               const int tag = -1);
+      GMSH_API int addRectangle(const double x, const double y,
+                                const double z, const double dx,
+                                const double dy,
+                                const int tag = -1,
+                                const double roundedRadius = 0.);
+      GMSH_API int addDisk(const double xc, const double yc,
+                           const double zc, const double rx,
+                           const double ry, const int tag = -1);
+      GMSH_API int addPlaneSurface(const std::vector<int> &wireTags,
                                    const int tag = -1);
-GMSH_API int gmshModelOccAddSphere(const double xc, const double yc,
-                                   const double zc, const double radius,
+      GMSH_API int addSurfaceFilling(int wireTag, const int tag = -1);
+      GMSH_API int addSurfaceLoop(const std::vector<int> &faceTags,
+                                  const int tag = -1);
+      GMSH_API int addVolume(const std::vector<int> &shellTags,
+                             const int tag = -1);
+      GMSH_API int addSphere(const double xc, const double yc,
+                             const double zc, const double radius,
+                             const int tag = -1,
+                             const double angle1 = -M_PI/2,
+                             const double angle2 = M_PI/2,
+                             const double angle3 = 2*M_PI);
+      GMSH_API int addBox(const double x, const double y, const double z,
+                          const double dx, const double dy, const double dz,
+                          const int tag = -1);
+      GMSH_API int addCylinder(const double x, const double y,
+                               const double z, const double dx,
+                               const double dy, const double dz,
+                               const double r, const int tag = -1,
+                               double angle = 2*M_PI);
+      GMSH_API int addCone(const double x, const double y, const double z,
+                           const double dx, const double dy, const double dz,
+                           const double r1, const double r2,
+                           const int tag = -1,
+                           const double angle = 2*M_PI);
+      GMSH_API int addWedge(const double x, const double y, const double z,
+                            const double dx, const double dy, const double dz,
+                            const int tag = -1, const double ltx = 0.);
+      GMSH_API int addTorus(const double x, const double y, const double z,
+                            const double r1, const double r2,
+                            const int tag = -1,
+                            const double angle = 2*M_PI);
+      GMSH_API int addThruSections(const std::vector<int> &wireTags,
+                                   vector_pair &outDimTags,
                                    const int tag = -1,
-                                   const double angle1 = -M_PI/2,
-                                   const double angle2 = M_PI/2,
-                                   const double angle3 = 2*M_PI);
-GMSH_API int gmshModelOccAddBox(const double x, const double y, const double z,
-                                const double dx, const double dy, const double dz,
-                                const int tag = -1);
-GMSH_API int gmshModelOccAddCylinder(const double x, const double y,
-                                     const double z, const double dx,
-                                     const double dy, const double dz,
-                                     const double r, const int tag = -1,
-                                     double angle = 2*M_PI);
-GMSH_API int gmshModelOccAddCone(const double x, const double y, const double z,
-                                 const double dx, const double dy, const double dz,
-                                 const double r1, const double r2,
-                                 const int tag = -1,
-                                 const double angle = 2*M_PI);
-GMSH_API int gmshModelOccAddWedge(const double x, const double y, const double z,
-                                  const double dx, const double dy, const double dz,
-                                  const int tag = -1, const double ltx = 0.);
-GMSH_API int gmshModelOccAddTorus(const double x, const double y, const double z,
-                                  const double r1, const double r2,
-                                  const int tag = -1,
-                                  const double angle = 2*M_PI);
-GMSH_API int gmshModelOccAddThruSections(const std::vector<int> &wireTags,
-                                         vector_pair &outDimTags,
-                                         const int tag = -1,
-                                         const bool makeSolid = true,
-                                         const bool makeRuled = false);
-GMSH_API int addThickSolid(const int solidTag,
-                           const std::vector<int> &excludeFaceTags,
-                           const double offset, vector_pair &outDimTags,
-                           const int tag = -1);
-GMSH_API void gmshModelOccExtrude(const vector_pair &dimTags, const double dx,
-                                  const double dy, const double dz,
-                                  vector_pair &outDimTags,
-                                  const std::vector<int> &numElements =
-                                  std::vector<int>(),
-                                  const std::vector<double> &heights =
-                                  std::vector<double>(),
-                                  const bool recombine = false);
-GMSH_API void gmshModelOccRevolve(const vector_pair &dimTags,
-                                  const double x, const double y, const double z,
-                                  const double ax, const double ay, const double az,
-                                  const double angle, vector_pair &outDimTags,
-                                  const std::vector<int> &numElements =
-                                  std::vector<int>(),
-                                  const std::vector<double> &heights =
-                                  std::vector<double>(),
-                                  const bool recombine = false);
-GMSH_API void gmshModelOccAddPipe(const vector_pair &dimTags, int wireTag,
-                                  vector_pair &outDimTags);
-GMSH_API void gmshModelOccFillet(const std::vector<int> &regionTags,
-                                 const std::vector<int> &edgeTags,
-                                 const double radius, vector_pair &outDimTags,
-                                 const bool removeRegion = true);
-GMSH_API int gmshModelOccBooleanUnion(const vector_pair &objectDimTags,
-                                      const vector_pair &toolDimTags,
-                                      vector_pair &outDimTags,
-                                      std::vector<vector_pair> &outDimTagsMap,
-                                      const int tag = -1,
-                                      const bool removeObject = true,
-                                      const bool removeTool = true);
-GMSH_API int gmshModelOccBooleanIntersection(const vector_pair &objectDimTags,
-                                             const vector_pair &toolDimTags,
-                                             vector_pair &outDimTags,
-                                             std::vector<vector_pair> &outDimTagsMap,
-                                             const int tag = -1,
-                                             const bool removeObject = true,
-                                             const bool removeTool = true);
-GMSH_API int gmshModelOccBooleanDifference(const vector_pair &objectDimTags,
-                                           const vector_pair &toolDimTags,
-                                           vector_pair &outDimTags,
-                                           std::vector<vector_pair> &outDimTagsMap,
-                                           const int tag = -1,
-                                           const bool removeObject = true,
-                                           const bool removeTool = true);
-GMSH_API int gmshModelOccBooleanFragments(const vector_pair &objectDimTags,
-                                          const vector_pair &toolDimTags,
-                                          vector_pair &outDimTags,
-                                          std::vector<vector_pair> &outDimTagsMap,
-                                          const int tag = -1,
-                                          const bool removeObject = true,
-                                          const bool removeTool = true);
-GMSH_API void gmshModelOccTranslate(const vector_pair &dimTags, const double dx,
-                                    const double dy, const double dz);
-GMSH_API void gmshModelOccRotate(const vector_pair &dimTags, const double x,
-                                 const double y, const double z, const double ax,
-                                 const double ay, const double az, const double angle);
-GMSH_API void gmshModelOccDilate(const vector_pair &dimTags, const double x,
-                                 const double y, const double z, const double a,
-                                 const double b, const double c);
-GMSH_API void gmshModelOccSymmetry(const vector_pair &dimTags, const double a,
-                                   const double b, const double c, const double d);
-GMSH_API void gmshModelOccCopy(const vector_pair &dimTags, vector_pair &outDimTags);
-GMSH_API void gmshModelOccRemove(const vector_pair &dimTags,
-                                 const bool recursive = false);
-GMSH_API void gmshModelOccRemoveAllDuplicates();
-GMSH_API void gmshModelOccImportShapes(const std::string &fileName,
+                                   const bool makeSolid = true,
+                                   const bool makeRuled = false);
+      GMSH_API int addThickSolid(const int solidTag,
+                                 const std::vector<int> &excludeFaceTags,
+                                 const double offset, vector_pair &outDimTags,
+                                 const int tag = -1);
+      GMSH_API void extrude(const vector_pair &dimTags, const double dx,
+                            const double dy, const double dz,
+                            vector_pair &outDimTags,
+                            const std::vector<int> &numElements =
+                            std::vector<int>(),
+                            const std::vector<double> &heights =
+                            std::vector<double>(),
+                            const bool recombine = false);
+      GMSH_API void revolve(const vector_pair &dimTags,
+                            const double x, const double y, const double z,
+                            const double ax, const double ay, const double az,
+                            const double angle, vector_pair &outDimTags,
+                            const std::vector<int> &numElements =
+                            std::vector<int>(),
+                            const std::vector<double> &heights =
+                            std::vector<double>(),
+                            const bool recombine = false);
+      GMSH_API void addPipe(const vector_pair &dimTags, int wireTag,
+                            vector_pair &outDimTags);
+      GMSH_API void fillet(const std::vector<int> &regionTags,
+                           const std::vector<int> &edgeTags,
+                           const double radius, vector_pair &outDimTags,
+                           const bool removeRegion = true);
+      GMSH_API int booleanUnion(const vector_pair &objectDimTags,
+                                const vector_pair &toolDimTags,
+                                vector_pair &outDimTags,
+                                std::vector<vector_pair> &outDimTagsMap,
+                                const int tag = -1,
+                                const bool removeObject = true,
+                                const bool removeTool = true);
+      GMSH_API int booleanIntersection(const vector_pair &objectDimTags,
+                                       const vector_pair &toolDimTags,
                                        vector_pair &outDimTags,
-                                       const bool highestDimOnly = true,
-                                       const std::string &format = "");
-
-// Sets a mesh size constraint on the geometrical entities `dimTags'. Currently
-// only entities of dimension 0 (points) are handled.
-GMSH_API void gmshModelOccSetMeshSize(const vector_pair &dimTags, const double size);
-
-// Synchronize the internal OpenCASCADE CAD representation with the current Gmsh
-// model. This can be called at any time, but since it involves a non trivial
-// amount of processing, the number of synchronization points should normally be
-// minimized.
-GMSH_API void gmshModelOccSynchronize();
-
-// -----------------------------------------------------------------------------
-// Module gmshModelField: per-model mesh size field functions
-// -----------------------------------------------------------------------------
-
-// Creates a new mesh size field of type `type'. If `tag' is positive, assign
-// the tag explcitly; otherwise a new tag is assigned automatically. Returns the
-// field tag.
-GMSH_API int gmshModelFieldCreate(const std::string &type, const int tag = -1);
-
-// Deletes the field with tag `tag'.
-GMSH_API void gmshModelFieldDelete(const int tag);
-
-// Sets the numerical option `option' to value `value' for field `tag'.
-GMSH_API void gmshModelFieldSetNumber(const int tag, const std::string &option,
-                                      const double value);
-
-// Sets the string option `option' to value `value' for field `tag'.
-GMSH_API void gmshModelFieldSetString(const int tag, const std::string &option,
-                                      const std::string &value);
-
-// Sets the numerical list option `option' to value `value' for field `tag'.
-GMSH_API void gmshModelFieldSetNumbers(const int tag, const std::string &option,
-                                       const std::vector<double> &value);
-
-// Sets the field `tag' as background mesh size field.
-GMSH_API void gmshModelFieldSetAsBackground(const int tag);
-
-// -----------------------------------------------------------------------------
-// Module gmshView: post-processing view functions
-// -----------------------------------------------------------------------------
-
-// Creates a new post-processing view, with name `name'. If `tag' is positive
-// use it (and delete the view with that tag if it already exists), otherwise
-// associate a new tag. Returns the view tag.
-GMSH_API int gmshViewCreate(const std::string &name, const int tag = -1);
-
-// Deletes the view with tag `tag'.
-GMSH_API void gmshViewDelete(const int tag);
-
-// Gets the index of the view with tag `tag' in the list of currently loaded
-// views. This dynamic index (it can change when views are deleted) is used to
-// access view options with the gmshOption functions.
-GMSH_API int gmshViewGetIndex(const int tag);
-
-// Gets the tags of all views.
-GMSH_API void gmshViewGetTags(std::vector<int> &tags);
-
-// Adds model-based post-processing data to the view with tag `tag'. `modelName'
-// identifies the model the data is attached to. `dataType' specifies the type
-// of data, currently either "NodeData", "ElementData" or
-// "ElementNodeData". `tags' gives the tags of the vertices or elements in the
-// mesh to which the data is associated. `data' is a vector of length
-// `tags.size()`: each entry is the vector of double precision numbers
-// representing the data associated with the corresponding tag. The optional
-// `step` and `time` arguments associate a time step and time value with the
-// data. `numComponents' gives the number of data components (1 for scalar data,
-// 3 for vector data, etc.) per entity; if negative, it is automatically
-// inferred (when possible) from the input data. `partition' allows to specify
-// data in several sub-sets.
-GMSH_API void gmshViewAddModelData(const int tag, const std::string &modelName,
-                                   const std::string &dataType,
-                                   const std::vector<int> &tags,
-                                   const std::vector<std::vector<double> > &data,
-                                   const int step = 0, const int time = 0.,
-                                   const int numComponents = -1,
-                                   const int partition = 0);
-
-// Adds list-based post-processing data to the view with tag `tag'. `type'
-// identifies the data: "SP" for scalar points, "VP", for vector points,
-// etc. `numEle' gives the number of elements in the data. `data' contains the
-// data for the `numEle' elements.
-GMSH_API void gmshViewAddListData(const int tag, const std::string &type,
-                                  const int numEle, const std::vector<double> &data);
-
-// Probes the view `tag' for its `value' at point (`x', `y', `z').
-GMSH_API void gmshViewProbe(const int tag, const double x, const double y,
-                            const double z, std::vector<double> &value,
-                            const int step = -1, const int numComp = -1,
-                            const bool gradient = false,
-                            const double tolerance = 0.,
-                            const std::vector<double> xElemCoord
-                            = std::vector<double>(),
-                            const std::vector<double> yElemCoord
-                            = std::vector<double>(),
-                            const std::vector<double> zElemCoord
-                            = std::vector<double>());
-
-// Exports the view to a file. The export format is determined by the file
-// extension.
-GMSH_API void gmshViewExport(const int tag, const std::string &fileName,
-                             const bool append = false);
-
-// -----------------------------------------------------------------------------
-// Module gmshPlugin: plugin functions
-// -----------------------------------------------------------------------------
-
-// Sets the numerical option `option` to the value `value' for plugin `name'.
-GMSH_API void gmshPluginSetNumber(const std::string &name,
-                                  const std::string &option,
-                                  const double value);
-
-// Sets the string option `option` to the value `value' for plugin `name'.
-GMSH_API void gmshPluginSetString(const std::string &name,
-                                  const std::string &option,
-                                  const std::string &value);
-
-// Runs the plugin `name'.
-GMSH_API void gmshPluginRun(const std::string &name);
+                                       std::vector<vector_pair> &outDimTagsMap,
+                                       const int tag = -1,
+                                       const bool removeObject = true,
+                                       const bool removeTool = true);
+      GMSH_API int booleanDifference(const vector_pair &objectDimTags,
+                                     const vector_pair &toolDimTags,
+                                     vector_pair &outDimTags,
+                                     std::vector<vector_pair> &outDimTagsMap,
+                                     const int tag = -1,
+                                     const bool removeObject = true,
+                                     const bool removeTool = true);
+      GMSH_API int booleanFragments(const vector_pair &objectDimTags,
+                                    const vector_pair &toolDimTags,
+                                    vector_pair &outDimTags,
+                                    std::vector<vector_pair> &outDimTagsMap,
+                                    const int tag = -1,
+                                    const bool removeObject = true,
+                                    const bool removeTool = true);
+      GMSH_API void translate(const vector_pair &dimTags, const double dx,
+                              const double dy, const double dz);
+      GMSH_API void rotate(const vector_pair &dimTags, const double x,
+                           const double y, const double z, const double ax,
+                           const double ay, const double az, const double angle);
+      GMSH_API void dilate(const vector_pair &dimTags, const double x,
+                           const double y, const double z, const double a,
+                           const double b, const double c);
+      GMSH_API void symmetry(const vector_pair &dimTags, const double a,
+                             const double b, const double c, const double d);
+      GMSH_API void copy(const vector_pair &dimTags, vector_pair &outDimTags);
+      GMSH_API void remove(const vector_pair &dimTags,
+                           const bool recursive = false);
+      GMSH_API void removeAllDuplicates();
+      GMSH_API void importShapes(const std::string &fileName,
+                                 vector_pair &outDimTags,
+                                 const bool highestDimOnly = true,
+                                 const std::string &format = "");
+
+      // Sets a mesh size constraint on the geometrical entities
+      // `dimTags'. Currently only entities of dimension 0 (points) are handled.
+      GMSH_API void setMeshSize(const vector_pair &dimTags, const double size);
+
+      // Synchronize the internal OpenCASCADE CAD representation with the
+      // current Gmsh model. This can be called at any time, but since it
+      // involves a non trivial amount of processing, the number of
+      // synchronization points should normally be minimized.
+      GMSH_API void synchronize();
+
+    } // namespace occ
+
+  } // namespace model
+
+  namespace view { // Post-processing view functions
+
+    // Adds a new post-processing view, with name `name'. If `tag' is positive
+    // use it (and remove the view with that tag if it already exists),
+    // otherwise associate a new tag. Returns the view tag.
+    GMSH_API int add(const std::string &name, const int tag = -1);
+
+    // Removes the view with tag `tag'.
+    GMSH_API void remove(const int tag);
+
+    // Gets the index of the view with tag `tag' in the list of currently loaded
+    // views. This dynamic index (it can change when views are removed) is used
+    // to access view options with the gmshOption functions.
+    GMSH_API int getIndex(const int tag);
+
+    // Gets the tags of all views.
+    GMSH_API void getTags(std::vector<int> &tags);
+
+    // Adds model-based post-processing data to the view with tag
+    // `tag'. `modelName' identifies the model the data is attached
+    // to. `dataType' specifies the type of data, currently either "NodeData",
+    // "ElementData" or "ElementNodeData". `tags' gives the tags of the vertices
+    // or elements in the mesh to which the data is associated. `data' is a
+    // vector of length `tags.size()`: each entry is the vector of double
+    // precision numbers representing the data associated with the corresponding
+    // tag. The optional `step` and `time` arguments associate a time step and
+    // time value with the data. `numComponents' gives the number of data
+    // components (1 for scalar data, 3 for vector data, etc.) per entity; if
+    // negative, it is automatically inferred (when possible) from the input
+    // data. `partition' allows to specify data in several sub-sets.
+    GMSH_API void addModelData(const int tag, const std::string &modelName,
+                               const std::string &dataType,
+                               const std::vector<int> &tags,
+                               const std::vector<std::vector<double> > &data,
+                               const int step = 0, const int time = 0.,
+                               const int numComponents = -1,
+                               const int partition = 0);
+
+    // Adds list-based post-processing data to the view with tag `tag'. `type'
+    // identifies the data: "SP" for scalar points, "VP", for vector points,
+    // etc. `numEle' gives the number of elements in the data. `data' contains
+    // the data for the `numEle' elements.
+    GMSH_API void addListData(const int tag, const std::string &type,
+                              const int numEle, const std::vector<double> &data);
+
+    // Probes the view `tag' for its `value' at point (`x', `y', `z').
+    GMSH_API void probe(const int tag, const double x, const double y,
+                        const double z, std::vector<double> &value,
+                        const int step = -1, const int numComp = -1,
+                        const bool gradient = false,
+                        const double tolerance = 0.,
+                        const std::vector<double> xElemCoord
+                        = std::vector<double>(),
+                        const std::vector<double> yElemCoord
+                        = std::vector<double>(),
+                        const std::vector<double> zElemCoord
+                        = std::vector<double>());
+
+    // Writes the view to a file. The export format is determined by the file
+    // extension.
+    GMSH_API void write(const int tag, const std::string &fileName,
+                        const bool append = false);
+
+  } // namespace view
+
+  namespace plugin { // Plugin functions
+
+    // Sets the numerical option `option` to the value `value' for plugin `name'.
+    GMSH_API void setNumber(const std::string &name,
+                            const std::string &option,
+                            const double value);
+
+    // Sets the string option `option` to the value `value' for plugin `name'.
+    GMSH_API void setString(const std::string &name,
+                            const std::string &option,
+                            const std::string &value);
+
+    // Runs the plugin `name'.
+    GMSH_API void run(const std::string &name);
+
+  } // namespace plugin
+
+} // namespace gmsh
 
 #undef GMSH_API
 
diff --git a/Common/gmsh.i b/Common/gmsh.i
index 1297cbffe6..1a3cb6d9b0 100644
--- a/Common/gmsh.i
+++ b/Common/gmsh.i
@@ -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"
diff --git a/demos/api/boolean.cpp b/demos/api/boolean.cpp
index 22eb6800eb..4dd2ee309c 100644
--- a/demos/api/boolean.cpp
+++ b/demos/api/boolean.cpp
@@ -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;
 }
diff --git a/demos/api/boolean.py b/demos/api/boolean.py
index 9bbfbf1a1a..975deb1963 100644
--- a/demos/api/boolean.py
+++ b/demos/api/boolean.py
@@ -1,38 +1,38 @@
 # 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()
 
diff --git a/demos/api/discrete.cpp b/demos/api/discrete.cpp
index 25753dde17..ffe12cf559 100644
--- a/demos/api/discrete.cpp
+++ b/demos/api/discrete.cpp
@@ -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;
 }
diff --git a/demos/api/discrete.py b/demos/api/discrete.py
index 2322afc6ad..84003f726f 100644
--- a/demos/api/discrete.py
+++ b/demos/api/discrete.py
@@ -1,18 +1,18 @@
 #!/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()
 
diff --git a/demos/api/explore.cpp b/demos/api/explore.cpp
index 6933ec3bfa..6336a43dc2 100644
--- a/demos/api/explore.cpp
+++ b/demos/api/explore.cpp
@@ -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;
 }
diff --git a/demos/api/explore.py b/demos/api/explore.py
index 77059ac4a2..a4656cfcc2 100644
--- a/demos/api/explore.py
+++ b/demos/api/explore.py
@@ -1,32 +1,32 @@
 #!/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()
diff --git a/demos/api/open.cpp b/demos/api/open.cpp
index a25096fa24..0f0042995f 100644
--- a/demos/api/open.cpp
+++ b/demos/api/open.cpp
@@ -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;
 }
diff --git a/demos/api/open.py b/demos/api/open.py
index 4f09a068f2..d3df5f7263 100644
--- a/demos/api/open.py
+++ b/demos/api/open.py
@@ -1,16 +1,16 @@
 #!/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()
 
diff --git a/demos/api/plugin.cpp b/demos/api/plugin.cpp
index feba77fc57..016e2615f7 100644
--- a/demos/api/plugin.cpp
+++ b/demos/api/plugin.cpp
@@ -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;
 }
 
diff --git a/demos/api/plugin.py b/demos/api/plugin.py
index 70dfe49067..f96c425aa6 100644
--- a/demos/api/plugin.py
+++ b/demos/api/plugin.py
@@ -1,43 +1,43 @@
 #!/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()
 
 
diff --git a/demos/api/t1.cpp b/demos/api/t1.cpp
index dbecc7040a..049ce3f896 100644
--- a/demos/api/t1.cpp
+++ b/demos/api/t1.cpp
@@ -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;
 }
diff --git a/demos/api/t1.py b/demos/api/t1.py
index 83d4fc4472..869810a6aa 100644
--- a/demos/api/t1.py
+++ b/demos/api/t1.py
@@ -7,19 +7,19 @@
 # of the Python API.
 
 # The API is entirely defined in the gmsh module
-from gmsh import *
+import gmsh
 
 # Before using any functions in the Python 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.optionSetNumber("General.Terminal", 1)
 
 # This creates a new model, named "t1". If gmshModelCreate() is not called, a
 # new default (unnamed) model will be created on the fly, if necessary.
-gmshModelCreate("t1")
+gmsh.modelAdd("t1")
 
 # The Python API provides direct access to the internal CAD kernels. The
 # built-in CAD kernel was used in t1.geo: the corresponding API functions have
@@ -32,35 +32,35 @@ gmshModelCreate("t1")
 #
 # - the last (optional) argument is the point tag
 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.modelGeoAddPoint(0, 0, 0, lc, 1)
+gmsh.modelGeoAddPoint(.1, 0,  0, lc, 2)
+gmsh.modelGeoAddPoint(.1, .3, 0, lc, 3)
+gmsh.modelGeoAddPoint(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.modelGeoAddLine(1, 2, 1)
+gmsh.modelGeoAddLine(3, 2, 2)
+gmsh.modelGeoAddLine(3, 4, 3)
+gmsh.modelGeoAddLine(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.modelGeoAddLineLoop([4, 1, -2, 3], 1)
+gmsh.modelGeoAddPlaneSurface([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.modelAddPhysicalGroup(0, [1, 2], 1)
+gmsh.modelAddPhysicalGroup(1, [1, 2], 2)
+gmsh.modelAddPhysicalGroup(2, [1], 6)
 
 # Physical names are also defined by providing the dimension and tag of the
 # entity.
-gmshModelSetPhysicalName(2, 6, "My surface")
+gmsh.modelSetPhysicalName(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 structures. This
@@ -69,13 +69,13 @@ gmshModelSetPhysicalName(2, 6, "My surface")
 # 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.modelGeoSynchronize()
 
 # We can then generate a 2D mesh...
-gmshModelMesh(2)
+gmsh.modelMeshGenerate(2)
 
 # ... and save it to disk
-gmshExport("t1.msh")
+gmsh.write("t1.msh")
 
 # This should be called at the end:
-gmshFinalize()
+gmsh.finalize()
diff --git a/demos/api/t10.cpp b/demos/api/t10.cpp
index 517a20225e..c87fe66cb4 100644
--- a/demos/api/t10.cpp
+++ b/demos/api/t10.cpp
@@ -3,66 +3,69 @@
 #include <gmsh.h>
 #include <sstream>
 
+using namespace gmsh;
+
 int main(int argc, char **argv)
 {
-  gmshInitialize(argc, argv);
-  gmshOptionSetNumber("General.Terminal", 1);
+  initialize(argc, argv);
+  option::setNumber("General.Terminal", 1);
 
-  gmshModelCreate("t1");
+  model::add("t1");
 
   double lc = .15;
-  gmshModelGeoAddPoint(0.0,0.0,0,lc, 1);
-  gmshModelGeoAddPoint(1,0.0,0,lc, 2);
-  gmshModelGeoAddPoint(1,1,0,lc, 3);
-  gmshModelGeoAddPoint(0,1,0,lc, 4);
-  gmshModelGeoAddPoint(0.2,.5,0,lc, 5);
-
-  gmshModelGeoAddLine(1,2, 1);
-  gmshModelGeoAddLine(2,3, 2);
-  gmshModelGeoAddLine(3,4, 3);
-  gmshModelGeoAddLine(4,1, 4);
-
-  gmshModelGeoAddLineLoop({1,2,3,4}, 5);
-  gmshModelGeoAddPlaneSurface({5}, 6);
-
-  gmshModelFieldCreate("Attractor", 1);
-  gmshModelFieldSetNumbers(1, "NodesList", {5});
-  gmshModelFieldSetNumber(1, "NNodesByEdge", 100);
-  gmshModelFieldSetNumbers(1, "EdgesList", {2});
-
-  gmshModelFieldCreate("Threshold", 2);
-  gmshModelFieldSetNumber(2, "IField", 1);
-  gmshModelFieldSetNumber(2, "LcMin", lc / 30);
-  gmshModelFieldSetNumber(2, "LcMax", lc);
-  gmshModelFieldSetNumber(2, "DistMin", 0.15);
-  gmshModelFieldSetNumber(2, "DistMax", 0.5);
-
-  gmshModelFieldCreate("MathEval", 3);
-  gmshModelFieldSetString(3, "F", "Cos(4*3.14*x) * Sin(4*3.14*y) / 10 + 0.101");
-
-  gmshModelFieldCreate("Attractor", 4);
-  gmshModelFieldSetNumbers(4, "NodesList", {1});
-
-  gmshModelFieldCreate("MathEval", 5);
+  model::geo::addPoint(0.0,0.0,0,lc, 1);
+  model::geo::addPoint(1,0.0,0,lc, 2);
+  model::geo::addPoint(1,1,0,lc, 3);
+  model::geo::addPoint(0,1,0,lc, 4);
+  model::geo::addPoint(0.2,.5,0,lc, 5);
+
+  model::geo::addLine(1,2, 1);
+  model::geo::addLine(2,3, 2);
+  model::geo::addLine(3,4, 3);
+  model::geo::addLine(4,1, 4);
+
+  model::geo::addLineLoop({1,2,3,4}, 5);
+  model::geo::addPlaneSurface({5}, 6);
+
+  model::mesh::field::add("Attractor", 1);
+  model::mesh::field::setNumbers(1, "NodesList", {5});
+  model::mesh::field::setNumber(1, "NNodesByEdge", 100);
+  model::mesh::field::setNumbers(1, "EdgesList", {2});
+
+  model::mesh::field::add("Threshold", 2);
+  model::mesh::field::setNumber(2, "IField", 1);
+  model::mesh::field::setNumber(2, "LcMin", lc / 30);
+  model::mesh::field::setNumber(2, "LcMax", lc);
+  model::mesh::field::setNumber(2, "DistMin", 0.15);
+  model::mesh::field::setNumber(2, "DistMax", 0.5);
+
+  model::mesh::field::add("MathEval", 3);
+  model::mesh::field::setString(3, "F", "Cos(4*3.14*x) * Sin(4*3.14*y) / 10 + 0.101");
+
+  model::mesh::field::add("Attractor", 4);
+  model::mesh::field::setNumbers(4, "NodesList", {1});
+
+  model::mesh::field::add("MathEval", 5);
   std::stringstream stream;
   stream << "F4^3 + " << lc / 100;
-  gmshModelFieldSetString(5, "F", stream.str());
+  model::mesh::field::setString(5, "F", stream.str());
 
-  gmshModelFieldCreate("Box", 6);
-  gmshModelFieldSetNumber(6, "VIn", lc / 15);
-  gmshModelFieldSetNumber(6, "VOut", lc);
-  gmshModelFieldSetNumber(6, "XMin", 0.3);
-  gmshModelFieldSetNumber(6, "XMax", 0.6);
-  gmshModelFieldSetNumber(6, "YMin", 0.3);
-  gmshModelFieldSetNumber(6, "YMax", 0.6);
+  model::mesh::field::add("Box", 6);
+  model::mesh::field::setNumber(6, "VIn", lc / 15);
+  model::mesh::field::setNumber(6, "VOut", lc);
+  model::mesh::field::setNumber(6, "XMin", 0.3);
+  model::mesh::field::setNumber(6, "XMax", 0.6);
+  model::mesh::field::setNumber(6, "YMin", 0.3);
+  model::mesh::field::setNumber(6, "YMax", 0.6);
 
-  gmshModelFieldCreate("Min", 7);
-  gmshModelFieldSetNumbers(7, "FieldsList", {2, 3, 5, 6});
+  model::mesh::field::add("Min", 7);
+  model::mesh::field::setNumbers(7, "FieldsList", {2, 3, 5, 6});
 
-  gmshModelFieldSetAsBackground(7);
+  model::mesh::field::setAsBackground(7);
 
-  gmshModelGeoSynchronize();
-  gmshModelMesh(2);
-  gmshExport("t10.msh");
+  model::geo::synchronize();
+  model::mesh::generate(2);
+  write("t10.msh");
+  finalize();
   return 0;
 }
diff --git a/demos/api/t10.py b/demos/api/t10.py
index 5514bf0a8e..48142ab640 100644
--- a/demos/api/t10.py
+++ b/demos/api/t10.py
@@ -2,63 +2,65 @@
 
 # This file reimplements gmsh/tutorial/t10.geo in Python.
 
-from gmsh import *
+import gmsh
 import math
 
-gmshInitialize()
-gmshOptionSetNumber("General.Terminal", 1)
+gmsh.initialize()
+gmsh.optionSetNumber("General.Terminal", 1)
 
-gmshModelCreate("t10")
+gmsh.modelAdd("t10")
 
 lc = .15
-gmshModelGeoAddPoint(0.0,0.0,0, lc, 1)
-gmshModelGeoAddPoint(1,0.0,0, lc, 2)
-gmshModelGeoAddPoint(1,1,0, lc, 3)
-gmshModelGeoAddPoint(0,1,0, lc, 4)
-gmshModelGeoAddPoint(0.2,.5,0, lc, 5)
-
-gmshModelGeoAddLine(1,2, 1);
-gmshModelGeoAddLine(2,3, 2);
-gmshModelGeoAddLine(3,4, 3);
-gmshModelGeoAddLine(4,1, 4);
-
-gmshModelGeoAddLineLoop([1,2,3,4], 5)
-gmshModelGeoAddPlaneSurface([5], 6)
-
-gmshModelFieldCreate("Attractor", 1)
-gmshModelFieldSetNumbers(1, "NodesList", [5])
-gmshModelFieldSetNumber(1, "NNodesByEdge", 100)
-gmshModelFieldSetNumbers(1, "EdgesList", [2])
-
-gmshModelFieldCreate("Threshold", 2);
-gmshModelFieldSetNumber(2, "IField", 1);
-gmshModelFieldSetNumber(2, "LcMin", lc / 30)
-gmshModelFieldSetNumber(2, "LcMax", lc)
-gmshModelFieldSetNumber(2, "DistMin", 0.15)
-gmshModelFieldSetNumber(2, "DistMax", 0.5)
-
-gmshModelFieldCreate("MathEval", 3)
-gmshModelFieldSetString(3, "F", "Cos(4*3.14*x) * Sin(4*3.14*y) / 10 + 0.101")
-
-gmshModelFieldCreate("Attractor", 4)
-gmshModelFieldSetNumbers(4, "NodesList", [1])
-
-gmshModelFieldCreate("MathEval", 5);
-gmshModelFieldSetString(5, "F", "F4^3 + " + str(lc / 100))
-
-gmshModelFieldCreate("Box", 6)
-gmshModelFieldSetNumber(6, "VIn", lc / 15)
-gmshModelFieldSetNumber(6, "VOut", lc)
-gmshModelFieldSetNumber(6, "XMin", 0.3)
-gmshModelFieldSetNumber(6, "XMax", 0.6)
-gmshModelFieldSetNumber(6, "YMin", 0.3)
-gmshModelFieldSetNumber(6, "YMax", 0.6)
-
-gmshModelFieldCreate("Min", 7)
-gmshModelFieldSetNumbers(7, "FieldsList", [2, 3, 5, 6])
-
-gmshModelFieldSetAsBackground(7)
-
-gmshModelGeoSynchronize()
-gmshModelMesh(2)
-gmshExport("t10.msh")
+gmsh.modelGeoAddPoint(0.0,0.0,0, lc, 1)
+gmsh.modelGeoAddPoint(1,0.0,0, lc, 2)
+gmsh.modelGeoAddPoint(1,1,0, lc, 3)
+gmsh.modelGeoAddPoint(0,1,0, lc, 4)
+gmsh.modelGeoAddPoint(0.2,.5,0, lc, 5)
+
+gmsh.modelGeoAddLine(1,2, 1);
+gmsh.modelGeoAddLine(2,3, 2);
+gmsh.modelGeoAddLine(3,4, 3);
+gmsh.modelGeoAddLine(4,1, 4);
+
+gmsh.modelGeoAddLineLoop([1,2,3,4], 5)
+gmsh.modelGeoAddPlaneSurface([5], 6)
+
+gmsh.modelMeshFieldAdd("Attractor", 1)
+gmsh.modelMeshFieldSetNumbers(1, "NodesList", [5])
+gmsh.modelMeshFieldSetNumber(1, "NNodesByEdge", 100)
+gmsh.modelMeshFieldSetNumbers(1, "EdgesList", [2])
+
+gmsh.modelMeshFieldAdd("Threshold", 2);
+gmsh.modelMeshFieldSetNumber(2, "IField", 1);
+gmsh.modelMeshFieldSetNumber(2, "LcMin", lc / 30)
+gmsh.modelMeshFieldSetNumber(2, "LcMax", lc)
+gmsh.modelMeshFieldSetNumber(2, "DistMin", 0.15)
+gmsh.modelMeshFieldSetNumber(2, "DistMax", 0.5)
+
+gmsh.modelMeshFieldAdd("MathEval", 3)
+gmsh.modelMeshFieldSetString(3, "F", "Cos(4*3.14*x) * Sin(4*3.14*y) / 10 + 0.101")
+
+gmsh.modelMeshFieldAdd("Attractor", 4)
+gmsh.modelMeshFieldSetNumbers(4, "NodesList", [1])
+
+gmsh.modelMeshFieldAdd("MathEval", 5);
+gmsh.modelMeshFieldSetString(5, "F", "F4^3 + " + str(lc / 100))
+
+gmsh.modelMeshFieldAdd("Box", 6)
+gmsh.modelMeshFieldSetNumber(6, "VIn", lc / 15)
+gmsh.modelMeshFieldSetNumber(6, "VOut", lc)
+gmsh.modelMeshFieldSetNumber(6, "XMin", 0.3)
+gmsh.modelMeshFieldSetNumber(6, "XMax", 0.6)
+gmsh.modelMeshFieldSetNumber(6, "YMin", 0.3)
+gmsh.modelMeshFieldSetNumber(6, "YMax", 0.6)
+
+gmsh.modelMeshFieldAdd("Min", 7)
+gmsh.modelMeshFieldSetNumbers(7, "FieldsList", [2, 3, 5, 6])
+
+gmsh.modelMeshFieldSetAsBackground(7)
+
+gmsh.modelGeoSynchronize()
+gmsh.modelMeshGenerate(2)
+gmsh.write("t10.msh")
+gmsh.finalize()
+
diff --git a/demos/api/t16.cpp b/demos/api/t16.cpp
index 055e0e3d23..47c61e43cd 100644
--- a/demos/api/t16.cpp
+++ b/demos/api/t16.cpp
@@ -4,47 +4,47 @@
 
 int main(int argc, char **argv)
 {
-  gmshInitialize(argc, argv);
-  gmshOptionSetNumber("General.Terminal", 1);
+  gmsh::initialize(argc, argv);
+  gmsh::option::setNumber("General.Terminal", 1);
 
-  gmshModelCreate("t16");
+  gmsh::model::add("t16");
 
   std::vector<std::pair<int, int> > ov;
   std::vector<std::vector<std::pair<int, int> > > ovv;
-  gmshModelOccAddBox(0,0,0, 1,1,1, 1);
-  gmshModelOccAddBox(0,0,0, 0.5,0.5,0.5, 2);
-  gmshModelOccBooleanDifference({{3,1}}, {{3,2}}, ov, ovv, 3);
+  gmsh::model::occ::addBox(0,0,0, 1,1,1, 1);
+  gmsh::model::occ::addBox(0,0,0, 0.5,0.5,0.5, 2);
+  gmsh::model::occ::booleanDifference({{3,1}}, {{3,2}}, ov, ovv, 3);
   double x = 0, y = 0.75, z = 0, r = 0.09 ;
   std::vector<std::pair<int, int> > holes;
   for(int t = 1; t <= 5; t++){
     x += 0.166 ;
     z += 0.166 ;
-    gmshModelOccAddSphere(x,y,z,r, 3 + t);
+    gmsh::model::occ::addSphere(x,y,z,r, 3 + t);
     holes.push_back({3, 3 + t});
   }
-  gmshModelOccBooleanFragments({{3,3}}, holes, ov, ovv);
+  gmsh::model::occ::booleanFragments({{3,3}}, holes, ov, ovv);
 
-  gmshModelOccSynchronize();
+  gmsh::model::occ::synchronize();
 
   double lcar1 = .1;
   double lcar2 = .0005;
   double lcar3 = .055;
 
-  gmshModelGetEntities(ov, 0);
-  gmshModelSetMeshSize(ov, lcar1);
+  gmsh::model::getEntities(ov, 0);
+  gmsh::model::mesh::setSize(ov, lcar1);
 
-  gmshModelGetBoundary(holes, ov, false, false, true);
-  gmshModelSetMeshSize(ov, lcar3);
+  gmsh::model::getBoundary(holes, ov, false, false, true);
+  gmsh::model::mesh::setSize(ov, lcar3);
 
   double eps = 1e-3;
-  gmshModelGetEntitiesInBoundingBox(0.5-eps, 0.5-eps, 0.5-eps,
-                                    0.5+eps, 0.5+eps, 0.5+eps, ov, 0);
-  gmshModelSetMeshSize(ov, lcar2);
+  gmsh::model::getEntitiesInBoundingBox(0.5-eps, 0.5-eps, 0.5-eps,
+                                        0.5+eps, 0.5+eps, 0.5+eps, ov, 0);
+  gmsh::model::mesh::setSize(ov, lcar2);
 
-  gmshModelMesh(3);
+  gmsh::model::mesh::generate(3);
 
-  gmshExport("t16.msh");
+  gmsh::write("t16.msh");
 
-  gmshFinalize();
+  gmsh::finalize();
   return 0;
 }
diff --git a/demos/api/t16.py b/demos/api/t16.py
index 3343f9e978..b5575264a2 100644
--- a/demos/api/t16.py
+++ b/demos/api/t16.py
@@ -2,50 +2,50 @@
 
 # This file reimplements gmsh/tutorial/t16.geo in Python.
 
-from gmsh import *
+import gmsh
 import math
 
-gmshInitialize()
-gmshOptionSetNumber("General.Terminal", 1)
+gmsh.initialize()
+gmsh.optionSetNumber("General.Terminal", 1)
 
-gmshModelCreate("t16")
+gmsh.modelAdd("t16")
 
-ov = PairVector(); ovv = PairVectorVector()
+ov = gmsh.PairVector(); ovv = gmsh.PairVectorVector()
 
-gmshModelOccAddBox(0,0,0, 1,1,1, 1)
-gmshModelOccAddBox(0,0,0, 0.5,0.5,0.5, 2)
-gmshModelOccBooleanDifference([(3,1)], [(3,2)], ov, ovv, 3)
+gmsh.modelOccAddBox(0,0,0, 1,1,1, 1)
+gmsh.modelOccAddBox(0,0,0, 0.5,0.5,0.5, 2)
+gmsh.modelOccBooleanDifference([(3,1)], [(3,2)], ov, ovv, 3)
 
 x = 0; y = 0.75; z = 0; r = 0.09
 
-holes = PairVector()
+holes = gmsh.PairVector()
 for t in range(1, 6):
     x += 0.166
     z += 0.166
-    gmshModelOccAddSphere(x,y,z,r, 3 + t)
+    gmsh.modelOccAddSphere(x,y,z,r, 3 + t)
     holes.append((3, 3 + t))
 
-gmshModelOccBooleanFragments([(3,3)], holes, ov, ovv)
+gmsh.modelOccBooleanFragments([(3,3)], holes, ov, ovv)
 
-gmshModelOccSynchronize()
+gmsh.modelOccSynchronize()
 
 lcar1 = .1
 lcar2 = .0005
 lcar3 = .055
 
-gmshModelGetEntities(ov, 0);
-gmshModelSetMeshSize(ov, lcar1);
+gmsh.modelGetEntities(ov, 0);
+gmsh.modelMeshSetSize(ov, lcar1);
 
-gmshModelGetBoundary(holes, ov, False, False, True);
-gmshModelSetMeshSize(ov, lcar3);
+gmsh.modelGetBoundary(holes, ov, False, False, True);
+gmsh.modelMeshSetSize(ov, lcar3);
 
 eps = 1e-3
-gmshModelGetEntitiesInBoundingBox(0.5-eps, 0.5-eps, 0.5-eps,
+gmsh.modelGetEntitiesInBoundingBox(0.5-eps, 0.5-eps, 0.5-eps,
                                   0.5+eps, 0.5+eps, 0.5+eps, ov, 0)
-gmshModelSetMeshSize(ov, lcar2)
+gmsh.modelMeshSetSize(ov, lcar2)
 
-gmshModelMesh(3)
+gmsh.modelMeshGenerate(3)
 
-gmshExport("t16.msh")
+gmsh.write("t16.msh")
 
-gmshFinalize()
+gmsh.finalize()
diff --git a/demos/api/t2.cpp b/demos/api/t2.cpp
index 85666ba8d5..094e34fbce 100644
--- a/demos/api/t2.cpp
+++ b/demos/api/t2.cpp
@@ -3,108 +3,111 @@
 
 #include <gmsh.h>
 
+// make all function in the gmsh namespace directly available
+using namespace gmsh;
+
 int main(int argc, char **argv)
 {
   // If argc/argv are passed, Gmsh will parse the commandline in the same way as
   // the standalone Gmsh code.
-  gmshInitialize(argc, argv);
-  gmshOptionSetNumber("General.Terminal", 1);
+  initialize(argc, argv);
+  option::setNumber("General.Terminal", 1);
 
-  gmshModelCreate("t2");
+  model::add("t2");
 
   // Copied from t1.cpp...
   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);
-  gmshModelGeoAddLine(1, 2, 1);
-  gmshModelGeoAddLine(3, 2, 2);
-  gmshModelGeoAddLine(3, 4, 3);
-  gmshModelGeoAddLine(4, 1, 4);
-  gmshModelGeoAddLineLoop({4, 1, -2, 3}, 1);
-  gmshModelGeoAddPlaneSurface({1}, 1);
-  gmshModelAddPhysicalGroup(0, {1, 2}, 1);
-  gmshModelAddPhysicalGroup(1, {1, 2}, 2);
-  gmshModelAddPhysicalGroup(2, {1}, 6);
-  gmshModelSetPhysicalName(2, 6, "My surface");
+  model::geo::addPoint(0, 0, 0, lc, 1);
+  model::geo::addPoint(.1, 0,  0, lc, 2);
+  model::geo::addPoint(.1, .3, 0, lc, 3);
+  model::geo::addPoint(0,  .3, 0, lc, 4);
+  model::geo::addLine(1, 2, 1);
+  model::geo::addLine(3, 2, 2);
+  model::geo::addLine(3, 4, 3);
+  model::geo::addLine(4, 1, 4);
+  model::geo::addLineLoop({4, 1, -2, 3}, 1);
+  model::geo::addPlaneSurface({1}, 1);
+  model::addPhysicalGroup(0, {1, 2}, 1);
+  model::addPhysicalGroup(1, {1, 2}, 2);
+  model::addPhysicalGroup(2, {1}, 6);
+  model::setPhysicalName(2, 6, "My surface");
   // ...end of copy
 
-  gmshModelGeoAddPoint(0, .4, 0, lc, 5);
-  gmshModelGeoAddLine(4, 5, 5);
+  model::geo::addPoint(0, .4, 0, lc, 5);
+  model::geo::addLine(4, 5, 5);
 
   // Geometrical transformations take a vector of pairs of integers as first
   // argument, which contains the list of entities, represented by (dimension,
   // tag) pairs. Here we thus translate point 3 (dimension=0, tag=3), by
   // dx=-0.05, dy=0, dz=0.
-  gmshModelGeoTranslate({{0, 3}}, -0.05, 0, 0);
+  model::geo::translate({{0, 3}}, -0.05, 0, 0);
 
   // The "Duplicata" functionality in .geo files is handled by
-  // gmshModelGeoCopy(), which takes a vector of (dim, tag) pairs as input, and
+  // model::geo::copy(), which takes a vector of (dim, tag) pairs as input, and
   // returns another vector of (dim, tag) pairs.
   std::vector<std::pair<int, int> > ov;
-  gmshModelGeoCopy({{0, 3}}, ov);
-  gmshModelGeoTranslate(ov, 0, 0.1, 0);
+  model::geo::copy({{0, 3}}, ov);
+  model::geo::translate(ov, 0, 0.1, 0);
 
-  gmshModelGeoAddLine(3, ov[0].second, 7);
-  gmshModelGeoAddLine(ov[0].second, 5, 8);
-  gmshModelGeoAddLineLoop({5,-8,-7,3}, 10);
-  gmshModelGeoAddPlaneSurface({10}, 11);
+  model::geo::addLine(3, ov[0].second, 7);
+  model::geo::addLine(ov[0].second, 5, 8);
+  model::geo::addLineLoop({5,-8,-7,3}, 10);
+  model::geo::addPlaneSurface({10}, 11);
 
-  gmshModelGeoCopy({{2, 1}, {2, 11}}, ov);
-  gmshModelGeoTranslate(ov, 0.12, 0, 0);
+  model::geo::copy({{2, 1}, {2, 11}}, ov);
+  model::geo::translate(ov, 0.12, 0, 0);
 
   std::printf("New surfaces '%d' and '%d'\n", ov[0].second, ov[1].second);
 
-  gmshModelGeoAddPoint(0., 0.3, 0.13, lc, 100);
-  gmshModelGeoAddPoint(0.08, 0.3, 0.1, lc, 101);
-  gmshModelGeoAddPoint(0.08, 0.4, 0.1, lc, 102);
-  gmshModelGeoAddPoint(0., 0.4, 0.13, lc, 103);
-
-  gmshModelGeoAddLine(4, 100, 110);
-  gmshModelGeoAddLine(3, 101, 111);
-  gmshModelGeoAddLine(6, 102, 112);
-  gmshModelGeoAddLine(5, 103, 113);
-  gmshModelGeoAddLine(103, 100, 114);
-  gmshModelGeoAddLine(100, 101, 115);
-  gmshModelGeoAddLine(101, 102, 116);
-  gmshModelGeoAddLine(102, 103, 117);
-
-  gmshModelGeoAddLineLoop({115, -111, 3, 110}, 118);
-  gmshModelGeoAddPlaneSurface({118}, 119);
-  gmshModelGeoAddLineLoop({111, 116, -112, -7}, 120);
-  gmshModelGeoAddPlaneSurface({120}, 121);
-  gmshModelGeoAddLineLoop({112, 117, -113, -8}, 122);
-  gmshModelGeoAddPlaneSurface({122}, 123);
-  gmshModelGeoAddLineLoop({114, -110, 5, 113}, 124);
-  gmshModelGeoAddPlaneSurface({124}, 125);
-  gmshModelGeoAddLineLoop({115, 116, 117, 114}, 126);
-  gmshModelGeoAddPlaneSurface({126}, 127);
+  model::geo::addPoint(0., 0.3, 0.13, lc, 100);
+  model::geo::addPoint(0.08, 0.3, 0.1, lc, 101);
+  model::geo::addPoint(0.08, 0.4, 0.1, lc, 102);
+  model::geo::addPoint(0., 0.4, 0.13, lc, 103);
+
+  model::geo::addLine(4, 100, 110);
+  model::geo::addLine(3, 101, 111);
+  model::geo::addLine(6, 102, 112);
+  model::geo::addLine(5, 103, 113);
+  model::geo::addLine(103, 100, 114);
+  model::geo::addLine(100, 101, 115);
+  model::geo::addLine(101, 102, 116);
+  model::geo::addLine(102, 103, 117);
+
+  model::geo::addLineLoop({115, -111, 3, 110}, 118);
+  model::geo::addPlaneSurface({118}, 119);
+  model::geo::addLineLoop({111, 116, -112, -7}, 120);
+  model::geo::addPlaneSurface({120}, 121);
+  model::geo::addLineLoop({112, 117, -113, -8}, 122);
+  model::geo::addPlaneSurface({122}, 123);
+  model::geo::addLineLoop({114, -110, 5, 113}, 124);
+  model::geo::addPlaneSurface({124}, 125);
+  model::geo::addLineLoop({115, 116, 117, 114}, 126);
+  model::geo::addPlaneSurface({126}, 127);
 
   // The API to create surface loops ("shells") and volumes is similar to the
   // one used to create line loops and surfaces.
-  gmshModelGeoAddSurfaceLoop({127, 119, 121, 123, 125, 11}, 128);
-  gmshModelGeoAddVolume({128}, 129);
+  model::geo::addSurfaceLoop({127, 119, 121, 123, 125, 11}, 128);
+  model::geo::addVolume({128}, 129);
 
   // Extrusion works as expected, by providing a vector of (dim, tag) pairs as
   // input, the translation vector, and a vector of (dim, tag) pairs as output.
   std::vector<std::pair<int, int> > ov2;
-  gmshModelGeoExtrude({ov[1]}, 0, 0, 0.12, ov2);
+  model::geo::extrude({ov[1]}, 0, 0, 0.12, ov2);
 
   // Mesh sizes associated to geometrical points can be set by passing a vector
   // of (dim, tag) pairs for the corresponding points.
-  gmshModelGeoSetMeshSize({{0,103}, {0,105}, {0,109}, {0,102}, {0,28},
-                           {0, 24}, {0,6}, {0,5}}, lc * 3);
+  model::geo::mesh::setSize({{0,103}, {0,105}, {0,109}, {0,102}, {0,28},
+                            {0, 24}, {0,6}, {0,5}}, lc * 3);
 
-  gmshModelAddPhysicalGroup(3, {129,130}, 1);
-  gmshModelSetPhysicalName(3, 1, "The volume");
+  model::addPhysicalGroup(3, {129,130}, 1);
+  model::setPhysicalName(3, 1, "The volume");
 
-  gmshModelGeoSynchronize();
+  model::geo::synchronize();
 
-  gmshModelMesh(3);
+  model::mesh::generate(3);
 
-  gmshExport("t2.msh");
+  write("t2.msh");
 
-  gmshFinalize();
+  finalize();
   return 0;
 }
diff --git a/demos/api/t2.py b/demos/api/t2.py
index 1e6f9857dd..e1d6e32a7a 100644
--- a/demos/api/t2.py
+++ b/demos/api/t2.py
@@ -3,110 +3,110 @@
 # This file reimplements gmsh/tutorial/t2.geo in Python. Comments focus on the new
 # API functions used, compared to the ones introduced in t1.py.
 
-from gmsh import *
+import gmsh
 import sys
 
 # If sys.argv is passed, Gmsh will parse the commandline in the same way as the
 # standalone Gmsh code.
-gmshInitialize(sys.argv)
+gmsh.initialize(sys.argv)
 
-gmshOptionSetNumber("General.Terminal", 1)
+gmsh.optionSetNumber("General.Terminal", 1)
 
-gmshModelCreate("t2")
+gmsh.modelAdd("t2")
 
 # Copied from t1.py...
 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)
-gmshModelGeoAddLine(1, 2, 1)
-gmshModelGeoAddLine(3, 2, 2)
-gmshModelGeoAddLine(3, 4, 3)
-gmshModelGeoAddLine(4, 1, 4)
-gmshModelGeoAddLineLoop([4, 1, -2, 3], 1)
-gmshModelGeoAddPlaneSurface([1], 1)
-gmshModelAddPhysicalGroup(0, [1, 2], 1)
-gmshModelAddPhysicalGroup(1, [1, 2], 2)
-gmshModelAddPhysicalGroup(2, [1], 6)
-gmshModelSetPhysicalName(2, 6, "My surface")
+gmsh.modelGeoAddPoint(0, 0, 0, lc, 1)
+gmsh.modelGeoAddPoint(.1, 0,  0, lc, 2)
+gmsh.modelGeoAddPoint(.1, .3, 0, lc, 3)
+gmsh.modelGeoAddPoint(0, .3, 0, lc, 4)
+gmsh.modelGeoAddLine(1, 2, 1)
+gmsh.modelGeoAddLine(3, 2, 2)
+gmsh.modelGeoAddLine(3, 4, 3)
+gmsh.modelGeoAddLine(4, 1, 4)
+gmsh.modelGeoAddLineLoop([4, 1, -2, 3], 1)
+gmsh.modelGeoAddPlaneSurface([1], 1)
+gmsh.modelAddPhysicalGroup(0, [1, 2], 1)
+gmsh.modelAddPhysicalGroup(1, [1, 2], 2)
+gmsh.modelAddPhysicalGroup(2, [1], 6)
+gmsh.modelSetPhysicalName(2, 6, "My surface")
 # ...end of copy
 
-gmshModelGeoAddPoint(0, .4, 0, lc, 5)
-gmshModelGeoAddLine(4, 5, 5)
+gmsh.modelGeoAddPoint(0, .4, 0, lc, 5)
+gmsh.modelGeoAddLine(4, 5, 5)
 
 # Geometrical transformations take a vector of pairs of integers as first
 # argument, which contains the list of entities, represented by (dimension, tag)
 # pairs. Here we thus translate point 3 (dimension=0, tag=3), by dx=-0.05, dy=0,
 # dz=0.
-gmshModelGeoTranslate([(0, 3)], -0.05, 0, 0)
+gmsh.modelGeoTranslate([(0, 3)], -0.05, 0, 0)
 
 # The "Duplicata" functionality in .geo files is handled by
-# gmshModelGeoCopy(), which takes a vector of (dim, tag) pairs as input, and
+# gmsh.modelGeoCopy(), which takes a vector of (dim, tag) pairs as input, and
 # returns another vector of (dim, tag) pairs.
 
-ov = PairVector()
-gmshModelGeoCopy([(0, 3)], ov)
-gmshModelGeoTranslate(ov, 0, 0.1, 0)
+ov = gmsh.PairVector()
+gmsh.modelGeoCopy([(0, 3)], ov)
+gmsh.modelGeoTranslate(ov, 0, 0.1, 0)
 
-gmshModelGeoAddLine(3, ov[0][1], 7)
-gmshModelGeoAddLine(ov[0][1], 5, 8)
-gmshModelGeoAddLineLoop([5,-8,-7,3], 10)
-gmshModelGeoAddPlaneSurface([10], 11)
+gmsh.modelGeoAddLine(3, ov[0][1], 7)
+gmsh.modelGeoAddLine(ov[0][1], 5, 8)
+gmsh.modelGeoAddLineLoop([5,-8,-7,3], 10)
+gmsh.modelGeoAddPlaneSurface([10], 11)
 
-gmshModelGeoCopy([(2, 1), (2, 11)], ov)
-gmshModelGeoTranslate(ov, 0.12, 0, 0)
+gmsh.modelGeoCopy([(2, 1), (2, 11)], ov)
+gmsh.modelGeoTranslate(ov, 0.12, 0, 0)
 
 print "New surfaces " + str(ov[0][1]) + " and " + str(ov[1][1])
 
-gmshModelGeoAddPoint(0., 0.3, 0.13, lc, 100)
-gmshModelGeoAddPoint(0.08, 0.3, 0.1, lc, 101)
-gmshModelGeoAddPoint(0.08, 0.4, 0.1, lc, 102)
-gmshModelGeoAddPoint(0., 0.4, 0.13, lc, 103)
-
-gmshModelGeoAddLine(4, 100, 110)
-gmshModelGeoAddLine(3, 101, 111)
-gmshModelGeoAddLine(6, 102, 112)
-gmshModelGeoAddLine(5, 103, 113)
-gmshModelGeoAddLine(103, 100, 114)
-gmshModelGeoAddLine(100, 101, 115)
-gmshModelGeoAddLine(101, 102, 116)
-gmshModelGeoAddLine(102, 103, 117)
-
-gmshModelGeoAddLineLoop([115, -111, 3, 110], 118)
-gmshModelGeoAddPlaneSurface([118], 119)
-gmshModelGeoAddLineLoop([111, 116, -112, -7], 120)
-gmshModelGeoAddPlaneSurface([120], 121)
-gmshModelGeoAddLineLoop([112, 117, -113, -8], 122)
-gmshModelGeoAddPlaneSurface([122], 123)
-gmshModelGeoAddLineLoop([114, -110, 5, 113], 124)
-gmshModelGeoAddPlaneSurface([124], 125)
-gmshModelGeoAddLineLoop([115, 116, 117, 114], 126)
-gmshModelGeoAddPlaneSurface([126], 127)
+gmsh.modelGeoAddPoint(0., 0.3, 0.13, lc, 100)
+gmsh.modelGeoAddPoint(0.08, 0.3, 0.1, lc, 101)
+gmsh.modelGeoAddPoint(0.08, 0.4, 0.1, lc, 102)
+gmsh.modelGeoAddPoint(0., 0.4, 0.13, lc, 103)
+
+gmsh.modelGeoAddLine(4, 100, 110)
+gmsh.modelGeoAddLine(3, 101, 111)
+gmsh.modelGeoAddLine(6, 102, 112)
+gmsh.modelGeoAddLine(5, 103, 113)
+gmsh.modelGeoAddLine(103, 100, 114)
+gmsh.modelGeoAddLine(100, 101, 115)
+gmsh.modelGeoAddLine(101, 102, 116)
+gmsh.modelGeoAddLine(102, 103, 117)
+
+gmsh.modelGeoAddLineLoop([115, -111, 3, 110], 118)
+gmsh.modelGeoAddPlaneSurface([118], 119)
+gmsh.modelGeoAddLineLoop([111, 116, -112, -7], 120)
+gmsh.modelGeoAddPlaneSurface([120], 121)
+gmsh.modelGeoAddLineLoop([112, 117, -113, -8], 122)
+gmsh.modelGeoAddPlaneSurface([122], 123)
+gmsh.modelGeoAddLineLoop([114, -110, 5, 113], 124)
+gmsh.modelGeoAddPlaneSurface([124], 125)
+gmsh.modelGeoAddLineLoop([115, 116, 117, 114], 126)
+gmsh.modelGeoAddPlaneSurface([126], 127)
 
 # The API to create surface loops ("shells") and volumes is similar to the
 # one used to create line loops and surfaces.
-gmshModelGeoAddSurfaceLoop([127, 119, 121, 123, 125, 11], 128)
-gmshModelGeoAddVolume([128], 129)
+gmsh.modelGeoAddSurfaceLoop([127, 119, 121, 123, 125, 11], 128)
+gmsh.modelGeoAddVolume([128], 129)
 
 # Extrusion works as expected, by providing a vector of (dim, tag) pairs as
 # input, the translation vector, and a vector of (dim, tag) pairs as output.
-ov2 = PairVector()
-gmshModelGeoExtrude([ov[1]], 0, 0, 0.12, ov2)
+ov2 = gmsh.PairVector()
+gmsh.modelGeoExtrude([ov[1]], 0, 0, 0.12, ov2)
 
 # Mesh sizes associated to geometrical points can be set by passing a vector of
 # (dim, tag) pairs for the corresponding points.
 
-gmshModelGeoSetMeshSize([(0,103), (0,105), (0,109), (0,102), (0,28),
+gmsh.modelGeoMeshSetSize([(0,103), (0,105), (0,109), (0,102), (0,28),
                          (0, 24), (0,6), (0,5)], lc * 3)
 
-gmshModelAddPhysicalGroup(3, [129,130], 1)
-gmshModelSetPhysicalName(3, 1, "The volume")
+gmsh.modelAddPhysicalGroup(3, [129,130], 1)
+gmsh.modelSetPhysicalName(3, 1, "The volume")
 
-gmshModelGeoSynchronize()
+gmsh.modelGeoSynchronize()
 
-gmshModelMesh(3)
+gmsh.modelMeshGenerate(3)
 
-gmshExport("t2.msh")
+gmsh.write("t2.msh")
 
-gmshFinalize()
+gmsh.finalize()
diff --git a/demos/api/t3.cpp b/demos/api/t3.cpp
index cf60d3ad81..adbc952dbe 100644
--- a/demos/api/t3.cpp
+++ b/demos/api/t3.cpp
@@ -3,29 +3,31 @@
 #include <cmath>
 #include <gmsh.h>
 
+using namespace gmsh;
+
 int main(int argc, char **argv)
 {
-  gmshInitialize(argc, argv);
-  gmshOptionSetNumber("General.Terminal", 1);
+  initialize(argc, argv);
+  option::setNumber("General.Terminal", 1);
 
-  gmshModelCreate("t3");
+  model::add("t3");
 
   // Copied from t1.cpp...
   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);
-  gmshModelGeoAddLine(1, 2, 1);
-  gmshModelGeoAddLine(3, 2, 2);
-  gmshModelGeoAddLine(3, 4, 3);
-  gmshModelGeoAddLine(4, 1, 4);
-  gmshModelGeoAddLineLoop({4, 1, -2, 3}, 1);
-  gmshModelGeoAddPlaneSurface({1}, 1);
-  gmshModelAddPhysicalGroup(0, {1, 2}, 1);
-  gmshModelAddPhysicalGroup(1, {1, 2}, 2);
-  gmshModelAddPhysicalGroup(2, {1}, 6);
-  gmshModelSetPhysicalName(2, 6, "My surface");
+  model::geo::addPoint(0, 0, 0, lc, 1);
+  model::geo::addPoint(.1, 0,  0, lc, 2);
+  model::geo::addPoint(.1, .3, 0, lc, 3);
+  model::geo::addPoint(0,  .3, 0, lc, 4);
+  model::geo::addLine(1, 2, 1);
+  model::geo::addLine(3, 2, 2);
+  model::geo::addLine(3, 4, 3);
+  model::geo::addLine(4, 1, 4);
+  model::geo::addLineLoop({4, 1, -2, 3}, 1);
+  model::geo::addPlaneSurface({1}, 1);
+  model::addPhysicalGroup(0, {1, 2}, 1);
+  model::addPhysicalGroup(1, {1, 2}, 2);
+  model::addPhysicalGroup(2, {1}, 6);
+  model::setPhysicalName(2, 6, "My surface");
   // ...end of copy
 
   double h = 0.1, angle = 90.;
@@ -34,21 +36,22 @@ int main(int argc, char **argv)
   // Extruding the mesh in addition to the geometry works as in .geo files: the
   // number of elements for each layer and the (end) height of each layer are
   // specified in two vectors.
-  gmshModelGeoExtrude({{2,1}}, 0, 0, h, ov, {8,2}, {0.5,1});
+  model::geo::extrude({{2,1}}, 0, 0, h, ov, {8,2}, {0.5,1});
 
   // Rotational and twisted extrusions are available as well with the built-in
   // CAD kernel. The last (optional) argument for the Extrude/Revolve/Twist
   // commands specified whether the extruded mesh should be recombined or not.
-  gmshModelGeoRevolve({{2,28}}, -0.1,0,0.1, 0,1,0, -M_PI/2, ov, {7});
-  gmshModelGeoTwist({{2,50}}, 0,0.15,0.25, -2*h,0,0, 1,0,0, angle*M_PI/180.,
+  model::geo::revolve({{2,28}}, -0.1,0,0.1, 0,1,0, -M_PI/2, ov, {7});
+  model::geo::twist({{2,50}}, 0,0.15,0.25, -2*h,0,0, 1,0,0, angle*M_PI/180.,
                     ov, {10}, {}, true);
 
-  gmshModelAddPhysicalGroup(3, {1, 2, ov[1].second}, 101);
+  model::geo::synchronize();
+
+  model::addPhysicalGroup(3, {1, 2, ov[1].second}, 101);
 
-  gmshModelGeoSynchronize();
-  gmshModelMesh(3);
-  gmshExport("t3.msh");
-  gmshFinalize();
+  model::mesh::generate(3);
+  write("t3.msh");
+  finalize();
 
   return 0;
 }
diff --git a/demos/api/t3.py b/demos/api/t3.py
index 4a948910dd..8651015545 100644
--- a/demos/api/t3.py
+++ b/demos/api/t3.py
@@ -2,52 +2,52 @@
 
 # This files reimplements gmsh/tutorial/t3.geo in Python.
 
-from gmsh import *
+import gmsh
 import math
 
-gmshInitialize()
-gmshOptionSetNumber("General.Terminal", 1)
+gmsh.initialize()
+gmsh.optionSetNumber("General.Terminal", 1)
 
-gmshModelCreate("t3")
+gmsh.modelAdd("t3")
 
 # Copied from t1.py...
 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)
-gmshModelGeoAddLine(1, 2, 1)
-gmshModelGeoAddLine(3, 2, 2)
-gmshModelGeoAddLine(3, 4, 3)
-gmshModelGeoAddLine(4, 1, 4)
-gmshModelGeoAddLineLoop([4, 1, -2, 3], 1)
-gmshModelGeoAddPlaneSurface([1], 1)
-gmshModelAddPhysicalGroup(0, [1, 2], 1)
-gmshModelAddPhysicalGroup(1, [1, 2], 2)
-gmshModelAddPhysicalGroup(2, [1], 6)
-gmshModelSetPhysicalName(2, 6, "My surface")
+gmsh.modelGeoAddPoint(0, 0, 0, lc, 1)
+gmsh.modelGeoAddPoint(.1, 0,  0, lc, 2)
+gmsh.modelGeoAddPoint(.1, .3, 0, lc, 3)
+gmsh.modelGeoAddPoint(0, .3, 0, lc, 4)
+gmsh.modelGeoAddLine(1, 2, 1)
+gmsh.modelGeoAddLine(3, 2, 2)
+gmsh.modelGeoAddLine(3, 4, 3)
+gmsh.modelGeoAddLine(4, 1, 4)
+gmsh.modelGeoAddLineLoop([4, 1, -2, 3], 1)
+gmsh.modelGeoAddPlaneSurface([1], 1)
+gmsh.modelAddPhysicalGroup(0, [1, 2], 1)
+gmsh.modelAddPhysicalGroup(1, [1, 2], 2)
+gmsh.modelAddPhysicalGroup(2, [1], 6)
+gmsh.modelSetPhysicalName(2, 6, "My surface")
 # ...end of copy
 
 h = 0.1
 angle = 90.
 
-ov = PairVector()
+ov = gmsh.PairVector()
   
 # Extruding the mesh in addition to the geometry works as in .geo files: the
 # number of elements for each layer and the (end) height of each layer are
 # specified in two vectors.
-gmshModelGeoExtrude([(2,1)], 0, 0, h, ov, [8,2], [0.5,1])
+gmsh.modelGeoExtrude([(2,1)], 0, 0, h, ov, [8,2], [0.5,1])
 
 #/ Rotational and twisted extrusions are available as well with the built-in CAD
 # kernel. The last (optional) argument for the Extrude/Revolve/Twist commands
 # specified whether the extruded mesh should be recombined or not.
-gmshModelGeoRevolve([(2,28)], -0.1,0,0.1, 0,1,0, -math.pi/2, ov, [7])
-gmshModelGeoTwist([(2,50)], 0,0.15,0.25, -2*h,0,0, 1,0,0, angle*math.pi/180.,
+gmsh.modelGeoRevolve([(2,28)], -0.1,0,0.1, 0,1,0, -math.pi/2, ov, [7])
+gmsh.modelGeoTwist([(2,50)], 0,0.15,0.25, -2*h,0,0, 1,0,0, angle*math.pi/180.,
                   ov, [10], [], True)
 
-gmshModelAddPhysicalGroup(3, [1, 2, ov[1][1]], 101)
+gmsh.modelAddPhysicalGroup(3, [1, 2, ov[1][1]], 101)
 
-gmshModelGeoSynchronize()
-gmshModelMesh(3)
-gmshExport("t3.msh")
-gmshFinalize()
+gmsh.modelGeoSynchronize()
+gmsh.modelMeshGenerate(3)
+gmsh.write("t3.msh")
+gmsh.finalize()
diff --git a/demos/api/t4.cpp b/demos/api/t4.cpp
index 72cd55c561..3302979b2c 100644
--- a/demos/api/t4.cpp
+++ b/demos/api/t4.cpp
@@ -3,14 +3,16 @@
 #include <math.h>
 #include <gmsh.h>
 
+using namespace gmsh;
+
 double hypoth(double a, double b){ return sqrt(a * a + b * b); }
 
 int main(int argc, char **argv)
 {
-  gmshInitialize(argc, argv);
-  gmshOptionSetNumber("General.Terminal", 1);
+  initialize(argc, argv);
+  option::setNumber("General.Terminal", 1);
 
-  gmshModelCreate("t4");
+  model::add("t4");
 
   double cm = 1e-02;
   double e1 = 4.5 * cm, e2 = 6 * cm / 2, e3 =  5 * cm / 2;
@@ -22,63 +24,63 @@ int main(int argc, char **argv)
   double ccos = (-h5*R1 + e2 * hypot(h5, hypot(e2, R1))) / (h5*h5 + e2*e2);
   double ssin = sqrt(1 - ccos*ccos);
 
-  gmshModelGeoAddPoint(-e1-e2, 0    , 0, Lc1, 1);
-  gmshModelGeoAddPoint(-e1-e2, h1   , 0, Lc1, 2);
-  gmshModelGeoAddPoint(-e3-r , h1   , 0, Lc2, 3);
-  gmshModelGeoAddPoint(-e3-r , h1+r , 0, Lc2, 4);
-  gmshModelGeoAddPoint(-e3   , h1+r , 0, Lc2, 5);
-  gmshModelGeoAddPoint(-e3   , h1+h2, 0, Lc1, 6);
-  gmshModelGeoAddPoint( e3   , h1+h2, 0, Lc1, 7);
-  gmshModelGeoAddPoint( e3   , h1+r , 0, Lc2, 8);
-  gmshModelGeoAddPoint( e3+r , h1+r , 0, Lc2, 9);
-  gmshModelGeoAddPoint( e3+r , h1   , 0, Lc2, 10);
-  gmshModelGeoAddPoint( e1+e2, h1   , 0, Lc1, 11);
-  gmshModelGeoAddPoint( e1+e2, 0    , 0, Lc1, 12);
-  gmshModelGeoAddPoint( e2   , 0    , 0, Lc1, 13);
-
-  gmshModelGeoAddPoint( R1 / ssin, h5+R1*ccos, 0, Lc2, 14);
-  gmshModelGeoAddPoint( 0        , h5        , 0, Lc2, 15);
-  gmshModelGeoAddPoint(-R1 / ssin, h5+R1*ccos, 0, Lc2, 16);
-  gmshModelGeoAddPoint(-e2       , 0.0       , 0, Lc1, 17);
-
-  gmshModelGeoAddPoint(-R2 , h1+h3   , 0, Lc2, 18);
-  gmshModelGeoAddPoint(-R2 , h1+h3+h4, 0, Lc2, 19);
-  gmshModelGeoAddPoint( 0  , h1+h3+h4, 0, Lc2, 20);
-  gmshModelGeoAddPoint( R2 , h1+h3+h4, 0, Lc2, 21);
-  gmshModelGeoAddPoint( R2 , h1+h3   , 0, Lc2, 22);
-  gmshModelGeoAddPoint( 0  , h1+h3   , 0, Lc2, 23);
-
-  gmshModelGeoAddPoint(0, h1+h3+h4+R2, 0, Lc2, 24);
-  gmshModelGeoAddPoint(0, h1+h3-R2,    0, Lc2, 25);
-
-  gmshModelGeoAddLine(1 , 17, 1);
-  gmshModelGeoAddLine(17, 16, 2);
-
-  gmshModelGeoAddCircleArc(14,15,16, 3);
-  gmshModelGeoAddLine(14,13, 4);
-  gmshModelGeoAddLine(13,12, 5);
-  gmshModelGeoAddLine(12,11, 6);
-  gmshModelGeoAddLine(11,10, 7);
-  gmshModelGeoAddCircleArc(8,9,10, 8);
-  gmshModelGeoAddLine(8,7, 9);
-  gmshModelGeoAddLine(7,6, 10);
-  gmshModelGeoAddLine(6,5, 11);
-  gmshModelGeoAddCircleArc(3,4,5, 12);
-  gmshModelGeoAddLine(3,2, 13);
-  gmshModelGeoAddLine(2,1, 14);
-  gmshModelGeoAddLine(18,19, 15);
-  gmshModelGeoAddCircleArc(21,20,24, 16);
-  gmshModelGeoAddCircleArc(24,20,19, 17);
-  gmshModelGeoAddCircleArc(18,23,25, 18);
-  gmshModelGeoAddCircleArc(25,23,22, 19);
-  gmshModelGeoAddLine(21,22, 20);
-
-  gmshModelGeoAddLineLoop({17,-15,18,19,-20,16}, 21);
-  gmshModelGeoAddPlaneSurface({21}, 22);
-  gmshModelGeoAddLineLoop({11,-12,13,14,1,2,-3,4,5,6,7,-8,9,10}, 23);
+  model::geo::addPoint(-e1-e2, 0    , 0, Lc1, 1);
+  model::geo::addPoint(-e1-e2, h1   , 0, Lc1, 2);
+  model::geo::addPoint(-e3-r , h1   , 0, Lc2, 3);
+  model::geo::addPoint(-e3-r , h1+r , 0, Lc2, 4);
+  model::geo::addPoint(-e3   , h1+r , 0, Lc2, 5);
+  model::geo::addPoint(-e3   , h1+h2, 0, Lc1, 6);
+  model::geo::addPoint( e3   , h1+h2, 0, Lc1, 7);
+  model::geo::addPoint( e3   , h1+r , 0, Lc2, 8);
+  model::geo::addPoint( e3+r , h1+r , 0, Lc2, 9);
+  model::geo::addPoint( e3+r , h1   , 0, Lc2, 10);
+  model::geo::addPoint( e1+e2, h1   , 0, Lc1, 11);
+  model::geo::addPoint( e1+e2, 0    , 0, Lc1, 12);
+  model::geo::addPoint( e2   , 0    , 0, Lc1, 13);
+
+  model::geo::addPoint( R1 / ssin, h5+R1*ccos, 0, Lc2, 14);
+  model::geo::addPoint( 0        , h5        , 0, Lc2, 15);
+  model::geo::addPoint(-R1 / ssin, h5+R1*ccos, 0, Lc2, 16);
+  model::geo::addPoint(-e2       , 0.0       , 0, Lc1, 17);
+
+  model::geo::addPoint(-R2 , h1+h3   , 0, Lc2, 18);
+  model::geo::addPoint(-R2 , h1+h3+h4, 0, Lc2, 19);
+  model::geo::addPoint( 0  , h1+h3+h4, 0, Lc2, 20);
+  model::geo::addPoint( R2 , h1+h3+h4, 0, Lc2, 21);
+  model::geo::addPoint( R2 , h1+h3   , 0, Lc2, 22);
+  model::geo::addPoint( 0  , h1+h3   , 0, Lc2, 23);
+
+  model::geo::addPoint(0, h1+h3+h4+R2, 0, Lc2, 24);
+  model::geo::addPoint(0, h1+h3-R2,    0, Lc2, 25);
+
+  model::geo::addLine(1 , 17, 1);
+  model::geo::addLine(17, 16, 2);
+
+  model::geo::addCircleArc(14,15,16, 3);
+  model::geo::addLine(14,13, 4);
+  model::geo::addLine(13,12, 5);
+  model::geo::addLine(12,11, 6);
+  model::geo::addLine(11,10, 7);
+  model::geo::addCircleArc(8,9,10, 8);
+  model::geo::addLine(8,7, 9);
+  model::geo::addLine(7,6, 10);
+  model::geo::addLine(6,5, 11);
+  model::geo::addCircleArc(3,4,5, 12);
+  model::geo::addLine(3,2, 13);
+  model::geo::addLine(2,1, 14);
+  model::geo::addLine(18,19, 15);
+  model::geo::addCircleArc(21,20,24, 16);
+  model::geo::addCircleArc(24,20,19, 17);
+  model::geo::addCircleArc(18,23,25, 18);
+  model::geo::addCircleArc(25,23,22, 19);
+  model::geo::addLine(21,22, 20);
+
+  model::geo::addLineLoop({17,-15,18,19,-20,16}, 21);
+  model::geo::addPlaneSurface({21}, 22);
+  model::geo::addLineLoop({11,-12,13,14,1,2,-3,4,5,6,7,-8,9,10}, 23);
 
   // A surface with one hole is specified using 2 line loops:
-  gmshModelGeoAddPlaneSurface({23,21}, 24);
+  model::geo::addPlaneSurface({23,21}, 24);
 
   // FIXME: this will be implemented through the gmshView API
   /*
@@ -92,12 +94,12 @@ int main(int argc, char **argv)
   };
   */
 
-  gmshModelGeoSynchronize();
+  model::geo::synchronize();
 
-  gmshModelMesh(2);
+  model::mesh::generate(2);
 
-  gmshExport("t4.msh");
+  write("t4.msh");
 
-  gmshFinalize();
+  finalize();
   return 0;
 }
diff --git a/demos/api/t4.py b/demos/api/t4.py
index 3e442c83d9..f3acf82159 100644
--- a/demos/api/t4.py
+++ b/demos/api/t4.py
@@ -1,12 +1,12 @@
 # This file reimplements gmsh/tutorial/t4.geo in Python.
 
-from gmsh import *
+import gmsh
 import math
 
-gmshInitialize()
-gmshOptionSetNumber("General.Terminal", 1)
+gmsh.initialize()
+gmsh.optionSetNumber("General.Terminal", 1)
 
-gmshModelCreate("t4")
+gmsh.modelAdd("t4")
 
 cm = 1e-02
 e1 = 4.5 * cm; e2 = 6 * cm / 2; e3 =  5 * cm / 2
@@ -21,63 +21,63 @@ def hypot(a, b):
 ccos = (-h5*R1 + e2 * hypot(h5, hypot(e2, R1))) / (h5*h5 + e2*e2)
 ssin = math.sqrt(1 - ccos*ccos)
 
-gmshModelGeoAddPoint(-e1-e2, 0    , 0, Lc1, 1)
-gmshModelGeoAddPoint(-e1-e2, h1   , 0, Lc1, 2)
-gmshModelGeoAddPoint(-e3-r , h1   , 0, Lc2, 3)
-gmshModelGeoAddPoint(-e3-r , h1+r , 0, Lc2, 4)
-gmshModelGeoAddPoint(-e3   , h1+r , 0, Lc2, 5)
-gmshModelGeoAddPoint(-e3   , h1+h2, 0, Lc1, 6)
-gmshModelGeoAddPoint( e3   , h1+h2, 0, Lc1, 7)
-gmshModelGeoAddPoint( e3   , h1+r , 0, Lc2, 8)
-gmshModelGeoAddPoint( e3+r , h1+r , 0, Lc2, 9)
-gmshModelGeoAddPoint( e3+r , h1   , 0, Lc2, 10)
-gmshModelGeoAddPoint( e1+e2, h1   , 0, Lc1, 11)
-gmshModelGeoAddPoint( e1+e2, 0    , 0, Lc1, 12)
-gmshModelGeoAddPoint( e2   , 0    , 0, Lc1, 13)
-
-gmshModelGeoAddPoint( R1 / ssin, h5+R1*ccos, 0, Lc2, 14)
-gmshModelGeoAddPoint( 0        , h5        , 0, Lc2, 15)
-gmshModelGeoAddPoint(-R1 / ssin, h5+R1*ccos, 0, Lc2, 16)
-gmshModelGeoAddPoint(-e2       , 0.0       , 0, Lc1, 17)
-
-gmshModelGeoAddPoint(-R2 , h1+h3   , 0, Lc2, 18)
-gmshModelGeoAddPoint(-R2 , h1+h3+h4, 0, Lc2, 19)
-gmshModelGeoAddPoint( 0  , h1+h3+h4, 0, Lc2, 20)
-gmshModelGeoAddPoint( R2 , h1+h3+h4, 0, Lc2, 21)
-gmshModelGeoAddPoint( R2 , h1+h3   , 0, Lc2, 22)
-gmshModelGeoAddPoint( 0  , h1+h3   , 0, Lc2, 23)
+gmsh.modelGeoAddPoint(-e1-e2, 0    , 0, Lc1, 1)
+gmsh.modelGeoAddPoint(-e1-e2, h1   , 0, Lc1, 2)
+gmsh.modelGeoAddPoint(-e3-r , h1   , 0, Lc2, 3)
+gmsh.modelGeoAddPoint(-e3-r , h1+r , 0, Lc2, 4)
+gmsh.modelGeoAddPoint(-e3   , h1+r , 0, Lc2, 5)
+gmsh.modelGeoAddPoint(-e3   , h1+h2, 0, Lc1, 6)
+gmsh.modelGeoAddPoint( e3   , h1+h2, 0, Lc1, 7)
+gmsh.modelGeoAddPoint( e3   , h1+r , 0, Lc2, 8)
+gmsh.modelGeoAddPoint( e3+r , h1+r , 0, Lc2, 9)
+gmsh.modelGeoAddPoint( e3+r , h1   , 0, Lc2, 10)
+gmsh.modelGeoAddPoint( e1+e2, h1   , 0, Lc1, 11)
+gmsh.modelGeoAddPoint( e1+e2, 0    , 0, Lc1, 12)
+gmsh.modelGeoAddPoint( e2   , 0    , 0, Lc1, 13)
+
+gmsh.modelGeoAddPoint( R1 / ssin, h5+R1*ccos, 0, Lc2, 14)
+gmsh.modelGeoAddPoint( 0        , h5        , 0, Lc2, 15)
+gmsh.modelGeoAddPoint(-R1 / ssin, h5+R1*ccos, 0, Lc2, 16)
+gmsh.modelGeoAddPoint(-e2       , 0.0       , 0, Lc1, 17)
+
+gmsh.modelGeoAddPoint(-R2 , h1+h3   , 0, Lc2, 18)
+gmsh.modelGeoAddPoint(-R2 , h1+h3+h4, 0, Lc2, 19)
+gmsh.modelGeoAddPoint( 0  , h1+h3+h4, 0, Lc2, 20)
+gmsh.modelGeoAddPoint( R2 , h1+h3+h4, 0, Lc2, 21)
+gmsh.modelGeoAddPoint( R2 , h1+h3   , 0, Lc2, 22)
+gmsh.modelGeoAddPoint( 0  , h1+h3   , 0, Lc2, 23)
                                                 
-gmshModelGeoAddPoint( 0, h1+h3+h4+R2, 0, Lc2, 24)
-gmshModelGeoAddPoint( 0, h1+h3-R2,    0, Lc2, 25)
-
-gmshModelGeoAddLine(1 , 17, 1)
-gmshModelGeoAddLine(17, 16, 2)
-
-gmshModelGeoAddCircleArc(14,15,16, 3)
-gmshModelGeoAddLine(14,13, 4)
-gmshModelGeoAddLine(13,12, 5)
-gmshModelGeoAddLine(12,11, 6)
-gmshModelGeoAddLine(11,10, 7)
-gmshModelGeoAddCircleArc(8,9,10, 8)
-gmshModelGeoAddLine(8,7, 9)
-gmshModelGeoAddLine(7,6, 10)
-gmshModelGeoAddLine(6,5, 11)
-gmshModelGeoAddCircleArc(3,4,5, 12)
-gmshModelGeoAddLine(3,2, 13)
-gmshModelGeoAddLine(2,1, 14)
-gmshModelGeoAddLine(18,19, 15)
-gmshModelGeoAddCircleArc(21,20,24, 16)
-gmshModelGeoAddCircleArc(24,20,19, 17)
-gmshModelGeoAddCircleArc(18,23,25, 18)
-gmshModelGeoAddCircleArc(25,23,22, 19)
-gmshModelGeoAddLine(21,22, 20)
-
-gmshModelGeoAddLineLoop([17,-15,18,19,-20,16], 21)
-gmshModelGeoAddPlaneSurface([21], 22)
-gmshModelGeoAddLineLoop([11,-12,13,14,1,2,-3,4,5,6,7,-8,9,10], 23)
+gmsh.modelGeoAddPoint( 0, h1+h3+h4+R2, 0, Lc2, 24)
+gmsh.modelGeoAddPoint( 0, h1+h3-R2,    0, Lc2, 25)
+
+gmsh.modelGeoAddLine(1 , 17, 1)
+gmsh.modelGeoAddLine(17, 16, 2)
+
+gmsh.modelGeoAddCircleArc(14,15,16, 3)
+gmsh.modelGeoAddLine(14,13, 4)
+gmsh.modelGeoAddLine(13,12, 5)
+gmsh.modelGeoAddLine(12,11, 6)
+gmsh.modelGeoAddLine(11,10, 7)
+gmsh.modelGeoAddCircleArc(8,9,10, 8)
+gmsh.modelGeoAddLine(8,7, 9)
+gmsh.modelGeoAddLine(7,6, 10)
+gmsh.modelGeoAddLine(6,5, 11)
+gmsh.modelGeoAddCircleArc(3,4,5, 12)
+gmsh.modelGeoAddLine(3,2, 13)
+gmsh.modelGeoAddLine(2,1, 14)
+gmsh.modelGeoAddLine(18,19, 15)
+gmsh.modelGeoAddCircleArc(21,20,24, 16)
+gmsh.modelGeoAddCircleArc(24,20,19, 17)
+gmsh.modelGeoAddCircleArc(18,23,25, 18)
+gmsh.modelGeoAddCircleArc(25,23,22, 19)
+gmsh.modelGeoAddLine(21,22, 20)
+
+gmsh.modelGeoAddLineLoop([17,-15,18,19,-20,16], 21)
+gmsh.modelGeoAddPlaneSurface([21], 22)
+gmsh.modelGeoAddLineLoop([11,-12,13,14,1,2,-3,4,5,6,7,-8,9,10], 23)
 
 # A surface with one hole is specified using 2 line loops:
-gmshModelGeoAddPlaneSurface([23,21], 24)
+gmsh.modelGeoAddPlaneSurface([23,21], 24)
 
 # FIXME: this will be implemented through the gmshView API
 #  View "comments" {
@@ -89,10 +89,10 @@ gmshModelGeoAddPlaneSurface([23,21], 24)
 #    T2(350, -7, 0){ "file://image.png@20x0" };
 # };
 
-gmshModelGeoSynchronize()
+gmsh.modelGeoSynchronize()
 
-gmshModelMesh(2)
+gmsh.modelMeshGenerate(2)
 
-gmshExport("t4.msh")
+gmsh.write("t4.msh")
 
-gmshFinalize()
+gmsh.finalize()
diff --git a/demos/api/t5.cpp b/demos/api/t5.cpp
index fb07865d46..3b8110e634 100644
--- a/demos/api/t5.cpp
+++ b/demos/api/t5.cpp
@@ -3,123 +3,125 @@
 #include <gmsh.h>
 #include <cstdio>
 
+using namespace gmsh;
+
 void cheeseHole(double x, double y, double z, double r, double lc,
                 std::vector<int> &shells, std::vector<int> &volumes)
 {
   // When the tag is not specified, a new one is automatically provided
-  int p1 = gmshModelGeoAddPoint(x,  y,  z,  lc);
-  int p2 = gmshModelGeoAddPoint(x+r,y,  z,   lc);
-  int p3 = gmshModelGeoAddPoint(x,  y+r,z,   lc);
-  int p4 = gmshModelGeoAddPoint(x,  y,  z+r, lc);
-  int p5 = gmshModelGeoAddPoint(x-r,y,  z,   lc);
-  int p6 = gmshModelGeoAddPoint(x,  y-r,z,   lc);
-  int p7 = gmshModelGeoAddPoint(x,  y,  z-r, lc);
-
-  int c1 = gmshModelGeoAddCircleArc(p2,p1,p7);
-  int c2 = gmshModelGeoAddCircleArc(p7,p1,p5);
-  int c3 = gmshModelGeoAddCircleArc(p5,p1,p4);
-  int c4 = gmshModelGeoAddCircleArc(p4,p1,p2);
-  int c5 = gmshModelGeoAddCircleArc(p2,p1,p3);
-  int c6 = gmshModelGeoAddCircleArc(p3,p1,p5);
-  int c7 = gmshModelGeoAddCircleArc(p5,p1,p6);
-  int c8 = gmshModelGeoAddCircleArc(p6,p1,p2);
-  int c9 = gmshModelGeoAddCircleArc(p7,p1,p3);
-  int c10 = gmshModelGeoAddCircleArc(p3,p1,p4);
-  int c11 = gmshModelGeoAddCircleArc(p4,p1,p6);
-  int c12 = gmshModelGeoAddCircleArc(p6,p1,p7);
-
-  int l1 = gmshModelGeoAddLineLoop({c5,c10,c4});
-  int l2 = gmshModelGeoAddLineLoop({c9,-c5,c1});
-  int l3 = gmshModelGeoAddLineLoop({c12,-c8,-c1});
-  int l4 = gmshModelGeoAddLineLoop({c8,-c4,c11});
-  int l5 = gmshModelGeoAddLineLoop({-c10,c6,c3});
-  int l6 = gmshModelGeoAddLineLoop({-c11,-c3,c7});
-  int l7 = gmshModelGeoAddLineLoop({-c2,-c7,-c12});
-  int l8 = gmshModelGeoAddLineLoop({-c6,-c9,c2});
-
-  int s1 = gmshModelGeoAddSurfaceFilling({l1});
-  int s2 = gmshModelGeoAddSurfaceFilling({l2});
-  int s3 = gmshModelGeoAddSurfaceFilling({l3});
-  int s4 = gmshModelGeoAddSurfaceFilling({l4});
-  int s5 = gmshModelGeoAddSurfaceFilling({l5});
-  int s6 = gmshModelGeoAddSurfaceFilling({l6});
-  int s7 = gmshModelGeoAddSurfaceFilling({l7});
-  int s8 = gmshModelGeoAddSurfaceFilling({l8});
-
-  int sl = gmshModelGeoAddSurfaceLoop({s1, s2, s3, s4, s5, s6, s7, s8});
-  int v = gmshModelGeoAddVolume({sl});
+  int p1 = model::geo::addPoint(x,  y,  z,  lc);
+  int p2 = model::geo::addPoint(x+r,y,  z,   lc);
+  int p3 = model::geo::addPoint(x,  y+r,z,   lc);
+  int p4 = model::geo::addPoint(x,  y,  z+r, lc);
+  int p5 = model::geo::addPoint(x-r,y,  z,   lc);
+  int p6 = model::geo::addPoint(x,  y-r,z,   lc);
+  int p7 = model::geo::addPoint(x,  y,  z-r, lc);
+
+  int c1 = model::geo::addCircleArc(p2,p1,p7);
+  int c2 = model::geo::addCircleArc(p7,p1,p5);
+  int c3 = model::geo::addCircleArc(p5,p1,p4);
+  int c4 = model::geo::addCircleArc(p4,p1,p2);
+  int c5 = model::geo::addCircleArc(p2,p1,p3);
+  int c6 = model::geo::addCircleArc(p3,p1,p5);
+  int c7 = model::geo::addCircleArc(p5,p1,p6);
+  int c8 = model::geo::addCircleArc(p6,p1,p2);
+  int c9 = model::geo::addCircleArc(p7,p1,p3);
+  int c10 = model::geo::addCircleArc(p3,p1,p4);
+  int c11 = model::geo::addCircleArc(p4,p1,p6);
+  int c12 = model::geo::addCircleArc(p6,p1,p7);
+
+  int l1 = model::geo::addLineLoop({c5,c10,c4});
+  int l2 = model::geo::addLineLoop({c9,-c5,c1});
+  int l3 = model::geo::addLineLoop({c12,-c8,-c1});
+  int l4 = model::geo::addLineLoop({c8,-c4,c11});
+  int l5 = model::geo::addLineLoop({-c10,c6,c3});
+  int l6 = model::geo::addLineLoop({-c11,-c3,c7});
+  int l7 = model::geo::addLineLoop({-c2,-c7,-c12});
+  int l8 = model::geo::addLineLoop({-c6,-c9,c2});
+
+  int s1 = model::geo::addSurfaceFilling({l1});
+  int s2 = model::geo::addSurfaceFilling({l2});
+  int s3 = model::geo::addSurfaceFilling({l3});
+  int s4 = model::geo::addSurfaceFilling({l4});
+  int s5 = model::geo::addSurfaceFilling({l5});
+  int s6 = model::geo::addSurfaceFilling({l6});
+  int s7 = model::geo::addSurfaceFilling({l7});
+  int s8 = model::geo::addSurfaceFilling({l8});
+
+  int sl = model::geo::addSurfaceLoop({s1, s2, s3, s4, s5, s6, s7, s8});
+  int v = model::geo::addVolume({sl});
   shells.push_back(sl);
   volumes.push_back(v);
 }
 
 int main(int argc, char **argv)
 {
-  gmshInitialize();
-  gmshOptionSetNumber("General.Terminal", 1);
+  initialize();
+  option::setNumber("General.Terminal", 1);
 
   double lcar1 = .1;
   double lcar2 = .0005;
   double lcar3 = .055;
 
-  gmshModelGeoAddPoint(0.5,0.5,0.5, lcar2, 1);
-  gmshModelGeoAddPoint(0.5,0.5,0, lcar1, 2);
-  gmshModelGeoAddPoint(0,0.5,0.5, lcar1, 3);
-  gmshModelGeoAddPoint(0,0,0.5, lcar1, 4);
-  gmshModelGeoAddPoint(0.5,0,0.5, lcar1, 5);
-  gmshModelGeoAddPoint(0.5,0,0, lcar1, 6);
-  gmshModelGeoAddPoint(0,0.5,0, lcar1, 7);
-  gmshModelGeoAddPoint(0,1,0, lcar1, 8);
-  gmshModelGeoAddPoint(1,1,0, lcar1, 9);
-  gmshModelGeoAddPoint(0,0,1, lcar1, 10);
-  gmshModelGeoAddPoint(0,1,1, lcar1, 11);
-  gmshModelGeoAddPoint(1,1,1, lcar1, 12);
-  gmshModelGeoAddPoint(1,0,1, lcar1, 13);
-  gmshModelGeoAddPoint(1,0,0, lcar1, 14);
-
-  gmshModelGeoAddLine(8,9, 1);
-  gmshModelGeoAddLine(9,12, 2);
-  gmshModelGeoAddLine(12,11, 3);
-  gmshModelGeoAddLine(11,8, 4);
-  gmshModelGeoAddLine(9,14, 5);
-  gmshModelGeoAddLine(14,13, 6);
-  gmshModelGeoAddLine(13,12, 7);
-  gmshModelGeoAddLine(11,10, 8);
-  gmshModelGeoAddLine(10,13, 9);
-  gmshModelGeoAddLine(10,4, 10);
-  gmshModelGeoAddLine(4,5, 11);
-  gmshModelGeoAddLine(5,6, 12);
-  gmshModelGeoAddLine(6,2, 13);
-  gmshModelGeoAddLine(2,1, 14);
-  gmshModelGeoAddLine(1,3, 15);
-  gmshModelGeoAddLine(3,7, 16);
-  gmshModelGeoAddLine(7,2, 17);
-  gmshModelGeoAddLine(3,4, 18);
-  gmshModelGeoAddLine(5,1, 19);
-  gmshModelGeoAddLine(7,8, 20);
-  gmshModelGeoAddLine(6,14, 21);
-
-  gmshModelGeoAddLineLoop({-11,-19,-15,-18}, 22);
-  gmshModelGeoAddPlaneSurface({22}, 23);
-  gmshModelGeoAddLineLoop({16,17,14,15}, 24);
-  gmshModelGeoAddPlaneSurface({24}, 25);
-  gmshModelGeoAddLineLoop({-17,20,1,5,-21,13}, 26);
-  gmshModelGeoAddPlaneSurface({26}, 27);
-  gmshModelGeoAddLineLoop({-4,-1,-2,-3}, 28);
-  gmshModelGeoAddPlaneSurface({28}, 29);
-  gmshModelGeoAddLineLoop({-7,2,-5,-6}, 30);
-  gmshModelGeoAddPlaneSurface({30}, 31);
-  gmshModelGeoAddLineLoop({6,-9,10,11,12,21}, 32);
-  gmshModelGeoAddPlaneSurface({32}, 33);
-  gmshModelGeoAddLineLoop({7,3,8,9}, 34);
-  gmshModelGeoAddPlaneSurface({34}, 35);
-  gmshModelGeoAddLineLoop({-10,18,-16,-20,4,-8}, 36);
-  gmshModelGeoAddPlaneSurface({36}, 37);
-  gmshModelGeoAddLineLoop({-14,-13,-12,19}, 38);
-  gmshModelGeoAddPlaneSurface({38}, 39);
+  model::geo::addPoint(0.5,0.5,0.5, lcar2, 1);
+  model::geo::addPoint(0.5,0.5,0, lcar1, 2);
+  model::geo::addPoint(0,0.5,0.5, lcar1, 3);
+  model::geo::addPoint(0,0,0.5, lcar1, 4);
+  model::geo::addPoint(0.5,0,0.5, lcar1, 5);
+  model::geo::addPoint(0.5,0,0, lcar1, 6);
+  model::geo::addPoint(0,0.5,0, lcar1, 7);
+  model::geo::addPoint(0,1,0, lcar1, 8);
+  model::geo::addPoint(1,1,0, lcar1, 9);
+  model::geo::addPoint(0,0,1, lcar1, 10);
+  model::geo::addPoint(0,1,1, lcar1, 11);
+  model::geo::addPoint(1,1,1, lcar1, 12);
+  model::geo::addPoint(1,0,1, lcar1, 13);
+  model::geo::addPoint(1,0,0, lcar1, 14);
+
+  model::geo::addLine(8,9, 1);
+  model::geo::addLine(9,12, 2);
+  model::geo::addLine(12,11, 3);
+  model::geo::addLine(11,8, 4);
+  model::geo::addLine(9,14, 5);
+  model::geo::addLine(14,13, 6);
+  model::geo::addLine(13,12, 7);
+  model::geo::addLine(11,10, 8);
+  model::geo::addLine(10,13, 9);
+  model::geo::addLine(10,4, 10);
+  model::geo::addLine(4,5, 11);
+  model::geo::addLine(5,6, 12);
+  model::geo::addLine(6,2, 13);
+  model::geo::addLine(2,1, 14);
+  model::geo::addLine(1,3, 15);
+  model::geo::addLine(3,7, 16);
+  model::geo::addLine(7,2, 17);
+  model::geo::addLine(3,4, 18);
+  model::geo::addLine(5,1, 19);
+  model::geo::addLine(7,8, 20);
+  model::geo::addLine(6,14, 21);
+
+  model::geo::addLineLoop({-11,-19,-15,-18}, 22);
+  model::geo::addPlaneSurface({22}, 23);
+  model::geo::addLineLoop({16,17,14,15}, 24);
+  model::geo::addPlaneSurface({24}, 25);
+  model::geo::addLineLoop({-17,20,1,5,-21,13}, 26);
+  model::geo::addPlaneSurface({26}, 27);
+  model::geo::addLineLoop({-4,-1,-2,-3}, 28);
+  model::geo::addPlaneSurface({28}, 29);
+  model::geo::addLineLoop({-7,2,-5,-6}, 30);
+  model::geo::addPlaneSurface({30}, 31);
+  model::geo::addLineLoop({6,-9,10,11,12,21}, 32);
+  model::geo::addPlaneSurface({32}, 33);
+  model::geo::addLineLoop({7,3,8,9}, 34);
+  model::geo::addPlaneSurface({34}, 35);
+  model::geo::addLineLoop({-10,18,-16,-20,4,-8}, 36);
+  model::geo::addPlaneSurface({36}, 37);
+  model::geo::addLineLoop({-14,-13,-12,19}, 38);
+  model::geo::addPlaneSurface({38}, 39);
 
   std::vector<int> shells, volumes;
 
-  int sl = gmshModelGeoAddSurfaceLoop({35,31,29,37,33,23,39,25,27});
+  int sl = model::geo::addSurfaceLoop({35,31,29,37,33,23,39,25,27});
   shells.push_back(sl);
 
   double x = 0, y = 0.75, z = 0, r = 0.09 ;
@@ -127,16 +129,16 @@ int main(int argc, char **argv)
     x += 0.166 ;
     z += 0.166 ;
     cheeseHole(x, y, z, r, lcar3, shells, volumes);
-    gmshModelAddPhysicalGroup(3, {volumes.back()}, t);
+    model::addPhysicalGroup(3, {volumes.back()}, t);
     std::printf("Hole %d (center = {%g,%g,%g}, radius = %g) has number %d!\n",
                 t, x, y, z, r, volumes.back());
   }
 
-  gmshModelGeoAddVolume(shells, 186);
+  model::geo::addVolume(shells, 186);
 
-  gmshModelAddPhysicalGroup(3, {186}, 10);
-  gmshModelGeoSynchronize();
-  gmshModelMesh(3);
-  gmshExport("t5.msh");
+  model::addPhysicalGroup(3, {186}, 10);
+  model::geo::synchronize();
+  model::mesh::generate(3);
+  write("t5.msh");
   return 0;
 }
diff --git a/demos/api/t5.py b/demos/api/t5.py
index 9f1a3e7039..7bf3f52165 100644
--- a/demos/api/t5.py
+++ b/demos/api/t5.py
@@ -1,111 +1,111 @@
 # This file reimplements gmsh/tutorial/t5.geo in Python.
 
-from gmsh import *
+import gmsh
 import math
 
-gmshInitialize()
-gmshOptionSetNumber("General.Terminal", 1)
+gmsh.initialize()
+gmsh.optionSetNumber("General.Terminal", 1)
 
-gmshModelCreate("t5")
+gmsh.modelAdd("t5")
 
 lcar1 = .1
 lcar2 = .0005
 lcar3 = .055
 
-gmshModelGeoAddPoint(0.5,0.5,0.5, lcar2, 1)
-gmshModelGeoAddPoint(0.5,0.5,0, lcar1, 2)
-gmshModelGeoAddPoint(0,0.5,0.5, lcar1, 3)
-gmshModelGeoAddPoint(0,0,0.5, lcar1, 4)
-gmshModelGeoAddPoint(0.5,0,0.5, lcar1, 5)
-gmshModelGeoAddPoint(0.5,0,0, lcar1, 6)
-gmshModelGeoAddPoint(0,0.5,0, lcar1, 7)
-gmshModelGeoAddPoint(0,1,0, lcar1, 8)
-gmshModelGeoAddPoint(1,1,0, lcar1, 9)
-gmshModelGeoAddPoint(0,0,1, lcar1, 10)
-gmshModelGeoAddPoint(0,1,1, lcar1, 11)
-gmshModelGeoAddPoint(1,1,1, lcar1, 12)
-gmshModelGeoAddPoint(1,0,1, lcar1, 13)
-gmshModelGeoAddPoint(1,0,0, lcar1, 14)
+gmsh.modelGeoAddPoint(0.5,0.5,0.5, lcar2, 1)
+gmsh.modelGeoAddPoint(0.5,0.5,0, lcar1, 2)
+gmsh.modelGeoAddPoint(0,0.5,0.5, lcar1, 3)
+gmsh.modelGeoAddPoint(0,0,0.5, lcar1, 4)
+gmsh.modelGeoAddPoint(0.5,0,0.5, lcar1, 5)
+gmsh.modelGeoAddPoint(0.5,0,0, lcar1, 6)
+gmsh.modelGeoAddPoint(0,0.5,0, lcar1, 7)
+gmsh.modelGeoAddPoint(0,1,0, lcar1, 8)
+gmsh.modelGeoAddPoint(1,1,0, lcar1, 9)
+gmsh.modelGeoAddPoint(0,0,1, lcar1, 10)
+gmsh.modelGeoAddPoint(0,1,1, lcar1, 11)
+gmsh.modelGeoAddPoint(1,1,1, lcar1, 12)
+gmsh.modelGeoAddPoint(1,0,1, lcar1, 13)
+gmsh.modelGeoAddPoint(1,0,0, lcar1, 14)
 
-gmshModelGeoAddLine(8,9, 1);   gmshModelGeoAddLine(9,12, 2)
-gmshModelGeoAddLine(12,11, 3); gmshModelGeoAddLine(11,8, 4)
-gmshModelGeoAddLine(9,14, 5);  gmshModelGeoAddLine(14,13, 6)
-gmshModelGeoAddLine(13,12, 7); gmshModelGeoAddLine(11,10, 8)
-gmshModelGeoAddLine(10,13, 9); gmshModelGeoAddLine(10,4, 10)
-gmshModelGeoAddLine(4,5, 11);  gmshModelGeoAddLine(5,6, 12)
-gmshModelGeoAddLine(6,2, 13);  gmshModelGeoAddLine(2,1, 14)
-gmshModelGeoAddLine(1,3, 15);  gmshModelGeoAddLine(3,7, 16)
-gmshModelGeoAddLine(7,2, 17);  gmshModelGeoAddLine(3,4, 18)
-gmshModelGeoAddLine(5,1, 19);  gmshModelGeoAddLine(7,8, 20)
-gmshModelGeoAddLine(6,14, 21); 
+gmsh.modelGeoAddLine(8,9, 1);   gmsh.modelGeoAddLine(9,12, 2)
+gmsh.modelGeoAddLine(12,11, 3); gmsh.modelGeoAddLine(11,8, 4)
+gmsh.modelGeoAddLine(9,14, 5);  gmsh.modelGeoAddLine(14,13, 6)
+gmsh.modelGeoAddLine(13,12, 7); gmsh.modelGeoAddLine(11,10, 8)
+gmsh.modelGeoAddLine(10,13, 9); gmsh.modelGeoAddLine(10,4, 10)
+gmsh.modelGeoAddLine(4,5, 11);  gmsh.modelGeoAddLine(5,6, 12)
+gmsh.modelGeoAddLine(6,2, 13);  gmsh.modelGeoAddLine(2,1, 14)
+gmsh.modelGeoAddLine(1,3, 15);  gmsh.modelGeoAddLine(3,7, 16)
+gmsh.modelGeoAddLine(7,2, 17);  gmsh.modelGeoAddLine(3,4, 18)
+gmsh.modelGeoAddLine(5,1, 19);  gmsh.modelGeoAddLine(7,8, 20)
+gmsh.modelGeoAddLine(6,14, 21); 
 
-gmshModelGeoAddLineLoop([-11,-19,-15,-18], 22)
-gmshModelGeoAddPlaneSurface([22], 23)
-gmshModelGeoAddLineLoop([16,17,14,15], 24)
-gmshModelGeoAddPlaneSurface([24], 25)
-gmshModelGeoAddLineLoop([-17,20,1,5,-21,13], 26)
-gmshModelGeoAddPlaneSurface([26], 27)
-gmshModelGeoAddLineLoop([-4,-1,-2,-3], 28)
-gmshModelGeoAddPlaneSurface([28], 29)
-gmshModelGeoAddLineLoop([-7,2,-5,-6], 30)
-gmshModelGeoAddPlaneSurface([30], 31)
-gmshModelGeoAddLineLoop([6,-9,10,11,12,21], 32)
-gmshModelGeoAddPlaneSurface([32], 33)
-gmshModelGeoAddLineLoop([7,3,8,9], 34)
-gmshModelGeoAddPlaneSurface([34], 35)
-gmshModelGeoAddLineLoop([-10,18,-16,-20,4,-8], 36)
-gmshModelGeoAddPlaneSurface([36], 37)
-gmshModelGeoAddLineLoop([-14,-13,-12,19], 38)
-gmshModelGeoAddPlaneSurface([38], 39)
+gmsh.modelGeoAddLineLoop([-11,-19,-15,-18], 22)
+gmsh.modelGeoAddPlaneSurface([22], 23)
+gmsh.modelGeoAddLineLoop([16,17,14,15], 24)
+gmsh.modelGeoAddPlaneSurface([24], 25)
+gmsh.modelGeoAddLineLoop([-17,20,1,5,-21,13], 26)
+gmsh.modelGeoAddPlaneSurface([26], 27)
+gmsh.modelGeoAddLineLoop([-4,-1,-2,-3], 28)
+gmsh.modelGeoAddPlaneSurface([28], 29)
+gmsh.modelGeoAddLineLoop([-7,2,-5,-6], 30)
+gmsh.modelGeoAddPlaneSurface([30], 31)
+gmsh.modelGeoAddLineLoop([6,-9,10,11,12,21], 32)
+gmsh.modelGeoAddPlaneSurface([32], 33)
+gmsh.modelGeoAddLineLoop([7,3,8,9], 34)
+gmsh.modelGeoAddPlaneSurface([34], 35)
+gmsh.modelGeoAddLineLoop([-10,18,-16,-20,4,-8], 36)
+gmsh.modelGeoAddPlaneSurface([36], 37)
+gmsh.modelGeoAddLineLoop([-14,-13,-12,19], 38)
+gmsh.modelGeoAddPlaneSurface([38], 39)
 
-shells = IntVector(); volumes = IntVector()
+shells = gmsh.IntVector(); volumes = gmsh.IntVector()
 
 # When the tag is not specified, a new one is automatically provided
-sl = gmshModelGeoAddSurfaceLoop([35,31,29,37,33,23,39,25,27])
+sl = gmsh.modelGeoAddSurfaceLoop([35,31,29,37,33,23,39,25,27])
 shells.push_back(sl)
 
 def cheeseHole(x, y, z, r, lc, shells, volumes):
-    p1 = gmshModelGeoAddPoint(x,  y,  z,   lc)
-    p2 = gmshModelGeoAddPoint(x+r,y,  z,   lc)
-    p3 = gmshModelGeoAddPoint(x,  y+r,z,   lc)
-    p4 = gmshModelGeoAddPoint(x,  y,  z+r, lc)
-    p5 = gmshModelGeoAddPoint(x-r,y,  z,   lc)
-    p6 = gmshModelGeoAddPoint(x,  y-r,z,   lc)
-    p7 = gmshModelGeoAddPoint(x,  y,  z-r, lc)
+    p1 = gmsh.modelGeoAddPoint(x,  y,  z,   lc)
+    p2 = gmsh.modelGeoAddPoint(x+r,y,  z,   lc)
+    p3 = gmsh.modelGeoAddPoint(x,  y+r,z,   lc)
+    p4 = gmsh.modelGeoAddPoint(x,  y,  z+r, lc)
+    p5 = gmsh.modelGeoAddPoint(x-r,y,  z,   lc)
+    p6 = gmsh.modelGeoAddPoint(x,  y-r,z,   lc)
+    p7 = gmsh.modelGeoAddPoint(x,  y,  z-r, lc)
 
-    c1 = gmshModelGeoAddCircleArc(p2,p1,p7)
-    c2 = gmshModelGeoAddCircleArc(p7,p1,p5)
-    c3 = gmshModelGeoAddCircleArc(p5,p1,p4)
-    c4 = gmshModelGeoAddCircleArc(p4,p1,p2)
-    c5 = gmshModelGeoAddCircleArc(p2,p1,p3)
-    c6 = gmshModelGeoAddCircleArc(p3,p1,p5)
-    c7 = gmshModelGeoAddCircleArc(p5,p1,p6)
-    c8 = gmshModelGeoAddCircleArc(p6,p1,p2)
-    c9 = gmshModelGeoAddCircleArc(p7,p1,p3)
-    c10 = gmshModelGeoAddCircleArc(p3,p1,p4)
-    c11 = gmshModelGeoAddCircleArc(p4,p1,p6)
-    c12 = gmshModelGeoAddCircleArc(p6,p1,p7)
+    c1 = gmsh.modelGeoAddCircleArc(p2,p1,p7)
+    c2 = gmsh.modelGeoAddCircleArc(p7,p1,p5)
+    c3 = gmsh.modelGeoAddCircleArc(p5,p1,p4)
+    c4 = gmsh.modelGeoAddCircleArc(p4,p1,p2)
+    c5 = gmsh.modelGeoAddCircleArc(p2,p1,p3)
+    c6 = gmsh.modelGeoAddCircleArc(p3,p1,p5)
+    c7 = gmsh.modelGeoAddCircleArc(p5,p1,p6)
+    c8 = gmsh.modelGeoAddCircleArc(p6,p1,p2)
+    c9 = gmsh.modelGeoAddCircleArc(p7,p1,p3)
+    c10 = gmsh.modelGeoAddCircleArc(p3,p1,p4)
+    c11 = gmsh.modelGeoAddCircleArc(p4,p1,p6)
+    c12 = gmsh.modelGeoAddCircleArc(p6,p1,p7)
     
-    l1 = gmshModelGeoAddLineLoop([c5,c10,c4])
-    l2 = gmshModelGeoAddLineLoop([c9,-c5,c1])
-    l3 = gmshModelGeoAddLineLoop([c12,-c8,-c1])
-    l4 = gmshModelGeoAddLineLoop([c8,-c4,c11])
-    l5 = gmshModelGeoAddLineLoop([-c10,c6,c3])
-    l6 = gmshModelGeoAddLineLoop([-c11,-c3,c7])
-    l7 = gmshModelGeoAddLineLoop([-c2,-c7,-c12])
-    l8 = gmshModelGeoAddLineLoop([-c6,-c9,c2])
+    l1 = gmsh.modelGeoAddLineLoop([c5,c10,c4])
+    l2 = gmsh.modelGeoAddLineLoop([c9,-c5,c1])
+    l3 = gmsh.modelGeoAddLineLoop([c12,-c8,-c1])
+    l4 = gmsh.modelGeoAddLineLoop([c8,-c4,c11])
+    l5 = gmsh.modelGeoAddLineLoop([-c10,c6,c3])
+    l6 = gmsh.modelGeoAddLineLoop([-c11,-c3,c7])
+    l7 = gmsh.modelGeoAddLineLoop([-c2,-c7,-c12])
+    l8 = gmsh.modelGeoAddLineLoop([-c6,-c9,c2])
     
-    s1 = gmshModelGeoAddSurfaceFilling([l1])
-    s2 = gmshModelGeoAddSurfaceFilling([l2])
-    s3 = gmshModelGeoAddSurfaceFilling([l3])
-    s4 = gmshModelGeoAddSurfaceFilling([l4])
-    s5 = gmshModelGeoAddSurfaceFilling([l5])
-    s6 = gmshModelGeoAddSurfaceFilling([l6])
-    s7 = gmshModelGeoAddSurfaceFilling([l7])
-    s8 = gmshModelGeoAddSurfaceFilling([l8])
+    s1 = gmsh.modelGeoAddSurfaceFilling([l1])
+    s2 = gmsh.modelGeoAddSurfaceFilling([l2])
+    s3 = gmsh.modelGeoAddSurfaceFilling([l3])
+    s4 = gmsh.modelGeoAddSurfaceFilling([l4])
+    s5 = gmsh.modelGeoAddSurfaceFilling([l5])
+    s6 = gmsh.modelGeoAddSurfaceFilling([l6])
+    s7 = gmsh.modelGeoAddSurfaceFilling([l7])
+    s8 = gmsh.modelGeoAddSurfaceFilling([l8])
     
-    sl = gmshModelGeoAddSurfaceLoop([s1, s2, s3, s4, s5, s6, s7, s8])
-    v = gmshModelGeoAddVolume([sl])
+    sl = gmsh.modelGeoAddSurfaceLoop([s1, s2, s3, s4, s5, s6, s7, s8])
+    v = gmsh.modelGeoAddVolume([sl])
     shells.append(sl)
     volumes.append(v)
 
@@ -114,13 +114,13 @@ for t in range(1, 6):
     x += 0.166 ;
     z += 0.166 ;
     cheeseHole(x, y, z, r, lcar3, shells, volumes);
-    gmshModelAddPhysicalGroup(3, [volumes.back()], t);
+    gmsh.modelAddPhysicalGroup(3, [volumes.back()], t);
 
-gmshModelGeoAddVolume(shells, 186);
+gmsh.modelGeoAddVolume(shells, 186);
       
-gmshModelAddPhysicalGroup(3, [186], 10);
-gmshModelGeoSynchronize()
-gmshModelMesh(3)
-gmshExport("t5.msh")
+gmsh.modelAddPhysicalGroup(3, [186], 10);
+gmsh.modelGeoSynchronize()
+gmsh.modelMeshGenerate(3)
+gmsh.write("t5.msh")
 
-gmshFinalize()
+gmsh.finalize()
diff --git a/demos/api/t6.cpp b/demos/api/t6.cpp
index 579d6997eb..9f9f846da5 100644
--- a/demos/api/t6.cpp
+++ b/demos/api/t6.cpp
@@ -2,92 +2,95 @@
 
 #include <gmsh.h>
 
+using namespace gmsh;
+
 int main(int argc, char **argv)
 {
-  gmshInitialize();
-  gmshOptionSetNumber("General.Terminal", 1);
-
-  gmshModelCreate("t2");
+  initialize();
+  option::setNumber("General.Terminal", 1);
 
+  model::add("t2");
 
   // Copied from t1.cpp...
   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);
-  gmshModelGeoAddLine(1, 2, 1);
-  gmshModelGeoAddLine(3, 2, 2);
-  gmshModelGeoAddLine(3, 4, 3);
-  gmshModelGeoAddLine(4, 1, 4);
-  gmshModelGeoAddLineLoop({4, 1, -2, 3}, 1);
-  gmshModelGeoAddPlaneSurface({1}, 1);
-  gmshModelAddPhysicalGroup(0, {1, 2}, 1);
-  gmshModelAddPhysicalGroup(1, {1, 2}, 2);
-  gmshModelAddPhysicalGroup(2, {1}, 6);
-  gmshModelSetPhysicalName(2, 6, "My surface");
+  model::geo::addPoint(0, 0, 0, lc, 1);
+  model::geo::addPoint(.1, 0,  0, lc, 2);
+  model::geo::addPoint(.1, .3, 0, lc, 3);
+  model::geo::addPoint(0,  .3, 0, lc, 4);
+  model::geo::addLine(1, 2, 1);
+  model::geo::addLine(3, 2, 2);
+  model::geo::addLine(3, 4, 3);
+  model::geo::addLine(4, 1, 4);
+  model::geo::addLineLoop({4, 1, -2, 3}, 1);
+  model::geo::addPlaneSurface({1}, 1);
+  model::addPhysicalGroup(0, {1, 2}, 1);
+  model::addPhysicalGroup(1, {1, 2}, 2);
+  model::addPhysicalGroup(2, {1}, 6);
+  model::setPhysicalName(2, 6, "My surface");
   // ...end of copy
 
   // Delete surface 1 and left boundary (line 4)
-  gmshModelGeoRemove({{2,1}, {1,4}});
+  model::geo::remove({{2,1}, {1,4}});
 
   // Replace left boundary with 3 new lines
-  int p1 = gmshModelGeoAddPoint(-0.05, 0.05, 0, lc);
-  int p2 = gmshModelGeoAddPoint(-0.05, 0.1, 0, lc);
-  int l1 = gmshModelGeoAddLine(1, p1);
-  int l2 = gmshModelGeoAddLine(p1, p2);
-  int l3 = gmshModelGeoAddLine(p2, 4);
+  int p1 = model::geo::addPoint(-0.05, 0.05, 0, lc);
+  int p2 = model::geo::addPoint(-0.05, 0.1, 0, lc);
+  int l1 = model::geo::addLine(1, p1);
+  int l2 = model::geo::addLine(p1, p2);
+  int l3 = model::geo::addLine(p2, 4);
 
   // Recreate surface
-  gmshModelGeoAddLineLoop({2, -1, l1, l2, l3, -3}, 2);
-  gmshModelGeoAddPlaneSurface({-2}, 1);
+  model::geo::addLineLoop({2, -1, l1, l2, l3, -3}, 2);
+  model::geo::addPlaneSurface({-2}, 1);
 
   // Put 20 points with a refinement toward the extremities on curve 2
-  gmshModelGeoSetTransfiniteLine(2, 20, "Bump", 0.05);
+  model::geo::mesh::setTransfiniteLine(2, 20, "Bump", 0.05);
 
   // Put 20 points total on combination of curves l1, l2 and l3 (beware that the
   // points p1 and p2 are shared by the curves, so we do not create 6 + 6 + 10 =
   // 22 points, but 20!)
-  gmshModelGeoSetTransfiniteLine(l1, 6);
-  gmshModelGeoSetTransfiniteLine(l2, 6);
-  gmshModelGeoSetTransfiniteLine(l3, 10);
+  model::geo::mesh::setTransfiniteLine(l1, 6);
+  model::geo::mesh::setTransfiniteLine(l2, 6);
+  model::geo::mesh::setTransfiniteLine(l3, 10);
 
   // Put 30 points following a geometric progression on curve 1 (reversed) and
   // on curve 3
-  gmshModelGeoSetTransfiniteLine(1, 30, "Progression", -1.2);
-  gmshModelGeoSetTransfiniteLine(3, 30, "Progression", 1.2);
+  model::geo::mesh::setTransfiniteLine(1, 30, "Progression", -1.2);
+  model::geo::mesh::setTransfiniteLine(3, 30, "Progression", 1.2);
 
   // Define the Surface as transfinite, by specifying the four corners of the
   // transfinite interpolation
-  gmshModelGeoSetTransfiniteSurface(1, "Left", {1,2,3,4});
+  model::geo::mesh::setTransfiniteSurface(1, "Left", {1,2,3,4});
 
   // Recombine the triangles into quads
-  gmshModelGeoSetRecombine(2, 1);
+  model::geo::mesh::setRecombine(2, 1);
 
   // Apply an elliptic smoother to the grid
-  gmshOptionSetNumber("Mesh.Smoothing", 100);
-  gmshModelAddPhysicalGroup(2, {1}, 1);
+  option::setNumber("Mesh.Smoothing", 100);
+  model::addPhysicalGroup(2, {1}, 1);
 
   // When the surface has only 3 or 4 control points, the transfinite constraint
   // can be applied automatically (without specifying the corners explictly).
-  gmshModelGeoAddPoint(0.2, 0.2, 0, 1.0, 7);
-  gmshModelGeoAddPoint(0.2, 0.1, 0, 1.0, 8);
-  gmshModelGeoAddPoint(0, 0.3, 0, 1.0, 9);
-  gmshModelGeoAddPoint(0.25, 0.2, 0, 1.0, 10);
-  gmshModelGeoAddPoint(0.3, 0.1, 0, 1.0, 11);
-  gmshModelGeoAddLine(8, 11, 10);
-  gmshModelGeoAddLine(11, 10, 11);
-  gmshModelGeoAddLine(10, 7, 12);
-  gmshModelGeoAddLine(7, 8, 13);
-  gmshModelGeoAddLineLoop({13, 10, 11, 12}, 14);
-  gmshModelGeoAddPlaneSurface({14}, 15);
+  model::geo::addPoint(0.2, 0.2, 0, 1.0, 7);
+  model::geo::addPoint(0.2, 0.1, 0, 1.0, 8);
+  model::geo::addPoint(0, 0.3, 0, 1.0, 9);
+  model::geo::addPoint(0.25, 0.2, 0, 1.0, 10);
+  model::geo::addPoint(0.3, 0.1, 0, 1.0, 11);
+  model::geo::addLine(8, 11, 10);
+  model::geo::addLine(11, 10, 11);
+  model::geo::addLine(10, 7, 12);
+  model::geo::addLine(7, 8, 13);
+  model::geo::addLineLoop({13, 10, 11, 12}, 14);
+  model::geo::addPlaneSurface({14}, 15);
   for(int i = 10; i <= 13; i++)
-    gmshModelGeoSetTransfiniteLine(i, 10);
-  gmshModelGeoSetTransfiniteSurface(15);
-  gmshModelAddPhysicalGroup(2, {15}, 2);
+    model::geo::mesh::setTransfiniteLine(i, 10);
+  model::geo::mesh::setTransfiniteSurface(15);
+
+  model::addPhysicalGroup(2, {15}, 2);
 
-  gmshModelMesh(2);
-  gmshExport("t6.msh");
-  gmshFinalize();
+  model::geo::synchronize();
+  model::mesh::generate(2);
+  write("t6.msh");
+  finalize();
   return 0;
 }
diff --git a/demos/api/t6.py b/demos/api/t6.py
index 30a5bf14cd..2c83df0bb8 100644
--- a/demos/api/t6.py
+++ b/demos/api/t6.py
@@ -1,89 +1,89 @@
 # This file reimplements gmsh/tutorial/t6.geo in Python.
 
-from gmsh import *
+import gmsh
 import math
 
-gmshInitialize()
-gmshOptionSetNumber("General.Terminal", 1)
+gmsh.initialize()
+gmsh.optionSetNumber("General.Terminal", 1)
 
-gmshModelCreate("t6")
+gmsh.modelAdd("t6")
 
 # Copied from t1.py...
 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)
-gmshModelGeoAddLine(1, 2, 1)
-gmshModelGeoAddLine(3, 2, 2)
-gmshModelGeoAddLine(3, 4, 3)
-gmshModelGeoAddLine(4, 1, 4)
-gmshModelGeoAddLineLoop([4, 1, -2, 3], 1)
-gmshModelGeoAddPlaneSurface([1], 1)
-gmshModelAddPhysicalGroup(0, [1, 2], 1)
-gmshModelAddPhysicalGroup(1, [1, 2], 2)
-gmshModelAddPhysicalGroup(2, [1], 6)
-gmshModelSetPhysicalName(2, 6, "My surface")
+gmsh.modelGeoAddPoint(0, 0, 0, lc, 1)
+gmsh.modelGeoAddPoint(.1, 0,  0, lc, 2)
+gmsh.modelGeoAddPoint(.1, .3, 0, lc, 3)
+gmsh.modelGeoAddPoint(0, .3, 0, lc, 4)
+gmsh.modelGeoAddLine(1, 2, 1)
+gmsh.modelGeoAddLine(3, 2, 2)
+gmsh.modelGeoAddLine(3, 4, 3)
+gmsh.modelGeoAddLine(4, 1, 4)
+gmsh.modelGeoAddLineLoop([4, 1, -2, 3], 1)
+gmsh.modelGeoAddPlaneSurface([1], 1)
+gmsh.modelAddPhysicalGroup(0, [1, 2], 1)
+gmsh.modelAddPhysicalGroup(1, [1, 2], 2)
+gmsh.modelAddPhysicalGroup(2, [1], 6)
+gmsh.modelSetPhysicalName(2, 6, "My surface")
 # ...end of copy
 
 # Delete surface 1 and left boundary (line 4)
-gmshModelGeoRemove([[2,1], [1,4]])
+gmsh.modelGeoRemove([[2,1], [1,4]])
 
 # Replace left boundary with 3 new lines
-p1 = gmshModelGeoAddPoint(-0.05, 0.05, 0, lc)
-p2 = gmshModelGeoAddPoint(-0.05, 0.1, 0, lc)
-l1 = gmshModelGeoAddLine(1, p1)
-l2 = gmshModelGeoAddLine(p1, p2)
-l3 = gmshModelGeoAddLine(p2, 4)
+p1 = gmsh.modelGeoAddPoint(-0.05, 0.05, 0, lc)
+p2 = gmsh.modelGeoAddPoint(-0.05, 0.1, 0, lc)
+l1 = gmsh.modelGeoAddLine(1, p1)
+l2 = gmsh.modelGeoAddLine(p1, p2)
+l3 = gmsh.modelGeoAddLine(p2, 4)
 
 # Recreate surface
-gmshModelGeoAddLineLoop([2, -1, l1, l2, l3, -3], 2)
-gmshModelGeoAddPlaneSurface([-2], 1)
+gmsh.modelGeoAddLineLoop([2, -1, l1, l2, l3, -3], 2)
+gmsh.modelGeoAddPlaneSurface([-2], 1)
 
 # Put 20 points with a refinement toward the extremities on curve 2
-gmshModelGeoSetTransfiniteLine(2, 20, "Bump", 0.05)
+gmsh.modelGeoMeshSetTransfiniteLine(2, 20, "Bump", 0.05)
 
 # Put 20 points total on combination of curves l1, l2 and l3 (beware that the
 # points p1 and p2 are shared by the curves, so we do not create 6 + 6 + 10 = 22
 # points, but 20!)
-gmshModelGeoSetTransfiniteLine(l1, 6)
-gmshModelGeoSetTransfiniteLine(l2, 6)
-gmshModelGeoSetTransfiniteLine(l3, 10)
+gmsh.modelGeoMeshSetTransfiniteLine(l1, 6)
+gmsh.modelGeoMeshSetTransfiniteLine(l2, 6)
+gmsh.modelGeoMeshSetTransfiniteLine(l3, 10)
 
 # Put 30 points following a geometric progression on curve 1 (reversed) and on
 # curve 3
-gmshModelGeoSetTransfiniteLine(1, 30, "Progression", -1.2)
-gmshModelGeoSetTransfiniteLine(3, 30, "Progression", 1.2)
+gmsh.modelGeoMeshSetTransfiniteLine(1, 30, "Progression", -1.2)
+gmsh.modelGeoMeshSetTransfiniteLine(3, 30, "Progression", 1.2)
 
 # Define the Surface as transfinite, by specifying the four corners of the
 # transfinite interpolation
-gmshModelGeoSetTransfiniteSurface(1, "Left", [1,2,3,4])
+gmsh.modelGeoMeshSetTransfiniteSurface(1, "Left", [1,2,3,4])
 
 # Recombine the triangles into quads
-gmshModelGeoSetRecombine(2, 1)
+gmsh.modelGeoMeshSetRecombine(2, 1)
 
 # Apply an elliptic smoother to the grid
-gmshOptionSetNumber("Mesh.Smoothing", 100)
-gmshModelAddPhysicalGroup(2, [1], 1)
+gmsh.optionSetNumber("Mesh.Smoothing", 100)
+gmsh.modelAddPhysicalGroup(2, [1], 1)
 
 # When the surface has only 3 or 4 control points, the transfinite constraint
 # can be applied automatically (without specifying the corners explictly).
-gmshModelGeoAddPoint(0.2, 0.2, 0, 1.0, 7)
-gmshModelGeoAddPoint(0.2, 0.1, 0, 1.0, 8)
-gmshModelGeoAddPoint(0, 0.3, 0, 1.0, 9)
-gmshModelGeoAddPoint(0.25, 0.2, 0, 1.0, 10)
-gmshModelGeoAddPoint(0.3, 0.1, 0, 1.0, 11)
-gmshModelGeoAddLine(8, 11, 10)
-gmshModelGeoAddLine(11, 10, 11)
-gmshModelGeoAddLine(10, 7, 12)
-gmshModelGeoAddLine(7, 8, 13)
-gmshModelGeoAddLineLoop([13, 10, 11, 12], 14)
-gmshModelGeoAddPlaneSurface([14], 15)
+gmsh.modelGeoAddPoint(0.2, 0.2, 0, 1.0, 7)
+gmsh.modelGeoAddPoint(0.2, 0.1, 0, 1.0, 8)
+gmsh.modelGeoAddPoint(0, 0.3, 0, 1.0, 9)
+gmsh.modelGeoAddPoint(0.25, 0.2, 0, 1.0, 10)
+gmsh.modelGeoAddPoint(0.3, 0.1, 0, 1.0, 11)
+gmsh.modelGeoAddLine(8, 11, 10)
+gmsh.modelGeoAddLine(11, 10, 11)
+gmsh.modelGeoAddLine(10, 7, 12)
+gmsh.modelGeoAddLine(7, 8, 13)
+gmsh.modelGeoAddLineLoop([13, 10, 11, 12], 14)
+gmsh.modelGeoAddPlaneSurface([14], 15)
 for i in range(10,14):
-    gmshModelGeoSetTransfiniteLine(i, 10)
-gmshModelGeoSetTransfiniteSurface(15)
-gmshModelAddPhysicalGroup(2, [15], 2)
+    gmsh.modelGeoMeshSetTransfiniteLine(i, 10)
+gmsh.modelGeoMeshSetTransfiniteSurface(15)
+gmsh.modelAddPhysicalGroup(2, [15], 2)
 
-gmshModelMesh(2)
-gmshExport("t6.msh")
-gmshFinalize()
+gmsh.modelMeshGenerate(2)
+gmsh.write("t6.msh")
+gmsh.finalize()
diff --git a/demos/api/view.cpp b/demos/api/view.cpp
index 4260bf17ac..dad52aa137 100644
--- a/demos/api/view.cpp
+++ b/demos/api/view.cpp
@@ -2,36 +2,35 @@
 
 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 new post-processing view
-  int t = gmshViewCreate("some data");
+  int t = gmsh::view::add("some data");
 
   // add 10 steps of model-based data, on the nodes of the mesh
   for(int step = 0; step < 10; step++)
-    gmshViewAddModelData(t, "test", "NodeData",
-                         {1, 2, 3, 4}, // tags of nodes
-                         {{10.},{10.},{12.+step},{13.+step}}, // data, per node
-                         step);
+    gmsh::view::addModelData(t, "test", "NodeData",
+                             {1, 2, 3, 4}, // tags of nodes
+                             {{10.},{10.},{12.+step},{13.+step}}, // data, per node
+                             step);
 
-  gmshViewExport(t, "data.msh");
+  gmsh::view::write(t, "data.msh");
 
-  gmshFinalize();
+  gmsh::finalize();
   return 0;
 }
 
diff --git a/demos/api/view.py b/demos/api/view.py
index e97da80ad5..55bb11784f 100644
--- a/demos/api/view.py
+++ b/demos/api/view.py
@@ -1,34 +1,34 @@
 #!/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 new post-processing view
-t = gmshViewCreate("some data")
+t = gmsh.viewAdd("some data")
 
 # add 10 steps of model-based data, on the nodes of the mesh
 for step in range(0, 10):
-    gmshViewAddModelData(t, "test", "NodeData",
+    gmsh.viewAddModelData(t, "test", "NodeData",
                          [1, 2, 3, 4], # tags of nodes
                          [[10.],[10.],[12.+step],[13.+step]], # data, per node
                          step)
     
-gmshViewExport(t, "data.msh")
+gmsh.viewWrite(t, "data.msh")
     
-gmshFinalize()
+gmsh.finalize()
diff --git a/demos/api/viewlist.cpp b/demos/api/viewlist.cpp
index 1cede58c22..eabc7d1fa0 100644
--- a/demos/api/viewlist.cpp
+++ b/demos/api/viewlist.cpp
@@ -2,8 +2,8 @@
 
 int main(int argc, char **argv)
 {
-  gmshInitialize();
-  gmshOptionSetNumber("General.Terminal", 1);
+  gmsh::initialize();
+  gmsh::option::setNumber("General.Terminal", 1);
 
   std::vector<double> tri1 = {0., 1., 1.,
                               0., 0., 1.,
@@ -21,15 +21,15 @@ int main(int argc, char **argv)
     tri2.push_back(13. + step);
   }
 
-  int t = gmshViewCreate("some data");
+  int t = gmsh::view::add("some data");
   std::vector<double> data;
   data.insert(data.end(), tri1.begin(), tri1.end());
   data.insert(data.end(), tri2.begin(), tri2.end());
 
-  gmshViewAddListData(t, "ST", 2, data);
+  gmsh::view::addListData(t, "ST", 2, data);
 
-  gmshViewExport(t, "data.pos");
+  gmsh::view::write(t, "data.pos");
 
-  gmshFinalize();
+  gmsh::finalize();
   return 0;
 }
diff --git a/demos/api/viewlist.py b/demos/api/viewlist.py
index 95d607393f..a2532de287 100644
--- a/demos/api/viewlist.py
+++ b/demos/api/viewlist.py
@@ -1,10 +1,10 @@
 #!/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)
 
 tri1 = [0., 1., 1.,
         0., 0., 1.,
@@ -17,10 +17,10 @@ for step in range(0, 10):
     tri1.append(10.); tri1.append(10.); tri1.append(12. + step)
     tri2.append(10.); tri2.append(12. + step); tri2.append(13. + step)
 
-t = gmshViewCreate("some data")
+t = gmsh.viewAdd("some data")
 
-gmshViewAddListData(t, "ST", 2, tri1 + tri2)
+gmsh.viewAddListData(t, "ST", 2, tri1 + tri2)
 
-gmshViewExport(t, "data.pos")
+gmsh.viewWrite(t, "data.pos")
 
-gmshFinalize()
+gmsh.finalize()
-- 
GitLab