diff --git a/Common/gmsh.cpp b/Common/gmsh.cpp index 474cb55a088db0951755d97739853aae1fe4763f..f1edd293bd754f1db5c1f7eb4d448509896ad0bb 100644 --- a/Common/gmsh.cpp +++ b/Common/gmsh.cpp @@ -341,37 +341,128 @@ int gmshModelSetMeshSize(int dim, int tag, double size) int gmshModelSetTransfiniteLine(int tag, int nPoints, int type, double coef) { - return 0; + GEdge *ge = GModel::current()->getEdgeByTag(tag); + if(ge){ + ge->meshAttributes.method = MESH_TRANSFINITE; + ge->meshAttributes.nbPointsTransfinite = nPoints; + ge->meshAttributes.typeTransfinite = type; + ge->meshAttributes.coeffTransfinite = coef; + return 0; + } + return 1; } int gmshModelSetTransfiniteSurface(int tag, int arrangement, const std::vector<int> &cornerTags) { - return 0; + GFace *gf = GModel::current()->getFaceByTag(tag); + if(gf){ + gf->meshAttributes.method = MESH_TRANSFINITE; + gf->meshAttributes.transfiniteArrangement = arrangement; + if(cornerTags.empty() || cornerTags.size() == 3 || cornerTags.size() == 4){ + for(unsigned int j = 0; j < cornerTags.size(); j++){ + GVertex *gv = GModel::current()->getVertexByTag(cornerTags[j]); + if(gv) + gf->meshAttributes.corners.push_back(gv); + } + } + return 0; + } + return 1; } int gmshModelSetTransfiniteVolume(int tag, const std::vector<int> &cornerTags) { - return 0; + GRegion *gr = GModel::current()->getRegionByTag(tag); + if(gr){ + gr->meshAttributes.method = MESH_TRANSFINITE; + if(cornerTags.empty() || cornerTags.size() == 6 || cornerTags.size() == 8){ + for(unsigned int i = 0; i < cornerTags.size(); i++){ + GVertex *gv = GModel::current()->getVertexByTag(cornerTags[i]); + if(gv) + gr->meshAttributes.corners.push_back(gv); + } + } + return 0; + } + return 1; } int gmshModelSetRecombine(int dim, int tag, double angle) { - return 0; + GFace *gf = GModel::current()->getFaceByTag(tag); + if(gf){ + gf->meshAttributes.recombine = 1; + gf->meshAttributes.recombineAngle = angle; + return 0; + } + return 1; } int gmshModelSetSmoothing(int tag, int val) { - return 0; + GFace *gf = GModel::current()->getFaceByTag(tag); + if(gf){ + gf->meshAttributes.transfiniteSmoothing = val; + return 0; + } + return 1; } int gmshModelSetReverseMesh(int dim, int tag) { + if(dim == 1){ + GEdge *ge = GModel::current()->getEdgeByTag(tag); + if(ge) ge->meshAttributes.reverseMesh = 1; + } + else if(dim == 2){ + GFace *gf = GModel::current()->getFaceByTag(tag); + if(gf) gf->meshAttributes.reverseMesh = 1; + } return 0; } -int gmshModelAddEmbeddedVertex(int tag, int inDim, int inTag) -{ +int gmshModelAddEmbedded(int dim, const std::vector<int> &tags, int toDim, int toTag) +{ + if(toDim == 2){ + GFace *gf = GModel::current()->getFaceByTag(toTag); + if(gf){ + for(unsigned int i = 0; i < tags.size(); i++){ + if(dim == 0){ + GVertex *gv = GModel::current()->getVertexByTag(tags[i]); + if(gv) + gf->addEmbeddedVertex(gv); + } + else if(dim == 1){ + GEdge *ge = GModel::current()->getEdgeByTag(tags[i]); + if(ge) + gf->addEmbeddedEdge(ge); + } + } + } + } + else if(toDim == 3){ + GRegion *gr = GModel::current()->getRegionByTag(toTag); + if(gr){ + for(unsigned int i = 0; i < tags.size(); i++){ + if(dim == 0){ + GVertex *gv = GModel::current()->getVertexByTag(tags[i]); + if(gv) + gr->addEmbeddedVertex(gv); + } + else if(dim == 1){ + GEdge *ge = GModel::current()->getEdgeByTag(tags[i]); + if(ge) + gr->addEmbeddedEdge(ge); + } + else if(dim == 2){ + GFace *gf = GModel::current()->getFaceByTag(tags[i]); + if(gf) + gr->addEmbeddedFace(gf); + } + } + } + } return 0; } diff --git a/Common/gmsh.h b/Common/gmsh.h index 976651a9e8cd0891511000fed0df7cae29452c01..5fd0bba0f8b894cf46d6eacd8d1acfa082cbd805 100644 --- a/Common/gmsh.h +++ b/Common/gmsh.h @@ -78,7 +78,8 @@ GMSH_API gmshModelSetTransfiniteVolume(int tag, const std::vector<int> &cornerTa GMSH_API gmshModelSetRecombine(int dim, int tag, double angle); GMSH_API gmshModelSetSmoothing(int tag, int val); GMSH_API gmshModelSetReverseMesh(int dim, int tag); -GMSH_API gmshModelAddEmbeddedVertex(int tag, int inDim, int inTag); +GMSH_API gmshModelAddEmbedded(int dim, const std::vector<int> &tags, + int toDim, int toTag); // gmshModelGeo GMSH_API gmshModelGeoAddVertex(int &tag, double x, double y, double z, double lc); diff --git a/utils/api_demos/CMakeLists.txt b/utils/api_demos/CMakeLists.txt index 2341f6722393efcbf33c79a2259087ef84212bcb..dc5c58756d7b303a7fa650ae64465e40e40d3479 100644 --- a/utils/api_demos/CMakeLists.txt +++ b/utils/api_demos/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR) +# TODO: Gmsh will should create a cmake file when installing the lib, so all the +# external dependencies can be obtained automatically + find_library(GMSH_LIB gmsh) if(NOT GMSH_LIB) message(FATAL_ERROR "Could not find libgmsh") @@ -17,5 +20,8 @@ endif(GMSH_LIB MATCHES ".a") include_directories(${GMSH_INC}) -add_executable(t0 t0.cpp) -target_link_libraries(t0 ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB}) +add_executable(basic basic.cpp) +target_link_libraries(basic ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB}) + +add_executable(basic2 basic2.cpp) +target_link_libraries(basic2 ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB}) diff --git a/utils/api_demos/basic.cpp b/utils/api_demos/basic.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a25096fa248fa7d3f99ac12443b7473eeefe2612 --- /dev/null +++ b/utils/api_demos/basic.cpp @@ -0,0 +1,19 @@ +#include <iostream> +#include <gmsh.h> + +int main(int argc, char **argv) +{ + if(argc < 2){ + std::cout << "Usage: " << argv[0] << " file.geo [options]" << std::endl; + return 1; + } + + gmshInitialize(); + gmshOptionSetNumber("General.Terminal", 1); + gmshOpen(argv[1]); + gmshModelMesh(3); + gmshExport("test.msh"); + gmshFinalize(); + + return 0; +} diff --git a/utils/api_demos/t0.cpp b/utils/api_demos/basic2.cpp similarity index 79% rename from utils/api_demos/t0.cpp rename to utils/api_demos/basic2.cpp index 33c99384a96c3198d310584810887ba11bf6a64f..6b068c895e3bc02419173465ca7ac24c5f6a308a 100644 --- a/utils/api_demos/t0.cpp +++ b/utils/api_demos/basic2.cpp @@ -4,26 +4,33 @@ int main(int argc, char **argv) { if(argc < 2){ - std::cout << "Usage: " << argv[0] << " file.geo [options]\n"; + std::cout << "Usage: " << argv[0] << " file.geo [options]" << std::endl; return 1; } + gmshInitialize(); gmshOptionSetNumber("General.Terminal", 1); - gmshOptionSetNumber("Mesh.Algorithm", 5); gmshOpen(argv[1]); gmshModelMesh(3); + // get all elementary entities in the model std::vector<std::pair<int, int> > entities; gmshModelGetEntities(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; int dim = entities[i].first, tag = entities[i].second; gmshModelGetMeshVertices(dim, tag, vertexTags, vertexCoords); + + // 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); + // report some statistics int numElem = 0; for(unsigned int i = 0; i < elemTags.size(); i++) numElem += elemTags[i].size(); @@ -32,8 +39,6 @@ int main(int argc, char **argv) << dim << "," << tag << ")\n"; } - gmshExport("test.msh"); - gmshExport("test.unv"); gmshFinalize(); return 0; }