# include <deal.II/base/std_cxx11/shared_ptr.h>
# include <deal.II/lac/exceptions.h>
+# include <deal.II/lac/petsc_solver.h>
# include <petscksp.h>
# include <slepceps.h>
DEAL_II_NAMESPACE_OPEN
+namespace PETScWrappers
+{
+ // forward declarations
+ class SolverBase;
+}
namespace SLEPcWrappers
{
*/
class TransformationBase
{
- public:
+ protected:
/**
* Constructor.
*/
- TransformationBase ();
+ TransformationBase (const MPI_Comm &mpi_communicator);
+ public:
/**
* Destructor.
*/
virtual ~TransformationBase ();
- /**
- * Record the EPS object that is associated to the spectral transformation
- */
- void set_context (EPS &eps);
-
/**
* Set a flag to indicate how the transformed matrices are being stored in
* the spectral transformations.
*/
void set_matrix_mode(const STMatMode mode);
- protected:
-
- virtual void set_transformation_type (ST &st) const = 0;
-
- private:
-
/**
- * Objects of this type are explicitly created, but are destroyed when the
- * surrounding solver object goes out of scope, or when we assign a new
- * value to the pointer to this object. The respective Destroy functions
- * are therefore written into the destructor of this object, even though
- * the object does not have a constructor.
+ * Set solver to be used when solving a system of
+ * linear algebraic equations inside the eigensolver.
*/
- struct TransformationData
- {
+ void
+ set_solver(const PETScWrappers::SolverBase &solver);
- /**
- * Destructor.
- */
- ~TransformationData ();
-
- /**
- * Objects for Eigenvalue Problem Solver.
- */
- ST st;
- };
+ protected:
+ /**
+ * SLEPc spectral transformation object.
+ */
+ ST st;
- std_cxx11::shared_ptr<TransformationData> transformation_data;
+ /**
+ * Make the solver class a friend, since it needs to set spectral
+ * transformation object.
+ */
+ friend class SolverBase;
- std_cxx11::shared_ptr<STMatMode> mat_mode;
};
/**
/**
* Constructor.
*/
- TransformationShift (const AdditionalData &data = AdditionalData());
+ TransformationShift (const MPI_Comm &mpi_communicator,
+ const AdditionalData &data = AdditionalData());
protected:
* Store a copy of the flags for this particular solver.
*/
const AdditionalData additional_data;
-
- /**
- * Function that takes a Spectral Transformation context object, and sets
- * the type of spectral transformation that is appropriate for this class.
- */
- virtual void set_transformation_type (ST &st) const;
};
/**
/**
* Constructor.
*/
- TransformationShiftInvert (const AdditionalData &data = AdditionalData());
+ TransformationShiftInvert (const MPI_Comm &mpi_communicator,
+ const AdditionalData &data = AdditionalData());
protected:
* Store a copy of the flags for this particular solver.
*/
const AdditionalData additional_data;
-
- /**
- * Function that takes a Spectral Transformation context object, and sets
- * the type of spectral transformation that is appropriate for this class.
- */
- virtual void set_transformation_type (ST &st) const;
};
/**
/**
* Constructor.
*/
- TransformationSpectrumFolding (const AdditionalData &data = AdditionalData());
+ TransformationSpectrumFolding (const MPI_Comm &mpi_communicator,
+ const AdditionalData &data = AdditionalData());
protected:
* Store a copy of the flags for this particular solver.
*/
const AdditionalData additional_data;
-
- /**
- * Function that takes a Spectral Transformation context object, and sets
- * the type of spectral transformation that is appropriate for this class.
- */
- virtual void set_transformation_type (ST &st) const;
};
/**
/**
* Constructor.
*/
- TransformationCayley (const double shift,
- const double antishift);
+ TransformationCayley (const MPI_Comm &mpi_communicator,
+ const AdditionalData &data = AdditionalData());
protected:
* Store a copy of the flags for this particular solver.
*/
const AdditionalData additional_data;
-
- /**
- * Function that takes a Spectral Transformation context object, and sets
- * the type of spectral transformation that is appropriate for this class.
- */
- virtual void set_transformation_type (ST &st) const;
};
}
namespace SLEPcWrappers
{
- TransformationBase::TransformationData::~TransformationData ()
- {}
-
- TransformationBase::TransformationBase ()
- {}
-
- TransformationBase::~TransformationBase ()
- {}
-
- void TransformationBase::set_context (EPS &eps)
+ TransformationBase::TransformationBase (const MPI_Comm &mpi_communicator)
{
- AssertThrow (transformation_data.get() == 0,
- SolverBase::ExcSLEPcWrappersUsageError());
- transformation_data.reset (new TransformationData());
-
- int ierr = EPSGetST(eps, &transformation_data->st);
+ int ierr = STCreate(mpi_communicator, &st);
AssertThrow (ierr == 0, SolverBase::ExcSLEPcError(ierr));
+ }
- set_transformation_type(transformation_data->st);
-
- // if mat_mode has been set,
- // pass it to ST object
- if (mat_mode.get() != 0)
+ TransformationBase::~TransformationBase ()
+ {
+ if (st!=NULL)
{
- int ierr = STSetMatMode(transformation_data->st,*(mat_mode.get()) );
+ int ierr = STDestroy(&st);
AssertThrow (ierr == 0, SolverBase::ExcSLEPcError(ierr));
}
}
void TransformationBase::set_matrix_mode(const STMatMode mode)
{
- mat_mode.reset (new STMatMode(mode));
+ int ierr = STSetMatMode(st,mode);
+ AssertThrow (ierr == 0, SolverBase::ExcSLEPcError(ierr));
+ }
+
+ void TransformationBase::set_solver(const PETScWrappers::SolverBase &solver)
+ {
+ int ierr = STSetKSP(st,solver.solver_data->ksp);
+ AssertThrow (ierr == 0, SolverBase::ExcSLEPcError(ierr));
}
/* ------------------- TransformationShift --------------------- */
shift_parameter (shift_parameter)
{}
- TransformationShift::TransformationShift (const AdditionalData &data)
+ TransformationShift::TransformationShift (const MPI_Comm &mpi_communicator,
+ const AdditionalData &data)
:
+ TransformationBase(mpi_communicator),
additional_data (data)
- {}
-
- void
- TransformationShift::set_transformation_type (ST &st) const
{
int ierr;
ierr = STSetType (st, const_cast<char *>(STSHIFT));
shift_parameter (shift_parameter)
{}
- TransformationShiftInvert::TransformationShiftInvert (const AdditionalData &data)
+ TransformationShiftInvert::TransformationShiftInvert (const MPI_Comm &mpi_communicator,
+ const AdditionalData &data)
:
+ TransformationBase(mpi_communicator),
additional_data (data)
- {}
-
- void
- TransformationShiftInvert::set_transformation_type (ST &st) const
{
int ierr;
#if DEAL_II_PETSC_VERSION_LT(3,1,0)
shift_parameter (shift_parameter)
{}
- TransformationSpectrumFolding::TransformationSpectrumFolding (const AdditionalData &data)
+ TransformationSpectrumFolding::TransformationSpectrumFolding (const MPI_Comm &mpi_communicator,
+ const AdditionalData &data)
:
+ TransformationBase(mpi_communicator),
additional_data (data)
- {}
-
-
- void
- TransformationSpectrumFolding::set_transformation_type (ST &st) const
{
#if DEAL_II_PETSC_VERSION_LT(3,5,0)
int ierr;
{
}
- TransformationCayley::TransformationCayley (const double shift,
- const double antishift)
+ TransformationCayley::TransformationCayley (const MPI_Comm &mpi_communicator,
+ const AdditionalData &data)
:
- additional_data (shift, antishift)
- {}
-
- void
- TransformationCayley::set_transformation_type (ST &st) const
+ TransformationBase(mpi_communicator),
+ additional_data (data)
{
int ierr = STSetType (st, const_cast<char *>(STCAYLEY));
AssertThrow (ierr == 0, SolverBase::ExcSLEPcError(ierr));