From: Wolfgang Bangerth Date: Thu, 25 May 2023 21:23:18 +0000 (-0600) Subject: Convert tests. X-Git-Tag: v9.5.0-rc1~189^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2b8a2e130ea45928544ac3f2bb1246e3763445a;p=dealii.git Convert tests. --- diff --git a/tests/petsc/petsc_snes_00.cc b/tests/petsc/petsc_snes_00.cc index ddc9c38752..58ffea706a 100644 --- a/tests/petsc/petsc_snes_00.cc +++ b/tests/petsc/petsc_snes_00.cc @@ -69,21 +69,19 @@ main(int argc, char **argv) // Here we only pass the callback for the function evaluation // The tangent system will be approximated via matrix-free finite // differencing. - solver.residual = [&](const VectorType &X, VectorType &F) -> int { + solver.residual = [&](const VectorType &X, VectorType &F) -> void { auto x = X[0]; auto y = X[1]; F(0) = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3); F(1) = x + 2 * y - 3; F.compress(VectorOperation::insert); - return 0; }; // Test attaching a user-defined monitoring routine solver.monitor = [&](const VectorType & X, const unsigned int step, - const real_type fval) -> int { + const real_type fval) -> void { out << "# " << step << ": " << fval << std::endl; - return 0; }; // Create and initialize solution vector @@ -102,13 +100,12 @@ main(int argc, char **argv) Solver solver(data); - solver.residual = [&](const VectorType &X, VectorType &F) -> int { + solver.residual = [&](const VectorType &X, VectorType &F) -> void { auto x = X[0]; auto y = X[1]; F(0) = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3); F(1) = x + 2 * y - 3; F.compress(VectorOperation::insert); - return 0; }; // Here we use the Jacobian callback following the PETSc style, @@ -118,7 +115,7 @@ main(int argc, char **argv) // will handle the case of users requesting Jacobian-free Newton // Krylov (i.e. using -snes_mf_operator) solver.jacobian = - [&](const VectorType &X, MatrixType &A, MatrixType &P) -> int { + [&](const VectorType &X, MatrixType &A, MatrixType &P) -> void { auto x = X[0]; auto y = X[1]; auto f0_x = 3 * std::pow(x - std::pow(y, 3) + 1, 2); @@ -129,7 +126,6 @@ main(int argc, char **argv) P.set(1, 0, 1); P.set(1, 1, 2); P.compress(VectorOperation::insert); - return 0; }; VectorType x(MPI_COMM_SELF, 2, 2); @@ -150,13 +146,12 @@ main(int argc, char **argv) Solver solver(data); - solver.residual = [&](const VectorType &X, VectorType &F) -> int { + solver.residual = [&](const VectorType &X, VectorType &F) -> void { auto x = X[0]; auto y = X[1]; F(0) = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3); F(1) = x + 2 * y - 3; F.compress(VectorOperation::insert); - return 0; }; // When users want to be in full control of the linear system @@ -165,7 +160,7 @@ main(int argc, char **argv) // during setup_jacobian and we use it in the solve phase FullMatrix Jinv(2, 2); - solver.setup_jacobian = [&](const VectorType &X) -> int { + solver.setup_jacobian = [&](const VectorType &X) -> void { auto x = X[0]; auto y = X[1]; auto f0_x = 3 * std::pow(x - std::pow(y, 3) + 1, 2); @@ -177,7 +172,6 @@ main(int argc, char **argv) J(1, 0) = 1; J(1, 1) = 2; Jinv.invert(J); - return 0; }; // Solve phase. By default, PETSc will use this callback as a preconditioner @@ -185,11 +179,10 @@ main(int argc, char **argv) // solvers can still be used in a Jacobian-free way and selected at command // line or within user code. solver.solve_with_jacobian = [&](const VectorType &src, - VectorType & dst) -> int { + VectorType & dst) -> void { dst(0) = Jinv(0, 0) * src(0) + Jinv(0, 1) * src(1); dst(1) = Jinv(1, 0) * src(0) + Jinv(1, 1) * src(1); dst.compress(VectorOperation::insert); - return 0; }; VectorType x(MPI_COMM_SELF, 2, 2); @@ -201,6 +194,4 @@ main(int argc, char **argv) out << "# Solution " << x[0] << ", " << x[1] << std::endl; out << "# Iterations " << nit << std::endl; } - - return 0; } diff --git a/tests/petsc/petsc_snes_01.cc b/tests/petsc/petsc_snes_01.cc index 916d70fe1d..db1d2a364b 100644 --- a/tests/petsc/petsc_snes_01.cc +++ b/tests/petsc/petsc_snes_01.cc @@ -51,14 +51,13 @@ main(int argc, char **argv) Solver solver; - solver.residual = [&](const VectorType &X, VectorType &F) -> int { + solver.residual = [&](const VectorType &X, VectorType &F) -> void { auto x = X.block(0)[0]; auto y = X.block(1)[0]; F.block(0)[0] = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3); F.block(1)[0] = x + 2 * y - 3; F.compress(VectorOperation::insert); - return 0; }; VectorType x(2, MPI_COMM_SELF, 1, 1); @@ -75,18 +74,17 @@ main(int argc, char **argv) Solver solver; - solver.residual = [&](const VectorType &X, VectorType &F) -> int { + solver.residual = [&](const VectorType &X, VectorType &F) -> void { auto x = X.block(0)[0]; auto y = X.block(1)[0]; F.block(0)[0] = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3); F.block(1)[0] = x + 2 * y - 3; F.compress(VectorOperation::insert); - return 0; }; solver.jacobian = - [&](const VectorType &X, MatrixType &A, MatrixType &P) -> int { + [&](const VectorType &X, MatrixType &A, MatrixType &P) -> void { auto x = X.block(0)[0]; auto y = X.block(1)[0]; auto f0_x = 3 * std::pow(x - std::pow(y, 3) + 1, 2); @@ -97,7 +95,6 @@ main(int argc, char **argv) P.block(1, 0).set(0, 0, 1); P.block(1, 1).set(0, 0, 2); P.compress(VectorOperation::insert); - return 0; }; VectorType x(2, MPI_COMM_SELF, 1, 1); @@ -132,19 +129,18 @@ main(int argc, char **argv) Solver solver; - solver.residual = [&](const VectorType &X, VectorType &F) -> int { + solver.residual = [&](const VectorType &X, VectorType &F) -> void { auto x = X.block(0)[0]; auto y = X.block(1)[0]; F.block(0)[0] = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3); F.block(1)[0] = x + 2 * y - 3; F.compress(VectorOperation::insert); - return 0; }; FullMatrix Jinv(2, 2); - solver.setup_jacobian = [&](const VectorType &X) -> int { + solver.setup_jacobian = [&](const VectorType &X) -> void { auto x = X.block(0)[0]; auto y = X.block(1)[0]; auto f0_x = 3 * std::pow(x - std::pow(y, 3) + 1, 2); @@ -156,17 +152,15 @@ main(int argc, char **argv) J(1, 0) = 1; J(1, 1) = 2; Jinv.invert(J); - return 0; }; solver.solve_with_jacobian = [&](const VectorType &src, - VectorType & dst) -> int { + VectorType & dst) -> void { dst.block(0)[0] = Jinv(0, 0) * src.block(0)[0] + Jinv(0, 1) * src.block(1)[0]; dst.block(1)[0] = Jinv(1, 0) * src.block(0)[0] + Jinv(1, 1) * src.block(1)[0]; dst.compress(VectorOperation::insert); - return 0; }; VectorType x(2, MPI_COMM_SELF, 1, 1); @@ -177,6 +171,4 @@ main(int argc, char **argv) out << "# Solution " << x[0] << ", " << x[1] << std::endl; out << "# Iterations " << nit << std::endl; } - - return 0; } diff --git a/tests/petsc/petsc_snes_02.cc b/tests/petsc/petsc_snes_02.cc index 35fc9759d4..7975927d9e 100644 --- a/tests/petsc/petsc_snes_02.cc +++ b/tests/petsc/petsc_snes_02.cc @@ -81,5 +81,4 @@ main(int argc, char **argv) { deallog << exc.what() << std::endl; } - return 0; } diff --git a/tests/petsc/petsc_snes_03.cc b/tests/petsc/petsc_snes_03.cc index b7d48a2671..f9c5b8e371 100644 --- a/tests/petsc/petsc_snes_03.cc +++ b/tests/petsc/petsc_snes_03.cc @@ -46,14 +46,12 @@ main(int argc, char **argv) { Solver solver; - solver.energy = [&](const VectorType &X, real_type &v) -> int { + solver.energy = [&](const VectorType &X, real_type &v) -> void { v = X.norm_sqr(); - return 0; }; - solver.residual = [&](const VectorType &X, VectorType &F) -> int { + solver.residual = [&](const VectorType &X, VectorType &F) -> void { F.equ(2, X); - return 0; }; auto commsize = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD); @@ -66,5 +64,4 @@ main(int argc, char **argv) deallog << "Iterations " << nit << std::endl; x.print(deallog.get_file_stream()); } - return 0; } diff --git a/tests/petsc/petsc_snes_04.cc b/tests/petsc/petsc_snes_04.cc index 9f09ff4424..498cfd8c93 100644 --- a/tests/petsc/petsc_snes_04.cc +++ b/tests/petsc/petsc_snes_04.cc @@ -42,9 +42,8 @@ main(int argc, char **argv) Solver solver(data); - solver.residual = [&](const VectorType &X, VectorType &F) -> int { + solver.residual = [&](const VectorType &X, VectorType &F) -> void { F.equ(2, X); - return 0; }; auto commsize = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD); @@ -61,5 +60,4 @@ main(int argc, char **argv) deallog << exc.what() << std::endl; } } - return 0; }