Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parameterlist/test/ParameterList/cxx_main.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
13 #include "Teuchos_getConst.hpp"
14 #include "Teuchos_Version.hpp"
16 #include "Teuchos_FancyOStream.hpp"
17 #include "Teuchos_ArrayRCP.hpp"
19 
20 #ifdef HAVE_TEUCHOS_EXTENDED
22 #include <fstream>
23 #endif
24 
25 #ifdef HAVE_MPI
26 #include "mpi.h"
27 #endif
28 
31 using Teuchos::getParameter;
32 typedef ParameterList::PrintOptions PLPrintOptions;
34 using Teuchos::OSTab;
35 using Teuchos::rcp;
36 using Teuchos::inoutArg;
37 
38 void print_break() { std::cout << "---------------------------------------------------" << std::endl; }
39 double Plus ( double a, double b ) { return a+b; }
40 
41 int main( int argc, char *argv[] )
42 {
43 
44  using std::cout;
45  using std::endl;
46 
47  bool verbose = true;
48  int FailedTests = 0;
49  bool result;
50 
51  Teuchos::GlobalMPISession mpiSession(&argc,&argv);
52  const int procRank = Teuchos::GlobalMPISession::getRank();
53 
54  bool success = true;
55 
56  try {
57 
58  // Read options from the command line.
59  CommandLineProcessor clp(false); // Don't throw exceptions
60  clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
61  CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
62  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
63  cout << "Processor "<< procRank <<", parse_return "<< parse_return << std::endl;
64  cout << "End Result: TEST FAILED" << std::endl;
65  return parse_return;
66  }
67 
68  // Only print on 0 processor
69  if (procRank != 0 && verbose)
70  verbose = false;
71 
72  if (verbose)
73  cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
74 
75  //-----------------------------------------------------------
76  // Create Main Parameter List / Sublist Structure
77  //-----------------------------------------------------------
78 
79  ParameterList PL_Main("PL_Main");
80  const std::string Direction_Doc = "This sublist controls how direction is computed.";
81  ParameterList& PL_Direction = PL_Main.sublist("Direction",false,Direction_Doc);
82  ParameterList& PL_Newton = PL_Direction.sublist("Newton");
83  ParameterList& PL_LinSol = PL_Newton.sublist("Linear Solver");
84  ParameterList& PL_LineSearch = PL_Main.sublist("Line Search");
85 
86  //-----------------------------------------------------------
87  // Check Parameter List Structure
88  //-----------------------------------------------------------
89  if (verbose) {
90  print_break();
91  cout << "Empty Parameter List Structure" << std::endl;
92  print_break();
93  cout<<PL_Main<< std::endl;
94  }
95  if (verbose) cout << "Is 'Direction' recognized as a sublist of 'Main' ... ";
96  if ( PL_Main.isSublist( "Direction" ) ) {
97  if (verbose) cout << "yes"<< std::endl;
98  } else {
99  if (verbose) cout << "no"<< std::endl;
100  FailedTests++;
101  }
102  if (verbose) cout << "Is 'Newton' recognized as a sublist of 'Direction' ... ";
103  if ( PL_Direction.isSublist( "Newton" ) ) {
104  if (verbose) cout << "yes"<< std::endl;
105  } else {
106  if (verbose) cout << "no"<< std::endl;
107  FailedTests++;
108  }
109  if (verbose) cout << "Is 'Linear Solver' recognized as a sublist of 'Newton' ... ";
110  if ( PL_Newton.isSublist( "Linear Solver" ) ) {
111  if (verbose) cout << "yes"<< std::endl;
112  } else {
113  if (verbose) cout << "no"<< std::endl;
114  FailedTests++;
115  }
116  if (verbose) cout << "Is 'Line Search' recognized as a sublist of 'Main' ... ";
117  if ( PL_Main.isSublist( "Line Search" ) ) {
118  if (verbose) cout << "yes"<< std::endl;
119  } else {
120  if (verbose) cout << "no"<< std::endl;
121  FailedTests++;
122  }
123 
124  if (verbose) cout << "Is subist documentation std::string maintained ...\n";
125  {
126  Teuchos::OSTab tab(cout);
128  *paramEntry = PL_Main.getEntryPtr("Direction");
129  TEUCHOS_TEST_FOR_EXCEPT(0==paramEntry);
130  const std::string extracted_Direction_Doc = paramEntry->docString();
131  if (verbose) tab.o() << "Expected doc std::string = \"" << Direction_Doc << "\"\n";
132  if (verbose) tab.o() << "Extracted doc std::string = \"" << extracted_Direction_Doc << "\"\n";
133  if (extracted_Direction_Doc == Direction_Doc) {
134  if (verbose) tab.o() << "passed! They match :-)\n";
135  }
136  else {
137  if (verbose) tab.o() << "failed! They do not match :-("<< std::endl;
138  FailedTests++;
139  }
140  }
141 
142 
143  //-----------------------------------------------------------
144  // Fill in Direction Sublist
145  //-----------------------------------------------------------
146 
147  double tol = 0.0;
148  bool RBNS = false;
149  PL_Direction.get("Method", "Newton");
150  PL_LinSol.set("Tol",1e-5);
151  tol = PL_LinSol.get("Tolerance",1e-10);
152  (void)tol; // Not used, bad test!
153  RBNS = PL_Newton.get("Rescue Bad Newton Solve", true );
154  (void)RBNS; // Not used, bad test!
155 
156  //-----------------------------------------------------------
157  // Print out Direction Sublist
158  //-----------------------------------------------------------
159  if (verbose) {
160  print_break();
161  cout << "Direction Parameter List" << std::endl;
162  print_break();
163  PL_Direction.print(cout);
164  }
165  if (verbose) cout << "Is 'Newton' recognized as a parameter of 'Direction' ... ";
166  if ( PL_Direction.isParameter( "Newton" ) ) {
167  if (verbose) cout << "yes"<< std::endl;
168  } else {
169  if (verbose) cout << "no"<< std::endl;
170  FailedTests++;
171  }
172  if (verbose) cout << "Is 'Tolerance' recognized as a parameter of 'Newton' ... ";
173  if ( PL_Newton.isParameter( "Tolerance" ) ) {
174  if (verbose) cout << "yes (should be no)"<< std::endl;
175  FailedTests++;
176  } else {
177  if (verbose) cout << "no (as expected)"<< std::endl;
178  }
179  if (verbose) cout << "Is 'Tolerance' recognized as a parameter of 'Linear Solver' ... ";
180  if ( PL_LinSol.isParameter( "Tolerance" ) ) {
181  if (verbose) cout << "yes"<< std::endl;
182  } else {
183  if (verbose) cout << "no"<< std::endl;
184  FailedTests++;
185  }
186  if (verbose) cout << "Is 'Rescue Bad Newton Solve' recognized as a parameter of 'Newton' ... ";
187  if ( PL_Newton.isParameter( "Rescue Bad Newton Solve" ) ) {
188  if (verbose) cout << "yes"<< std::endl;
189  } else {
190  if (verbose) cout << "no"<< std::endl;
191  FailedTests++;
192  }
193 
194  //-----------------------------------------------------------
195  // Line Search Sublist
196  // (if there are no failures, this will be constructed and added)
197  //-----------------------------------------------------------
198  if (!FailedTests) {
199  int ARI = 0, default_step = 0, max_iter_inc = 0, rec_step = 0;
200  double alpha_factor = 0.0, min_bnds_factor = 0.0, max_bnds_factor = 0.0;
201  bool force_interp = true, use_cntrs = false;
202  std::string ls_method = "Polynomial";
203  // This is to force a char* to be passed into the get method to see if the template
204  // specialization for char* is working.
205  char* ls_method_char = const_cast<char *>(ls_method.c_str());
206  ParameterList PL_My_LineSearch("PL_My_LineSearch");
207  ls_method = PL_My_LineSearch.get("Method", ls_method_char);
208  ParameterList& PL_Polynomial = PL_My_LineSearch.sublist("Polynomial");
209  ARI = PL_Polynomial.get("Allowed Relative Increase", 100 );
210  (void)ARI; // Not used, bad test!
211  alpha_factor = PL_Polynomial.get("Alpha Factor", 0.0001 );
212  (void)alpha_factor; // Not used, bad test!
213  default_step = PL_Polynomial.get("Default Step", 1 );
214  (void)default_step; // Not used, bad test!
215  force_interp = PL_Polynomial.get("Force Interpolation", false );
216  (void)force_interp; // Not used, bad test!
217  std::string interp_type = PL_Polynomial.get("Interpolation Type", "Cubic" );
218  max_bnds_factor = PL_Polynomial.get("Max Bounds Factor", 0.5 );
219  (void)max_bnds_factor; // Not used, bad test!
220  PL_Polynomial.set("Max Iters", 3 );
221  max_iter_inc = PL_Polynomial.get("Maximum Iteration for Increase", 0 );
222  (void)max_iter_inc; // Not used, bad test!
223  min_bnds_factor = PL_Polynomial.get("Min Bounds Factor", 0.1 );
224  (void)min_bnds_factor; // Not used, bad test!
225  rec_step = PL_Polynomial.get("Recovery Step", 1 );
226  (void)rec_step; // Not used, bad test!
227  std::string rec_step_type = PL_Polynomial.get("Recovery Step Type", "Constant");
228  std::string suff_dec_cond = PL_Polynomial.get("Sufficient Decrease Condition", "Armijo-Goldstein" );
229  use_cntrs = PL_Polynomial.get("Use Counters", true );
230  (void)use_cntrs; // Not used, bad test!
231  PL_Main.set("Nonlinear Solver", "Line Search Based");
232 
233  //-----------------------------------------------------------
234  // Set the Line Search Parameter List equal to the one just constructed
235  //-----------------------------------------------------------
236  PL_LineSearch.setParameters(PL_My_LineSearch);
237  ParameterList& PL_My_Polynomial = PL_LineSearch.sublist("Polynomial");
238  if (verbose) cout<< "Is 'operator=' functional ... ";
239  if ( PL_My_Polynomial.isParameter("Recovery Step Type") ) {
240  if (verbose) cout<< "yes" << std::endl;
241  } else {
242  if (verbose) cout<< "no" << std::endl;
243  FailedTests++;
244  }
245 
246  //-----------------------------------------------------------
247  // Set Copying of parameter sublists and names
248  //-----------------------------------------------------------
249 
250  if (verbose) {
251  print_break();
252  if (verbose) cout << "Test copying of sublist\n";
253  print_break();
254  PL_Direction.print(cout);
255  }
256  {
257  const ParameterList
258  &linearSolverPL = PL_Main.sublist("Direction").sublist("Newton").sublist("Line Search");
259  const ParameterList
260  linearSolverPL_copy(linearSolverPL);
261  if (verbose) cout << "linearSolverPL.name() = " << linearSolverPL.name() << endl;
262  if (verbose) cout << "linearSolverPL_copy.name() = " << linearSolverPL_copy.name() << endl;
263  if (verbose) cout << "linearSolverPL_copy == linearSolverPL.name() : ";
264  if (linearSolverPL_copy == linearSolverPL.name()) {
265  if (verbose) cout << "passed" << endl;
266  }
267  else {
268  if (verbose) cout << "failed" << endl;
269  FailedTests++;
270  }
271  }
272 
273  if (verbose) {
274  print_break();
275  if (verbose) cout << "General tests\n";
276  print_break();
277  PL_Direction.print(cout);
278  }
279 
280  ParameterList Copied_PL_Main(PL_Main);
281 
282  if (verbose) cout << "Copied_PL_Main.name() == PL_Main.name() : ";
283  if (Copied_PL_Main.name() == PL_Main.name()) {
284  if (verbose) cout << "passed" << endl;
285  }
286  else {
287  if (verbose) cout << "failed" << endl;
288  FailedTests++;
289  if (verbose) cout << "Copyed_PL_Main.name() = " << Copied_PL_Main.name() << endl;
290  }
291 
292  if (verbose) cout<< "Is the copy constructor functional ... ";
293  if ( Copied_PL_Main.isParameter("Nonlinear Solver") ) {
294  if (verbose) cout<< "yes" << std::endl;
295  } else {
296  if (verbose) cout<< "no" << std::endl;
297  FailedTests++;
298  }
299 
300  bool tempMeth = true;
301 
302  //-----------------------------------------------------------
303  // Check the templated 'get' method.
304  //-----------------------------------------------------------
305  //
306  //-----------------------------------------------------------
307  // Retrieve some information from the parameter list using templated "get" method.
308  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
309  // non-templated code needs ".template" before the method name )
310  //-----------------------------------------------------------
311  int max_iters = 0, max_iters_again = 0;
312  std::string nonlin_solver;
313  tempMeth = true;
314  try {
315  max_iters = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER get<int>("Max Iters");
316  max_iters_again = Teuchos::getConst(PL_My_Polynomial).INVALID_TEMPLATE_QUALIFIER get<int>("Max Iters");
317  nonlin_solver = PL_Main.INVALID_TEMPLATE_QUALIFIER get<std::string>("Nonlinear Solver");
318  }
319  catch( const Teuchos::Exceptions::InvalidParameter&) { tempMeth = false; }
320  if (verbose) {
321  cout<< "Is the templated 'get' method functional ... "<<std::endl;
322  cout<< " Can we retrieve information using the CORRECT variable type ... ";
323  }
324  if (tempMeth && max_iters==3) { if (verbose) cout << "yes" << std::endl; }
325  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
326  if (verbose) {
327  cout<< " Can we retrieve const information using the CORRECT variable type ... ";
328  }
329  if (tempMeth && max_iters_again==3) { if (verbose) cout << "yes" << std::endl; }
330  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
331 
332  //-----------------------------------------------------------
333  // Retrieve some information from the parameter list that we know is a bad "get".
334  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
335  // non-templated code needs ".template" before the method name )
336  //-----------------------------------------------------------
337  float mbf = 0.0;
338  tempMeth = false;
339  try {
340  mbf = PL_LinSol.INVALID_TEMPLATE_QUALIFIER get<float>( "Tol" );
341  (void)mbf; // Not used, bad test!
342  FailedTests++;
343  }
345  tempMeth = true;
346  }
347  if (verbose) {
348  cout<< " Can we retrieve information using the WRONG variable type ... ";
349  }
350  if (tempMeth) { if (verbose) cout << "no" << std::endl; }
351  else { if (verbose) cout << "yes" << std::endl; }
352 
353  //-----------------------------------------------------------
354  // Retrieve some information from the parameter list using templated "get" method.
355  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
356  // non-templated code needs ".template" before the method name )
357  //-----------------------------------------------------------
358  tempMeth = true;
359  try {
360  max_iters = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER get<int>("Max Iters");
361  nonlin_solver = PL_Main.INVALID_TEMPLATE_QUALIFIER get<std::string>("Nonlinear Solver");
362  }
363  catch( const Teuchos::Exceptions::InvalidParameter&) { tempMeth = false; }
364  if (verbose) {
365  cout<< "Is the templated 'get' method functional ... "<<std::endl;
366  cout<< " Can we retrieve information using the CORRECT variable type ... ";
367  }
368  if (tempMeth && max_iters==3) { if (verbose) cout << "yes" << std::endl; }
369  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
370 
371  //-----------------------------------------------------------
372  // Retrieve some information from the parameter list that we know is a bad "get".
373  //-----------------------------------------------------------
374  tempMeth = false;
375  try {
376  mbf = PL_LinSol.INVALID_TEMPLATE_QUALIFIER get<float>( "Tol" );
377  (void)mbf; // Not used, bad test!
378  FailedTests++;
379  }
381  tempMeth = true;
382  }
383  if (verbose) {
384  cout<< " Can we retrieve information using the WRONG variable type ... ";
385  }
386  if (tempMeth) { if (verbose) cout << "no" << std::endl; }
387  else { if (verbose) cout << "yes" << std::endl; }
388 
389  //-----------------------------------------------------------
390  // Check the templated 'getPtr' method.
391  //-----------------------------------------------------------
392 
393  //-----------------------------------------------------------
394  // Retrieve some information from the parameter list using templated "get" method.
395  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
396  // non-templated code needs ".template" before the method name )
397  //-----------------------------------------------------------
398  int *max_iters_ptr = 0;
399  const int *max_iters_ptr_again = 0;
400  std::string* nonlin_solver_ptr;
401 
402  max_iters_ptr = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER getPtr<int>("Max Iters");
403  max_iters_ptr_again = Teuchos::getConst(PL_My_Polynomial).INVALID_TEMPLATE_QUALIFIER getPtr<int>("Max Iters");
404  nonlin_solver_ptr = PL_Main.INVALID_TEMPLATE_QUALIFIER getPtr<std::string>("Nonlinear Solver");
405 
406  if (verbose) {
407  cout<< "Is the templated 'getPtr' method functional ... "<<std::endl;
408  cout<< " Can we retrieve information using the CORRECT variable type ... ";
409  }
410  if (max_iters_ptr) {
411  if ((*max_iters_ptr)==3) {
412  if (verbose) cout << "yes" << std::endl;
413  }
414  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
415  }
416  if (verbose) {
417  cout<< " Can we retrieve const information using the CORRECT variable type ... ";
418  }
419  if (max_iters_ptr_again) {
420  if ((*max_iters_ptr_again)==3) {
421  if (verbose) cout << "yes" << std::endl;
422  }
423  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
424  }
425 
426  //-----------------------------------------------------------
427  // Retrieve some information from the parameter list that we know is a bad "get".
428  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
429  // non-templated code needs ".template" before the method name )
430  //-----------------------------------------------------------
431  float* mbf_ptr = 0;
432 
433  mbf_ptr = PL_LinSol.INVALID_TEMPLATE_QUALIFIER getPtr<float>( "Tol" );
434 
435  if (mbf_ptr)
436  ++FailedTests;
437 
438  if (verbose) {
439  cout<< " Can we retrieve information using the WRONG variable type ... ";
440  }
441  if (!mbf_ptr) { if (verbose) cout << "no" << std::endl; }
442  else { if (verbose) cout << "yes" << std::endl; }
443 
444  //-----------------------------------------------------------
445  // Retrieve some information from the parameter list using templated "get" method.
446  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
447  // non-templated code needs ".template" before the method name )
448  //-----------------------------------------------------------
449 
450  max_iters_ptr = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER getPtr<int>("Max Iters");
451  nonlin_solver_ptr = PL_Main.INVALID_TEMPLATE_QUALIFIER getPtr<std::string>("Nonlinear Solver");
452  (void)nonlin_solver_ptr; // Not used, bad test!
453 
454  if (verbose) {
455  cout<< "Is the templated 'getPtr' method functional ... "<<std::endl;
456  cout<< " Can we retrieve information using the CORRECT variable type ... ";
457  }
458  if (max_iters_ptr) {
459  if ((*max_iters_ptr)==3) {
460  if (verbose) cout << "yes" << std::endl;
461  }
462  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
463  }
464 
465  //-----------------------------------------------------------
466  // Retrieve some information from the parameter list that we know is a bad "get".
467  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
468  // non-templated code needs ".template" before the method name )
469  //-----------------------------------------------------------
470 
471  mbf_ptr = PL_LinSol.INVALID_TEMPLATE_QUALIFIER getPtr<float>( "Tol" );
472 
473  if (mbf_ptr)
474  ++FailedTests;
475 
476  if (verbose) {
477  cout<< " Can we retrieve information using the WRONG variable type ... ";
478  }
479  if (!mbf_ptr) { if (verbose) cout << "no" << std::endl; }
480  else { if (verbose) cout << "yes" << std::endl; }
481 
482  //-----------------------------------------------------------
483  // Check the 'getParameter' helper function.
484  //-----------------------------------------------------------
485  int def_step = 0;
486  double alpha_fact = 0.0;
487  tempMeth = true;
488  try {
489  def_step = Teuchos::getParameter<int>(PL_Polynomial, "Default Step");
490  alpha_fact = Teuchos::getParameter<double>(PL_Polynomial, "Alpha Factor");
491  (void)alpha_fact; // Not used, bad test!
492  }
493  catch( const Teuchos::Exceptions::InvalidParameter&) { tempMeth = false; }
494  if (verbose && def_step==1) {
495  cout<< "Is the helper function 'getParameter' functional ... ";
496  }
497  if (tempMeth) { if (verbose) cout << "yes" << std::endl; }
498  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
499 
500  //-----------------------------------------------------------
501  // Check templated isType functionality
502  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
503  // non-templated code needs ".template" before the method name )
504  //-----------------------------------------------------------
505  bool PT1, PT2, PT3;
506  PT1 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<int>("Default Step");
507  PT2 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<long int>("Default Step");
508  PT3 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<std::string>("Interpolation Type");
509  if (verbose) {
510  cout<< "Is the templated 'isType' method functional ... "<<std::endl;
511  cout<< " Is the 'Default Step' of type 'int' ... ";
512  }
513  if (PT1) { if (verbose) cout<< "yes" << std::endl; }
514  else { if (verbose) cout<< "no" << std::endl; FailedTests++; }
515  if (verbose) {
516  cout<< " Is the 'Default Step' of type 'long int' ... ";
517  }
518  if (PT2) { if (verbose) cout<< "yes" << std::endl; FailedTests++; }
519  else { if (verbose) cout<< "no (as expected)" << std::endl; }
520  if (verbose) {
521  cout<< " Is the 'Interpolation Type' of type 'std::string' ... ";
522  }
523  if (PT3) { if (verbose) cout<< "yes" << std::endl; }
524  else { if (verbose) cout<< "no" << std::endl; FailedTests++; }
525 
526  //-----------------------------------------------------------
527  // Check the 'isParameterType' helper function.
528  //-----------------------------------------------------------
529  bool PT4, PT5;
530  PT4 = Teuchos::isParameterType<double>(PL_Polynomial, "Max Bounds Factor");
531  PT5 = Teuchos::isParameterType<float>(PL_Polynomial, "Max Bounds Factor");
532  if (verbose) {
533  cout<< "Is the helper function 'isParameterType' functional ... "<<std::endl;
534  cout<< " Is the 'Max Bounds Factor' of type 'double' ... ";
535  }
536  if (PT4) { if (verbose) cout<< "yes" <<std::endl; }
537  else { if (verbose) cout<< "no" << std::endl; FailedTests++; }
538  if (verbose) {
539  cout<< " Is the 'Max Bounds Factor' of type 'float' ... ";
540  }
541  if (PT5) { if (verbose) cout<< "yes" <<std::endl; FailedTests++; }
542  else { if (verbose) cout<< "no (as expected)" << std::endl; }
543 
544  //-----------------------------------------------------------
545  // Can we pass a pointer to a std::vector to the parameter list.
546  //-----------------------------------------------------------
547  Teuchos::ArrayRCP<double> tempvec1_arcp = Teuchos::arcp<double>(10);
548  {
549  double * tempvec1 = tempvec1_arcp.get();
550  for (int i=0; i<10; i++) { tempvec1[i] = i; }
551  PL_Main.set( "Address of Norm Vector", tempvec1 );
552  double* tempvec2 = Teuchos::getParameter<double*>( PL_Main, "Address of Norm Vector" );
553  tempvec1[4] = 2.0; tempvec1[6] = 1.0;
554  if (verbose) {
555  cout<< "Can we pass a pointer to a std::vector to a parameter list ... ";
556  }
557  if ((tempvec2[4]-tempvec1[4])!=0.0 || (tempvec2[6]-tempvec1[6])!=0.0) {
558  if (verbose) { cout<<"no"<<std::endl; }
559  FailedTests++;
560  } else {
561  if (verbose) { cout<<"yes"<<std::endl; }
562  }
563  }
564 
565  //-----------------------------------------------------------
566  // We can add Array<T> objects of various types T as std::string parameters!
567  //-----------------------------------------------------------
568  if(verbose) {
569  print_break();
570  cout << "Setting int and double array objects as std::string parameters ...\n";
571  print_break();
572  }
573  const Teuchos::Array<int>
574  intArray = Teuchos::tuple<int>(0,1,2,3,4,5,6);
576  doubleArray = Teuchos::tuple<double>(0,1.0,2.0,3.0,4.0,5.0,6.0);
577  //const Teuchos::Array<bool>
578  //boolArray = Teuchos::tuple<bool>(true,true,false,false);
579  Teuchos::setStringParameterFromArray("Int Array",intArray,&PL_Main);
580  Teuchos::setStringParameterFromArray("Double Array",doubleArray,&PL_Main);
581  //Teuchos::setStringParameterFromArray("Bool Array",boolArray,&PL_Main);
582  if(verbose) {
583  print_break();
584  cout << "Testing retrieval of set array objects ...\n";
585  print_break();
586  }
587  {
588 
589  const Teuchos::Array<int>
590  readIntArray = Teuchos::getArrayFromStringParameter<int>(PL_Main,"Int Array");
591  result = readIntArray == intArray;
592  if(!result) ++FailedTests;
593  if(verbose)
594  cout
595  << "readIntArray = " << readIntArray << " == intArray = " << intArray << " ? "
596  << (result ? "passed" : "failed")
597  << "\n";
598 
599  const Teuchos::Array<int>
600  readDoubleAsIntArray = Teuchos::getArrayFromStringParameter<int>(PL_Main,"Double Array");
601  result = readDoubleAsIntArray == intArray;
602  if(!result) ++FailedTests;
603  if(verbose)
604  cout
605  << "readDoubleAsIntArray = " << readDoubleAsIntArray << " == intArray = " << intArray << " ? "
606  << (result ? "passed" : "failed")
607  << "\n";
608 
609 /*
610  const Teuchos::Array<bool>
611  readBoolArray = Teuchos::getArrayFromStringParameter<bool>(PL_Main,"Bool Array");
612  result = readBoolArray == boolArray;
613  if(!result) ++FailedTests;
614  if(verbose)
615  cout
616  << "readBoolArray = " << readBoolArray << " == boolArray = " << boolArray << " ? "
617  << (result ? "passed" : "failed")
618  << "\n";
619 */
620 
621  if(verbose) {
622  print_break();
623  }
624 
625  }
626 
627  //-----------------------------------------------------------
628  // We can directly set the array strings!
629  //-----------------------------------------------------------
630 
631  if(verbose) {
632  print_break();
633  cout << "Setting a array of doubles as a std::string parameter directly ...\n";
634  print_break();
635  }
636 
637  PL_Main.set(
638  "Double Array"
639  ," {\n"
640  " 0.00000\n"
641  " ,1.0e0\n"
642  " ,0.2e1\n"
643  " ,30.0e-1\n"
644  " ,4\n"
645  " ,5.0000\n"
646  " ,6\n"
647  " }\n "
648  );
649 
650  {
651 
653  readDoubleArray = Teuchos::getArrayFromStringParameter<double>(PL_Main,"Double Array");
655  doubleAsIntArray(readDoubleArray.size());
656  for(int i=0;i<static_cast<int>(readDoubleArray.size());++i)
657  doubleAsIntArray[i] = static_cast<int>(readDoubleArray[i]);
658  result = doubleAsIntArray == intArray;
659  if(!result) ++FailedTests;
660  if(verbose)
661  cout
662  << "doubleAsIntArray = " << doubleAsIntArray << " == intArray = " << intArray << " ? "
663  << (result ? "passed" : "failed")
664  << "\n";
665 
666  if(verbose) {
667  print_break();
668  }
669 
670  }
671 
672  //-----------------------------------------------------------
673  // Can we pass a pointer to a function to the parameter list.
674  // Use a simple function, pass it in and get it back out ...
675  // ( HKT 03/23/2004 This test is not supported on Janus )
676  //-----------------------------------------------------------
677 #ifndef JANUS_STLPORT
678  double (*pt2Function) (double, double);
679  PL_Main.set( "Address to Simple Function", &Plus );
680  pt2Function = Teuchos::getParameter<double(*)(double,double)>( PL_Main, "Address to Simple Function" );
681  if (verbose) {
682  cout<< "Can we pass a pointer to a function to a parameter list ... ";
683  }
684  if ( pt2Function( 1.0, 2.0 ) != 3.0 ) {
685  if (verbose) cout<<"no"<<std::endl;
686  FailedTests++;
687  } else {
688  if (verbose) cout<<"yes"<<std::endl;
689  }
690 #endif
691  }
692 
693  //-----------------------------------------------------------
694  // We can store and retrieve void* pointers!
695  //-----------------------------------------------------------
696 
697  {
698  ParameterList pl;
699  int someInt = 1;
700  void *someIntPtr = &someInt;
701  pl.set("Some Pointer", someIntPtr);
702  void *someIntPtrRtn = getParameter<void*>(pl, "Some Pointer");
703  TEUCHOS_TEST_FOR_EXCEPT(someIntPtrRtn != someIntPtr);
704  if (verbose)
705  cout << "someIntPtrRtn = " << someIntPtrRtn << " == " << someIntPtr << " : ";
706  if (someIntPtrRtn == someIntPtr) {
707  if (verbose) cout << "passed\n";
708  }
709  else {
710  if (verbose) cout << "failed\n";
711  FailedTests++;
712  }
713  }
714 
715  //-----------------------------------------------------------
716  // Print using the public iterators
717  // KL - 7 August 2004
718  //-----------------------------------------------------------
719  ParameterList::ConstIterator iter;
720 
721  if (verbose)
722  {
723  print_break();
724  cout << " printing using public iterators "
725  << std::endl;
726  print_break();
727  }
728  for (iter = PL_Main.begin(); iter != PL_Main.end(); ++iter)
729  {
730  const ParameterEntry& val = PL_Main.entry(iter);
731  const std::string& name = PL_Main.name(iter);
732  if (val.isList())
733  {
734  if (verbose) cout << name << std::endl;
735  const ParameterList& sublist = Teuchos::getValue<ParameterList>(val);
736  ParameterList::ConstIterator i;
737  for (i=sublist.begin(); i != sublist.end(); ++i)
738  {
739  const std::string& nm = sublist.name(i);
740  const ParameterEntry& v = sublist.entry(i);
741  if (v.isList())
742  {
743  if (verbose) cout << " " << nm << std::endl;
744  if (verbose) Teuchos::getValue<ParameterList>(v).print(cout, 6);
745  }
746  else
747  {
748  if (verbose) cout << " " << nm << " " << v << std::endl;
749  }
750  }
751  }
752  else
753  {
754  if (verbose) cout << name << " " << val << std::endl;
755  }
756  }
757 
758 
759 #if defined(HAVE_TEUCHOS_EXTENDED)
760 
761  try {
762 
763  if (verbose) {
764 
765  print_break();
766  cout << "writing to XML std::ostream" << std::endl;
767  print_break();
768  writeParameterListToXmlOStream(PL_Main,cout);
769 
770  print_break();
771  cout << "writing to XML file" << std::endl;
772  print_break();
773  writeParameterListToXmlFile(PL_Main,"PL_Main.xml");
774 
775  print_break();
776  cout << "reading from XML file" << std::endl;
777  print_break();
778  ParameterList readBack;
779  updateParametersFromXmlFile("PL_Main.xml", inoutArg(readBack));
780  if (verbose) readBack.print(cout);
781 
782  print_break();
783  cout << "reading from XML std::string" << std::endl;
784  print_break();
785  std::ifstream xmlInFile("PL_Main.xml");
786  std::string xmlStr;
787  while(!xmlInFile.eof()) {
788  std::string line;
789  std::getline(xmlInFile,line);
790  xmlStr += line + "\n";
791  }
792  readBack = ParameterList();
793  updateParametersFromXmlString(xmlStr, inoutArg(readBack));
794  if (verbose) readBack.print(cout);
795 
796  }
797 
798  }
799  catch(const std::exception& e)
800  {
801  if(verbose) {
802  std::cerr << "caught std::exception:\n\n";
803  OSTab tab(std::cerr);
804  std::cerr << e.what() << std::endl;
805  }
806  FailedTests++;
807  }
808 
809 #endif // defined(HAVE_TEUCHOS_EXTENDED)
810 
811  //-----------------------------------------------------------
812  // Print out main list
813  //-----------------------------------------------------------
814 
815  if (verbose) {
816  print_break();
817  cout << "The Final Parameter List" << std::endl;
818  print_break();
819  PL_Main.print(cout);
820  print_break();
821  cout << "The unused parameters" << std::endl;
822  PL_Main.unused(cout);
823  }
824 
825  //-----------------------------------------------------------
826  // Show error outputs
827  //-----------------------------------------------------------
828 
829  if (verbose) {
830  print_break();
831  cout << "Accessing a sublist using the wrong name (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
832  print_break();
833  }
834  try {
835  PL_Main.sublist("Direction").sublist("Newton").sublist("Linear Solvers",true);
836  if (verbose) cout << "Did not throw std::exception, error!\n";
837  ++FailedTests;
838  }
840  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
841  OSTab tab(std::cerr);
842  std::cerr << e.what() << std::endl;
843  }
844  if (verbose) {
845  print_break();
846  cout << "Accessing a parameter using the wrong name (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
847  print_break();
848  }
849  try {
850  Teuchos::getParameter<int>(PL_Main.sublist("Direction").sublist("Newton").sublist("Linear Solver"),"Tolerances");
851  if (verbose) cout << "Did not throw std::exception, error!\n";
852  ++FailedTests;
853  }
855  if(verbose) {
856  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
857  OSTab tab(std::cerr);
858  std::cerr << e.what() << std::endl;
859  }
860  }
861  catch(const std::exception &e) {
862  if(verbose) {
863  std::cerr << "caught unexpected std::exception:\n\n";
864  OSTab tab(std::cerr);
865  std::cerr << e.what() << std::endl;
866  }
867  ++FailedTests;
868  }
869 
870  if (verbose) {
871  print_break();
872  cout << "Accessing a parameter using the wrong parameter type (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
873  print_break();
874  }
875  try {
876  Teuchos::getParameter<int>(PL_Main.sublist("Direction").sublist("Newton").sublist("Linear Solver"),"Tolerance");
877  if (verbose) cout << "Did not throw std::exception, error!\n";
878  ++FailedTests;
879  }
881  if(verbose) {
882  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
883  OSTab tab(std::cerr);
884  std::cerr << e.what() << std::endl;
885  }
886  }
887  catch(const std::exception &e) {
888  if(verbose) {
889  std::cerr << "caught unexpected std::exception:\n\n";
890  OSTab tab(std::cerr);
891  std::cerr << e.what() << std::endl;
892  }
893  ++FailedTests;
894  }
895 
896  //-----------------------------------------------------------
897  // Validate the parameter list
898  //-----------------------------------------------------------
899 
900  // Create a validator version of PL_Main that we will validate against!
901  Teuchos::ParameterList PL_Main_valid("PL_Main_copy");
902  PL_Main_valid.setParameters(PL_Main);
903 
904  // Create a validator for the "Nonlinear Solver" parameter
905  Teuchos::setStringToIntegralParameter<int>(
906  "Nonlinear Solver", "Line Search Based",
907  "Selects the type of nonlinear solver to use",
908  Teuchos::tuple<std::string>("Line Search Based","Trust Region Based"),
909  &PL_Main
910  );
911 
912 /*
913  Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
914  nonlinearSolverValidator = rcp(
915  new Teuchos::StringToIntegralParameterEntryValidator<int>(
916  Teuchos::tuple<std::string>("Line Search Based","Trust Region Based")
917  ,"Nonlinear Solver"
918  )
919  );
920  PL_Main_valid.set(
921  "Nonlinear Solver", "Line Search Based"
922  ,"Selects the type of nonlinear solver to use"
923  ,nonlinearSolverValidator
924  );
925 */
926 
927  // Create a validator for the parameter "Line Search"->"Polynomial"->"Max Iters"
928  // that accepts an 'int', a 'double' or a 'std::string' value!
931  linesearchMaxItersValiator = rcp(
934  AcceptedTypes(false).allowInt(true).allowDouble(true).allowString(true)
935  )
936  );
937  PL_Main_valid.sublist("Line Search").sublist("Polynomial").set(
938  "Max Iters",3
939  ,"The maximum number of inner linear search iterations allowed."
940  ,linesearchMaxItersValiator
941  );
942 
943  // Create a validator for the parameter "Direction"->"Newton"->"Linear Solver"->"Tol"
944  // that accepts a 'double' or a 'std::string' value!
947  linSolveTolValidator = rcp(
950  AcceptedTypes(false).allowDouble(true).allowString(true)
951  )
952  );
953  PL_Main_valid.sublist("Direction",true).sublist("Newton",true)
954  .sublist("Linear Solver",true).set(
955  "Tol", double(1e-5)
956  ,"Select the linear solve tolerance"
957  ,linSolveTolValidator
958  );
959 
960  if (verbose) {
961  print_break();
962  cout << "Validating the parameter list against itself (should not throw std::exception)...\n";
963  print_break();
964  }
965  try {
966  PL_Main.validateParameters(PL_Main_valid);
967  if (verbose) cout << "Did not throw std::exception, success!\n\n";
968  }
969  catch(const std::exception &e) {
970  if(verbose) {
971  std::cerr << "caught unexpected std::exception:\n\n";
972  OSTab tab(std::cerr);
973  std::cerr << e.what() << std::endl;
974  }
975  ++FailedTests;
976  }
977 
978  if (verbose) {
979  print_break();
980  cout << "Adding an invalid parameter type then validating (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
981  print_break();
982  }
983  try {
984  PL_Main.sublist("Line Search").sublist("Polynomial").set("Max Iters",(short int)(3)); // Should be an int!
985  PL_Main.validateParameters(PL_Main_valid);
986  if (verbose) cout << "Did not throw std::exception, error!\n";
987  ++FailedTests;
988  }
990  if(verbose) {
991  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
992  OSTab tab(std::cerr);
993  std::cerr << e.what() << std::endl;
994  }
995  }
996  catch(const std::exception &e) {
997  if(verbose) {
998  std::cerr << "caught unexpected std::exception:\n\n";
999  OSTab tab(std::cerr);
1000  std::cerr << e.what() << std::endl;
1001  }
1002  ++FailedTests;
1003  }
1004  PL_Main.sublist("Line Search").sublist("Polynomial").set("Max Iters",3); // Put back the valid int!
1005 
1006  if (verbose) {
1007  print_break();
1008  cout << "Adding an invalid parameter name then validating (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
1009  print_break();
1010  }
1011  try {
1012  PL_Main.sublist("Line Search").sublist("Polynomial").set("Max Iter",10);
1013  PL_Main.validateParameters(PL_Main_valid);
1014  if (verbose) cout << "Did not throw std::exception, error!\n";
1015  ++FailedTests;
1016  }
1018  if(verbose) {
1019  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
1020  OSTab tab(std::cerr);
1021  std::cerr << e.what() << std::endl;
1022  }
1023  }
1024  catch(const std::exception &e) {
1025  if(verbose) {
1026  std::cerr << "caught unexpected std::exception:\n\n";
1027  OSTab tab(std::cerr);
1028  std::cerr << e.what() << std::endl;
1029  }
1030  ++FailedTests;
1031  }
1032  PL_Main.sublist("Line Search").sublist("Polynomial").remove("Max Iter");
1033 
1034  if (verbose) {
1035  print_break();
1036  cout << "Adding an invalid parameter type then validating using validator (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
1037  print_break();
1038  }
1039  try {
1040  PL_Main.set("Nonlinear Solver",int(0)); // Should be a std::string!
1041  PL_Main.validateParameters(PL_Main_valid);
1042  if (verbose) cout << "Did not throw std::exception, error!\n";
1043  ++FailedTests;
1044  }
1046  if(verbose) {
1047  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
1048  OSTab tab(std::cerr);
1049  std::cerr << e.what() << std::endl;
1050  }
1051  }
1052  catch(const std::exception &e) {
1053  if(verbose) {
1054  std::cerr << "caught unexpected std::exception:\n\n";
1055  OSTab tab(std::cerr);
1056  std::cerr << e.what() << std::endl;
1057  }
1058  ++FailedTests;
1059  }
1060  PL_Main.set("Nonlinear Solver","Line Search Based"); // Put back the valid value!
1061 
1062  if (verbose) {
1063  print_break();
1064  cout << "Adding an invalid parameter value then validating using validator (should throw a Teuchos::Exceptions::InvalidParameterValue std::exception)...\n";
1065  print_break();
1066  }
1067  try {
1068  PL_Main.set("Nonlinear Solver","LineSearch Based"); // Should be "Line Search Based"!
1069  PL_Main.validateParameters(PL_Main_valid);
1070  if (verbose) cout << "Did not throw std::exception, error!\n";
1071  ++FailedTests;
1072  }
1074  if(verbose) {
1075  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterValue:\n\n";
1076  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1077  }
1078  }
1079  catch(const std::exception &e) {
1080  if(verbose) {
1081  std::cerr << "caught unexpected std::exception:\n\n";
1082  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1083  }
1084  ++FailedTests;
1085  }
1086  PL_Main.set("Nonlinear Solver","Line Search Based"); // Put back the valid value!
1087 
1088  if (verbose) {
1089  print_break();
1090  cout << "Use the validator to access integral value (should *not* throw std::exception)...\n";
1091  print_break();
1092  }
1093  try {
1094  const int
1095  nonlinearSolverValue = Teuchos::getIntegralValue<int>(PL_Main,"Nonlinear Solver");
1096  const bool
1097  l_result = (nonlinearSolverValue == 0);
1098  cout
1099  << "Read value = " << nonlinearSolverValue << " == 0 : "
1100  << ( l_result ? "passed" : "failed") << "\n";
1101  if(!l_result) ++FailedTests;
1102  }
1103  catch(const std::exception &e) {
1104  if(verbose) {
1105  std::cerr << "caught unexpected std::exception:\n\n";
1106  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1107  }
1108  ++FailedTests;
1109  }
1110 
1111  if (verbose) {
1112  print_break();
1113  cout << "Use the validator to access std::string value (should *not* throw std::exception)...\n";
1114  print_break();
1115  }
1116  try {
1117  const std::string
1118  nonlinearSolverValue = Teuchos::getStringValue<int>(PL_Main,"Nonlinear Solver");
1119  const bool
1120  l_result = (nonlinearSolverValue == "Line Search Based");
1121  cout
1122  << "Read value = \"" << nonlinearSolverValue << " == \"Line Search Based\" : "
1123  << ( l_result ? "passed" : "failed") << "\n";
1124  if(!l_result) ++FailedTests;
1125  }
1126  catch(const std::exception &e) {
1127  if(verbose) {
1128  std::cerr << "caught unexpected std::exception:\n\n";
1129  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1130  }
1131  ++FailedTests;
1132  }
1133 
1134  //-----------------------------------------------------------
1135  // Validate and set defaults
1136  //-----------------------------------------------------------
1137 
1138  // Set the default parameters for an emplty list
1139  ParameterList validatedPL;
1140 
1141  if (verbose) {
1142  print_break();
1143  cout << "Validating and setting defaults for an empty parameter list (should not throw) ...\n";
1144  print_break();
1145  }
1146  try {
1147  validatedPL.validateParametersAndSetDefaults(PL_Main_valid);
1148  if (verbose) cout << "Did not throw std::exception, success!\n\n";
1149  }
1150  catch(const std::exception &e) {
1151  if(verbose) {
1152  std::cerr << "caught unexpected std::exception:\n\n";
1153  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1154  }
1155  ++FailedTests;
1156  }
1157 
1158  if (verbose) {
1159  print_break();
1160  cout << "Parameter list with defaults set:" << std::endl;
1161  print_break();
1162  validatedPL.print(cout,PLPrintOptions().showTypes(true).showDoc(true));
1163  print_break();
1164  }
1165 
1166  if (verbose) {
1167  print_break();
1168  cout << "Checking that validatedPL and PL_Main_valid have the same values : ";
1169  }
1170  result = haveSameValues(validatedPL,PL_Main_valid);
1171  if(!result)
1172  ++FailedTests;
1173  if (verbose) {
1174  cout << ( result ? "passed" : "failed" ) << "\n";
1175  print_break();
1176  }
1177 
1178  //
1179  // Testing access of numbers using validator where validator is not buried
1180  // in the parameter
1181  //
1182 
1183  for( int type_i = 0; type_i < 3; ++type_i ) {
1184 
1185  ParameterList &Polynomial_sublist
1186  = PL_Main.sublist("Line Search",true).sublist("Polynomial",true);
1187 
1188  std::string typeName;
1189 
1190  // Set the input type
1191 
1192  switch(type_i) {
1193  case 0:
1194  typeName = "int";
1195  Polynomial_sublist.set("Max Iters",(int)(3));
1196  break;
1197  case 1:
1198  typeName = "double";
1199  Polynomial_sublist.set("Max Iters",(double)(3.0));
1200  break;
1201  case 2:
1202  typeName = "std::string";
1203  Polynomial_sublist.set("Max Iters",(std::string)("3"));
1204  break;
1205  default:
1207  }
1208 
1209  // Extract using external validator
1210 
1211  if (verbose) {
1212  print_break();
1213  cout << "Use the external number validator to access a "<<typeName<<" as an int ...\n";
1214  print_break();
1215  }
1216  try {
1217  const int
1218  lineserchMaxIters
1219  = linesearchMaxItersValiator->getInt(
1220  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1221  ,"Max Iters",0
1222  );
1223  const bool
1224  l_result = (lineserchMaxIters == int(3));
1225  cout
1226  << "Read value = " << lineserchMaxIters << " == 3 : "
1227  << ( l_result ? "passed" : "failed") << "\n";
1228  if(!l_result) ++FailedTests;
1229  }
1230  catch(const std::exception &e) {
1231  if(verbose) {
1232  std::cerr << "caught unexpected std::exception:\n\n";
1233  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1234  }
1235  ++FailedTests;
1236  }
1237 
1238  if (verbose) {
1239  print_break();
1240  cout << "Use the external number validator to access a "<<typeName<<" as a double ...\n";
1241  print_break();
1242  }
1243  try {
1244  const double
1245  lineserchMaxIters
1246  = linesearchMaxItersValiator->getDouble(
1247  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1248  ,"Max Iters",0.0
1249  );
1250  const bool
1251  l_result = (lineserchMaxIters == double(3.0));
1252  cout
1253  << "Read value = " << lineserchMaxIters << " == 3 : "
1254  << ( l_result ? "passed" : "failed") << "\n";
1255  if(!l_result) ++FailedTests;
1256  }
1257  catch(const std::exception &e) {
1258  if(verbose) {
1259  std::cerr << "caught unexpected std::exception:\n\n";
1260  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1261  }
1262  ++FailedTests;
1263  }
1264 
1265  if (verbose) {
1266  print_break();
1267  cout << "Use the external number validator to access a "<<typeName<<" as a std::string ...\n";
1268  print_break();
1269  }
1270  try {
1271  const std::string
1272  lineserchMaxIters
1273  = linesearchMaxItersValiator->getString(
1274  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1275  ,"Max Iters","0"
1276  );
1277  const bool
1278  l_result = (lineserchMaxIters == "3");
1279  cout
1280  << "Read value = \"" << lineserchMaxIters << "\" == \"3\" : "
1281  << ( l_result ? "passed" : "failed") << "\n";
1282  if(!l_result) ++FailedTests;
1283  }
1284  catch(const std::exception &e) {
1285  if(verbose) {
1286  std::cerr << "caught unexpected std::exception:\n\n";
1287  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1288  }
1289  ++FailedTests;
1290  }
1291 
1292  // Extract using nonmember functions
1293 
1294  if (verbose) {
1295  print_break();
1296  cout << "Use the nomember help function to access a "<<typeName<<" as an int ...\n";
1297  print_break();
1298  }
1299  try {
1300  const int
1301  lineserchMaxIters
1302  = Teuchos::getIntParameter(
1303  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1304  ,"Max Iters"
1305  );
1306  const bool
1307  l_result = (lineserchMaxIters == int(3));
1308  cout
1309  << "Read value = " << lineserchMaxIters << " == 3 : "
1310  << ( l_result ? "passed" : "failed") << "\n";
1311  if(!l_result) ++FailedTests;
1312  }
1313  catch(const std::exception &e) {
1314  if(verbose) {
1315  std::cerr << "caught unexpected std::exception:\n\n";
1316  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1317  }
1318  ++FailedTests;
1319  }
1320 
1321  if (verbose) {
1322  print_break();
1323  cout << "Use the nomember help function to access a "<<typeName<<" as a double ...\n";
1324  print_break();
1325  }
1326  try {
1327  const double
1328  lineserchMaxIters
1329  = Teuchos::getDoubleParameter(
1330  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1331  ,"Max Iters"
1332  );
1333  const bool
1334  l_result = (lineserchMaxIters == double(3.0));
1335  cout
1336  << "Read value = " << lineserchMaxIters << " == 3 : "
1337  << ( l_result ? "passed" : "failed") << "\n";
1338  if(!l_result) ++FailedTests;
1339  }
1340  catch(const std::exception &e) {
1341  if(verbose) {
1342  std::cerr << "caught unexpected std::exception:\n\n";
1343  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1344  }
1345  ++FailedTests;
1346  }
1347 
1348  if (verbose) {
1349  print_break();
1350  cout << "Use the nomember help function to access a "<<typeName<<" as a std::string ...\n";
1351  print_break();
1352  }
1353  try {
1354  const std::string
1355  lineserchMaxIters
1356  = Teuchos::getNumericStringParameter(
1357  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1358  ,"Max Iters"
1359  );
1360  const bool
1361  l_result = (lineserchMaxIters == "3");
1362  cout
1363  << "Read value = \"" << lineserchMaxIters << "\" == \"3\" : "
1364  << ( l_result ? "passed" : "failed") << "\n";
1365  if(!l_result) ++FailedTests;
1366  }
1367  catch(const std::exception &e) {
1368  if(verbose) {
1369  std::cerr << "caught unexpected std::exception:\n\n";
1370  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1371  }
1372  ++FailedTests;
1373  }
1374 
1375  }
1376 
1377  //
1378  // Testing access of numbers using validator where validator is buried in
1379  // the parameter
1380  //
1381 
1382  for( int type_i = 0; type_i < 4; ++type_i ) {
1383 
1384  ParameterList &Polynomial_sublist
1385  = PL_Main.sublist("Line Search",true).sublist("Polynomial",true);
1386 
1387  std::string typeName;
1388 
1389  // Set the input type
1390 
1391  switch(type_i) {
1392  case 0:
1393  typeName = "int";
1394  Teuchos::setIntParameter("Max Iters",3,"",&Polynomial_sublist);
1395  break;
1396  case 1:
1397  typeName = "double";
1398  Teuchos::setDoubleParameter("Max Iters",3.0,"",&Polynomial_sublist);
1399  break;
1400  case 2:
1401  typeName = "std::string";
1402  Teuchos::setNumericStringParameter("Max Iters","3","",&Polynomial_sublist);
1403  break;
1404  case 3:
1405  typeName = "long long";
1406  Teuchos::setLongLongParameter("Max Iters",3,"",&Polynomial_sublist);
1407  break;
1408  default:
1410  }
1411 
1412  // Extract using nonmember functions (which should use the internal validator)
1413 
1414  if (verbose) {
1415  print_break();
1416  cout << "Use the nomember help function to access a "<<typeName<<" as an int ...\n";
1417  print_break();
1418  }
1419  try {
1420  const int
1421  lineserchMaxIters
1422  = Teuchos::getIntParameter(
1423  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1424  ,"Max Iters"
1425  );
1426  const bool
1427  l_result = (lineserchMaxIters == int(3));
1428  cout
1429  << "Read value = " << lineserchMaxIters << " == 3 : "
1430  << ( l_result ? "passed" : "failed") << "\n";
1431  if(!l_result) ++FailedTests;
1432  }
1433  catch(const std::exception &e) {
1434  if(verbose) {
1435  std::cerr << "caught unexpected std::exception:\n\n";
1436  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1437  }
1438  ++FailedTests;
1439  }
1440 
1441  if (verbose) {
1442  print_break();
1443  cout << "Use the nomember help function to access a "<<typeName<<" as a double ...\n";
1444  print_break();
1445  }
1446  try {
1447  const double
1448  lineserchMaxIters
1449  = Teuchos::getDoubleParameter(
1450  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1451  ,"Max Iters"
1452  );
1453  const bool
1454  l_result = (lineserchMaxIters == double(3.0));
1455  cout
1456  << "Read value = " << lineserchMaxIters << " == 3 : "
1457  << ( l_result ? "passed" : "failed") << "\n";
1458  if(!l_result) ++FailedTests;
1459  }
1460  catch(const std::exception &e) {
1461  if(verbose) {
1462  std::cerr << "caught unexpected std::exception:\n\n";
1463  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1464  }
1465  ++FailedTests;
1466  }
1467 
1468  if (verbose) {
1469  print_break();
1470  cout << "Use the nomember help function to access a "<<typeName<<" as a std::string ...\n";
1471  print_break();
1472  }
1473  try {
1474  const std::string
1475  lineserchMaxIters
1476  = Teuchos::getNumericStringParameter(
1477  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1478  ,"Max Iters"
1479  );
1480  const bool
1481  l_result = (lineserchMaxIters == "3");
1482  cout
1483  << "Read value = \"" << lineserchMaxIters << "\" == \"3\" : "
1484  << ( l_result ? "passed" : "failed") << "\n";
1485  if(!l_result) ++FailedTests;
1486  }
1487  catch(const std::exception &e) {
1488  if(verbose) {
1489  std::cerr << "caught unexpected std::exception:\n\n";
1490  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1491  }
1492  ++FailedTests;
1493  }
1494 
1495  if (verbose) {
1496  print_break();
1497  cout << "Use the nomember help function to access a "<<typeName<<" as an long long ...\n";
1498  print_break();
1499  }
1500  try {
1501  const long long
1502  lineserchMaxIters
1503  = Teuchos::getLongLongParameter(
1504  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1505  ,"Max Iters"
1506  );
1507  const bool
1508  l_result = (lineserchMaxIters == (long long)(3));
1509  cout
1510  << "Read value = " << lineserchMaxIters << " == 3 : "
1511  << ( l_result ? "passed" : "failed") << "\n";
1512  if(!l_result) ++FailedTests;
1513  }
1514  catch(const std::exception &e) {
1515  if(verbose) {
1516  std::cerr << "caught unexpected std::exception:\n\n";
1517  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1518  }
1519  ++FailedTests;
1520  }
1521 
1522  }
1523 
1524  //
1525  // Testing access of numbers where correct number is set using
1526  // validateParametersAndSetDefaults(...) with no special access.
1527  //
1528 
1529  for( int type_i = 0; type_i < 3; ++type_i ) {
1530 
1531  ParameterList valid_PL_Main(PL_Main);
1532 
1533  ParameterList &Polynomial_sublist
1534  = PL_Main.sublist("Line Search",true).sublist("Polynomial",true);
1535 
1536  std::string typeName;
1537 
1538  // Set the input type
1539 
1540  switch(type_i) {
1541  case 0:
1542  typeName = "int";
1543  Teuchos::setIntParameter("Max Iters",3,"",&Polynomial_sublist);
1544  break;
1545  case 1:
1546  typeName = "double";
1547  Teuchos::setDoubleParameter("Max Iters",3.0,"",&Polynomial_sublist);
1548  break;
1549  case 2:
1550  typeName = "std::string";
1551  Teuchos::setNumericStringParameter("Max Iters","3","",&Polynomial_sublist);
1552  break;
1553  default:
1555  }
1556 
1557  // Extract using nonmember functions (which should use the internal validator)
1558 
1559  if (verbose) {
1560  print_break();
1561  cout << "Use validateParemetersAndSetDefaults(...) to access a "<<typeName<<" as an int ...\n";
1562  print_break();
1563  }
1564  try {
1565  Teuchos::setIntParameter(
1566  "Max Iters", 0, "",
1567  &valid_PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1568  );
1569  ParameterList copied_PL_Main(PL_Main);
1570  copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main);
1571  const int
1572  lineserchMaxIters
1573  = Teuchos::getParameter<int>(
1574  copied_PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1575  ,"Max Iters"
1576  );
1577  const bool
1578  l_result = (lineserchMaxIters == int(3));
1579  cout
1580  << "Read value = " << lineserchMaxIters << " == 3 : "
1581  << ( l_result ? "passed" : "failed") << "\n";
1582  if(!l_result) ++FailedTests;
1583  }
1584  catch(const std::exception &e) {
1585  if(verbose) {
1586  std::cerr << "caught unexpected std::exception:\n\n";
1587  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1588  }
1589  ++FailedTests;
1590  }
1591 
1592  if (verbose) {
1593  print_break();
1594  cout << "Use validateParemetersAndSetDefaults(...) to access a "<<typeName<<" as a double ...\n";
1595  print_break();
1596  }
1597  try {
1598  Teuchos::setDoubleParameter(
1599  "Max Iters", 0.0, "",
1600  &valid_PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1601  );
1602  ParameterList copied_PL_Main(PL_Main);
1603  copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main);
1604  const double
1605  lineserchMaxIters
1606  = Teuchos::getParameter<double>(
1607  copied_PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1608  ,"Max Iters"
1609  );
1610  const bool
1611  l_result = (lineserchMaxIters == double(3.0));
1612  cout
1613  << "Read value = " << lineserchMaxIters << " == 3 : "
1614  << ( l_result ? "passed" : "failed") << "\n";
1615  if(!l_result) ++FailedTests;
1616  }
1617  catch(const std::exception &e) {
1618  if(verbose) {
1619  std::cerr << "caught unexpected std::exception:\n\n";
1620  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1621  }
1622  ++FailedTests;
1623  }
1624 
1625  if (verbose) {
1626  print_break();
1627  cout << "Use validateParemetersAndSetDefaults(...) to access a "<<typeName<<" as a std::string ...\n";
1628  print_break();
1629  }
1630  try {
1631  Teuchos::setNumericStringParameter(
1632  "Max Iters", "0", "",
1633  &valid_PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1634  );
1635  ParameterList copied_PL_Main(PL_Main);
1636  copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main);
1637  const std::string
1638  lineserchMaxIters
1639  = Teuchos::getParameter<std::string>(
1640  copied_PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1641  ,"Max Iters"
1642  );
1643  const bool
1644  l_result = (lineserchMaxIters == "3");
1645  cout
1646  << "Read value = \"" << lineserchMaxIters << "\" == \"3\" : "
1647  << ( l_result ? "passed" : "failed") << "\n";
1648  if(!l_result) ++FailedTests;
1649  }
1650  catch(const std::exception &e) {
1651  if(verbose) {
1652  std::cerr << "caught unexpected std::exception:\n\n";
1653  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1654  }
1655  ++FailedTests;
1656  }
1657 
1658  }
1659 
1660  if (verbose) {
1661  print_break();
1662  cout << "Adding an invalid sublist then validating (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
1663  print_break();
1664  }
1665  try {
1666  PL_Main.sublist("Line Search").sublist("Polynomials").set("Max Iters",3); // param correct, sublist wrong
1667  PL_Main.validateParameters(PL_Main_valid);
1668  if (verbose) cout << "Did not throw std::exception, error!\n";
1669  ++FailedTests;
1670  }
1672  if(verbose) {
1673  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
1674  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1675  }
1676  }
1677  catch(const std::exception &e) {
1678  if(verbose) {
1679  std::cerr << "caught unexpected std::exception:\n\n";
1680  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1681  }
1682  ++FailedTests;
1683  }
1684  PL_Main.sublist("Line Search").remove("Polynomials");
1685 
1686  if (verbose) {
1687  print_break();
1688  cout << "Validating only the top level list (should not throw std::exception)...\n";
1689  print_break();
1690  }
1691  try {
1692  PL_Main.validateParameters(PL_Main_valid,0);
1693  if (verbose) cout << "Did not throw std::exception, success!\n\n";
1694  }
1695  catch(const std::exception &e) {
1696  if(verbose) {
1697  std::cerr << "caught unexpected std::exception:\n\n";
1698  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1699  }
1700  ++FailedTests;
1701  }
1702 
1703  //-----------------------------------------------------------
1704  // Compare lists
1705  //-----------------------------------------------------------
1706 
1707  if (verbose) {
1708  print_break();
1709  cout << "Checking that PL_Main == PL_Main == true : ";
1710  }
1711  result = (PL_Main == PL_Main);
1712  if(!result)
1713  ++FailedTests;
1714  if (verbose) {
1715  cout << ( result ? "passed" : "failed" ) << "\n";
1716  print_break();
1717  }
1718 
1719  if (verbose) {
1720  print_break();
1721  cout << "Checking that PL_Main != PL_Main == false : ";
1722  }
1723  result = !(PL_Main != PL_Main);
1724  if(!result)
1725  ++FailedTests;
1726  if (verbose) {
1727  cout << ( result ? "passed" : "failed" ) << "\n";
1728  print_break();
1729  }
1730 
1731  if (verbose) {
1732  print_break();
1733  cout << "Checking that PL_Main and PL_Main have the same values : ";
1734  }
1735  result = haveSameValues(PL_Main,PL_Main);
1736  if(!result)
1737  ++FailedTests;
1738  if (verbose) {
1739  cout << ( result ? "passed" : "failed" ) << "\n";
1740  print_break();
1741  }
1742 
1743  if (verbose) {
1744  print_break();
1745  cout << "Create copy PL_Main_copy, change PL_Main_copy, and check that PL_Main != PL_Main == true : ";
1746  }
1747  ParameterList PL_Main_copy(PL_Main);
1748  PL_Main_copy.sublist("Line Search",true).sublist("Polynomial",true).set("Max Iters",100); // Not the default!
1749  result = (PL_Main_copy != PL_Main);
1750  if(!result)
1751  ++FailedTests;
1752  if (verbose) {
1753  cout << ( result ? "passed" : "failed" ) << "\n";
1754  print_break();
1755  }
1756 
1757  //-----------------------------------------------------------
1758  // Print out main list showing the types
1759  //-----------------------------------------------------------
1760 
1761  if (verbose) {
1762  print_break();
1763  cout << "The Final Parameter List with Types and Documentation" << std::endl;
1764  print_break();
1765  PL_Main.print(cout,PLPrintOptions().showTypes(true).showDoc(true));
1766  print_break();
1767  cout << "The unused parameters" << std::endl;
1768  PL_Main.unused(cout);
1769  print_break();
1770  cout << "Number of Failed Tests : " << FailedTests << std::endl;
1771  print_break();
1772  }
1773 
1774  //-----------------------------------------------------------
1775  // Return -1 if there are any failed tests,
1776  // else 0 will be returned indicating a clean finish!
1777  //-----------------------------------------------------------
1778 
1779  } // end try
1780  TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose,std::cerr,success);
1781  if(!success) ++FailedTests;
1782 
1783  if ( FailedTests > 0 ) {
1784  cout << "End Result: TEST FAILED" << std::endl;
1785  return 1; // Can't return negative numbers from main()!
1786  }
1787 
1788  if ( FailedTests == 0 )
1789  cout << "End Result: TEST PASSED" << std::endl;
1790 
1791  return 0;
1792 
1793 }
1794 
void print() const
Print function to use in debugging in a debugger.
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
const std::string & name() const
The name of this ParameterList.
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
ConstIterator end() const
An iterator pointing beyond the last entry.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
T & get(const std::string &name, T def_value)
Return the parameter&#39;s value, or the default value if it is not there.
basic_FancyOStream< CharT, Traits > & o() const
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValues(const ParameterList &list1, const ParameterList &list2, bool verbose=false)
Returns true if two parameter lists have the same values.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void updateParametersFromXmlFile(const std::string &xmlFileName, const Ptr< ParameterList > &paramList)
Reads XML parameters from a file and updates those already in the given parameter list...
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
std::string getString(const ParameterEntry &entry, const std::string &paramName="", const std::string &sublistName="", const bool activeQuery=true) const
Get a std::string value from a parameter entry.
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Return a RCP to a sublist in another RCP-ed parameter list.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
Initialize, finalize, and query the global MPI session.
Simple helper functions that make it easy to read and write XML to and from a parameterlist.
basic_OSTab< char > OSTab
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
bool isParameter(const std::string &name) const
Whether the given parameter exists in this list.
bool remove(std::string const &name, bool throwIfNotExists=true)
Remove a parameter (does not depend on the type of the parameter).
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Set a boolean option.
double Plus(double a, double b)
double getDouble(const ParameterEntry &entry, const std::string &paramName="", const std::string &sublistName="", const bool activeQuery=true) const
Get a double value from a parameter entry. will call std::stod.
bool isSublist(const std::string &name) const
Whether the given sublist exists in this list.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void writeParameterListToXmlFile(const ParameterList &paramList, const std::string &xmlFileName, RCP< const DependencySheet > depSheet=null)
Write parameters and sublist to an XML file.
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
Parse a command line.
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
Validate the parameters in this list given valid selections in the input list and set defaults for th...
Ptr< T > inoutArg(T &arg)
create a non-persisting (required or optional) input/output argument for a function call...
ConstIterator begin() const
An iterator pointing to the first entry.
ParameterList::PrintOptions PLPrintOptions
bool isList() const
Return whether or not the value itself is a list.
std::string Teuchos_Version()
A list of parameters of arbitrary type.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Validate the parameters in this list given valid selections in the input list.
ParameterList & setParameters(const ParameterList &source)
int main(int argc, char *argv[])
const ParameterEntry & entry(ConstIterator i) const
Access to ParameterEntry (i.e., returns i-&gt;second)
int getInt(const ParameterEntry &entry, const std::string &paramName="", const std::string &sublistName="", const bool activeQuery=true) const
Get an integer value from a parameter entry. will call std::stoi Note that std::stoi throws on badly ...
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
size_type size() const
void unused(std::ostream &os) const
Print out unused parameters in the ParameterList.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Creates an empty sublist and returns a reference to the sublist name. If the list already exists...
Smart reference counting pointer class for automatic garbage collection.
RCP< basic_FancyOStream< CharT, Traits > > tab(const RCP< basic_FancyOStream< CharT, Traits > > &out, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
Create a tab for an RCP-wrapped basic_FancyOStream object to cause the indentation of all output auto...
std::string docString() const
Return the (optional) documentation std::string.
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
T * get() const
Get the raw C++ pointer to the underlying object.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void writeParameterListToXmlOStream(const ParameterList &paramList, std::ostream &xmlOut, RCP< const DependencySheet > depSheet=null)
Write parameters and sublists in XML format to an std::ostream.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void updateParametersFromXmlString(const std::string &xmlStr, const Ptr< ParameterList > &paramList, bool overwrite=true)
Reads XML parameters from a std::string and updates those already in the given parameter list...
Class that helps parse command line input arguments from (argc,argv[]) and set options.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...
Reference-counted smart pointer for managing arrays.