diff --git a/HW4/compute_temperature.hh b/HW4/compute_temperature.hh index 1e185ba..dbc213f 100644 --- a/HW4/compute_temperature.hh +++ b/HW4/compute_temperature.hh @@ -1,38 +1,57 @@ #ifndef __COMPUTE_TEMPERATURE__HH__ #define __COMPUTE_TEMPERATURE__HH__ /* -------------------------------------------------------------------------- */ #include "compute.hh" //! Compute contact interaction between ping-pong balls class ComputeTemperature : public Compute { - + public: + + /// Define getter and setter (read/write) the private constants + //! temperature evolution implementation void compute(System& system) override; //! return the heat conductivity Real & getConductivity(){return conductivity;}; + //! set the heat conductivity + void setConductivity(Real Conductivity_var){conductivity = Conductivity_var;}; + //! return the heat capacity Real & getCapacity(){return capacity;}; - //! return the heat capacity + //! set the heat capacity + void setCapacity(Real capacity_var){capacity = capacity_var;}; + + //! return the density Real & getDensity(){return density;}; + //! set the density + void setDensity(Real density_var){density = density_var;}; + //! return the characteristic length of the square Real & getL(){return L;}; - //! return the characteristic length of the square + //! set the characteristic length of the square + void setL(Real L_var){L = L_var;}; + + //! return delta Real & getDeltat(){return delta_t;}; + //! set delta + void setDeltat(Real delta_t_var){delta_t = delta_t_var;}; bool implicit = true; + + private: - + Real conductivity; Real capacity; Real density; //! side length of the problem Real L; Real delta_t; }; /* -------------------------------------------------------------------------- */ #endif //__COMPUTE_TEMPERATURE__HH__ diff --git a/HW4/py_wrap.cc b/HW4/py_wrap.cc index 2e16d20..f34ce3f 100644 --- a/HW4/py_wrap.cc +++ b/HW4/py_wrap.cc @@ -1,111 +1,140 @@ #include +#include #include + #include "material_points_factory.hh" #include "ping_pong_balls_factory.hh" #include "particles_factory_interface.hh" #include "planets_factory.hh" #include "compute_temperature.hh" #include "csv_writer.hh" #include "system.hh" +#include "my_types.hh" // All the classes which are to be used in python are included here, together with the needed external library. // instead of just including this header at the end of each file! namespace py = pybind11; //Start of the py_wrap.cc module: PYBIND11_MODULE(pypart,m){ // Generate Documentation m.doc()="This file is to wrap the C++ library over a Python API for the particles project."; // Wrapping ParticlesFactoryInterface with Reference Return (C++ will handle the Garbage Collection) py::class_(m, "ParticlesFactoryInterface") .def("getInstance", &ParticlesFactoryInterface::getInstance, py::return_value_policy::reference) - ; + + .def("createSimulation", + &ParticlesFactoryInterface::createSimulation) + + ; // Wrapping the PingPongBallsFactory (Reference Return) py::class_(m, "PingPongBallsFactory") .def("getInstance", &PingPongBallsFactory::getInstance, py::return_value_policy::reference) .def("createSimulation", &PingPongBallsFactory::createSimulation, py::return_value_policy::reference) + ; // Wrapping the PlanetsFactory interface (Reference Return) py::class_(m, "PlanetsFactory") .def("getInstance", &PlanetsFactory::getInstance, py::return_value_policy::reference) .def("createSimulation", - &PlanetsFactory::createSimulation, - py::return_value_policy::reference) + &PlanetsFactory::createSimulation) + ; // Wrapping the MaterialPointsFactory (Reference Return) 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)*/ + + .def_property_readonly("system_evolution", + &MaterialPointsFactory::getSystemEvolution); + ; // 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. // Wrapping SystemEvoution class py::class_(m, "SystemEvolution") .def("setNSteps", &SystemEvolution::setNSteps) .def("setDumpFreq", &SystemEvolution::setDumpFreq) .def("evolve", &SystemEvolution::evolve) + .def("addCompute", &SystemEvolution::addCompute) + .def("getSystem", &SystemEvolution::getSystem, py::return_value_policy::reference) + ; // Wrapping the system writer (CSV files) py::class_(m, "CsvWriter") .def(py::init()) .def("write", &CsvWriter::write) + ; py::class_(m, "System"); // Wrapping ComputeTemperature class // To read protected classes variables in Python, it is necessary to use "getsmt" methods, instead of reading them directly. - py::class_(m, "ComputeTemperature") + py::class_>(m, "ComputeTemperature") -// .def("compute", &ComputeTemperature::compute) - ; // delete this semicolon for debugging only -/* - .def_property("deltat", &ComputeTemperature::getDeltat) + // Define Getters first and then Setters ! + + .def(py::init()) + + .def("compute", &ComputeTemperature::compute) + + .def_property("deltat", + &ComputeTemperature::getDeltat, + &ComputeTemperature::setDeltat) + + .def_property("density", + &ComputeTemperature::getDensity, + &ComputeTemperature::setDensity) - .def_property("density", &ComputeTemperature::getDensity) + .def_property("L", + &ComputeTemperature::getL, + &ComputeTemperature::setL) - .def_property("L", &ComputeTemperature::getL) + .def_property("capacity", + &ComputeTemperature::getCapacity, + &ComputeTemperature::setCapacity) - .def_property("capacity", &ComputeTemperature::getCapacity) + .def_property("conductivity", + &ComputeTemperature::getConductivity, + &ComputeTemperature::setConductivity) - .def_property("conductivity", &ComputeTemperature::getConductivity) ; - */ }