diff --git a/CMakeLists.txt b/CMakeLists.txt index 43021af00d3f70ec5fd91b8d6285fced0641af14..38be60d0cf392f44126b98e75f27959a8aed232d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ opt(BUILD_LIB "Enable 'lib' target for building static Gmsh library" OFF) opt(BUILD_SHARED "Enable 'shared' target for building shared Gmsh library" OFF) opt(BUILD_DYNAMIC "Enable dynamic Gmsh executable (linked with shared lib)" OFF) opt(BUILD_ANDROID "Enable Android NDK library target (experimental)" OFF) -opt(BUILD_IOS "Enable iOS (ARM) library target (experimental)" OFF) +opt(BUILD_IOS "Enable iOS library target (experimental)" OFF) opt(CGNS "Enable CGNS mesh export (experimental)" OFF) opt(CAIRO "Enable Cairo to render fonts (experimental)" ${DEFAULT}) opt(CHACO "Enable Chaco mesh partitioner (alternative to Metis)" ${DEFAULT}) diff --git a/Common/gmsh.cpp b/Common/gmsh.cpp index d5f59ca54b0e785dc9d7596bfc72b2513b96d8c8..565ffb9eb0034a262396e86d0b0d22bc135e04d6 100644 --- a/Common/gmsh.cpp +++ b/Common/gmsh.cpp @@ -9,7 +9,7 @@ #include "GModelIO_GEO.h" #include "GModelIO_OCC.h" -// Gmsh +// gmsh int gmshInitialize(int argc, char **argv) { @@ -41,7 +41,7 @@ int gmshClear() return !GmshClearProject(); } -// GmshOption +// gmshOption static void splitOptionName(const std::string &fullName, std::string &category, std::string &name, int &index) @@ -94,7 +94,7 @@ int gmshOptionGetString(const std::string &name, std::string &value) return !GmshGetOption(c, n, value, i); } -// GmshModel +// gmshModel int gmshModelCreate(const std::string &name) { @@ -122,6 +122,123 @@ int gmshModelDestroy() return 1; } +int gmshModelGetElementaryTags(int dim, std::vector<int> &tags) +{ + std::vector<GEntity*> entities; + GModel::current()->getEntities(entities, dim); + tags.clear(); + for(unsigned int i = 0; i < entities.size(); i++) + tags.push_back(entities[i]->tag()); + return 0; +} + +int gmshModelGetPhysicalTags(int dim, std::vector<int> &tags) +{ + std::map<int, std::vector<GEntity*> > groups; + GModel::current()->getPhysicalGroups(dim, groups); + tags.clear(); + for(std::map<int, std::vector<GEntity*> >::iterator it = groups.begin(); + it != groups.end(); it++) + tags.push_back(it->first); + return 0; +} + +int gmshModelAddPhysicalGroup(int dim, int tag, const std::vector<int> &tags) +{ + bool r = GModel::current()->getGEOInternals()->modifyPhysicalGroup + (dim, tag, 0, tags); + if(r){ + GModel::current()->getGEOInternals()->synchronize(GModel::current()); + return 0; + } + return 1; +} + +int gmshModelGetElementaryTagsForPhysicalGroup(int dim, int tag, + std::vector<int> &tags) +{ + std::map<int, std::vector<GEntity*> > groups; + GModel::current()->getPhysicalGroups(dim, groups); + std::map<int, std::vector<GEntity*> >::iterator it = groups.find(tag); + tags.clear(); + if(it != groups.end()){ + for(unsigned j = 0; j < it->second.size(); j++) + tags.push_back(it->second[j]->tag()); + } + return 0; +} + +int gmshModelSetPhysicalName(int dim, int tag, const std::string &name) +{ + GModel::current()->setPhysicalName(name, dim, tag); + return 0; +} + +int gmshModelGetPhysicalName(int dim, int tag, std::string &name) +{ + name = GModel::current()->getPhysicalName(dim, tag); + return 0; +} + +int gmshModelGetVertexCoordinates(int tag, double &x, double &y, double &z) +{ + GVertex *gv = GModel::current()->getVertexByTag(tag); + if(gv){ + x = gv->x(); + y = gv->y(); + z = gv->z(); + return 0; + } + return 1; +} + +int gmshModelGetBoundaryTags(const std::vector<std::pair<int, int> > &inDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool combined, bool oriented, bool recursive) +{ + bool r = GModel::current()->getBoundaryTags(inDimTags, outDimTags, combined, + oriented, recursive); + if(r) return 0; + return 1; +} + +int gmshModelGetElementaryTagsInBoundingBox(int dim, + double x1, double y1, double z1, + double x2, double y2, double z2, + std::vector<int> &tags) +{ + SBoundingBox3d box(x1, y1, z1, x2, y2, z2); + std::vector<GEntity*> entities; + GModel::current()->getEntitiesInBox(entities, box, dim); + tags.clear(); + for(unsigned int i = 0; i < entities.size(); i++) + tags.push_back(entities[i]->tag()); + return 0; +} + +int gmshModelGetBoundingBox(int dim, int tag, double &x1, double &y1, double &z1, + double &x2, double &y2, double &z2) +{ + GEntity *ge = GModel::current()->getEntityByTag(dim, tag); + if(!ge) return 1; + SBoundingBox3d box = ge->bounds(); + if(box.empty()) return 2; + x1 = box.min().x(); + y1 = box.min().y(); + z1 = box.min().z(); + x2 = box.max().x(); + y2 = box.max().y(); + z2 = box.max().z(); + return 0; +} + +int gmshModelRemove(const std::vector<std::pair<int, int> > &dimTags, + bool recursive) +{ + GModel::current()->remove(dimTags, recursive); + return 0; +} + int gmshModelMesh(int dim) { GModel *m = GModel::current(); @@ -131,3 +248,65 @@ int gmshModelMesh(int dim) } return 1; } + +int gmshModelGetMeshVertices(int dim, int tag, std::vector<int> &vertexTags, + std::vector<double> &coords, + std::vector<double> ¶metricCoords) +{ + return 0; +} + +int gmshModelGetMeshElements(int dim, int tag, std::vector<int> &types, + std::vector<std::vector<int> > &elementTags, + std::vector<std::vector<int> > &vertexTags) +{ + return 0; +} + +int gmshModelSetMeshSize(int dim, int tag, double size) +{ + return 0; +} + +int gmshModelSetCompound(int dim, const std::vector<int> &tags) +{ + return 0; +} + +int gmshModelSetTransfiniteLine(int tag, int nPoints, int type, double coef) +{ + return 0; +} + +int gmshModelSetTransfiniteSurface(int tag, int arrangement, + const std::vector<int> &cornerTags) +{ + return 0; +} + +int gmshModelSetTransfiniteVolume(int tag, const std::vector<int> &cornerTags) +{ + return 0; +} + +int gmshModelSetRecombine(int dim, int tag, double angle) +{ + return 0; +} + +int gmshModelSetSmoothing(int tag, int val) +{ + return 0; +} + +int gmshModelSetReverseMesh(int dim, int tag) +{ + return 0; +} + +int gmshModelAddEmbeddedVertex(int tag, int inDim, int inTag) +{ + return 0; +} + +// gmshModelGeo diff --git a/Common/gmsh.h b/Common/gmsh.h index 6ff1bda955a43755a74c289874db0faef5dc367f..b0c660d8421eedb8f87ff12c937f239f6d515a6c 100644 --- a/Common/gmsh.h +++ b/Common/gmsh.h @@ -28,7 +28,7 @@ #define GMSH_API int #endif -// Gmsh +// gmsh GMSH_API gmshInitialize(int argc, char **argv); GMSH_API gmshFinalize(); GMSH_API gmshOpen(const std::string &fileName); @@ -36,35 +36,44 @@ GMSH_API gmshMerge(const std::string &fileName); GMSH_API gmshExport(const std::string &fileName); GMSH_API gmshClear(); -// GmshOption +// gmshOption GMSH_API gmshOptionSetNumber(const std::string &name, double value); GMSH_API gmshOptionGetNumber(const std::string &name, double &value); GMSH_API gmshOptionSetString(const std::string &name, const std::string &value); GMSH_API gmshOptionGetString(const std::string &name, std::string &value); -// GmshModel +// gmshModel GMSH_API gmshModelCreate(const std::string &name); GMSH_API gmshModelSetCurrent(const std::string &name); GMSH_API gmshModelDestroy(); -GMSH_API gmshModelMesh(int dim); GMSH_API gmshModelGetElementaryTags(int dim, std::vector<int> &tags); GMSH_API gmshModelGetPhysicalTags(int dim, std::vector<int> &tags); GMSH_API gmshModelAddPhysicalGroup(int dim, int tag, const std::vector<int> &tags); -GMSH_API gmshModelGetPhysicalGroup(int dim, int tag, std::vector<int> &tags); +GMSH_API gmshModelGetElementaryTagsForPhysicalGroup(int dim, int tag, + std::vector<int> &tags); GMSH_API gmshModelSetPhysicalName(int dim, int tag, const std::string &name); GMSH_API gmshModelGetPhysicalName(int dim, int tag, std::string &name); -GMSH_API gmshModelGetVertexCoordinates(int tag, double &x, std::vector<double> &coord); +GMSH_API gmshModelGetVertexCoordinates(int tag, std::vector<double> &coord); +GMSH_API gmshModelGetBoundaryTags(const std::vector<std::pair<int, int> > &inDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool combined, bool oriented, bool recursive); +GMSH_API gmshModelGetElementaryTagsInBoundingBox(int dim, + double x1, double y1, double z1, + double x2, double y2, double z2, + std::vector<int> &tags); +GMSH_API gmshModelGetBoundingBox(int dim, int tag, double &x1, double &y1, double &z1, + double &x2, double &y2, double &z2); +GMSH_API gmshModelRemove(const std::vector<std::pair<int, int> > &dimTags, + bool recursive=false); +GMSH_API gmshModelMesh(int dim); GMSH_API gmshModelGetMeshVertices(int dim, int tag, std::vector<int> &vertexTags, std::vector<double> &coords, std::vector<double> ¶metricCoords); GMSH_API gmshModelGetMeshElements(int dim, int tag, std::vector<int> &types, std::vector<std::vector<int> > &elementTags, std::vector<std::vector<int> > &vertexTags); -GMSH_API gmshModelGetBoundaryTags(const std::vector<std::pair<int, int> > &inDimTags, - std::vector<std::pair<int, int> > &outDimTags, - bool combined, bool oriented, bool recursive); GMSH_API gmshModelSetMeshSize(int dim, int tag, double size); -GMSH_API gmshModelSetCompoundMesh(int dim, const std::vector<int> &tags); +GMSH_API gmshModelSetCompound(int dim, const std::vector<int> &tags); GMSH_API gmshModelSetTransfiniteLine(int tag, int nPoints, int type, double coef); GMSH_API gmshModelSetTransfiniteSurface(int tag, int arrangement, const std::vector<int> &cornerTags); @@ -73,10 +82,8 @@ 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 gmshModelRemove(const std::vector<std::pair<int, int> > &dimTags, - bool recursive=false); -// GmshModelGeo +// gmshModelGeo GMSH_API gmshModelGeoAddVertex(int &tag, double x, double y, double z, double lc); GMSH_API gmshModelGeoAddLine(int &tag, int startTag, int endTag); GMSH_API gmshModelGeoAddCircleArc(int &tag, int startTag, int centerTag, int endTag, @@ -129,7 +136,7 @@ GMSH_API gmshModelGeoRemove(const std::vector<std::pair<int, int> > &dimTags, GMSH_API gmshModelGeoRemoveAllDuplicates(); GMSH_API gmshModelGeoSynchronize(); -// GmshModelOCC +// gmshModelOCC GMSH_API gmshModelOCCAddVertex(int &tag, double x, double y, double z, double lc); GMSH_API gmshModelOCCAddLine(int &tag, int startVertexTag, int endVertexTag); GMSH_API gmshModelOCCExtrude(const std::vector<std::pair<int, int> > &inDimTag, @@ -138,10 +145,10 @@ GMSH_API gmshModelOCCExtrude(const std::vector<std::pair<int, int> > &inDimTag, GMSH_API gmshModelOCCRemoveAllDuplicates(); GMSH_API gmshModelOCCSynchronize(); -// GmshSolver +// gmshSolver -// GmshPost +// gmshPost -// GmshPlugin +// gmshPlugin #endif diff --git a/utils/api_demos/CMakeLists.txt b/utils/api_demos/CMakeLists.txt index eab5b73d8b576786b4954945919c252080741c7f..478c8da82f1c2adde1416db3ce95bbff9f789545 100644 --- a/utils/api_demos/CMakeLists.txt +++ b/utils/api_demos/CMakeLists.txt @@ -1,64 +1,21 @@ -cmake_minimum_required(VERSION 2.6 FATAL_ERROR) +cmake_minimum_required(VERSION 2.8 FATAL_ERROR) -# if CMAKE_BUILD_TYPE is specified use it; otherwise set the default -# build type to "RelWithDebInfo" ("-O2 -g" with gcc) prior to calling -# project() -if(DEFINED CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose build type") -else(DEFINED CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose build type") -endif(DEFINED CMAKE_BUILD_TYPE) +find_library(GMSH_LIB gmsh) +if(NOT GMSH_LIB) + message(FATAL_ERROR "Could not find libgmsh") +endif(NOT GMSH_LIB) -project(api_demos CXX) +find_path(GMSH_INC gmsh.h) +if(NOT GMSH_INC) + message(FATAL_ERROR "Could not find gmsh.h") +endif(NOT GMSH_INC) -add_subdirectory(../.. "${CMAKE_CURRENT_BINARY_DIR}/gmsh") +if(GMSH_LIB MATCHES ".a") + find_library(BLAS_LIB blas) + find_library(LAPACK_LIB lapack) +endif(GMSH_LIB MATCHES ".a") -include_directories(../../Common ../../Numeric ../../Geo ../../Mesh - ../../Solver ../../Post ../../Plugin ../../Graphics - ../../contrib/ANN/include ../../contrib/MathEx ../../contrib/kbipack - ../../contrib/DiscreteIntegration - ${GMSH_EXTERNAL_INCLUDE_DIRS} - ${CMAKE_CURRENT_BINARY_DIR}/gmsh/Common) - -if(APPLE) - set(glut "-framework GLUT") -else(APPLE) - set(glut "glut") -endif(APPLE) - -add_executable(mainVertexArray mainVertexArray.cpp) -target_link_libraries(mainVertexArray shared) - -#add_executable(mainAntTweakBar mainAntTweakBar.cpp) -#target_link_libraries(mainAntTweakBar shared AntTweakBar ${glut}) - -add_executable(mainCartesian mainCartesian.cpp) -target_link_libraries(mainCartesian shared) - -add_executable(mainElasticity mainElasticity.cpp) -target_link_libraries(mainElasticity shared) - -add_executable(mainGlut mainGlut.cpp) -target_link_libraries(mainGlut shared ${glut}) - -add_executable(mainHomology mainHomology.cpp) -target_link_libraries(mainHomology shared) - -add_executable(mainOcc mainOcc.cpp) -target_link_libraries(mainOcc shared) - -add_executable(mainPost mainPost.cpp) -target_link_libraries(mainPost shared) +include_directories(${GMSH_INC}) add_executable(mainSimple mainSimple.cpp) -target_link_libraries(mainSimple shared) - -add_executable(mainReadMesh mainReadMesh.cpp) -target_link_libraries(mainReadMesh shared) - -add_executable(mainGeoFactory mainGeoFactory.cpp) -target_link_libraries(mainGeoFactory shared) - -add_executable(mainRemesh mainRemesh.cpp) -target_link_libraries(mainRemesh shared) - +target_link_libraries(mainSimple ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB}) diff --git a/utils/api_demos/mainSimple.cpp b/utils/api_demos/mainSimple.cpp index e7b875286640274551c305ff643b7dd763a858dd..46a4947658294e3bbb50beef16eb6dadde972c96 100644 --- a/utils/api_demos/mainSimple.cpp +++ b/utils/api_demos/mainSimple.cpp @@ -1,23 +1,13 @@ -#include <stdio.h> #include <gmsh.h> int main(int argc, char **argv) { gmshInitialize(argc, argv); - gmshSetOption("Mesh", "Algorithm", 5.); - GModel *m = new GModel(); - m->readGEO("../../tutorial/t5.geo"); - //GmshMergeFile("../../tutorial/t5.geo"); // will also set the bbox - m->mesh(3); - for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it){ - GRegion *r = *it; - printf("volume %d contains %d elements:\n", r->tag(), r->getNumMeshElements()); - for(unsigned int i = 0; i < r->getNumMeshElements(); i++) - printf(" %d", r->getMeshElement(i)->getNum()); - printf("\n"); - } - m->writeMSH("test.msh"); - m->writeUNV("test.unv"); - delete m; - GmshFinalize(); + gmshOptionSetNumber("General.Terminal", 1); + gmshOptionSetNumber("Mesh.Algorithm", 5); + gmshOpen("../../tutorial/t5.geo"); + gmshModelMesh(3); + gmshExport("test.msh"); + gmshExport("test.unv"); + gmshFinalize(); }