IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
Ifpack_DynamicFactory.cpp
00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 */
00029 
00030 #include "Ifpack_ConfigDefs.h"
00031 #include "Ifpack_DynamicFactory.h"
00032 #include "Ifpack_Preconditioner.h"
00033 #include "Ifpack_PointRelaxation.h"
00034 #include "Ifpack_BlockRelaxation.h"
00035 #include "Ifpack_IC.h"
00036 #include "Ifpack_ICT.h"
00037 #include "Ifpack_ILU.h"
00038 #include "Ifpack_ILUT.h"
00039 #include "Ifpack_SPARSKIT.h"
00040 #include "Ifpack_AdditiveSchwarz.h"
00041 #include "Ifpack_DenseContainer.h"
00042 #include "Ifpack_SparseContainer.h"
00043 #ifdef HAVE_IFPACK_AMESOS
00044 #include "Ifpack_Amesos.h"
00045 #endif
00046 #ifdef HAVE_IFPACK_HIPS
00047 #include "Ifpack_HIPS.h"
00048 #endif
00049 #ifdef HAVE_IFPACK_SUPERLU
00050 #include "Ifpack_SILU.h"
00051 #endif
00052 
00053 #include "Ifpack_Chebyshev.h"
00054 #include "Ifpack_IHSS.h"
00055 #include "Ifpack_SORa.h"
00056 
00057 #include "Teuchos_StringToIntMap.hpp"
00058 #include "Epetra_CrsMatrix.h"
00059 
00060 std::map<std::string, Ifpack_DynamicFactory::builderFunction>
00061     Ifpack_DynamicFactory::PreconditionerMap_;
00062 bool Ifpack_DynamicFactory::Initialized_ = false;
00063 int Ifpack_DynamicFactory::NumPreconditioners_ = 0;
00064 
00065 bool Ifpack_DynamicFactory::Initialize()
00066 {
00067     if (! Initialized_) {
00068         PreconditionerMap_["point relaxation"]
00069               = &buildPreconditioner<Ifpack_PointRelaxation, false>;
00070         PreconditionerMap_["point relaxation stand-alone"]
00071               = &buildPreconditioner<Ifpack_PointRelaxation, true>;
00072         PreconditionerMap_["block relaxation"]
00073               = &buildPreconditioner<Ifpack_BlockRelaxation<Ifpack_DenseContainer>, false>;
00074         PreconditionerMap_["block relaxation stand-alone"]
00075               = &buildPreconditioner<Ifpack_BlockRelaxation<Ifpack_DenseContainer>, true>;
00076         PreconditionerMap_["block relaxation stand-alone (ILU)"]
00077               = &buildPreconditioner<Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_ILU> >, true>;
00078 
00079 #ifdef HAVE_IFPACK_AMESOS
00080         PreconditionerMap_["block relaxation stand-alone (Amesos)"]
00081               = &buildPreconditioner<Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> >, true>;
00082         PreconditionerMap_["block relaxation (Amesos)"]
00083               = &buildPreconditioner<Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> >, false>;
00084         PreconditionerMap_["Amesos"]
00085               = &buildPreconditioner<Ifpack_Amesos, false>;
00086         PreconditionerMap_["Amesos stand-alone"]
00087               = &buildPreconditioner<Ifpack_Amesos, true>;
00088 #endif // HAVE_IFPACK_AMESOS
00089 
00090         PreconditionerMap_["IC"] = &buildPreconditioner<Ifpack_IC, false>;
00091         PreconditionerMap_["IC stand-alone"] = &buildPreconditioner<Ifpack_IC, true>;
00092         PreconditionerMap_["ICT"] = &buildPreconditioner<Ifpack_ICT, false>;
00093         PreconditionerMap_["ICT stand-alone"] = &buildPreconditioner<Ifpack_ICT, true>;
00094         PreconditionerMap_["ILU"] = &buildPreconditioner<Ifpack_ILU, false>;
00095         PreconditionerMap_["ILU stand-alone"] = &buildPreconditioner<Ifpack_ILU, true>;
00096         PreconditionerMap_["ILUT"] = &buildPreconditioner<Ifpack_ILUT, false>;
00097         PreconditionerMap_["ILUT stand-alone"] = &buildPreconditioner<Ifpack_ILUT, true>;
00098 
00099 #ifdef HAVE_IFPACK_SPARSKIT
00100         PreconditionerMap_["SPARSKIT"]
00101               = &buildPreconditioner<Ifpack_SPARSKIT, true>;
00102 #endif
00103 
00104 #ifdef HAVE_IFPACK_HIPS
00105         PreconditionerMap_["HIPS"]
00106               = &buildPreconditioner<Ifpack_HIPS, true>;
00107 #endif
00108 
00109 #ifdef HAVE_HYPRE
00110         PreconditionerMap_["Hypre"]
00111               = &buildPreconditioner<Ifpack_Hypre, true>;
00112 #endif
00113 
00114 #ifdef HAVE_IFPACK_SUPERLU
00115         PreconditionerMap_["SILU"]
00116               = &buildPreconditioner<Ifpack_SILU, true>;
00117 #endif
00118 
00119         PreconditionerMap_["Chebyshev"]
00120               = &buildPreconditioner<Ifpack_Chebyshev, true>;
00121 
00122 #ifdef HAVE_IFPACK_EPETRAEXT
00123         PreconditionerMap_["IHSS"]
00124               = &buildPreconditioner<Ifpack_IHSS, true>;
00125         PreconditionerMap_["SORa"]
00126               = &buildPreconditioner<Ifpack_SORa, true>;
00127 #endif
00128 
00129         NumPreconditioners_ =
00130                 +5
00131         #ifdef HAVE_IFPACK_AMESOS
00132                 +4
00133         #endif
00134                 +8
00135         #ifdef HAVE_IFPACK_SPARSKIT
00136                 +1
00137         #endif
00138         #ifdef HAVE_IFPACK_HIPS
00139                 +1
00140         #endif
00141         #ifdef HAVE_HYPRE
00142                 +1
00143         #endif
00144         #ifdef HAVE_IFPACK_SUPERLU
00145                 +1
00146         #endif
00147                 +1
00148         #ifdef HAVE_IFPACK_EPETRAEXT
00149                 +2
00150         #endif
00151                 ;
00152 
00153         Initialized_ = true;
00154     }
00155 
00156     return true;
00157 }
00158 
00159 int Ifpack_DynamicFactory::RegisterPreconditioner(
00160         const std::string PrecName,
00161         Ifpack_DynamicFactory::builderFunction PrecBuilder)
00162 {
00163     if (PreconditionerMap_.find(PrecName) == PreconditionerMap_.end()) {
00164         PreconditionerMap_[PrecName] = PrecBuilder;
00165         NumPreconditioners_++;
00166         return 0;
00167     }
00168     return 1;
00169 }
00170 
00171 void Ifpack_DynamicFactory::Print(std::ostream& os)
00172 {
00173     os << "Ifpack_DynamicFactory registered preconditioners: " << std::endl;
00174     for (std::map<std::string, builderFunction>::const_iterator it = PreconditionerMap_.begin();
00175          it != PreconditionerMap_.end(); ++it) {
00176         os << it->first << std::endl;
00177     }
00178 }
00179 
00180 //==============================================================================
00181 Ifpack_Preconditioner* Ifpack_DynamicFactory::Create(const string PrecType,
00182                                       Epetra_RowMatrix* Matrix,
00183                                       const int Overlap,
00184                                       bool overrideSerialDefault)
00185 {
00186   bool serial = (Matrix->Comm().NumProc() == 1);
00187 
00188   std::map<std::string, builderFunction>::const_iterator it
00189         = PreconditionerMap_.find(PrecType);
00190   bool found = it != PreconditionerMap_.end();
00191   if (found) {
00192     builderFunction f = it->second;
00193     return f(Matrix, Overlap, serial, overrideSerialDefault);
00194   }
00195 
00196   return 0;
00197 }
00198 
00199 // Let's initialize the factory upon compilation
00200 namespace {
00201   bool init = Ifpack_DynamicFactory::Initialize();
00202 }
00203 
 All Classes Files Functions Variables Enumerations Friends