]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add python wrapper for Triangulation.
authorBruno Turcksin <bruno.turcksin@gmail.com>
Tue, 17 May 2016 20:53:11 +0000 (16:53 -0400)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Wed, 3 Aug 2016 20:34:02 +0000 (16:34 -0400)
source/CMakeLists.txt
source/python/CMakeLists.txt [new file with mode: 0644]
source/python/__init__.py [new file with mode: 0644]
source/python/dummy.py [new file with mode: 0644]
source/python/wrappers.cc [new file with mode: 0644]

index 4d3e8f7b4fd90281125145a93809e50a70fd3384..7075734e5f45b04390535621c25ef0ee83138e31 100644 (file)
@@ -48,6 +48,7 @@ ADD_SUBDIRECTORY(integrators)
 ADD_SUBDIRECTORY(matrix_free)
 ADD_SUBDIRECTORY(meshworker)
 ADD_SUBDIRECTORY(opencascade)
+ADD_SUBDIRECTORY(python)
 
 FOREACH(build ${DEAL_II_BUILD_TYPES})
   STRING(TOLOWER ${build} build_lowercase)
diff --git a/source/python/CMakeLists.txt b/source/python/CMakeLists.txt
new file mode 100644 (file)
index 0000000..baf7813
--- /dev/null
@@ -0,0 +1,66 @@
+## ---------------------------------------------------------------------
+##
+## Copyright (C) 2016 by the deal.II authors
+##
+## This file is part of the deal.II library.
+##
+## The deal.II library is free software; you can use it, redistribute
+## it, and/or modify it under the terms of the GNU Lesser General
+## Public License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+## The full text of the license can be found in the file LICENSE at
+## the top level of the deal.II distribution.
+##
+## ---------------------------------------------------------------------
+
+FIND_LIBRARY(Boost_PYTHON_LIBRARY boost_python PATH ${Boost_LIBRARY_DIRS} NO_DEFAULT_PATH)
+INCLUDE(FindPythonLibs)
+INCLUDE(FindPythonInterp)
+INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
+INCLUDE_DIRECTORIES(SYSTEM ${PYTHON_INCLUDE_DIRS})
+
+SET(_src
+  wrappers.cc
+  )
+
+FILE(GLOB _header
+  ${CMAKE_SOURCE_DIR}/include/deal.II/python/*.h
+  )
+
+
+PYTHON_ADD_MODULE(PyDealII ${_src})
+
+SET(PYTHON_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
+
+TARGET_LINK_LIBRARIES(PyDealII deal_II.g)
+TARGET_LINK_LIBRARIES(PyDealII ${Boost_PYTHON_LIBRARY})
+TARGET_LINK_LIBRARIES(PyDealII ${PYTHON_LIBRARIES})
+
+SET_TARGET_PROPERTIES(PyDealII PROPERTIES
+  CXX_STANDARD 11
+  )
+
+INSTALL(TARGETS PyDealII DESTINATION ${PYTHON_INSTALL_PREFIX}/pydealii)
+
+SET(PYTHON_SOURCES
+  __init__.py
+  dummy.py
+  )                                                                                                                                                                                                               
+FOREACH(PYTHON_SOURCE ${PYTHON_SOURCES})                                                                                                                                                                            
+  ADD_CUSTOM_COMMAND(                                                                                                                                                                                             
+    OUTPUT ${CMAKE_BINARY_DIR}/python/pydealii/${PYTHON_SOURCE}                                                                                                                                                    
+    DEPENDS ${CMAKE_SOURCE_DIR}/source/python/${PYTHON_SOURCE}                                                                                                                                                  
+    COMMAND ${CMAKE_COMMAND}                                                                                                                                                                                    
+    ARGS -E copy ${CMAKE_SOURCE_DIR}/source/python/${PYTHON_SOURCE} ${CMAKE_BINARY_DIR}/python/pydealii/${PYTHON_SOURCE}                                                                                           
+    COMMENT "Copying ${PYTHON_SOURCE}"                                                                                                                                                                          
+    )                                                                                                                                                                                                           
+  ADD_CUSTOM_TARGET(                                                                                                                                                                                              
+    ${PYTHON_SOURCE} ALL
+    DEPENDS ${CMAKE_BINARY_DIR}/python/pydealii/${PYTHON_SOURCE}                                                                                                                                                   
+    )                                                                                                                                                                                                           
+ENDFOREACH()                                                                                                                                                                                                        
+INSTALL(                                                                                                                                                                                                            
+  DIRECTORY ${CMAKE_BINARY_DIR}/python/pydealii
+  DESTINATION ${PYTHON_INSTALL_PREFIX}                                                                                                                                                                            
+  FILES_MATCHING PATTERN "*.py"                                                                                                                                                                                   
+  ) 
diff --git a/source/python/__init__.py b/source/python/__init__.py
new file mode 100644 (file)
index 0000000..f632632
--- /dev/null
@@ -0,0 +1,20 @@
+# ---------------------------------------------------------------------
+#
+# Copyright (C) 2016 by the deal.II authors
+#
+# This file is part of the deal.II library.
+#
+# The deal.II library is free software; you can use it, redistribute
+# it, and/or modify it under the terms of the GNU Lesser General
+# Public License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+# The full text of the license can be found in the file LICENSE at
+# the top level of the deal.II distribution.
+#
+# ---------------------------------------------------------------------
+
+from .PyDealII import *
+from .dummy import *
+
+__all__ = ['PyDealII', 'dummy']
+__doc__ = PyDealII.__doc__
diff --git a/source/python/dummy.py b/source/python/dummy.py
new file mode 100644 (file)
index 0000000..4523f75
--- /dev/null
@@ -0,0 +1,29 @@
+# ---------------------------------------------------------------------
+#
+# Copyright (C) 2016 by the deal.II authors
+#
+# This file is part of the deal.II library.
+#
+# The deal.II library is free software; you can use it, redistribute
+# it, and/or modify it under the terms of the GNU Lesser General
+# Public License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+# The full text of the license can be found in the file LICENSE at
+# the top level of the deal.II distribution.
+#
+# ---------------------------------------------------------------------
+
+"""This a dummy module that contains a global function and a class."""
+
+__all__ = ['Dummy', 'bar']
+
+def bar():
+    """Print bar."""
+    print('bar')
+
+class Dummy:
+    """This a dummy class that has only one member function."""
+    
+    def foo(self):
+        """Print foo."""
+        print('foo')
diff --git a/source/python/wrappers.cc b/source/python/wrappers.cc
new file mode 100644 (file)
index 0000000..271a030
--- /dev/null
@@ -0,0 +1,51 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+#include <boost/python.hpp>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+
+char const *pydealii_docstring =
+  "                                                             \n"
+  "PyDealII                                                     \n"
+  "========                                                     \n"
+  "Some interesting doc.                                        \n"
+  ;
+
+unsigned int n_active_cells(const dealii::Triangulation<2> &triangulation)
+{
+  return triangulation.n_active_cells();
+}
+
+void generate_cube(dealii::Triangulation<2> &triangulation)
+{
+  dealii::GridGenerator::hyper_cube(triangulation);
+}
+
+BOOST_PYTHON_MODULE(PyDealII)
+{
+  boost::python::scope().attr("__doc__") = pydealii_docstring;
+
+  boost::python::docstring_options doc_options;
+  doc_options.enable_user_defined();
+  doc_options.enable_py_signatures();
+  doc_options.disable_cpp_signatures();
+
+
+  boost::python::class_<dealii::Triangulation<2>> ("Triangulation")
+                                               .def("n_active_cells", &n_active_cells)
+                                               .def("generate_cube", &generate_cube)
+                                               .def("refine_global", &dealii::Triangulation<2>::refine_global);
+}

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.