]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify the implementation of a function. 2260/head
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 28 Feb 2016 18:06:45 +0000 (12:06 -0600)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 28 Feb 2016 18:37:44 +0000 (12:37 -0600)
In particular, write an assertion with less code. Also remove some
alias variables.

source/grid/manifold.cc

index 57a8a5250fa1e51892d7989678d370a3bffb3871..0a758164b1f83bca6e96597edf53c7ec4effd718 100644 (file)
@@ -51,21 +51,14 @@ Point<spacedim>
 Manifold<dim, spacedim>::
 get_new_point (const Quadrature<spacedim> &quad) const
 {
-  const std::vector<Point<spacedim> > &surrounding_points = quad.get_points();
-  const std::vector<double> &weights = quad.get_weights();
-  Point<spacedim> p;
+  Assert(std::abs(std::accumulate(quad.get_weights().begin(), quad.get_weights().end(), 0.0)-1.0) < 1e-10,
+         ExcMessage("The weights for the individual points should sum to 1!"));
 
-#ifdef DEBUG
-  double sum=0;
-  for (unsigned int i=0; i<weights.size(); ++i)
-    sum+= weights[i];
-  Assert(std::abs(sum-1.0) < 1e-10, ExcMessage("Weights should sum to 1!"));
-#endif
-
-  for (unsigned int i=0; i<surrounding_points.size(); ++i)
-    p += surrounding_points[i]*weights[i];
+  Point<spacedim> p;
+  for (unsigned int i=0; i<quad.size(); ++i)
+    p += quad.weight(i) * quad.point(i);
 
-  return project_to_manifold(surrounding_points, p);
+  return project_to_manifold(quad.get_points(), p);
 }
 
 
@@ -219,19 +212,12 @@ Point<spacedim>
 FlatManifold<dim, spacedim>::
 get_new_point (const Quadrature<spacedim> &quad) const
 {
+  Assert(std::abs(std::accumulate(quad.get_weights().begin(), quad.get_weights().end(), 0.0)-1.0) < 1e-10,
+         ExcMessage("The weights for the individual points should sum to 1!"));
+
   const std::vector<Point<spacedim> > &surrounding_points = quad.get_points();
   const std::vector<double> &weights = quad.get_weights();
 
-#ifdef DEBUG
-  double sum=0;
-  for (unsigned int i=0; i<weights.size(); ++i)
-    sum+= weights[i];
-  // Here it is correct to use tolerance as an absolute one, since
-  // this should be relative to unity.
-  Assert(std::abs(sum-1.0) < tolerance, ExcMessage("Weights should sum to 1!"));
-#endif
-
-
   Point<spacedim> p;
   Point<spacedim> dp;
   Point<spacedim> minP = periodicity;

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.