Commit a97a6006 authored by Oliver Sander's avatar Oliver Sander
Browse files

Merge branch 'localfunctions-python-bindings' into 'master'

Adapted the Python bindings to the new structure.

See merge request !189
parents 2345c2c0 10c34a9e
Pipeline #35854 passed with stage
in 10 minutes and 55 seconds
......@@ -11,3 +11,22 @@ before_script:
- . /duneci/bin/duneci-init-job
- duneci-install-module https://gitlab.dune-project.org/core/dune-common.git
- duneci-install-module https://gitlab.dune-project.org/core/dune-geometry.git
debian-11-gcc-9-17-python:
image: registry.dune-project.org/docker/ci/debian:11
script: duneci-standard-test
variables:
DUNECI_TOOLCHAIN: gcc-9-17
# so we need some variables to build the dune-py module during execution of the first python test:
# we need to find the dune mdoule
DUNE_CONTROL_PATH: /duneci/modules:$CI_PROJECT_DIR
# the position for the dune-py module
DUNE_PY_DIR: /duneci/modules/dune-py
# during dune-py build this variable is used - do know a way to access
# the CMAKE_FLAGS used to build the modules...
DUNE_CMAKE_FLAGS: "-DCMAKE_CXX_COMPILER=g++-9 -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_CXX_FLAGS='-std=c++17 -O2 -g -Wall -fdiagnostics-color=always' -DDUNE_ENABLE_PYTHONBINDINGS=ON -DDUNE_MAX_TEST_CORES=4 -DBUILD_SHARED_LIBS=TRUE -DDUNE_PYTHON_INSTALL_LOCATION=none -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_LATEX=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_Alberta=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_Vc=TRUE -DCMAKE_DISABLE_DOCUMENTATION=TRUE"
# cmake flags we use for all dune moudle - important is that build shared libs is set (need some better way of doing this)
DUNECI_CMAKE_FLAGS: $DUNE_CMAKE_FLAGS
# finally set the python path to all modules
PYTHONPATH: /duneci/modules/dune-common/build-cmake/python:/duneci/modules/dune-geometry/build-cmake/python:$CI_PROJECT_DIR/build-cmake/python
tags: [duneci]
......@@ -25,6 +25,8 @@
* Remove deprecated `GenericLocalFiniteElement::topologyId()`, use
`type().id()` instead.
* Imported the Python bindings from the 2.7 branch of dune-python.
# Release 2.7
* The header `lagrange.hh` now includes all headers of all Lagrange implementations,
......
......@@ -25,4 +25,10 @@ dune_project()
add_subdirectory(doc)
add_subdirectory(dune)
if( DUNE_ENABLE_PYTHONBINDINGS )
add_subdirectory(python)
dune_python_install_package(PATH python)
endif()
finalize_dune_project(GENERATE_CONFIG_H_CMAKE)
add_subdirectory(localfunctions)
if( DUNE_ENABLE_PYTHONBINDINGS )
add_subdirectory("python")
endif()
add_subdirectory(localfunctions)
install(FILES
localfiniteelement.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/python/localfunctions
)
#ifndef DUNE_PYTHON_LOCALFUNCTIONS_LOCALFINITEELEMENT_HH
#define DUNE_PYTHON_LOCALFUNCTIONS_LOCALFINITEELEMENT_HH
#include <dune/python/pybind11/pybind11.h>
#include <dune/common/visibility.hh>
#include <dune/localfunctions/common/localkey.hh>
#include <dune/localfunctions/common/virtualinterface.hh>
namespace Dune {
namespace Python {
namespace detail {
template<typename LocalBasis>
DUNE_EXPORT auto registerLocalBasis(pybind11::handle scope)
{
static auto cls = pybind11::class_<LocalBasis>(scope, "LocalBasis");
cls.def("__len__", [](const LocalBasis& basis) { return basis.size(); });
cls.def_property_readonly("order", [](const LocalBasis& basis) { return basis.order(); });
cls.def("evaluateFunction",
[](const LocalBasis& basis, const typename LocalBasis::Traits::DomainType& in) {
std::vector<typename LocalBasis::Traits::RangeType> out;
basis.evaluateFunction(in, out);
return out;
});
cls.def("evaluateJacobian",
[](const LocalBasis& basis, const typename LocalBasis::Traits::DomainType& in) {
std::vector<typename LocalBasis::Traits::JacobianType> out;
basis.evaluateJacobian(in, out);
return out;
});
return cls;
}
DUNE_EXPORT auto registerLocalKey(pybind11::handle scope)
{
static auto cls = pybind11::class_<LocalKey>(scope, "LocalKey");
cls.def_property_readonly("subEntity", &LocalKey::subEntity);
cls.def_property_readonly("codim", &LocalKey::codim);
cls.def_property("index",
[](const LocalKey& key) { return key.index(); },
[](LocalKey& key, unsigned int index) { key.index(index); });
cls.def("__lt__", &LocalKey::operator<);
return cls;
}
} /* namespace detail */
template<typename LocalFiniteElement>
DUNE_EXPORT auto registerLocalFiniteElement(pybind11::handle scope, const char* name = "LocalFiniteElement")
{
static auto cls = pybind11::class_<LocalFiniteElement>(scope, name);
detail::registerLocalBasis<typename LocalFiniteElement::Traits::LocalBasisType>(cls);
cls.def_property_readonly("localBasis", &LocalFiniteElement::localBasis, pybind11::return_value_policy::reference_internal);
// cls.def_property_readonly("localCoefficients", &LocalFiniteElement::localCoefficients);
// cls.def_property_readonly("localInterpolation", &LocalFiniteElement::localInterpolation);
cls.def("__len__", &LocalFiniteElement::size);
cls.def_property_readonly("type", &LocalFiniteElement::type);
return cls;
}
} /* namespace Python */
} /* namespace Dune */
#endif
add_subdirectory(dune)
configure_file(setup.py.in setup.py)
add_subdirectory(localfunctions)
add_python_targets(dune
__init__
)
__import__('pkg_resources').declare_namespace(__name__)
add_python_targets(localfunctions
__init__
)
dune_add_pybind11_module(NAME _localfunctions)
from __future__ import absolute_import, unicode_literals
from ._localfunctions import *
#include <dune/python/pybind11/pybind11.h>
#include <dune/python/localfunctions/localfiniteelement.hh>
PYBIND11_MODULE(_localfunctions, module)
{
Dune::Python::detail::registerLocalKey(module);
}
from setuptools import setup, find_packages
pkg = [m for m in "${ProjectPythonRequires}".split(' ') if "dune" not in m]
setup(name="${ProjectName}",
namespace_packages=['dune'],
description="${ProjectDescription}",
version="${ProjectVersionString}",
author="${ProjectAuthor}",
author_email="${ProjectMaintainerEmail}",
packages = find_packages(),
zip_safe = 0,
package_data = {'': ['*.so']},
install_requires = pkg
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment