diff --git a/hw4-pybind/pypart.cc b/hw4-pybind/pypart.cc index 1c821eb9..1453a4ba 100644 --- a/hw4-pybind/pypart.cc +++ b/hw4-pybind/pypart.cc @@ -1,64 +1,67 @@ #include #include #include #include "material_points_factory.hh" #include "ping_pong_balls_factory.hh" #include "planets_factory.hh" -#include "csv_writer.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" + namespace py = pybind11; PYBIND11_MODULE(pypart, m) { m.doc() = "pybind pypart plugin"; // optional docstring - - // TODO: - // The member functions of the various classes (used in main.py) must be exposed to pybind + // 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("createSimulation",&createSimulation); - .def("getInstance", &ParticlesFactoryInterface::getInstance); - // DOES NOT COMPILE: - //.def(py::init(m, "MaterialPointsFactory" ) - .def("getInstance", &MaterialPointsFactory::getInstance); // inherits from ParticlesFactoryInterface - py::class_(m, "PingPongBallsFactory" ) // inherits from ParticlesFactoryInterface - .def("getInstance", &PingPongBallsFactory::getInstance); - py::class_(m, "PlanetsFactory" ) // inherits from ParticlesFactoryInterface - .def("getInstance", &PlanetsFactory::getInstance); + .def("getInstance", &ParticlesFactoryInterface::getInstance, 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",(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", &PingPongBallsFactory::createSimulation,py::return_value_policy::reference); + py::class_(m, "PlanetsFactory") + .def("getInstance", &PlanetsFactory::getInstance, py::return_value_policy::reference) + .def("createSimulation", &PlanetsFactory::createSimulation,py::return_value_policy::reference); // Exercise 2 - Question 1, 2, 3 - py::class_(m, "Compute" ); - py::class_(m, "CsvWrite" ) // inherits from Compute - .def("write", &CsvWriter::write); - py::class_(m, "ComputeTemperature", py::dynamic_attr()) // inherits from Compute + 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") // inherits from Compute + py::class_>(m, "ComputeGravity") + .def(py::init<>()) .def("setG", &ComputeGravity::setG); - py::class_(m, "ComputeVerletIntegration") // inherits from Compute + py::class_>(m, "ComputeVerletIntegration") + .def(py::init()) .def("addInteraction", &ComputeVerletIntegration::addInteraction); // Exercise 3 - Question 1 - - py::class_(m, "system_evolution") // no heritage but referenced : strange ! system_evolution in main.py !? + 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, "ComputeInteraction" ); // inherits from Compute - // Should we use the inheritance class in pybind??? Like below? - // py::class_(m, "PingPongBallsFactory"); + py::class_(m, "System"); // not necessary but added for clarity }