From b66bbf9914dc9346b8cbcc3989ee0b5907a9799d Mon Sep 17 00:00:00 2001 From: Bruno Turcksin Date: Mon, 13 Jun 2016 08:47:27 -0400 Subject: [PATCH] Make a few functions const and remove reset_triangulation. --- include/deal.II/python/point_wrapper.h | 6 +- .../deal.II/python/triangulation_wrapper.h | 17 ++-- source/python/point_wrapper.cc | 6 +- source/python/triangulation_wrapper.cc | 78 ++++++------------- 4 files changed, 34 insertions(+), 73 deletions(-) diff --git a/include/deal.II/python/point_wrapper.h b/include/deal.II/python/point_wrapper.h index 73c40ac938..bce81d97b7 100644 --- a/include/deal.II/python/point_wrapper.h +++ b/include/deal.II/python/point_wrapper.h @@ -41,7 +41,7 @@ namespace PyDealII /** * Return the first component of the Point. */ - double get_x(); + double get_x() const; /** * Set the first component of the Point. @@ -51,7 +51,7 @@ namespace PyDealII /** * Return the second component of the Point. */ - double get_y(); + double get_y() const; /** * Set the second component of the Point. @@ -61,7 +61,7 @@ namespace PyDealII /** * Return the third component of the Point. */ - double get_z(); + double get_z() const; /** * Set the third component of the Point. diff --git a/include/deal.II/python/triangulation_wrapper.h b/include/deal.II/python/triangulation_wrapper.h index cfcd16daf5..2ac14b3bfc 100644 --- a/include/deal.II/python/triangulation_wrapper.h +++ b/include/deal.II/python/triangulation_wrapper.h @@ -39,7 +39,7 @@ namespace PyDealII /** * Return the number of active cells. */ - unsigned int n_active_cells(); + unsigned int n_active_cells() const; /** * Generate a hyper cube (square in 2D and cube in 3D) with exactly one @@ -100,14 +100,14 @@ namespace PyDealII TriangulationWrapper &triangulation_2); /** - * Refine all the cells @p times times. + * Refine all the cells @p n times. */ - void refine_global(const unsigned int times); + void refine_global(const unsigned int n); /** * Write the Triangulation in file. */ - void save(const std::string &filename); + void save(const std::string &filename) const; /** * Load the Triangulation from a file. @@ -117,7 +117,7 @@ namespace PyDealII /** * Return the dimension of the underlying Triangulation object. */ - int get_dim(); + int get_dim() const; /** * Return a pointer that can be casted to the underlying Triangulation @@ -126,11 +126,6 @@ namespace PyDealII void *get_triangulation(); private: - /** - * Reset the underlying Triangulation object. - */ - void reset_triangulation(); - /** * Dimension of the underlying Triangulation object. */ @@ -148,7 +143,7 @@ namespace PyDealII inline - int TriangulationWrapper::get_dim() + int TriangulationWrapper::get_dim() const { return dim; } diff --git a/source/python/point_wrapper.cc b/source/python/point_wrapper.cc index 8459bd5ddf..7a0214fb57 100644 --- a/source/python/point_wrapper.cc +++ b/source/python/point_wrapper.cc @@ -65,7 +65,7 @@ namespace PyDealII - double PointWrapper::get_x() + double PointWrapper::get_x() const { if (dim == 2) return (*static_cast*>(point))(0); @@ -85,7 +85,7 @@ namespace PyDealII - double PointWrapper::get_y() + double PointWrapper::get_y() const { if (dim == 2) return (*static_cast*>(point))(1); @@ -105,7 +105,7 @@ namespace PyDealII - double PointWrapper::get_z() + double PointWrapper::get_z() const { if (dim == 3) return (*static_cast*>(point))(2); diff --git a/source/python/triangulation_wrapper.cc b/source/python/triangulation_wrapper.cc index 98717593b4..2c7c8b5696 100644 --- a/source/python/triangulation_wrapper.cc +++ b/source/python/triangulation_wrapper.cc @@ -30,10 +30,12 @@ namespace PyDealII if ((dimension.compare("2D")==0) || (dimension.compare("2d")==0)) { dim = 2; + triangulation = new dealii::Triangulation<2>(); } else if ((dimension.compare("3D")==0) || (dimension.compare("3d")==0)) { dim = 3; + triangulation = new dealii::Triangulation<3>(); } else AssertThrow(false, dealii::ExcMessage("Dimension needs to be 2D or 3D")); @@ -64,7 +66,7 @@ namespace PyDealII - unsigned int TriangulationWrapper::n_active_cells() + unsigned int TriangulationWrapper::n_active_cells() const { if (dim == 2) { @@ -80,19 +82,18 @@ namespace PyDealII const double right, const bool colorize) { - // Create a new Triangulation - reset_triangulation(); - if (dim == 2) { dealii::Triangulation<2> *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::hyper_cube(*tria, left, right, colorize); } else { dealii::Triangulation<3> *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::hyper_cube(*tria, left, right, colorize); } } @@ -101,9 +102,6 @@ namespace PyDealII void TriangulationWrapper::generate_simplex(boost::python::list &vertices) { - // Create a new Triangulation - reset_triangulation(); - // Extract the PointWrapper object from the python list std::vector wrapped_points(dim); for (int i=0; i *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::simplex(*tria, points); } else @@ -128,6 +127,7 @@ namespace PyDealII dealii::Triangulation<3> *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::simplex(*tria, points); } } @@ -138,19 +138,18 @@ namespace PyDealII const double left, const double right) { - // Create a new Triangulation - reset_triangulation(); - if (dim == 2) { dealii::Triangulation<2> *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::subdivided_hyper_cube(*tria, repetitions, left, right); } else { dealii::Triangulation<3> *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::subdivided_hyper_cube(*tria, repetitions, left, right); } } @@ -161,9 +160,6 @@ namespace PyDealII PointWrapper &p2, const bool colorize) { - // Create a new Triangulation - reset_triangulation(); - if (dim == 2) { // Cast the PointWrapper object to Point @@ -172,6 +168,7 @@ namespace PyDealII dealii::Triangulation<2> *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::hyper_rectangle(*tria, point_1, point_2, colorize); } else @@ -181,6 +178,7 @@ namespace PyDealII dealii::Triangulation<3> *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::hyper_rectangle(*tria, point_1, point_2, colorize); } @@ -193,9 +191,6 @@ namespace PyDealII PointWrapper &p2, const bool colorize) { - // Create a new Triangulation - reset_triangulation(); - // Extract the repetitions from the python list std::vector repetitions(dim); for (int i=0; i *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::subdivided_hyper_rectangle(*tria, repetitions, point_1, point_2, colorize); } @@ -219,6 +215,7 @@ namespace PyDealII dealii::Triangulation<3> *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::subdivided_hyper_rectangle(*tria, repetitions, point_1, point_2, colorize); } @@ -229,9 +226,6 @@ namespace PyDealII void TriangulationWrapper::generate_hyper_ball(PointWrapper ¢er, const double radius) { - // Create a new Triangulation - reset_triangulation(); - if (dim == 2) { // Cast the PointWrapper object to Point @@ -240,6 +234,7 @@ namespace PyDealII dealii::Triangulation<2> *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::hyper_ball(*tria, center_point, radius); } else @@ -249,6 +244,7 @@ namespace PyDealII dealii::Triangulation<3> *tria = static_cast*>(triangulation); + tria->clear(); dealii::GridGenerator::hyper_ball(*tria, center_point, radius); } } @@ -288,14 +284,11 @@ namespace PyDealII AssertThrow(triangulation_1.get_dim() == triangulation_2.get_dim(), dealii::ExcMessage("Triangulation_1 and Triangulation_2 should have the same dimension.")); - // Create a new Triangulation - reset_triangulation(); - if (triangulation_1.get_dim() == 2) { dealii::Triangulation<2> *tria = static_cast*>(triangulation); - tria = new dealii::Triangulation<2>(); + tria->clear(); dealii::Triangulation<2> *tria_1 = static_cast*>(triangulation_1.get_triangulation()); dealii::Triangulation<2> *tria_2 = @@ -307,10 +300,9 @@ namespace PyDealII } else { - TriangulationWrapper merged_triangulation("3D"); dealii::Triangulation<3> *tria = - static_cast*>(merged_triangulation.get_triangulation()); - tria = new dealii::Triangulation<3>(); + static_cast*>(triangulation); + tria->clear(); dealii::Triangulation<3> *tria_1 = static_cast*>(triangulation_1.get_triangulation()); dealii::Triangulation<3> *tria_2 = @@ -322,7 +314,7 @@ namespace PyDealII - void TriangulationWrapper::save(const std::string &filename) + void TriangulationWrapper::save(const std::string &filename) const { std::ofstream ofs(filename); boost::archive::text_oarchive oa(ofs); @@ -368,45 +360,19 @@ namespace PyDealII - void TriangulationWrapper::refine_global(const unsigned int times) + void TriangulationWrapper::refine_global(const unsigned int n) { if (dim == 2) { dealii::Triangulation<2> *tria = static_cast*>(triangulation); - tria->refine_global(times); + tria->refine_global(n); } else { dealii::Triangulation<3> *tria = static_cast*>(triangulation); - tria->refine_global(times); - } - } - - - - void TriangulationWrapper::reset_triangulation() - { - if (dim == 2) - { - if (triangulation != nullptr) - { - // We cannot call delete on a void pointer so cast the void pointer back - // first. - dealii::Triangulation<2> *tmp = static_cast*>(triangulation); - delete tmp; - } - triangulation = new dealii::Triangulation<2>(); - } - else - { - if (triangulation != nullptr) - { - dealii::Triangulation<3> *tmp = static_cast*>(triangulation); - delete tmp; - } - triangulation = new dealii::Triangulation<3> (); + tria->refine_global(n); } } } -- 2.39.5