Stratimikos Package Browser (Single Doxygen Collection) Version of the Day
AztecOOParameterList.cpp
Go to the documentation of this file.
00001 /*@HEADER
00002 // ***********************************************************************
00003 // 
00004 //        AztecOO: An Object-Oriented Aztec Linear Solver 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 "AztecOOParameterList.hpp"
00031 #include "Teuchos_StandardParameterEntryValidators.hpp"
00032 #include "Teuchos_ValidatorXMLConverterDB.hpp"
00033 #include "Teuchos_StandardValidatorXMLConverters.hpp"
00034 
00035 namespace {
00036 
00037 //
00038 // Define the names of the different parameters.  Since the name of a
00039 // parameter is used several times, it is a good idea to define a varible that
00040 // stores the string name so that typing errors get caught at compile-time.
00041 //
00042 
00043 const std::string AztecSolver_name = "Aztec Solver";
00044 
00045 const std::string AztecPreconditioner_name = "Aztec Preconditioner";
00046 
00047 enum EAztecPreconditioner {
00048   AZTEC_PREC_NONE, AZTEC_PREC_ILU, AZTEC_PREC_ILUT, AZTEC_PREC_JACOBI,
00049   AZTEC_PREC_SYMMGS, AZTEC_PREC_POLY, AZTEC_PREC_LSPOLY
00050 };
00051 
00053 inline istream& operator>>(istream& is, EAztecPreconditioner& prec){
00054   int intval;
00055   is >> intval;
00056   prec = (EAztecPreconditioner)intval;
00057   return is;
00058 }
00059   
00060 
00061 const std::string Overlap_name = "Overlap";
00062 
00063 const std::string GraphFill_name = "Graph Fill";
00064 
00065 const std::string DropTolerance_name = "Drop Tolerance";
00066 
00067 const std::string FillFactor_name = "Fill Factor";
00068 
00069 const std::string Steps_name = "Steps";
00070 
00071 const std::string PolynomialOrder_name = "Polynomial Order";
00072 
00073 const std::string RCMReordering_name = "RCM Reordering";
00074 
00075 const std::string Orthogonalization_name = "Orthogonalization";
00076 
00077 const std::string SizeOfKrylovSubspace_name = "Size of Krylov Subspace";
00078 
00079 const std::string ConvergenceTest_name = "Convergence Test";
00080 
00081 const std::string IllConditioningThreshold_name = "Ill-Conditioning Threshold";
00082 
00083 const std::string OutputFrequency_name = "Output Frequency";
00084 
00085 Teuchos::RCP<Teuchos::ParameterList>  validAztecOOParams;
00086 
00087 } // namespace
00088 
00089 void setAztecOOParameters(
00090   Teuchos::ParameterList  *pl
00091   ,AztecOO                *solver
00092   )
00093 {
00094   using Teuchos::getIntegralValue;
00095   using Teuchos::getParameter;
00096   TEUCHOS_TEST_FOR_EXCEPT(pl==NULL);
00097   TEUCHOS_TEST_FOR_EXCEPT(solver==NULL);
00098   // Validate the parameters and set their defaults!  This also sets the
00099   // validators needed to read in the parameters in an integral form.
00100   pl->validateParametersAndSetDefaults(*getValidAztecOOParameters());
00101   // Aztec Solver
00102   solver->SetAztecOption(
00103     AZ_solver
00104     ,getIntegralValue<int>(*pl,AztecSolver_name)
00105     );
00106   // Aztec Preconditioner
00107   switch(
00108     getIntegralValue<EAztecPreconditioner>(
00109       *pl,AztecPreconditioner_name
00110       )
00111     )
00112   {
00113     case AZTEC_PREC_NONE:
00114       solver->SetAztecOption(AZ_precond,AZ_none);
00115       break;
00116     case AZTEC_PREC_ILU:
00117       solver->SetAztecOption(AZ_precond,AZ_dom_decomp);
00118       solver->SetAztecOption(AZ_overlap,getParameter<int>(*pl,Overlap_name));
00119       solver->SetAztecOption(AZ_subdomain_solve,AZ_ilu);
00120       solver->SetAztecOption(AZ_graph_fill,getParameter<int>(*pl,GraphFill_name));
00121       break;
00122     case AZTEC_PREC_ILUT:
00123       solver->SetAztecOption(AZ_precond,AZ_dom_decomp);
00124       solver->SetAztecOption(AZ_overlap,getParameter<int>(*pl,Overlap_name));
00125       solver->SetAztecOption(AZ_subdomain_solve,AZ_ilut);
00126       solver->SetAztecParam(AZ_drop,getParameter<double>(*pl,DropTolerance_name));
00127       solver->SetAztecParam(AZ_ilut_fill,getParameter<double>(*pl,FillFactor_name));
00128       break;
00129     case AZTEC_PREC_JACOBI:
00130       solver->SetAztecOption(AZ_precond,AZ_Jacobi);
00131       solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,Steps_name));
00132       break;
00133     case AZTEC_PREC_SYMMGS:
00134       solver->SetAztecOption(AZ_precond,AZ_sym_GS);
00135       solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,Steps_name));
00136       break;
00137     case AZTEC_PREC_POLY:
00138       solver->SetAztecOption(AZ_precond,AZ_Neumann);
00139       solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,PolynomialOrder_name));
00140       break;
00141     case AZTEC_PREC_LSPOLY:
00142       solver->SetAztecOption(AZ_precond,AZ_ls);
00143       solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,PolynomialOrder_name));
00144       break;
00145     default:
00146       TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
00147   }
00148   // RCM Reordering (in conjunction with domain decomp preconditioning)
00149   solver->SetAztecOption(
00150     AZ_reorder
00151     ,getIntegralValue<int>(*pl,RCMReordering_name)
00152     );
00153   // Gram-Schmidt orthogonalization procedure (GMRES only)
00154   solver->SetAztecOption(
00155     AZ_orthog
00156     ,getIntegralValue<int>(*pl,Orthogonalization_name)
00157     );
00158   // Size of the krylov subspace
00159   solver->SetAztecOption(AZ_kspace,getParameter<int>(*pl,SizeOfKrylovSubspace_name));
00160   // Convergence criteria to use in the linear solver
00161   solver->SetAztecOption(
00162     AZ_conv
00163     ,getIntegralValue<int>(*pl,ConvergenceTest_name)
00164     );
00165   // Set the ill-conditioning threshold for the upper hessenberg matrix
00166   solver->SetAztecParam(
00167     AZ_ill_cond_thresh, getParameter<double>(*pl,IllConditioningThreshold_name)
00168     );
00169   // Frequency of linear solve residual output
00170   solver->SetAztecOption(
00171     AZ_output, getParameter<int>(*pl,OutputFrequency_name)
00172     );
00173 #ifdef TEUCHOS_DEBUG
00174   // Check to make sure that I did not use the PL incorrectly!
00175   pl->validateParameters(*getValidAztecOOParameters());
00176 #endif // TEUCHOS_DEBUG
00177 }
00178 
00179 Teuchos::RCP<const Teuchos::ParameterList>
00180 getValidAztecOOParameters()
00181 {
00182   //
00183   // This function defines the valid parameter list complete with validators
00184   // and default values.  The default values never need to be repeated because
00185   // if the use of the function validateParametersAndSetDefaults(...) used
00186   // above in setAztecOOParameters(...).  Also, the validators do not need to
00187   // be kept track of since they will be set in the input list also.
00188   //
00189   using Teuchos::RCP;
00190   using Teuchos::rcp;
00191   using Teuchos::tuple;
00192   using Teuchos::setStringToIntegralParameter;
00193   using Teuchos::setIntParameter;
00194   using Teuchos::setDoubleParameter;
00195   using Teuchos::ParameterList;
00202   Teuchos::ValidatorXMLConverterDB::addConverter(
00203     Teuchos::DummyObjectGetter<
00204       Teuchos::StringToIntegralParameterEntryValidator<EAztecPreconditioner> 
00205     >::getDummyObject(),
00206     Teuchos::DummyObjectGetter<Teuchos::StringToIntegralValidatorXMLConverter<
00207       EAztecPreconditioner> >::getDummyObject());
00208   //
00209   RCP<ParameterList> pl = validAztecOOParams;
00210   if(pl.get()) return pl;
00211   pl = validAztecOOParams = rcp(new ParameterList());
00212   //
00213   setStringToIntegralParameter<int>(
00214     AztecSolver_name, "GMRES",
00215     "Type of linear solver algorithm to use.",
00216     tuple<std::string>("CG","GMRES","CGS","TFQMR","BiCGStab","LU","GMRESR"),
00217     tuple<int>(AZ_cg,AZ_gmres,AZ_cgs,AZ_tfqmr,AZ_bicgstab,AZ_lu,AZ_GMRESR),
00218     &*pl
00219     );
00220   setStringToIntegralParameter<EAztecPreconditioner>(
00221     AztecPreconditioner_name, "ilu",
00222     "Type of internal preconditioner to use.\n"
00223     "Note! this preconditioner will only be used if the input operator\n"
00224     "supports the Epetra_RowMatrix interface and the client does not pass\n"
00225     "in an external preconditioner!",
00226     tuple<std::string>(
00227       "none","ilu","ilut","Jacobi",
00228       "Symmetric Gauss-Seidel","Polynomial","Least-squares Polynomial"
00229       ),
00230     tuple<EAztecPreconditioner>(
00231       AZTEC_PREC_NONE,AZTEC_PREC_ILU,AZTEC_PREC_ILUT,AZTEC_PREC_JACOBI,
00232       AZTEC_PREC_SYMMGS,AZTEC_PREC_POLY,AZTEC_PREC_LSPOLY
00233       ),
00234     &*pl
00235     );
00236   setIntParameter(
00237     Overlap_name, 0,
00238     "The amount of overlap used for the internal \"ilu\" and \"ilut\" preconditioners.",
00239     &*pl
00240     );
00241   setIntParameter(
00242     GraphFill_name, 0,
00243     "The amount of fill allowed for the internal \"ilu\" preconditioner.",
00244     &*pl
00245     );
00246   setDoubleParameter(
00247     DropTolerance_name, 0.0,
00248     "The tolerance below which an entry from the factors of an internal \"ilut\"\n"
00249     "preconditioner will be dropped.",
00250     &*pl
00251     );
00252   setDoubleParameter(
00253     FillFactor_name, 1.0,
00254     "The amount of fill allowed for an internal \"ilut\" preconditioner.",
00255     &*pl
00256     );
00257   setIntParameter(
00258     Steps_name, 3,
00259     "Number of steps taken for the \"Jacobi\" or the \"Symmetric Gauss-Seidel\"\n"
00260     "internal preconditioners for each preconditioner application.",
00261     &*pl
00262     );
00263   setIntParameter(
00264     PolynomialOrder_name, 3,
00265     "The order for of the polynomials used for the \"Polynomial\" and\n"
00266     "\"Least-squares Polynomial\" internal preconditioners.",
00267     &*pl
00268     );
00269   setStringToIntegralParameter<int>(
00270     RCMReordering_name, "Disabled",
00271     "Determines if RCM reordering is used with the internal\n"
00272     "\"ilu\" or \"ilut\" preconditioners.",
00273     tuple<std::string>("Enabled","Disabled"),
00274     tuple<int>(1,0),
00275     &*pl
00276     );
00277   setStringToIntegralParameter<int>(
00278     Orthogonalization_name, "Classical",
00279     "The type of orthogonalization to use with the \"GMRES\" solver.",
00280     tuple<std::string>("Classical","Modified"),
00281     tuple<int>(AZ_classic,AZ_modified),
00282     &*pl
00283     );
00284   setIntParameter(
00285     SizeOfKrylovSubspace_name, 300,
00286     "The maximum size of the Krylov subspace used with \"GMRES\" before\n"
00287     "a restart is performed.",
00288     &*pl
00289     );
00290   setStringToIntegralParameter<int>(
00291     ConvergenceTest_name, "r0", // Same as "rhs" when x=0
00292     "The convergence test to use for terminating the iterative solver.",
00293     tuple<std::string>("r0","rhs","Anorm","no scaling","sol"),
00294     tuple<int>(AZ_r0,AZ_rhs,AZ_Anorm,AZ_noscaled,AZ_sol),
00295     &*pl
00296     );
00297   setDoubleParameter(
00298     IllConditioningThreshold_name, 1e+11,
00299     "The threshold tolerance above which a system is considered\n"
00300     "ill conditioned.",
00301     &*pl
00302     );
00303   setIntParameter(
00304     OutputFrequency_name, 0, // By default, no output from Aztec!
00305     "The number of iterations between each output of the solver's progress.",
00306     &*pl
00307     );
00308   //
00309   return pl;
00310 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines