From 174cfeb46c1d0a0369a2b538a9e0c7aef6fd1589 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Fri, 3 Aug 2012 20:33:30 +0200
Subject: [PATCH] Add descentAtZero()

---
 dune/tectonic/ellipticenergy.hh | 37 +++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/dune/tectonic/ellipticenergy.hh b/dune/tectonic/ellipticenergy.hh
index 89b403e2..39aa3f0f 100644
--- a/dune/tectonic/ellipticenergy.hh
+++ b/dune/tectonic/ellipticenergy.hh
@@ -31,27 +31,32 @@ template <int dim> class EllipticEnergy {
     return y * v + (*phi)(v); // <1/2 Av - b,v> + H(|v|)
   }
 
+  void descentAtZero(SmallVector &ret) const {
+    SmallVector const zero(0);
+    // If there is a direction of descent, this is it
+    SmallVector d;
+    smoothGradient(zero, d);
+    d *= -1;
+
+    Interval<double> D;
+    phi->directionalSubDiff(zero, d, D);
+    double const nonlinearDecline = D[1];
+    double const smoothDecline = -(d * d);
+    double const combinedDecline = smoothDecline + nonlinearDecline;
+
+    if (combinedDecline < 0) {
+      ret = d;
+    } else {
+      ret = 0;
+    }
+  }
+
   // returns false if the direction is tangential
   bool descentDirection(SmallVector const &x, SmallVector &ret) const {
     // Check the squared norm rather than each component because
     // complementaryProjection() divides by it
     if (x.two_norm2() == 0.0) {
-      // If there is a direction of descent, this is it
-      SmallVector d;
-      smoothGradient(x, d);
-      d *= -1;
-
-      Interval<double> D;
-      phi->directionalSubDiff(x, d, D);
-      double const nonlinearDecline = D[1];
-      double const smoothDecline = -(d * d);
-      double const combinedDecline = smoothDecline + nonlinearDecline;
-
-      if (combinedDecline < 0) {
-        ret = d;
-      } else {
-        ret = 0;
-      }
+      descentAtZero(ret);
       return true;
     }
 
-- 
GitLab