]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Merge pull request #15267 from bangerth/requires
authorDavid Wells <drwells@email.unc.edu>
Tue, 30 May 2023 18:37:13 +0000 (14:37 -0400)
committerGitHub <noreply@github.com>
Tue, 30 May 2023 18:37:13 +0000 (14:37 -0400)
Add 'requires' clauses for matrix template arguments to PETSc TS and SNES solvers.

1  2 
include/deal.II/lac/petsc_snes.h
include/deal.II/lac/petsc_snes.templates.h
include/deal.II/lac/petsc_ts.h
include/deal.II/lac/petsc_ts.templates.h

Simple merge
index 16b9b647ac93d4ba2104da885c97f09499b36e4a,e03cf66ef82938768f512f5ca7694db8e9441783..eaa262e44f4debe1f486325a45a53cab5deacc15
@@@ -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 <typename F, typename... Args>
 +    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>(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 <typename VectorType, typename PMatrixType, typename AMatrixType>
-   DEAL_II_CXX20_REQUIRES((concepts::is_dealii_petsc_vector_type<VectorType> ||
-                           std::constructible_from<VectorType, Vec>))
+   DEAL_II_CXX20_REQUIRES(
+     (concepts::is_dealii_petsc_vector_type<VectorType> ||
+      std::constructible_from<
+        VectorType,
+        Vec>)&&(concepts::is_dealii_petsc_matrix_type<PMatrixType> ||
+                std::constructible_from<
+                  PMatrixType,
+                  Mat>)&&(concepts::is_dealii_petsc_matrix_type<AMatrixType> ||
+                          std::constructible_from<AMatrixType, Mat>))
    NonlinearSolver<VectorType, PMatrixType, AMatrixType>::NonlinearSolver(
      const NonlinearSolverData &data,
      const MPI_Comm             mpi_comm)
Simple merge
index c368fa436e4f176f7c07d912bfd25a661250a91a,f8f12e2ca1a4d406658e0791404d8002df9333d4..3eec293ce33f634ff4948bc5c1c164471cb18767
@@@ -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 <typename F, typename... Args>
 +    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>(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 <typename VectorType, typename PMatrixType, typename AMatrixType>
-   DEAL_II_CXX20_REQUIRES((concepts::is_dealii_petsc_vector_type<VectorType> ||
-                           std::constructible_from<VectorType, Vec>))
+   DEAL_II_CXX20_REQUIRES(
+     (concepts::is_dealii_petsc_vector_type<VectorType> ||
+      std::constructible_from<
+        VectorType,
+        Vec>)&&(concepts::is_dealii_petsc_matrix_type<PMatrixType> ||
+                std::constructible_from<
+                  PMatrixType,
+                  Mat>)&&(concepts::is_dealii_petsc_matrix_type<AMatrixType> ||
+                          std::constructible_from<AMatrixType, Mat>))
    TimeStepper<VectorType, PMatrixType, AMatrixType>::TimeStepper(
      const TimeStepperData &data,
      const MPI_Comm         mpi_comm)

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.