diff --git a/Homework4/src/compute_gravity.hh b/Homework4/src/compute_gravity.hh index 2c308df..77071bd 100644 --- a/Homework4/src/compute_gravity.hh +++ b/Homework4/src/compute_gravity.hh @@ -1,28 +1,27 @@ #ifndef __COMPUTE_GRAVITY__HH__ #define __COMPUTE_GRAVITY__HH__ /* -------------------------------------------------------------------------- */ #include "compute_interaction.hh" //! Compute Newton gravity interaction class ComputeGravity : public ComputeInteraction { // Virtual implementation public: //! Newton gravity implementation void compute(System& system) override; // Accessors public: //! set the gravitational constant void setG(Real G); // Members private: //! newton constant - //Real G = 1.; - Real G = 6.67384e-11*5.97219e24*std::pow(60.0*60.0*24.0,2)/std::pow(149597870.7*1000.0,3); + Real G = 1.; }; /* -------------------------------------------------------------------------- */ #endif //__COMPUTE_GRAVITY__HH__ diff --git a/Homework4/src/pypart.cc b/Homework4/src/pypart.cc index c972770..678227f 100644 --- a/Homework4/src/pypart.cc +++ b/Homework4/src/pypart.cc @@ -1,163 +1,144 @@ #include #include #include #include #include "my_types.hh" #include "fft.hh" #include "system_evolution.hh" #include "particles_factory_interface.hh" #include "material_points_factory.hh" #include "planets_factory.hh" #include "ping_pong_balls_factory.hh" #include "csv_writer.hh" #include "compute.hh" #include "compute_temperature.hh" #include "compute_interaction.hh" #include "compute_gravity.hh" #include "compute_verlet_integration.hh" namespace py = pybind11; PYBIND11_MODULE(pypart, m) { m.doc() = "Python binding for the particles code."; - + // ========== Class System ================================================================== py::class_(m, "System"); - - - + + + // ========== Class SystemEvolution ========================================================= py::class_>(m, "SystemEvolution", py::dynamic_attr()) .def(py::init([](std::unique_ptr()){return std::unique_ptr();}), py::return_value_policy::move) .def("evolve", &SystemEvolution::evolve) .def("addCompute", &SystemEvolution::addCompute) .def("getSystem", &SystemEvolution::getSystem, py::return_value_policy::reference) .def("setNSteps", &SystemEvolution::setNSteps) .def("setDumpFreq", &SystemEvolution::setDumpFreq); - - - + + + // ========== Class ParticlesFactoryInterface =============================================== py::class_(m, "ParticlesFactoryInterface", py::dynamic_attr()) - .def_static("getInstance", &ParticlesFactoryInterface::getInstance, + .def("getInstance", &ParticlesFactoryInterface::getInstance, py::return_value_policy::reference) - .def("getSystemEvolution", &ParticlesFactoryInterface::getSystemEvolution, - py::return_value_policy::reference) .def_property_readonly("system_evolution", - &ParticlesFactoryInterface::getSystemEvolution); - - - + &ParticlesFactoryInterface::getSystemEvolution); + + + // ========== Class MaterialPointsFactory =================================================== py::class_(m, "MaterialPointsFactory", py::dynamic_attr()) - .def_static("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", - (SystemEvolution& (MaterialPointsFactory::*)(const std::string &,Real,py::object)) - &MaterialPointsFactory::createSimulation, - py::return_value_policy::reference); - - - + .def("createSimulation", py::overload_cast + (&ParticlesFactoryInterface::createSimulation), py::return_value_policy::reference) + .def("getInstance", &MaterialPointsFactory::getInstance, + py::return_value_policy::reference); + + + // ========== Class PlanetsFactory ========================================================== py::class_(m, "PlanetsFactory", py::dynamic_attr()) - .def_static("getInstance", &PlanetsFactory::getInstance, - py::return_value_policy::reference) - .def("createSimulation", - (SystemEvolution& (PlanetsFactory::*)(const std::string &,Real)) - &PlanetsFactory::createSimulation, - py::return_value_policy::reference) - .def("createSimulation", - (SystemEvolution& (PlanetsFactory::*)(const std::string &,Real,py::object)) - &PlanetsFactory::createSimulation, - 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); + + // ========== Class PingPongBallsFactory ==================================================== py::class_(m, "PingPongBallsFactory", py::dynamic_attr()) - .def_static("getInstance", &PingPongBallsFactory::getInstance, - py::return_value_policy::reference) - .def("createSimulation", (SystemEvolution& (PingPongBallsFactory::*)(const std::string &, - Real)) - &PingPongBallsFactory::createSimulation, - py::return_value_policy::reference) - .def("createSimulation",(SystemEvolution& (PingPongBallsFactory::*)(const std::string &, - Real, py::object)) - &PingPongBallsFactory::createSimulation, - 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); + + + + + // ========== Class Compute ================================================================= py::class_>(m, "Compute"); class Pycompute : public Compute{ public: using Compute::Compute; void compute(System &system) override{ PYBIND11_OVERLOAD_PURE(void, Compute, compute, system); } }; - - - + + + // ========== Class ComputeTemperature ====================================================== py::class_>(m, "ComputeTemperature", py::dynamic_attr()) .def(py::init<>()) .def("compute", &ComputeTemperature::compute, py::return_value_policy::reference) .def_property_readonly("conductivity", &ComputeTemperature::getConductivity) .def_property_readonly("capacity", &ComputeTemperature::getCapacity) .def_property_readonly("density", &ComputeTemperature::getDensity) .def_property_readonly("L", &ComputeTemperature::getL) .def_property_readonly("deltat", &ComputeTemperature::getDeltat); - - - + + + // ========== Class ComputeInteraction ====================================================== py::class_>(m, "ComputeInteraction", py::dynamic_attr()); - - - + + + // ========== Class ComputeGravity ========================================================== py::class_>(m, "ComputeGravity", py::dynamic_attr()) .def(py::init<>()) .def("compute", &ComputeGravity::compute, py::return_value_policy::reference) .def("setG", &ComputeGravity::setG); - - + + // ========== Class ComputeVerletIntegration ================================================ py::class_>(m, "ComputeVerletIntegration", py::dynamic_attr()) .def(py::init()) .def("compute", &ComputeVerletIntegration::compute, py::return_value_policy::reference) .def("addInteraction", &ComputeVerletIntegration::addInteraction) .def("setDeltaT", &ComputeVerletIntegration::setDeltaT); - - + + // ========== Class CsvWriter =============================================================== py::class_>(m,"CsvWriter") .def(py::init()) .def("write", &CsvWriter::write); }