10 #ifndef THYRA_BELOS_TPETRA_PRECONDITIONERFACTORY_DEF_HPP 
   11 #define THYRA_BELOS_TPETRA_PRECONDITIONERFACTORY_DEF_HPP 
   13 #include "Thyra_BelosTpetraPreconditionerFactory_decl.hpp" 
   15 #include "Thyra_DefaultPreconditioner.hpp" 
   16 #include "Thyra_TpetraLinearOp.hpp" 
   17 #include "Thyra_TpetraThyraWrappers.hpp" 
   19 #include "BelosTpetraOperator.hpp" 
   22 #include "BelosTpetraAdapter.hpp" 
   26 #include "Teuchos_TestForException.hpp" 
   27 #include "Teuchos_Assert.hpp" 
   28 #include "Teuchos_Time.hpp" 
   29 #include "Teuchos_FancyOStream.hpp" 
   30 #include "Teuchos_VerbosityLevel.hpp" 
   31 #include "Teuchos_VerboseObjectParameterListHelpers.hpp" 
   40 #if (!defined(HAVE_TPETRA_INST_DOUBLE) || (defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT))) && \ 
   41     (!defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) || (defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) && defined(HAVE_TPETRA_INST_COMPLEX_FLOAT))) 
   42 # define THYRA_BELOS_PREC_ENABLE_HALF_PRECISION 
   50 template <
typename MatrixType>
 
   58 template <
typename MatrixType>
 
   63   typedef typename MatrixType::local_ordinal_type local_ordinal_type;
 
   64   typedef typename MatrixType::global_ordinal_type global_ordinal_type;
 
   65   typedef typename MatrixType::node_type node_type;
 
   69   const auto tpetraFwdOp =  TpetraExtractHelper::getConstTpetraOperator(fwdOp);
 
   77 template <
typename MatrixType>
 
   85 template <
typename MatrixType>
 
  101   Teuchos::Time totalTimer(
"Stratimikos::BelosTpetraPreconditionerFactory");
 
  102   totalTimer.
start(
true);
 
  108     *out << 
"\nEntering Thyra::BelosTpetraPreconditionerFactory::initializePrec(...) ...\n";
 
  116   typedef typename MatrixType::local_ordinal_type local_ordinal_type;
 
  117   typedef typename MatrixType::global_ordinal_type global_ordinal_type;
 
  118   typedef typename MatrixType::node_type node_type;
 
  122   const auto tpetraFwdOp =  TpetraExtractHelper::getConstTpetraOperator(fwdOp);
 
  127   typedef Belos::TpetraOperator<scalar_type, local_ordinal_type, global_ordinal_type, node_type> BelosTpOp;
 
  130 #ifdef THYRA_BELOS_PREC_ENABLE_HALF_PRECISION 
  137   typedef Belos::TpetraOperator<half_scalar_type, local_ordinal_type, global_ordinal_type, node_type> BelosTpOpHalf;
 
  149   if (paramList_.is_null ()) {
 
  153     innerParamList = paramList_;
 
  156   bool useHalfPrecision = 
false;
 
  158     useHalfPrecision = Teuchos::getParameter<bool>(*innerParamList, 
"half precision");
 
  160   const std::string solverType = Teuchos::getParameter<std::string>(*innerParamList, 
"BelosPrec Solver Type");
 
  164   std::string solverTypeUpper (solverType);
 
  165   std::transform(solverTypeUpper.begin(), solverTypeUpper.end(),solverTypeUpper.begin(), ::toupper);
 
  169     *out << 
"\nCreating a new BelosTpetra::Preconditioner object...\n";
 
  173   if (useHalfPrecision) {
 
  174 #ifdef THYRA_BELOS_PREC_ENABLE_HALF_PRECISION 
  176       Teuchos::OSTab(out).o() << 
"> Creating half precision preconditioner\n";
 
  178     const RCP<const MatrixType> tpetraFwdMatrix = Teuchos::rcp_dynamic_cast<
const MatrixType>(tpetraFwdOp);
 
  180     auto tpetraFwdMatrixHalf = tpetraFwdMatrix->template convert<half_scalar_type>();
 
  183     belosLinProbHalf->setOperator(tpetraFwdMatrixHalf);
 
  184     RCP<TpetraLinOpHalf> belosOpRCPHalf = 
rcp(
new BelosTpOpHalf(belosLinProbHalf, packageParamList, solverType, 
true));
 
  194     belosLinProb->setOperator(tpetraFwdOp);
 
  195     RCP<TpetraLinOp> belosOpRCP = 
rcp(
new BelosTpOp(belosLinProb, packageParamList, solverType, 
true));
 
  198   defaultPrec->initializeUnspecified(thyraPrecOp);
 
  202     *out << 
"\nTotal time in Thyra::BelosTpetraPreconditionerFactory::initializePrec(...) = " << totalTimer.
totalElapsedTime() << 
" sec\n";
 
  206     *out << 
"\nLeaving Thyra::BelosTpetraPreconditionerFactory::initializePrec(...) ...\n";
 
  211 template <
typename MatrixType>
 
  230     *fwdOp = Teuchos::null;
 
  233   if (supportSolveUse) {
 
  238   defaultPrec->uninitialize();
 
  245 template <
typename MatrixType>
 
  252   const auto validParamList = this->getValidParameters();
 
  256   paramList_ = paramList;
 
  257   Teuchos::readVerboseObjectSublist(paramList_.getRawPtr(), 
this);
 
  261 template <
typename MatrixType>
 
  269 template <
typename MatrixType>
 
  274   paramList_ = Teuchos::null;
 
  275   return savedParamList;
 
  279 template <
typename MatrixType>
 
  286 template <
typename MatrixType>
 
  295       "BelosPrec Solver Type", 
"GMRES",
 
  296       "Name of Belos solver to be used as a preconditioner. (Use valid names for Belos::SolverFactory.)" 
  299       "half precision", 
false,
 
  300       "Whether a half-of-standard-precision Belos-solver-as-preconditioner should be built." 
  303       "BelosPrec Solver Params", 
false,
 
  304       "Belos solver settings that are passed onto the Belos solver itself." 
  306     Teuchos::setupVerboseObjectSublist(validParamList.
getRawPtr());
 
  309   return validParamList;
 
  315 template <
typename MatrixType>
 
  318   return "Thyra::BelosTpetraPreconditionerFactory";
 
  324 #endif // THYRA_BELOS_TPETRA_PRECONDITIONERFACTORY_DEF_HPP 
std::string description() const 
void uninitializePrec(PreconditionerBase< scalar_type > *prec, Teuchos::RCP< const LinearOpSourceBase< scalar_type > > *fwdOp, ESupportSolveUse *supportSolveUse) const 
basic_OSTab< char > OSTab
bool isCompatible(const LinearOpSourceBase< scalar_type > &fwdOp) const 
bool nonnull(const std::shared_ptr< T > &p)
bool is_null(const std::shared_ptr< T > &p)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void initializePrec(const Teuchos::RCP< const LinearOpSourceBase< scalar_type > > &fwdOp, PreconditionerBase< scalar_type > *prec, const ESupportSolveUse supportSolveUse) const 
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool isParameter(const std::string &name) const 
void start(bool reset=false)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const 
TEUCHOSCORE_LIB_DLL_EXPORT bool includesVerbLevel(const EVerbosityLevel verbLevel, const EVerbosityLevel requestedVerbLevel, const bool isDefaultLevel=false)
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const 
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const 
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
double totalElapsedTime(bool readCurrentTime=false) const 
Teuchos::RCP< PreconditionerBase< scalar_type > > createPrec() const 
BelosTpetraPreconditionerFactory()
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
RCP< LinearOpBase< Scalar > > createLinearOp(const RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraOperator, const RCP< const VectorSpaceBase< Scalar > > rangeSpace=Teuchos::null, const RCP< const VectorSpaceBase< Scalar > > domainSpace=Teuchos::null)
#define TEUCHOS_ASSERT(assertion_test)
virtual Teuchos::RCP< const LinearOpBase< Scalar > > getOp() const =0
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()