diff --git a/MANIFEST.in b/MANIFEST.in index 71b403799d0268ee24eddb6c1fcf668792a61b7a..adafcf99560acd9da79aa060194df8263b6e77e0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include pythonbindings/pyfluids/bindings* \ No newline at end of file +include pythonbindings/*/bindings* \ No newline at end of file diff --git a/pythonbindings/CMakeLists.txt b/pythonbindings/CMakeLists.txt index da0ab4ed24c0489714927209577e08d945dd0741..644b308c97760d6a8243ae7782f0737a1d168100 100644 --- a/pythonbindings/CMakeLists.txt +++ b/pythonbindings/CMakeLists.txt @@ -1,35 +1,35 @@ project(VirtualFluidsPython LANGUAGES CUDA CXX) -IF(BUILD_VF_GPU) - pybind11_add_module(python_bindings MODULE src/VirtualFluidsModulesGPU.cpp) - set_target_properties(python_bindings PROPERTIES +pybind11_add_module(python_bindings MODULE src/VirtualFluids.cpp) + +set_target_properties( python_bindings PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pythonbindings/pyfluids OUTPUT_NAME "bindings") - set_source_files_properties(src/VirtualFluidsModulesGPU.cpp PROPERTIES LANGUAGE CUDA) - target_link_libraries(python_bindings PRIVATE GridGenerator VirtualFluids_GPU basics lbmCuda logger) +IF(BUILD_VF_GPU) + set_source_files_properties(src/VirtualFluids.cpp PROPERTIES LANGUAGE CUDA) + target_include_directories(python_bindings PRIVATE ${VF_THIRD_DIR}/cuda_samples/) + target_compile_definitions(python_bindings PRIVATE VF_GPU_PYTHONBINDINGS) + target_link_libraries(python_bindings PRIVATE GridGenerator VirtualFluids_GPU basics lbmCuda logger) ENDIF() -IF(BUILD_VF_CPU) - pybind11_add_module(python_bindings MODULE src/VirtualFluidsModulesCPU.cpp) - pybind11_add_module(pymuparser MODULE src/muParser.cpp) - set_target_properties(python_bindings PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pythonbindings/pyfluids - OUTPUT_NAME "bindings") +IF(BUILD_VF_CPU) + target_compile_definitions(python_bindings PRIVATE VF_METIS VF_MPI VF_CPU_PYTHONBINDINGS) + target_link_libraries(python_bindings PRIVATE simulationconfig VirtualFluidsCore muparser basics) - set_target_properties(pymuparser PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pythonbindings/pyfluids - OUTPUT_NAME "pymuparser_bindings") + # include bindings for muparsers + pybind11_add_module(pymuparser MODULE src/muParser.cpp) # TODO: Move this to MuParser CMakeLists.txt set_target_properties(muparser PROPERTIES POSITION_INDEPENDENT_CODE ON) - target_compile_definitions(python_bindings PRIVATE VF_METIS VF_MPI) + set_target_properties( pymuparser PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pythonbindings/pymuparser + OUTPUT_NAME "bindings") target_compile_definitions(pymuparser PRIVATE VF_METIS VF_MPI) - - target_link_libraries(python_bindings PRIVATE simulationconfig VirtualFluidsCore muparser basics) target_link_libraries(pymuparser PRIVATE muparser) ENDIF() + target_include_directories(python_bindings PRIVATE ${CMAKE_SOURCE_DIR}/src/) target_include_directories(python_bindings PRIVATE ${CMAKE_BINARY_DIR}) \ No newline at end of file diff --git a/pythonbindings/pyfluids/__init__.py b/pythonbindings/pyfluids/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..5584420140073805ac66b07ffb9afe6eb9bd02e3 --- /dev/null +++ b/pythonbindings/pyfluids/__init__.py @@ -0,0 +1,20 @@ +try: + from .bindings import basics +except ImportError: + print("Basics bindings not included") +try: + from .bindings import logger +except ImportError: + print("Logger bindings not included") +try: + from .bindings import lbm +except ImportError: + print("LBM bindings not included") +try: + from .bindings import gpu +except ImportError: + print("GPU bindings not included") +try: + from .bindings import cpu +except ImportError: + print("CPU bindings not included") \ No newline at end of file diff --git a/pythonbindings/pymuparser/__init__.py b/pythonbindings/pymuparser/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..3a2ffbb3663be23e3dffcc4771da5fb24fd45f3e --- /dev/null +++ b/pythonbindings/pymuparser/__init__.py @@ -0,0 +1,4 @@ +try: + from .bindings import Parser +except ImportError as e: + raise ImportError("Pymuparser bindings were not built. Only included if VirtualFluids is built with VF_BUILD_CPU=ON.") \ No newline at end of file diff --git a/pythonbindings/src/VirtualFluidsModulesGPU.cpp b/pythonbindings/src/VirtualFluids.cpp similarity index 67% rename from pythonbindings/src/VirtualFluidsModulesGPU.cpp rename to pythonbindings/src/VirtualFluids.cpp index e0320115e1cf1fcb8c60d19af5a51f3fe92d7562..151d1757530494a928893713de47d9b340d3ca10 100644 --- a/pythonbindings/src/VirtualFluidsModulesGPU.cpp +++ b/pythonbindings/src/VirtualFluids.cpp @@ -1,19 +1,31 @@ #include <pybind11/pybind11.h> #include "basics/basics.cpp" #include "lbm/lbm.cpp" -#include "gpu/gpu.cpp" #include "logger/logger.cpp" +#ifdef VF_GPU_PYTHONBINDINGS +#include "gpu/gpu.cpp" +#endif +#ifdef VF_CPU_PYTHONBINDINGS +#include "cpu/cpu.cpp" +#endif + + namespace py_bindings { namespace py = pybind11; PYBIND11_MODULE(bindings, m) { + py::add_ostream_redirect(m, "ostream_redirect"); basics::makeModule(m); - gpu::makeModule(m); lbm::makeModule(m); logging::makeModule(m); - py::add_ostream_redirect(m, "ostream_redirect"); +#ifdef VF_GPU_PYTHONBINDINGS + gpu::makeModule(m); +#endif +#ifdef VF_CPU_PYTHONBINDINGS + cpu::makeModule(m); +#endif } } \ No newline at end of file diff --git a/pythonbindings/src/VirtualFluidsModulesCPU.cpp b/pythonbindings/src/VirtualFluidsModulesCPU.cpp deleted file mode 100644 index 9201a8ce9ab2f0e61b64ec0263185e5642feca18..0000000000000000000000000000000000000000 --- a/pythonbindings/src/VirtualFluidsModulesCPU.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include <pybind11/pybind11.h> -#include "cpu/cpu.cpp" - -namespace py_bindings -{ - namespace py = pybind11; - - PYBIND11_MODULE(bindings, m) - { - cpu::makeModule(m); - } -} \ No newline at end of file diff --git a/pythonbindings/src/muParser.cpp b/pythonbindings/src/muParser.cpp index 47408c2758fc92991f1be3113d78b8741215b152..0b65d715be20ba0dff48fd57a36c4116bbdfc33d 100644 --- a/pythonbindings/src/muParser.cpp +++ b/pythonbindings/src/muParser.cpp @@ -3,7 +3,7 @@ namespace py = pybind11; -PYBIND11_MODULE(pymuparser, m) { +PYBIND11_MODULE(bindings, m) { py::class_<mu::ParserBase>(m, "_ParserBase"); py::class_<mu::Parser, mu::ParserBase>(m, "Parser") diff --git a/setup.py b/setup.py index 61031c4db52f07369ad7dda4683bb604eb46b896..7c7a5580d02741a0f7a94df06aca1ec8832b2214 100644 --- a/setup.py +++ b/setup.py @@ -1,16 +1,15 @@ import sys from pathlib import Path -import setuptools import skbuild """ Install python wrapper of Virtual Fluids install via python: python setup.py install - set CMAKE Flags via -DBUILD_VF_GPU:BOOL=1 + set CMAKE Flags via -DBUILD_VF_GPU:BOOL=ON CMAKE flags have to be separated by -- - example: python setup.py install -- VBUILD_VF_CPU:BOOL=ON + example: python setup.py install -- -DBUILD_VF_CPU:BOOL=ON or install via pip: pip install . for pip>21: @@ -42,7 +41,7 @@ cmake_args += [ skbuild.setup( name=package_name, - packages=[package_name], + packages=[package_name, "pymuparser"], package_dir={"": src_dir}, cmake_args = cmake_args, cmake_install_target=target,