Skip to content
Snippets Groups Projects
Commit a4c9bec7 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

comment + fix finalize

parent afb335cb
No related branches found
No related tags found
No related merge requests found
...@@ -59,7 +59,12 @@ int gmshInitialize(int argc, char **argv) ...@@ -59,7 +59,12 @@ int gmshInitialize(int argc, char **argv)
int gmshFinalize() int gmshFinalize()
{ {
if(!isInitialized()) return -1; if(!isInitialized()) return -1;
return !GmshFinalize(); if(GmshFinalize()){
_initialized = 0;
return 0;
}
Msg::Error("Something went wrong when finalizing Gmsh");
return 1;
} }
int gmshOpen(const std::string &fileName) int gmshOpen(const std::string &fileName)
......
// This reimplements gmsh/tutorial/t1.geo in C++. For all the elementary // This reimplements gmsh/tutorial/t1.geo in C++. For all the elementary
// explanations about the general philosphy of entities in Gmsh, see the // explanations about the general philosphy of entities in Gmsh, see the
// comments in the .geo file. Comments here will focus on the specifics of the // comments in the .geo file. Comments here will focus on the specifics of the
...@@ -64,12 +63,17 @@ int main(int argc, char **argv) ...@@ -64,12 +63,17 @@ int main(int argc, char **argv)
// entity. // entity.
gmshModelSetPhysicalName(2, 6, "My surface"); gmshModelSetPhysicalName(2, 6, "My surface");
// Before it can be meshed, the internal CAD representation (here in the
// built-in "Geo" CAD kernel) must be synchronized with the Gmsh model, which
// will create the relevant Gmsh data structure to represent the full topology
// of the model. This is achieved by the gmshModelGeoSynchronize() API call.
gmshModelGeoSynchronize(); gmshModelGeoSynchronize();
// We can then generate a 2D mesh, and save it to disk.
gmshModelMesh(2); gmshModelMesh(2);
gmshExport("t1.msh"); gmshExport("t1.msh");
// Gmsh finalize should be called at the end.
gmshFinalize(); gmshFinalize();
return 0; return 0;
} }
#include <gmsh.h> // This reimplements gmsh/tutorial/t2.geo in C++. Comments focus on the new API
// functions used compared to t1.cpp.
// this reimplements gmsh/tutorial/t2.geo #include <gmsh.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
...@@ -9,7 +10,7 @@ int main(int argc, char **argv) ...@@ -9,7 +10,7 @@ int main(int argc, char **argv)
gmshModelCreate("t2"); gmshModelCreate("t2");
// copy/paste from t1.cpp // Copy/paste from t1.cpp
double lc = 1e-2; double lc = 1e-2;
int o; int o;
gmshModelGeoAddPoint(1, 0, 0, 0, o, lc); gmshModelGeoAddPoint(1, 0, 0, 0, o, lc);
...@@ -28,12 +29,20 @@ int main(int argc, char **argv) ...@@ -28,12 +29,20 @@ int main(int argc, char **argv)
gmshModelAddPhysicalGroup(1, 2, {1, 2}); gmshModelAddPhysicalGroup(1, 2, {1, 2});
gmshModelAddPhysicalGroup(2, 6, {1}); gmshModelAddPhysicalGroup(2, 6, {1});
gmshModelSetPhysicalName(2, 6, "My surface"); gmshModelSetPhysicalName(2, 6, "My surface");
// end copy/paste // End copy/paste
gmshModelGeoAddPoint(5, 0, .4, 0, o, lc); gmshModelGeoAddPoint(5, 0, .4, 0, o, lc);
gmshModelGeoAddLine(5, 4, 5, o); gmshModelGeoAddLine(5, 4, 5, o);
// Geometrical transformations take a std::vector of std::pair<int, int> as
// first argument, which contains the list of entities, represented by
// (dimension,tag) pairs. Here we translate point 3 (dimension = 0, tag = 3),
// by dx=-0.05, dy=0, dz=0.
gmshModelGeoTranslate({{0, 3}}, -0.05, 0, 0); gmshModelGeoTranslate({{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
// returns another vector of (dim,tag) pairs.
std::vector<std::pair<int, int> > ov, ov2; std::vector<std::pair<int, int> > ov, ov2;
gmshModelGeoCopy({{0, 3}}, ov); gmshModelGeoCopy({{0, 3}}, ov);
gmshModelGeoTranslate(ov, 0, 0.1, 0); gmshModelGeoTranslate(ov, 0, 0.1, 0);
...@@ -73,11 +82,17 @@ int main(int argc, char **argv) ...@@ -73,11 +82,17 @@ int main(int argc, char **argv)
gmshModelGeoAddLineLoop(126, {115, 116, 117, 114}, o); gmshModelGeoAddLineLoop(126, {115, 116, 117, 114}, o);
gmshModelGeoAddPlaneSurface(127, {126}, o); gmshModelGeoAddPlaneSurface(127, {126}, o);
// The API to create surface loops ("shells") and volumes is similar to the
// one use to create line loops and surfaces.
gmshModelGeoAddSurfaceLoop(128, {127, 119, 121, 123, 125, 11}, o); gmshModelGeoAddSurfaceLoop(128, {127, 119, 121, 123, 125, 11}, o);
gmshModelGeoAddVolume(129, {128}, o); gmshModelGeoAddVolume(129, {128}, o);
// 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.
gmshModelGeoExtrude({ov[1]}, 0, 0, 0.12, ov2); gmshModelGeoExtrude({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 entities
gmshModelGeoSetMeshSize({{0,103}, {0,105}, {0,109}, {0,102}, {0,28}, gmshModelGeoSetMeshSize({{0,103}, {0,105}, {0,109}, {0,102}, {0,28},
{0, 24}, {0,6}, {0,5}}, lc * 3); {0, 24}, {0,6}, {0,5}}, lc * 3);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment