From 43b822d8532efc2524dbabe9941e0b5be79f651e Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Sat, 12 Dec 2015 21:00:08 +0100 Subject: [PATCH] rework SLEPc spectral transformation (i) create unerlying SLEPc object in constructor; require MPI_Comm. (ii) add a function to set PETSc solver --- .../lac/slepc_spectral_transformation.h | 92 +++++++------------ source/lac/slepc_spectral_transformation.cc | 73 ++++++--------- 2 files changed, 59 insertions(+), 106 deletions(-) diff --git a/include/deal.II/lac/slepc_spectral_transformation.h b/include/deal.II/lac/slepc_spectral_transformation.h index 94bc5aaeea..8ebd735841 100644 --- a/include/deal.II/lac/slepc_spectral_transformation.h +++ b/include/deal.II/lac/slepc_spectral_transformation.h @@ -24,12 +24,18 @@ # include # include +# include # include # include DEAL_II_NAMESPACE_OPEN +namespace PETScWrappers +{ + // forward declarations + class SolverBase; +} namespace SLEPcWrappers { @@ -62,23 +68,19 @@ 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. @@ -89,36 +91,25 @@ namespace SLEPcWrappers */ 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 transformation_data; + /** + * Make the solver class a friend, since it needs to set spectral + * transformation object. + */ + friend class SolverBase; - std_cxx11::shared_ptr mat_mode; }; /** @@ -152,7 +143,8 @@ namespace SLEPcWrappers /** * Constructor. */ - TransformationShift (const AdditionalData &data = AdditionalData()); + TransformationShift (const MPI_Comm &mpi_communicator, + const AdditionalData &data = AdditionalData()); protected: @@ -161,12 +153,6 @@ namespace SLEPcWrappers * 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; }; /** @@ -200,7 +186,8 @@ namespace SLEPcWrappers /** * Constructor. */ - TransformationShiftInvert (const AdditionalData &data = AdditionalData()); + TransformationShiftInvert (const MPI_Comm &mpi_communicator, + const AdditionalData &data = AdditionalData()); protected: @@ -208,12 +195,6 @@ namespace SLEPcWrappers * 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; }; /** @@ -248,7 +229,8 @@ namespace SLEPcWrappers /** * Constructor. */ - TransformationSpectrumFolding (const AdditionalData &data = AdditionalData()); + TransformationSpectrumFolding (const MPI_Comm &mpi_communicator, + const AdditionalData &data = AdditionalData()); protected: @@ -256,12 +238,6 @@ namespace SLEPcWrappers * 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; }; /** @@ -296,8 +272,8 @@ namespace SLEPcWrappers /** * Constructor. */ - TransformationCayley (const double shift, - const double antishift); + TransformationCayley (const MPI_Comm &mpi_communicator, + const AdditionalData &data = AdditionalData()); protected: @@ -305,12 +281,6 @@ namespace SLEPcWrappers * 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; }; } diff --git a/source/lac/slepc_spectral_transformation.cc b/source/lac/slepc_spectral_transformation.cc index c8489bb1a2..6e9805a002 100644 --- a/source/lac/slepc_spectral_transformation.cc +++ b/source/lac/slepc_spectral_transformation.cc @@ -31,38 +31,31 @@ DEAL_II_NAMESPACE_OPEN 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 --------------------- */ @@ -73,13 +66,11 @@ namespace SLEPcWrappers 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(STSHIFT)); @@ -97,13 +88,11 @@ namespace SLEPcWrappers 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) @@ -125,14 +114,11 @@ namespace SLEPcWrappers 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; @@ -163,14 +149,11 @@ namespace SLEPcWrappers { } - 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(STCAYLEY)); AssertThrow (ierr == 0, SolverBase::ExcSLEPcError(ierr)); -- 2.39.5