]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make a few functions const and remove reset_triangulation.
authorBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 13 Jun 2016 12:47:27 +0000 (08:47 -0400)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Wed, 3 Aug 2016 20:34:02 +0000 (16:34 -0400)
include/deal.II/python/point_wrapper.h
include/deal.II/python/triangulation_wrapper.h
source/python/point_wrapper.cc
source/python/triangulation_wrapper.cc

index 73c40ac938d619e7409a3fa1bdcadcac05162e14..bce81d97b7469075184c4b57614f00f4e8bf654b 100644 (file)
@@ -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.
index cfcd16daf580b04beb927dc9bece9374491d83da..2ac14b3bfcf070f29394301a0a2056cabfd662d4 100644 (file)
@@ -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;
   }
index 8459bd5ddf5fe10ddb073eaf069284d610e5425b..7a0214fb57dff4f7789f25229a5214cc13df1aea 100644 (file)
@@ -65,7 +65,7 @@ namespace PyDealII
 
 
 
-  double PointWrapper::get_x()
+  double PointWrapper::get_x() const
   {
     if (dim == 2)
       return (*static_cast<dealii::Point<2>*>(point))(0);
@@ -85,7 +85,7 @@ namespace PyDealII
 
 
 
-  double PointWrapper::get_y()
+  double PointWrapper::get_y() const
   {
     if (dim == 2)
       return (*static_cast<dealii::Point<2>*>(point))(1);
@@ -105,7 +105,7 @@ namespace PyDealII
 
 
 
-  double PointWrapper::get_z()
+  double PointWrapper::get_z() const
   {
     if (dim == 3)
       return (*static_cast<dealii::Point<3>*>(point))(2);
index 98717593b498d548ecb15392d11eae64172bbd0a..2c7c8b5696d7a6a5f434f5e22a07bca3aaf08bb3 100644 (file)
@@ -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<dealii::Triangulation<2>*>(triangulation);
+        tria->clear();
         dealii::GridGenerator::hyper_cube(*tria, left, right, colorize);
       }
     else
       {
         dealii::Triangulation<3> *tria =
           static_cast<dealii::Triangulation<3>*>(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<PointWrapper> wrapped_points(dim);
     for (int i=0; i<dim; ++i)
@@ -118,6 +116,7 @@ namespace PyDealII
 
         dealii::Triangulation<2> *tria =
           static_cast<dealii::Triangulation<2>*>(triangulation);
+        tria->clear();
         dealii::GridGenerator::simplex(*tria, points);
       }
     else
@@ -128,6 +127,7 @@ namespace PyDealII
 
         dealii::Triangulation<3> *tria =
           static_cast<dealii::Triangulation<3>*>(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<dealii::Triangulation<2>*>(triangulation);
+        tria->clear();
         dealii::GridGenerator::subdivided_hyper_cube(*tria, repetitions, left, right);
       }
     else
       {
         dealii::Triangulation<3> *tria =
           static_cast<dealii::Triangulation<3>*>(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<dim>
@@ -172,6 +168,7 @@ namespace PyDealII
 
         dealii::Triangulation<2> *tria =
           static_cast<dealii::Triangulation<2>*>(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<dealii::Triangulation<3>*>(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<unsigned int> repetitions(dim);
     for (int i=0; i<dim; ++i)
@@ -209,6 +204,7 @@ namespace PyDealII
 
         dealii::Triangulation<2> *tria =
           static_cast<dealii::Triangulation<2>*>(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<dealii::Triangulation<3>*>(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 &center,
                                                  const double  radius)
   {
-    // Create a new Triangulation
-    reset_triangulation();
-
     if (dim == 2)
       {
         // Cast the PointWrapper object to Point<dim>
@@ -240,6 +234,7 @@ namespace PyDealII
 
         dealii::Triangulation<2> *tria =
           static_cast<dealii::Triangulation<2>*>(triangulation);
+        tria->clear();
         dealii::GridGenerator::hyper_ball(*tria, center_point, radius);
       }
     else
@@ -249,6 +244,7 @@ namespace PyDealII
 
         dealii::Triangulation<3> *tria =
           static_cast<dealii::Triangulation<3>*>(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<dealii::Triangulation<2>*>(triangulation);
-        tria = new dealii::Triangulation<2>();
+        tria->clear();
         dealii::Triangulation<2> *tria_1 =
           static_cast<dealii::Triangulation<2>*>(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<dealii::Triangulation<3>*>(merged_triangulation.get_triangulation());
-        tria = new dealii::Triangulation<3>();
+          static_cast<dealii::Triangulation<3>*>(triangulation);
+        tria->clear();
         dealii::Triangulation<3> *tria_1 =
           static_cast<dealii::Triangulation<3>*>(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<dealii::Triangulation<2>*>(triangulation);
-        tria->refine_global(times);
+        tria->refine_global(n);
       }
     else
       {
         dealii::Triangulation<3> *tria =
           static_cast<dealii::Triangulation<3>*>(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<dealii::Triangulation<2>*>(triangulation);
-            delete tmp;
-          }
-        triangulation = new dealii::Triangulation<2>();
-      }
-    else
-      {
-        if (triangulation != nullptr)
-          {
-            dealii::Triangulation<3> *tmp = static_cast<dealii::Triangulation<3>*>(triangulation);
-            delete tmp;
-          }
-        triangulation = new dealii::Triangulation<3> ();
+        tria->refine_global(n);
       }
   }
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.