From a02513434175e3bf4b46b02508d30a93026389db Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Sun, 29 Jul 2012 16:49:06 +0200 Subject: [PATCH] Compare with analytic solution --- src/test-gradient-trivial.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test-gradient-trivial.cc b/src/test-gradient-trivial.cc index 7b2b3661..895fdb5e 100644 --- a/src/test-gradient-trivial.cc +++ b/src/test-gradient-trivial.cc @@ -1,6 +1,6 @@ /* Checks if the descent direction is computed correctly using the analytic solution; also checks if the algorithm converges - regardless of where it starts */ + to the right solution regardless of where it starts */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -27,6 +27,10 @@ int main() { b[0] = 1; b[1] = 2; + Functional::SmallVector solution; // Analytic solution + solution[0] = 4.0 / 39.0; + solution[1] = 6.0 / 13.0; + auto f = Dune::make_shared<Dune::TrivialFunction const>(); auto phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); @@ -49,11 +53,18 @@ int main() { assert(error.two_norm() < 1e-10); double const ret1 = functionTester(J, start, 6); + error = solution; + error -= start; + assert(error.two_norm() < 1e-5); // Something random start[0] = 279; start[1] = -96; - double const ret2 = functionTester(J, start, 16); + double const ret2 = functionTester(J, start, 25); + error = solution; + error -= start; + assert(error.two_norm() < 1e-6); + assert(std::abs(ret1 - ret2) < 1e-5); } -- GitLab