From: Martin Steigemann Date: Fri, 26 Oct 2012 16:10:53 +0000 (+0000) Subject: Interface to PETSc::PreconditionNone and ParaSails Preconditioner from the Hypre... X-Git-Tag: v8.0.0~1924 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=085eb7a49b55de7e0a016f569fbb23e129452b75;p=dealii.git Interface to PETSc::PreconditionNone and ParaSails Preconditioner from the Hypre Suite git-svn-id: https://svn.dealii.org/trunk@27207 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/source/lac/petsc_precondition.cc b/deal.II/source/lac/petsc_precondition.cc index 2df82399d2..c6b468c013 100644 --- a/deal.II/source/lac/petsc_precondition.cc +++ b/deal.II/source/lac/petsc_precondition.cc @@ -483,6 +483,150 @@ namespace PETScWrappers } +/* ----------------- PreconditionParaSails -------------------- */ + + PreconditionParaSails::AdditionalData:: + AdditionalData(const unsigned int symmetric, + const unsigned int n_levels, + const double threshold, + const double filter, + const bool output_details) + : + symmetric(symmetric), + n_levels(n_levels), + threshold(threshold), + filter(filter), + output_details(output_details) + {} + + + PreconditionParaSails::PreconditionParaSails () + {} + + + PreconditionParaSails::PreconditionParaSails (const MatrixBase &matrix, + const AdditionalData &additional_data) + { + initialize(matrix, additional_data); + } + + + void + PreconditionParaSails::initialize (const MatrixBase &matrix_, + const AdditionalData &additional_data_) + { + matrix = static_cast(matrix_); + additional_data = additional_data_; + +#ifdef PETSC_HAVE_HYPRE + create_pc(); + + int ierr; + ierr = PCSetType (pc, const_cast(PCHYPRE)); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + ierr = PCHYPRESetType(pc, "parasails"); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + if (additional_data.output_details) + PetscOptionsSetValue("-pc_hypre_parasails_logging","1"); + + Assert ((additional_data.symmetric == 0 || + additional_data.symmetric == 1 || + additional_data.symmetric == 2), + ExcMessage("ParaSails parameter symmetric can only be equal to 0, 1, 2!")); + + std::stringstream ssStream; + + switch (additional_data.symmetric) + { + case 0: + { + ssStream << "nonsymmetric"; + break; + } + + case 1: + { + ssStream << "SPD"; + break; + } + + case 2: + { + ssStream << "nonsymmetric,SPD"; + break; + } + + default: + Assert (false, + ExcMessage("ParaSails parameter symmetric can only be equal to 0, 1, 2!")); + }; + + PetscOptionsSetValue("-pc_hypre_parasails_sym",ssStream.str().c_str()); + + PetscOptionsSetValue("-pc_hypre_parasails_nlevels", + Utilities::int_to_string( + additional_data.n_levels + ).c_str()); + + ssStream.str(""); // empty the stringstream + ssStream << additional_data.threshold; + PetscOptionsSetValue("-pc_hypre_parasails_thresh", ssStream.str().c_str()); + + ssStream.str(""); // empty the stringstream + ssStream << additional_data.filter; + PetscOptionsSetValue("-pc_hypre_parasails_filter", ssStream.str().c_str()); + + ierr = PCSetFromOptions (pc); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + ierr = PCSetUp (pc); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + +#else // PETSC_HAVE_HYPRE + (void)pc; + Assert (false, + ExcMessage ("Your PETSc installation does not include a copy of " + "the hypre package necessary for this preconditioner.")); +#endif + } + + +/* ----------------- PreconditionNone ------------------------- */ + + PreconditionNone::PreconditionNone () + {} + + + PreconditionNone::PreconditionNone (const MatrixBase &matrix, + const AdditionalData &additional_data) + { + initialize (matrix, additional_data); + } + + + void + PreconditionNone::initialize (const MatrixBase &matrix_, + const AdditionalData &additional_data_) + { + matrix = static_cast(matrix_); + additional_data = additional_data_; + + create_pc(); + + int ierr; + ierr = PCSetType (pc, const_cast(PCNONE)); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + ierr = PCSetFromOptions (pc); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + ierr = PCSetUp (pc); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + } + + /* ----------------- PreconditionLU -------------------- */ PreconditionLU::AdditionalData::