diff --git a/hw4-pybind/pypart.cc b/hw4-pybind/pypart.cc index 6b9e8c94..1d821a6a 100644 --- a/hw4-pybind/pypart.cc +++ b/hw4-pybind/pypart.cc @@ -1,83 +1,85 @@ #include #include #include #include "material_points_factory.hh" #include "ping_pong_balls_factory.hh" #include "planets_factory.hh" #include "compute.hh" #include "compute_temperature.hh" #include "compute_gravity.hh" #include "compute_verlet_integration.hh" #include "compute_interaction.hh" #include "csv_writer.hh" #include "system.hh" #include "system_evolution.hh" namespace py = pybind11; PYBIND11_MODULE(pypart, m) { m.doc() = "pybind pypart plugin"; // optional docstring // The member functions of the various classes (used in main.py) are exposed to pybind // Exercise 1 - Question 1, 2, 3 py::class_(m, "ParticlesFactoryInterface") .def("getInstance", &ParticlesFactoryInterface::getInstance, py::return_value_policy::reference) + .def("createSimulation",(SystemEvolution & (ParticlesFactoryInterface::*)(const std::string &, Real)) + &ParticlesFactoryInterface::createSimulation, py::return_value_policy::reference) .def("createSimulation",py::overload_cast(&ParticlesFactoryInterface::createSimulation), py::return_value_policy::reference) //.def("createSimulation", &ParticlesFactoryInterface::createSimulation,py::return_value_policy::reference) //.def("createSimulation",py::overload_cast(&ParticlesFactoryInterface::createSimulation),py::return_value_policy::reference) .def_property_readonly("system_evolution", &ParticlesFactoryInterface::getSystemEvolution); py::class_(m, "MaterialPointsFactory") .def("getInstance", &MaterialPointsFactory::getInstance, py::return_value_policy::reference) .def("createSimulation",py::overload_cast(&ParticlesFactoryInterface::createSimulation), 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::class_(m, "PingPongBallsFactory") - .def("getInstance", &PingPongBallsFactory::getInstance, py::return_value_policy::reference) - .def("createSimulation",py::overload_cast(&ParticlesFactoryInterface::createSimulation), - py::return_value_policy::reference); + .def("getInstance", &PingPongBallsFactory::getInstance, py::return_value_policy::reference); + //.def("createSimulation",py::overload_cast(&ParticlesFactoryInterface::createSimulation), + // py::return_value_policy::reference); //.def("createSimulation", &PingPongBallsFactory::createSimulation,py::return_value_policy::reference); py::class_(m, "PlanetsFactory") - .def("getInstance", &PlanetsFactory::getInstance, py::return_value_policy::reference) - .def("createSimulation",py::overload_cast(&ParticlesFactoryInterface::createSimulation), - py::return_value_policy::reference); + .def("getInstance", &PlanetsFactory::getInstance, py::return_value_policy::reference); + //.def("createSimulation",py::overload_cast(&ParticlesFactoryInterface::createSimulation), + // py::return_value_policy::reference); //.def("createSimulation", &PlanetsFactory::createSimulation,py::return_value_policy::reference); // Exercise 2 - Question 1, 2, 3 py::class_>(m, "Compute"); //To try: for memory conflict problem maybe: std::shared_ptr :NO py::class_>(m, "ComputeInteraction"); py::class_>(m, "ComputeTemperature") // (tried: py::dynamic_attr()) .def(py::init<>()) .def_property_readonly("conductivity", &ComputeTemperature::getConductivity) .def_property_readonly("capacity", &ComputeTemperature::getCapacity) .def_property_readonly("L", &ComputeTemperature::getL) .def_property_readonly("deltat", &ComputeTemperature::getDeltat); py::class_>(m, "ComputeGravity") .def(py::init<>()) .def("setG", &ComputeGravity::setG); py::class_>(m, "ComputeVerletIntegration") .def(py::init()) .def("addInteraction", &ComputeVerletIntegration::addInteraction); // Exercise 3 - Question 1 py::class_(m, "CsvWriter") .def(py::init()) .def("write", &CsvWriter::write); py::class_(m, "SystemEvolution") // no heritage but referenced : strange ! system_evolution in main.py !? .def("evolve", &SystemEvolution::evolve) .def("addCompute", &SystemEvolution::addCompute) .def("getSystem", &SystemEvolution::getSystem) .def("setNSteps", &SystemEvolution::setNSteps) .def("setDumpFreq", &SystemEvolution::setDumpFreq); py::class_(m, "System"); // not necessary but added for clarity }