From 9ade0fac93916adf54cfe7c6df09ca1c403a8a67 Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Fri, 27 Jul 2012 13:55:20 +0200 Subject: [PATCH] Make the test suite work again --- src/test-gradient-method-nicefunction.hh | 115 +++++++++++++++++++++++ src/test-gradient-method.cc | 1 + 2 files changed, 116 insertions(+) create mode 100644 src/test-gradient-method-nicefunction.hh diff --git a/src/test-gradient-method-nicefunction.hh b/src/test-gradient-method-nicefunction.hh new file mode 100644 index 00000000..93085e39 --- /dev/null +++ b/src/test-gradient-method-nicefunction.hh @@ -0,0 +1,115 @@ +#include <dune/tectonic/nicefunction.hh> + +namespace Dune { +class MyFunction : public NiceFunction { + double virtual second_deriv(double) const { + assert(false); + return 0; + } + + double virtual regularity(double) const { + assert(false); + return 0; + } +}; + +class LinearFunction : public MyFunction { +public: + LinearFunction(double a) : coefficient(a) {} + + void virtual evaluate(double const &x, double &y) const { + y = coefficient * x; + } + + double virtual leftDifferential(double s) const { return coefficient; } + + double virtual rightDifferential(double s) const { return coefficient; } + + double virtual second_deriv(double) const { return 0; } + + double virtual regularity(double s) const { return 0; } + +private: + double const coefficient; +}; + +template <int slope> class SampleFunction : public MyFunction { +public: + void virtual evaluate(double const &x, double &y) const { + y = (x < 1) ? x : (slope * (x - 1) + 1); + } + + double virtual leftDifferential(double s) const { + return (s <= 1) ? 1 : slope; + } + + double virtual rightDifferential(double s) const { + return (s < 1) ? 1 : slope; + } +}; + +class SteepFunction : public MyFunction { +public: + void virtual evaluate(double const &x, double &y) const { y = 100 * x; } + + double virtual leftDifferential(double s) const { return 100; } + + double virtual rightDifferential(double s) const { return 100; } +}; + +// slope in [n-1,n] is n +class HorribleFunction : public MyFunction { +public: + void virtual evaluate(double const &x, double &y) const { + double const fl = floor(x); + double const sum = fl * (fl + 1) / 2; + y = sum + (fl + 1) * (x - fl); + } + + double virtual leftDifferential(double x) const { + double const fl = floor(x); + if (x - fl < 1e-14) + return fl; + else + return fl + 1; + } + + double virtual rightDifferential(double x) const { + double const c = ceil(x); + if (c - x < 1e-14) + return c + 1; + else + return c; + } +}; + +// slope in [n-1,n] is log(n+1) +class HorribleFunctionLogarithmic : public MyFunction { +public: + void virtual evaluate(double const &x, double &y) const { + y = 0; + size_t const fl = floor(x); + for (size_t i = 1; i <= fl;) + y += std::log( + ++i); // factorials grow to fast so we compute this incrementally + + y += std::log(fl + 2) * (x - fl); + } + + double virtual leftDifferential(double x) const { + double const fl = floor(x); + if (x - fl < 1e-14) + return std::log(fl + 1); + else + return std::log(fl + 2); + } + + double virtual rightDifferential(double x) const { + double const c = ceil(x); + if (c - x < 1e-14) + return std::log(c + 2); + else + return std::log(c + 1); + } +}; +} diff --git a/src/test-gradient-method.cc b/src/test-gradient-method.cc index 9f7d0e3a..7a855416 100644 --- a/src/test-gradient-method.cc +++ b/src/test-gradient-method.cc @@ -11,6 +11,7 @@ #include <dune/tnnmg/problem-classes/bisection.hh> #include <dune/tectonic/samplefunctional.hh> +#include "test-gradient-method-nicefunction.hh" template <int dim> double functionTester(Dune::SampleFunctional<dim> J, -- GitLab