]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Enforce callback return value standard for the new NonlinearSolverSelector class. 15347/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 12 Jun 2023 16:33:14 +0000 (10:33 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 12 Jun 2023 16:36:48 +0000 (10:36 -0600)
include/deal.II/numerics/nonlinear.h
tests/numerics/nonlinear_solver_selector_01.cc
tests/numerics/nonlinear_solver_selector_03.cc

index 77d007599dc67ab4a8fdd5c37aee194707f140bc..cf4dc0c441a2c23597c48cf553ce86730ffe32fe 100644 (file)
@@ -288,9 +288,16 @@ public:
    * A function object that users should supply and that is intended to
    * compute the residual `dst = F(src)`.
    *
-   * This function should return an int for either failure or success.
+   * @note This variable represents a
+   * @ref GlossUserProvidedCallBack "user provided callback".
+   * See there for a description of how to deal with errors and other
+   * requirements and conventions. Some of the underlying packages
+   * used by this class can deal with recoverable exceptions, whereas
+   * others cannot. As a consequence, if a callback
+   * throws an exception of type RecoverableUserCallbackError, then this
+   * exception may or may not be treated like any other exception.
    */
-  std::function<int(const VectorType &src, VectorType &dst)> residual;
+  std::function<void(const VectorType &src, VectorType &dst)> residual;
 
   /**
    * A function object that users may supply and that is intended to
@@ -308,8 +315,17 @@ public:
    * approximate Jacobian matrix $L$.
    *
    * @param current_u Current value of $u$
+   *
+   * @note This variable represents a
+   * @ref GlossUserProvidedCallBack "user provided callback".
+   * See there for a description of how to deal with errors and other
+   * requirements and conventions. Some of the underlying packages
+   * used by this class can deal with recoverable exceptions, whereas
+   * others cannot. As a consequence, if a callback
+   * throws an exception of type RecoverableUserCallbackError, then this
+   * exception may or may not be treated like any other exception.
    */
-  std::function<int(const VectorType &current_u)> setup_jacobian;
+  std::function<void(const VectorType &current_u)> setup_jacobian;
 
   /**
    * A function object that users may supply and that is intended to solve
@@ -322,9 +338,18 @@ public:
    * @param[out] dst The solution of $J^{-1} * \texttt{src}$.
    * @param[in] tolerance The tolerance with which to solve the linear system
    *   of equations.
+   *
+   * @note This variable represents a
+   * @ref GlossUserProvidedCallBack "user provided callback".
+   * See there for a description of how to deal with errors and other
+   * requirements and conventions. Some of the underlying packages
+   * used by this class can deal with recoverable exceptions, whereas
+   * others cannot. As a consequence, if a callback
+   * throws an exception of type RecoverableUserCallbackError, then this
+   * exception may or may not be treated like any other exception.
    */
   std::function<
-    int(const VectorType &rhs, VectorType &dst, const double tolerance)>
+    void(const VectorType &rhs, VectorType &dst, const double tolerance)>
     solve_with_jacobian;
 
 private:
@@ -567,12 +592,12 @@ NonlinearSolverSelector<PETScWrappers::MPI::Vector>::solve_with_petsc(
 
   nonlinear_solver.solve_with_jacobian =
     [&](const PETScWrappers::MPI::Vector &src,
-        PETScWrappers::MPI::Vector &      dst) -> int {
-    // PETSc does not gives a tolerance, so we have to choose something
-    // reasonable to provide to the user:
-    const double tolerance = 1e-6;
-    return solve_with_jacobian(src, dst, tolerance);
-  };
+        PETScWrappers::MPI::Vector &      dst) {
+      // PETSc does not gives a tolerance, so we have to choose something
+      // reasonable to provide to the user:
+      const double tolerance = 1e-6;
+      solve_with_jacobian(src, dst, tolerance);
+    };
 
   nonlinear_solver.solve(initial_guess_and_solution);
 }
index e3126ba98b3af5f7ac265f51243bfab18f5ee928..958cf1aa38d5f73c9fe187f7db2febb59c8fb776 100644 (file)
@@ -369,22 +369,16 @@ namespace nonlinear_solver_selector_test
       nonlinear_solver.residual = [&](const Vector<double> &evaluation_point,
                                       Vector<double> &      residual) {
         compute_residual(evaluation_point, residual);
-
-        return 0;
       };
 
       nonlinear_solver.setup_jacobian = [&](const Vector<double> &current_u) {
         compute_and_factorize_jacobian(current_u);
-
-        return 0;
       };
 
       nonlinear_solver.solve_with_jacobian = [&](const Vector<double> &rhs,
                                                  Vector<double> &      dst,
                                                  const double tolerance) {
         this->solve(rhs, dst, tolerance);
-
-        return 0;
       };
 
       nonlinear_solver.solve(current_solution);
@@ -402,6 +396,4 @@ main()
 
   MinimalSurfaceProblem<2> laplace_problem_2d;
   laplace_problem_2d.run();
-
-  return 0;
 }
index 9026f572315f330aff127999ba99808749a6c841..1968ca6171319f75c56274af8581ffea9c4ae0c5 100644 (file)
@@ -451,22 +451,16 @@ namespace MPI_nonlinear_solver_selector_test
     nonlinear_solver.residual = [&](const LA::MPI::Vector &evaluation_point,
                                     LA::MPI::Vector &      residual) {
       compute_residual(evaluation_point, residual);
-
-      return 0;
     };
 
     nonlinear_solver.setup_jacobian = [&](const LA::MPI::Vector &current_u) {
       compute_and_factorize_jacobian(current_u);
-
-      return 0;
     };
 
     nonlinear_solver.solve_with_jacobian = [&](const LA::MPI::Vector &rhs,
                                                LA::MPI::Vector &      dst,
                                                const double tolerance) {
       this->solve(rhs, dst, tolerance);
-
-      return 0;
     };
 
     nonlinear_solver.solve(current_solution);
@@ -487,6 +481,4 @@ main(int argc, char *argv[])
 
   MinimalSurfaceProblem<2> laplace_problem_2d;
   laplace_problem_2d.run();
-
-  return 0;
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.