]> https://gitweb.dealii.org/ - dealii.git/commitdiff
In n_active_cells(), use the cached values.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 23 Nov 2009 04:45:01 +0000 (04:45 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 23 Nov 2009 04:45:01 +0000 (04:45 +0000)
git-svn-id: https://svn.dealii.org/trunk@20150 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/source/grid/tria.cc
deal.II/doc/news/changes.h

index 5380ba9dc0d3c88c09d5f6990a7390f08de1b770..d2dc8a9ffb7adbfafd12579d67230f97a4b7fef1 100644 (file)
@@ -11452,23 +11452,67 @@ Triangulation<dim, spacedim>::last_active_hex () const
 
 // -------------------------------- number of cells etc ---------------
 
+
+namespace internal
+{
+  namespace Triangulation
+  {
+    unsigned int
+    n_cells (const internal::Triangulation::NumberCache<1> &c)
+    {
+      return c.n_lines;
+    }
+
+
+    unsigned int
+    n_active_cells (const internal::Triangulation::NumberCache<1> &c)
+    {
+      return c.n_active_lines;
+    }
+
+
+    unsigned int
+    n_cells (const internal::Triangulation::NumberCache<2> &c)
+    {
+      return c.n_quads;
+    }
+
+
+    unsigned int
+    n_active_cells (const internal::Triangulation::NumberCache<2> &c)
+    {
+      return c.n_active_quads;
+    }
+
+
+    unsigned int
+    n_cells (const internal::Triangulation::NumberCache<3> &c)
+    {
+      return c.n_hexes;
+    }
+
+
+    unsigned int
+    n_active_cells (const internal::Triangulation::NumberCache<3> &c)
+    {
+      return c.n_active_hexes;
+    }
+  }
+}
+
+
+
 template <int dim, int spacedim>
 unsigned int Triangulation<dim, spacedim>::n_cells () const
 {
-  unsigned int n=0;
-  for (unsigned int l=0; l<n_levels(); ++l)
-    n += n_cells (l);
-  return n;
+  return internal::Triangulation::n_cells (number_cache);
 }
 
 
 template <int dim, int spacedim>
 unsigned int Triangulation<dim, spacedim>::n_active_cells () const
 {
-  unsigned int n=0;
-  for (unsigned int l=0; l<n_levels(); ++l)
-    n += n_active_cells (l);
-  return n;
+  return internal::Triangulation::n_active_cells (number_cache);
 }
 
 
index 8cb12751a21bf7df884b414c5a72aa0ba0003bec..3e7848ee826e18474bc763b2158326810bb32dde 100644 (file)
@@ -518,7 +518,7 @@ inconvenience this causes.
   in the past. Since Triangulation::n_active_cells() calls Triangulation::n_levels()
   repeatedly, by consequence it also is surprisingly expensive, which is
   particularly annoying since this is a frequently called function. This has
-  now been fixed by caching the result of this function.
+  now been fixed by caching the result of both functions.
   <br>
   (Wolfgang Bangerth 2009/11/22)
   </p>

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.