Stratimikos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AztecOOParameterList.cpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stratimikos: Thyra-based strategies for linear solvers
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include "AztecOOParameterList.hpp"
43 #include "Teuchos_StandardParameterEntryValidators.hpp"
44 #include "Teuchos_ValidatorXMLConverterDB.hpp"
45 #include "Teuchos_StandardValidatorXMLConverters.hpp"
46 
47 namespace {
48 
49 //
50 // Define the names of the different parameters. Since the name of a
51 // parameter is used several times, it is a good idea to define a variable that
52 // stores the std::string name so that typing errors get caught at compile-time.
53 //
54 
55 const std::string AztecSolver_name = "Aztec Solver";
56 
57 const std::string AztecPreconditioner_name = "Aztec Preconditioner";
58 
59 enum EAztecPreconditioner {
60  AZTEC_PREC_NONE, AZTEC_PREC_ILU, AZTEC_PREC_ILUT, AZTEC_PREC_JACOBI,
61  AZTEC_PREC_SYMMGS, AZTEC_PREC_POLY, AZTEC_PREC_LSPOLY
62 };
63 
65 inline std::istream& operator>>(std::istream& is, EAztecPreconditioner& prec){
66  int intval;
67  is >> intval;
68  prec = (EAztecPreconditioner)intval;
69  return is;
70 }
71 
72 const std::string Overlap_name = "Overlap";
73 
74 const std::string GraphFill_name = "Graph Fill";
75 
76 const std::string DropTolerance_name = "Drop Tolerance";
77 
78 const std::string FillFactor_name = "Fill Factor";
79 
80 const std::string Steps_name = "Steps";
81 
82 const std::string PolynomialOrder_name = "Polynomial Order";
83 
84 const std::string RCMReordering_name = "RCM Reordering";
85 
86 const std::string Orthogonalization_name = "Orthogonalization";
87 
88 const std::string SizeOfKrylovSubspace_name = "Size of Krylov Subspace";
89 
90 const std::string ConvergenceTest_name = "Convergence Test";
91 
92 const std::string IllConditioningThreshold_name = "Ill-Conditioning Threshold";
93 
94 const std::string OutputFrequency_name = "Output Frequency";
95 
96 Teuchos::RCP<Teuchos::ParameterList> validAztecOOParams;
97 
98 } // namespace
99 
100 void setAztecOOParameters(
102  ,AztecOO *solver
103  )
104 {
105  using Teuchos::getIntegralValue;
106  using Teuchos::getParameter;
107  TEUCHOS_TEST_FOR_EXCEPT(pl==NULL);
108  TEUCHOS_TEST_FOR_EXCEPT(solver==NULL);
109  // Validate the parameters and set their defaults! This also sets the
110  // validators needed to read in the parameters in an integral form.
111  pl->validateParametersAndSetDefaults(*getValidAztecOOParameters());
112  // Aztec Solver
113  solver->SetAztecOption(
114  AZ_solver
115  ,getIntegralValue<int>(*pl,AztecSolver_name)
116  );
117  // Aztec Preconditioner
118  switch(
119  getIntegralValue<EAztecPreconditioner>(
120  *pl,AztecPreconditioner_name
121  )
122  )
123  {
124  // This is the only place that EAztecPreconditioner is used. Everywhere
125  // else the code expects a string value.
126  case AZTEC_PREC_NONE:
127  solver->SetAztecOption(AZ_precond,AZ_none);
128  pl->set(AztecPreconditioner_name, "none");
129  break;
130  case AZTEC_PREC_ILU:
131  solver->SetAztecOption(AZ_precond,AZ_dom_decomp);
132  solver->SetAztecOption(AZ_overlap,getParameter<int>(*pl,Overlap_name));
133  solver->SetAztecOption(AZ_subdomain_solve,AZ_ilu);
134  solver->SetAztecOption(AZ_graph_fill,getParameter<int>(*pl,GraphFill_name));
135  pl->set(AztecPreconditioner_name, "ilu");
136  break;
137  case AZTEC_PREC_ILUT:
138  solver->SetAztecOption(AZ_precond,AZ_dom_decomp);
139  solver->SetAztecOption(AZ_overlap,getParameter<int>(*pl,Overlap_name));
140  solver->SetAztecOption(AZ_subdomain_solve,AZ_ilut);
141  solver->SetAztecParam(AZ_drop,getParameter<double>(*pl,DropTolerance_name));
142  solver->SetAztecParam(AZ_ilut_fill,getParameter<double>(*pl,FillFactor_name));
143  pl->set(AztecPreconditioner_name, "ilut");
144  break;
145  case AZTEC_PREC_JACOBI:
146  solver->SetAztecOption(AZ_precond,AZ_Jacobi);
147  solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,Steps_name));
148  pl->set(AztecPreconditioner_name, "Jacobi");
149  break;
150  case AZTEC_PREC_SYMMGS:
151  solver->SetAztecOption(AZ_precond,AZ_sym_GS);
152  solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,Steps_name));
153  pl->set(AztecPreconditioner_name, "Symmetric Gauss-Seidel");
154  break;
155  case AZTEC_PREC_POLY:
156  solver->SetAztecOption(AZ_precond,AZ_Neumann);
157  solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,PolynomialOrder_name));
158  pl->set(AztecPreconditioner_name, "Polynomial");
159  break;
160  case AZTEC_PREC_LSPOLY:
161  solver->SetAztecOption(AZ_precond,AZ_ls);
162  solver->SetAztecOption(AZ_poly_ord,getParameter<int>(*pl,PolynomialOrder_name));
163  pl->set(AztecPreconditioner_name, "Least-squares Polynomial");
164  break;
165  default:
166  TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
167  }
168  // RCM Reordering (in conjunction with domain decomp preconditioning)
169  solver->SetAztecOption(
170  AZ_reorder
171  ,getIntegralValue<int>(*pl,RCMReordering_name)
172  );
173  // Gram-Schmidt orthogonalization procedure (GMRES only)
174  solver->SetAztecOption(
175  AZ_orthog
176  ,getIntegralValue<int>(*pl,Orthogonalization_name)
177  );
178  // Size of the krylov subspace
179  solver->SetAztecOption(AZ_kspace,getParameter<int>(*pl,SizeOfKrylovSubspace_name));
180  // Convergence criteria to use in the linear solver
181  solver->SetAztecOption(
182  AZ_conv
183  ,getIntegralValue<int>(*pl,ConvergenceTest_name)
184  );
185  // Set the ill-conditioning threshold for the upper hessenberg matrix
186  solver->SetAztecParam(
187  AZ_ill_cond_thresh, getParameter<double>(*pl,IllConditioningThreshold_name)
188  );
189  // Frequency of linear solve residual output
190  solver->SetAztecOption(
191  AZ_output, getParameter<int>(*pl,OutputFrequency_name)
192  );
193 #ifdef TEUCHOS_DEBUG
194  // Check to make sure that I did not use the PL incorrectly!
195  pl->validateParameters(*getValidAztecOOParameters());
196 #endif // TEUCHOS_DEBUG
197 }
198 
200 getValidAztecOOParameters()
201 {
202  //
203  // This function defines the valid parameter list complete with validators
204  // and default values. The default values never need to be repeated because
205  // if the use of the function validateParametersAndSetDefaults(...) used
206  // above in setAztecOOParameters(...). Also, the validators do not need to
207  // be kept track of since they will be set in the input list also.
208  //
209  using Teuchos::RCP;
210  using Teuchos::rcp;
211  using Teuchos::tuple;
212  using Teuchos::setStringToIntegralParameter;
213  using Teuchos::setIntParameter;
214  using Teuchos::setDoubleParameter;
225  >::getDummyObject(),
227  EAztecPreconditioner> >::getDummyObject());
228  //
229  RCP<ParameterList> pl = validAztecOOParams;
230  if(pl.get()) return pl;
231  pl = validAztecOOParams = rcp(new ParameterList());
232  //
233  setStringToIntegralParameter<int>(
234  AztecSolver_name, "GMRES",
235  "Type of linear solver algorithm to use.",
236  tuple<std::string>("CG","GMRES","CGS","TFQMR","BiCGStab","LU","GMRESR","FixedPoint"),
237  tuple<int>(AZ_cg,AZ_gmres,AZ_cgs,AZ_tfqmr,AZ_bicgstab,AZ_lu,AZ_GMRESR,AZ_fixed_pt),
238  &*pl
239  );
240  setStringToIntegralParameter<EAztecPreconditioner>(
241  AztecPreconditioner_name, "ilu",
242  "Type of internal preconditioner to use.\n"
243  "Note! this preconditioner will only be used if the input operator\n"
244  "supports the Epetra_RowMatrix interface and the client does not pass\n"
245  "in an external preconditioner!",
246  tuple<std::string>(
247  "none","ilu","ilut","Jacobi",
248  "Symmetric Gauss-Seidel","Polynomial","Least-squares Polynomial"
249  ),
250  tuple<EAztecPreconditioner>(
251  AZTEC_PREC_NONE,AZTEC_PREC_ILU,AZTEC_PREC_ILUT,AZTEC_PREC_JACOBI,
252  AZTEC_PREC_SYMMGS,AZTEC_PREC_POLY,AZTEC_PREC_LSPOLY
253  ),
254  &*pl
255  );
256  setIntParameter(
257  Overlap_name, 0,
258  "The amount of overlap used for the internal \"ilu\" and \"ilut\" preconditioners.",
259  &*pl
260  );
261  setIntParameter(
262  GraphFill_name, 0,
263  "The amount of fill allowed for the internal \"ilu\" preconditioner.",
264  &*pl
265  );
266  setDoubleParameter(
267  DropTolerance_name, 0.0,
268  "The tolerance below which an entry from the factors of an internal \"ilut\"\n"
269  "preconditioner will be dropped.",
270  &*pl
271  );
272  setDoubleParameter(
273  FillFactor_name, 1.0,
274  "The amount of fill allowed for an internal \"ilut\" preconditioner.",
275  &*pl
276  );
277  setIntParameter(
278  Steps_name, 3,
279  "Number of steps taken for the \"Jacobi\" or the \"Symmetric Gauss-Seidel\"\n"
280  "internal preconditioners for each preconditioner application.",
281  &*pl
282  );
283  setIntParameter(
284  PolynomialOrder_name, 3,
285  "The order for of the polynomials used for the \"Polynomial\" and\n"
286  "\"Least-squares Polynomial\" internal preconditioners.",
287  &*pl
288  );
289  setStringToIntegralParameter<int>(
290  RCMReordering_name, "Disabled",
291  "Determines if RCM reordering is used with the internal\n"
292  "\"ilu\" or \"ilut\" preconditioners.",
293  tuple<std::string>("Enabled","Disabled"),
294  tuple<int>(1,0),
295  &*pl
296  );
297  setStringToIntegralParameter<int>(
298  Orthogonalization_name, "Classical",
299  "The type of orthogonalization to use with the \"GMRES\" solver.",
300  tuple<std::string>("Classical","Modified"),
301  tuple<int>(AZ_classic,AZ_modified),
302  &*pl
303  );
304  setIntParameter(
305  SizeOfKrylovSubspace_name, 300,
306  "The maximum size of the Krylov subspace used with \"GMRES\" before\n"
307  "a restart is performed.",
308  &*pl
309  );
310  setStringToIntegralParameter<int>(
311  ConvergenceTest_name, "r0", // Same as "rhs" when x=0
312  "The convergence test to use for terminating the iterative solver.",
313  tuple<std::string>("r0","rhs","Anorm","no scaling","sol"),
314  tuple<int>(AZ_r0,AZ_rhs,AZ_Anorm,AZ_noscaled,AZ_sol),
315  &*pl
316  );
317  setDoubleParameter(
318  IllConditioningThreshold_name, 1e+11,
319  "The threshold tolerance above which a system is considered\n"
320  "ill conditioned.",
321  &*pl
322  );
323  setIntParameter(
324  OutputFrequency_name, 0, // By default, no output from Aztec!
325  "The number of iterations between each output of the solver's progress.",
326  &*pl
327  );
328  //
329  return pl;
330 }
static void addConverter(RCP< const ParameterEntryValidator > validator, RCP< ValidatorXMLConverter > converterToAdd)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
int SetAztecParam(int param, double value)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
int SetAztecOption(int option, int value)
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)

Generated on Fri May 3 2024 09:22:05 for Stratimikos by doxygen 1.8.5