Skip to content
Snippets Groups Projects
Commit 3a6c2bf0 authored by wenqing's avatar wenqing
Browse files

added a member for quiting program

parent 87529fce
No related branches found
No related tags found
No related merge requests found
......@@ -60,7 +60,7 @@ bool PETScLinearSolver::solve(const PETScVector &b, PETScVector &x)
PetscPrintf(PETSC_COMM_WORLD, "\nLinear solver %s with %s preconditioner",
ksp_type, pc_type);
int its;
PetscInt its;
KSPGetIterationNumber(_solver, &its);
PetscPrintf(PETSC_COMM_WORLD,"\nConvergence in %d iterations.\n", its);
PetscPrintf(PETSC_COMM_WORLD,"\n================================================\n");
......@@ -68,10 +68,10 @@ bool PETScLinearSolver::solve(const PETScVector &b, PETScVector &x)
else if(reason == KSP_DIVERGED_ITS)
{
PetscPrintf(PETSC_COMM_WORLD, "\nWarning: maximum number of iterations reached.\n");
converged = false;
}
else
{
converged = false;
if(reason == KSP_DIVERGED_INDEFINITE_PC)
{
PetscPrintf(PETSC_COMM_WORLD, "\nDivergence because of indefinite preconditioner,");
......@@ -82,7 +82,6 @@ bool PETScLinearSolver::solve(const PETScVector &b, PETScVector &x)
PetscPrintf(PETSC_COMM_WORLD, "\nKSPBICG method was detected so the method could not continue to enlarge the Krylov space.");
PetscPrintf(PETSC_COMM_WORLD, "\nTry to run again with another solver.\n");
}
else if(reason == KSP_DIVERGED_NONSYMMETRIC)
{
PetscPrintf(PETSC_COMM_WORLD, "\nMatrix or preconditioner is unsymmetric but KSP requires symmetric.\n");
......@@ -91,11 +90,6 @@ bool PETScLinearSolver::solve(const PETScVector &b, PETScVector &x)
{
PetscPrintf(PETSC_COMM_WORLD, "\nDivergence detected, use command option -ksp_monitor or -log_summary to check the details.\n");
}
PetscPrintf(PETSC_COMM_WORLD, "\nLinear solver (PETSc KSP) failed, quit now.\n");
KSPDestroy(&_solver);
PetscFinalize();
std::exit(EXIT_FAILURE);
}
#ifdef TEST_MEM_PETSC
......
......@@ -52,18 +52,13 @@ class PETScLinearSolver
/*!
Solve a system of equations.
\param b The right hand of the equations.
\param b The right hand side of the equations.
\param x The solutions to be solved.
\return true: converged, false: diverged due to exceeding
the maximum iterations.
\return true: converged, false: diverged.
*/
bool solve(const PETScVector &b, PETScVector &x);
/*!
\brief Get number of iterations.
If function solve(...) returns false, the return value is
exactly the maximum iterations.
*/
/// Get number of iterations.
PetscInt getNumberOfIterations() const
{
PetscInt its = 0;
......@@ -71,6 +66,19 @@ class PETScLinearSolver
return its;
}
/*!
\brief Function used to prepare quiting of program
Release memory and conclude the program before exit.
It must be called before exit() being called after solver fails
to converge.
*/
void Finalize()
{
PetscPrintf(PETSC_COMM_WORLD, "\nLinear solver (PETSc KSP) failed, quit now.\n");
KSPDestroy(&_solver);
PetscFinalize();
}
private:
/// Matrix, kept as a member only for solving successive linear equation
/// that preconditioner matrix may vary.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment