From: David Wells Date: Tue, 30 May 2023 18:37:13 +0000 (-0400) Subject: Merge pull request #15267 from bangerth/requires X-Git-Tag: v9.5.0-rc1~184 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3044dfcd6aa7f42b3143ada0930867d714bb5576;p=dealii.git Merge pull request #15267 from bangerth/requires Add 'requires' clauses for matrix template arguments to PETSc TS and SNES solvers. --- 3044dfcd6aa7f42b3143ada0930867d714bb5576 diff --cc include/deal.II/lac/petsc_snes.templates.h index 16b9b647ac,e03cf66ef8..eaa262e44f --- a/include/deal.II/lac/petsc_snes.templates.h +++ b/include/deal.II/lac/petsc_snes.templates.h @@@ -38,52 -38,28 +38,59 @@@ DEAL_II_NAMESPACE_OPE } \ while (0) -// Shorthand notation for User error codes. -# define AssertUser(code, name) \ - do \ - { \ - int ierr = (code); \ - AssertThrow(ierr == 0, \ - StandardExceptions::ExcFunctionNonzeroReturn(name, ierr)); \ - } \ - while (0) - namespace PETScWrappers { + namespace + { + /** + * A function that calls the function object given by its first argument + * with the set of arguments following at the end. If the call returns + * regularly, the current function returns zero to indicate success. If + * the call fails with an exception, then the current function returns with + * an error code of -1. In that case, the exception thrown by `f` is + * captured and `eptr` is set to the exception. In case of success, + * `eptr` is set to `nullptr`. + */ + template + int + call_and_possibly_capture_exception(const F & f, + std::exception_ptr &eptr, + Args &&...args) + { + // See whether there is already something in the exception pointer + // variable. There is no reason why this should be so, and + // we should probably bail out: + AssertThrow(eptr == nullptr, ExcInternalError()); + + // Call the function and if that succeeds, return zero: + try + { + f(std::forward(args)...); + eptr = nullptr; + return 0; + } + // In case of an exception, capture the exception and + // return -1: + catch (...) + { + eptr = std::current_exception(); + return -1; + } + } + } // namespace + + + template - DEAL_II_CXX20_REQUIRES((concepts::is_dealii_petsc_vector_type || - std::constructible_from)) + DEAL_II_CXX20_REQUIRES( + (concepts::is_dealii_petsc_vector_type || + std::constructible_from< + VectorType, + Vec>)&&(concepts::is_dealii_petsc_matrix_type || + std::constructible_from< + PMatrixType, + Mat>)&&(concepts::is_dealii_petsc_matrix_type || + std::constructible_from)) NonlinearSolver::NonlinearSolver( const NonlinearSolverData &data, const MPI_Comm mpi_comm) diff --cc include/deal.II/lac/petsc_ts.templates.h index c368fa436e,f8f12e2ca1..3eec293ce3 --- a/include/deal.II/lac/petsc_ts.templates.h +++ b/include/deal.II/lac/petsc_ts.templates.h @@@ -38,52 -38,28 +38,59 @@@ DEAL_II_NAMESPACE_OPE } \ while (0) -// Shorthand notation for User error codes. -# define AssertUser(code, name) \ - do \ - { \ - int ierr = (code); \ - AssertThrow(ierr == 0, \ - StandardExceptions::ExcFunctionNonzeroReturn(name, ierr)); \ - } \ - while (0) - namespace PETScWrappers { + namespace + { + /** + * A function that calls the function object given by its first argument + * with the set of arguments following at the end. If the call returns + * regularly, the current function returns zero to indicate success. If + * the call fails with an exception, then the current function returns with + * an error code of -1. In that case, the exception thrown by `f` is + * captured and `eptr` is set to the exception. In case of success, + * `eptr` is set to `nullptr`. + */ + template + int + call_and_possibly_capture_exception(const F & f, + std::exception_ptr &eptr, + Args &&...args) + { + // See whether there is already something in the exception pointer + // variable. There is no reason why this should be so, and + // we should probably bail out: + AssertThrow(eptr == nullptr, ExcInternalError()); + + // Call the function and if that succeeds, return zero: + try + { + f(std::forward(args)...); + eptr = nullptr; + return 0; + } + // In case of an exception, capture the exception and + // return -1: + catch (...) + { + eptr = std::current_exception(); + return -1; + } + } + } // namespace + + + template - DEAL_II_CXX20_REQUIRES((concepts::is_dealii_petsc_vector_type || - std::constructible_from)) + DEAL_II_CXX20_REQUIRES( + (concepts::is_dealii_petsc_vector_type || + std::constructible_from< + VectorType, + Vec>)&&(concepts::is_dealii_petsc_matrix_type || + std::constructible_from< + PMatrixType, + Mat>)&&(concepts::is_dealii_petsc_matrix_type || + std::constructible_from)) TimeStepper::TimeStepper( const TimeStepperData &data, const MPI_Comm mpi_comm)