Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AztecOOParameterList.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stratimikos: Thyra-based strategies for linear solvers
4 //
5 // Copyright 2006 NTESS and the Stratimikos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "AztecOOParameterList.hpp"
14 
15 namespace {
16 
17 //
18 // Define the names of the different parameters. Since the name of a
19 // parameter is used several times, it is a good idea to define a variable that
20 // stores the std::string name so that typing errors get caught at compile-time.
21 //
22 
23 const std::string AztecSolver_name = "Aztec Solver";
24 
25 const std::string AztecPreconditioner_name = "Aztec Preconditioner";
26 
28  AZTEC_PREC_NONE, AZTEC_PREC_ILU, AZTEC_PREC_ILUT, AZTEC_PREC_JACOBI,
29  AZTEC_PREC_SYMMGS, AZTEC_PREC_POLY, AZTEC_PREC_LSPOLY
30 };
31 
33 inline std::istream& operator>>(std::istream& is, EAztecPreconditioner& prec){
34  int intval;
35  is >> intval;
36  prec = (EAztecPreconditioner)intval;
37  return is;
38 }
39 
40 const std::string Overlap_name = "Overlap";
41 
42 const std::string GraphFill_name = "Graph Fill";
43 
44 const std::string DropTolerance_name = "Drop Tolerance";
45 
46 const std::string FillFactor_name = "Fill Factor";
47 
48 const std::string Steps_name = "Steps";
49 
50 const std::string PolynomialOrder_name = "Polynomial Order";
51 
52 const std::string RCMReordering_name = "RCM Reordering";
53 
54 const std::string Orthogonalization_name = "Orthogonalization";
55 
56 const std::string SizeOfKrylovSubspace_name = "Size of Krylov Subspace";
57 
58 const std::string ConvergenceTest_name = "Convergence Test";
59 
60 const std::string IllConditioningThreshold_name = "Ill-Conditioning Threshold";
61 
62 const std::string OutputFrequency_name = "Output Frequency";
63 
64 Teuchos::RCP<Teuchos::ParameterList> validAztecOOParams;
65 
66 } // namespace
67 
70  ,AztecOO *solver
71  )
72 {
73  using Teuchos::getIntegralValue;
74  using Teuchos::getParameter;
75  TEUCHOS_TEST_FOR_EXCEPT(pl==NULL);
76  TEUCHOS_TEST_FOR_EXCEPT(solver==NULL);
77  // Validate the parameters and set their defaults! This also sets the
78  // validators needed to read in the parameters in an integral form.
80  // Aztec Solver
81  solver->SetAztecOption(
82  AZ_solver
83  ,getIntegralValue<int>(*pl,AztecSolver_name)
84  );
85  // Aztec Preconditioner
86  switch(
87  getIntegralValue<EAztecPreconditioner>(
88  *pl,AztecPreconditioner_name
89  )
90  )
91  {
92  // This is the only place that EAztecPreconditioner is used. Everywhere
93  // else the code expects a string value.
94  case AZTEC_PREC_NONE:
95  solver->SetAztecOption(AZ_precond,AZ_none);
96  pl->set(AztecPreconditioner_name, "none");
97  break;
98  case AZTEC_PREC_ILU:
99  solver->SetAztecOption(AZ_precond,AZ_dom_decomp);
100  solver->SetAztecOption(AZ_overlap,getParameter<int>(*pl,Overlap_name));
101  solver->SetAztecOption(AZ_subdomain_solve,AZ_ilu);
102  solver->SetAztecOption(AZ_graph_fill,getParameter<int>(*pl,GraphFill_name));
103  pl->set(AztecPreconditioner_name, "ilu");
104  break;
105  case AZTEC_PREC_ILUT:
106  solver->SetAztecOption(AZ_precond,AZ_dom_decomp);
107  solver->SetAztecOption(AZ_overlap,getParameter<int>(*pl,Overlap_name));
108  solver->SetAztecOption(AZ_subdomain_solve,AZ_ilut);
109  solver->SetAztecParam(AZ_drop,getParameter<double>(*pl,DropTolerance_name));
110  solver->SetAztecParam(AZ_ilut_fill,getParameter<double>(*pl,FillFactor_name));
111  pl->set(AztecPreconditioner_name, "ilut");
112  break;
113  case AZTEC_PREC_JACOBI:
114  solver->SetAztecOption(AZ_precond,AZ_Jacobi);
115  solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,Steps_name));
116  pl->set(AztecPreconditioner_name, "Jacobi");
117  break;
118  case AZTEC_PREC_SYMMGS:
119  solver->SetAztecOption(AZ_precond,AZ_sym_GS);
120  solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,Steps_name));
121  pl->set(AztecPreconditioner_name, "Symmetric Gauss-Seidel");
122  break;
123  case AZTEC_PREC_POLY:
124  solver->SetAztecOption(AZ_precond,AZ_Neumann);
125  solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,PolynomialOrder_name));
126  pl->set(AztecPreconditioner_name, "Polynomial");
127  break;
128  case AZTEC_PREC_LSPOLY:
129  solver->SetAztecOption(AZ_precond,AZ_ls);
130  solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,PolynomialOrder_name));
131  pl->set(AztecPreconditioner_name, "Least-squares Polynomial");
132  break;
133  default:
134  TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
135  }
136  // RCM Reordering (in conjunction with domain decomp preconditioning)
137  solver->SetAztecOption(
138  AZ_reorder
139  ,getIntegralValue<int>(*pl,RCMReordering_name)
140  );
141  // Gram-Schmidt orthogonalization procedure (GMRES only)
142  solver->SetAztecOption(
143  AZ_orthog
144  ,getIntegralValue<int>(*pl,Orthogonalization_name)
145  );
146  // Size of the krylov subspace
147  solver->SetAztecOption(AZ_kspace,getParameter<int>(*pl,SizeOfKrylovSubspace_name));
148  // Convergence criteria to use in the linear solver
149  solver->SetAztecOption(
150  AZ_conv
151  ,getIntegralValue<int>(*pl,ConvergenceTest_name)
152  );
153  // Set the ill-conditioning threshold for the upper hessenberg matrix
154  solver->SetAztecParam(
155  AZ_ill_cond_thresh, getParameter<double>(*pl,IllConditioningThreshold_name)
156  );
157  // Frequency of linear solve residual output
158  solver->SetAztecOption(
159  AZ_output, getParameter<int>(*pl,OutputFrequency_name)
160  );
161 #ifdef TEUCHOS_DEBUG
162  // Check to make sure that I did not use the PL incorrectly!
164 #endif // TEUCHOS_DEBUG
165 }
166 
169 {
170  //
171  // This function defines the valid parameter list complete with validators
172  // and default values. The default values never need to be repeated because
173  // if the use of the function validateParametersAndSetDefaults(...) used
174  // above in setAztecOOParameters(...). Also, the validators do not need to
175  // be kept track of since they will be set in the input list also.
176  //
177  using Teuchos::RCP;
178  using Teuchos::rcp;
179  using Teuchos::tuple;
180  using Teuchos::setStringToIntegralParameter;
181  using Teuchos::setIntParameter;
182  using Teuchos::setDoubleParameter;
193  >::getDummyObject(),
195  EAztecPreconditioner> >::getDummyObject());
196  //
197  RCP<ParameterList> pl = validAztecOOParams;
198  if(pl.get()) return pl;
199  pl = validAztecOOParams = rcp(new ParameterList());
200  //
201  setStringToIntegralParameter<int>(
202  AztecSolver_name, "GMRES",
203  "Type of linear solver algorithm to use.",
204  tuple<std::string>("CG","GMRES","CGS","TFQMR","BiCGStab","LU","GMRESR","FixedPoint"),
205  tuple<int>(AZ_cg,AZ_gmres,AZ_cgs,AZ_tfqmr,AZ_bicgstab,AZ_lu,AZ_GMRESR,AZ_fixed_pt),
206  &*pl
207  );
208  setStringToIntegralParameter<EAztecPreconditioner>(
209  AztecPreconditioner_name, "ilu",
210  "Type of internal preconditioner to use.\n"
211  "Note! this preconditioner will only be used if the input operator\n"
212  "supports the Epetra_RowMatrix interface and the client does not pass\n"
213  "in an external preconditioner!",
214  tuple<std::string>(
215  "none","ilu","ilut","Jacobi",
216  "Symmetric Gauss-Seidel","Polynomial","Least-squares Polynomial"
217  ),
218  tuple<EAztecPreconditioner>(
219  AZTEC_PREC_NONE,AZTEC_PREC_ILU,AZTEC_PREC_ILUT,AZTEC_PREC_JACOBI,
220  AZTEC_PREC_SYMMGS,AZTEC_PREC_POLY,AZTEC_PREC_LSPOLY
221  ),
222  &*pl
223  );
224  setIntParameter(
225  Overlap_name, 0,
226  "The amount of overlap used for the internal \"ilu\" and \"ilut\" preconditioners.",
227  &*pl
228  );
229  setIntParameter(
230  GraphFill_name, 0,
231  "The amount of fill allowed for the internal \"ilu\" preconditioner.",
232  &*pl
233  );
234  setDoubleParameter(
235  DropTolerance_name, 0.0,
236  "The tolerance below which an entry from the factors of an internal \"ilut\"\n"
237  "preconditioner will be dropped.",
238  &*pl
239  );
240  setDoubleParameter(
241  FillFactor_name, 1.0,
242  "The amount of fill allowed for an internal \"ilut\" preconditioner.",
243  &*pl
244  );
245  setIntParameter(
246  Steps_name, 3,
247  "Number of steps taken for the \"Jacobi\" or the \"Symmetric Gauss-Seidel\"\n"
248  "internal preconditioners for each preconditioner application.",
249  &*pl
250  );
251  setIntParameter(
252  PolynomialOrder_name, 3,
253  "The order for of the polynomials used for the \"Polynomial\" and\n"
254  "\"Least-squares Polynomial\" internal preconditioners.",
255  &*pl
256  );
257  setStringToIntegralParameter<int>(
258  RCMReordering_name, "Disabled",
259  "Determines if RCM reordering is used with the internal\n"
260  "\"ilu\" or \"ilut\" preconditioners.",
261  tuple<std::string>("Enabled","Disabled"),
262  tuple<int>(1,0),
263  &*pl
264  );
265  setStringToIntegralParameter<int>(
266  Orthogonalization_name, "Classical",
267  "The type of orthogonalization to use with the \"GMRES\" solver.",
268  tuple<std::string>("Classical","Modified"),
269  tuple<int>(AZ_classic,AZ_modified),
270  &*pl
271  );
272  setIntParameter(
273  SizeOfKrylovSubspace_name, 300,
274  "The maximum size of the Krylov subspace used with \"GMRES\" before\n"
275  "a restart is performed.",
276  &*pl
277  );
278  setStringToIntegralParameter<int>(
279  ConvergenceTest_name, "r0", // Same as "rhs" when x=0
280  "The convergence test to use for terminating the iterative solver.",
281  tuple<std::string>("r0","rhs","Anorm","no scaling","sol"),
282  tuple<int>(AZ_r0,AZ_rhs,AZ_Anorm,AZ_noscaled,AZ_sol),
283  &*pl
284  );
285  setDoubleParameter(
286  IllConditioningThreshold_name, 1e+11,
287  "The threshold tolerance above which a system is considered\n"
288  "ill conditioned.",
289  &*pl
290  );
291  setIntParameter(
292  OutputFrequency_name, 0, // By default, no output from Aztec!
293  "The number of iterations between each output of the solver's progress.",
294  &*pl
295  );
296  //
297  return pl;
298 }
void setAztecOOParameters(Teuchos::ParameterList *pl, AztecOO *solver)
Setup an AztecOO solver object with a set of parameters.
static void addConverter(RCP< const ParameterEntryValidator > validator, RCP< ValidatorXMLConverter > converterToAdd)
EAztecPreconditioner
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
std::istringstream & operator>>(std::istringstream &in, TwoDArray< T > &array)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Teuchos::RCP< const Teuchos::ParameterList > getValidAztecOOParameters()
Return the list of all valid AztecOO parameters (to validate against).
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)