diff --git a/src/test-circle.cc b/src/test-circle.cc index a7f308e41c490e232520826d90bd50b9bda825a9..9489723c3f5e9f01e23a43d4539024abfbc31985 100644 --- a/src/test-circle.cc +++ b/src/test-circle.cc @@ -26,13 +26,8 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 4; - A[0][1] = A[1][0] = 1.5; - A[1][1] = 3; - SmallVector b; - b[0] = 1; - b[1] = 2; + SmallMatrix A = { { 4, 1.5 }, { 1.5, 3 } }; + SmallVector b = { 1, 2 }; auto const f = Dune::make_shared<Dune::SampleFunction<2> const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); @@ -49,12 +44,8 @@ int main() { boost::format const formatter("J([%+e]) = %g"); for (size_t i = 0; i < radii.size(); ++i) { - SmallVector x; - x[0] = scale * std::sin(radii[i]); - x[1] = scale * std::cos(radii[i]); - SmallVector descDir; - descDir[0] = x[1]; - descDir[1] = -x[0]; + SmallVector x = { scale * std::sin(radii[i]), scale * std::cos(radii[i]) }; + SmallVector descDir = { x[1], -x[0] }; tangentialMinimisation(J, x, descDir, bisection); minima[i] = x; std::cout << boost::format(formatter) % x % J(x) << std::endl; @@ -63,13 +54,8 @@ int main() { double const intervals = 10000; for (size_t i = 0; i < intervals; ++i) { double const alpha = i / (double)intervals * 2 * M_PI; - SmallVector x; - x[0] = scale * std::sin(alpha); - x[1] = scale * std::cos(alpha); - - SmallVector descDir; - descDir[0] = x[1]; - descDir[1] = -x[0]; + SmallVector x = { scale * std::sin(alpha), scale * std::cos(alpha) }; + SmallVector descDir = { x[1], -x[0] }; tangentialMinimisation(J, x, descDir, bisection); bool minimum_hit(false); diff --git a/src/test-gradient-horrible-logarithmic.cc b/src/test-gradient-horrible-logarithmic.cc index 9507dcfe119b56509a4d583120823327c6528ce2..950a776c43c0620de83a5c27f4d52dbc54dbfd04 100644 --- a/src/test-gradient-horrible-logarithmic.cc +++ b/src/test-gradient-horrible-logarithmic.cc @@ -19,33 +19,31 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 3; - A[0][1] = A[1][0] = 1.5; - A[1][1] = 4; - SmallVector b; - b[0] = 1; - b[1] = 2; + SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } }; + SmallVector b = { 1, 2 }; auto const f = Dune::make_shared<Dune::HorribleFunctionLogarithmic const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector start = b; - start *= 17; - - double const ret1 = functionTester(J, start, 6); - - // Something random - start[0] = 279; - start[1] = -96; - - double const ret2 = functionTester(J, start, 12); + double ret1; + { + SmallVector start = { 17, 34 }; + ret1 = functionTester(J, start, 6); + } + + double ret2; + { + // Something random + SmallVector start = { 279, -96 }; + ret2 = functionTester(J, start, 12); + } assert(std::abs(ret1 - ret2) < 1e-5); - start[0] = 0; - start[1] = 0; - - double const ret3 = functionTester(J, start, 4); + double ret3; + { + SmallVector start = { 0, 0 }; + ret3 = functionTester(J, start, 4); + } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-horrible.cc b/src/test-gradient-horrible.cc index e3215d00dd731da612f1691304c1fb849e82242c..14de1df5a5d7b258e65bc2f66ff55e926a1b0677 100644 --- a/src/test-gradient-horrible.cc +++ b/src/test-gradient-horrible.cc @@ -19,33 +19,31 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 3; - A[0][1] = A[1][0] = 1.5; - A[1][1] = 4; - SmallVector b; - b[0] = 1; - b[1] = 2; + SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } }; + SmallVector b = { 1, 2 }; auto const f = Dune::make_shared<Dune::HorribleFunction const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector start = b; - start *= 17; - - double const ret1 = functionTester(J, start, 7); - - // Something random - start[0] = 279; - start[1] = -96; - - double const ret2 = functionTester(J, start, 8); + double ret1; + { + SmallVector start = { 17, 34 }; + ret1 = functionTester(J, start, 7); + } + + double ret2; + { + // Something random + SmallVector start = { 279, -96 }; + ret2 = functionTester(J, start, 8); + } assert(std::abs(ret1 - ret2) < 1e-5); - start[0] = 0; - start[1] = 0; - - double const ret3 = functionTester(J, start, 4); + double ret3; + { + SmallVector start = { 0, 0 }; + ret3 = functionTester(J, start, 4); + } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-identity.cc b/src/test-gradient-identity.cc index 82eac754f845540985128c4c22ffff611a41cc70..a9ba32e86af536cde20cd10dff164c75d9762afe 100644 --- a/src/test-gradient-identity.cc +++ b/src/test-gradient-identity.cc @@ -19,33 +19,31 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 3; - A[0][1] = A[1][0] = 1.5; - A[1][1] = 4; - SmallVector b; - b[0] = 1; - b[1] = 2; + SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } }; + SmallVector b = { 1, 2 }; auto const f = Dune::make_shared<Dune::LinearFunction const>(1); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector start = b; - start *= 17; - - double const ret1 = functionTester(J, start, 6); - - // Something random - start[0] = 279; - start[1] = -96; - - double const ret2 = functionTester(J, start, 10); + double ret1; + { + SmallVector start = { 17, 34 }; + ret1 = functionTester(J, start, 6); + } + + double ret2; + { + // Something random + SmallVector start = { 279, -96 }; + ret2 = functionTester(J, start, 10); + } assert(std::abs(ret1 - ret2) < 1e-5); - start[0] = 0; - start[1] = 0; - - double const ret3 = functionTester(J, start, 3); + double ret3; + { + SmallVector start = { 0, 0 }; + ret3 = functionTester(J, start, 3); + } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-parabola.cc b/src/test-gradient-parabola.cc index cce5f56b5f07e55a381a47f3bd71000278410ed6..a1d3d802564bb5ab65f93f2ce9bace1d34246c1d 100644 --- a/src/test-gradient-parabola.cc +++ b/src/test-gradient-parabola.cc @@ -21,13 +21,8 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 3; - A[0][1] = A[1][0] = 1.5; - A[1][1] = 4; - SmallVector b; - b[0] = 1; - b[1] = 2; + SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } }; + SmallVector b = { 1, 2 }; // |x|^2 as the nonlinearity is the same as having no nonlinearity // but twice the identity matrix added to A. In other words, we're @@ -36,10 +31,7 @@ int main() { auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector solution; // Analytic solution - solution[0] = 4.0 / 37.0; - solution[1] = 34.0 / 111.0; - + SmallVector solution = { 4.0 / 37.0, 34.0 / 111.0 }; // Analytic solution SmallMatrix M = A; M[0][0] += 2; M[1][1] += 2; @@ -63,10 +55,7 @@ int main() { double ret2; { // Something random - SmallVector start; - start[0] = 279; - start[1] = -96; - + SmallVector start = { 279, -96 }; SmallVector analytic_descent = b; M.mmv(start, analytic_descent); diff --git a/src/test-gradient-sample-3d.cc b/src/test-gradient-sample-3d.cc index ae2cb3e095b8bcd0981439461e2ea4bc46e0acd6..e57d2b845b5dbeb7dd2eda6fdabe4f0a96d0d6fb 100644 --- a/src/test-gradient-sample-3d.cc +++ b/src/test-gradient-sample-3d.cc @@ -19,38 +19,31 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A(0); - A[0][0] = 3; - A[0][1] = A[1][0] = 1.5; - A[1][1] = 4; - A[1][2] = A[2][1] = 1.5; - A[2][2] = 5; - SmallVector b; - b[0] = 1; - b[1] = 2; - b[2] = 3; + SmallMatrix A = { { 3, 1.5, 0 }, { 1.5, 4, 1.5 }, { 0, 1.5, 5 } }; + SmallVector b = { 1, 2, 3 }; auto const f = Dune::make_shared<Dune::SampleFunction<2> const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector start = b; - start *= 17; - - double const ret1 = functionTester(J, start, 9); - - // Something random - start[0] = 279; - start[1] = -96; - start[2] = -15; - - double const ret2 = functionTester(J, start, 15); + double ret1; + { + SmallVector start = { 17, 34, 51 }; + ret1 = functionTester(J, start, 9); + } + + double ret2; + { + // Something random + SmallVector start = { 279, -96, -15 }; + ret2 = functionTester(J, start, 15); + } assert(std::abs(ret1 - ret2) < 1e-5); - start[0] = 0; - start[1] = 0; - start[2] = 0; - - double const ret3 = functionTester(J, start, 5); + double ret3; + { + SmallVector start = { 0, 0, 0 }; + ret3 = functionTester(J, start, 5); + } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample-nonsmooth.cc b/src/test-gradient-sample-nonsmooth.cc index e8f49226e4832dd5c3e90fff8d119601356c610e..63c8034fe35dd880bcde45e4b7796931a8740983 100644 --- a/src/test-gradient-sample-nonsmooth.cc +++ b/src/test-gradient-sample-nonsmooth.cc @@ -20,20 +20,14 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 3; - A[0][1] = A[1][0] = 1.5; - A[1][1] = 4; - SmallVector b; - b[0] = 1; - b[1] = 2; + SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } }; + SmallVector b = { 1, 2 }; auto const f = Dune::make_shared<Dune::SampleFunction<2> const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); SmallVector start; - SmallVector analytic_descent; /* for x = b/|b|: @@ -54,8 +48,8 @@ int main() { SmallVector numerical_descent; J.descentDirection(start, numerical_descent); - analytic_descent[0] = -(7 / sqrt(5) - 1); - analytic_descent[1] = -(11.5 / sqrt(5) - 2); + SmallVector analytic_descent = { -(7 / sqrt(5) - 1), + -(11.5 / sqrt(5) - 2) }; assert(two_distance<dim>(analytic_descent, numerical_descent) < 1e-10); functionTester(J, start, 6); @@ -67,8 +61,8 @@ int main() { SmallVector numerical_descent; J.descentDirection(start, numerical_descent); - analytic_descent[0] = -(8 / sqrt(5) - 1); - analytic_descent[1] = -(13.5 / sqrt(5) - 2); + SmallVector analytic_descent = { -(8 / sqrt(5) - 1), + -(13.5 / sqrt(5) - 2) }; assert(two_distance<dim>(analytic_descent, numerical_descent) < 1e-10); functionTester(J, start, 6); diff --git a/src/test-gradient-sample-steep.cc b/src/test-gradient-sample-steep.cc index 3cd290dd0149b5d3bb945e8b123d923705a4e5e1..3bc51befe6ccb8e89f744de9a50d664c7dd631a8 100644 --- a/src/test-gradient-sample-steep.cc +++ b/src/test-gradient-sample-steep.cc @@ -19,35 +19,31 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 1; - A[0][1] = A[1][0] = 0; - A[1][1] = 1; - SmallVector b; - b[0] = 1; - b[1] = 2; + SmallMatrix A = { { 1, 0 }, { 0, 1 } }; + SmallVector b = { 1, 2 }; auto const f = Dune::make_shared<Dune::SampleFunction<2> const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector start; - - start[0] = 0; - start[1] = 1; - - double const ret1 = functionTester(J, start, 3); - - // Something random - start[0] = 279; - start[1] = -96; - - double const ret2 = functionTester(J, start, 3); + double ret1; + { + SmallVector start = { 0, 1 }; + ret1 = functionTester(J, start, 3); + } + + double ret2; + { + // Something random + SmallVector start = { 279, -96 }; + ret2 = functionTester(J, start, 3); + } assert(std::abs(ret1 - ret2) < 1e-5); - start[0] = 0; - start[1] = 0; - - double const ret3 = functionTester(J, start, 1); + double ret3; + { + SmallVector start = { 0, 0 }; + ret3 = functionTester(J, start, 1); + } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample-steep2.cc b/src/test-gradient-sample-steep2.cc index abbd289901d238822d2fdb8501a8e42f494498e9..f77c3788fb84488eb290fe8c605353bca8525a46 100644 --- a/src/test-gradient-sample-steep2.cc +++ b/src/test-gradient-sample-steep2.cc @@ -19,35 +19,31 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 1; - A[0][1] = A[1][0] = 0; - A[1][1] = 1; - SmallVector b; - b[0] = 1; - b[1] = 2.5; + SmallMatrix A = { { 1, 0 }, { 0, 1 } }; + SmallVector b = { 1, 2.5 }; auto const f = Dune::make_shared<Dune::SampleFunction<2> const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector start; - - start[0] = 0; - start[1] = 1; - - double const ret1 = functionTester(J, start, 1); - - // Something random - start[0] = 279; - start[1] = -96; - - double const ret2 = functionTester(J, start, 3); + double ret1; + { + SmallVector start = { 0, 1 }; + ret1 = functionTester(J, start, 1); + } + + double ret2; + { + // Something random + SmallVector start = { 279, -96 }; + ret2 = functionTester(J, start, 3); + } assert(std::abs(ret1 - ret2) < 1e-5); - start[0] = 0; - start[1] = 0; - - double const ret3 = functionTester(J, start, 1); + double ret3; + { + SmallVector start = { 0, 0 }; + ret3 = functionTester(J, start, 1); + } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample-verysteep.cc b/src/test-gradient-sample-verysteep.cc index 12fd5c3d9d9baa19008b03adcf24af167803055d..372787ae07bd85a5631e31d2761bd22bf270f8d9 100644 --- a/src/test-gradient-sample-verysteep.cc +++ b/src/test-gradient-sample-verysteep.cc @@ -19,35 +19,31 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 1; - A[0][1] = A[1][0] = 0; - A[1][1] = 1; - SmallVector b; - b[0] = 1; - b[1] = 2.5; + SmallMatrix A = { { 1, 0 }, { 0, 1 } }; + SmallVector b = { 1, 2.5 }; auto const f = Dune::make_shared<Dune::SampleFunction<100> const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector start; - - start[0] = 0; - start[1] = 1; - - double const ret1 = functionTester(J, start, 1); - - // Something random - start[0] = 279; - start[1] = -96; - - double const ret2 = functionTester(J, start, 4); + double ret1; + { + SmallVector start = { 0, 1 }; + ret1 = functionTester(J, start, 1); + } + + double ret2; + { + // Something random + SmallVector start = { 279, -96 }; + ret2 = functionTester(J, start, 4); + } assert(std::abs(ret1 - ret2) < 1e-8); - start[0] = 0; - start[1] = 0; - - double const ret3 = functionTester(J, start, 1); + double ret3; + { + SmallVector start = { 0, 0 }; + ret3 = functionTester(J, start, 1); + } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample.cc b/src/test-gradient-sample.cc index e10acc130a751ad0e89b097c85c11277843c7ff3..c7a8dc5ae5c6199c1345d82280d2cf15e38c8034 100644 --- a/src/test-gradient-sample.cc +++ b/src/test-gradient-sample.cc @@ -21,46 +21,43 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 3; - A[0][1] = A[1][0] = 1.5; - A[1][1] = 4; - SmallVector b; - b[0] = 1; - b[1] = 2; + SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } }; + SmallVector b = { 1, 2 }; auto const f = Dune::make_shared<Dune::SampleFunction<2> const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector start = b; - start *= 17; - /* j(x) = Ax - b + 2/|x| x = 17*(6, 9.5) - (1, 2) + 2/sqrt(5) (1, 2) = (102 - 1 + 2/sqrt(5), 161.5 - 2 + 4/sqrt(5)) */ - SmallVector analytic_descent; - analytic_descent[0] = -(102 - 1 + 2 / sqrt(5)); - analytic_descent[1] = -(161.5 - 2 + 4 / sqrt(5)); + SmallVector analytic_descent = { -(102 - 1 + 2 / sqrt(5)), + -(161.5 - 2 + 4 / sqrt(5)) }; SmallVector numerical_descent; - J.descentDirection(start, numerical_descent); + J.descentDirection(SmallVector({ 17, 34 }), numerical_descent); assert(two_distance<dim>(analytic_descent, numerical_descent) < 1e-10); - double const ret1 = functionTester(J, start, 6); - - // Something random - start[0] = 279; - start[1] = -96; - - double const ret2 = functionTester(J, start, 10); + double ret1; + { + SmallVector start = { 17, 34 }; + ret1 = functionTester(J, start, 6); + } + + double ret2; + { + // Something random + SmallVector start = { 279, -96 }; + ret2 = functionTester(J, start, 10); + } assert(std::abs(ret1 - ret2) < 1e-5); - start[0] = 0; - start[1] = 0; - - double const ret3 = functionTester(J, start, 3); + double ret3; + { + SmallVector start = { 0, 0 }; + ret3 = functionTester(J, start, 3); + } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample2.cc b/src/test-gradient-sample2.cc index 9bbd7ec476e9bf32ed9fb655df05b23b70b68989..ff80966d27a2196dcff385f896a20724e17865fa 100644 --- a/src/test-gradient-sample2.cc +++ b/src/test-gradient-sample2.cc @@ -21,32 +21,31 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 1; - A[0][1] = A[1][0] = 0; - A[1][1] = 1; - SmallVector b; - b[0] = 1; - b[1] = 1; + SmallMatrix A = { { 1, 0 }, { 0, 1 } }; + SmallVector b = { 1, 1 }; auto const f = Dune::make_shared<Dune::SampleFunction<2> const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector start = b; - - double const ret1 = functionTester(J, start, 2); - - // Something random - start[0] = 279; - start[1] = -96; - - double const ret2 = functionTester(J, start, 7); + double ret1; + { + SmallVector start = b; + ret1 = functionTester(J, start, 2); + } + + double ret2; + { + // Something random + SmallVector start = { 279, -96 }; + ret2 = functionTester(J, start, 7); + } assert(std::abs(ret1 - ret2) < 1e-5); - start[0] = 0; - start[1] = 0; - - double const ret3 = functionTester(J, start, 2); + double ret3; + { + SmallVector start = { 0, 0 }; + ret3 = functionTester(J, start, 2); + } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-trivial.cc b/src/test-gradient-trivial.cc index 2718dbe2313b0a44f55e33e07ab4e94e91849319..6368580f0c933172ef1277d5181db35b170761c2 100644 --- a/src/test-gradient-trivial.cc +++ b/src/test-gradient-trivial.cc @@ -20,21 +20,14 @@ int main() { typedef Functional::SmallMatrix SmallMatrix; typedef Functional::SmallVector SmallVector; - SmallMatrix A; - A[0][0] = 3; - A[0][1] = A[1][0] = 1.5; - A[1][1] = 4; - SmallVector b; - b[0] = 1; - b[1] = 2; + SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } }; + SmallVector b = { 1, 2 }; auto const f = Dune::make_shared<Dune::TrivialFunction const>(); auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f); Functional J(A, b, phi); - SmallVector solution; // Analytic solution - solution[0] = 4.0 / 39.0; - solution[1] = 6.0 / 13.0; + SmallVector solution = { 4.0 / 39.0, 6.0 / 13.0 }; // Analytic solution double ret1; { @@ -54,9 +47,7 @@ int main() { double ret2; { // Something random - SmallVector start; - start[0] = 279; - start[1] = -96; + SmallVector start = { 279, -96 }; SmallVector analytic_descent = b; A.mmv(start, analytic_descent);