]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Pass by const reference. Different sort approach.
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Thu, 18 Aug 2016 21:46:19 +0000 (15:46 -0600)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Fri, 19 Aug 2016 00:44:12 +0000 (18:44 -0600)
include/deal.II/base/quadrature_lib.h
source/base/quadrature_lib.cc

index 3e291b77f423a92571963a9d60a507ed00249d4f..e3e530ba635db34be22a98c6cecc7ac8d0e3ade9 100644 (file)
@@ -438,13 +438,13 @@ public:
   /**
    * The constructor takes an arbitrary quadrature formula.
    */
-  QSorted (const Quadrature<dim>);
+  QSorted (const Quadrature<dim> &quad);
 
   /**
    * A rule to reorder pairs of points and weights.
    */
-  bool operator()(const std::pair<double, Point<dim> > &a,
-                  const std::pair<double, Point<dim> > &b);
+  bool operator()(const std::size_t &a,
+                  const std::size_t &b) const;
 };
 
 /**
index dd16fb4c72de0c96ab6f6039fe783d1eec62d11e..e9c961c1b20daa6fe724eb66b9fff2c23e8314d0 100644 (file)
@@ -932,27 +932,26 @@ QGaussOneOverR<2>::QGaussOneOverR(const unsigned int n,
 
 
 template <int dim>
-QSorted<dim>::QSorted(Quadrature<dim> quad) :
-  Quadrature<dim>(quad.size())
+QSorted<dim>::QSorted(const Quadrature<dim> &quad) :
+  Quadrature<dim>(quad)
 {
-  std::vector< std::pair<double, Point<dim> > > wp;
-  for (unsigned int i=0; i<quad.size(); ++i)
-    wp.push_back(std::pair<double, Point<dim> >(quad.weight(i),
-                                                quad.point(i)));
-  sort(wp.begin(), wp.end(), *this);
+  std::vector<std::size_t> permutation(quad.size());
+  std::iota(permutation.begin(), permutation.end(), 0);
+  std::sort(permutation.begin(), permutation.end(), *this);
+
   for (unsigned int i=0; i<quad.size(); ++i)
     {
-      this->weights[i] = wp[i].first;
-      this->quadrature_points[i] = wp[i].second;
+      this->weights[i]           = quad.weight(permutation[i]);
+      this->quadrature_points[i] = quad.point(permutation[i]);
     }
 }
 
 
 template <int dim>
-bool QSorted<dim>::operator()(const std::pair<double, Point<dim> > &a,
-                              const std::pair<double, Point<dim> > &b)
+bool QSorted<dim>::operator()(const std::size_t &a,
+                              const std::size_t &b) const
 {
-  return (a.first < b.first);
+  return (this->weights[a] < this->weights[b]);
 }
 
 

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.