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

api

parent c6fd3a60
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -40,7 +40,7 @@ opt(BUILD_LIB "Enable 'lib' target for building static Gmsh library" OFF) ...@@ -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_SHARED "Enable 'shared' target for building shared Gmsh library" OFF)
opt(BUILD_DYNAMIC "Enable dynamic Gmsh executable (linked with shared lib)" 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_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(CGNS "Enable CGNS mesh export (experimental)" OFF)
opt(CAIRO "Enable Cairo to render fonts (experimental)" ${DEFAULT}) opt(CAIRO "Enable Cairo to render fonts (experimental)" ${DEFAULT})
opt(CHACO "Enable Chaco mesh partitioner (alternative to Metis)" ${DEFAULT}) opt(CHACO "Enable Chaco mesh partitioner (alternative to Metis)" ${DEFAULT})
... ...
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "GModelIO_GEO.h" #include "GModelIO_GEO.h"
#include "GModelIO_OCC.h" #include "GModelIO_OCC.h"
// Gmsh // gmsh
int gmshInitialize(int argc, char **argv) int gmshInitialize(int argc, char **argv)
{ {
...@@ -41,7 +41,7 @@ int gmshClear() ...@@ -41,7 +41,7 @@ int gmshClear()
return !GmshClearProject(); return !GmshClearProject();
} }
// GmshOption // gmshOption
static void splitOptionName(const std::string &fullName, std::string &category, static void splitOptionName(const std::string &fullName, std::string &category,
std::string &name, int &index) std::string &name, int &index)
...@@ -94,7 +94,7 @@ int gmshOptionGetString(const std::string &name, std::string &value) ...@@ -94,7 +94,7 @@ int gmshOptionGetString(const std::string &name, std::string &value)
return !GmshGetOption(c, n, value, i); return !GmshGetOption(c, n, value, i);
} }
// GmshModel // gmshModel
int gmshModelCreate(const std::string &name) int gmshModelCreate(const std::string &name)
{ {
...@@ -122,6 +122,123 @@ int gmshModelDestroy() ...@@ -122,6 +122,123 @@ int gmshModelDestroy()
return 1; 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) int gmshModelMesh(int dim)
{ {
GModel *m = GModel::current(); GModel *m = GModel::current();
...@@ -131,3 +248,65 @@ int gmshModelMesh(int dim) ...@@ -131,3 +248,65 @@ int gmshModelMesh(int dim)
} }
return 1; return 1;
} }
int gmshModelGetMeshVertices(int dim, int tag, std::vector<int> &vertexTags,
std::vector<double> &coords,
std::vector<double> &parametricCoords)
{
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
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#define GMSH_API int #define GMSH_API int
#endif #endif
// Gmsh // gmsh
GMSH_API gmshInitialize(int argc, char **argv); GMSH_API gmshInitialize(int argc, char **argv);
GMSH_API gmshFinalize(); GMSH_API gmshFinalize();
GMSH_API gmshOpen(const std::string &fileName); GMSH_API gmshOpen(const std::string &fileName);
...@@ -36,35 +36,44 @@ GMSH_API gmshMerge(const std::string &fileName); ...@@ -36,35 +36,44 @@ GMSH_API gmshMerge(const std::string &fileName);
GMSH_API gmshExport(const std::string &fileName); GMSH_API gmshExport(const std::string &fileName);
GMSH_API gmshClear(); GMSH_API gmshClear();
// GmshOption // gmshOption
GMSH_API gmshOptionSetNumber(const std::string &name, double value); GMSH_API gmshOptionSetNumber(const std::string &name, double value);
GMSH_API gmshOptionGetNumber(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 gmshOptionSetString(const std::string &name, const std::string &value);
GMSH_API gmshOptionGetString(const std::string &name, std::string &value); GMSH_API gmshOptionGetString(const std::string &name, std::string &value);
// GmshModel // gmshModel
GMSH_API gmshModelCreate(const std::string &name); GMSH_API gmshModelCreate(const std::string &name);
GMSH_API gmshModelSetCurrent(const std::string &name); GMSH_API gmshModelSetCurrent(const std::string &name);
GMSH_API gmshModelDestroy(); GMSH_API gmshModelDestroy();
GMSH_API gmshModelMesh(int dim);
GMSH_API gmshModelGetElementaryTags(int dim, std::vector<int> &tags); GMSH_API gmshModelGetElementaryTags(int dim, std::vector<int> &tags);
GMSH_API gmshModelGetPhysicalTags(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 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 gmshModelSetPhysicalName(int dim, int tag, const std::string &name);
GMSH_API gmshModelGetPhysicalName(int dim, int tag, 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, GMSH_API gmshModelGetMeshVertices(int dim, int tag, std::vector<int> &vertexTags,
std::vector<double> &coords, std::vector<double> &coords,
std::vector<double> &parametricCoords); std::vector<double> &parametricCoords);
GMSH_API gmshModelGetMeshElements(int dim, int tag, std::vector<int> &types, GMSH_API gmshModelGetMeshElements(int dim, int tag, std::vector<int> &types,
std::vector<std::vector<int> > &elementTags, std::vector<std::vector<int> > &elementTags,
std::vector<std::vector<int> > &vertexTags); 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 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 gmshModelSetTransfiniteLine(int tag, int nPoints, int type, double coef);
GMSH_API gmshModelSetTransfiniteSurface(int tag, int arrangement, GMSH_API gmshModelSetTransfiniteSurface(int tag, int arrangement,
const std::vector<int> &cornerTags); const std::vector<int> &cornerTags);
...@@ -73,10 +82,8 @@ GMSH_API gmshModelSetRecombine(int dim, int tag, double angle); ...@@ -73,10 +82,8 @@ GMSH_API gmshModelSetRecombine(int dim, int tag, double angle);
GMSH_API gmshModelSetSmoothing(int tag, int val); GMSH_API gmshModelSetSmoothing(int tag, int val);
GMSH_API gmshModelSetReverseMesh(int dim, int tag); GMSH_API gmshModelSetReverseMesh(int dim, int tag);
GMSH_API gmshModelAddEmbeddedVertex(int tag, int inDim, int inTag); 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 gmshModelGeoAddVertex(int &tag, double x, double y, double z, double lc);
GMSH_API gmshModelGeoAddLine(int &tag, int startTag, int endTag); GMSH_API gmshModelGeoAddLine(int &tag, int startTag, int endTag);
GMSH_API gmshModelGeoAddCircleArc(int &tag, int startTag, int centerTag, 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, ...@@ -129,7 +136,7 @@ GMSH_API gmshModelGeoRemove(const std::vector<std::pair<int, int> > &dimTags,
GMSH_API gmshModelGeoRemoveAllDuplicates(); GMSH_API gmshModelGeoRemoveAllDuplicates();
GMSH_API gmshModelGeoSynchronize(); GMSH_API gmshModelGeoSynchronize();
// GmshModelOCC // gmshModelOCC
GMSH_API gmshModelOCCAddVertex(int &tag, double x, double y, double z, double lc); GMSH_API gmshModelOCCAddVertex(int &tag, double x, double y, double z, double lc);
GMSH_API gmshModelOCCAddLine(int &tag, int startVertexTag, int endVertexTag); GMSH_API gmshModelOCCAddLine(int &tag, int startVertexTag, int endVertexTag);
GMSH_API gmshModelOCCExtrude(const std::vector<std::pair<int, int> > &inDimTag, 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, ...@@ -138,10 +145,10 @@ GMSH_API gmshModelOCCExtrude(const std::vector<std::pair<int, int> > &inDimTag,
GMSH_API gmshModelOCCRemoveAllDuplicates(); GMSH_API gmshModelOCCRemoveAllDuplicates();
GMSH_API gmshModelOCCSynchronize(); GMSH_API gmshModelOCCSynchronize();
// GmshSolver // gmshSolver
// GmshPost // gmshPost
// GmshPlugin // gmshPlugin
#endif #endif
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 find_library(GMSH_LIB gmsh)
# build type to "RelWithDebInfo" ("-O2 -g" with gcc) prior to calling if(NOT GMSH_LIB)
# project() message(FATAL_ERROR "Could not find libgmsh")
if(DEFINED CMAKE_BUILD_TYPE) endif(NOT GMSH_LIB)
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)
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 include_directories(${GMSH_INC})
../../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)
add_executable(mainSimple mainSimple.cpp) add_executable(mainSimple mainSimple.cpp)
target_link_libraries(mainSimple shared) target_link_libraries(mainSimple ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB})
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)
#include <stdio.h>
#include <gmsh.h> #include <gmsh.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gmshInitialize(argc, argv); gmshInitialize(argc, argv);
gmshSetOption("Mesh", "Algorithm", 5.); gmshOptionSetNumber("General.Terminal", 1);
GModel *m = new GModel(); gmshOptionSetNumber("Mesh.Algorithm", 5);
m->readGEO("../../tutorial/t5.geo"); gmshOpen("../../tutorial/t5.geo");
//GmshMergeFile("../../tutorial/t5.geo"); // will also set the bbox gmshModelMesh(3);
m->mesh(3); gmshExport("test.msh");
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it){ gmshExport("test.unv");
GRegion *r = *it; gmshFinalize();
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();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment