diff --git a/.flake8 b/.flake8 index 95b9d39..b3432bc 100644 --- a/.flake8 +++ b/.flake8 @@ -6,9 +6,10 @@ exclude = .git, .github, build, + cppwg/templates, doc, examples, - cppwg/templates, + _skbuild, tests, venv, diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml deleted file mode 100644 index 36af0e1..0000000 --- a/.github/workflows/build-and-test.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: build-and-test - -on: - workflow_dispatch: - pull_request: - branches: - - "**" - -jobs: - build-and-test: - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - - concurrency: - group: build-and-test-${{ github.ref }}-${{ matrix.python-version }} - cancel-in-progress: true - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install build dependencies - run: | - sudo apt-get update - sudo apt-get install cmake - - - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Install cppwg - run: | - python -m pip install --upgrade pip - pip install .[dev] - - - name: Lint with flake8 - run: python -m flake8 - - - name: Test wrapper generation - run: python -m unittest tests/test_wrapper_generation.py - - - name: Generate new wrappers - run: | - cd examples/shapes/wrapper - rm -rf geometry math_funcs primitives - cd .. - cppwg src/cpp \ - --wrapper_root wrapper/ \ - --package_info wrapper/package_info.yaml \ - --includes src/cpp/*/ extern/*/ \ - --std c++17 \ - --logfile cppwg.log - - - name: Check for new classes - run: | - cd examples/shapes - cat cppwg.log | grep "Unknown class" - - - name: Build Python module - run: | - cd examples/shapes - mkdir build - cd build - cmake .. - make -j $(nproc) - - - name: Test built module - run: | - cd examples/shapes/build - python -m unittest test_functions.py - python -m unittest test_classes.py diff --git a/.github/workflows/test-cells-conda.yml b/.github/workflows/test-cells-conda.yml new file mode 100644 index 0000000..5dfb488 --- /dev/null +++ b/.github/workflows/test-cells-conda.yml @@ -0,0 +1,91 @@ +name: test-cells-conda + +on: + workflow_dispatch: + pull_request: + branches: + - "**" + +jobs: + test-cells-conda: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + + concurrency: + group: test-cells-conda-${{ github.ref }}-${{ matrix.python-version }} + cancel-in-progress: true + + defaults: + run: + shell: bash -el {0} # -l needed to activate conda + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install cmake git + + - name: Setup Miniconda Python ${{ matrix.python-version }} + uses: conda-incubator/setup-miniconda@v3 + with: + auto-update-conda: true + use-mamba: true + miniforge-version: latest + python-version: ${{ matrix.python-version }} + channels: conda-forge + + - name: Install cppwg + run: | + python -m pip install --upgrade pip + python -m pip install . + + - name: Install requirements + run: mamba install --yes --file conda/requirements.txt + working-directory: examples/cells + + - name: Set config paths + run: | + echo "CMAKE_PREFIX_PATH=$CONDA_PREFIX;$CMAKE_PREFIX_PATH" >> $GITHUB_ENV + echo "PETSC_DIR=$CONDA_PREFIX" >> $GITHUB_ENV + echo "PETSC_ARCH=" >> $GITHUB_ENV + echo "VTK_DIR=$CONDA_PREFIX" >> $GITHUB_ENV + + - name: Configure + run: | + mkdir build && cd build + cmake .. + working-directory: examples/cells + + - name: Regenerate wrappers + run: | + rm -rf dynamic/wrappers + cd build + make pycells_wrappers + working-directory: examples/cells + + - name: Check for changes + run: | + git diff --exit-code dynamic/wrappers + grep "Unknown class" build/cppwg.log + working-directory: examples/cells + + - name: Install conda-build tools + run: mamba install boa conda-build conda-verify + + - name: Build + run: conda mambabuild recipe -m variants/python${{ matrix.python-version }}.yaml + working-directory: examples/cells/conda + + - name: Install + run: mamba install --use-local pycells + + - name: Test + run: python -m unittest discover tests + working-directory: examples/cells diff --git a/.github/workflows/test-cells-ubuntu.yml b/.github/workflows/test-cells-ubuntu.yml new file mode 100644 index 0000000..0e8545a --- /dev/null +++ b/.github/workflows/test-cells-ubuntu.yml @@ -0,0 +1,69 @@ +name: test-cells-ubuntu + +on: + workflow_dispatch: + pull_request: + branches: + - "**" + +concurrency: + group: test-cells-ubuntu-${{ github.ref }} + cancel-in-progress: true + +jobs: + test-cells-ubuntu: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install \ + cmake \ + git \ + libboost-all-dev \ + libpetsc-real3.15 \ + libpetsc-real3.15-dbg \ + libpetsc-real3.15-dev \ + libvtk9-dev \ + mpi-default-bin \ + mpi-default-dev \ + python3-mpi4py \ + python3-petsc4py-real3.15 \ + python3-vtk9 \ + vtk9 + + - name: Install cppwg + run: | + python -m pip install --upgrade pip + python -m pip install . + + - name: Configure + run: | + mkdir build && cd build + cmake .. + working-directory: examples/cells + + - name: Regenerate wrappers + run: | + rm -rf dynamic/wrappers + cd build + make pycells_wrappers + working-directory: examples/cells + + - name: Check for changes + run: | + git diff --exit-code dynamic/wrappers + grep "Unknown class" build/cppwg.log + working-directory: examples/cells + + - name: Build + run: python -m pip install -v . + working-directory: examples/cells + + - name: Test + run: python -m unittest discover tests + working-directory: examples/cells diff --git a/.github/workflows/test-shapes-pip.yml b/.github/workflows/test-shapes-pip.yml new file mode 100644 index 0000000..bea7477 --- /dev/null +++ b/.github/workflows/test-shapes-pip.yml @@ -0,0 +1,72 @@ +name: test-shapes-pip + +on: + workflow_dispatch: + pull_request: + branches: + - "**" + +jobs: + test-shapes-pip: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + + concurrency: + group: test-shapes-pip-${{ github.ref }}-${{ matrix.python-version }} + cancel-in-progress: true + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install cmake git + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install cppwg + run: | + python -m pip install --upgrade pip + python -m pip install . + + - name: Regenerate wrappers + run: | + rm -rf wrapper/*/ + cppwg src/cpp \ + --wrapper_root wrapper/ \ + --package_info wrapper/package_info.yaml \ + --includes src/cpp/*/ \ + --std c++17 \ + --logfile cppwg.log + working-directory: examples/shapes + + - name: Check for changes + run: | + git diff --exit-code wrapper + grep "Unknown class" cppwg.log + working-directory: examples/shapes + + - name: Configure + run: | + mkdir build && cd build + cmake .. + working-directory: examples/shapes + + - name: Build + run: make -j $(nproc) + working-directory: examples/shapes/build + + - name: Test + run: | + python -m unittest test_functions.py + python -m unittest test_classes.py + working-directory: examples/shapes/build diff --git a/.github/workflows/test-style.yml b/.github/workflows/test-style.yml new file mode 100644 index 0000000..7a9038d --- /dev/null +++ b/.github/workflows/test-style.yml @@ -0,0 +1,34 @@ +name: test-style + +on: + workflow_dispatch: + pull_request: + branches: + - "**" + +concurrency: + group: test-style-${{ github.ref }} + cancel-in-progress: true + +jobs: + test-style: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get update && \ + sudo apt-get install cmake + + - name: Install cppwg + run: | + python -m pip install --upgrade pip + python -m pip install .[dev] + + - name: Lint + run: | + python -m flake8 --version + python -m flake8 . diff --git a/.gitignore b/.gitignore index a40bdea..a3c89df 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ __pycache__/ .Python env/ build/ +_skbuild/ develop-eggs/ dist/ downloads/ diff --git a/README.md b/README.md index 1da1836..be70715 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -![build](https://github.com/Chaste/cppwg/actions/workflows/build-and-test.yml/badge.svg) +![pip](https://github.com/Chaste/cppwg/actions/workflows/test-shapes-pip.yml/badge.svg) +![ubuntu](https://github.com/Chaste/cppwg/actions/workflows/test-cells-ubuntu.yml/badge.svg) +![conda](https://github.com/Chaste/cppwg/actions/workflows/test-cells-conda.yml/badge.svg) # cppwg @@ -89,7 +91,7 @@ cd examples/shapes cppwg src/cpp \ --wrapper_root wrapper \ --package_info wrapper/package_info.yaml \ - --includes src/cpp/geometry src/cpp/math_funcs src/cpp/mesh src/cpp/primitives extern/meshgen + --includes src/cpp/geometry src/cpp/math_funcs src/cpp/mesh src/cpp/primitives ``` For the `Rectangle` class, this creates two files in diff --git a/cppwg/info/base_info.py b/cppwg/info/base_info.py index f777ace..1c35d86 100644 --- a/cppwg/info/base_info.py +++ b/cppwg/info/base_info.py @@ -106,7 +106,6 @@ def __init__(self, name: str, info_config: Optional[Dict[str, Any]] = None) -> N "unsigned int": "Unsigned", "Unsigned int": "Unsigned", "unsigned": "Unsigned", - "double": "Double", "std::vector": "Vector", "std::pair": "Pair", "std::map": "Map", diff --git a/cppwg/info/class_info.py b/cppwg/info/class_info.py index 1388ce3..ff1cf8e 100644 --- a/cppwg/info/class_info.py +++ b/cppwg/info/class_info.py @@ -305,7 +305,9 @@ class instantiation. For example, class "Foo" with template arguments arg_str = arg_str.replace(name, replacement) # Remove special characters - arg_str = arg_str.translate(rm_table) + arg_str = ( + arg_str.replace("<", "_").replace(",", "_").translate(rm_table) + ) # Capitalize the first letter if len(arg_str) > 1: diff --git a/examples/cells/CMakeLists.txt b/examples/cells/CMakeLists.txt new file mode 100644 index 0000000..e67d6d3 --- /dev/null +++ b/examples/cells/CMakeLists.txt @@ -0,0 +1,112 @@ +cmake_minimum_required(VERSION 3.16...3.22) +project(pycells LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) + +# Find Python +find_package(Python3 REQUIRED COMPONENTS Interpreter Development) + +# Find Boost +find_package (Boost REQUIRED) + +# Find VTK +foreach(_core_module vtkCommonCore CommonCore) + find_package(VTK COMPONENTS ${_core_module} QUIET) + if(VTK_FOUND) + break() + endif() +endforeach() + +if(VTK_VERSION VERSION_LESS 9.0.0) + find_package(VTK REQUIRED COMPONENTS vtkCommonCore vtkRenderingCore vtkRenderingOpenGL2 vtkWrappingPythonCore) +else() + find_package(VTK REQUIRED COMPONENTS CommonCore RenderingCore RenderingOpenGL2 WrappingPythonCore) +endif() + +message(STATUS "VTK version: ${VTK_VERSION}") + +# Find PETSc +find_package(PETSc REQUIRED) + +# Find PETSc4py +find_package(PETSc4py REQUIRED) + +# Find MPI +find_package(MPI REQUIRED COMPONENTS CXX) + +# Fetch pybind11 +include(FetchContent) +FetchContent_Declare( + pybind11 + GIT_REPOSITORY https://github.com/pybind/pybind11 + GIT_TAG v2.13.6 + GIT_SHALLOW 1 +) +FetchContent_MakeAvailable(pybind11) + +# Add a shared library target for the main C++ source +file(GLOB_RECURSE MAIN_SOURCES + ${CMAKE_SOURCE_DIR}/src/cpp/*.cpp + ${CMAKE_SOURCE_DIR}/src/cpp/*.hpp +) +add_library(cells SHARED ${MAIN_SOURCES}) +target_link_libraries(cells PUBLIC + ${Boost_LIBRARIES} + ${VTK_LIBRARIES} + ${PETSC_LIBRARIES} + ${MPI_C_LIBRARIES} + ${MPI_CXX_LIBRARIES} +) +target_include_directories(cells PUBLIC + ${CMAKE_SOURCE_DIR}/src/cpp + ${CMAKE_SOURCE_DIR}/src/cpp/cell + ${CMAKE_SOURCE_DIR}/src/cpp/mesh + ${CMAKE_SOURCE_DIR}/src/cpp/utils + ${CMAKE_SOURCE_DIR}/src/cpp/visualization + ${Boost_INCLUDE_DIR} + ${VTK_INCLUDE_DIRS} + ${PETSC_INCLUDES} + ${MPI_C_INCLUDE_PATH} + ${MPI_CXX_INCLUDE_PATH} +) + +# Set up the pycells module with pybind11 +file(GLOB WRAPPER_SOURCES + ${CMAKE_SOURCE_DIR}/dynamic/wrappers/all/*.cpp + ${CMAKE_SOURCE_DIR}/dynamic/wrappers/all/*.hpp +) +pybind11_add_module(_pycells_all MODULE ${WRAPPER_SOURCES}) +target_link_libraries(_pycells_all PRIVATE cells) +target_include_directories(_pycells_all PRIVATE + ${CMAKE_SOURCE_DIR}/dynamic/wrappers/all + ${CMAKE_SOURCE_DIR}/dynamic/typecasters/ + ${CMAKE_SOURCE_DIR}/dynamic/typecasters/thirdparty/dolfinx + ${CMAKE_SOURCE_DIR}/dynamic/typecasters/thirdparty/smtk + ${PETSC4PY_INCLUDES} +) + +# Add install targets for scikit-build +if(SKBUILD) + set_target_properties(_pycells_all PROPERTIES + SKIP_BUILD_RPATH FALSE + BUILD_WITH_INSTALL_RPATH FALSE + INSTALL_RPATH_USE_LINK_PATH TRUE + INSTALL_RPATH $ORIGIN + ) + install(TARGETS cells LIBRARY DESTINATION .) + install(TARGETS _pycells_all LIBRARY DESTINATION .) +endif() + +# Target for re-generating wrappers +add_custom_target(pycells_wrappers + COMMAND ${Python3_EXECUTABLE} -m cppwg ${CMAKE_SOURCE_DIR}/src/cpp + -w ${CMAKE_SOURCE_DIR}/dynamic/wrappers + -p ${CMAKE_SOURCE_DIR}/dynamic/config.yaml + -i "$,;>" + -l ${CMAKE_BINARY_DIR}/cppwg.log + --std c++17 + COMMAND_EXPAND_LISTS +) diff --git a/examples/cells/cmake/FindPETSc.cmake b/examples/cells/cmake/FindPETSc.cmake new file mode 100644 index 0000000..d15d3f5 --- /dev/null +++ b/examples/cells/cmake/FindPETSc.cmake @@ -0,0 +1,219 @@ +# - Try to find PETSc +# Once done this will define +# +# PETSC_FOUND - system has PETSc +# PETSC_INCLUDES - the PETSc include directories +# PETSC_LIBRARIES - link these to use PETSc +# PETSC_VERSION - version string (MAJOR.MINOR.SUBMINOR) +# +# Setting these changes the behavior of the search +# PETSC_DIR - directory in which PETSc resides +# PETSC_ARCH - build architecture +# +# Usage: find_package(PETSc) +# +#============================================================================= +# This file is based on https://github.com/jedbrown/cmake-modules.git +# (BSD 2-clause License) +# +# Copyright the authors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, this +# list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +# Set PETSC_DIR +# Ubuntu uses versioned paths e.g /usr/lib/petscdir/petsc3.15/x86_64-linux-gnu-real +file(GLOB ubuntu_paths "/usr/lib/petscdir/*") + +find_path( + PETSC_DIR + include/petsc.h + HINTS ENV PETSC_DIR + PATHS /usr/lib/petsc ${ubuntu_paths} + DOC "PETSc Directory" +) + +# Set PETSC_ARCH +if(PETSC_DIR AND NOT PETSC_ARCH) + foreach(_arch $ENV{PETSC_ARCH} x86_64-linux-gnu-real x86_64-linux-gnu-real-debug) + find_path( + petscconf + petscconf.h + HINTS ${PETSC_DIR} + PATH_SUFFIXES ${_arch}/include + NO_DEFAULT_PATH + ) + if(petscconf) + set(PETSC_ARCH "${_arch}" CACHE STRING "PETSc build architecture") + break() + endif() + endforeach() +endif() + +# Check for PETSc config files +if(EXISTS "${PETSC_DIR}/include/petscversion.h" AND + EXISTS "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/rules" AND + EXISTS "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables") + set(petsc_version_h "${PETSC_DIR}/include/petscversion.h") + set(petsc_conf_rules "${PETSC_DIR}/lib/petsc/conf/rules") + set(petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables") +else() + message(SEND_ERROR "The pair PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} do not specify a valid PETSc installation") +endif() + +# Get the PETSc version +file(STRINGS "${petsc_version_h}" _vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ") +foreach(_line ${_vstrings}) + string(REGEX REPLACE " +" ";" _fields ${_line}) # break line into three fields (the first is always "#define") + list(GET _fields 1 _var) + list(GET _fields 2 _val) + set(${_var} ${_val}) +endforeach() + +set(_version "${PETSC_VERSION_MAJOR}.${PETSC_VERSION_MINOR}.${PETSC_VERSION_SUBMINOR}") + +if(PETSC_VERSION_RELEASE) + if($(PETSC_VERSION_PATCH) GREATER 0) + set(_version "${_version}p${PETSC_VERSION_PATCH}") + endif() +else() + # make dev version compare higher than any patch level of a released version + set(_version "${_version}.99") +endif() +set(PETSC_VERSION "${_version}" CACHE INTERNAL "PETSc version") + +# A temporary makefile to probe the PETSc configuration +set(ENV{PETSC_DIR} "${PETSC_DIR}") +set(ENV{PETSC_ARCH} "${PETSC_ARCH}") +set(petsc_config_makefile "${PROJECT_BINARY_DIR}/Makefile.petsc") +file(WRITE "${petsc_config_makefile}" +"## This file was autogenerated by FindPETSc.cmake +# PETSC_DIR = ${PETSC_DIR} +# PETSC_ARCH = ${PETSC_ARCH} +include ${petsc_conf_rules} +include ${petsc_conf_variables} +show : +\t-@echo -n \${\${VARIABLE}} +") + +find_program(MAKE_EXECUTABLE NAMES make gmake) + +macro(PETSC_GET_VARIABLE name var) + set(${var} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) + execute_process( + COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} show VARIABLE=${name} + OUTPUT_VARIABLE ${var} + ) +endmacro() + +# Extract include paths from compile command line +petsc_get_variable(PETSC_CCPPFLAGS petsc_ccpp_flags) + +string(REGEX MATCHALL "-I([^\" ]+|\"[^\"]+\")" _all_tokens "${petsc_ccpp_flags}") + set(_incs_found "") + foreach(_token ${_all_tokens}) + string(REGEX REPLACE "^-I" "" _token ${_token}) + string(REGEX REPLACE "//" "/" _token ${_token}) + if(EXISTS ${_token}) + list(APPEND _incs_found ${_token}) + else() + message(STATUS "Include directory ${_token} does not exist") + endif() + endforeach() + list(REMOVE_DUPLICATES _incs_found) +set(PETSC_INCLUDES_ALL "${_incs_found}") + +# Find PETSc libraries +petsc_get_variable(PETSC_LIB_DIR petsc_lib_dir) +message(STATUS "petsc_lib_dir ${petsc_lib_dir}") + +macro(PETSC_FIND_LIBRARY suffix name) + set(PETSC_LIBRARY_${suffix} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # Clear any stale value, if we got here, we need to find it again + find_library(PETSC_LIBRARY_${suffix} NAMES ${name} HINTS ${petsc_lib_dir} NO_DEFAULT_PATH) + set(PETSC_LIBRARIES_${suffix} "${PETSC_LIBRARY_${suffix}}") + mark_as_advanced(PETSC_LIBRARY_${suffix}) +endmacro() + +# Look for petscvec first, if it doesn't exist, we must be using single-library +petsc_find_library(VEC petscvec) +if(PETSC_LIBRARY_VEC) + petsc_find_library(SYS petscsys) + petsc_find_library(MAT petscmat) + petsc_find_library(DM petscdm) + petsc_find_library(KSP petscksp) + petsc_find_library(SNES petscsnes) + petsc_find_library(TS petscts) + set(PETSC_LIBRARIES_ALL + ${PETSC_LIBRARY_SYS} + ${PETSC_LIBRARY_VEC} + ${PETSC_LIBRARY_MAT} + ${PETSC_LIBRARY_DM} + ${PETSC_LIBRARY_KSP} + ${PETSC_LIBRARY_SNES} + ${PETSC_LIBRARY_TS} + ) +else() + set(PETSC_LIBRARY_VEC "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) + petsc_find_library(SINGLE petsc) + # Ubuntu uses _real and _complex extensions + if(NOT PETSC_LIBRARY_SINGLE) + petsc_find_library(SINGLE petsc_real) + endif() + if(NOT PETSC_LIBRARY_SINGLE) + petsc_find_library(SINGLE petsc_complex) + endif() + set(PETSC_LIBRARIES_ALL "${PETSC_LIBRARY_SINGLE}") +endif() + +if(PETSC_LIBRARY_TS) + message(STATUS "Recognized PETSc install with separate libraries for each package") +else() + message(STATUS "Recognized PETSc install with single library for all packages") +endif() + +# We do an out-of-source build so __FILE__ will be an absolute path, hence __INSDIR__ is superfluous +set(PETSC_DEFINITIONS "-D__INSDIR__=" CACHE STRING "PETSc definitions" FORCE) + +set(PETSC_INCLUDES ${PETSC_INCLUDES_ALL} CACHE STRING "PETSc include path" FORCE) +set(PETSC_LIBRARIES ${PETSC_LIBRARIES_ALL} CACHE STRING "PETSc libraries" FORCE) + +# Sometimes this can be used to assist FindMPI.cmake +petsc_get_variable(PCC petsc_cc) +petsc_get_variable(MPIEXEC petsc_mpiexec) +set(PETSC_COMPILER ${petsc_cc} CACHE FILEPATH "PETSc compiler" FORCE) +set(PETSC_MPIEXEC ${petsc_mpiexec} CACHE FILEPATH "Executable for running PETSc MPI programs" FORCE) + +# Note that we have forced values for all these choices. If you +# change these, you are telling the system to trust you that they +# work. It is likely that you will end up with a broken build. +mark_as_advanced(PETSC_INCLUDES PETSC_LIBRARIES PETSC_COMPILER PETSC_DEFINITIONS PETSC_MPIEXEC) + +file(REMOVE ${petsc_config_makefile}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + PETSc + REQUIRED_VARS PETSC_INCLUDES PETSC_LIBRARIES + VERSION_VAR PETSC_VERSION + FAIL_MESSAGE "PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH." +) diff --git a/examples/cells/cmake/FindPETSc4py.cmake b/examples/cells/cmake/FindPETSc4py.cmake new file mode 100644 index 0000000..42a0792 --- /dev/null +++ b/examples/cells/cmake/FindPETSc4py.cmake @@ -0,0 +1,30 @@ +# - Try to find petsc4py +# Once done this will define +# +# PETSC4PY_FOUND - system has petsc4py +# PETSC4PY_INCLUDES - the petsc4py include directories +# PETSC4PY_VERSION - version string (MAJOR.MINOR.SUBMINOR) +# +# Usage: find_package(PETSc4py) + +execute_process( + COMMAND ${Python3_EXECUTABLE} -c "import petsc4py; print(petsc4py.get_include(), end='')" + OUTPUT_VARIABLE PETSC4PY_INCLUDES +) + +if(PETSC4PY_INCLUDES) + execute_process( + COMMAND ${Python3_EXECUTABLE} -c "import petsc4py; print(petsc4py.__version__, end='')" + OUTPUT_VARIABLE PETSC4PY_VERSION + ) +endif() + +mark_as_advanced(PETSC4PY_INCLUDES, PETSC4PY_VERSION) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + PETSc4py + REQUIRED_VARS PETSC4PY_INCLUDES + VERSION_VAR PETSC4PY_VERSION + FAIL_MESSAGE "PETSc4py could not be found." +) diff --git a/examples/cells/conda/recipe/build.sh b/examples/cells/conda/recipe/build.sh new file mode 100644 index 0000000..7dd38b3 --- /dev/null +++ b/examples/cells/conda/recipe/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash -ex + +export CMAKE_PREFIX_PATH="$PREFIX;$CMAKE_PREFIX_PATH" +export PETSC_DIR="$PREFIX" +export PETSC_ARCH= +export VTK_DIR="$PREFIX" + +$PYTHON -m pip install -v --no-build-isolation . diff --git a/examples/cells/conda/recipe/meta.yaml b/examples/cells/conda/recipe/meta.yaml new file mode 100644 index 0000000..9095ded --- /dev/null +++ b/examples/cells/conda/recipe/meta.yaml @@ -0,0 +1,31 @@ +{% set version = "0.0.1" %} +{% set build = 0 %} + +package: + name: pycells + version: {{ version }} + +source: + path: ../.. + +build: + number: {{ build }} + +requirements: + host: + - boost-cpp + - mpi4py + - openmpi + - petsc + - petsc4py + - pip + - python + - scikit-build-core + - vtk + +test: + imports: + - pycells + +about: + license: BSD-3-Clause diff --git a/examples/cells/conda/requirements.txt b/examples/cells/conda/requirements.txt new file mode 100644 index 0000000..6d4615c --- /dev/null +++ b/examples/cells/conda/requirements.txt @@ -0,0 +1,6 @@ +boost-cpp +mpi4py +openmpi +petsc +petsc4py +vtk diff --git a/examples/cells/conda/variants/python3.10.yaml b/examples/cells/conda/variants/python3.10.yaml new file mode 100644 index 0000000..49527e1 --- /dev/null +++ b/examples/cells/conda/variants/python3.10.yaml @@ -0,0 +1,2 @@ +python: + - 3.10.* diff --git a/examples/cells/conda/variants/python3.11.yaml b/examples/cells/conda/variants/python3.11.yaml new file mode 100644 index 0000000..b2289ba --- /dev/null +++ b/examples/cells/conda/variants/python3.11.yaml @@ -0,0 +1,2 @@ +python: + - 3.11.* diff --git a/examples/cells/conda/variants/python3.12.yaml b/examples/cells/conda/variants/python3.12.yaml new file mode 100644 index 0000000..1df82ad --- /dev/null +++ b/examples/cells/conda/variants/python3.12.yaml @@ -0,0 +1,2 @@ +python: + - 3.12.* diff --git a/examples/cells/conda/variants/python3.13.yaml b/examples/cells/conda/variants/python3.13.yaml new file mode 100644 index 0000000..13edda7 --- /dev/null +++ b/examples/cells/conda/variants/python3.13.yaml @@ -0,0 +1,2 @@ +python: + - 3.13.* diff --git a/examples/cells/conda/variants/python3.8.yaml b/examples/cells/conda/variants/python3.8.yaml new file mode 100644 index 0000000..b34e9cc --- /dev/null +++ b/examples/cells/conda/variants/python3.8.yaml @@ -0,0 +1,2 @@ +python: + - 3.8.* diff --git a/examples/cells/conda/variants/python3.9.yaml b/examples/cells/conda/variants/python3.9.yaml new file mode 100644 index 0000000..f305cf2 --- /dev/null +++ b/examples/cells/conda/variants/python3.9.yaml @@ -0,0 +1,2 @@ +python: + - 3.9.* diff --git a/examples/cells/dynamic/config.yaml b/examples/cells/dynamic/config.yaml new file mode 100644 index 0000000..044db50 --- /dev/null +++ b/examples/cells/dynamic/config.yaml @@ -0,0 +1,63 @@ +# For docs on config options, see examples/shapes/wrapper/package_info.yaml +name: pycells + +smart_ptr_type: std::shared_ptr +pointer_call_policy: reference +reference_call_policy: reference_internal + +common_include_file: False +source_includes: + - + +exclude_default_args: False + +template_substitutions: + - signature: + replacement: [[2], [3]] + - signature: + replacement: [[2], [3]] + - signature: + replacement: [[2, 2], [3, 3]] + - signature: + replacement: [[2, 2], [3, 3]] + +modules: + - name: all + source_locations: + - cell + - mesh + - utils + - visualization + + classes: + # cell + - name: Cell + + # mesh + - name: AbstractMesh + + - name: MeshFactory + source_includes: + - PottsMesh.hpp + template_substitutions: + - signature: + replacement: [["PottsMesh<2>"], ["PottsMesh<3>"]] + + - name: Node + source_includes: + - PybindUblasTypeCaster.hpp + + - name: PottsMesh + + # utils + - name: PetscUtils + source_includes: + - caster_petsc.h + + # visualization + - name: Scene + source_includes: + - PybindVTKTypeCaster.h + +prefix_text: | + // This file is auto-generated by cppwg; manual changes will be overwritten. diff --git a/examples/cells/dynamic/typecasters/PybindUblasTypeCaster.hpp b/examples/cells/dynamic/typecasters/PybindUblasTypeCaster.hpp new file mode 100644 index 0000000..64ccc6d --- /dev/null +++ b/examples/cells/dynamic/typecasters/PybindUblasTypeCaster.hpp @@ -0,0 +1,97 @@ +/* + +Copyright (c) 2005-2024, University of Oxford. +All rights reserved. + +University of Oxford means the Chancellor, Masters and Scholars of the +University of Oxford, having an administrative office at Wellington +Square, Oxford OX1 2JD, UK. + +This file is part of Chaste. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the University of Oxford nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef PYBINDUBLASTYPECASTER_HPP_ +#define PYBINDUBLASTYPECASTER_HPP_ + +#include + +#include +#include +#include + +#define PYBIND11_CVECTOR_TYPECASTER(T, N) \ + namespace pybind11 \ + { \ + namespace detail \ + { \ + template <> \ + struct type_caster > \ + { \ + public: \ + typedef boost::numeric::ublas::c_vector c_vector_##T##_##N##_t; \ + PYBIND11_TYPE_CASTER(c_vector_##T##_##N##_t, const_name("c_vector_" #T "_" #N "_t")); \ + bool load(handle src, bool convert) \ + { \ + if (!convert && !array_t::check_(src)) \ + { \ + return false; \ + } \ + auto buf = array_t::ensure(src); \ + if (!buf) \ + { \ + return false; \ + } \ + if (buf.ndim() != 1 or buf.shape()[0] != N) \ + { \ + return false; \ + } \ + value.resize(N); \ + for (unsigned i = 0; i < N; ++i) \ + { \ + value[i] = buf.data()[i]; \ + } \ + return true; \ + } \ + static handle cast(const boost::numeric::ublas::c_vector& src, \ + return_value_policy, \ + handle) \ + { \ + std::vector shape(1, N); \ + std::vector strides(1, sizeof(T)); \ + T* data = src.size() ? const_cast(&src[0]) : static_cast(NULL); \ + array a(std::move(shape), std::move(strides), data); \ + return a.release(); \ + } \ + }; \ + } \ + } + +PYBIND11_CVECTOR_TYPECASTER(double, 2); +PYBIND11_CVECTOR_TYPECASTER(double, 3); + +#undef PYBIND11_CVECTOR_TYPECASTER + +#endif // PYBINDUBLASTYPECASTER_HPP_ diff --git a/examples/cells/dynamic/typecasters/thirdparty/dolfinx/COPYING b/examples/cells/dynamic/typecasters/thirdparty/dolfinx/COPYING new file mode 100644 index 0000000..85f73fd --- /dev/null +++ b/examples/cells/dynamic/typecasters/thirdparty/dolfinx/COPYING @@ -0,0 +1,680 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + + +Note: Individual files contain the following tag instead of the full license text. + +SPDX-License-Identifier: LGPL-3.0-or-later +This enables machine processing of license information based on the SPDX License Identifiers that are here available: http://spdx.org/licenses/ \ No newline at end of file diff --git a/examples/cells/dynamic/typecasters/thirdparty/dolfinx/COPYING.LESSER b/examples/cells/dynamic/typecasters/thirdparty/dolfinx/COPYING.LESSER new file mode 100644 index 0000000..491226c --- /dev/null +++ b/examples/cells/dynamic/typecasters/thirdparty/dolfinx/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/examples/cells/dynamic/typecasters/thirdparty/dolfinx/caster_petsc.h b/examples/cells/dynamic/typecasters/thirdparty/dolfinx/caster_petsc.h new file mode 100644 index 0000000..0b926f1 --- /dev/null +++ b/examples/cells/dynamic/typecasters/thirdparty/dolfinx/caster_petsc.h @@ -0,0 +1,83 @@ +// Copyright (C) 2017-2023 Chris Richardson and Garth N. Wells +// +// This file is part of DOLFINx (https://www.fenicsproject.org) +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef CASTER_PETSC_H_ +#define CASTER_PETSC_H_ + +#include +#include + +#include +#include +#include + +// pybind11 casters for PETSc/petsc4py objects + +// Import petsc4py on demand +#define VERIFY_PETSC4PY_FROMPY(func) \ + if (!func) \ + { \ + if (import_petsc4py() != 0) \ + return false; \ + } + +#define VERIFY_PETSC4PY_FROMCPP(func) \ + if (!func) \ + { \ + if (import_petsc4py() != 0) \ + return {}; \ + } + +// Macro for casting between PETSc and petsc4py objects +#define PETSC_CASTER_MACRO(TYPE, P4PYTYPE, NAME) \ + template <> \ + class type_caster<_p_##TYPE> \ + { \ + public: \ + PYBIND11_TYPE_CASTER(TYPE, const_name(#NAME)); \ + bool load(handle src, bool) \ + { \ + VERIFY_PETSC4PY_FROMPY(PyPetsc##P4PYTYPE##_Get); \ + if (PyObject_TypeCheck(src.ptr(), &PyPetsc##P4PYTYPE##_Type) != 0) \ + { \ + value = PyPetsc##P4PYTYPE##_Get(src.ptr()); \ + return true; \ + } \ + else \ + return false; \ + } \ + \ + static handle cast(TYPE src, return_value_policy policy, handle) \ + { \ + VERIFY_PETSC4PY_FROMCPP(PyPetsc##P4PYTYPE##_New); \ + if (policy == return_value_policy::take_ownership) \ + { \ + PyObject *obj = PyPetsc##P4PYTYPE##_New(src); \ + PetscObjectDereference((PetscObject)src); \ + return pybind11::handle(obj); \ + } \ + else if (policy == return_value_policy::automatic_reference or \ + policy == return_value_policy::reference) \ + { \ + PyObject *obj = PyPetsc##P4PYTYPE##_New(src); \ + return pybind11::handle(obj); \ + } \ + else \ + { \ + return {}; \ + } \ + } \ + \ + operator TYPE() { return value; } \ + } + +namespace pybind11::detail +{ + PETSC_CASTER_MACRO(Mat, Mat, mat); + PETSC_CASTER_MACRO(Vec, Vec, vec); +} // namespace pybind11::detail + +#endif // CASTER_PETSC_H_ diff --git a/examples/cells/dynamic/typecasters/thirdparty/smtk/LICENSE.txt b/examples/cells/dynamic/typecasters/thirdparty/smtk/LICENSE.txt new file mode 100644 index 0000000..0f0d7b8 --- /dev/null +++ b/examples/cells/dynamic/typecasters/thirdparty/smtk/LICENSE.txt @@ -0,0 +1,38 @@ +SMTK License Version 1.0 +======================================================================== +Copyright (c) 2012 Kitware Inc. 28 Corporate Drive +Clifton Park, NY, 12065, USA. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of Kitware nor the names of any contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The following files and directories come from third parties. Check the +contents of these for details on the specifics of their respective +licenses. +- - - - - - - - - - - - - - - - - - - - - - - - +Thirdparty/pugixml +Thirdparty/PyYaml +Thidpary/rtvl +CMake/FindDocutils.cmake diff --git a/examples/cells/dynamic/typecasters/thirdparty/smtk/PybindVTKTypeCaster.h b/examples/cells/dynamic/typecasters/thirdparty/smtk/PybindVTKTypeCaster.h new file mode 100644 index 0000000..62218dc --- /dev/null +++ b/examples/cells/dynamic/typecasters/thirdparty/smtk/PybindVTKTypeCaster.h @@ -0,0 +1,139 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= + +#ifndef pybind_extension_vtk_source_VTKTypeCaster_h +#define pybind_extension_vtk_source_VTKTypeCaster_h + +#include +#include + +#include + +#include "vtkNew.h" +#include "vtkObjectBase.h" +#include "vtkPythonUtil.h" +#include "vtkSmartPointer.h" + +namespace pybind11 +{ +namespace detail +{ + +/// Thanks to Eric Cosineau, who figured out a more general means of casting +/// to/from VTK's python wrappings: +/// https://github.com/EricCousineau-TRI/repro/blob/b9e02d6d5a71f6315b80759ba1628b4bb383c0b8/python/vtk_pybind/vtk_pybind.h + +/// Direct access to VTK class. +template +struct type_caster::value> > +{ +private: + Class* value; + +public: + static constexpr auto name = _(); + + static handle cast(const Class* src, return_value_policy policy, handle /*parent*/) + { + if (!src) + return none().release(); + if (policy == return_value_policy::take_ownership) + { + throw cast_error("vtk_pybind: `take_ownership` does not make sense in VTK?"); + } + if (policy == return_value_policy::copy) + { + throw cast_error("vtk_pybind: `copy` does not make sense in VTK?"); + } + return vtkPythonUtil::GetObjectFromPointer(const_cast(src)); + } + + static handle cast(const Class& src, return_value_policy policy, handle parent) + { + return cast(&src, policy, parent); + } + + operator Class*() { return value; } + operator Class&() { return *value; } + // Does this even make sense in VTK? + operator Class &&() && { return std::move(*value); } + + template + using cast_op_type = pybind11::detail::movable_cast_op_type; + + bool load(handle src, bool /* convert */) + { + value = dynamic_cast( + vtkPythonUtil::GetPointerFromObject(src.ptr(), type_id().c_str())); + return value != nullptr; + } +}; + +/// VTK Pointer-like object - may be non-copyable. +template +struct vtk_ptr_cast_only +{ +protected: + using Class = intrinsic_t())>; + using value_caster_type = type_caster; + +public: + static constexpr auto name = _(); + static handle cast(const Ptr& ptr, return_value_policy policy, handle parent) + { + return value_caster_type::cast(*ptr, policy, parent); + ; + } +}; + +/// VTK Pointer-like object - copyable / movable. +template +struct vtk_ptr_cast_and_load : public vtk_ptr_cast_only +{ +private: + Ptr value; + // N.B. Can't easily access base versions... + using Class = intrinsic_t())>; + using value_caster_type = type_caster; + +public: + operator Ptr&() { return value; } + // Does this even make sense in VTK? + operator Ptr &&() && { return std::move(value); } + + template + using cast_op_type = pybind11::detail::movable_cast_op_type; + + bool load(handle src, bool convert) + { + value_caster_type value_caster; + if (!value_caster.load(src, convert)) + { + return false; + } + value = Ptr(value_caster.operator Class*()); + return true; + } +}; + +template +struct type_caster > : public vtk_ptr_cast_and_load > +{ +}; + +template +struct type_caster > : public vtk_ptr_cast_only > +{ +}; + +} // namespace detail +} // namespace pybind11 + +#endif diff --git a/examples/shapes/wrapper/mesh/AbstractMesh_2_2.cppwg.cpp b/examples/cells/dynamic/wrappers/all/AbstractMesh_2_2.cppwg.cpp similarity index 80% rename from examples/shapes/wrapper/mesh/AbstractMesh_2_2.cppwg.cpp rename to examples/cells/dynamic/wrappers/all/AbstractMesh_2_2.cppwg.cpp index b2a60a7..ed81b5f 100644 --- a/examples/shapes/wrapper/mesh/AbstractMesh_2_2.cppwg.cpp +++ b/examples/cells/dynamic/wrappers/all/AbstractMesh_2_2.cppwg.cpp @@ -1,9 +1,9 @@ -// This file is automatically generated by cppwg. -// Do not modify this file directly. +// This file is auto-generated by cppwg; manual changes will be overwritten. #include #include -#include "wrapper_header_collection.cppwg.hpp" +#include +#include "AbstractMesh.hpp" #include "AbstractMesh_2_2.cppwg.hpp" @@ -35,9 +35,9 @@ void register_AbstractMesh_2_2_class(py::module &m) .def("SetIndex", (void(AbstractMesh_2_2::*)(unsigned int)) &AbstractMesh_2_2::SetIndex, " ", py::arg("index")) - .def("AddVertex", - (void(AbstractMesh_2_2::*)(::Point<2>)) &AbstractMesh_2_2::AddVertex, - " ", py::arg("vertex")) + .def("AddNode", + (void(AbstractMesh_2_2::*)(::Node<2>)) &AbstractMesh_2_2::AddNode, + " ", py::arg("node")) .def("Scale", (void(AbstractMesh_2_2::*)(double const)) &AbstractMesh_2_2::Scale, " ", py::arg("factor")) diff --git a/examples/shapes/wrapper/mesh/AbstractMesh_2_2.cppwg.hpp b/examples/cells/dynamic/wrappers/all/AbstractMesh_2_2.cppwg.hpp similarity index 72% rename from examples/shapes/wrapper/mesh/AbstractMesh_2_2.cppwg.hpp rename to examples/cells/dynamic/wrappers/all/AbstractMesh_2_2.cppwg.hpp index e565615..c1503c6 100644 --- a/examples/shapes/wrapper/mesh/AbstractMesh_2_2.cppwg.hpp +++ b/examples/cells/dynamic/wrappers/all/AbstractMesh_2_2.cppwg.hpp @@ -1,5 +1,4 @@ -// This file is automatically generated by cppwg. -// Do not modify this file directly. +// This file is auto-generated by cppwg; manual changes will be overwritten. #ifndef AbstractMesh_2_2_hpp__cppwg_wrapper #define AbstractMesh_2_2_hpp__cppwg_wrapper diff --git a/examples/shapes/wrapper/mesh/AbstractMesh_3_3.cppwg.cpp b/examples/cells/dynamic/wrappers/all/AbstractMesh_3_3.cppwg.cpp similarity index 80% rename from examples/shapes/wrapper/mesh/AbstractMesh_3_3.cppwg.cpp rename to examples/cells/dynamic/wrappers/all/AbstractMesh_3_3.cppwg.cpp index f5b2b97..c56583b 100644 --- a/examples/shapes/wrapper/mesh/AbstractMesh_3_3.cppwg.cpp +++ b/examples/cells/dynamic/wrappers/all/AbstractMesh_3_3.cppwg.cpp @@ -1,9 +1,9 @@ -// This file is automatically generated by cppwg. -// Do not modify this file directly. +// This file is auto-generated by cppwg; manual changes will be overwritten. #include #include -#include "wrapper_header_collection.cppwg.hpp" +#include +#include "AbstractMesh.hpp" #include "AbstractMesh_3_3.cppwg.hpp" @@ -35,9 +35,9 @@ void register_AbstractMesh_3_3_class(py::module &m) .def("SetIndex", (void(AbstractMesh_3_3::*)(unsigned int)) &AbstractMesh_3_3::SetIndex, " ", py::arg("index")) - .def("AddVertex", - (void(AbstractMesh_3_3::*)(::Point<3>)) &AbstractMesh_3_3::AddVertex, - " ", py::arg("vertex")) + .def("AddNode", + (void(AbstractMesh_3_3::*)(::Node<3>)) &AbstractMesh_3_3::AddNode, + " ", py::arg("node")) .def("Scale", (void(AbstractMesh_3_3::*)(double const)) &AbstractMesh_3_3::Scale, " ", py::arg("factor")) diff --git a/examples/shapes/wrapper/mesh/AbstractMesh_3_3.cppwg.hpp b/examples/cells/dynamic/wrappers/all/AbstractMesh_3_3.cppwg.hpp similarity index 72% rename from examples/shapes/wrapper/mesh/AbstractMesh_3_3.cppwg.hpp rename to examples/cells/dynamic/wrappers/all/AbstractMesh_3_3.cppwg.hpp index f122f63..1b26ef7 100644 --- a/examples/shapes/wrapper/mesh/AbstractMesh_3_3.cppwg.hpp +++ b/examples/cells/dynamic/wrappers/all/AbstractMesh_3_3.cppwg.hpp @@ -1,5 +1,4 @@ -// This file is automatically generated by cppwg. -// Do not modify this file directly. +// This file is auto-generated by cppwg; manual changes will be overwritten. #ifndef AbstractMesh_3_3_hpp__cppwg_wrapper #define AbstractMesh_3_3_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/Cell.cppwg.cpp b/examples/cells/dynamic/wrappers/all/Cell.cppwg.cpp new file mode 100644 index 0000000..f9ba7bb --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/Cell.cppwg.cpp @@ -0,0 +1,22 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include +#include +#include "Cell.hpp" + +#include "Cell.cppwg.hpp" + +namespace py = pybind11; +typedef Cell Cell; +PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + +void register_Cell_class(py::module &m) +{ + py::class_>(m, "Cell") + .def(py::init<>()) + .def("GetCellId", + (unsigned int(Cell::*)() const) &Cell::GetCellId, + " ") + ; +} diff --git a/examples/cells/dynamic/wrappers/all/Cell.cppwg.hpp b/examples/cells/dynamic/wrappers/all/Cell.cppwg.hpp new file mode 100644 index 0000000..ae3fe5b --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/Cell.cppwg.hpp @@ -0,0 +1,9 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef Cell_hpp__cppwg_wrapper +#define Cell_hpp__cppwg_wrapper + +#include + +void register_Cell_class(pybind11::module &m); +#endif // Cell_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_2.cppwg.cpp b/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_2.cppwg.cpp new file mode 100644 index 0000000..3147611 --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_2.cppwg.cpp @@ -0,0 +1,23 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include +#include "PottsMesh.hpp" +#include +#include "MeshFactory.hpp" + +#include "MeshFactory_PottsMesh_2.cppwg.hpp" + +namespace py = pybind11; +typedef MeshFactory> MeshFactory_PottsMesh_2; +PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + +void register_MeshFactory_PottsMesh_2_class(py::module &m) +{ + py::class_>(m, "MeshFactory_PottsMesh_2") + .def(py::init<>()) + .def("generateMesh", + (::std::shared_ptr>(MeshFactory_PottsMesh_2::*)()) &MeshFactory_PottsMesh_2::generateMesh, + " ") + ; +} diff --git a/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_2.cppwg.hpp b/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_2.cppwg.hpp new file mode 100644 index 0000000..28dc4ad --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_2.cppwg.hpp @@ -0,0 +1,9 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef MeshFactory_PottsMesh_2_hpp__cppwg_wrapper +#define MeshFactory_PottsMesh_2_hpp__cppwg_wrapper + +#include + +void register_MeshFactory_PottsMesh_2_class(pybind11::module &m); +#endif // MeshFactory_PottsMesh_2_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_3.cppwg.cpp b/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_3.cppwg.cpp new file mode 100644 index 0000000..2a8b1dc --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_3.cppwg.cpp @@ -0,0 +1,23 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include +#include "PottsMesh.hpp" +#include +#include "MeshFactory.hpp" + +#include "MeshFactory_PottsMesh_3.cppwg.hpp" + +namespace py = pybind11; +typedef MeshFactory> MeshFactory_PottsMesh_3; +PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + +void register_MeshFactory_PottsMesh_3_class(py::module &m) +{ + py::class_>(m, "MeshFactory_PottsMesh_3") + .def(py::init<>()) + .def("generateMesh", + (::std::shared_ptr>(MeshFactory_PottsMesh_3::*)()) &MeshFactory_PottsMesh_3::generateMesh, + " ") + ; +} diff --git a/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_3.cppwg.hpp b/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_3.cppwg.hpp new file mode 100644 index 0000000..eb7de7c --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/MeshFactory_PottsMesh_3.cppwg.hpp @@ -0,0 +1,9 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef MeshFactory_PottsMesh_3_hpp__cppwg_wrapper +#define MeshFactory_PottsMesh_3_hpp__cppwg_wrapper + +#include + +void register_MeshFactory_PottsMesh_3_class(pybind11::module &m); +#endif // MeshFactory_PottsMesh_3_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/Node_2.cppwg.cpp b/examples/cells/dynamic/wrappers/all/Node_2.cppwg.cpp new file mode 100644 index 0000000..3db7b00 --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/Node_2.cppwg.cpp @@ -0,0 +1,31 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include +#include "PybindUblasTypeCaster.hpp" +#include +#include "Node.hpp" + +#include "Node_2.cppwg.hpp" + +namespace py = pybind11; +typedef Node<2> Node_2; +PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + +void register_Node_2_class(py::module &m) +{ + py::class_>(m, "Node_2") + .def(py::init<>()) + .def(py::init<::std::vector>(), py::arg("coords")) + .def(py::init<::boost::numeric::ublas::c_vector>(), py::arg("coords")) + .def("GetIndex", + (unsigned int(Node_2::*)() const) &Node_2::GetIndex, + " ") + .def("GetLocation", + (::boost::numeric::ublas::c_vector(Node_2::*)()) &Node_2::GetLocation, + " ") + .def("Translate", + (void(Node_2::*)(::boost::numeric::ublas::c_vector const &)) &Node_2::Translate, + " ", py::arg("rDisplacement")) + ; +} diff --git a/examples/cells/dynamic/wrappers/all/Node_2.cppwg.hpp b/examples/cells/dynamic/wrappers/all/Node_2.cppwg.hpp new file mode 100644 index 0000000..35b1aeb --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/Node_2.cppwg.hpp @@ -0,0 +1,9 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef Node_2_hpp__cppwg_wrapper +#define Node_2_hpp__cppwg_wrapper + +#include + +void register_Node_2_class(pybind11::module &m); +#endif // Node_2_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/Node_3.cppwg.cpp b/examples/cells/dynamic/wrappers/all/Node_3.cppwg.cpp new file mode 100644 index 0000000..d6149b9 --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/Node_3.cppwg.cpp @@ -0,0 +1,31 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include +#include "PybindUblasTypeCaster.hpp" +#include +#include "Node.hpp" + +#include "Node_3.cppwg.hpp" + +namespace py = pybind11; +typedef Node<3> Node_3; +PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + +void register_Node_3_class(py::module &m) +{ + py::class_>(m, "Node_3") + .def(py::init<>()) + .def(py::init<::std::vector>(), py::arg("coords")) + .def(py::init<::boost::numeric::ublas::c_vector>(), py::arg("coords")) + .def("GetIndex", + (unsigned int(Node_3::*)() const) &Node_3::GetIndex, + " ") + .def("GetLocation", + (::boost::numeric::ublas::c_vector(Node_3::*)()) &Node_3::GetLocation, + " ") + .def("Translate", + (void(Node_3::*)(::boost::numeric::ublas::c_vector const &)) &Node_3::Translate, + " ", py::arg("rDisplacement")) + ; +} diff --git a/examples/cells/dynamic/wrappers/all/Node_3.cppwg.hpp b/examples/cells/dynamic/wrappers/all/Node_3.cppwg.hpp new file mode 100644 index 0000000..0c2935d --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/Node_3.cppwg.hpp @@ -0,0 +1,9 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef Node_3_hpp__cppwg_wrapper +#define Node_3_hpp__cppwg_wrapper + +#include + +void register_Node_3_class(pybind11::module &m); +#endif // Node_3_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/PetscUtils.cppwg.cpp b/examples/cells/dynamic/wrappers/all/PetscUtils.cppwg.cpp new file mode 100644 index 0000000..c7de3f9 --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/PetscUtils.cppwg.cpp @@ -0,0 +1,35 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include +#include "caster_petsc.h" +#include +#include "PetscUtils.hpp" + +#include "PetscUtils.cppwg.hpp" + +namespace py = pybind11; +typedef PetscUtils PetscUtils; +PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + +void register_PetscUtils_class(py::module &m) +{ + py::class_>(m, "PetscUtils") + .def(py::init<>()) + .def_static("Initialise", + (void(*)()) &PetscUtils::Initialise, + " ") + .def_static("IsInitialised", + (bool(*)()) &PetscUtils::IsInitialised, + " ") + .def_static("GetSize", + (int(*)()) &PetscUtils::GetSize, + " ") + .def_static("GetRank", + (int(*)()) &PetscUtils::GetRank, + " ") + .def_static("CreateVec", + (::Vec(*)(int)) &PetscUtils::CreateVec, + " ", py::arg("size"), py::return_value_policy::reference) + ; +} diff --git a/examples/cells/dynamic/wrappers/all/PetscUtils.cppwg.hpp b/examples/cells/dynamic/wrappers/all/PetscUtils.cppwg.hpp new file mode 100644 index 0000000..3b30963 --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/PetscUtils.cppwg.hpp @@ -0,0 +1,9 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef PetscUtils_hpp__cppwg_wrapper +#define PetscUtils_hpp__cppwg_wrapper + +#include + +void register_PetscUtils_class(pybind11::module &m); +#endif // PetscUtils_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/PottsMesh_2.cppwg.cpp b/examples/cells/dynamic/wrappers/all/PottsMesh_2.cppwg.cpp new file mode 100644 index 0000000..a26f649 --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/PottsMesh_2.cppwg.cpp @@ -0,0 +1,36 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include +#include +#include "PottsMesh.hpp" + +#include "PottsMesh_2.cppwg.hpp" + +namespace py = pybind11; +typedef PottsMesh<2> PottsMesh_2; +PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + +class PottsMesh_2_Overrides : public PottsMesh_2 +{ +public: + using PottsMesh_2::PottsMesh; + void Scale(double const factor) override + { + PYBIND11_OVERRIDE( + void, + PottsMesh_2, + Scale, + factor); + } +}; + +void register_PottsMesh_2_class(py::module &m) +{ + py::class_, AbstractMesh<2>>(m, "PottsMesh_2") + .def(py::init<>()) + .def("Scale", + (void(PottsMesh_2::*)(double const)) &PottsMesh_2::Scale, + " ", py::arg("factor")) + ; +} diff --git a/examples/cells/dynamic/wrappers/all/PottsMesh_2.cppwg.hpp b/examples/cells/dynamic/wrappers/all/PottsMesh_2.cppwg.hpp new file mode 100644 index 0000000..30615bd --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/PottsMesh_2.cppwg.hpp @@ -0,0 +1,9 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef PottsMesh_2_hpp__cppwg_wrapper +#define PottsMesh_2_hpp__cppwg_wrapper + +#include + +void register_PottsMesh_2_class(pybind11::module &m); +#endif // PottsMesh_2_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/PottsMesh_3.cppwg.cpp b/examples/cells/dynamic/wrappers/all/PottsMesh_3.cppwg.cpp new file mode 100644 index 0000000..9ac2287 --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/PottsMesh_3.cppwg.cpp @@ -0,0 +1,36 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include +#include +#include "PottsMesh.hpp" + +#include "PottsMesh_3.cppwg.hpp" + +namespace py = pybind11; +typedef PottsMesh<3> PottsMesh_3; +PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + +class PottsMesh_3_Overrides : public PottsMesh_3 +{ +public: + using PottsMesh_3::PottsMesh; + void Scale(double const factor) override + { + PYBIND11_OVERRIDE( + void, + PottsMesh_3, + Scale, + factor); + } +}; + +void register_PottsMesh_3_class(py::module &m) +{ + py::class_, AbstractMesh<3>>(m, "PottsMesh_3") + .def(py::init<>()) + .def("Scale", + (void(PottsMesh_3::*)(double const)) &PottsMesh_3::Scale, + " ", py::arg("factor")) + ; +} diff --git a/examples/cells/dynamic/wrappers/all/PottsMesh_3.cppwg.hpp b/examples/cells/dynamic/wrappers/all/PottsMesh_3.cppwg.hpp new file mode 100644 index 0000000..51ee08f --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/PottsMesh_3.cppwg.hpp @@ -0,0 +1,9 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef PottsMesh_3_hpp__cppwg_wrapper +#define PottsMesh_3_hpp__cppwg_wrapper + +#include + +void register_PottsMesh_3_class(pybind11::module &m); +#endif // PottsMesh_3_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/Scene_2.cppwg.cpp b/examples/cells/dynamic/wrappers/all/Scene_2.cppwg.cpp new file mode 100644 index 0000000..bccdd79 --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/Scene_2.cppwg.cpp @@ -0,0 +1,23 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include +#include "PybindVTKTypeCaster.h" +#include +#include "Scene.hpp" + +#include "Scene_2.cppwg.hpp" + +namespace py = pybind11; +typedef Scene<2> Scene_2; +PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + +void register_Scene_2_class(py::module &m) +{ + py::class_>(m, "Scene_2") + .def(py::init<>()) + .def("GetRenderer", + (::vtkSmartPointer(Scene_2::*)()) &Scene_2::GetRenderer, + " ") + ; +} diff --git a/examples/cells/dynamic/wrappers/all/Scene_2.cppwg.hpp b/examples/cells/dynamic/wrappers/all/Scene_2.cppwg.hpp new file mode 100644 index 0000000..bfca3fc --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/Scene_2.cppwg.hpp @@ -0,0 +1,9 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef Scene_2_hpp__cppwg_wrapper +#define Scene_2_hpp__cppwg_wrapper + +#include + +void register_Scene_2_class(pybind11::module &m); +#endif // Scene_2_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/Scene_3.cppwg.cpp b/examples/cells/dynamic/wrappers/all/Scene_3.cppwg.cpp new file mode 100644 index 0000000..04b2d41 --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/Scene_3.cppwg.cpp @@ -0,0 +1,23 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include +#include "PybindVTKTypeCaster.h" +#include +#include "Scene.hpp" + +#include "Scene_3.cppwg.hpp" + +namespace py = pybind11; +typedef Scene<3> Scene_3; +PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); + +void register_Scene_3_class(py::module &m) +{ + py::class_>(m, "Scene_3") + .def(py::init<>()) + .def("GetRenderer", + (::vtkSmartPointer(Scene_3::*)()) &Scene_3::GetRenderer, + " ") + ; +} diff --git a/examples/cells/dynamic/wrappers/all/Scene_3.cppwg.hpp b/examples/cells/dynamic/wrappers/all/Scene_3.cppwg.hpp new file mode 100644 index 0000000..b9c477c --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/Scene_3.cppwg.hpp @@ -0,0 +1,9 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef Scene_3_hpp__cppwg_wrapper +#define Scene_3_hpp__cppwg_wrapper + +#include + +void register_Scene_3_class(pybind11::module &m); +#endif // Scene_3_hpp__cppwg_wrapper diff --git a/examples/cells/dynamic/wrappers/all/_pycells_all.main.cppwg.cpp b/examples/cells/dynamic/wrappers/all/_pycells_all.main.cppwg.cpp new file mode 100644 index 0000000..0bcd915 --- /dev/null +++ b/examples/cells/dynamic/wrappers/all/_pycells_all.main.cppwg.cpp @@ -0,0 +1,33 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#include +#include "Cell.cppwg.hpp" +#include "Node_2.cppwg.hpp" +#include "Node_3.cppwg.hpp" +#include "AbstractMesh_2_2.cppwg.hpp" +#include "AbstractMesh_3_3.cppwg.hpp" +#include "PottsMesh_2.cppwg.hpp" +#include "PottsMesh_3.cppwg.hpp" +#include "MeshFactory_PottsMesh_2.cppwg.hpp" +#include "MeshFactory_PottsMesh_3.cppwg.hpp" +#include "PetscUtils.cppwg.hpp" +#include "Scene_2.cppwg.hpp" +#include "Scene_3.cppwg.hpp" + +namespace py = pybind11; + +PYBIND11_MODULE(_pycells_all, m) +{ + register_Cell_class(m); + register_Node_2_class(m); + register_Node_3_class(m); + register_AbstractMesh_2_2_class(m); + register_AbstractMesh_3_3_class(m); + register_PottsMesh_2_class(m); + register_PottsMesh_3_class(m); + register_MeshFactory_PottsMesh_2_class(m); + register_MeshFactory_PottsMesh_3_class(m); + register_PetscUtils_class(m); + register_Scene_2_class(m); + register_Scene_3_class(m); +} diff --git a/examples/cells/dynamic/wrappers/wrapper_header_collection.cppwg.hpp b/examples/cells/dynamic/wrappers/wrapper_header_collection.cppwg.hpp new file mode 100644 index 0000000..1db0a7d --- /dev/null +++ b/examples/cells/dynamic/wrappers/wrapper_header_collection.cppwg.hpp @@ -0,0 +1,42 @@ +// This file is auto-generated by cppwg; manual changes will be overwritten. + +#ifndef pycells_HEADERS_HPP_ +#define pycells_HEADERS_HPP_ + +// Includes +#include "AbstractMesh.hpp" +#include "Cell.hpp" +#include "MeshFactory.hpp" +#include "Node.hpp" +#include "PetscUtils.hpp" +#include "PottsMesh.hpp" +#include "Scene.hpp" + +// Instantiate Template Classes +template class AbstractMesh<2, 2>; +template class AbstractMesh<3, 3>; +template class MeshFactory>; +template class MeshFactory>; +template class Node<2>; +template class Node<3>; +template class PottsMesh<2>; +template class PottsMesh<3>; +template class Scene<2>; +template class Scene<3>; + +// Typedefs for nicer naming +namespace cppwg +{ + typedef AbstractMesh<2, 2> AbstractMesh_2_2; + typedef AbstractMesh<3, 3> AbstractMesh_3_3; + typedef MeshFactory> MeshFactory_PottsMesh_2; + typedef MeshFactory> MeshFactory_PottsMesh_3; + typedef Node<2> Node_2; + typedef Node<3> Node_3; + typedef PottsMesh<2> PottsMesh_2; + typedef PottsMesh<3> PottsMesh_3; + typedef Scene<2> Scene_2; + typedef Scene<3> Scene_3; +} // namespace cppwg + +#endif // pycells_HEADERS_HPP_ diff --git a/examples/cells/pyproject.toml b/examples/cells/pyproject.toml new file mode 100644 index 0000000..3b7db8c --- /dev/null +++ b/examples/cells/pyproject.toml @@ -0,0 +1,14 @@ +[build-system] +requires = ["scikit-build-core >= 0.10.0"] +build-backend = "scikit_build_core.build" + +[project] +name = "pycells" +version = "0.0.1" +license = { text = "BSD-3-Clause License" } +requires-python = ">=3.8" + +[tool.scikit-build] +cmake.build-type = "Release" +wheel.packages = ["src/py/pycells"] +wheel.install-dir = "pycells" diff --git a/examples/cells/src/cpp/cell/Cell.cpp b/examples/cells/src/cpp/cell/Cell.cpp new file mode 100644 index 0000000..c7d3a6a --- /dev/null +++ b/examples/cells/src/cpp/cell/Cell.cpp @@ -0,0 +1,14 @@ +#include "Cell.hpp" + +Cell::Cell() : mIndex(0) +{ +} + +Cell::~Cell() +{ +} + +unsigned Cell::GetCellId() const +{ + return mIndex; +} diff --git a/examples/cells/src/cpp/cell/Cell.hpp b/examples/cells/src/cpp/cell/Cell.hpp new file mode 100644 index 0000000..68b8b49 --- /dev/null +++ b/examples/cells/src/cpp/cell/Cell.hpp @@ -0,0 +1,29 @@ +#ifndef CELL_HPP_ +#define CELL_HPP_ + +class Cell +{ +private: + /** + * Cell index + */ + unsigned mIndex; + +public: + /** + * Default Constructor + */ + Cell(); + + /** + * Destructor + */ + virtual ~Cell(); + + /** + * Return the index + */ + unsigned GetCellId() const; +}; + +#endif // CELL_HPP_ diff --git a/examples/shapes/src/cpp/mesh/AbstractMesh.cpp b/examples/cells/src/cpp/mesh/AbstractMesh.cpp similarity index 87% rename from examples/shapes/src/cpp/mesh/AbstractMesh.cpp rename to examples/cells/src/cpp/mesh/AbstractMesh.cpp index 7f6ec65..5bffc2b 100644 --- a/examples/shapes/src/cpp/mesh/AbstractMesh.cpp +++ b/examples/cells/src/cpp/mesh/AbstractMesh.cpp @@ -1,4 +1,5 @@ #include "AbstractMesh.hpp" +#include "Node.hpp" template AbstractMesh::AbstractMesh() : mIndex(0) @@ -23,7 +24,7 @@ void AbstractMesh::SetIndex(unsigned index) } template -void AbstractMesh::AddVertex(Point vertex) +void AbstractMesh::AddNode(Node node) { } diff --git a/examples/shapes/src/cpp/mesh/AbstractMesh.hpp b/examples/cells/src/cpp/mesh/AbstractMesh.hpp similarity index 87% rename from examples/shapes/src/cpp/mesh/AbstractMesh.hpp rename to examples/cells/src/cpp/mesh/AbstractMesh.hpp index 4ccbae6..057a896 100644 --- a/examples/shapes/src/cpp/mesh/AbstractMesh.hpp +++ b/examples/cells/src/cpp/mesh/AbstractMesh.hpp @@ -1,7 +1,7 @@ #ifndef _ABSTRACT_MESH_HPP #define _ABSTRACT_MESH_HPP -#include "Point.hpp" +#include "Node.hpp" /** * A mesh in SPACE_DIM space with ELEMENT_DIM dimensional elements @@ -37,9 +37,9 @@ class AbstractMesh void SetIndex(unsigned index); /** - * Add a vertex to the mesh + * Add a node to the mesh */ - void AddVertex(Point vertex); + void AddNode(Node node); /** * Scale the mesh by a factor diff --git a/examples/cells/src/cpp/mesh/MeshFactory.cpp b/examples/cells/src/cpp/mesh/MeshFactory.cpp new file mode 100644 index 0000000..4602d8a --- /dev/null +++ b/examples/cells/src/cpp/mesh/MeshFactory.cpp @@ -0,0 +1,23 @@ +#include "MeshFactory.hpp" +#include "PottsMesh.hpp" + +#include + +template +MeshFactory::MeshFactory() +{ +} + +template +MeshFactory::~MeshFactory() +{ +} + +template +std::shared_ptr MeshFactory::generateMesh() +{ + return std::make_shared(); +} + +template class MeshFactory>; +template class MeshFactory>; diff --git a/examples/shapes/src/cpp/mesh/MeshFactory.hpp b/examples/cells/src/cpp/mesh/MeshFactory.hpp similarity index 74% rename from examples/shapes/src/cpp/mesh/MeshFactory.hpp rename to examples/cells/src/cpp/mesh/MeshFactory.hpp index 1f414cd..14a20a2 100644 --- a/examples/shapes/src/cpp/mesh/MeshFactory.hpp +++ b/examples/cells/src/cpp/mesh/MeshFactory.hpp @@ -1,7 +1,7 @@ #ifndef _MESH_FACTORY_HPP #define _MESH_FACTORY_HPP -#include "MeshGen.hpp" +#include /** * A concrete mesh implementation @@ -9,9 +9,6 @@ template class MeshFactory { -private: - MeshGen mMeshGen; - public: /** * Default Constructor @@ -22,6 +19,11 @@ class MeshFactory * Destructor */ ~MeshFactory(); + + /** + * Generate a mesh + */ + std::shared_ptr generateMesh(); }; #endif // _MESH_FACTORY_HPP diff --git a/examples/cells/src/cpp/mesh/Node.cpp b/examples/cells/src/cpp/mesh/Node.cpp new file mode 100644 index 0000000..8a2f675 --- /dev/null +++ b/examples/cells/src/cpp/mesh/Node.cpp @@ -0,0 +1,61 @@ +#include "Node.hpp" + +#include + +#include +#include + +template +Node::Node() + : Node({0.0, 0.0, 0.0}) +{ +} + +template +Node::Node(std::vector coords) + : mIndex(0), mLocation() +{ + for (unsigned i = 0; i < SPACE_DIM; ++i) + { + mLocation[i] = coords[i]; + } +} + +template +Node::Node(boost::numeric::ublas::c_vector coords) + : mIndex(0), mLocation() +{ + for (unsigned i = 0; i < SPACE_DIM; ++i) + { + mLocation[i] = coords[i]; + } +} + +template +Node::~Node() +{ +} + +template +unsigned Node::GetIndex() const +{ + return mIndex; +} + +template +boost::numeric::ublas::c_vector Node::GetLocation() +{ + return mLocation; +} + +template +void Node::Translate(const boost::numeric::ublas::c_vector &rDisplacement) +{ + for (unsigned i = 0; i < SPACE_DIM; ++i) + { + mLocation[i] += rDisplacement[i]; + } +} + +template class Node<2>; +template class Node<3>; diff --git a/examples/cells/src/cpp/mesh/Node.hpp b/examples/cells/src/cpp/mesh/Node.hpp new file mode 100644 index 0000000..e995d15 --- /dev/null +++ b/examples/cells/src/cpp/mesh/Node.hpp @@ -0,0 +1,63 @@ +#ifndef _NODE_HPP_ +#define _NODE_HPP_ + +#include + +#include +#include + +/** + * A node in a mesh + */ +template +class Node +{ +private: + /** + * Node index + */ + unsigned mIndex; + + /** + * Node location + */ + boost::numeric::ublas::c_vector mLocation; + +public: + /** + * Default Constructor + */ + Node(); + + /** + * Constructor with std::vector coordinates + */ + Node(std::vector coords); + + /** + * Constructor with c_vector coordinates + */ + Node(boost::numeric::ublas::c_vector coords); + + /** + * Destructor + */ + ~Node(); + + /** + * Return the index + */ + unsigned GetIndex() const; + + /** + * Return the location + */ + boost::numeric::ublas::c_vector GetLocation(); + + /** + * Translate with the given displacement vector + */ + void Translate(const boost::numeric::ublas::c_vector &rDisplacement); +}; + +#endif //_NODE_HPP_ diff --git a/examples/cells/src/cpp/mesh/PottsMesh.cpp b/examples/cells/src/cpp/mesh/PottsMesh.cpp new file mode 100644 index 0000000..1c3c456 --- /dev/null +++ b/examples/cells/src/cpp/mesh/PottsMesh.cpp @@ -0,0 +1,18 @@ +#include "PottsMesh.hpp" + +template +PottsMesh::PottsMesh() : AbstractMesh() +{ +} + +template +PottsMesh::~PottsMesh() +{ +} +template +void PottsMesh::Scale(const double factor){ + // Scale the mesh +}; + +template class PottsMesh<2>; +template class PottsMesh<3>; diff --git a/examples/shapes/src/cpp/mesh/ConcreteMesh.hpp b/examples/cells/src/cpp/mesh/PottsMesh.hpp similarity index 54% rename from examples/shapes/src/cpp/mesh/ConcreteMesh.hpp rename to examples/cells/src/cpp/mesh/PottsMesh.hpp index 84d917e..684e7b3 100644 --- a/examples/shapes/src/cpp/mesh/ConcreteMesh.hpp +++ b/examples/cells/src/cpp/mesh/PottsMesh.hpp @@ -1,24 +1,24 @@ -#ifndef _CONCRETE_MESH_HPP -#define _CONCRETE_MESH_HPP +#ifndef _POTTS_MESH_HPP +#define _POTTS_MESH_HPP #include "AbstractMesh.hpp" /** - * A concrete mesh implementation + * A Potts mesh implementation */ template -class ConcreteMesh : public AbstractMesh +class PottsMesh : public AbstractMesh { public: /** * Default Constructor */ - ConcreteMesh(); + PottsMesh(); /** * Destructor */ - ~ConcreteMesh(); + ~PottsMesh(); /** * Scale the mesh by a factor @@ -26,4 +26,4 @@ class ConcreteMesh : public AbstractMesh void Scale(const double factor) override; }; -#endif // _CONCRETE_MESH_HPP +#endif // _POTTS_MESH_HPP diff --git a/examples/cells/src/cpp/utils/PetscUtils.cpp b/examples/cells/src/cpp/utils/PetscUtils.cpp new file mode 100644 index 0000000..eb16b08 --- /dev/null +++ b/examples/cells/src/cpp/utils/PetscUtils.cpp @@ -0,0 +1,66 @@ +#include "PetscUtils.hpp" + +#include +#include +#include +#include +#include + +#include + +void PetscUtils::Initialise() +{ + if (!PetscUtils::IsInitialised()) + { +#if PETSC_VERSION_GE(3, 19, 0) + PetscInitialize(PETSC_NULLPTR, PETSC_NULLPTR, PETSC_NULLPTR, PETSC_NULLPTR); +#else + PetscInitialize(PETSC_NULL, PETSC_NULL, PETSC_NULL, PETSC_NULL); +#endif + } +} + +bool PetscUtils::IsInitialised() +{ + PetscBool isInitialised; + PetscInitialized(&isInitialised); + return (bool)isInitialised; +} + +int PetscUtils::GetSize() +{ + if (!PetscUtils::IsInitialised()) + { + PetscUtils::Initialise(); + } + + PetscInt size; + MPI_Comm_size(PETSC_COMM_WORLD, &size); + return (unsigned)size; +} + +int PetscUtils::GetRank() +{ + if (!PetscUtils::IsInitialised()) + { + PetscUtils::Initialise(); + } + + PetscInt rank; + MPI_Comm_rank(PETSC_COMM_WORLD, &rank); + return (unsigned)rank; +} + +Vec PetscUtils::CreateVec(int size) +{ + if (!PetscUtils::IsInitialised()) + { + PetscUtils::Initialise(); + } + + Vec v; + VecCreate(PETSC_COMM_WORLD, &v); + VecSetSizes(v, PETSC_DECIDE, size); + VecSetFromOptions(v); + return v; +} diff --git a/examples/cells/src/cpp/utils/PetscUtils.hpp b/examples/cells/src/cpp/utils/PetscUtils.hpp new file mode 100644 index 0000000..d6e89bb --- /dev/null +++ b/examples/cells/src/cpp/utils/PetscUtils.hpp @@ -0,0 +1,24 @@ +#ifndef PETSCUTILS_HPP_ +#define PETSCUTILS_HPP_ + +#include +#include +#include +#include + +#include + +class PetscUtils +{ +public: + static void Initialise(); + + static bool IsInitialised(); + + static int GetSize(); + static int GetRank(); + + static Vec CreateVec(int size); +}; + +#endif // PETSCUTILS_HPP_ diff --git a/examples/cells/src/cpp/visualization/Scene.cpp b/examples/cells/src/cpp/visualization/Scene.cpp new file mode 100644 index 0000000..97a29aa --- /dev/null +++ b/examples/cells/src/cpp/visualization/Scene.cpp @@ -0,0 +1,30 @@ +#include "Scene.hpp" + +#include +#include +#include +#include + +template +Scene::Scene() + : mpRenderer(vtkSmartPointer::New()), + mpRenderWindow(vtkSmartPointer::New()) +{ + mpRenderer->SetBackground(1.0, 1.0, 1.0); + mpRenderWindow->AddRenderer(mpRenderer); + mpRenderWindow->SetSize(800.0, 600.0); +} + +template +Scene::~Scene() +{ +} + +template +vtkSmartPointer Scene::GetRenderer() +{ + return mpRenderer; +} + +template class Scene<2>; +template class Scene<3>; diff --git a/examples/cells/src/cpp/visualization/Scene.hpp b/examples/cells/src/cpp/visualization/Scene.hpp new file mode 100644 index 0000000..6fe3296 --- /dev/null +++ b/examples/cells/src/cpp/visualization/Scene.hpp @@ -0,0 +1,25 @@ +#ifndef SCENE_HPP_ +#define SCENE_HPP_ + +#include +#include +#include +#include + +VTK_MODULE_INIT(vtkRenderingOpenGL2); + +template +class Scene +{ + vtkSmartPointer mpRenderer; + vtkSmartPointer mpRenderWindow; + +public: + Scene(); + + virtual ~Scene(); + + vtkSmartPointer GetRenderer(); +}; + +#endif // SCENE_HPP_ diff --git a/examples/cells/src/py/pycells/__init__.py b/examples/cells/src/py/pycells/__init__.py new file mode 100644 index 0000000..2825225 --- /dev/null +++ b/examples/cells/src/py/pycells/__init__.py @@ -0,0 +1,52 @@ +"""Main pycells module.""" + +from ._pycells_all import ( + Cell, + MeshFactory_PottsMesh_2, + MeshFactory_PottsMesh_3, + Node_2, + Node_3, + PetscUtils, + PottsMesh_2, + PottsMesh_3, + Scene_2, + Scene_3, +) +from ._syntax import TemplateClassDict + +MeshFactory = TemplateClassDict( + { + ("PottsMesh", "2"): MeshFactory_PottsMesh_2, + ("PottsMesh", "3"): MeshFactory_PottsMesh_3, + } +) + +Node = TemplateClassDict( + { + ("2",): Node_2, + ("3",): Node_3, + } +) + +PottsMesh = TemplateClassDict( + { + ("2",): PottsMesh_2, + ("3",): PottsMesh_3, + } +) + +Scene = TemplateClassDict( + { + ("2",): Scene_2, + ("3",): Scene_3, + } +) + +__all__ = [ + "Cell", + "MeshFactory", + "Node", + "PetscUtils", + "PottsMesh", + "Scene", +] diff --git a/examples/cells/src/py/pycells/_syntax.py b/examples/cells/src/py/pycells/_syntax.py new file mode 100644 index 0000000..a6733ea --- /dev/null +++ b/examples/cells/src/py/pycells/_syntax.py @@ -0,0 +1,27 @@ +"""Syntax module.""" + +import inspect +from collections.abc import Iterable + + +class TemplateClassDict: + + def __init__(self, template_dict): + self._dict = {} + for arg_tuple, cls in template_dict.items(): + if not inspect.isclass(cls): + raise TypeError("Expected class, got {}".format(type(cls))) + if not isinstance(arg_tuple, Iterable): + arg_tuple = (arg_tuple,) + key = tuple( + arg.__name__ if inspect.isclass(arg) else str(arg) for arg in arg_tuple + ) + self._dict[key] = cls + + def __getitem__(self, arg_tuple): + if not isinstance(arg_tuple, Iterable): + arg_tuple = (arg_tuple,) + key = tuple( + arg.__name__ if inspect.isclass(arg) else str(arg) for arg in arg_tuple + ) + return self._dict[key] diff --git a/examples/cells/tests/test_cells.py b/examples/cells/tests/test_cells.py new file mode 100644 index 0000000..6b4390d --- /dev/null +++ b/examples/cells/tests/test_cells.py @@ -0,0 +1,29 @@ +import sys +import unittest + +import petsc4py +import vtk +from pycells import Node, PetscUtils, Scene + + +class TestCells(unittest.TestCase): + + def testVtkCaster(self): + scene = Scene[2]() + renderer = scene.GetRenderer() + self.assertIsNotNone(renderer) + + def testPetscCaster(self): + petsc4py.init(sys.argv) + vec = PetscUtils.CreateVec(10) + self.assertIsNotNone(vec) + + def testUblasCaster(self): + node = Node[2]() + self.assertEqual(list(node.GetLocation()), [0, 0]) + node.Translate([1, 1]) + self.assertEqual(list(node.GetLocation()), [1, 1]) + + +if __name__ == "__main__": + unittest.main() diff --git a/examples/shapes/CMakeLists.txt b/examples/shapes/CMakeLists.txt index 3f72e81..95d872f 100644 --- a/examples/shapes/CMakeLists.txt +++ b/examples/shapes/CMakeLists.txt @@ -16,9 +16,6 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(pybind11) -# Add external library -add_subdirectory(extern/meshgen meshgen_build) - # Add a shared library for the main C++ source file(GLOB_RECURSE SHAPES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.cpp) add_library(shapes SHARED ${SHAPES_SOURCES}) @@ -28,10 +25,8 @@ target_include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/geometry ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/math_funcs - ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/mesh ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/primitives ) -target_link_libraries(shapes PUBLIC meshgen::meshgen) # Copy the Python source and test trees to the build location file( @@ -39,12 +34,12 @@ file( DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ ) file( - COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/py/test/ + COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/py/tests/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ ) # Create a shared library for each wrapper module -foreach(MODULE geometry math_funcs mesh primitives) +foreach(MODULE geometry math_funcs primitives) # Add the autogenerated wrappers to the module target file(GLOB MODULE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrapper/${MODULE}/*.cpp) @@ -63,7 +58,6 @@ foreach(MODULE geometry math_funcs mesh primitives) ${CMAKE_CURRENT_SOURCE_DIR}/wrapper ${CMAKE_CURRENT_SOURCE_DIR}/wrapper/geometry ${CMAKE_CURRENT_SOURCE_DIR}/wrapper/math_funcs - ${CMAKE_CURRENT_SOURCE_DIR}/wrapper/mesh ${CMAKE_CURRENT_SOURCE_DIR}/wrapper/primitives ) diff --git a/examples/shapes/extern/meshgen/CMakeLists.txt b/examples/shapes/extern/meshgen/CMakeLists.txt deleted file mode 100644 index 672572f..0000000 --- a/examples/shapes/extern/meshgen/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.8) -project(meshgen) - -add_library(meshgen MeshGen.cpp MeshGen.hpp) -target_include_directories(meshgen PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -add_library(meshgen::meshgen ALIAS meshgen) diff --git a/examples/shapes/extern/meshgen/MeshGen.cpp b/examples/shapes/extern/meshgen/MeshGen.cpp deleted file mode 100644 index e411abc..0000000 --- a/examples/shapes/extern/meshgen/MeshGen.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "MeshGen.hpp" - -MeshGen::MeshGen() -{ - // Constructor -} - -MeshGen::~MeshGen() -{ - // Destructor -} - -void MeshGen::generateMesh() -{ - // Generate a mesh -} diff --git a/examples/shapes/extern/meshgen/MeshGen.hpp b/examples/shapes/extern/meshgen/MeshGen.hpp deleted file mode 100644 index 0e71bf0..0000000 --- a/examples/shapes/extern/meshgen/MeshGen.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _MESHGEN_HPP -#define _MESHGEN_HPP - -class MeshGen -{ - -public: - /** - * Default Constructor - */ - MeshGen(); - - /** - * Destructor - */ - ~MeshGen(); - - /** - * Generate a mesh - */ - void generateMesh(); -}; - -#endif // _MESHGEN_HPP diff --git a/examples/shapes/src/cpp/mesh/ConcreteMesh.cpp b/examples/shapes/src/cpp/mesh/ConcreteMesh.cpp deleted file mode 100644 index 65cee4f..0000000 --- a/examples/shapes/src/cpp/mesh/ConcreteMesh.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "AbstractMesh.hpp" -#include "ConcreteMesh.hpp" - -template -ConcreteMesh::ConcreteMesh() : AbstractMesh() -{ -} - -template -ConcreteMesh::~ConcreteMesh() -{ -} -template -void ConcreteMesh::Scale(const double factor){ - // Scale the mesh -}; - -template class ConcreteMesh<2>; -template class ConcreteMesh<3>; diff --git a/examples/shapes/src/cpp/mesh/MeshFactory.cpp b/examples/shapes/src/cpp/mesh/MeshFactory.cpp deleted file mode 100644 index cc95b03..0000000 --- a/examples/shapes/src/cpp/mesh/MeshFactory.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "ConcreteMesh.hpp" - -#include "MeshFactory.hpp" - -template -MeshFactory::MeshFactory(): mMeshGen() -{ -} - -template -MeshFactory::~MeshFactory() -{ -} - -template class MeshFactory >; -template class MeshFactory >; diff --git a/examples/shapes/src/py/test/test_classes.py b/examples/shapes/src/py/tests/test_classes.py similarity index 80% rename from examples/shapes/src/py/test/test_classes.py rename to examples/shapes/src/py/tests/test_classes.py index 23ebe0f..d723b25 100644 --- a/examples/shapes/src/py/test/test_classes.py +++ b/examples/shapes/src/py/tests/test_classes.py @@ -1,7 +1,6 @@ import unittest import pyshapes.geometry -import pyshapes.mesh import pyshapes.primitives @@ -36,14 +35,6 @@ def testGeometry(self): cuboid = pyshapes.primitives.Cuboid(5.0, 10.0, 20.0) self.assertTrue(len(cuboid.rGetVertices()) == 8) - def testMesh(self): - - cmesh = pyshapes.mesh.ConcreteMesh_2() - self.assertTrue(cmesh.GetIndex() == 0) - - cmesh.SetIndex(1) - self.assertTrue(cmesh.GetIndex() == 1) - def testSyntax(self): self.assertEqual(pyshapes.geometry.Point[2], pyshapes.geometry.Point_2) @@ -51,10 +42,6 @@ def testSyntax(self): point = pyshapes.geometry.Point[3](0.0, 1.0, 2.0) self.assertTrue(point.GetLocation() == [0.0, 1.0, 2.0]) - self.assertEqual( - pyshapes.mesh.AbstractMesh[2, 2], pyshapes.mesh.AbstractMesh_2_2 - ) - if __name__ == "__main__": unittest.main() diff --git a/examples/shapes/src/py/test/test_functions.py b/examples/shapes/src/py/tests/test_functions.py similarity index 100% rename from examples/shapes/src/py/test/test_functions.py rename to examples/shapes/src/py/tests/test_functions.py diff --git a/examples/shapes/wrapper/mesh/ConcreteMesh_2.cppwg.cpp b/examples/shapes/wrapper/mesh/ConcreteMesh_2.cppwg.cpp deleted file mode 100644 index 8750693..0000000 --- a/examples/shapes/wrapper/mesh/ConcreteMesh_2.cppwg.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// This file is automatically generated by cppwg. -// Do not modify this file directly. - -#include -#include -#include "wrapper_header_collection.cppwg.hpp" - -#include "ConcreteMesh_2.cppwg.hpp" - -namespace py = pybind11; -typedef ConcreteMesh<2> ConcreteMesh_2; -PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); - -class ConcreteMesh_2_Overrides : public ConcreteMesh_2 -{ -public: - using ConcreteMesh_2::ConcreteMesh; - void Scale(double const factor) override - { - PYBIND11_OVERRIDE( - void, - ConcreteMesh_2, - Scale, - factor); - } -}; - -void register_ConcreteMesh_2_class(py::module &m) -{ - py::class_, AbstractMesh<2>>(m, "ConcreteMesh_2") - .def(py::init<>()) - .def("Scale", - (void(ConcreteMesh_2::*)(double const)) &ConcreteMesh_2::Scale, - " ", py::arg("factor")) - ; -} diff --git a/examples/shapes/wrapper/mesh/ConcreteMesh_2.cppwg.hpp b/examples/shapes/wrapper/mesh/ConcreteMesh_2.cppwg.hpp deleted file mode 100644 index fcf783a..0000000 --- a/examples/shapes/wrapper/mesh/ConcreteMesh_2.cppwg.hpp +++ /dev/null @@ -1,10 +0,0 @@ -// This file is automatically generated by cppwg. -// Do not modify this file directly. - -#ifndef ConcreteMesh_2_hpp__cppwg_wrapper -#define ConcreteMesh_2_hpp__cppwg_wrapper - -#include - -void register_ConcreteMesh_2_class(pybind11::module &m); -#endif // ConcreteMesh_2_hpp__cppwg_wrapper diff --git a/examples/shapes/wrapper/mesh/ConcreteMesh_3.cppwg.cpp b/examples/shapes/wrapper/mesh/ConcreteMesh_3.cppwg.cpp deleted file mode 100644 index 3c96c97..0000000 --- a/examples/shapes/wrapper/mesh/ConcreteMesh_3.cppwg.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// This file is automatically generated by cppwg. -// Do not modify this file directly. - -#include -#include -#include "wrapper_header_collection.cppwg.hpp" - -#include "ConcreteMesh_3.cppwg.hpp" - -namespace py = pybind11; -typedef ConcreteMesh<3> ConcreteMesh_3; -PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); - -class ConcreteMesh_3_Overrides : public ConcreteMesh_3 -{ -public: - using ConcreteMesh_3::ConcreteMesh; - void Scale(double const factor) override - { - PYBIND11_OVERRIDE( - void, - ConcreteMesh_3, - Scale, - factor); - } -}; - -void register_ConcreteMesh_3_class(py::module &m) -{ - py::class_, AbstractMesh<3>>(m, "ConcreteMesh_3") - .def(py::init<>()) - .def("Scale", - (void(ConcreteMesh_3::*)(double const)) &ConcreteMesh_3::Scale, - " ", py::arg("factor")) - ; -} diff --git a/examples/shapes/wrapper/mesh/ConcreteMesh_3.cppwg.hpp b/examples/shapes/wrapper/mesh/ConcreteMesh_3.cppwg.hpp deleted file mode 100644 index 900cb8d..0000000 --- a/examples/shapes/wrapper/mesh/ConcreteMesh_3.cppwg.hpp +++ /dev/null @@ -1,10 +0,0 @@ -// This file is automatically generated by cppwg. -// Do not modify this file directly. - -#ifndef ConcreteMesh_3_hpp__cppwg_wrapper -#define ConcreteMesh_3_hpp__cppwg_wrapper - -#include - -void register_ConcreteMesh_3_class(pybind11::module &m); -#endif // ConcreteMesh_3_hpp__cppwg_wrapper diff --git a/examples/shapes/wrapper/mesh/_pyshapes_mesh.main.cppwg.cpp b/examples/shapes/wrapper/mesh/_pyshapes_mesh.main.cppwg.cpp deleted file mode 100644 index 4361e15..0000000 --- a/examples/shapes/wrapper/mesh/_pyshapes_mesh.main.cppwg.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// This file is automatically generated by cppwg. -// Do not modify this file directly. - -#include -#include "wrapper_header_collection.cppwg.hpp" -#include "AbstractMesh_2_2.cppwg.hpp" -#include "AbstractMesh_3_3.cppwg.hpp" -#include "ConcreteMesh_2.cppwg.hpp" -#include "ConcreteMesh_3.cppwg.hpp" - -namespace py = pybind11; - -PYBIND11_MODULE(_pyshapes_mesh, m) -{ - register_AbstractMesh_2_2_class(m); - register_AbstractMesh_3_3_class(m); - register_ConcreteMesh_2_class(m); - register_ConcreteMesh_3_class(m); -} diff --git a/examples/shapes/wrapper/package_info.yaml b/examples/shapes/wrapper/package_info.yaml index 5b8d9d0..9a6c7e1 100644 --- a/examples/shapes/wrapper/package_info.yaml +++ b/examples/shapes/wrapper/package_info.yaml @@ -94,12 +94,6 @@ modules: - name: Triangle excluded: True # Exclude this class from wrapping. - - name: mesh - source_locations: - classes: - - name: ConcreteMesh - - name: AbstractMesh - # Text to add at the top of all wrappers prefix_text: | // This file is automatically generated by cppwg. diff --git a/examples/shapes/wrapper/wrapper_header_collection.cppwg.hpp b/examples/shapes/wrapper/wrapper_header_collection.cppwg.hpp index 8eb7eb1..b4694d9 100644 --- a/examples/shapes/wrapper/wrapper_header_collection.cppwg.hpp +++ b/examples/shapes/wrapper/wrapper_header_collection.cppwg.hpp @@ -5,10 +5,7 @@ #define pyshapes_HEADERS_HPP_ // Includes -#include "AbstractMesh.hpp" -#include "ConcreteMesh.hpp" #include "Cuboid.hpp" -#include "MeshFactory.hpp" #include "Point.hpp" #include "Rectangle.hpp" #include "Shape.hpp" @@ -21,10 +18,6 @@ template class Point<2>; template class Point<3>; template class Shape<2>; template class Shape<3>; -template class AbstractMesh<2, 2>; -template class AbstractMesh<3, 3>; -template class ConcreteMesh<2>; -template class ConcreteMesh<3>; // Typedefs for nicer naming namespace cppwg @@ -33,10 +26,6 @@ namespace cppwg typedef Point<3> Point_3; typedef Shape<2> Shape_2; typedef Shape<3> Shape_3; - typedef AbstractMesh<2, 2> AbstractMesh_2_2; - typedef AbstractMesh<3, 3> AbstractMesh_3_3; - typedef ConcreteMesh<2> ConcreteMesh_2; - typedef ConcreteMesh<3> ConcreteMesh_3; } // namespace cppwg #endif // pyshapes_HEADERS_HPP_ diff --git a/pyproject.toml b/pyproject.toml index fcdd3ae..b874398 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,57 +1,15 @@ [build-system] requires = ["setuptools", "wheel"] -[project] -name = "cppwg" -description = "An automatic Python wrapper generator for C++" -authors = [ - { name = "Chaste Developers", email = "chaste-users@maillist.ox.ac.uk" }, - { name = "James Grogan", email = "grogan@maths.ox.ac.uk" }, - { name = "Kwabena Amponsah", email = "kwabenantim@gmail.com" }, -] -license = { file = "LICENSE" } -keywords = ["C++", "Python", "Pybind11"] -readme = "README.md" -version = "0.3.1" - -classifiers = [ - "Development Status :: 4 - Beta", - "Environment :: Console", - "Intended Audience :: Developers", - "Operating System :: MacOS :: MacOS X", - "Operating System :: Microsoft :: Windows", - "Operating System :: POSIX", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: Implementation :: CPython", - "Topic :: Software Development", -] - -dependencies = ["pyyaml >=6.0", "pygccxml >=2.2", "castxml >=0.4"] - -requires-python = ">=3.8" - -[project.optional-dependencies] -dev = ["black", "flake8", "flake8-bugbear", "flake8-docstrings", "isort"] -docs = ["sphinx", "sphinx-rtd-theme", "numpydoc"] - -[project.scripts] -cppwg = "cppwg.__main__:main" - -[project.urls] -Repository = "https://github.com/Chaste/cppwg/" - [tool.black] target-version = ["py38", "py39", "py310", "py311", "py312"] extend-exclude = """ ( ^/cppwg/templates/ + | _skbuild/ ) """ [tool.isort] profile = "black" -extend_skip_glob = ["examples/shapes/wrapper/pybind11/*"] +extend_skip = ["_skbuild"] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..4bafa3a --- /dev/null +++ b/setup.cfg @@ -0,0 +1,52 @@ +[metadata] +name = cppwg +version = 0.3.1 +author = Chaste Developers +author_email = chaste-users@maillist.ox.ac.uk +description = An automatic Python wrapper generator for C++ code +long_description = file: README.md +keywords = C++, Python, pybind11 +license = BSD-3-Clause +classifiers = + Development Status :: 4 - Beta + Environment :: Console + Intended Audience :: Developers + Operating System :: MacOS :: MacOS X + Operating System :: Microsoft :: Windows + Operating System :: POSIX + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 + Programming Language :: Python :: Implementation :: CPython + Topic :: Software Development + +project_urls = + Source Code = https://github.com/Chaste/cppwg/ + +[options] +zip_safe = False +packages = find: +python_requires = >=3.8 +install_requires = + pyyaml>=6.0 + pygccxml>=2.2 + castxml>=0.4 + +[options.entry_points] +console_scripts = + cppwg = cppwg.__main__:main + +[options.extras_require] +dev = + black + flake8 + flake8-bugbear + flake8-docstrings + isort + +docs = + sphinx + sphinx-rtd-theme + numpydoc diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..685c789 --- /dev/null +++ b/setup.py @@ -0,0 +1,5 @@ +"""Setup.""" + +from setuptools import setup + +setup() diff --git a/tests/test_wrapper_generation.py b/tests/test_wrapper_generation.py deleted file mode 100644 index b91050f..0000000 --- a/tests/test_wrapper_generation.py +++ /dev/null @@ -1,92 +0,0 @@ -import os -import subprocess -import unittest -from difflib import context_diff -from glob import glob - - -def file_diff(file_a: str, file_b: str) -> bool: - """Check if two files have the same content. - - Parameters - __________ - file_a: str - The path to the first file - file__b: str - The path to the second file - - Returns - __________ - str - A diff of the two files - """ - # Read files and remove excess whitespace - with open(file_a, "r") as fa: - a = [line.strip() for line in fa] - a = [line for line in a if line] - - with open(file_b, "r") as fb: - b = [line.strip() for line in fb] - b = [line for line in b if line] - - return "\n".join(context_diff(a, b)) - - -class TestWrapperGeneration(unittest.TestCase): - - def test_wrapper_generation(self) -> None: - """ - Generate wrappers and compare with the reference wrappers. - """ - - # Set paths to the shapes code, reference and generated wrappers, etc. - shapes_root = os.path.abspath("examples/shapes") - shapes_src = os.path.join(shapes_root, "src/cpp") - extern_src = os.path.join(shapes_root, "extern") - - wrapper_root_ref = os.path.join(shapes_root, "wrapper") - wrapper_root_gen = os.path.join(shapes_root, "gen_wrapper") - - self.assertTrue(os.path.isdir(shapes_root)) - self.assertTrue(os.path.isdir(shapes_src)) - self.assertTrue(os.path.isdir(extern_src)) - self.assertTrue(os.path.isdir(wrapper_root_ref)) - - generate_script = os.path.abspath("cppwg/__main__.py") - package_info_path = os.path.join(wrapper_root_ref, "package_info.yaml") - self.assertTrue(os.path.isfile(package_info_path)) - - includes = glob(shapes_src + "/*/") + glob(extern_src + "/*/") - - # Generate the wrappers - subprocess.call( - [ - "python", - generate_script, - shapes_src, - "--wrapper_root", - wrapper_root_gen, - "--package_info", - package_info_path, - "--includes", - ] - + includes - ) - - self.assertTrue(os.path.isdir(wrapper_root_gen)) - - # Compare the generated files with reference files - self.maxDiff = None - for dirpath, _, filenames in os.walk(wrapper_root_ref): - for filename in filenames: - if filename.endswith(".cppwg.cpp") or filename.endswith(".cppwg.hpp"): - file_ref = os.path.join(dirpath, filename) - file_gen = file_ref.replace(wrapper_root_ref, wrapper_root_gen, 1) - - self.assertTrue(os.path.isfile(file_ref)) - self.assertTrue(os.path.isfile(file_gen)) - self.assertEqual(file_diff(file_gen, file_ref), "", f"\n{file_ref}") - - -if __name__ == "__main__": - unittest.main()