From: Luca Heltai Date: Fri, 21 May 2021 16:00:02 +0000 (+0200) Subject: Fixed naming in IDA. X-Git-Tag: v9.3.0-rc1~17^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b157b0d0b680a258bc51ffafe8bc8c4df5038ee;p=dealii.git Fixed naming in IDA. --- diff --git a/doc/news/changes/minor/20210521LucaHeltai b/doc/news/changes/minor/20210521LucaHeltai new file mode 100644 index 0000000000..68abd1344a --- /dev/null +++ b/doc/news/changes/minor/20210521LucaHeltai @@ -0,0 +1,3 @@ +Fixed: Make SUNDIALS::IDA function names consistent with SUNDIALS::KINSOL function names. +
+(Luca Heltai, 2021/05/21) diff --git a/include/deal.II/sundials/ida.h b/include/deal.II/sundials/ida.h index 8726e9b157..b8c2ef02de 100644 --- a/include/deal.II/sundials/ida.h +++ b/include/deal.II/sundials/ida.h @@ -72,11 +72,11 @@ namespace SUNDIALS * - reinit_vector; * - residual; * - setup_jacobian; - * - solve_jacobian_system/solve_jacobian_system_up_to_tolerance; + * - solve_jacobian_system/solve_with_jacobian; * * The function `solve_jacobian_system` should be implemented for SUNDIALS * < 4.0.0. For later versions, you should use - * `solve_jacobian_system_up_to_tolerance` to leverage better non-linear + * `solve_with_jacobian` to leverage better non-linear * algorithms. * * Optionally, also the following functions could be provided. By default @@ -607,21 +607,6 @@ namespace SUNDIALS */ ~IDA(); - /** - * Save the number of iterations of the last Jacobian solve. - */ - void - set_n_iterations(const int n_iter); - - /** - * Return the number of iterations of the last Jacobian solve. This - * piece of information corresponds to the what the - * solve_jacobian_system_up_to_tolerance() function returns through - * its third argument. - */ - int - get_n_iterations() const; - /** * Integrate differential-algebraic equations. This function returns the * final number of computed steps. @@ -679,7 +664,7 @@ namespace SUNDIALS * update is required. The user should compute the Jacobian (or update all * the variables that allow the application of the Jacobian). This function * is called by IDA once, before any call to solve_jacobian_system() (for - * SUNDIALS < 4.0.0) or solve_jacobian_system_up_to_tolerance() (for + * SUNDIALS < 4.0.0) or solve_with_jacobian() (for * SUNDIALS >= 4.0.0). * * The Jacobian $J$ should be a (possibly inexact) computation of @@ -692,13 +677,13 @@ namespace SUNDIALS * is the right place where an assembly routine should be called to * assemble both a matrix and a preconditioner for the Jacobian system. * Subsequent calls (possibly more than one) to solve_jacobian_system() or - * solve_jacobian_system_up_to_tolerance() can assume that this function has + * solve_with_jacobian() can assume that this function has * been called at least once. * * Notice that no assumption is made by this interface on what the user * should do in this function. IDA only assumes that after a call to * setup_jacobian() it is possible to call solve_jacobian_system() or - * solve_jacobian_system_up_to_tolerance() to obtain a solution $x$ to the + * solve_with_jacobian() to obtain a solution $x$ to the * system $J x = b$. * * This function should return: @@ -746,9 +731,7 @@ namespace SUNDIALS * specifying the tolerance for the resolution. A part from the tolerance * only `rhs` is provided and `dst` needs to be returned. */ -# if DEAL_II_SUNDIALS_VERSION_GTE(4, 0, 0) DEAL_II_DEPRECATED_EARLY -# endif std::function solve_jacobian_system; @@ -761,7 +744,7 @@ namespace SUNDIALS * setup_jacobian() again. If, on the contrary, internal IDA convergence * tests fail, then IDA calls again setup_jacobian() with updated vectors * and coefficients so that successive calls to - * solve_jacobian_system_up_to_tolerance() lead to better convergence in the + * solve_with_jacobian() lead to better convergence in the * Newton process. * * The Jacobian $J$ should be (an approximation of) the system Jacobian @@ -774,11 +757,6 @@ namespace SUNDIALS * * @param[in] rhs The system right hand side to solve for. * @param[out] dst The solution of $J^{-1} * src$. - * @param[out] n_iter the number of iterations required to solve the - * Jacobian system. This is an output argument through which the - * function can communicate how many iterations it took to solve the - * linear system, and that can then be queried from the outside using the - * get_n_iterations() function. * @param[in] tolerance The tolerance with which to solve the linear system * of equations. * @@ -798,11 +776,9 @@ namespace SUNDIALS * - <0: Unrecoverable error the computation will be aborted and an * assertion will be thrown. */ - std::function - solve_jacobian_system_up_to_tolerance; + std::function< + int(const VectorType &rhs, VectorType &dst, const double tolerance)> + solve_with_jacobian; /** * Process solution. This function is called by IDA at fixed time steps, @@ -905,13 +881,6 @@ namespace SUNDIALS */ void *ida_mem; - /** - * Number of iteration that were required to solve the last - * Jacobian system. This variable is set by the wrapper that calls - * `solve_jacobian_system_up_to_tolerance`. - */ - int n_iterations; - /** * MPI communicator. SUNDIALS solver runs happily in * parallel. Note that if the library is compiled without MPI diff --git a/source/sundials/ida.cc b/source/sundials/ida.cc index 653c98dcd6..d03a402876 100644 --- a/source/sundials/ida.cc +++ b/source/sundials/ida.cc @@ -180,20 +180,10 @@ namespace SUNDIALS auto *src_b = internal::unwrap_nvector_const(b); auto *dst_x = internal::unwrap_nvector(x); int err = 0; - if (solver.solve_jacobian_system_up_to_tolerance) - { - int n_iter = 0; - - err = solver.solve_jacobian_system_up_to_tolerance(*src_b, - *dst_x, - n_iter, - tol); - solver.set_n_iterations(n_iter > 0 ? n_iter : 1); - } + if (solver.solve_with_jacobian) + err = solver.solve_with_jacobian(*src_b, *dst_x, tol); else if (solver.solve_jacobian_system) - { - err = solver.solve_jacobian_system(*src_b, *dst_x); - } + err = solver.solve_jacobian_system(*src_b, *dst_x); else // We have already checked this outside, so we should never get here. Assert(false, ExcInternalError()); @@ -233,24 +223,6 @@ namespace SUNDIALS - template - void - IDA::set_n_iterations(const int n_iter) - { - n_iterations = n_iter; - } - - - - template - int - IDA::get_n_iterations() const - { - return n_iterations; - } - - - template unsigned int IDA::solve_dae(VectorType &solution, VectorType &solution_dot) @@ -259,7 +231,6 @@ namespace SUNDIALS double h = data.initial_step_size; unsigned int step_number = 0; - this->n_iterations = 1; int status; (void)status; @@ -411,10 +382,9 @@ namespace SUNDIALS return 0; }; - AssertThrow( - solve_jacobian_system || solve_jacobian_system_up_to_tolerance, - ExcFunctionNotProvided( - "solve_jacobian_system or solve_jacobian_system_up_to_tolerance")); + AssertThrow(solve_jacobian_system || solve_with_jacobian, + ExcFunctionNotProvided( + "solve_jacobian_system or solve_with_jacobian")); LS->ops->solve = t_dae_solve_jacobian_system; // When we set an iterative solver IDA requires that resid is provided. From @@ -430,10 +400,7 @@ namespace SUNDIALS // When we set an iterative solver IDA requires that last number of // iteration is provided. Since we can't know what kind of solver the user // has provided we set 1. This is clearly suboptimal. - LS->ops->numiters = [](SUNLinearSolver LS) -> int { - IDA &solver = *static_cast *>(LS->content); - return solver.get_n_iterations(); - }; + LS->ops->numiters = [](SUNLinearSolver /*ignored*/) -> int { return 1; }; // Even though we don't use it, IDA still wants us to set some // kind of matrix object for the nonlinear solver. This is because // if we don't set it, it won't call the functions that set up diff --git a/tests/sundials/ida_01.cc b/tests/sundials/ida_01.cc index be104c411e..7d87619d3c 100644 --- a/tests/sundials/ida_01.cc +++ b/tests/sundials/ida_01.cc @@ -107,13 +107,9 @@ public: }; // Used in ver >= 4.0.0 - time_stepper.solve_jacobian_system_up_to_tolerance = - [&](const VectorType &src, - VectorType & dst, - int & n_iter, - const double) -> int { + time_stepper.solve_with_jacobian = + [&](const VectorType &src, VectorType &dst, const double) -> int { Jinv.vmult(dst, src); - n_iter = 1; return 0; }; diff --git a/tests/sundials/ida_02.cc b/tests/sundials/ida_02.cc index 700f676be4..73e556ff98 100644 --- a/tests/sundials/ida_02.cc +++ b/tests/sundials/ida_02.cc @@ -101,15 +101,12 @@ public: return 0; }; - time_stepper.solve_jacobian_system_up_to_tolerance = - [&](const VectorType &src, - VectorType & dst, - int & n_iter, - const double tolerance) -> int { + time_stepper.solve_with_jacobian = [&](const VectorType &src, + VectorType & dst, + const double tolerance) -> int { SolverControl solver_control(1000, tolerance); SolverGMRES> solver(solver_control); solver.solve(J, dst, src, PreconditionIdentity()); - n_iter = solver_control.last_step() > 0 ? solver_control.last_step() : 1; return 0; };