AztecOOParameterList.cpp

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

Generated on Wed Jul 22 12:56:29 2009 for Stratimikos by  doxygen 1.5.8