diff --git a/HW4/CMakeLists.txt b/HW4/CMakeLists.txt index f589231..972f39b 100644 --- a/HW4/CMakeLists.txt +++ b/HW4/CMakeLists.txt @@ -1,101 +1,107 @@ cmake_minimum_required (VERSION 3.1) project (Particles) cmake_policy(VERSION 3.3) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(CMAKE_CXX_STANDARD 14) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") ################################################################ # FFTW ################################################################ #find_package(FFTW) # FFTW3 Check on/off - on by default option (FFTW_ENABLE "Use FFTW Library" ON) if (FFTW_ENABLE) # Find the library find_library(FFT_LIBRARY fftw3) endif (FFTW_ENABLE) ################################################################ # Pybind11 ################################################################ # (attached file "pybind11") option (PYBIND_ENABLE "Use FFTW Library" ON) if (PYBIND_ENABLE) - # Add the library + # Add the library by subdirectory -> For Ubuntu add_subdirectory(pybind11) + + # Link the wrapper library + add_library(pypart MODULE py_wrap.cc) + target_link_libraries(pypart PRIVATE pybind11::module) + set_target_properties(pypart PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" + SUFFIX "${PYTHON_MODULE_EXTENSION}") # Copy main.py file to the binaries directory file( COPY ${CMAKE_CURRENT_SOURCE_DIR}/main.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ ) endif (PYBIND_ENABLE) ################################################################ # libpart ################################################################ add_library(part SHARED compute_boundary.cc compute_verlet_integration.cc particle.cc planet.cc compute_gravity.cc csv_reader.cc particles_factory_interface.cc planets_factory.cc compute_contact.cc compute_kinetic_energy.cc csv_writer.cc system.cc compute_energy.cc compute_potential_energy.cc ping_pong_ball.cc material_point.cc system_evolution.cc ping_pong_balls_factory.cc compute_interaction.cc compute_temperature.cc material_points_factory.cc ) target_link_libraries(part ${FFTW_LIBRARIES}) add_executable(particles main.cc) target_link_libraries(particles part) ################################################################ # Google test ################################################################ include(GoogleTest) enable_testing() find_package(GTest) if (GTEST_FOUND) include_directories(${GTEST_INCLUDE_DIRS}) add_executable(test_kepler test_kepler.cc) add_executable(test_fft test_fft.cc) target_link_libraries(test_kepler part ${GTEST_BOTH_LIBRARIES} pthread) target_link_libraries(test_fft part ${GTEST_BOTH_LIBRARIES} ${FFTW_LIBRARIES} pthread) gtest_discover_tests(test_kepler) gtest_discover_tests(test_fft) endif() ################################################################ # Doxygen ################################################################ find_package(Doxygen) if (DOXYGEN_FOUND) # to set other options, read: https://cmake.org/cmake/help/v3.9/module/FindDoxygen.html doxygen_add_docs( doxygen ${PROJECT_SOURCE_DIR} COMMENT "Generate html pages" ) add_custom_target(doc DEPENDS doxygen) endif(DOXYGEN_FOUND) diff --git a/HW4/py_wrap.cc b/HW4/py_wrap.cc index 00f5b3e..68902af 100644 --- a/HW4/py_wrap.cc +++ b/HW4/py_wrap.cc @@ -1,72 +1,71 @@ #include #include #include "material_points_factory.hh" #include "ping_pong_balls_factory.hh" -#include "particle_factory.hh" -#include "planet_factory.hh" +#include "particles_factory_interface.hh" +#include "planets_factory.hh" #include "compute_temperature.hh" #include "csv_writer.hh" // All the classes which are to be used in python are included here, together with the needed external library. namespace py = pybind11; //Start of the pybind module: PYBIND11_MODULE(pypart,m) { - m.doc="Using the pybind plugin"; - + m.doc()="This file is to wrap the C++ library over a Python API for the particles project."; py::class_(m, "MaterialPointsFactory") .def("getInstance", &MaterialPointsFactory::getInstance, py::return_value_policy::reference) .def("createSimulation", (SystemEvolution & (MaterialPointsFactory::*)(const std::string &, Real)) &MaterialPointsFactory::createSimulation, py::return_value_policy::reference) - + .def("createSimulation", py::overload_cast (&MaterialPointsFactory::createSimulation), - py::return_value_policy::reference); + py::return_value_policy::reference); -// In this case py::overload_cast operator has been used. The reason is that otherwise compiler can not know which method to use and thus produces the error. +// In this case py::overload_cast operator has been used. The reason is that otherwise compiler can not know which method to use and thus produces the error. // In Python method overloading does not exist in the same way like in c++ (there is no overloading resolution by the compiler obviously), thus we use py::overload_cast. }