# include <petscksp.h>
+#ifdef DEAL_II_WITH_SLEPC
+#include <deal.II/lac/slepc_spectral_transformation.h>
+#endif
+
DEAL_II_NAMESPACE_OPEN
+#ifdef DEAL_II_WITH_SLEPC
+namespace SLEPcWrappers
+{
+ // forward declarations
+ class TransformationBase;
+}
+#endif
namespace PETScWrappers
{
*/
SolverControl &control() const;
+ /**
+ * Initialise the solver with the preconditioner.
+ * This function is intended for use with SLEPc spectral transformation class.
+ */
+ void initialise(const PreconditionerBase &preconditioner);
+
/**
* Exception
*/
~SolverData ();
/**
- * Objects for Krylov subspace solvers and preconditioners.
+ * Object for Krylov subspace solvers.
*/
KSP ksp;
- PC pc;
};
/**
* in the main solver routine if necessary.
*/
std_cxx11::shared_ptr<SolverData> solver_data;
+
+ /**
+ * Make the transformation class a friend, since it needs to set the solver.
+ */
+ friend SLEPcWrappers::TransformationBase;
};
SolverBase::SolverData::~SolverData ()
{
- // destroy the solver object
+ if (ksp != NULL)
+ {
+ // destroy the solver object
#if DEAL_II_PETSC_VERSION_LT(3,2,0)
- int ierr = KSPDestroy (ksp);
+ int ierr = KSPDestroy (ksp);
#else
- int ierr = KSPDestroy (&ksp);
+ int ierr = KSPDestroy (&ksp);
#endif
- AssertThrow (ierr == 0, ExcPETScError(ierr));
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+ }
}
return 0;
}
+ void
+ SolverBase::initialise(const PreconditionerBase &preconditioner)
+ {
+ int ierr;
+
+ solver_data.reset (new SolverData());
+
+ ierr = KSPCreate (mpi_communicator, &solver_data->ksp);
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+ // let derived classes set the solver
+ // type, and the preconditioning
+ // object set the type of
+ // preconditioner
+ set_solver_type (solver_data->ksp);
+
+ ierr = KSPSetPC (solver_data->ksp, preconditioner.get_pc());
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+ // then a convergence monitor
+ // function. that function simply
+ // checks with the solver_control
+ // object we have in this object for
+ // convergence
+ KSPSetConvergenceTest (solver_data->ksp, &convergence_test,
+ reinterpret_cast<void *>(&solver_control),
+ PETSC_NULL);
+
+ // set the command line options provided
+ // by the user to override the defaults
+ ierr = KSPSetFromOptions (solver_data->ksp);
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+ }
+
/* ---------------------- SolverRichardson ------------------------ */