diff --git a/src/test-gradient-method-helper.hh b/src/test-gradient-method-helper.hh index 2bb22ad9e587a4c589fbecfeed93b153e23bec8c..310e60d82a92cddf0744e481c0e3ff67fce0f4e7 100644 --- a/src/test-gradient-method-helper.hh +++ b/src/test-gradient-method-helper.hh @@ -28,6 +28,24 @@ double functionTester(Dune::EllipticEnergy<dim> J, return final; } +template <int dim> +double functionTester2(Dune::EllipticEnergy<dim> J, + typename Dune::EllipticEnergy<dim>::SmallVector &start, + size_t runs) { + Bisection const bisection( + 0.0, // acceptError: Stop if the search interval has + // become smaller than this number + 1.0, // acceptFactor: ? + 1e-12, // requiredResidual: ? + true, // fastQuadratic + 0); // safety: acceptance factor for inexact minimization + Dune::minimise2(J, start, runs, bisection); + double const final = J(start); + std::cout << boost::format(" -> %e (%e)") % final % start + << std::endl; + return final; +} + template <int dim> double two_distance(typename Dune::EllipticEnergy<dim>::SmallVector const &x, typename Dune::EllipticEnergy<dim>::SmallVector const &y) { diff --git a/src/test-gradient-sample-steep.cc b/src/test-gradient-sample-steep.cc index 9e7350bdb317171282b1e3009bc49956cd6427a0..3f082c4a84bcc0b56f800ba911e3f71695b1e9de 100644 --- a/src/test-gradient-sample-steep.cc +++ b/src/test-gradient-sample-steep.cc @@ -29,7 +29,10 @@ int main() { double ret1; { SmallVector start = { 0, 1 }; - ret1 = functionTester(J, start, 3); + ret1 = functionTester(J, start, 2); + SmallVector minimum; + functionTester2(J, minimum, 2); + assert(two_distance<dim>(start, minimum) < 1e-5); } double ret2; @@ -37,6 +40,9 @@ int main() { // Something random SmallVector start = { 279, -96 }; ret2 = functionTester(J, start, 3); + SmallVector minimum; + functionTester2(J, minimum, 3); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret2) < 1e-5); @@ -44,6 +50,9 @@ int main() { { SmallVector start = { 0, 0 }; ret3 = functionTester(J, start, 1); + SmallVector minimum; + functionTester2(J, minimum, 1); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample-steep2.cc b/src/test-gradient-sample-steep2.cc index 30a8507e5f0dd57e781ee9c48d56c898c732978a..3f082c4a84bcc0b56f800ba911e3f71695b1e9de 100644 --- a/src/test-gradient-sample-steep2.cc +++ b/src/test-gradient-sample-steep2.cc @@ -30,6 +30,9 @@ int main() { { SmallVector start = { 0, 1 }; ret1 = functionTester(J, start, 2); + SmallVector minimum; + functionTester2(J, minimum, 2); + assert(two_distance<dim>(start, minimum) < 1e-5); } double ret2; @@ -37,6 +40,9 @@ int main() { // Something random SmallVector start = { 279, -96 }; ret2 = functionTester(J, start, 3); + SmallVector minimum; + functionTester2(J, minimum, 3); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret2) < 1e-5); @@ -44,6 +50,9 @@ int main() { { SmallVector start = { 0, 0 }; ret3 = functionTester(J, start, 1); + SmallVector minimum; + functionTester2(J, minimum, 1); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample-verysteep.cc b/src/test-gradient-sample-verysteep.cc index 86b3f2c8cd6a52f6feb051056e362fb3cd207061..4d5f09ad3e5c41e033386f747ffffd32a1b17784 100644 --- a/src/test-gradient-sample-verysteep.cc +++ b/src/test-gradient-sample-verysteep.cc @@ -30,6 +30,9 @@ int main() { { SmallVector start = { 0, 1 }; ret1 = functionTester(J, start, 2); + SmallVector minimum; + functionTester2(J, minimum, 2); + assert(two_distance<dim>(start, minimum) < 1e-5); } double ret2; @@ -37,6 +40,9 @@ int main() { // Something random SmallVector start = { 279, -96 }; ret2 = functionTester(J, start, 4); + SmallVector minimum; + functionTester2(J, minimum, 4); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret2) < 1e-8); @@ -44,6 +50,9 @@ int main() { { SmallVector start = { 0, 0 }; ret3 = functionTester(J, start, 1); + SmallVector minimum; + functionTester2(J, minimum, 1); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample.cc b/src/test-gradient-sample.cc index 742bbf091df83e858c47413cff109b70049d6a87..245249b7bfde9f5a7c4a1fc1eb74639919ad758e 100644 --- a/src/test-gradient-sample.cc +++ b/src/test-gradient-sample.cc @@ -43,7 +43,10 @@ int main() { double ret1; { SmallVector start = { 17, 34 }; - ret1 = functionTester(J, start, 6); + ret1 = functionTester(J, start, 8); + SmallVector minimum; + functionTester2(J, minimum, 8); + assert(two_distance<dim>(start, minimum) < 1e-5); } double ret2; @@ -51,6 +54,9 @@ int main() { // Something random SmallVector start = { 279, -96 }; ret2 = functionTester(J, start, 10); + SmallVector minimum; + functionTester2(J, minimum, 10); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret2) < 1e-5); @@ -58,6 +64,9 @@ int main() { { SmallVector start = { 0, 0 }; ret3 = functionTester(J, start, 3); + SmallVector minimum; + functionTester2(J, minimum, 3); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret3) < 1e-5); }