From b59b645e3f938fd335797af2eef41d4417eee626 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 2 May 2023 17:50:12 -0600 Subject: [PATCH] Convert tests. --- tests/sundials/kinsol_01.cc | 4 +- tests/sundials/kinsol_02.cc | 13 ++---- tests/sundials/kinsol_03.cc | 13 ++---- tests/sundials/kinsol_03_new_interface.cc | 50 ++++++++++------------- tests/sundials/kinsol_04.cc | 14 ++----- tests/sundials/kinsol_04_new_interface.cc | 14 ++----- tests/sundials/kinsol_05.cc | 14 ++----- tests/sundials/kinsol_05_new_interface.cc | 14 ++----- tests/sundials/kinsol_06.cc | 18 +++----- tests/sundials/step-77.cc | 7 ---- 10 files changed, 52 insertions(+), 109 deletions(-) diff --git a/tests/sundials/kinsol_01.cc b/tests/sundials/kinsol_01.cc index 9224bdf423..7d5623e242 100644 --- a/tests/sundials/kinsol_01.cc +++ b/tests/sundials/kinsol_01.cc @@ -61,7 +61,7 @@ main() kinsol.reinit_vector = [N](VectorType &v) { v.reinit(N); }; // Robert example - kinsol.iteration_function = [](const VectorType &u, VectorType &F) -> int { + kinsol.iteration_function = [](const VectorType &u, VectorType &F) { const double dstep = 0.1; const double y10 = 1.0; const double y20 = 0.0; @@ -73,8 +73,6 @@ main() F[0] = yd1 + y10; F[1] = -yd1 - yd3 + y20; F[2] = yd3 + y30; - - return 0; }; VectorType v(N); diff --git a/tests/sundials/kinsol_02.cc b/tests/sundials/kinsol_02.cc index 5c8574a767..fc5e214b20 100644 --- a/tests/sundials/kinsol_02.cc +++ b/tests/sundials/kinsol_02.cc @@ -63,27 +63,20 @@ main() kinsol.reinit_vector = [N](VectorType &v) { v.reinit(N); }; - kinsol.residual = [&](const VectorType &u, VectorType &F) -> int { + kinsol.residual = [&](const VectorType &u, VectorType &F) { F = u; F[0] += .1 * u[0] * u[0] - 1; F[1] += .1 * u[1] * u[1] - 2; - return 0; }; kinsol.solve_with_jacobian = - [&](const VectorType &rhs, VectorType &dst, double) -> int { - dst = rhs; - return 0; - }; + [&](const VectorType &rhs, VectorType &dst, double) { dst = rhs; }; kinsol.solve_jacobian_system = [&](const VectorType &, const VectorType &, const VectorType &rhs, - VectorType & dst) -> int { - dst = rhs; - return 0; - }; + VectorType & dst) { dst = rhs; }; VectorType v(N); diff --git a/tests/sundials/kinsol_03.cc b/tests/sundials/kinsol_03.cc index e90968e733..f0af240a1e 100644 --- a/tests/sundials/kinsol_03.cc +++ b/tests/sundials/kinsol_03.cc @@ -65,17 +65,16 @@ main() kinsol.reinit_vector = [N](VectorType &v) { v.reinit(N); }; - kinsol.residual = [](const VectorType &u, VectorType &F) -> int { + kinsol.residual = [](const VectorType &u, VectorType &F) { deallog << "Evaluating the solution at u=(" << u[0] << ',' << u[1] << ')' << std::endl; F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1]; - return 0; }; - kinsol.iteration_function = [](const VectorType &u, VectorType &F) -> int { + kinsol.iteration_function = [](const VectorType &u, VectorType &F) { // We want a Newton-type scheme, not a fixed point iteration. So we // shouldn't get into this function. std::abort(); @@ -83,23 +82,21 @@ main() // But if anyone wanted to see how it would look like: F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0] - u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1] - u[1]; - return 0; }; - kinsol.setup_jacobian = [](const VectorType &u, const VectorType &F) -> int { + kinsol.setup_jacobian = [](const VectorType &u, const VectorType &F) { // We don't do any kind of set-up in this program, but we can at least // say that we're here deallog << "Setting up Jacobian system at u=(" << u[0] << ',' << u[1] << ')' << std::endl; - return 0; }; kinsol.solve_jacobian_system = [](const VectorType &, const VectorType &, const VectorType &rhs, - VectorType & dst) -> int { + VectorType & dst) { deallog << "Solving Jacobian system with rhs=(" << rhs[0] << ',' << rhs[1] << ')' << std::endl; @@ -120,8 +117,6 @@ main() J_inverse.invert(J); J_inverse.vmult(dst, rhs); - - return 0; }; VectorType v(N); diff --git a/tests/sundials/kinsol_03_new_interface.cc b/tests/sundials/kinsol_03_new_interface.cc index 11ab7f3c50..86ccd31119 100644 --- a/tests/sundials/kinsol_03_new_interface.cc +++ b/tests/sundials/kinsol_03_new_interface.cc @@ -65,17 +65,16 @@ main() kinsol.reinit_vector = [N](VectorType &v) { v.reinit(N); }; - kinsol.residual = [](const VectorType &u, VectorType &F) -> int { + kinsol.residual = [](const VectorType &u, VectorType &F) { deallog << "Evaluating the solution at u=(" << u[0] << ',' << u[1] << ')' << std::endl; F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1]; - return 0; }; - kinsol.iteration_function = [](const VectorType &u, VectorType &F) -> int { + kinsol.iteration_function = [](const VectorType &u, VectorType &F) { // We want a Newton-type scheme, not a fixed point iteration. So we // shouldn't get into this function. std::abort(); @@ -83,45 +82,40 @@ main() // But if anyone wanted to see how it would look like: F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0] - u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1] - u[1]; - return 0; }; - kinsol.setup_jacobian = [](const VectorType &u, const VectorType &F) -> int { + kinsol.setup_jacobian = [](const VectorType &u, const VectorType &F) { // We don't do any kind of set-up in this program, but we can at least // say that we're here deallog << "Setting up Jacobian system at u=(" << u[0] << ',' << u[1] << ')' << std::endl; - return 0; }; - kinsol.solve_with_jacobian = [](const VectorType &rhs, - VectorType & dst, - const double /*tolerance*/) -> int { - deallog << "Solving Jacobian system with rhs=(" << rhs[0] << ',' << rhs[1] - << ')' << std::endl; + kinsol.solve_with_jacobian = + [](const VectorType &rhs, VectorType &dst, const double /*tolerance*/) { + deallog << "Solving Jacobian system with rhs=(" << rhs[0] << ',' << rhs[1] + << ')' << std::endl; - // This isn't right for SUNDIALS >4.0: We don't actually get a valid - // 'u' vector, and so do the linearization of the problem around - // the zero vector. This *happens* to converge, but it isn't the - // right approach. Check the _04 test for a better approach. - VectorType u(2); - u[0] = u[1] = 0; + // This isn't right for SUNDIALS >4.0: We don't actually get a valid + // 'u' vector, and so do the linearization of the problem around + // the zero vector. This *happens* to converge, but it isn't the + // right approach. Check the _04 test for a better approach. + VectorType u(2); + u[0] = u[1] = 0; - FullMatrix J(2, 2); - J(0, 0) = -std::sin(u[0] + u[1]) + 2; - J(0, 1) = -std::sin(u[0] + u[1]); - J(1, 0) = std::cos(u[0] - u[1]); - J(1, 1) = -std::cos(u[0] - u[1]) + 2; + FullMatrix J(2, 2); + J(0, 0) = -std::sin(u[0] + u[1]) + 2; + J(0, 1) = -std::sin(u[0] + u[1]); + J(1, 0) = std::cos(u[0] - u[1]); + J(1, 1) = -std::cos(u[0] - u[1]) + 2; - FullMatrix J_inverse(2, 2); - J_inverse.invert(J); + FullMatrix J_inverse(2, 2); + J_inverse.invert(J); - J_inverse.vmult(dst, rhs); - - return 0; - }; + J_inverse.vmult(dst, rhs); + }; VectorType v(N); v(0) = 0.5; diff --git a/tests/sundials/kinsol_04.cc b/tests/sundials/kinsol_04.cc index a499ad1afc..429658f652 100644 --- a/tests/sundials/kinsol_04.cc +++ b/tests/sundials/kinsol_04.cc @@ -77,17 +77,16 @@ main() kinsol.reinit_vector = [N](VectorType &v) { v.reinit(N); }; - kinsol.residual = [](const VectorType &u, VectorType &F) -> int { + kinsol.residual = [](const VectorType &u, VectorType &F) { deallog << "Evaluating the solution at u=(" << u[0] << ',' << u[1] << ')' << std::endl; F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1]; - return 0; }; - kinsol.iteration_function = [](const VectorType &u, VectorType &F) -> int { + kinsol.iteration_function = [](const VectorType &u, VectorType &F) { // We want a Newton-type scheme, not a fixed point iteration. So we // shouldn't get into this function. std::abort(); @@ -95,13 +94,12 @@ main() // But if anyone wanted to see how it would look like: F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0] - u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1] - u[1]; - return 0; }; FullMatrix J_inverse(2, 2); kinsol.setup_jacobian = [&J_inverse](const VectorType &u, - const VectorType &F) -> int { + const VectorType &F) { deallog << "Setting up Jacobian system at u=(" << u[0] << ',' << u[1] << ')' << std::endl; @@ -112,21 +110,17 @@ main() J(1, 1) = -std::cos(u[0] - u[1]) + 2; J_inverse.invert(J); - - return 0; }; kinsol.solve_jacobian_system = [&J_inverse](const VectorType &u, const VectorType &, const VectorType &rhs, - VectorType & dst) -> int { + VectorType & dst) { deallog << "Solving Jacobian system with rhs=(" << rhs[0] << ',' << rhs[1] << ')' << std::endl; J_inverse.vmult(dst, rhs); - - return 0; }; VectorType v(N); diff --git a/tests/sundials/kinsol_04_new_interface.cc b/tests/sundials/kinsol_04_new_interface.cc index f4435d7911..a2fe0f3e0e 100644 --- a/tests/sundials/kinsol_04_new_interface.cc +++ b/tests/sundials/kinsol_04_new_interface.cc @@ -77,17 +77,16 @@ main() kinsol.reinit_vector = [N](VectorType &v) { v.reinit(N); }; - kinsol.residual = [](const VectorType &u, VectorType &F) -> int { + kinsol.residual = [](const VectorType &u, VectorType &F) { deallog << "Evaluating the solution at u=(" << u[0] << ',' << u[1] << ')' << std::endl; F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1]; - return 0; }; - kinsol.iteration_function = [](const VectorType &u, VectorType &F) -> int { + kinsol.iteration_function = [](const VectorType &u, VectorType &F) { // We want a Newton-type scheme, not a fixed point iteration. So we // shouldn't get into this function. std::abort(); @@ -95,13 +94,12 @@ main() // But if anyone wanted to see how it would look like: F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0] - u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1] - u[1]; - return 0; }; FullMatrix J_inverse(2, 2); kinsol.setup_jacobian = [&J_inverse](const VectorType &u, - const VectorType &F) -> int { + const VectorType &F) { deallog << "Setting up Jacobian system at u=(" << u[0] << ',' << u[1] << ')' << std::endl; @@ -112,20 +110,16 @@ main() J(1, 1) = -std::cos(u[0] - u[1]) + 2; J_inverse.invert(J); - - return 0; }; kinsol.solve_with_jacobian = [&J_inverse](const VectorType &rhs, VectorType & dst, - const double /*tolerance*/) -> int { + const double /*tolerance*/) { deallog << "Solving Jacobian system with rhs=(" << rhs[0] << ',' << rhs[1] << ')' << std::endl; J_inverse.vmult(dst, rhs); - - return 0; }; VectorType v(N); diff --git a/tests/sundials/kinsol_05.cc b/tests/sundials/kinsol_05.cc index 9e8f2046e5..b35068108e 100644 --- a/tests/sundials/kinsol_05.cc +++ b/tests/sundials/kinsol_05.cc @@ -75,17 +75,16 @@ main() kinsol.reinit_vector = [N](VectorType &v) { v.reinit(N); }; - kinsol.residual = [](const VectorType &u, VectorType &F) -> int { + kinsol.residual = [](const VectorType &u, VectorType &F) { deallog << "Evaluating the solution at u=(" << u[0] << ',' << u[1] << ')' << std::endl; F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1]; - return 0; }; - kinsol.iteration_function = [](const VectorType &u, VectorType &F) -> int { + kinsol.iteration_function = [](const VectorType &u, VectorType &F) { // We want a Newton-type scheme, not a fixed point iteration. So we // shouldn't get into this function. std::abort(); @@ -93,13 +92,12 @@ main() // But if anyone wanted to see how it would look like: F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0] - u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1] - u[1]; - return 0; }; FullMatrix J_inverse(2, 2); kinsol.setup_jacobian = [&J_inverse](const VectorType &u, - const VectorType &F) -> int { + const VectorType &F) { // We don't do any kind of set-up in this program, but we can at least // say that we're here deallog << "Setting up Jacobian system at u=(" << u[0] << ',' << u[1] << ')' @@ -112,21 +110,17 @@ main() J(1, 1) = -std::cos(u[0] - u[1]) + 2; J_inverse.invert(J); - - return 0; }; kinsol.solve_jacobian_system = [&J_inverse](const VectorType &u, const VectorType &, const VectorType &rhs, - VectorType & dst) -> int { + VectorType & dst) { deallog << "Solving Jacobian system with rhs=(" << rhs[0] << ',' << rhs[1] << ')' << std::endl; J_inverse.vmult(dst, rhs); - - return 0; }; VectorType v(N); diff --git a/tests/sundials/kinsol_05_new_interface.cc b/tests/sundials/kinsol_05_new_interface.cc index 09d40c03c7..facf645aa8 100644 --- a/tests/sundials/kinsol_05_new_interface.cc +++ b/tests/sundials/kinsol_05_new_interface.cc @@ -75,17 +75,16 @@ main() kinsol.reinit_vector = [N](VectorType &v) { v.reinit(N); }; - kinsol.residual = [](const VectorType &u, VectorType &F) -> int { + kinsol.residual = [](const VectorType &u, VectorType &F) { deallog << "Evaluating the solution at u=(" << u[0] << ',' << u[1] << ')' << std::endl; F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1]; - return 0; }; - kinsol.iteration_function = [](const VectorType &u, VectorType &F) -> int { + kinsol.iteration_function = [](const VectorType &u, VectorType &F) { // We want a Newton-type scheme, not a fixed point iteration. So we // shouldn't get into this function. std::abort(); @@ -93,13 +92,12 @@ main() // But if anyone wanted to see how it would look like: F(0) = std::cos(u[0] + u[1]) - 1 + 2 * u[0] - u[0]; F(1) = std::sin(u[0] - u[1]) + 2 * u[1] - u[1]; - return 0; }; FullMatrix J_inverse(2, 2); kinsol.setup_jacobian = [&J_inverse](const VectorType &u, - const VectorType &F) -> int { + const VectorType &F) { // We don't do any kind of set-up in this program, but we can at least // say that we're here deallog << "Setting up Jacobian system at u=(" << u[0] << ',' << u[1] << ')' @@ -112,20 +110,16 @@ main() J(1, 1) = -std::cos(u[0] - u[1]) + 2; J_inverse.invert(J); - - return 0; }; kinsol.solve_with_jacobian = [&J_inverse](const VectorType &rhs, VectorType & dst, - const double /*tolerance*/) -> int { + const double /*tolerance*/) { deallog << "Solving Jacobian system with rhs=(" << rhs[0] << ',' << rhs[1] << ')' << std::endl; J_inverse.vmult(dst, rhs); - - return 0; }; VectorType v(N); diff --git a/tests/sundials/kinsol_06.cc b/tests/sundials/kinsol_06.cc index 359dff96b2..917a4546db 100644 --- a/tests/sundials/kinsol_06.cc +++ b/tests/sundials/kinsol_06.cc @@ -60,40 +60,34 @@ main() kinsol.reinit_vector = [N](VectorType &v) { v.reinit(N); }; - kinsol.residual = [&](const VectorType &u, VectorType &F) -> int { + kinsol.residual = [&](const VectorType &u, VectorType &F) { deallog << "Computing residual at " << u[0] << std::endl; if ((u[0] < -10) || (u[0] > 20)) { deallog << "Reporting recoverable failure." << std::endl; - return 1; + throw RecoverableUserCallbackError(); } F.reinit(u); F[0] = std::atan(u[0]) - 0.5; - - return 0; }; double J_inverse; kinsol.setup_jacobian = [&J_inverse](const VectorType &u, - const VectorType &F) -> int { + const VectorType &F) { deallog << "Setting up Jacobian system at u=" << u[0] << std::endl; const double J = 1. / (1 + u[0] * u[0]); J_inverse = 1. / J; - - return 0; }; - kinsol.solve_with_jacobian = - [&](const VectorType &rhs, VectorType &dst, double) -> int { - dst[0] = J_inverse * rhs[0]; - return 0; - }; + kinsol.solve_with_jacobian = [&](const VectorType &rhs, + VectorType & dst, + double) { dst[0] = J_inverse * rhs[0]; }; VectorType v(N); v[0] = 10; diff --git a/tests/sundials/step-77.cc b/tests/sundials/step-77.cc index 7585e58fb0..4c427d2636 100644 --- a/tests/sundials/step-77.cc +++ b/tests/sundials/step-77.cc @@ -424,24 +424,18 @@ namespace Step77 [&](const Vector &evaluation_point, Vector & residual) { compute_residual(evaluation_point, residual); - - return 0; }; nonlinear_solver.setup_jacobian = [&](const Vector ¤t_u, const Vector & /*current_f*/) { compute_and_factorize_jacobian(current_u); - - return 0; }; nonlinear_solver.solve_with_jacobian = [&](const Vector &rhs, Vector & dst, const double tolerance) { this->solve(rhs, dst, tolerance); - - return 0; }; nonlinear_solver.solve(current_solution); @@ -461,5 +455,4 @@ main() MinimalSurfaceProblem<2> laplace_problem_2d; laplace_problem_2d.run(); - return 0; } -- 2.39.5