diff --git a/exercice_4/README.md b/exercice_4/README.md index 59944d2..6cc11c0 100644 --- a/exercice_4/README.md +++ b/exercice_4/README.md @@ -1,40 +1,41 @@ # Readme exercice 4 code by Marti Bosch (marti.bosch@epfl.ch) and Marc Schwaerzel (marc.schwaerzel@epfl.ch) ## Exercise 1 ## Exercise 2 2.2 We used shared pointers for the pybind of the classes compute and compute_temperature in order not to desallocate when python's reference count goes to 0. A unique pointer could lead to a segmentation fault (memory allocation issues). -2.3 We used the method where we put setters directely in the compute_temperature.py in order to access private members from outside the class.But there is a smarter way to access private members --> reread class notes and implement them +2.3 We used the method where we put setters directely in the compute_temperature.py in order to access private members from outside the class.But there is a smarter way to access private members --> reread class notes and implement them. ## Exercise 3 -In this exercice we need to write csvwrite in the pybind with the given name. -We also need to create setter for evol.setNsteps, evol.setDumpFreq, evol.evolve +created bind for csvwriter, evol.setNsteps, evol.setDumpFreq and evol.evolve... + +still need something for self.system_evolution.addCompute(compute_temp) ln50 of main ## Instructions to run the code To run the code follow the instructions: 1) Create a new directory in the exercice_4 directory and go into that folder: $ mkdir build $ cd build 2) Check whether your paths are set correctly $ ccmake ../ 2) Compile the code: $ cmake ../ $ make 3) Then run as follows $ ./particles --help Usage: ./particles nsteps dump_freq input.csv particle_type timestep particle type can be: planet, ping_pong, material_point diff --git a/exercice_4/src/pypart_pybind.cc b/exercice_4/src/pypart_pybind.cc index effd784..2bf982c 100644 --- a/exercice_4/src/pypart_pybind.cc +++ b/exercice_4/src/pypart_pybind.cc @@ -1,56 +1,63 @@ #include "material_points_factory.hh" #include "particles_factory_interface.hh" #include "ping_pong_balls_factory.hh" #include "planets_factory.hh" #include "compute_temperature.hh" #include "csv_writer.hh" #include namespace py = pybind11; PYBIND11_MODULE(pypart, m) { m.doc() = "pybind for particles code"; py::class_(m, "ParticlesFactoryInterface") .def("getInstance", &ParticlesFactoryInterface::getInstance) .def("createSimulation", &ParticlesFactoryInterface::createSimulation); py::class_( m, "MaterialPointsFactory") .def("getInstance", &MaterialPointsFactory::getInstance) /*.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 ); py::class_( m, "PingPongBallsFactory") .def("getInstance", &PingPongBallsFactory::getInstance) .def("createSimulation", &PingPongBallsFactory::createSimulation); py::class_(m, "PlanetsFactory") .def("getInstance", &PlanetsFactory::getInstance) .def("createSimulation", &PlanetsFactory::createSimulation); py::class_>(m, "Compute"); py::class_ >(m, "ComputeTemperature") .def("compute", &ComputeTemperature::compute) .def_property("conductivity", &ComputeTemperature::setConductivity, &ComputeTemperature::getConductivity) .def_property("capacity", &ComputeTemperature::setCapacity, &ComputeTemperature::getCapacity) .def_property("density", &ComputeTemperature::setDensity, &ComputeTemperature::getDensity) .def_property("L", &ComputeTemperature::setL, &ComputeTemperature::getL) .def_property("delta_t", &ComputeTemperature::setDeltat, &ComputeTemperature::getDeltat); py::class_>(m, "CsvWriter") .def(py::init()) - .def("write", &CsvWriter::write) - ; + .def("write", &CsvWriter::write); + + py::class_(m, "System"); + + py::class_(m, "SystemEvolution") + .def("setNSteps", &SystemEvolution::setNSteps) + .def("setDumpFreq", &SystemEvolution::setDumpFreq) + .def("evolve", &SystemEvolution::evolve); + }