Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
AztecOOParameterList.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Stratimikos: Thyra-based strategies for linear solvers
00005 //                Copyright (2006) 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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include "AztecOOParameterList.hpp"
00043 #include "Teuchos_StandardParameterEntryValidators.hpp"
00044 #include "Teuchos_ValidatorXMLConverterDB.hpp"
00045 #include "Teuchos_StandardValidatorXMLConverters.hpp"
00046 
00047 namespace {
00048 
00049 //
00050 // Define the names of the different parameters.  Since the name of a
00051 // parameter is used several times, it is a good idea to define a variable that
00052 // stores the std::string name so that typing errors get caught at compile-time.
00053 //
00054 
00055 const std::string AztecSolver_name = "Aztec Solver";
00056 
00057 const std::string AztecPreconditioner_name = "Aztec Preconditioner";
00058 
00059 enum EAztecPreconditioner {
00060   AZTEC_PREC_NONE, AZTEC_PREC_ILU, AZTEC_PREC_ILUT, AZTEC_PREC_JACOBI,
00061   AZTEC_PREC_SYMMGS, AZTEC_PREC_POLY, AZTEC_PREC_LSPOLY
00062 };
00063 
00065 inline std::istream& operator>>(std::istream& is, EAztecPreconditioner& prec){
00066   int intval;
00067   is >> intval;
00068   prec = (EAztecPreconditioner)intval;
00069   return is;
00070 }
00071   
00072 
00073 const std::string Overlap_name = "Overlap";
00074 
00075 const std::string GraphFill_name = "Graph Fill";
00076 
00077 const std::string DropTolerance_name = "Drop Tolerance";
00078 
00079 const std::string FillFactor_name = "Fill Factor";
00080 
00081 const std::string Steps_name = "Steps";
00082 
00083 const std::string PolynomialOrder_name = "Polynomial Order";
00084 
00085 const std::string RCMReordering_name = "RCM Reordering";
00086 
00087 const std::string Orthogonalization_name = "Orthogonalization";
00088 
00089 const std::string SizeOfKrylovSubspace_name = "Size of Krylov Subspace";
00090 
00091 const std::string ConvergenceTest_name = "Convergence Test";
00092 
00093 const std::string IllConditioningThreshold_name = "Ill-Conditioning Threshold";
00094 
00095 const std::string OutputFrequency_name = "Output Frequency";
00096 
00097 Teuchos::RCP<Teuchos::ParameterList>  validAztecOOParams;
00098 
00099 } // namespace
00100 
00101 void setAztecOOParameters(
00102   Teuchos::ParameterList  *pl
00103   ,AztecOO                *solver
00104   )
00105 {
00106   using Teuchos::getIntegralValue;
00107   using Teuchos::getParameter;
00108   TEUCHOS_TEST_FOR_EXCEPT(pl==NULL);
00109   TEUCHOS_TEST_FOR_EXCEPT(solver==NULL);
00110   // Validate the parameters and set their defaults!  This also sets the
00111   // validators needed to read in the parameters in an integral form.
00112   pl->validateParametersAndSetDefaults(*getValidAztecOOParameters());
00113   // Aztec Solver
00114   solver->SetAztecOption(
00115     AZ_solver
00116     ,getIntegralValue<int>(*pl,AztecSolver_name)
00117     );
00118   // Aztec Preconditioner
00119   switch(
00120     getIntegralValue<EAztecPreconditioner>(
00121       *pl,AztecPreconditioner_name
00122       )
00123     )
00124   {
00125     case AZTEC_PREC_NONE:
00126       solver->SetAztecOption(AZ_precond,AZ_none);
00127       break;
00128     case AZTEC_PREC_ILU:
00129       solver->SetAztecOption(AZ_precond,AZ_dom_decomp);
00130       solver->SetAztecOption(AZ_overlap,getParameter<int>(*pl,Overlap_name));
00131       solver->SetAztecOption(AZ_subdomain_solve,AZ_ilu);
00132       solver->SetAztecOption(AZ_graph_fill,getParameter<int>(*pl,GraphFill_name));
00133       break;
00134     case AZTEC_PREC_ILUT:
00135       solver->SetAztecOption(AZ_precond,AZ_dom_decomp);
00136       solver->SetAztecOption(AZ_overlap,getParameter<int>(*pl,Overlap_name));
00137       solver->SetAztecOption(AZ_subdomain_solve,AZ_ilut);
00138       solver->SetAztecParam(AZ_drop,getParameter<double>(*pl,DropTolerance_name));
00139       solver->SetAztecParam(AZ_ilut_fill,getParameter<double>(*pl,FillFactor_name));
00140       break;
00141     case AZTEC_PREC_JACOBI:
00142       solver->SetAztecOption(AZ_precond,AZ_Jacobi);
00143       solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,Steps_name));
00144       break;
00145     case AZTEC_PREC_SYMMGS:
00146       solver->SetAztecOption(AZ_precond,AZ_sym_GS);
00147       solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,Steps_name));
00148       break;
00149     case AZTEC_PREC_POLY:
00150       solver->SetAztecOption(AZ_precond,AZ_Neumann);
00151       solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,PolynomialOrder_name));
00152       break;
00153     case AZTEC_PREC_LSPOLY:
00154       solver->SetAztecOption(AZ_precond,AZ_ls);
00155       solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,PolynomialOrder_name));
00156       break;
00157     default:
00158       TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
00159   }
00160   // RCM Reordering (in conjunction with domain decomp preconditioning)
00161   solver->SetAztecOption(
00162     AZ_reorder
00163     ,getIntegralValue<int>(*pl,RCMReordering_name)
00164     );
00165   // Gram-Schmidt orthogonalization procedure (GMRES only)
00166   solver->SetAztecOption(
00167     AZ_orthog
00168     ,getIntegralValue<int>(*pl,Orthogonalization_name)
00169     );
00170   // Size of the krylov subspace
00171   solver->SetAztecOption(AZ_kspace,getParameter<int>(*pl,SizeOfKrylovSubspace_name));
00172   // Convergence criteria to use in the linear solver
00173   solver->SetAztecOption(
00174     AZ_conv
00175     ,getIntegralValue<int>(*pl,ConvergenceTest_name)
00176     );
00177   // Set the ill-conditioning threshold for the upper hessenberg matrix
00178   solver->SetAztecParam(
00179     AZ_ill_cond_thresh, getParameter<double>(*pl,IllConditioningThreshold_name)
00180     );
00181   // Frequency of linear solve residual output
00182   solver->SetAztecOption(
00183     AZ_output, getParameter<int>(*pl,OutputFrequency_name)
00184     );
00185 #ifdef TEUCHOS_DEBUG
00186   // Check to make sure that I did not use the PL incorrectly!
00187   pl->validateParameters(*getValidAztecOOParameters());
00188 #endif // TEUCHOS_DEBUG
00189 }
00190 
00191 Teuchos::RCP<const Teuchos::ParameterList>
00192 getValidAztecOOParameters()
00193 {
00194   //
00195   // This function defines the valid parameter list complete with validators
00196   // and default values.  The default values never need to be repeated because
00197   // if the use of the function validateParametersAndSetDefaults(...) used
00198   // above in setAztecOOParameters(...).  Also, the validators do not need to
00199   // be kept track of since they will be set in the input list also.
00200   //
00201   using Teuchos::RCP;
00202   using Teuchos::rcp;
00203   using Teuchos::tuple;
00204   using Teuchos::setStringToIntegralParameter;
00205   using Teuchos::setIntParameter;
00206   using Teuchos::setDoubleParameter;
00207   using Teuchos::ParameterList;
00214   Teuchos::ValidatorXMLConverterDB::addConverter(
00215     Teuchos::DummyObjectGetter<
00216       Teuchos::StringToIntegralParameterEntryValidator<EAztecPreconditioner> 
00217     >::getDummyObject(),
00218     Teuchos::DummyObjectGetter<Teuchos::StringToIntegralValidatorXMLConverter<
00219       EAztecPreconditioner> >::getDummyObject());
00220   //
00221   RCP<ParameterList> pl = validAztecOOParams;
00222   if(pl.get()) return pl;
00223   pl = validAztecOOParams = rcp(new ParameterList());
00224   //
00225   setStringToIntegralParameter<int>(
00226     AztecSolver_name, "GMRES",
00227     "Type of linear solver algorithm to use.",
00228     tuple<std::string>("CG","GMRES","CGS","TFQMR","BiCGStab","LU","GMRESR","FixedPoint"),
00229     tuple<int>(AZ_cg,AZ_gmres,AZ_cgs,AZ_tfqmr,AZ_bicgstab,AZ_lu,AZ_GMRESR,AZ_fixed_pt),
00230     &*pl
00231     );
00232   setStringToIntegralParameter<EAztecPreconditioner>(
00233     AztecPreconditioner_name, "ilu",
00234     "Type of internal preconditioner to use.\n"
00235     "Note! this preconditioner will only be used if the input operator\n"
00236     "supports the Epetra_RowMatrix interface and the client does not pass\n"
00237     "in an external preconditioner!",
00238     tuple<std::string>(
00239       "none","ilu","ilut","Jacobi",
00240       "Symmetric Gauss-Seidel","Polynomial","Least-squares Polynomial"
00241       ),
00242     tuple<EAztecPreconditioner>(
00243       AZTEC_PREC_NONE,AZTEC_PREC_ILU,AZTEC_PREC_ILUT,AZTEC_PREC_JACOBI,
00244       AZTEC_PREC_SYMMGS,AZTEC_PREC_POLY,AZTEC_PREC_LSPOLY
00245       ),
00246     &*pl
00247     );
00248   setIntParameter(
00249     Overlap_name, 0,
00250     "The amount of overlap used for the internal \"ilu\" and \"ilut\" preconditioners.",
00251     &*pl
00252     );
00253   setIntParameter(
00254     GraphFill_name, 0,
00255     "The amount of fill allowed for the internal \"ilu\" preconditioner.",
00256     &*pl
00257     );
00258   setDoubleParameter(
00259     DropTolerance_name, 0.0,
00260     "The tolerance below which an entry from the factors of an internal \"ilut\"\n"
00261     "preconditioner will be dropped.",
00262     &*pl
00263     );
00264   setDoubleParameter(
00265     FillFactor_name, 1.0,
00266     "The amount of fill allowed for an internal \"ilut\" preconditioner.",
00267     &*pl
00268     );
00269   setIntParameter(
00270     Steps_name, 3,
00271     "Number of steps taken for the \"Jacobi\" or the \"Symmetric Gauss-Seidel\"\n"
00272     "internal preconditioners for each preconditioner application.",
00273     &*pl
00274     );
00275   setIntParameter(
00276     PolynomialOrder_name, 3,
00277     "The order for of the polynomials used for the \"Polynomial\" and\n"
00278     "\"Least-squares Polynomial\" internal preconditioners.",
00279     &*pl
00280     );
00281   setStringToIntegralParameter<int>(
00282     RCMReordering_name, "Disabled",
00283     "Determines if RCM reordering is used with the internal\n"
00284     "\"ilu\" or \"ilut\" preconditioners.",
00285     tuple<std::string>("Enabled","Disabled"),
00286     tuple<int>(1,0),
00287     &*pl
00288     );
00289   setStringToIntegralParameter<int>(
00290     Orthogonalization_name, "Classical",
00291     "The type of orthogonalization to use with the \"GMRES\" solver.",
00292     tuple<std::string>("Classical","Modified"),
00293     tuple<int>(AZ_classic,AZ_modified),
00294     &*pl
00295     );
00296   setIntParameter(
00297     SizeOfKrylovSubspace_name, 300,
00298     "The maximum size of the Krylov subspace used with \"GMRES\" before\n"
00299     "a restart is performed.",
00300     &*pl
00301     );
00302   setStringToIntegralParameter<int>(
00303     ConvergenceTest_name, "r0", // Same as "rhs" when x=0
00304     "The convergence test to use for terminating the iterative solver.",
00305     tuple<std::string>("r0","rhs","Anorm","no scaling","sol"),
00306     tuple<int>(AZ_r0,AZ_rhs,AZ_Anorm,AZ_noscaled,AZ_sol),
00307     &*pl
00308     );
00309   setDoubleParameter(
00310     IllConditioningThreshold_name, 1e+11,
00311     "The threshold tolerance above which a system is considered\n"
00312     "ill conditioned.",
00313     &*pl
00314     );
00315   setIntParameter(
00316     OutputFrequency_name, 0, // By default, no output from Aztec!
00317     "The number of iterations between each output of the solver's progress.",
00318     &*pl
00319     );
00320   //
00321   return pl;
00322 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines