Ifpack2 Templated Preconditioning Package Version 1.0
Ifpack2_Factory.hpp
00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2009) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 */
00029 
00030 #ifndef IFPACK2_FACTORY_HPP
00031 #define IFPACK2_FACTORY_HPP
00032 
00033 #include "Ifpack2_ConfigDefs.hpp"
00034 #include "Ifpack2_Preconditioner.hpp"
00035 #include "Ifpack2_Relaxation.hpp"
00036 #include "Ifpack2_Diagonal.hpp"
00037 #include "Ifpack2_Chebyshev.hpp"
00038 #include "Ifpack2_RILUK.hpp"
00039 #include "Ifpack2_ILUT.hpp"
00040 #include "Ifpack2_Krylov.hpp"
00041 
00043 namespace Ifpack2 {
00044 
00047 bool supportsUnsymmetric(const std::string& prec_type);
00048 
00050 
00103 class Factory {
00104 public:
00105 
00120   template<class MatrixType>
00121   static
00122   Teuchos::RCP<Ifpack2::Preconditioner<typename MatrixType::scalar_type,
00123                                        typename MatrixType::local_ordinal_type,
00124                                        typename MatrixType::global_ordinal_type,
00125                                        typename MatrixType::node_type> >
00126   create(const std::string& prec_type,
00127          const Teuchos::RCP<const MatrixType>& matrix,
00128          const int overlap = 0);
00129 };
00130 
00133 
00134 template<class MatrixType>
00135 Teuchos::RCP<Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> >
00136 Factory::create(const std::string& prec_type,
00137                 const Teuchos::RCP<const MatrixType>& matrix,
00138                 const int overlap)
00139 {
00140   typedef typename MatrixType::scalar_type Scalar;
00141   typedef typename MatrixType::local_ordinal_type LocalOrdinal;
00142   typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
00143   typedef typename MatrixType::node_type Node;
00144   (void)overlap;
00145   Teuchos::RCP<Ifpack2::Preconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node> > prec;
00146 
00147   if (prec_type == "ILUT") {
00148     prec = Teuchos::rcp(new Ifpack2::ILUT<MatrixType>(matrix));
00149   }
00150   else if (prec_type == "RILUK") {
00151     prec = Teuchos::rcp(new Ifpack2::RILUK<MatrixType>(matrix));
00152   }
00153   else if (prec_type == "RELAXATION") {
00154     prec = Teuchos::rcp(new Ifpack2::Relaxation<MatrixType>(matrix));
00155   }
00156   else if (prec_type == "CHEBYSHEV") {
00157     prec = Teuchos::rcp(new Ifpack2::Chebyshev<MatrixType>(matrix));
00158   }
00159   else if (prec_type == "DIAGONAL") {
00160     prec = Teuchos::rcp(new Ifpack2::Diagonal<MatrixType>(matrix));
00161   }
00162   else if (prec_type == "KRYLOV") {
00163     prec = Teuchos::rcp(new Ifpack2::Krylov< MatrixType,Ifpack2::ILUT<MatrixType> >(matrix));
00164   }
00165   else {
00166     std::ostringstream os;
00167     os << "Ifpack2::Factory::Create ERROR, invalid preconditioner type ("
00168        << prec_type << ")";
00169     std::string str = os.str();
00170     throw std::runtime_error(str);
00171   }
00172   return prec;
00173 }
00174 
00175 } //namespace Ifpack2
00176 
00177 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends