]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify some manifold code. 2399/head
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 23 Mar 2016 22:13:08 +0000 (17:13 -0500)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 24 Mar 2016 14:56:17 +0000 (09:56 -0500)
The previous code precomputed a global flag whether the manifold
is periodic or not, but ultimately had to check each coordinate
direction manually anyway. So do away with the global flag, and
simplify the code structure somewhat.

source/grid/manifold.cc

index 80f4aa997059e492cf69218de15386e786eb7e13..9f18fe8d81f0fd78bf4b8f54a7f4b52740dab1bd 100644 (file)
@@ -246,37 +246,36 @@ 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;
-  Point<spacedim> dp;
   Point<spacedim> minP = periodicity;
-  const bool check_period = (periodicity.norm() > tolerance);
-  if (check_period)
-    for (unsigned int i=0; i<surrounding_points.size(); ++i)
-      for (unsigned int d=0; d<spacedim; ++d)
+
+  for (unsigned int d=0; d<spacedim; ++d)
+    if (periodicity[d] > 0)
+      for (unsigned int i=0; i<surrounding_points.size(); ++i)
         {
           minP[d] = std::min(minP[d], surrounding_points[i][d]);
-          if (periodicity[d] > 0)
-            Assert( (surrounding_points[i][d] < periodicity[d]+tolerance*periodicity.norm()) ||
-                    (surrounding_points[i][d] >= -tolerance*periodicity.norm()),
-                    ExcPeriodicBox(d, surrounding_points[i], periodicity, tolerance*periodicity.norm()));
+          Assert( (surrounding_points[i][d] < periodicity[d]+tolerance*periodicity.norm()) ||
+                  (surrounding_points[i][d] >= -tolerance*periodicity.norm()),
+                  ExcPeriodicBox(d, surrounding_points[i], periodicity, tolerance*periodicity.norm()));
         }
 
+  // compute the weighted average point, possibly taking into account periodicity
+  Point<spacedim> p;
   for (unsigned int i=0; i<surrounding_points.size(); ++i)
     {
-      dp = Point<spacedim>();
-      if (check_period)
-        {
-          for (unsigned int d=0; d<spacedim; ++d)
-            if (periodicity[d] > 0)
-              dp[d] = ( (surrounding_points[i][d]-minP[d]) > periodicity[d]/2.0 ?
-                        -periodicity[d] : 0.0 );
-        }
+      Point<spacedim> dp;
+      for (unsigned int d=0; d<spacedim; ++d)
+        if (periodicity[d] > 0)
+          dp[d] = ( (surrounding_points[i][d]-minP[d]) > periodicity[d]/2.0 ?
+                    -periodicity[d] : 0.0 );
+
       p += (surrounding_points[i]+dp)*weights[i];
     }
-  if (check_period)
-    for (unsigned int d=0; d<spacedim; ++d)
-      if (periodicity[d] > 0)
-        p[d] = (p[d] < 0 ? p[d] + periodicity[d] : p[d]);
+
+  // if necessary, also adjust the weighted point by the periodicity
+  for (unsigned int d=0; d<spacedim; ++d)
+    if (periodicity[d] > 0)
+      if (p[d] < 0)
+        p[d] += periodicity[d];
 
   return project_to_manifold(surrounding_points, 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.