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 
00042 namespace Ifpack2 {
00043 
00046 bool supportsUnsymmetric(const std::string& prec_type);
00047 
00049 
00101 class Factory {
00102 public:
00103 
00118   template<class MatrixType>
00119   static
00120   Teuchos::RCP<Ifpack2::Preconditioner<typename MatrixType::scalar_type,
00121                                        typename MatrixType::local_ordinal_type,
00122                                        typename MatrixType::global_ordinal_type,
00123                                        typename MatrixType::node_type> >
00124   create(const std::string& prec_type,
00125          const Teuchos::RCP<const MatrixType>& matrix,
00126          const int overlap = 0);
00127 };
00128 
00131 
00132 template<class MatrixType>
00133 Teuchos::RCP<Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> >
00134 Factory::create(const std::string& prec_type,
00135                 const Teuchos::RCP<const MatrixType>& matrix,
00136                 const int overlap)
00137 {
00138   typedef typename MatrixType::scalar_type Scalar;
00139   typedef typename MatrixType::local_ordinal_type LocalOrdinal;
00140   typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
00141   typedef typename MatrixType::node_type Node;
00142   (void)overlap;
00143   Teuchos::RCP<Ifpack2::Preconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node> > prec;
00144 
00145   if (prec_type == "ILUT") {
00146     prec = Teuchos::rcp(new Ifpack2::ILUT<MatrixType>(matrix));
00147   }
00148   else if (prec_type == "RILUK") {
00149     prec = Teuchos::rcp(new Ifpack2::RILUK<MatrixType>(matrix));
00150   }
00151   else if (prec_type == "RELAXATION") {
00152     prec = Teuchos::rcp(new Ifpack2::Relaxation<MatrixType>(matrix));
00153   }
00154   else if (prec_type == "CHEBYSHEV") {
00155     prec = Teuchos::rcp(new Ifpack2::Chebyshev<MatrixType>(matrix));
00156   }
00157   else if (prec_type == "DIAGONAL") {
00158     prec = Teuchos::rcp(new Ifpack2::Diagonal<MatrixType>(matrix));
00159   }
00160   else {
00161     std::ostringstream os;
00162     os << "Ifpack2::Factory::Create ERROR, invalid preconditioner type ("
00163        << prec_type << ")";
00164     std::string str = os.str();
00165     throw std::runtime_error(str);
00166   }
00167   return prec;
00168 }
00169 
00170 } //namespace Ifpack2
00171 
00172 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends