Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recoverable SNES and TS #15276

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/deal.II/lac/petsc_compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ namespace PETScWrappers
void
petsc_increment_state_counter(Mat A);

/**
* Resets internal domain error flags in the SNES object.
*/
void
snes_reset_domain_flags(SNES snes);

/**
* Tell PETSc nonlinear solver to use matrix free finite differencing (MFFD).
*
Expand Down Expand Up @@ -151,6 +157,13 @@ namespace PETScWrappers
*/
unsigned int
ts_get_step_number(TS ts);

/**
* Return true if the TS has a SNES object.
*/
bool
ts_has_snes(TS ts);

} // namespace PETScWrappers

DEAL_II_NAMESPACE_CLOSE
Expand Down
26 changes: 21 additions & 5 deletions include/deal.II/lac/petsc_precondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -1107,13 +1107,23 @@ namespace PETScWrappers

/**
* The callback for the application of the preconditioner.
*
* @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.
*/
std::function<int(VectorBase &dst, const VectorBase &src)> vmult;
std::function<void(VectorBase &dst, const VectorBase &src)> vmult;

/**
* The callback for the application of the transposed preconditioner.
* The callback for the transposed application of the preconditioner.
*
* @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.
*/
std::function<int(VectorBase &dst, const VectorBase &src)> vmultT;
std::function<void(VectorBase &dst, const VectorBase &src)> vmultT;

protected:
/**
Expand All @@ -1134,14 +1144,20 @@ namespace PETScWrappers
/**
* Callback-function invoked by PCApply
*/
static int
static PetscErrorCode
pcapply(PC pc, Vec src, Vec dst);

/**
* Callback-function invoked by PCApplyTranspose
*/
static int
static PetscErrorCode
pcapply_transpose(PC pc, Vec src, Vec dst);

/**
* Callback-function invoked by PCSetUp
*/
static PetscErrorCode
pcsetup(PC pc);
};

/**
Expand Down
33 changes: 9 additions & 24 deletions include/deal.II/lac/petsc_snes.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ namespace PETScWrappers
* @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. PETSc's SNES package can not deal
* with "recoverable" errors, so if a callback
* throws an exception of type RecoverableUserCallbackError, then this
* exception is treated like any other exception.
* requirements and conventions.
*/
std::function<void(const VectorType &x, VectorType &res)> residual;

Expand All @@ -383,10 +380,7 @@ namespace PETScWrappers
* @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. PETSc's SNES package can not deal
* with "recoverable" errors, so if a callback
* throws an exception of type RecoverableUserCallbackError, then this
* exception is treated like any other exception.
* requirements and conventions.
*/
std::function<void(const VectorType &x, AMatrixType &A, PMatrixType &P)>
jacobian;
Expand All @@ -401,10 +395,7 @@ namespace PETScWrappers
* @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. PETSc's SNES package can not deal
* with "recoverable" errors, so if a callback
* throws an exception of type RecoverableUserCallbackError, then this
* exception is treated like any other exception.
* requirements and conventions.
*/
std::function<void(const VectorType & x,
const unsigned int step_number,
Expand All @@ -422,10 +413,7 @@ namespace PETScWrappers
* @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. PETSc's SNES package can not deal
* with "recoverable" errors, so if a callback
* throws an exception of type RecoverableUserCallbackError, then this
* exception is treated like any other exception.
* requirements and conventions.
*/
std::function<void(const VectorType &x)> setup_jacobian;

Expand All @@ -438,10 +426,7 @@ namespace PETScWrappers
* @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. PETSc's SNES package can not deal
* with "recoverable" errors, so if a callback
* throws an exception of type RecoverableUserCallbackError, then this
* exception is treated like any other exception.
* requirements and conventions.
*/
std::function<void(const VectorType &src, VectorType &dst)>
solve_with_jacobian;
Expand All @@ -461,10 +446,7 @@ namespace PETScWrappers
* @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. PETSc's SNES package can not deal
* with "recoverable" errors, so if a callback
* throws an exception of type RecoverableUserCallbackError, then this
* exception is treated like any other exception.
* requirements and conventions.
*/
std::function<void(const VectorType &x, real_type &energy_value)> energy;

Expand All @@ -474,6 +456,9 @@ namespace PETScWrappers
*/
SNES snes;

/**
* Pointers to the internal PETSc matrix objects.
*/
SmartPointer<AMatrixType, NonlinearSolver> A;
SmartPointer<PMatrixType, NonlinearSolver> P;

Expand Down