diff --git a/CMakeLists.txt b/CMakeLists.txt index ebaffc6753112bd86b451c7f0ea9c4c20dac0bf3..c1b77656f672b56bb72870b52dcd0e01c7c365f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -578,18 +578,19 @@ endif ( ) ## ############################################################################################################################# if ( WALBERLA_BUILD_WITH_CODEGEN ) - find_package( PythonInterp 3 QUIET REQUIRED) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import lbmpy" + set( Python_FIND_FRAMEWORK LAST ) + find_package (Python COMPONENTS Interpreter Development) + execute_process(COMMAND ${Python_EXECUTABLE} -c "import lbmpy" RESULT_VARIABLE LBMPY_FOUND ) if(NOT LBMPY_FOUND EQUAL 0) message(FATAL_ERROR "WALBERLA_BUILD_WITH_CODEGEN activated but pystencils or lbmpy package not found. Please install lbmpy e.g.: 'pip3 install lbmpy'") endif() - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from pystencils.include import get_pystencils_include_path; print(get_pystencils_include_path())" + execute_process(COMMAND ${Python_EXECUTABLE} -c "from pystencils.include import get_pystencils_include_path; print(get_pystencils_include_path())" OUTPUT_VARIABLE PYSTENCILS_INCLUDE_PATH) include_directories( ${PYSTENCILS_INCLUDE_PATH} ) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import jinja2" + execute_process(COMMAND ${Python_EXECUTABLE} -c "import jinja2" RESULT_VARIABLE JINJA2_FOUND ) if(NOT JINJA2_FOUND EQUAL 0) message(FATAL_ERROR "WALBERLA_BUILD_WITH_CODEGEN activated and jinja2 package not found. @@ -607,13 +608,8 @@ endif() ## ############################################################################################################################# if ( WALBERLA_BUILD_WITH_PYTHON ) - - find_package( PythonInterp 3.6 QUIET REQUIRED) - find_package( PythonLibs QUIET REQUIRED) - - if( NOT (PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR ) ) - message( FATAL_ERROR "Couldn't find any python library" ) - endif() + set( Python_FIND_FRAMEWORK LAST ) + find_package( Python COMPONENTS Interpreter Development REQUIRED) if(WALBERLA_CXX_COMPILER_IS_INTEL) # Intel C++17 support introduced in 2.6.2 (https://github.com/pybind/pybind11/pull/2729) @@ -622,11 +618,11 @@ if ( WALBERLA_BUILD_WITH_PYTHON ) set(PYBIND11_MINIMUM_VERSION "2.6.0") endif() - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import pybind11; print(pybind11._version.__version__)" + execute_process(COMMAND ${Python_EXECUTABLE} -c "import pybind11; print(pybind11._version.__version__)" OUTPUT_VARIABLE pybind11_VERSION ERROR_QUIET RESULT_VARIABLE pybind11_VERSION_RESULT) string(STRIP "${pybind11_VERSION}" pybind11_VERSION) if(pybind11_VERSION_RESULT EQUAL "0" AND pybind11_VERSION VERSION_GREATER_EQUAL "${PYBIND11_MINIMUM_VERSION}") - execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pybind11 --cmakedir + execute_process(COMMAND ${Python_EXECUTABLE} -m pybind11 --cmakedir OUTPUT_VARIABLE PYBIND11_CMAKE_PATH) string(STRIP "${PYBIND11_CMAKE_PATH}" PYBIND11_CMAKE_PATH) find_package(pybind11 PATHS "${PYBIND11_CMAKE_PATH}" NO_DEFAULT_PATH REQUIRED) @@ -656,10 +652,10 @@ if ( WALBERLA_BUILD_WITH_PYTHON ) add_subdirectory(extern/pybind11) if(pybind11_VERSION VERSION_LESS "2.6.2") - # if pybind11 was installed into ${PYTHON_INCLUDE_DIR} (e.g. by pip), that will have a higher priority than the Git submodule unless we reorder the search path + # if pybind11 was installed into ${Python_INCLUDE_DIRS} (e.g. by pip), that will have a higher priority than the Git submodule unless we reorder the search path # introduced in 2.6.0 (https://github.com/pybind/pybind11/issues/2709), fixed in 2.6.2 (https://github.com/pybind/pybind11/pull/2716) set_property( TARGET pybind11::pybind11 - PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/extern/pybind11/include" "${PYTHON_INCLUDE_DIR}") + PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/extern/pybind11/include" "${Python_INCLUDE_DIRS}") endif() endif() diff --git a/apps/benchmarks/FlowAroundSphereCodeGen/CMakeLists.txt b/apps/benchmarks/FlowAroundSphereCodeGen/CMakeLists.txt index 6f7a128f33735ef9365c6daca215de07f7a09ac0..a598b3323ba5c449b0faac046d1a7fb5e4c2744d 100644 --- a/apps/benchmarks/FlowAroundSphereCodeGen/CMakeLists.txt +++ b/apps/benchmarks/FlowAroundSphereCodeGen/CMakeLists.txt @@ -13,7 +13,6 @@ if (WALBERLA_BUILD_WITH_CUDA) FlowAroundSphereCodeGen_InfoHeader.h) waLBerla_add_executable( NAME FlowAroundSphereCodeGen FILE FlowAroundSphereCodeGen.cpp DEPENDS blockforest boundary core domain_decomposition field geometry timeloop vtk FlowAroundSphereGenerated) - set_target_properties( FlowAroundSphereCodeGen PROPERTIES CXX_VISIBILITY_PRESET hidden) else () waLBerla_generate_target_from_python(NAME FlowAroundSphereGenerated FILE FlowAroundSphereCodeGen.py @@ -27,5 +26,4 @@ else () FlowAroundSphereCodeGen_InfoHeader.h) waLBerla_add_executable( NAME FlowAroundSphereCodeGen FILE FlowAroundSphereCodeGen.cpp DEPENDS blockforest boundary core domain_decomposition field geometry timeloop vtk FlowAroundSphereGenerated) - set_target_properties( FlowAroundSphereCodeGen PROPERTIES CXX_VISIBILITY_PRESET hidden) endif() \ No newline at end of file diff --git a/apps/benchmarks/PhaseFieldAllenCahn/CMakeLists.txt b/apps/benchmarks/PhaseFieldAllenCahn/CMakeLists.txt index 951f04a225d870d92e693c99d3ea3406bd5bc3f7..629c9ec0a609c7312027d037f5504fc3a4d3ecb6 100644 --- a/apps/benchmarks/PhaseFieldAllenCahn/CMakeLists.txt +++ b/apps/benchmarks/PhaseFieldAllenCahn/CMakeLists.txt @@ -16,7 +16,6 @@ if (WALBERLA_BUILD_WITH_CUDA) waLBerla_add_executable(NAME benchmark_multiphase FILES benchmark_multiphase.cpp InitializerFunctions.cpp multiphase_codegen.py DEPENDS blockforest core cuda field postprocessing lbm geometry timeloop gui BenchmarkPhaseFieldCodeGenGPU) - set_target_properties(benchmark_multiphase PROPERTIES CXX_VISIBILITY_PRESET hidden) else () waLBerla_generate_target_from_python(NAME BenchmarkPhaseFieldCodeGenCPU FILE multiphase_codegen.py @@ -32,6 +31,5 @@ else () waLBerla_add_executable(NAME benchmark_multiphase FILES benchmark_multiphase.cpp InitializerFunctions.cpp multiphase_codegen.py DEPENDS blockforest core field postprocessing lbm geometry timeloop gui BenchmarkPhaseFieldCodeGenCPU) - set_target_properties(benchmark_multiphase PROPERTIES CXX_VISIBILITY_PRESET hidden) endif (WALBERLA_BUILD_WITH_CUDA) diff --git a/apps/benchmarks/UniformGridGPU/CMakeLists.txt b/apps/benchmarks/UniformGridGPU/CMakeLists.txt index a3a430204b232de43d07819e1a1647d6e444b999..d084f8171a9581f0e1aded38cde8182d7821f815 100644 --- a/apps/benchmarks/UniformGridGPU/CMakeLists.txt +++ b/apps/benchmarks/UniformGridGPU/CMakeLists.txt @@ -25,7 +25,6 @@ foreach(streaming_pattern pull push aa esotwist) waLBerla_add_executable(NAME UniformGridGPU_${config} FILES UniformGridGPU.cpp DEPENDS blockforest boundary core cuda domain_decomposition field geometry timeloop vtk UniformGridGPUGenerated_${config}) - set_target_properties( UniformGridGPU_${config} PROPERTIES CXX_VISIBILITY_PRESET hidden) # all configs are excluded from all except for pull d3q27. if (${streaming_pattern} STREQUAL "pull" AND ${stencil} STREQUAL "d3q27") diff --git a/apps/benchmarks/UniformGridGenerated/CMakeLists.txt b/apps/benchmarks/UniformGridGenerated/CMakeLists.txt index d0b16d6e20b4c3fd5068608c921d793f8633f8b3..dda05f8fdda22c560543253a3a8f97e21781afc3 100644 --- a/apps/benchmarks/UniformGridGenerated/CMakeLists.txt +++ b/apps/benchmarks/UniformGridGenerated/CMakeLists.txt @@ -16,6 +16,5 @@ foreach(config srt trt smagorinsky mrt entropic_kbc_n4 cumulant ) FILES UniformGridGenerated.cpp DEPENDS blockforest boundary core domain_decomposition field geometry timeloop vtk gui UniformGridGenerated_${config} python_coupling) - set_target_properties(UniformGridBenchmarkGenerated_${config} PROPERTIES CXX_VISIBILITY_PRESET hidden) endforeach() diff --git a/apps/pythonmodule/CMakeLists.txt b/apps/pythonmodule/CMakeLists.txt index 38290ffa55a94e9e4effa3502dcfde4d328e2622..ee58a3257f9d9408f3da4eb608663e429aea84f1 100644 --- a/apps/pythonmodule/CMakeLists.txt +++ b/apps/pythonmodule/CMakeLists.txt @@ -25,10 +25,9 @@ if ( WALBERLA_BUILD_WITH_PYTHON ) SUFFIX "${PYTHON_MODULE_EXTENSION}" ) set_target_properties( walberla_cpp PROPERTIES MACOSX_RPATH TRUE ) - set_target_properties( walberla_cpp PROPERTIES CXX_VISIBILITY_PRESET hidden) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/setup.py ${CMAKE_CURRENT_BINARY_DIR}/setup.py ) - add_custom_target( pythonModule ALL ${PYTHON_EXECUTABLE} setup.py build DEPENDS walberla_cpp ) - add_custom_target( pythonModuleInstall ${PYTHON_EXECUTABLE} setup.py install --user DEPENDS walberla_cpp ) + add_custom_target( pythonModule ALL ${Python_EXECUTABLE} setup.py build DEPENDS walberla_cpp ) + add_custom_target( pythonModuleInstall ${Python_EXECUTABLE} setup.py install --user DEPENDS walberla_cpp ) endif() diff --git a/apps/showcases/PhaseFieldAllenCahn/CPU/CMakeLists.txt b/apps/showcases/PhaseFieldAllenCahn/CPU/CMakeLists.txt index cf550a8e1f8392dbce80bb709ac71c3857724787..07cc9000ed8a1b2dc6f952904d6b217c868629b0 100644 --- a/apps/showcases/PhaseFieldAllenCahn/CPU/CMakeLists.txt +++ b/apps/showcases/PhaseFieldAllenCahn/CPU/CMakeLists.txt @@ -19,5 +19,3 @@ waLBerla_generate_target_from_python(NAME PhaseFieldCodeGenCPU waLBerla_add_executable(NAME multiphaseCPU FILES multiphase.cpp PythonExports.cpp InitializerFunctions.cpp multiphase_codegen.py DEPENDS blockforest core field postprocessing lbm geometry timeloop gui PhaseFieldCodeGenCPU) - -set_target_properties(multiphaseCPU PROPERTIES CXX_VISIBILITY_PRESET hidden) diff --git a/apps/showcases/PhaseFieldAllenCahn/GPU/CMakeLists.txt b/apps/showcases/PhaseFieldAllenCahn/GPU/CMakeLists.txt index a8ff39721f322b6bdd5deed047984176ed570c15..8cd135d5615458707f86cd2f0b0811f11da99ccf 100644 --- a/apps/showcases/PhaseFieldAllenCahn/GPU/CMakeLists.txt +++ b/apps/showcases/PhaseFieldAllenCahn/GPU/CMakeLists.txt @@ -19,5 +19,3 @@ waLBerla_generate_target_from_python(NAME PhaseFieldCodeGenGPU waLBerla_add_executable(NAME multiphaseGPU FILES multiphase.cpp PythonExports.cpp InitializerFunctions.cpp util.cpp multiphase_codegen.py DEPENDS blockforest core cuda field postprocessing lbm geometry timeloop gui PhaseFieldCodeGenGPU) - -set_target_properties(multiphaseGPU PROPERTIES CXX_VISIBILITY_PRESET hidden) diff --git a/cmake/waLBerlaHelperFunctions.cmake b/cmake/waLBerlaHelperFunctions.cmake index 50e457c071b8b9e5681c40baa4ae7794af1ee876..b8c0f2ecb07ddf34105fc3c4e5e1f45a69dc8f90 100644 --- a/cmake/waLBerlaHelperFunctions.cmake +++ b/cmake/waLBerlaHelperFunctions.cmake @@ -79,7 +79,7 @@ function( waLBerla_generate_target_from_python ) add_custom_command(OUTPUT ${generatedWithAbsolutePath} DEPENDS ${sourceFile} - COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${WALBERLA_PYTHON_DIR}:$ENV{PYTHONPATH} ${PYTHON_EXECUTABLE} ${sourceFile} ${pythonParameters} + COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${WALBERLA_PYTHON_DIR}:$ENV{PYTHONPATH} ${Python_EXECUTABLE} ${sourceFile} ${pythonParameters} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${codegenCfg}") add_library(${PYGEN_NAME} ${generatedWithAbsolutePath}) diff --git a/extern/pybind11 b/extern/pybind11 index 8de7772cc72daca8e947b79b83fea46214931604..f7b499615e14d70ab098a20deb0cdb3889998a1a 160000 --- a/extern/pybind11 +++ b/extern/pybind11 @@ -1 +1 @@ -Subproject commit 8de7772cc72daca8e947b79b83fea46214931604 +Subproject commit f7b499615e14d70ab098a20deb0cdb3889998a1a diff --git a/src/python_coupling/CMakeLists.txt b/src/python_coupling/CMakeLists.txt index 882a6d559986692861fe38fd58c9f463b32a82c0..758289636ada5eefe4bdf7d8d02290c8f83dedcd 100644 --- a/src/python_coupling/CMakeLists.txt +++ b/src/python_coupling/CMakeLists.txt @@ -1,5 +1,4 @@ if (WALBERLA_BUILD_WITH_PYTHON) waLBerla_add_module(DEPENDS core communication domain_decomposition stencil field blockforest vtk cuda) target_link_libraries(python_coupling PUBLIC pybind11::embed core domain_decomposition) - set_target_properties(python_coupling PROPERTIES CXX_VISIBILITY_PRESET hidden) endif() \ No newline at end of file diff --git a/src/python_coupling/DictWrapper.h b/src/python_coupling/DictWrapper.h index c7f1f9511b2b8ef31f2bb01a57f702c14ee7704f..c51902cfa9a58c493760a59a5c440d149140fdd6 100644 --- a/src/python_coupling/DictWrapper.h +++ b/src/python_coupling/DictWrapper.h @@ -60,7 +60,6 @@ namespace python_coupling { #ifdef WALBERLA_BUILD_WITH_PYTHON - public: pybind11::dict & dict() { return d_; } const pybind11::dict & dict() const { return d_; } protected: diff --git a/src/python_coupling/Manager.cpp b/src/python_coupling/Manager.cpp index 4b22df9746a03c20ed8047014ad565efb4333573..eaae658adc6b4d0e5c3a4054e3c8b38d462b597d 100644 --- a/src/python_coupling/Manager.cpp +++ b/src/python_coupling/Manager.cpp @@ -97,6 +97,7 @@ void Manager::triggerInitialization() py::module::import("__main__"); py::module::import("walberla_cpp"); + // Setup python path addPath( std::string(WALBERLA_SOURCE_DIR) + "/python" ); diff --git a/src/python_coupling/PythonCallback.cpp b/src/python_coupling/PythonCallback.cpp index b4d0fb6d8a1fefcdbbf562ab3ea163e26ada1bae..61ef6a1cc9f4a76fba5850574404af8ea95a526e 100644 --- a/src/python_coupling/PythonCallback.cpp +++ b/src/python_coupling/PythonCallback.cpp @@ -22,7 +22,7 @@ #include "PythonCallback.h" #include "DictWrapper.h" - +#include "core/logging/all.h" #ifdef WALBERLA_BUILD_WITH_PYTHON #include "Manager.h" @@ -69,7 +69,6 @@ namespace python_coupling { } catch ( py::error_already_set &e) { throw py::value_error(e.what()); - return py::none(); } } @@ -122,7 +121,7 @@ namespace python_coupling { { if ( ! isCallable() ) WALBERLA_ABORT_NO_DEBUG_INFO( "Could not call python function '" << functionName_ << "'. " << - "Did you forget to set the callback function?" ); + "Did you forget to set the callback function?" ) namespace py = pybind11; diff --git a/src/python_coupling/PythonCallback.h b/src/python_coupling/PythonCallback.h index 5d7aeb48cdb396e5531248bc0040c78cb5a3f526..038b544a27d196a1c85d462226f9941636882331 100644 --- a/src/python_coupling/PythonCallback.h +++ b/src/python_coupling/PythonCallback.h @@ -82,8 +82,8 @@ namespace python_coupling { PythonCallback(); PythonCallback( const std::string & functionName ); PythonCallback( const std::string & moduleOrFile, - const std::string & functionName, - const std::vector<std::string> & argv = std::vector<std::string>() ); + const std::string & functionName, + const std::vector<std::string> & argv = std::vector<std::string>() ); DictWrapper & data() { return *exposedVars_; } const DictWrapper & data() const { return *exposedVars_; } @@ -97,9 +97,5 @@ namespace python_coupling { shared_ptr<DictWrapper> callbackDict_; }; - - } // namespace python_coupling } // namespace walberla - - diff --git a/src/python_coupling/PythonWrapper.h b/src/python_coupling/PythonWrapper.h index 9e1bfe173502d86b86d5b0fb696bf5eff4855f71..d609230d62d77cf3b4b053b3832df78bffc08b7c 100644 --- a/src/python_coupling/PythonWrapper.h +++ b/src/python_coupling/PythonWrapper.h @@ -28,6 +28,14 @@ #ifdef WALBERLA_BUILD_WITH_PYTHON // macro defined in waLBerlaDefinitions.h +#define PYBIND11_NAMESPACE walberla::pybind11 + +namespace PYBIND11_NAMESPACE {} +namespace pybind11 { + // pybind11 uses ::pybind11 in a few places internally, so we need this alias + using namespace PYBIND11_NAMESPACE; +} + #include "pybind11/pybind11.h" #endif diff --git a/src/python_coupling/export/BasicExport.cpp b/src/python_coupling/export/BasicExport.cpp index 767a6fd0c0ef18344a0f947e2114e78ab211428a..22b444d1b97040a3b50e489da14853d4d783b09e 100644 --- a/src/python_coupling/export/BasicExport.cpp +++ b/src/python_coupling/export/BasicExport.cpp @@ -373,63 +373,6 @@ void timingTreeStopWrapper(WcTimingTree & tt, const std::string& name) tt.stop(name); } -void exportTiming(py::module_ &m) -{ - py::class_<WcTimer> (m, "Timer") - .def( py::init<>() ) - .def( "start", &WcTimer::start ) - .def( "stop", &WcTimer::end ) - .def( "reset", &WcTimer::reset ) - .def( "merge", &WcTimer::merge ) - .def_property_readonly( "counter", &WcTimer::getCounter ) - .def_property_readonly( "total", &WcTimer::total ) - .def_property_readonly( "sumOfSquares", &WcTimer::sumOfSquares ) - .def_property_readonly( "average", &WcTimer::average ) - .def_property_readonly( "variance", &WcTimer::variance ) - .def_property_readonly( "min", &WcTimer::min ) - .def_property_readonly( "max", &WcTimer::max ) - .def_property_readonly( "last", &WcTimer::last ) - ; - - - WcTimer & ( WcTimingPool::*pGetItem ) ( const std::string & ) = &WcTimingPool::operator[]; - - { - py::scope classScope = - py::class_<WcTimingPool, shared_ptr<WcTimingPool> > (m, "TimingPool") - .def( py::init<>() ) - .def_property_readonly( "__getitem__", pGetItem) - .def( "__contains__", &WcTimingPool::timerExists ) - .def( "getReduced", &WcTimingPool::getReduced) - .def( "merge", &WcTimingPool::merge) - .def( "clear", &WcTimingPool::clear ) - .def( "unifyRegisteredTimersAcrossProcesses", &WcTimingPool::unifyRegisteredTimersAcrossProcesses ) - .def( "logResultOnRoot", &WcTimingPool::logResultOnRoot) - ; - WALBERLA_UNUSED( classScope ); - - py::enum_<timing::ReduceType>(m, "ReduceType") - .value("min" , timing::REDUCE_MIN) - .value("avg" , timing::REDUCE_AVG) - .value("max" , timing::REDUCE_MAX) - .value("total", timing::REDUCE_TOTAL) - .export_values() - ; - } - - const WcTimer & ( WcTimingTree::*pTimingTreeGet ) ( const std::string & ) const = &WcTimingTree::operator[]; - py::class_<WcTimingTree, shared_ptr<WcTimingTree> > (m, "TimingTree") - .def( py::init<>() ) - .def_property_readonly( "__getitem__", pTimingTreeGet ) - .def( "start", &WcTimingTree::start ) - .def( "stop", &timingTreeStopWrapper ) - .def( "getReduced", &WcTimingTree::getReduced ) - .def( "toDict", &buildDictFromTimingTree ) - ; -} - - - //====================================================================================================================== // @@ -700,8 +643,6 @@ void exportBasicWalberlaDatastructures(py::module_ &m) exportCellInterval(m); exportAABB(m); - exportTiming(m); - exportIBlock(m); exportCommunication(m); diff --git a/tests/python_coupling/CMakeLists.txt b/tests/python_coupling/CMakeLists.txt index 462c2b8f201e78ac51bd7d793c3198a6214a2e6a..81ab5fc723a5cdd4851a61c849ff3e662ef985a9 100644 --- a/tests/python_coupling/CMakeLists.txt +++ b/tests/python_coupling/CMakeLists.txt @@ -14,12 +14,10 @@ if (WALBERLA_BUILD_WITH_PYTHON) waLBerla_compile_test( FILES CallbackTest.cpp DEPENDS blockforest field ) waLBerla_execute_test( NAME CallbackTest COMMAND $<TARGET_FILE:CallbackTest> ${CMAKE_CURRENT_SOURCE_DIR}/CallbackTest.py ) - set_target_properties(CallbackTest PROPERTIES CXX_VISIBILITY_PRESET hidden) waLBerla_compile_test( FILES FieldExportTest.cpp DEPENDS blockforest field ) waLBerla_execute_test( NAME FieldExportTest COMMAND $<TARGET_FILE:FieldExportTest> ${CMAKE_CURRENT_SOURCE_DIR}/FieldExportTest.py ) - set_target_properties(FieldExportTest PROPERTIES CXX_VISIBILITY_PRESET hidden) add_test( NAME PythonWalberlaTest COMMAND python3 -m unittest discover waLBerla_tests/ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python/) diff --git a/tests/python_coupling/CallbackTest.cpp b/tests/python_coupling/CallbackTest.cpp index 08790f31f02a810a17aa30faf26a33f3b2f1156d..be90b3055396da7f0d19615456d88211d8a825df 100644 --- a/tests/python_coupling/CallbackTest.cpp +++ b/tests/python_coupling/CallbackTest.cpp @@ -32,14 +32,18 @@ using namespace walberla; +using ScalarField = GhostLayerField<int, 1>; + int main( int argc, char ** argv ) { auto pythonManager = python_coupling::Manager::instance(); - pythonManager->addExporterFunction( field::exportModuleToPython<Field<int,1>> ); + pythonManager->addExporterFunction( field::exportModuleToPython<Field<int, 1>> ); + pythonManager->triggerInitialization(); - if ( argc != 2 ) { - WALBERLA_ABORT_NO_DEBUG_INFO("Wrong parameter count: \nUsage: \n ./CallbackTest CallbackTest.py"); + if ( argc != 2 ) + { + WALBERLA_ABORT_NO_DEBUG_INFO("Wrong parameter count: \nUsage: \n ./CallbackTest CallbackTest.py") } std::string pythonFile ( argv[1] ); @@ -58,25 +62,27 @@ int main( int argc, char ** argv ) // This callback should sum up the two given integers python_coupling::PythonCallback cb1 ( pythonFile, "cb1" ); - WALBERLA_ASSERT( cb1.isCallable() ); + WALBERLA_ASSERT( cb1.isCallable() ) + cb1.data().exposeValue("input1", 5); cb1.data().exposeValue("input2", 10); cb1(); + int result = cb1.data().get<int>( "returnValue" ); - WALBERLA_CHECK_EQUAL( result, 15 ); - typedef GhostLayerField<int,1> ScalarField; + WALBERLA_CHECK_EQUAL( result, 15 ) + + ScalarField f ( 3,2,2, 1, 25 ); python_coupling::PythonCallback cb2 ( pythonFile, "cb2" ); - WALBERLA_ASSERT( cb2.isCallable() ); + + WALBERLA_ASSERT( cb2.isCallable() ) + cb2.data().exposePtr("field", &f ); cb2(); - WALBERLA_CHECK_EQUAL( f(0,0,0), 42 ); - WALBERLA_CHECK_EQUAL( f(-1,-1,-1), 5 ); - - //python_coupling::Shell shell("MyGreatInputShell"); - //shell(); + WALBERLA_CHECK_EQUAL( f(0,0,0), 42 ) + WALBERLA_CHECK_EQUAL( f(-1,-1,-1), 5 ) - return 0; + return EXIT_SUCCESS; } diff --git a/tests/python_coupling/ConfigFromPythonTest.cpp b/tests/python_coupling/ConfigFromPythonTest.cpp index 7b3437463d4fffc0cb3c4f50c123ab9e43ad913b..33a822699aaad82b357c6836f3527cc93b077696 100644 --- a/tests/python_coupling/ConfigFromPythonTest.cpp +++ b/tests/python_coupling/ConfigFromPythonTest.cpp @@ -55,7 +55,7 @@ int main(int argc, char** argv) WALBERLA_CHECK(testString == "someString") WALBERLA_CHECK(testDouble > 42 && testDouble < 43) - WALBERLA_CHECK(testVector == Vector3< real_t >(0.5, 0.5, 0.7)) + WALBERLA_CHECK(testVector == Vector3< real_t >(real_c(0.5), real_c(0.5), real_c(0.7))) WALBERLA_CHECK(testBool == false) WALBERLA_LOG_INFO_ON_ROOT(test_int) diff --git a/tests/python_coupling/FieldExportTest.cpp b/tests/python_coupling/FieldExportTest.cpp index b78bc36828ada3cad436f49d2e103699fc81240e..eb7d5020d9df64c3040a1373a0385e489951564a 100644 --- a/tests/python_coupling/FieldExportTest.cpp +++ b/tests/python_coupling/FieldExportTest.cpp @@ -32,6 +32,7 @@ #include "python_coupling/PythonWrapper.h" #include "python_coupling/export/BlockForestExport.h" #include "python_coupling/export/FieldExports.h" +#include <pybind11/embed.h> #include "stencil/D2Q9.h" @@ -44,11 +45,18 @@ int main( int argc, char ** argv ) debug::enterTestMode(); mpi::Environment mpiEnv( argc, argv ); + if ( argc != 2 ) + { + WALBERLA_ABORT_NO_DEBUG_INFO("Wrong parameter count: \nUsage: \n ./FieldExportTest FieldExportTest.py") + } + std::string pythonFile ( argv[1] ); + auto pythonManager = python_coupling::Manager::instance(); pythonManager->addExporterFunction( field::exportModuleToPython<Field<int, 3>, Field<real_t, 3>> ); pythonManager->addBlockDataConversion< Field<int, 3>, Field<real_t, 3> >() ; pythonManager->addExporterFunction( blockforest::exportModuleToPython<stencil::D2Q9> ); + pythonManager->triggerInitialization(); shared_ptr< StructuredBlockForest > blocks = blockforest::createUniformBlockGrid( 1,1,1, 20,20,1, real_t(1.0), false, true,true,true ); @@ -58,7 +66,6 @@ int main( int argc, char ** argv ) auto srcDoubleFieldID = field::addToStorage< GhostLayerField<real_t, 3> >( blocks, "srcDoubleFieldID", real_t(0.0), field::fzyx, 1 ); auto dstDoubleFieldID = field::addToStorage< GhostLayerField<real_t, 3> >( blocks, "dstDoubleFieldID", real_t(0.0), field::fzyx, 1 ); - // random init for( auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt ) { @@ -70,14 +77,11 @@ int main( int argc, char ** argv ) *cellIt = math::realRandom( real_t(0.0), real_t(42.0) ); } - // call python function which should copy over the values to the Vector fields - std::string pythonFile ( argv[1] ); python_coupling::PythonCallback cb ( pythonFile, "theCallback" ); - WALBERLA_ASSERT( cb.isCallable() ); + WALBERLA_ASSERT( cb.isCallable() ) cb.data().exposeValue("blocks", blocks); cb(); - // check for equivalence for( auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt ) { @@ -91,20 +95,18 @@ int main( int argc, char ** argv ) for(cell_idx_t y = 0; y < cell_idx_c(srcIntField->zSize()); ++y) for(cell_idx_t x = 0; x < cell_idx_c(srcIntField->zSize()); ++x) { - WALBERLA_CHECK_EQUAL( srcIntField->get(x,y,z, 0), dstIntField->get(x,y,z, 0) ); - WALBERLA_CHECK_EQUAL( srcIntField->get(x,y,z, 1), dstIntField->get(x,y,z, 1) ); + WALBERLA_CHECK_EQUAL( srcIntField->get(x,y,z, 0), dstIntField->get(x,y,z, 0) ) + WALBERLA_CHECK_EQUAL( srcIntField->get(x,y,z, 1), dstIntField->get(x,y,z, 1) ) } for(cell_idx_t z = 0; z < cell_idx_c(srcDoubleField->zSize()); ++z) for(cell_idx_t y = 0; y < cell_idx_c(srcDoubleField->zSize()); ++y) for(cell_idx_t x = 0; x < cell_idx_c(srcDoubleField->zSize()); ++x) { - WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 0), dstDoubleField->get(x,y,z, 0) ); - WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 1), dstDoubleField->get(x,y,z, 1) ); - WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 2), dstDoubleField->get(x,y,z, 2) ); + WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 0), dstDoubleField->get(x,y,z, 0) ) + WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 1), dstDoubleField->get(x,y,z, 1) ) + WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 2), dstDoubleField->get(x,y,z, 2) ) } } } - - - return 0; + return EXIT_SUCCESS; } diff --git a/utilities/conda/openmesh/bld.bat b/utilities/conda/openmesh/bld.bat index a5583cece55570bbd09d48ebb8d00b73180caf75..d8e5fcb3a782cfafee42984429d4610bb9ccec53 100644 --- a/utilities/conda/openmesh/bld.bat +++ b/utilities/conda/openmesh/bld.bat @@ -10,7 +10,7 @@ cmake -LAH -G"Visual Studio 15 2017 Win64" ^ -DCMAKE_FIND_ROOT_PATH="%LIBRARY_PREFIX%" ^ -DCMAKE_INSTALL_PREFIX="%LIBRARY_PREFIX%" ^ -DBUILD_APPS=OFF ^ - -DPYTHON_LIBRARY:FILEPATH="%PYTHON_LIBRARY%" ^ + -DPython_EXECUTABLE:FILEPATH="%PYTHON_LIBRARY%" ^ -DOPENMESH_PYTHON_VERSION="%PY_VER%" ^ -DPYTHON_INSTALL_DIR="%SP_DIR%" ^ -DOPENMESH_BUILD_PYTHON_UNIT_TESTS=ON ..