diff --git a/exercice_4/src/particles_factory_interface.hh b/exercice_4/src/particles_factory_interface.hh index 793d97b..623fb19 100644 --- a/exercice_4/src/particles_factory_interface.hh +++ b/exercice_4/src/particles_factory_interface.hh @@ -1,42 +1,48 @@ #ifndef __PARTICLES_FACTORY_INTERFACE__HH__ #define __PARTICLES_FACTORY_INTERFACE__HH__ /* -------------------------------------------------------------------------- */ #include "system_evolution.hh" /* -------------------------------------------------------------------------- */ //! Abstract factory defining interface class ParticlesFactoryInterface { // Constructors/Destructors protected: //! Instance constructor (protected) ParticlesFactoryInterface() = default; public: virtual ~ParticlesFactoryInterface() = default; // Methods public: //! Create a whole simulation from file - virtual SystemEvolution& createSimulation(const std::string& fname, + virtual SystemEvolution &createSimulation(const std::string &fname, Real timestep) = 0; //! Create a new particle virtual std::unique_ptr createParticle() = 0; //! Get singleton instance - static ParticlesFactoryInterface& getInstance(); + static ParticlesFactoryInterface &getInstance(); //! get reference to the system evolution - SystemEvolution& getSystemEvolution() { return *system_evolution; }; + SystemEvolution &getSystemEvolution() { return *system_evolution; }; + + template + SystemEvolution &createSimulation(const std::string &fname, Real timestep, + Func func) { + return this->createSimulation(fname, timestep); + } // Members protected: - std::vector list_particles; + std::vector list_particles; std::unique_ptr system_evolution = nullptr; // Standard pointer because constructor is protected (cannot use make_unique) - static ParticlesFactoryInterface* factory; + static ParticlesFactoryInterface *factory; }; /* -------------------------------------------------------------------------- */ -#endif //__PARTICLES_FACTORY_INTERFACE__HH__ +#endif //__PARTICLES_FACTORY_INTERFACE__HH__ diff --git a/exercice_4/src/pypart_pybind.cc b/exercice_4/src/pypart_pybind.cc index 95664d4..6e026dd 100644 --- a/exercice_4/src/pypart_pybind.cc +++ b/exercice_4/src/pypart_pybind.cc @@ -1,81 +1,78 @@ #include "compute_temperature.hh" #include "csv_writer.hh" #include "material_points_factory.hh" #include "particles_factory_interface.hh" #include "ping_pong_balls_factory.hh" #include "planets_factory.hh" #include namespace py = pybind11; PYBIND11_MODULE(pypart, m) { m.doc() = "pybind for particles code"; py::class_(m, "ParticlesFactoryInterface") .def("getInstance", &ParticlesFactoryInterface::getInstance, py::return_value_policy::reference) - .def("createSimulation", &ParticlesFactoryInterface::createSimulation); + .def("createSimulation", + py::overload_cast( + &ParticlesFactoryInterface::createSimulation), + py::return_value_policy::reference); py::class_( m, "MaterialPointsFactory") .def("getInstance", &MaterialPointsFactory::getInstance, py::return_value_policy::reference) - /*.def("createSimulation", py::overload_cast( - &MaterialPointsFactory::createSimulation)) - // no need for py::overload_cast - .def("createSimulation", - py::overload_cast( - &MaterialPointsFactory::createSimulation)); - */ - .def("createSimulation", // less elegant way to do the overload cast --> - // forum - (SystemEvolution & - (MaterialPointsFactory::*)(const std::string &, Real)) & - MaterialPointsFactory::createSimulation) .def("createSimulation", py::overload_cast( &MaterialPointsFactory::createSimulation), py::return_value_policy::reference) .def_property_readonly("system_evolution", &MaterialPointsFactory::getSystemEvolution); py::class_( m, "PingPongBallsFactory") .def("getInstance", &PingPongBallsFactory::getInstance, py::return_value_policy::reference) - .def("createSimulation", &PingPongBallsFactory::createSimulation); + .def("createSimulation", + py::overload_cast( + &ParticlesFactoryInterface::createSimulation), + py::return_value_policy::reference); py::class_(m, "PlanetsFactory") .def("getInstance", &PlanetsFactory::getInstance, py::return_value_policy::reference) - .def("createSimulation", &PlanetsFactory::createSimulation); + .def("createSimulation", + py::overload_cast( + &ParticlesFactoryInterface::createSimulation), + py::return_value_policy::reference); py::class_>(m, "Compute"); py::class_>( m, "ComputeTemperature") .def(py::init()) .def("compute", &ComputeTemperature::compute) .def_property("conductivity", &ComputeTemperature::getConductivity, &ComputeTemperature::setConductivity) .def_property("capacity", &ComputeTemperature::getCapacity, &ComputeTemperature::setCapacity) .def_property("density", &ComputeTemperature::getDensity, &ComputeTemperature::setDensity) .def_property("L", &ComputeTemperature::getL, &ComputeTemperature::setL) .def_property("deltat", &ComputeTemperature::getDeltat, &ComputeTemperature::setDeltat); py::class_>(m, "CsvWriter") .def(py::init()) .def("write", &CsvWriter::write); py::class_(m, "System"); py::class_(m, "SystemEvolution") .def("setNSteps", &SystemEvolution::setNSteps) .def("setDumpFreq", &SystemEvolution::setDumpFreq) .def("evolve", &SystemEvolution::evolve) .def("addCompute", &SystemEvolution::addCompute) .def("getSystem", &SystemEvolution::getSystem); }