diff --git a/Common/gmsh.cpp b/Common/gmsh.cpp index 658754da041ed6877c0a742742b5c3b3b8e0f887..ea434ae6f307556c36d93755b3362ad8c9d9b35d 100644 --- a/Common/gmsh.cpp +++ b/Common/gmsh.cpp @@ -3,6 +3,7 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to the public mailing list <gmsh@onelab.info>. +#include "gmsh.h" #include "GmshGlobal.h" #include "GModel.h" #include "GModelIO_GEO.h" @@ -140,7 +141,7 @@ int gmshModelDestroy() return 1; } -int gmshModelGetEntities(std::vector<std::pair<int, int> > &dimTags) +int gmshModelGetEntities(vector_pair &dimTags) { std::vector<GEntity*> entities; GModel::current()->getEntities(entities); @@ -149,7 +150,7 @@ int gmshModelGetEntities(std::vector<std::pair<int, int> > &dimTags) return 0; } -int gmshModelGetPhysicalGroups(std::vector<std::pair<int, int> > &dimTags) +int gmshModelGetPhysicalGroups(vector_pair &dimTags) { std::map<int, std::vector<GEntity*> > groups[4]; GModel::current()->getPhysicalGroups(groups); @@ -209,8 +210,7 @@ int gmshModelGetVertexCoordinates(int tag, double &x, double &y, double &z) return 1; } -int gmshModelGetBoundary(const std::vector<std::pair<int, int> > &inDimTags, - std::vector<std::pair<int, int> > &outDimTags, +int gmshModelGetBoundary(const vector_pair &inDimTags, vector_pair &outDimTags, bool combined, bool oriented, bool recursive) { bool r = GModel::current()->getBoundaryTags(inDimTags, outDimTags, combined, @@ -248,8 +248,7 @@ int gmshModelGetBoundingBox(int dim, int tag, double &x1, double &y1, double &z1 return 0; } -int gmshModelRemove(const std::vector<std::pair<int, int> > &dimTags, - bool recursive) +int gmshModelRemove(const vector_pair &dimTags, bool recursive) { GModel::current()->remove(dimTags, recursive); return 0; @@ -551,9 +550,9 @@ static ExtrudeParams *getExtrudeParams(const std::vector<int> &numElements, return e; } -int gmshModelGeoExtrude(const std::vector<std::pair<int, int> > &inDimTags, +int gmshModelGeoExtrude(const vector_pair &inDimTags, double dx, double dy, double dz, - std::vector<std::pair<int, int> > &outDimTags, + vector_pair &outDimTags, const std::vector<int> &numElements, const std::vector<double> &heights, bool recombine) { @@ -562,10 +561,10 @@ int gmshModelGeoExtrude(const std::vector<std::pair<int, int> > &inDimTags, getExtrudeParams(numElements, heights, recombine)); } -int gmshModelGeoRevolve(const std::vector<std::pair<int, int> > &inDimTags, +int gmshModelGeoRevolve(const vector_pair &inDimTags, double x, double y, double z, double ax, double ay, double az, double angle, - std::vector<std::pair<int, int> > &outDimTags, + vector_pair &outDimTags, const std::vector<int> &numElements, const std::vector<double> &heights, bool recombine) { @@ -574,11 +573,11 @@ int gmshModelGeoRevolve(const std::vector<std::pair<int, int> > &inDimTags, getExtrudeParams(numElements, heights, recombine)); } -int gmshModelGeoTwist(const std::vector<std::pair<int, int> > &inDimTags, +int gmshModelGeoTwist(const vector_pair &inDimTags, double x, double y, double z, double dx, double dy, double dz, double ax, double ay, double az, double angle, - std::vector<std::pair<int, int> > &outDimTags, + vector_pair &outDimTags, const std::vector<int> &numElements, const std::vector<double> &heights, bool recombine) { @@ -587,13 +586,13 @@ int gmshModelGeoTwist(const std::vector<std::pair<int, int> > &inDimTags, getExtrudeParams(numElements, heights, recombine)); } -int gmshModelGeoTranslate(const std::vector<std::pair<int, int> > &dimTags, +int gmshModelGeoTranslate(const vector_pair &dimTags, double dx, double dy, double dz) { return !GModel::current()->getGEOInternals()->translate(dimTags, dx, dy, dz); } -int gmshModelGeoRotate(const std::vector<std::pair<int, int> > &dimTags, +int gmshModelGeoRotate(const vector_pair &dimTags, double x, double y, double z, double ax, double ay, double az, double angle) { @@ -601,7 +600,7 @@ int gmshModelGeoRotate(const std::vector<std::pair<int, int> > &dimTags, (dimTags, x, y, z, ax, ay, az, angle); } -int gmshModelGeoDilate(const std::vector<std::pair<int, int> > &dimTags, +int gmshModelGeoDilate(const vector_pair &dimTags, double x, double y, double z, double a, double b, double c) { @@ -609,21 +608,19 @@ int gmshModelGeoDilate(const std::vector<std::pair<int, int> > &dimTags, (dimTags, x, y, z, a, b, c); } -int gmshModelGeoSymmetry(const std::vector<std::pair<int, int> > &dimTags, +int gmshModelGeoSymmetry(const vector_pair &dimTags, double a, double b, double c, double d) { return !GModel::current()->getGEOInternals()->symmetry (dimTags, a, b, c, d); } -int gmshModelGeoCopy(const std::vector<std::pair<int, int> > &inDimTags, - std::vector<std::pair<int, int> > &outDimTags) +int gmshModelGeoCopy(const vector_pair &inDimTags, vector_pair &outDimTags) { return !GModel::current()->getGEOInternals()->copy(inDimTags, outDimTags); } -int gmshModelGeoRemove(const std::vector<std::pair<int, int> > &dimTags, - bool recursive) +int gmshModelGeoRemove(const vector_pair &dimTags, bool recursive) { return !GModel::current()->getGEOInternals()->remove(dimTags, recursive); } @@ -653,6 +650,218 @@ int gmshModelOccAddVertex(int &tag, double x, double y, double z, double meshSiz return !GModel::current()->getOCCInternals()->addVertex(tag, x, y, z, meshSize); } +int gmshModelOccAddLine(int &tag, int startTag, int endTag) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addLine(tag, startTag, endTag); +} + +int gmshModelOccAddCircleArc(int &tag, int startTag, int centerTag, + int endTag) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addCircleArc + (tag, startTag, centerTag, endTag); +} + +int gmshModelOccAddCircle(int &tag, double x, double y, double z, double r, + double angle1, double angle2) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addCircle + (tag, x, y, z, r, angle1, angle2); +} + +int gmshModelOccAddEllipseArc(int &tag, int startTag, int centerTag, int endTag) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addEllipseArc + (tag, startTag, centerTag, endTag); +} + +int gmshModelOccAddEllipse(int &tag, double x, double y, double z, double r1, + double r2, double angle1, double angle2) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addEllipse + (tag, x, y, z, r1, r2, angle1, angle2); +} + +int gmshModelOccAddSpline(int &tag, const std::vector<int> &vertexTags) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addSpline(tag, vertexTags); +} + +int gmshModelOccAddBezier(int &tag, const std::vector<int> &vertexTags) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addBezier(tag, vertexTags); +} + +int gmshModelOccAddBSpline(int &tag, const std::vector<int> &vertexTags) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addBSpline(tag, vertexTags); +} + +int gmshModelOccAddWire(int &tag, const std::vector<int> &edgeTags, + bool checkClosed) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addWire + (tag, edgeTags, checkClosed); +} + +int gmshModelOccAddLineLoop(int &tag, const std::vector<int> &edgeTags) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addLineLoop(tag, edgeTags); +} + +int gmshModelOccAddRectangle(int &tag, double x, double y, double z, + double dx, double dy, double roundedRadius) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addRectangle + (tag, x, y, z, dx, dy, roundedRadius); +} + +int gmshModelOccAddDisk(int &tag, double xc, double yc, double zc, + double rx, double ry) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addDisk + (tag, xc, yc, zc, rx, ry); +} + +int gmshModelOccAddPlaneSurface(int &tag, const std::vector<int> &wireTags) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addPlaneSurface(tag, wireTags); +} + +int gmshModelOccAddSurfaceFilling(int &tag, int wireTag) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addSurfaceFilling(tag, wireTag); +} + +int gmshModelOccAddSurfaceLoop(int &tag, const std::vector<int> &faceTags) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addSurfaceLoop(tag, faceTags); +} + +int gmshModelOccAddVolume(int &tag, const std::vector<int> &shellTags) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addVolume(tag, shellTags); +} + +int gmshModelOccAddSphere(int &tag, double xc, double yc, double zc, + double radius, double angle1, double angle2, + double angle3) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addSphere + (tag, xc, yc, zc, radius, angle1, angle2, angle3); +} + +int gmshModelOccAddBox(int &tag, double x, double y, double z, + double dx, double dy, double dz) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addBox + (tag, x, y, z, dx, dy, dz); +} + +int gmshModelOccAddCylinder(int &tag, double x, double y, double z, + double dx, double dy, double dz, double r, + double angle) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addCylinder + (tag, x, y, z, dx, dy, dz, r, angle); +} + +int gmshModelOccAddCone(int &tag, double x, double y, double z, + double dx, double dy, double dz, double r1, double r2, + double angle) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addCone + (tag, x, y, z, dx, dy, dz, r1, r2, angle); +} + +int gmshModelOccAddWedge(int &tag, double x, double y, double z, double dx, + double dy, double dz, double ltx) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addWedge + (tag, x, y, z, dx, dy, dz, ltx); +} + +int gmshModelOccAddTorus(int &tag, double x, double y, double z, double r1, + double r2, double angle) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->addTorus + (tag, x, y, z, r1, r2, angle); +} + + + + + +int gmshModelOccBooleanUnion(int tag, const vector_pair &objectDimTags, + const vector_pair &toolDimTags, + vector_pair &outDimTags, + std::vector<vector_pair > &outDimTagsMap, + bool removeObject, bool removeTool) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->booleanUnion + (tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, + removeObject, removeTool); +} + +int gmshModelOccBooleanIntersection(int tag, const vector_pair &objectDimTags, + const vector_pair &toolDimTags, + vector_pair &outDimTags, + std::vector<vector_pair > &outDimTagsMap, + bool removeObject, bool removeTool) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->booleanIntersection + (tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, + removeObject, removeTool); +} + +int gmshModelOccBooleanDifference(int tag, const vector_pair &objectDimTags, + const vector_pair &toolDimTags, + vector_pair &outDimTags, + std::vector<vector_pair > &outDimTagsMap, + bool removeObject, bool removeTool) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->booleanDifference + (tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, + removeObject, removeTool); +} + +int gmshModelOccBooleanFragments(int tag, const vector_pair &objectDimTags, + const vector_pair &toolDimTags, + vector_pair &outDimTags, + std::vector<vector_pair> &outDimTagsMap, + bool removeObject, bool removeTool) +{ + createOcc(); + return !GModel::current()->getOCCInternals()->booleanFragments + (tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, + removeObject, removeTool); +} + int gmshModelOccSynchronize() { createOcc(); diff --git a/Common/gmsh.h b/Common/gmsh.h index 559efa663ea848cdea378938c8360459942a872a..7965c2ffefe926d0c6a9a608eb1b220fd0bd0fc6 100644 --- a/Common/gmsh.h +++ b/Common/gmsh.h @@ -19,6 +19,7 @@ // All functions return 0 on successful completion. +#include <cmath> #include <vector> #include <string> @@ -28,6 +29,8 @@ #define GMSH_API int #endif +typedef std::vector<std::pair<int, int> > vector_pair; + // gmsh GMSH_API gmshInitialize(int argc = 0, char **argv = 0); GMSH_API gmshFinalize(); @@ -46,16 +49,15 @@ GMSH_API gmshOptionGetString(const std::string &name, std::string &value); GMSH_API gmshModelCreate(const std::string &name); GMSH_API gmshModelSetCurrent(const std::string &name); GMSH_API gmshModelDestroy(); -GMSH_API gmshModelGetEntities(std::vector<std::pair<int, int> > &dimTags); -GMSH_API gmshModelGetPhysicalGroups(std::vector<std::pair<int, int> > &dimTags); +GMSH_API gmshModelGetEntities(vector_pair &dimTags); +GMSH_API gmshModelGetPhysicalGroups(vector_pair &dimTags); GMSH_API gmshModelAddPhysicalGroup(int dim, int tag, const std::vector<int> &tags); GMSH_API gmshModelGetEntitiesForPhysicalGroup(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, double &y, double &z); -GMSH_API gmshModelGetBoundary(const std::vector<std::pair<int, int> > &inDimTags, - std::vector<std::pair<int, int> > &outDimTags, +GMSH_API gmshModelGetBoundary(const vector_pair &inDimTags, vector_pair &outDimTags, bool combined = true, bool oriented = true, bool recursive = false); GMSH_API gmshModelGetEntitiesInBoundingBox(int dim, double x1, double y1, double z1, @@ -63,8 +65,7 @@ GMSH_API gmshModelGetEntitiesInBoundingBox(int dim, double x1, double y1, double 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 gmshModelRemove(const vector_pair &dimTags, bool recursive = false); GMSH_API gmshModelMesh(int dim); GMSH_API gmshModelGetMeshVertices(int dim, int tag, std::vector<int> &vertexTags, std::vector<double> &coords); @@ -99,49 +100,107 @@ GMSH_API gmshModelGeoAddSurfaceFilling(int &tag, const std::vector<int> &wireTag int sphereCenterTag = -1); GMSH_API gmshModelGeoAddSurfaceLoop(int &tag, const std::vector<int> &faceTags); GMSH_API gmshModelGeoAddVolume(int &tag, const std::vector<int> &shellTags); -GMSH_API gmshModelGeoExtrude(const std::vector<std::pair<int, int> > &inDimTags, +GMSH_API gmshModelGeoExtrude(const vector_pair &inDimTags, double dx, double dy, double dz, - std::vector<std::pair<int, int> > &outDimTags, + vector_pair &outDimTags, const std::vector<int> &numElements = std::vector<int>(), const std::vector<double> &heights = std::vector<double>(), bool recombine = false); -GMSH_API gmshModelGeoRevolve(const std::vector<std::pair<int, int> > &inDimTags, +GMSH_API gmshModelGeoRevolve(const vector_pair &inDimTags, double x, double y, double z, double ax, double ay, double az, double angle, - std::vector<std::pair<int, int> > &outDimTags, + vector_pair &outDimTags, const std::vector<int> &numElements = std::vector<int>(), const std::vector<double> &heights = std::vector<double>(), bool recombine = false); -GMSH_API gmshModelGeoTwist(const std::vector<std::pair<int, int> > &inDimTags, +GMSH_API gmshModelGeoTwist(const vector_pair &inDimTags, double x, double y, double z, double dx, double dy, double dz, double ax, double ay, double az, double angle, - std::vector<std::pair<int, int> > &outDimTags, + vector_pair &outDimTags, const std::vector<int> &numElements = std::vector<int>(), const std::vector<double> &heights = std::vector<double>(), bool recombine = false); -GMSH_API gmshModelGeoTranslate(const std::vector<std::pair<int, int> > &dimTags, +GMSH_API gmshModelGeoTranslate(const vector_pair &dimTags, double dx, double dy, double dz); -GMSH_API gmshModelGeoRotate(const std::vector<std::pair<int, int> > &dimTags, - double x, double y, double z, double ax, double ay, - double az, double angle); -GMSH_API gmshModelGeoDilate(const std::vector<std::pair<int, int> > &dimTags, - double x, double y, double z, +GMSH_API gmshModelGeoRotate(const vector_pair &dimTags, double x, double y, double z, + double ax, double ay, double az, double angle); +GMSH_API gmshModelGeoDilate(const vector_pair &dimTags, double x, double y, double z, double a, double b, double c); -GMSH_API gmshModelGeoSymmetry(const std::vector<std::pair<int, int> > &dimTags, - double a, double b, double c, double d); -GMSH_API gmshModelGeoCopy(const std::vector<std::pair<int, int> > &inDimTags, - std::vector<std::pair<int, int> > &outDimTags); -GMSH_API gmshModelGeoRemove(const std::vector<std::pair<int, int> > &dimTags, - bool recursive = false); +GMSH_API gmshModelGeoSymmetry(const vector_pair &dimTags, double a, double b, + double c, double d); +GMSH_API gmshModelGeoCopy(const vector_pair &inDimTags, vector_pair &outDimTags); +GMSH_API gmshModelGeoRemove(const vector_pair &dimTags, bool recursive = false); GMSH_API gmshModelGeoRemoveAllDuplicates(); GMSH_API gmshModelGeoSynchronize(); // gmshModelOcc GMSH_API gmshModelOccAddVertex(int &tag, double x, double y, double z, double meshSize); +GMSH_API gmshModelOccAddLine(int &tag, int startTag, int endTag); +GMSH_API gmshModelOccAddCircleArc(int &tag, int startTag, int centerTag, + int endTag); +GMSH_API gmshModelOccAddCircle(int &tag, double x, double y, double z, double r, + double angle1, double angle2); +GMSH_API gmshModelOccAddEllipseArc(int &tag, int startTag, int centerTag, + int endTag); +GMSH_API gmshModelOccAddEllipse(int &tag, double x, double y, double z, double r1, + double r2, double angle1, double angle2); +GMSH_API gmshModelOccAddSpline(int &tag, const std::vector<int> &vertexTags); +GMSH_API gmshModelOccAddBezier(int &tag, const std::vector<int> &vertexTags); +GMSH_API gmshModelOccAddBSpline(int &tag, const std::vector<int> &vertexTags); +GMSH_API gmshModelOccAddWire(int &tag, const std::vector<int> &edgeTags, + bool checkClosed=false); +GMSH_API gmshModelOccAddLineLoop(int &tag, const std::vector<int> &edgeTags); +GMSH_API gmshModelOccAddRectangle(int &tag, double x, double y, double z, + double dx, double dy, double roundedRadius = 0.); +GMSH_API gmshModelOccAddDisk(int &tag, double xc, double yc, double zc, + double rx, double ry); +GMSH_API gmshModelOccAddPlaneSurface(int &tag, const std::vector<int> &wireTags); +GMSH_API gmshModelOccAddSurfaceFilling(int &tag, int wireTag); +GMSH_API gmshModelOccAddSurfaceLoop(int &tag, const std::vector<int> &faceTags); +GMSH_API gmshModelOccAddVolume(int &tag, const std::vector<int> &shellTags); +GMSH_API gmshModelOccAddSphere(int &tag, double xc, double yc, double zc, + double radius, double angle1 = -M_PI/2, + double angle2 = M_PI/2, double angle3 = 2*M_PI); +GMSH_API gmshModelOccAddBox(int &tag, double x, double y, double z, + double dx, double dy, double dz); +GMSH_API gmshModelOccAddCylinder(int &tag, double x, double y, double z, + double dx, double dy, double dz, double r, + double angle = 2*M_PI); +GMSH_API gmshModelOccAddCone(int &tag, double x, double y, double z, + double dx, double dy, double dz, double r1, double r2, + double angle = 2*M_PI); +GMSH_API gmshModelOccAddWedge(int &tag, double x, double y, double z, double dx, + double dy, double dz, double ltx = 0.); +GMSH_API gmshModelOccAddTorus(int &tag, double x, double y, double z, double r1, + double r2, double angle = 2*M_PI); + +GMSH_API gmshModelOccBooleanUnion(int tag, const vector_pair &objectDimTags, + const vector_pair &toolDimTags, + vector_pair &outDimTags, + std::vector<vector_pair > &outDimTagsMap, + bool removeObject, bool removeTool); +GMSH_API gmshModelOccBooleanIntersection(int tag, const vector_pair &objectDimTags, + const vector_pair &toolDimTags, + vector_pair &outDimTags, + std::vector<vector_pair > &outDimTagsMap, + bool removeObject, bool removeTool); +GMSH_API gmshModelOccBooleanDifference(int tag, const vector_pair &objectDimTags, + const vector_pair &toolDimTags, + vector_pair &outDimTags, + std::vector<vector_pair > &outDimTagsMap, + bool removeObject, bool removeTool); +GMSH_API gmshModelOccBooleanFragments(int tag, const vector_pair &objectDimTags, + const vector_pair &toolDimTags, + vector_pair &outDimTags, + std::vector<vector_pair> &outDimTagsMap, + bool removeObject, bool removeTool); + GMSH_API gmshModelOccSynchronize(); +// gmshField + // gmshSolver // gmshPost diff --git a/demos/api/CMakeLists.txt b/demos/api/CMakeLists.txt index fb39aa307b631120e2c0ff8b8ac84d873d84ceb6..d092d614b4b7935b31ffb6309656fa39d6b3fdd7 100644 --- a/demos/api/CMakeLists.txt +++ b/demos/api/CMakeLists.txt @@ -22,11 +22,9 @@ endif(GMSH_LIB MATCHES ".a") include_directories(${GMSH_INC}) -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}) - -add_executable(t1 t1.cpp) -target_link_libraries(t1 ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB}) +file(GLOB FILES *.cpp) +foreach(FILE ${FILES}) + get_filename_component(DEMO ${FILE} NAME_WE) + add_executable(${DEMO} ${FILE}) + target_link_libraries(${DEMO} ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB}) +endforeach(FILE)