Skip to content
Snippets Groups Projects
Commit 14b2fced authored by Elias Pipping's avatar Elias Pipping Committed by Elias Pipping
Browse files

Compare minimise() and minimise2()

parent 8f7cbb67
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,24 @@ double functionTester(Dune::EllipticEnergy<dim> J, ...@@ -28,6 +28,24 @@ double functionTester(Dune::EllipticEnergy<dim> J,
return final; 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> template <int dim>
double two_distance(typename Dune::EllipticEnergy<dim>::SmallVector const &x, double two_distance(typename Dune::EllipticEnergy<dim>::SmallVector const &x,
typename Dune::EllipticEnergy<dim>::SmallVector const &y) { typename Dune::EllipticEnergy<dim>::SmallVector const &y) {
......
...@@ -29,7 +29,10 @@ int main() { ...@@ -29,7 +29,10 @@ int main() {
double ret1; double ret1;
{ {
SmallVector start = { 0, 1 }; 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; double ret2;
...@@ -37,6 +40,9 @@ int main() { ...@@ -37,6 +40,9 @@ int main() {
// Something random // Something random
SmallVector start = { 279, -96 }; SmallVector start = { 279, -96 };
ret2 = functionTester(J, start, 3); 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); assert(std::abs(ret1 - ret2) < 1e-5);
...@@ -44,6 +50,9 @@ int main() { ...@@ -44,6 +50,9 @@ int main() {
{ {
SmallVector start = { 0, 0 }; SmallVector start = { 0, 0 };
ret3 = functionTester(J, start, 1); 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); assert(std::abs(ret1 - ret3) < 1e-5);
} }
...@@ -30,6 +30,9 @@ int main() { ...@@ -30,6 +30,9 @@ int main() {
{ {
SmallVector start = { 0, 1 }; SmallVector start = { 0, 1 };
ret1 = functionTester(J, start, 2); ret1 = functionTester(J, start, 2);
SmallVector minimum;
functionTester2(J, minimum, 2);
assert(two_distance<dim>(start, minimum) < 1e-5);
} }
double ret2; double ret2;
...@@ -37,6 +40,9 @@ int main() { ...@@ -37,6 +40,9 @@ int main() {
// Something random // Something random
SmallVector start = { 279, -96 }; SmallVector start = { 279, -96 };
ret2 = functionTester(J, start, 3); 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); assert(std::abs(ret1 - ret2) < 1e-5);
...@@ -44,6 +50,9 @@ int main() { ...@@ -44,6 +50,9 @@ int main() {
{ {
SmallVector start = { 0, 0 }; SmallVector start = { 0, 0 };
ret3 = functionTester(J, start, 1); 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); assert(std::abs(ret1 - ret3) < 1e-5);
} }
...@@ -30,6 +30,9 @@ int main() { ...@@ -30,6 +30,9 @@ int main() {
{ {
SmallVector start = { 0, 1 }; SmallVector start = { 0, 1 };
ret1 = functionTester(J, start, 2); ret1 = functionTester(J, start, 2);
SmallVector minimum;
functionTester2(J, minimum, 2);
assert(two_distance<dim>(start, minimum) < 1e-5);
} }
double ret2; double ret2;
...@@ -37,6 +40,9 @@ int main() { ...@@ -37,6 +40,9 @@ int main() {
// Something random // Something random
SmallVector start = { 279, -96 }; SmallVector start = { 279, -96 };
ret2 = functionTester(J, start, 4); 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); assert(std::abs(ret1 - ret2) < 1e-8);
...@@ -44,6 +50,9 @@ int main() { ...@@ -44,6 +50,9 @@ int main() {
{ {
SmallVector start = { 0, 0 }; SmallVector start = { 0, 0 };
ret3 = functionTester(J, start, 1); 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); assert(std::abs(ret1 - ret3) < 1e-5);
} }
...@@ -43,7 +43,10 @@ int main() { ...@@ -43,7 +43,10 @@ int main() {
double ret1; double ret1;
{ {
SmallVector start = { 17, 34 }; 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; double ret2;
...@@ -51,6 +54,9 @@ int main() { ...@@ -51,6 +54,9 @@ int main() {
// Something random // Something random
SmallVector start = { 279, -96 }; SmallVector start = { 279, -96 };
ret2 = functionTester(J, start, 10); 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); assert(std::abs(ret1 - ret2) < 1e-5);
...@@ -58,6 +64,9 @@ int main() { ...@@ -58,6 +64,9 @@ int main() {
{ {
SmallVector start = { 0, 0 }; SmallVector start = { 0, 0 };
ret3 = functionTester(J, start, 3); 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); assert(std::abs(ret1 - ret3) < 1e-5);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment