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

Generated on Wed May 12 21:46:02 2010 for IFPACK by  doxygen 1.4.7