From cc564534f658abe8d4f2e4d36451baeb443e3fec Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Sat, 28 Jul 2012 13:02:45 +0200
Subject: [PATCH] Fix up CurvedFunction

---
 dune/tectonic/curvedfunction.hh       | 26 +++++++++++++-------------
 src/test-gradient-sample-steep.cc     |  8 ++++----
 src/test-gradient-sample-steep2.cc    |  8 ++++----
 src/test-gradient-sample-verysteep.cc |  8 ++++----
 4 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/dune/tectonic/curvedfunction.hh b/dune/tectonic/curvedfunction.hh
index 4c8a0350..5d8ed728 100644
--- a/dune/tectonic/curvedfunction.hh
+++ b/dune/tectonic/curvedfunction.hh
@@ -1,6 +1,7 @@
 #ifndef CURVED_FUNCTION_HH
 #define CURVED_FUNCTION_HH
 
+#include <cmath>
 #include <dune/fufem/interval.hh>
 
 namespace Dune {
@@ -35,16 +36,14 @@ template <class NonlinearityType> class CurvedFunction {
   }
 
   void domain(Interval<double> &domain) const {
-    // TODO
-    domain[0] = 0;
-    domain[1] = 1;
+    domain[0] = -M_PI;
+    domain[1] = M_PI;
   }
 
   void cartesian(double m, VectorType &y) const {
     y = 0;
-    y.axpy(1 - m, x);
-    y.axpy(m, dir);
-    y /= y.two_norm();
+    y.axpy(std::cos(m), x);
+    y.axpy(std::sin(m), dir);
   }
 
 private:
@@ -54,17 +53,18 @@ template <class NonlinearityType> class CurvedFunction {
   VectorType const &x;
   VectorType const &dir;
 
-  /*
-    Tangential vector within the plane, with positive direction.
+  /* If x and d were normalised, we would have
 
-    < (1-m)x + m*y,-m*|y|^2*x+(1-m)*|x|^2*y>
-    = -m(1-m)|y|^2<x,x> + m(1-m)|x|^2<y,y> (because <x,y> = 0)
-    = 0
+       cartesian(a) =  cos(a) * x + sin(a) * d and
+       tangent(a)   = -sin(a) * x + cos(a) * d.
+
+     Since we x and d are not normalised and the return of
+     cartesian() is fixed, we scale the tangent.
   */
   void tangentialDirection(double m, VectorType &y) const {
     y = 0;
-    y.axpy(-m * dir.two_norm2(), x);
-    y.axpy((1 - m) * x.two_norm2(), dir);
+    y.axpy(-std::sin(m) * dir.two_norm2(), x);
+    y.axpy(std::cos(m) * x.two_norm2(), dir);
   }
 };
 }
diff --git a/src/test-gradient-sample-steep.cc b/src/test-gradient-sample-steep.cc
index dfe498f2..1f07afd8 100644
--- a/src/test-gradient-sample-steep.cc
+++ b/src/test-gradient-sample-steep.cc
@@ -35,18 +35,18 @@ int main() {
   start[0] = 0;
   start[1] = 1;
 
-  double const ret1 = functionTester(J, start, 3);
+  double const ret1 = functionTester(J, start, 5);
 
   // Something random
   start[0] = 279;
   start[1] = -96;
 
-  double const ret2 = functionTester(J, start, 3);
-  assert(std::abs(ret1 - ret2) < 1e-5);
+  double const ret2 = functionTester(J, start, 5);
+  assert(std::abs(ret1 - ret2) < 1e-7);
 
   start[0] = 0;
   start[1] = 0;
 
   double const ret3 = functionTester(J, start, 1);
-  assert(std::abs(ret1 - ret3) < 1e-5);
+  assert(std::abs(ret1 - ret3) < 1e-7);
 }
diff --git a/src/test-gradient-sample-steep2.cc b/src/test-gradient-sample-steep2.cc
index f5892cd5..4ea0244c 100644
--- a/src/test-gradient-sample-steep2.cc
+++ b/src/test-gradient-sample-steep2.cc
@@ -41,12 +41,12 @@ int main() {
   start[0] = 279;
   start[1] = -96;
 
-  double const ret2 = functionTester(J, start, 3);
-  assert(std::abs(ret1 - ret2) < 1e-5);
+  double const ret2 = functionTester(J, start, 5);
+  assert(std::abs(ret1 - ret2) < 1e-7);
 
   start[0] = 0;
   start[1] = 0;
 
-  double const ret3 = functionTester(J, start, 1);
-  assert(std::abs(ret1 - ret3) < 1e-5);
+  double const ret3 = functionTester(J, start, 2);
+  assert(std::abs(ret1 - ret3) < 1e-7);
 }
diff --git a/src/test-gradient-sample-verysteep.cc b/src/test-gradient-sample-verysteep.cc
index 0cc230e6..8d10a8fd 100644
--- a/src/test-gradient-sample-verysteep.cc
+++ b/src/test-gradient-sample-verysteep.cc
@@ -41,12 +41,12 @@ int main() {
   start[0] = 279;
   start[1] = -96;
 
-  double const ret2 = functionTester(J, start, 4);
-  assert(std::abs(ret1 - ret2) < 1e-8);
+  double const ret2 = functionTester(J, start, 5);
+  assert(std::abs(ret1 - ret2) < 1e-7);
 
   start[0] = 0;
   start[1] = 0;
 
-  double const ret3 = functionTester(J, start, 1);
-  assert(std::abs(ret2 - ret3) < 1e-5);
+  double const ret3 = functionTester(J, start, 2);
+  assert(std::abs(ret1 - ret3) < 1e-7);
 }
-- 
GitLab