From: Bruno Turcksin Date: Fri, 27 May 2016 18:32:41 +0000 (-0400) Subject: Improve documentation in python and add save/load functions. X-Git-Tag: v8.5.0-rc1~809^2~23 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2683c367db097905c0eb53f4fa9c5a58c4cc7a3a;p=dealii.git Improve documentation in python and add save/load functions. --- diff --git a/source/python/wrappers.cc b/source/python/wrappers.cc index 271a03096c..ed78375979 100644 --- a/source/python/wrappers.cc +++ b/source/python/wrappers.cc @@ -13,9 +13,12 @@ // // --------------------------------------------------------------------- +#include +#include #include #include #include +#include char const *pydealii_docstring = " \n" @@ -34,6 +37,22 @@ void generate_cube(dealii::Triangulation<2> &triangulation) dealii::GridGenerator::hyper_cube(triangulation); } +void save(const dealii::Triangulation<2> &triangulation, + const std::string filename) +{ + std::ofstream ofs(filename); + boost::archive::text_oarchive oa(ofs); + oa << triangulation; +} + +void load(dealii::Triangulation<2> &triangulation, + const std::string filename) +{ + std::ifstream ifs(filename); + boost::archive::text_iarchive ia(ifs); + ia >> triangulation; +} + BOOST_PYTHON_MODULE(PyDealII) { boost::python::scope().attr("__doc__") = pydealii_docstring; @@ -45,7 +64,16 @@ BOOST_PYTHON_MODULE(PyDealII) boost::python::class_> ("Triangulation") - .def("n_active_cells", &n_active_cells) - .def("generate_cube", &generate_cube) - .def("refine_global", &dealii::Triangulation<2>::refine_global); + .def("n_active_cells", &n_active_cells, + "Return the number of active cells", + boost::python::args("self")) + .def("generate_cube", &generate_cube, + "Generate a hypercube", boost::python::args("self")) + .def("refine_global", &dealii::Triangulation<2>::refine_global, + "Refine the mesh uniformly", + boost::python::args("self", "times")) + .def("save", &save, "Serialize and save the triangulation", + boost::python::args("self", "filename")) + .def("load", &load, "Load and deserialize a triangulation", + boost::python::args("self", "filename")); }