IFPACK Development
Ifpack.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., 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 #include "Ifpack_ConfigDefs.h"
00031 #include "Ifpack.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_CommandLineProcessor.hpp"
00058 #include "Teuchos_StringToIntMap.hpp"
00059 #include "Epetra_CrsMatrix.h"
00060 
00061 
00062 namespace {
00063 
00064 const Teuchos::StringToIntMap
00065 precTypeNameToIntMap(
00066   "parameter \"Prec Type\"", Ifpack::numPrecTypes, Ifpack::precTypeNames
00067   );
00068 
00069 } // namespace
00070 
00071 //==============================================================================
00072 const Ifpack::EPrecType Ifpack::precTypeValues[Ifpack::numPrecTypes] =
00073 {
00074   POINT_RELAXATION
00075   ,POINT_RELAXATION_STAND_ALONE
00076   ,BLOCK_RELAXATION
00077   ,BLOCK_RELAXATION_STAND_ALONE
00078   ,BLOCK_RELAXATION_STAND_ALONE_ILU
00079 #ifdef HAVE_IFPACK_AMESOS
00080   ,BLOCK_RELAXATION_STAND_ALONE_AMESOS
00081   ,BLOCK_RELAXATION_AMESOS
00082   ,AMESOS
00083   ,AMESOS_STAND_ALONE
00084 #endif // HAVE_IFPACK_AMESOS
00085   ,IC
00086   ,IC_STAND_ALONE
00087   ,ICT
00088   ,ICT_STAND_ALONE
00089   ,ILU
00090   ,ILU_STAND_ALONE
00091   ,ILUT
00092   ,ILUT_STAND_ALONE
00093 #ifdef HAVE_IFPACK_SPARSKIT
00094   ,SPARSKIT
00095 #endif // HAVE_IFPACK_SPARSKIT
00096 #ifdef HAVE_IFPACK_HIPS
00097   ,HIPS
00098 #endif
00099 #ifdef HAVE_HYPRE
00100   ,HYPRE
00101 #endif
00102 #ifdef HAVE_IFPACK_SUPERLU
00103   ,SILU
00104 #endif
00105   ,CHEBYSHEV
00106   ,IHSS
00107   ,SORA
00108 };
00109 
00110 //==============================================================================
00111 const char* Ifpack::precTypeNames[Ifpack::numPrecTypes] =
00112 {
00113   "point relaxation"
00114   ,"point relaxation stand-alone"
00115   ,"block relaxation"
00116   ,"block relaxation stand-alone"
00117   ,"block relaxation stand-alone (ILU)"
00118 #ifdef HAVE_IFPACK_AMESOS
00119   ,"block relaxation stand-alone (Amesos)"
00120   ,"block relaxation (Amesos)"
00121   ,"Amesos"
00122   ,"Amesos stand-alone"
00123 #endif
00124   ,"IC"
00125   ,"IC stand-alone"
00126   ,"ICT"
00127   ,"ICT stand-alone"
00128   ,"ILU"
00129   ,"ILU stand-alone"
00130   ,"ILUT"
00131   ,"ILUT stand-alone"
00132 #ifdef HAVE_IFPACK_SPARSKIT
00133   ,"SPARSKIT"
00134 #endif
00135 #ifdef HAVE_IFPACK_HIPS
00136   ,"HIPS"
00137 #endif
00138 #ifdef HAVE_HYPRE
00139   ,"Hypre"
00140 #endif
00141 #ifdef HAVE_IFPACK_SUPERLU
00142   ,"SILU"
00143 #endif
00144   ,"Chebyshev"
00145   ,"IHSS"
00146   ,"SORa"
00147 };
00148 
00149 //==============================================================================
00150 const bool Ifpack::supportsUnsymmetric[Ifpack::numPrecTypes] =
00151 {
00152   true // point relaxation
00153   ,true // point relaxation stand-alone
00154   ,true // block relaxation
00155   ,true // block relaxation stand-alone
00156   ,true // block relaxation stand-alone (ILU)
00157 #ifdef HAVE_IFPACK_AMESOS
00158   ,true // block relaxation stand-alone (Amesos)
00159   ,true // block relaxation (Amesos)
00160   ,true // Amesos
00161   ,true // Amesos stand-alone 
00162 #endif
00163   ,false // IC
00164   ,false // IC stand-alone
00165   ,false // ICT
00166   ,false // ICT stand-alone
00167   ,true // ILU
00168   ,true // ILU stand-alone
00169   ,true // ILUT
00170   ,true // ILUT stand-alone
00171 #ifdef HAVE_IFPACK_SPARSKIT
00172   ,true // SPARSKIT
00173 #endif
00174 #ifdef HAVE_IFPACK_HIPS
00175   ,true // HIPS
00176 #endif  
00177 #ifdef HAVE_HYPRE
00178   ,true
00179 #endif
00180 #ifdef HAVE_IFPACK_SUPERLU
00181   ,true // SuperLU's Supernodal ILUTP
00182 #endif
00183   ,false // CHEBYSHEV
00184   ,true  // IHSS
00185   ,true  // SORa
00186 };
00187 
00188 //==============================================================================
00189 Ifpack_Preconditioner* Ifpack::Create(EPrecType PrecType,
00190                                       Epetra_RowMatrix* Matrix,
00191                                       const int Overlap)
00192 {
00193   switch(PrecType) {
00194     case POINT_RELAXATION:
00195       return(new Ifpack_AdditiveSchwarz<Ifpack_PointRelaxation>(Matrix, Overlap));
00196     case POINT_RELAXATION_STAND_ALONE:
00197       return(new Ifpack_PointRelaxation(Matrix));
00198     case BLOCK_RELAXATION:
00199       return(new Ifpack_AdditiveSchwarz<
00200              Ifpack_BlockRelaxation<Ifpack_DenseContainer> >(Matrix,Overlap));
00201     case BLOCK_RELAXATION_STAND_ALONE:
00202       return(new Ifpack_BlockRelaxation<Ifpack_DenseContainer>(Matrix));
00203     case BLOCK_RELAXATION_STAND_ALONE_ILU:
00204       return(new Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_ILU> >(Matrix));
00205 #ifdef HAVE_IFPACK_AMESOS
00206     case BLOCK_RELAXATION_STAND_ALONE_AMESOS:
00207       return(new Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> >(Matrix));
00208     case BLOCK_RELAXATION_AMESOS:
00209       return(new Ifpack_AdditiveSchwarz<
00210              Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> > >(Matrix,Overlap));
00211     case AMESOS:
00212       return(new Ifpack_AdditiveSchwarz<Ifpack_Amesos>(Matrix,Overlap));
00213     case AMESOS_STAND_ALONE:
00214       return(new Ifpack_Amesos(Matrix));
00215 #endif
00216     case IC:
00217       return(new Ifpack_AdditiveSchwarz<Ifpack_IC>(Matrix,Overlap));
00218     case IC_STAND_ALONE:
00219       return(new Ifpack_IC(Matrix));
00220     case ICT:
00221       return(new Ifpack_AdditiveSchwarz<Ifpack_ICT>(Matrix,Overlap));
00222     case ICT_STAND_ALONE:
00223       return(new Ifpack_ICT(Matrix));
00224     case ILU:
00225       return(new Ifpack_AdditiveSchwarz<Ifpack_ILU>(Matrix,Overlap));
00226     case ILU_STAND_ALONE:
00227       return(new Ifpack_ILU(Matrix));
00228     case ILUT:
00229       return(new Ifpack_AdditiveSchwarz<Ifpack_ILUT>(Matrix,Overlap));
00230     case ILUT_STAND_ALONE:
00231       return(new Ifpack_ILUT(Matrix));
00232 #ifdef HAVE_IFPACK_SPARSKIT
00233     case SPARSKIT:
00234       return(new Ifpack_SPARSKIT(Matrix));
00235 #endif
00236 #ifdef HAVE_IFPACK_HIPS
00237     case HIPS:      
00238       return(new Ifpack_HIPS(Matrix));
00239 #endif      
00240 #ifdef HAVE_HYPRE
00241     case HYPRE:
00242       return(new Ifpack_Hypre(Matrix));
00243 #endif
00244 #ifdef HAVE_IFPACK_SUPERLU
00245     case SILU:
00246       return(new Ifpack_SILU(Matrix));
00247 #endif
00248     case CHEBYSHEV:
00249       return(new Ifpack_Chebyshev(Matrix));
00250 #ifdef HAVE_IFPACK_EPETRAEXT
00251     case IHSS:
00252       return(new Ifpack_IHSS(Matrix));  
00253     case SORA:
00254       return(new Ifpack_SORa(Matrix));  
00255 #endif
00256     default:
00257       TEUCHOS_TEST_FOR_EXCEPT(true);
00258       // The only way to get here is if some code developer does a cast like
00259       // (EPrecType)(anyNumber).  You can never get here by passing in a
00260       // string value for the preconditioner!
00261   } // end switch
00262   return 0; // This will never ever be executed!
00263 }
00264 
00265 //==============================================================================
00266 Ifpack_Preconditioner* Ifpack::Create(const string PrecType,
00267                                       Epetra_RowMatrix* Matrix,
00268                                       const int Overlap)
00269 {
00270   try {
00271     return Ifpack::Create(Teuchos::get<EPrecType>(::precTypeNameToIntMap,PrecType),Matrix,Overlap);
00272   }
00273   catch( const Teuchos::StringToIntMap::DoesNotExist &excpt ) {
00274     // The old implementation of this function just silently returned a NULL
00275     // when a preconditiner type name was not recognized.  If you like this
00276     // behavior then you should use this function.  If you do not like this
00277     // behavior, then consider using the Ifpack/Thyra adapter
00278     // Thyra::IfpackPreconditionerFactory or better yet the Stratimikos
00279     // wrapper class Stratimikos::DefaultLinearSolverBuilder.
00280   }
00281   return 0;
00282 }
00283 
00284 // ======================================================================
00285 int Ifpack::SetParameters(int argc, char* argv[],
00286                           Teuchos::ParameterList& List, string& PrecType,
00287                           int& Overlap)
00288 {
00289   // THIS FUNCTION IS VERY INCOMPLETE...
00290 
00291   Teuchos::CommandLineProcessor CLP;
00292 
00293   // prec type
00294   string ifp_prec_type = "ILU";
00295   CLP.setOption("ifp-prec-type",&ifp_prec_type,"Preconditioner type");
00296   // overlap among the processors
00297   int ifp_overlap = 0;
00298   CLP.setOption("ifp-overlap",&ifp_overlap,"Overlap among processors");
00299   // relaxation type
00300   string ifp_relax_type = "Jacobi";
00301   CLP.setOption("ifp-relax-type",&ifp_relax_type,"Relaxation type");
00302   // sweeps (for relax only)
00303   int ifp_relax_sweeps = 1;
00304   CLP.setOption("ifp-relax-sweeps",
00305                 &ifp_relax_sweeps,"Number of sweeps for relaxation");
00306   // damping (for relax only)
00307   double ifp_relax_damping = 1.0;
00308   CLP.setOption("ifp-relax-damping",
00309                 &ifp_relax_damping,"Damping for relaxation");
00310   // partitioner type (for block relaxation only)
00311   string ifp_part_type = "greedy";
00312   CLP.setOption("ifp-part-type",&ifp_part_type,"Partitioner type");
00313   // number of local parts (for block relaxation only)
00314   int ifp_part_local = 1;
00315   CLP.setOption("ifp-part-local",&ifp_part_local,"number of local partitions");
00316 
00317   // allow users to specify other options for other packages
00318   CLP.recogniseAllOptions(false);
00319   CLP.throwExceptions(false);
00320   CLP.parse(argc,argv);
00321 
00322   // I cannot really set those in the List, I pass them back to the user
00323   PrecType = ifp_prec_type;
00324   Overlap = ifp_overlap;
00325 
00326   // set the list here
00327   List.set("relaxation: type", ifp_relax_type);
00328   List.set("relaxation: sweeps", ifp_relax_sweeps);
00329   List.set("relaxation: damping factor", ifp_relax_damping);
00330   List.set("partitioner: type", ifp_part_type);
00331   List.set("partitioner: local parts", ifp_part_local);
00332 
00333   return(0);
00334 }
 All Classes Files Functions Variables Enumerations Friends