diff --git a/CMakeLists.txt b/CMakeLists.txt index ee8ae9f50036b2ce3a12afd2d7099fcfec0b5527..b854c62e628a089dab7cd29ce92bda2332a8bb65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -946,23 +946,7 @@ elseif(MSVC) set_target_properties(gmsh PROPERTIES LINK_FLAGS "/STACK:16777216") endif(WIN32 AND NOT MSVC) -if(ENABLE_SWIG) - find_package(SWIG) - if(SWIG_FOUND) - message(STATUS "Found SWIG version " ${SWIG_VERSION}) - string(SUBSTRING ${SWIG_VERSION} 0 1 SWIG_MAJOR_VERSION) - if(SWIG_MAJOR_VERSION EQUAL 1) - message("WARNING: Python bindings require SWIG >= 2: disabling Python") - else(SWIG_MAJOR_VERSION EQUAL 1) - include(${SWIG_USE_FILE}) - find_package(PythonLibs) - include_directories(${PYTHON_INCLUDE_DIR}) - set_source_files_properties(Common/gmshpy.i PROPERTIES CPLUSPLUS ON) - swig_add_module(gmshpy python Common/gmshpy.i ${GMSH_API}) - swig_link_libraries(gmshpy ${PYTHON_LIBRARIES} shared) - endif(SWIG_MAJOR_VERSION EQUAL 1) - endif(SWIG_FOUND) -endif(ENABLE_SWIG) +add_subdirectory(gmshpy) find_program(BISON bison) find_program(FLEX flex) diff --git a/Common/gmshpy.i b/Common/gmshpy.i deleted file mode 100644 index 5b35cfa4316d849b523784f4416aa010de6803eb..0000000000000000000000000000000000000000 --- a/Common/gmshpy.i +++ /dev/null @@ -1,153 +0,0 @@ -%feature("autodoc", "1"); -%module gmshpy -%include std_string.i -%include std_vector.i -%include std_list.i -%include cpointer.i - -%{ - #include "GmshConfig.h" - #include "GModel.h" - #include "highOrderTools.h" - #include "DefaultOptions.h" - #include "fullMatrix.h" - #include "function.h" - #include "dofManager.h" - #include "linearSystem.h" - #include "linearSystemFull.h" - #include "linearSystemPETSc.h" - #include "linearSystemCSR.h" - #include "GEntity.h" - #include "GVertex.h" - #include "GEdge.h" - #include "GFace.h" - #include "GRegion.h" - #include "GPoint.h" - #include "MElement.h" - #include "MVertex.h" - #include "MTriangle.h" - #include "MPrism.h" - #include "MQuadrangle.h" - #include "MLine.h" - #include "GmshMessage.h" - #include "polynomialBasis.h" - #include "Gauss.h" - #include "meshPartitionOptions.h" - #include "meshGFaceOptimize.h" - #include "Generator.h" - #include "linearSystemCSR.h" - #include "elasticitySolver.h" - #include "meshGFaceLloyd.h" - #include "PView.h" - #include "PViewData.h" - #include "PViewFactory.h" - #include "DivideAndConquer.h" - #include "Gmsh.h" - #include "functionPython.h" - #include "Context.h" - #include "SVector3.h" - #include "SPoint3.h" - #include "SPoint2.h" - #include "GPoint.h" - #include "GmshDefines.h" - #include "JacobianBasis.h" - #include "Curvature.h" - #if defined(HAVE_FLTK) - #include "FlGui.h" - #endif - class errorHandler: public GmshMessage { - void operator()(std::string level, std::string message){ - #if defined(HAVE_FLTK) - // don't output anything special if we're running in a gui - if(FlGui::available()) return; - #endif - std::cout<<level<<" : "<<message<<std::endl; - if (level == "Fatal") - throw; - } - }; -%} - -%init %{ - errorHandler *eH = new errorHandler; - Msg::SetCallback(eH); - GmshInitialize(); -%} - -%pointer_functions(double,doublep) -%pointer_functions(int,intp) -namespace std { - %template(IntVector) vector<int>; - %template(DoubleVector) vector<double, std::allocator<double> >; - %template(VectorOfDoubleVector) vector<vector<double, std::allocator<double> > >; - %template(StringVector) vector<std::string, std::allocator<std::string> >; - %template(GEntityVector) vector<GEntity*, std::allocator<GEntity*> >; - %template(GVertexVector) vector<GVertex*, std::allocator<GVertex*> >; - %template(GEdgeVector) vector<GEdge*, std::allocator<GEdge*> >; - %template(GFaceVector) vector<GFace*, std::allocator<GFace*> >; - %template(GRegionVector) vector<GRegion*, std::allocator<GRegion*> >; - %template(MVertexVector) vector< MVertex *,std::allocator< MVertex * > >; - %template(MElementVector) vector< MElement *,std::allocator< MElement * > >; - %template(VectorFunctionConst) vector<const function*, std::allocator<const function*> >; - %template(GEdgeVectorVector) vector< std::vector< GEdge *,std::allocator< GEdge * > >,std::allocator< std::vector< GEdge *,std::allocator< GEdge * > > > >; - %template(GFaceList) list<GFace*, std::allocator<GFace*> >; - %template(GEdgeList) list<GEdge*, std::allocator<GEdge*> >; -} - -%include "GmshConfig.h" -%include "Context.h" -%include "fullMatrix.h" -%template(fullMatrixDouble) fullMatrix<double>; -%template(fullVectorDouble) fullVector<double>; -%include "dofManager.h" -%template(dofManagerDouble) dofManager<double>; -%include "GModel.h" -%include "highOrderTools.h" -%include "function.h" -%include "linearSystem.h" -%template(linearSystemDouble) linearSystem<double>; -%template(linearSystemFullMatrixDouble) linearSystem<fullMatrix<double> >; -%include "linearSystemFull.h" -%template(linearSystemFullDouble) linearSystemFull<double> ; -%include "linearSystemPETSc.h" -%template(linearSystemPETScDouble) linearSystemPETSc<double>; -%include "linearSystemCSR.h" -%template(linearSystemCSRDouble) linearSystemCSR<double>; -%template(linearSystemTAUCSDouble) linearSystemCSRTaucs<double>; -%include "GEntity.h" -%include "GVertex.h" -%include "GEdge.h" -%include "GFace.h" -%include "GRegion.h" -%include "GPoint.h" -%include "MElement.h" -%include "MVertex.h" -%include "MTriangle.h" -%include "MPrism.h" -%include "MQuadrangle.h" -%include "MLine.h" -%include "GmshMessage.h" -%include "polynomialBasis.h" -%include "Gauss.h" -%include "meshPartitionOptions.h" -%include "elasticitySolver.h" -%include "PView.h" -%include "PViewData.h" -%include "PViewFactory.h" -%include "DivideAndConquer.h" -%include "Gmsh.h" -%include "SVector3.h" -%include "SPoint3.h" -%include "SPoint2.h" -%include "GPoint.h" -%include "functionPython.h" -%include "meshGFaceLloyd.h" -%include "DefaultOptions.h" -%include "meshGFaceOptimize.h" -%include "Generator.h" -%include "GmshDefines.h" -%include "JacobianBasis.h" -%include "Curvature.h" -#if defined(HAVE_FLTK) -%include "FlGui.h" -#endif diff --git a/Geo/GModel.i b/Geo/GModel.i deleted file mode 100644 index 83aba859eba2bf113a53faa3808aca83df148f6f..0000000000000000000000000000000000000000 --- a/Geo/GModel.i +++ /dev/null @@ -1,9 +0,0 @@ -%module gmshPython -%include std_string.i -%{ - #include "GModel.h" - void GmshInitialize(int argc=0, char **argv=NULL); -%} - -void GmshInitialize(int argc=0, char **argv=NULL); -%include "GModel.h" diff --git a/gmshpy/CMakeLists.txt b/gmshpy/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..07f93bf0b9f0f2503ff0ce7ad498d172f825dc59 --- /dev/null +++ b/gmshpy/CMakeLists.txt @@ -0,0 +1,35 @@ +set (SWIG_MODULES + gmshCommon + gmshGeo + gmshNumeric + gmshPost + gmshSolver + gmshMesh +) + +if(ENABLE_SWIG) + find_package(SWIG) + if(SWIG_FOUND) + message(STATUS "Found SWIG version " ${SWIG_VERSION}) + string(SUBSTRING ${SWIG_VERSION} 0 1 SWIG_MAJOR_VERSION) + if(SWIG_MAJOR_VERSION EQUAL 1) + message("WARNING: Python bindings require SWIG >= 2: disabling Python") + else(SWIG_MAJOR_VERSION EQUAL 1) + include(${SWIG_USE_FILE}) + find_package(PythonLibs) + include_directories(${PYTHON_INCLUDE_DIR}) + + foreach(module ${SWIG_MODULES}) + set_source_files_properties(${module}.i PROPERTIES CPLUSPLUS ON) + swig_add_module(${module} python ${module}.i) + swig_link_libraries(${module} ${PYTHON_LIBRARIES} shared) + SET(GMSH_PYTHON_MODULES_INCLUDE_CODE + "${GMSH_PYTHON_MODULES_INCLUDE_CODE}from ${module} import *\n") + endforeach(module) + + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in + ${CMAKE_CURRENT_BINARY_DIR}/__init__.py) + + endif(SWIG_MAJOR_VERSION EQUAL 1) + endif(SWIG_FOUND) +endif(ENABLE_SWIG) diff --git a/gmshpy/__init__.py.in b/gmshpy/__init__.py.in new file mode 100644 index 0000000000000000000000000000000000000000..f333dda83bf7977fcaf1560e3a05b8264a58a19d --- /dev/null +++ b/gmshpy/__init__.py.in @@ -0,0 +1,2 @@ +${GMSH_PYTHON_MODULES_INCLUDE_CODE} +GmshInitialize() diff --git a/gmshpy/gmshCommon.i b/gmshpy/gmshCommon.i new file mode 100644 index 0000000000000000000000000000000000000000..d76c61e5a8999a9fe15f150211cd8bb1e60dfc91 --- /dev/null +++ b/gmshpy/gmshCommon.i @@ -0,0 +1,55 @@ +%feature("autodoc", "1"); +%module gmshCommon + +%include std_string.i +%include std_vector.i +%include cpointer.i + +%{ + #include "GmshConfig.h" + + #include "Context.h" + #include "DefaultOptions.h" + #include "Gmsh.h" + #include "GmshDefines.h" + #include "GmshMessage.h" +#if defined(HAVE_FLTK) + #include "FlGui.h" +#endif + class errorHandler: public GmshMessage { + void operator()(std::string level, std::string message){ +#if defined(HAVE_FLTK) + // don't output anything special if we're running in a gui + if(FlGui::available()) return; +#endif + std::cout<<level<<" : "<<message<<std::endl; + if (level == "Fatal") + throw; + } + }; +%} + +%init %{ + errorHandler *eH = new errorHandler; + Msg::SetCallback(eH); +%} + +namespace std { + %template(IntVector) std::vector<int>; + %template(DoubleVector) std::vector<double, std::allocator<double> >; + %template(DoubleVectorVector) std::vector<std::vector<double, std::allocator<double> > >; + %template(StringVector) std::vector<std::string, std::allocator<std::string> >; +} +%pointer_functions(double,doublep) +%pointer_functions(int,intp) + +%include "GmshConfig.h" + +%include "Context.h" +#include "DefaultOptions.h" +#if defined(HAVE_FLTK) +%include "FlGui.h" +#endif +%include "Gmsh.h" +%include "GmshDefines.h" +%include "GmshMessage.h" diff --git a/gmshpy/gmshGeo.i b/gmshpy/gmshGeo.i new file mode 100644 index 0000000000000000000000000000000000000000..c3d257035174eb6a9d5602b790603dd831c24866 --- /dev/null +++ b/gmshpy/gmshGeo.i @@ -0,0 +1,63 @@ +%feature("autodoc", "1"); +%module gmshGeo + +%include std_string.i +%include std_list.i +%include std_vector.i + +%{ + #include "GmshConfig.h" + + #include "Curvature.h" + #include "GModel.h" + #include "GPoint.h" + #include "GEntity.h" + #include "GVertex.h" + #include "GEdge.h" + #include "GFace.h" + #include "GRegion.h" + #include "GPoint.h" + #include "MElement.h" + #include "MVertex.h" + #include "MTriangle.h" + #include "MPrism.h" + #include "MQuadrangle.h" + #include "MLine.h" + #include "SVector3.h" + #include "SPoint3.h" + #include "SPoint2.h" +%} + +namespace std { + %template(GEntityVector) vector<GEntity*, std::allocator<GEntity*> >; + %template(GVertexVector) vector<GVertex*, std::allocator<GVertex*> >; + %template(GEdgeVector) vector<GEdge*, std::allocator<GEdge*> >; + %template(GFaceVector) vector<GFace*, std::allocator<GFace*> >; + %template(GRegionVector) vector<GRegion*, std::allocator<GRegion*> >; + %template(MVertexVector) vector< MVertex *,std::allocator< MVertex * > >; + %template(MElementVector) vector< MElement *,std::allocator< MElement * > >; + %template(GEdgeVectorVector) vector< std::vector< GEdge *,std::allocator< GEdge * > >,std::allocator< std::vector< GEdge *,std::allocator< GEdge * > > > >; + %template(GFaceList) list<GFace*, std::allocator<GFace*> >; + %template(GEdgeList) list<GEdge*, std::allocator<GEdge*> >; +} + +%include "GmshConfig.h" + +%include "Curvature.h" +%include "GModel.h" +%include "GPoint.h" +%include "GEntity.h" +%include "GVertex.h" +%include "GEdge.h" +%include "GFace.h" +%include "GRegion.h" +%include "GPoint.h" +%include "MElement.h" +%include "MVertex.h" +%include "MTriangle.h" +%include "MPrism.h" +%include "MQuadrangle.h" +%include "MLine.h" +%include "SVector3.h" +%include "SPoint3.h" +%include "SPoint2.h" diff --git a/gmshpy/gmshMesh.i b/gmshpy/gmshMesh.i new file mode 100644 index 0000000000000000000000000000000000000000..96c334324af90efeb41a133acc739e75c07c53cb --- /dev/null +++ b/gmshpy/gmshMesh.i @@ -0,0 +1,20 @@ +%feature("autodoc", "1"); +%module gmshMesh +%include std_string.i + +%{ + #include "GmshConfig.h" + + #include "Generator.h" + #include "highOrderTools.h" + #include "meshGFaceLloyd.h" + #include "meshGFaceOptimize.h" + #include "meshPartitionOptions.h" +%} + +%include "GmshConfig.h" +%include "Generator.h" +%include "highOrderTools.h" +%include "meshGFaceLloyd.h" +%include "meshGFaceOptimize.h" +%include "meshPartitionOptions.h" diff --git a/gmshpy/gmshNumeric.i b/gmshpy/gmshNumeric.i new file mode 100644 index 0000000000000000000000000000000000000000..77c064d0d287fad0d818f630cdcd39e55ba3f540 --- /dev/null +++ b/gmshpy/gmshNumeric.i @@ -0,0 +1,23 @@ +%feature("autodoc", "1"); +%module gmshNumeric + +%include std_string.i +%include std_vector.i + +%{ + #include "GmshConfig.h" + + #include "DivideAndConquer.h" + #include "Gauss.h" + #include "JacobianBasis.h" + #include "fullMatrix.h" + #include "polynomialBasis.h" +%} + +%include "DivideAndConquer.h" +%include "Gauss.h" +%include "JacobianBasis.h" +%include "fullMatrix.h" +%template(fullMatrixDouble) fullMatrix<double>; +%template(fullVectorDouble) fullVector<double>; +%include "polynomialBasis.h" diff --git a/gmshpy/gmshPost.i b/gmshpy/gmshPost.i new file mode 100644 index 0000000000000000000000000000000000000000..e7922ec07067fc13bd38849cf8274dc6214938af --- /dev/null +++ b/gmshpy/gmshPost.i @@ -0,0 +1,18 @@ +%feature("autodoc", "1"); +%module gmshPost +%include std_string.i + +%{ + #include "GmshConfig.h" + + #include "fullMatrix.h" + #include "PView.h" + #include "PViewData.h" + #include "PViewFactory.h" +%} + +%include "GmshConfig.h" + +%include "PView.h" +%include "PViewData.h" +%include "PViewFactory.h" diff --git a/gmshpy/gmshSolver.i b/gmshpy/gmshSolver.i new file mode 100644 index 0000000000000000000000000000000000000000..f8fe04487dcbca626f5cd6ee42ed97ee3a8274e1 --- /dev/null +++ b/gmshpy/gmshSolver.i @@ -0,0 +1,40 @@ +%feature("autodoc", "1"); +%module gmshSolver +%include std_string.i +%include std_vector.i +%import "gmshCommon.i" + +%{ + #include "GmshConfig.h" + + #include "dofManager.h" + #include "elasticitySolver.h" + #include "function.h" + #include "functionPython.h" + #include "linearSystem.h" + #include "linearSystemCSR.h" + #include "linearSystemFull.h" + #include "linearSystemPETSc.h" +%} + +namespace std { + %template(VectorFunctionConst) vector<const function*, std::allocator<const function*> >; +} + +%include "GmshConfig.h" + +%include "dofManager.h" +%template(dofManagerDouble) dofManager<double>; +%include "elasticitySolver.h" +%include "function.h" +%include "functionPython.h" +%include "linearSystem.h" +%template(linearSystemDouble) linearSystem<double>; +%template(linearSystemFullMatrixDouble) linearSystem<fullMatrix<double> >; +%include "linearSystemCSR.h" +%template(linearSystemCSRDouble) linearSystemCSR<double>; +%template(linearSystemTAUCSDouble) linearSystemCSRTaucs<double>; +%include "linearSystemFull.h" +%template(linearSystemFullDouble) linearSystemFull<double> ; +%include "linearSystemPETSc.h" +%template(linearSystemPETScDouble) linearSystemPETSc<double>;