]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Set the tolerances for the Newton iteration at run time in a way that they are not...
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 6 Mar 2009 22:34:06 +0000 (22:34 +0000)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 6 Mar 2009 22:34:06 +0000 (22:34 +0000)
git-svn-id: https://svn.dealii.org/trunk@18462 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/quadrature_lib.cc

index dbd291c40ea90c6a3c95be64e8f0f7ca64f9ad95..d05d70bc67a7f3497f69d5f7609a812e5c5ea864 100644 (file)
@@ -117,18 +117,26 @@ QGauss<1>::QGauss (const unsigned int n)
     double_eps      = 2.23-16;
 #endif
 
-                                  // now check whether long double is
-                                  // more accurate than double, and
-                                  // set tolerances accordingly
+                                  // now check whether long double is more
+                                  // accurate than double, and set
+                                  // tolerances accordingly. generate a one
+                                  // that really is generated at run-time
+                                  // and is not optimized away by the
+                                  // compiler. that makes sure that the
+                                  // tolerance is set at run-time with the
+                                  // current behavior, not at compile-time
+                                  // (not doing so leads to trouble with
+                                  // valgrind for example).
+  volatile long double runtime_one = 1.0;
   const long double tolerance
-    = (static_cast<long double>(1.0) + long_double_eps != static_cast<long double>(1.0)
+    = (runtime_one + long_double_eps != runtime_one
        ?
        std::max (double_eps / 100, long_double_eps * 5)
        :
        double_eps * 5
        );
 
-  
+
   for (unsigned int i=1; i<=m; ++i)
     {
       long double z = std::cos(numbers::PI * (i-.25)/(n+.5));
@@ -212,8 +220,9 @@ compute_quadrature_points(const unsigned int q,
                                   // check whether long double is
                                   // more accurate than double, and
                                   // set tolerances accordingly
-  const long double epsilon
-    = (static_cast<long double>(1.0) + long_double_eps != static_cast<long double>(1.0)
+  volatile long double runtime_one = 1.0;
+  const long double tolerance
+    = (runtime_one + long_double_eps != runtime_one
        ?
        std::max (double_eps / 100, long_double_eps * 5)
        :
@@ -244,7 +253,7 @@ compute_quadrature_points(const unsigned int q,
          delta = f/(f*s- J_x);
          r += delta;
        }
-      while (std::fabs(delta) >= epsilon);
+      while (std::fabs(delta) >= tolerance);
       
       x[k] = r;
     } // for

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.