From f56a135ed2b57c3ffbf3725596df3bfb28c8de6c Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Tue, 1 Nov 2011 16:45:08 +0100
Subject: [PATCH] Add template parameter to SampleFunction class

Obsoletes SteepFunctionNonsmooth
---
 dune/tectonic/nicefunction.hh | 23 ++++++++---------------
 src/test-gradient-method.cc   | 12 ++++++------
 2 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/dune/tectonic/nicefunction.hh b/dune/tectonic/nicefunction.hh
index efa0ba61..f4dfc107 100644
--- a/dune/tectonic/nicefunction.hh
+++ b/dune/tectonic/nicefunction.hh
@@ -23,15 +23,19 @@ class Identity : public NiceFunction {
   double virtual rightDifferential(double s) const { return 1; }
 };
 
-class SampleFunction : public NiceFunction {
+template <int slope> class SampleFunction : public NiceFunction {
 public:
   void virtual evaluate(double const& x, double& y) const {
-    y = (x < 1) ? x : (2 * x - 1);
+    y = (x < 1) ? x : (slope * (x - 1) + 1);
   }
 
-  double virtual leftDifferential(double s) const { return (s <= 1) ? 1 : 2; }
+  double virtual leftDifferential(double s) const {
+    return (s <= 1) ? 1 : slope;
+  }
 
-  double virtual rightDifferential(double s) const { return (s < 1) ? 1 : 2; }
+  double virtual rightDifferential(double s) const {
+    return (s < 1) ? 1 : slope;
+  }
 };
 
 class SteepFunction : public NiceFunction {
@@ -43,17 +47,6 @@ class SteepFunction : public NiceFunction {
   double virtual rightDifferential(double s) const { return 100; }
 };
 
-class SteepFunctionNonsmooth : public NiceFunction {
-public:
-  void virtual evaluate(double const& x, double& y) const {
-    y = (x < 1) ? x : (100 * x - 99);
-  }
-
-  double virtual leftDifferential(double s) const { return (s <= 1) ? 1 : 100; }
-
-  double virtual rightDifferential(double s) const { return (s < 1) ? 1 : 100; }
-};
-
 class TrivialFunction : public NiceFunction {
 public:
   void virtual evaluate(double const& x, double& y) const { y = 0; }
diff --git a/src/test-gradient-method.cc b/src/test-gradient-method.cc
index 92253a81..9f312bd1 100644
--- a/src/test-gradient-method.cc
+++ b/src/test-gradient-method.cc
@@ -70,7 +70,7 @@ void testSampleFunction() {
   b[0] = 1;
   b[1] = 2;
 
-  Dune::SampleFunction f;
+  Dune::SampleFunction<2> f;
   Functional J(A, b, Dune::MyNonlinearity<dim>(f));
 
   Functional::SmallVector start = b;
@@ -119,7 +119,7 @@ void testSampleFunctionNonsmooth() {
   b[0] = 1;
   b[1] = 2;
 
-  Dune::SampleFunction f;
+  Dune::SampleFunction<2> f;
   Functional J(A, b, Dune::MyNonlinearity<dim>(f));
 
   Functional::SmallVector start;
@@ -299,7 +299,7 @@ void testSampleFunction3D() {
   b[1] = 2;
   b[2] = 3;
 
-  Dune::SampleFunction f;
+  Dune::SampleFunction<2> f;
   Functional J(A, b, Dune::MyNonlinearity<dim>(f));
 
   Functional::SmallVector start = b;
@@ -337,7 +337,7 @@ void testSampleFunction2() {
   b[0] = 1;
   b[1] = 1;
 
-  Dune::SampleFunction f;
+  Dune::SampleFunction<2> f;
   Functional J(A, b, Dune::MyNonlinearity<dim>(f));
 
   Functional::SmallVector start = b;
@@ -371,7 +371,7 @@ void testSampleFunctionSteep1() {
   b[0] = 1;
   b[1] = 2;
 
-  Dune::SampleFunction f;
+  Dune::SampleFunction<2> f;
   Functional J(A, b, Dune::MyNonlinearity<dim>(f));
 
   Functional::SmallVector start;
@@ -408,7 +408,7 @@ void testSampleFunctionSteep2() {
   b[0] = 1;
   b[1] = 2.5;
 
-  Dune::SampleFunction f;
+  Dune::SampleFunction<2> f;
   Functional J(A, b, Dune::MyNonlinearity<dim>(f));
 
   Functional::SmallVector start;
-- 
GitLab