Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
parameterlist/test/ParameterList/cxx_main.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) 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 Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
45 #include "Teuchos_getConst.hpp"
46 #include "Teuchos_Version.hpp"
48 #include "Teuchos_FancyOStream.hpp"
49 #include "Teuchos_ArrayRCP.hpp"
51 
52 #ifdef HAVE_TEUCHOS_EXTENDED
54 #endif
55 
56 #ifdef HAVE_MPI
57 #include "mpi.h"
58 #endif
59 
62 using Teuchos::getParameter;
63 typedef ParameterList::PrintOptions PLPrintOptions;
65 using Teuchos::OSTab;
66 using Teuchos::rcp;
67 using Teuchos::inoutArg;
68 
69 void print_break() { std::cout << "---------------------------------------------------" << std::endl; }
70 double Plus ( double a, double b ) { return a+b; }
71 
72 int main( int argc, char *argv[] )
73 {
74 
75  using std::cout;
76  using std::endl;
77 
78  bool verbose = true;
79  int FailedTests = 0;
80  bool result;
81 
82  Teuchos::GlobalMPISession mpiSession(&argc,&argv);
83  const int procRank = Teuchos::GlobalMPISession::getRank();
84 
85  bool success = true;
86 
87  try {
88 
89  // Read options from the command line.
90  CommandLineProcessor clp(false); // Don't throw exceptions
91  clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
92  CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
93  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
94  cout << "Processor "<< procRank <<", parse_return "<< parse_return << std::endl;
95  cout << "End Result: TEST FAILED" << std::endl;
96  return parse_return;
97  }
98 
99  // Only print on 0 processor
100  if (procRank != 0 && verbose)
101  verbose = false;
102 
103  if (verbose)
104  cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
105 
106  //-----------------------------------------------------------
107  // Create Main Parameter List / Sublist Structure
108  //-----------------------------------------------------------
109 
110  ParameterList PL_Main("PL_Main");
111  const std::string Direction_Doc = "This sublist controls how direction is computed.";
112  ParameterList& PL_Direction = PL_Main.sublist("Direction",false,Direction_Doc);
113  ParameterList& PL_Newton = PL_Direction.sublist("Newton");
114  ParameterList& PL_LinSol = PL_Newton.sublist("Linear Solver");
115  ParameterList& PL_LineSearch = PL_Main.sublist("Line Search");
116 
117  //-----------------------------------------------------------
118  // Check Parameter List Structure
119  //-----------------------------------------------------------
120  if (verbose) {
121  print_break();
122  cout << "Empty Parameter List Structure" << std::endl;
123  print_break();
124  cout<<PL_Main<< std::endl;
125  }
126  if (verbose) cout << "Is 'Direction' recognized as a sublist of 'Main' ... ";
127  if ( PL_Main.isSublist( "Direction" ) ) {
128  if (verbose) cout << "yes"<< std::endl;
129  } else {
130  if (verbose) cout << "no"<< std::endl;
131  FailedTests++;
132  }
133  if (verbose) cout << "Is 'Newton' recognized as a sublist of 'Direction' ... ";
134  if ( PL_Direction.isSublist( "Newton" ) ) {
135  if (verbose) cout << "yes"<< std::endl;
136  } else {
137  if (verbose) cout << "no"<< std::endl;
138  FailedTests++;
139  }
140  if (verbose) cout << "Is 'Linear Solver' recognized as a sublist of 'Newton' ... ";
141  if ( PL_Newton.isSublist( "Linear Solver" ) ) {
142  if (verbose) cout << "yes"<< std::endl;
143  } else {
144  if (verbose) cout << "no"<< std::endl;
145  FailedTests++;
146  }
147  if (verbose) cout << "Is 'Line Search' recognized as a sublist of 'Main' ... ";
148  if ( PL_Main.isSublist( "Line Search" ) ) {
149  if (verbose) cout << "yes"<< std::endl;
150  } else {
151  if (verbose) cout << "no"<< std::endl;
152  FailedTests++;
153  }
154 
155  if (verbose) cout << "Is subist documentation std::string maintained ...\n";
156  {
157  Teuchos::OSTab tab(cout);
159  *paramEntry = PL_Main.getEntryPtr("Direction");
160  TEUCHOS_TEST_FOR_EXCEPT(0==paramEntry);
161  const std::string extracted_Direction_Doc = paramEntry->docString();
162  if (verbose) tab.o() << "Expected doc std::string = \"" << Direction_Doc << "\"\n";
163  if (verbose) tab.o() << "Extracted doc std::string = \"" << extracted_Direction_Doc << "\"\n";
164  if (extracted_Direction_Doc == Direction_Doc) {
165  if (verbose) tab.o() << "passed! They match :-)\n";
166  }
167  else {
168  if (verbose) tab.o() << "failed! They do not match :-("<< std::endl;
169  FailedTests++;
170  }
171  }
172 
173 
174  //-----------------------------------------------------------
175  // Fill in Direction Sublist
176  //-----------------------------------------------------------
177 
178  double tol = 0.0;
179  bool RBNS = false;
180  PL_Direction.get("Method", "Newton");
181  PL_LinSol.set("Tol",1e-5);
182  tol = PL_LinSol.get("Tolerance",1e-10);
183  (void)tol; // Not used, bad test!
184  RBNS = PL_Newton.get("Rescue Bad Newton Solve", true );
185  (void)RBNS; // Not used, bad test!
186 
187  //-----------------------------------------------------------
188  // Print out Direction Sublist
189  //-----------------------------------------------------------
190  if (verbose) {
191  print_break();
192  cout << "Direction Parameter List" << std::endl;
193  print_break();
194  PL_Direction.print(cout);
195  }
196  if (verbose) cout << "Is 'Newton' recognized as a parameter of 'Direction' ... ";
197  if ( PL_Direction.isParameter( "Newton" ) ) {
198  if (verbose) cout << "yes"<< std::endl;
199  } else {
200  if (verbose) cout << "no"<< std::endl;
201  FailedTests++;
202  }
203  if (verbose) cout << "Is 'Tolerance' recognized as a parameter of 'Newton' ... ";
204  if ( PL_Newton.isParameter( "Tolerance" ) ) {
205  if (verbose) cout << "yes (should be no)"<< std::endl;
206  FailedTests++;
207  } else {
208  if (verbose) cout << "no (as expected)"<< std::endl;
209  }
210  if (verbose) cout << "Is 'Tolerance' recognized as a parameter of 'Linear Solver' ... ";
211  if ( PL_LinSol.isParameter( "Tolerance" ) ) {
212  if (verbose) cout << "yes"<< std::endl;
213  } else {
214  if (verbose) cout << "no"<< std::endl;
215  FailedTests++;
216  }
217  if (verbose) cout << "Is 'Rescue Bad Newton Solve' recognized as a parameter of 'Newton' ... ";
218  if ( PL_Newton.isParameter( "Rescue Bad Newton Solve" ) ) {
219  if (verbose) cout << "yes"<< std::endl;
220  } else {
221  if (verbose) cout << "no"<< std::endl;
222  FailedTests++;
223  }
224 
225  //-----------------------------------------------------------
226  // Line Search Sublist
227  // (if there are no failures, this will be constructed and added)
228  //-----------------------------------------------------------
229  if (!FailedTests) {
230  int ARI = 0, default_step = 0, max_iter_inc = 0, rec_step = 0;
231  double alpha_factor = 0.0, min_bnds_factor = 0.0, max_bnds_factor = 0.0;
232  bool force_interp = true, use_cntrs = false;
233  std::string ls_method = "Polynomial";
234  // This is to force a char* to be passed into the get method to see if the template
235  // specialization for char* is working.
236  char* ls_method_char = const_cast<char *>(ls_method.c_str());
237  ParameterList PL_My_LineSearch("PL_My_LineSearch");
238  ls_method = PL_My_LineSearch.get("Method", ls_method_char);
239  ParameterList& PL_Polynomial = PL_My_LineSearch.sublist("Polynomial");
240  ARI = PL_Polynomial.get("Allowed Relative Increase", 100 );
241  (void)ARI; // Not used, bad test!
242  alpha_factor = PL_Polynomial.get("Alpha Factor", 0.0001 );
243  (void)alpha_factor; // Not used, bad test!
244  default_step = PL_Polynomial.get("Default Step", 1 );
245  (void)default_step; // Not used, bad test!
246  force_interp = PL_Polynomial.get("Force Interpolation", false );
247  (void)force_interp; // Not used, bad test!
248  std::string interp_type = PL_Polynomial.get("Interpolation Type", "Cubic" );
249  max_bnds_factor = PL_Polynomial.get("Max Bounds Factor", 0.5 );
250  (void)max_bnds_factor; // Not used, bad test!
251  PL_Polynomial.set("Max Iters", 3 );
252  max_iter_inc = PL_Polynomial.get("Maximum Iteration for Increase", 0 );
253  (void)max_iter_inc; // Not used, bad test!
254  min_bnds_factor = PL_Polynomial.get("Min Bounds Factor", 0.1 );
255  (void)min_bnds_factor; // Not used, bad test!
256  rec_step = PL_Polynomial.get("Recovery Step", 1 );
257  (void)rec_step; // Not used, bad test!
258  std::string rec_step_type = PL_Polynomial.get("Recovery Step Type", "Constant");
259  std::string suff_dec_cond = PL_Polynomial.get("Sufficient Decrease Condition", "Armijo-Goldstein" );
260  use_cntrs = PL_Polynomial.get("Use Counters", true );
261  (void)use_cntrs; // Not used, bad test!
262  PL_Main.set("Nonlinear Solver", "Line Search Based");
263 
264  //-----------------------------------------------------------
265  // Set the Line Search Parameter List equal to the one just constructed
266  //-----------------------------------------------------------
267  PL_LineSearch.setParameters(PL_My_LineSearch);
268  ParameterList& PL_My_Polynomial = PL_LineSearch.sublist("Polynomial");
269  if (verbose) cout<< "Is 'operator=' functional ... ";
270  if ( PL_My_Polynomial.isParameter("Recovery Step Type") ) {
271  if (verbose) cout<< "yes" << std::endl;
272  } else {
273  if (verbose) cout<< "no" << std::endl;
274  FailedTests++;
275  }
276 
277  //-----------------------------------------------------------
278  // Set Copying of parameter sublists and names
279  //-----------------------------------------------------------
280 
281  if (verbose) {
282  print_break();
283  if (verbose) cout << "Test copying of sublist\n";
284  print_break();
285  PL_Direction.print(cout);
286  }
287  {
288  const ParameterList
289  &linearSolverPL = PL_Main.sublist("Direction").sublist("Newton").sublist("Line Search");
290  const ParameterList
291  linearSolverPL_copy(linearSolverPL);
292  if (verbose) cout << "linearSolverPL.name() = " << linearSolverPL.name() << endl;
293  if (verbose) cout << "linearSolverPL_copy.name() = " << linearSolverPL_copy.name() << endl;
294  if (verbose) cout << "linearSolverPL_copy == linearSolverPL.name() : ";
295  if (linearSolverPL_copy == linearSolverPL.name()) {
296  if (verbose) cout << "passed" << endl;
297  }
298  else {
299  if (verbose) cout << "failed" << endl;
300  FailedTests++;
301  }
302  }
303 
304  if (verbose) {
305  print_break();
306  if (verbose) cout << "General tests\n";
307  print_break();
308  PL_Direction.print(cout);
309  }
310 
311  ParameterList Copied_PL_Main(PL_Main);
312 
313  if (verbose) cout << "Copied_PL_Main.name() == PL_Main.name() : ";
314  if (Copied_PL_Main.name() == PL_Main.name()) {
315  if (verbose) cout << "passed" << endl;
316  }
317  else {
318  if (verbose) cout << "failed" << endl;
319  FailedTests++;
320  if (verbose) cout << "Copyed_PL_Main.name() = " << Copied_PL_Main.name() << endl;
321  }
322 
323  if (verbose) cout<< "Is the copy constructor functional ... ";
324  if ( Copied_PL_Main.isParameter("Nonlinear Solver") ) {
325  if (verbose) cout<< "yes" << std::endl;
326  } else {
327  if (verbose) cout<< "no" << std::endl;
328  FailedTests++;
329  }
330 
331  bool tempMeth = true;
332 
333  //-----------------------------------------------------------
334  // Check the templated 'get' method.
335  //-----------------------------------------------------------
336  //
337  //-----------------------------------------------------------
338  // Retrieve some information from the parameter list using templated "get" method.
339  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
340  // non-templated code needs ".template" before the method name )
341  //-----------------------------------------------------------
342  int max_iters = 0, max_iters_again = 0;
343  std::string nonlin_solver;
344  tempMeth = true;
345  try {
346  max_iters = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER get<int>("Max Iters");
347  max_iters_again = Teuchos::getConst(PL_My_Polynomial).INVALID_TEMPLATE_QUALIFIER get<int>("Max Iters");
348  nonlin_solver = PL_Main.INVALID_TEMPLATE_QUALIFIER get<std::string>("Nonlinear Solver");
349  }
350  catch( const Teuchos::Exceptions::InvalidParameter&) { tempMeth = false; }
351  if (verbose) {
352  cout<< "Is the templated 'get' method functional ... "<<std::endl;
353  cout<< " Can we retrieve information using the CORRECT variable type ... ";
354  }
355  if (tempMeth && max_iters==3) { if (verbose) cout << "yes" << std::endl; }
356  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
357  if (verbose) {
358  cout<< " Can we retrieve const information using the CORRECT variable type ... ";
359  }
360  if (tempMeth && max_iters_again==3) { if (verbose) cout << "yes" << std::endl; }
361  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
362 
363  //-----------------------------------------------------------
364  // Retrieve some information from the parameter list that we know is a bad "get".
365  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
366  // non-templated code needs ".template" before the method name )
367  //-----------------------------------------------------------
368  float mbf = 0.0;
369  tempMeth = false;
370  try {
371  mbf = PL_LinSol.INVALID_TEMPLATE_QUALIFIER get<float>( "Tol" );
372  (void)mbf; // Not used, bad test!
373  FailedTests++;
374  }
376  tempMeth = true;
377  }
378  if (verbose) {
379  cout<< " Can we retrieve information using the WRONG variable type ... ";
380  }
381  if (tempMeth) { if (verbose) cout << "no" << std::endl; }
382  else { if (verbose) cout << "yes" << std::endl; }
383 
384  //-----------------------------------------------------------
385  // Retrieve some information from the parameter list using templated "get" method.
386  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
387  // non-templated code needs ".template" before the method name )
388  //-----------------------------------------------------------
389  tempMeth = true;
390  try {
391  max_iters = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER get<int>("Max Iters");
392  nonlin_solver = PL_Main.INVALID_TEMPLATE_QUALIFIER get<std::string>("Nonlinear Solver");
393  }
394  catch( const Teuchos::Exceptions::InvalidParameter&) { tempMeth = false; }
395  if (verbose) {
396  cout<< "Is the templated 'get' method functional ... "<<std::endl;
397  cout<< " Can we retrieve information using the CORRECT variable type ... ";
398  }
399  if (tempMeth && max_iters==3) { if (verbose) cout << "yes" << std::endl; }
400  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
401 
402  //-----------------------------------------------------------
403  // Retrieve some information from the parameter list that we know is a bad "get".
404  //-----------------------------------------------------------
405  tempMeth = false;
406  try {
407  mbf = PL_LinSol.INVALID_TEMPLATE_QUALIFIER get<float>( "Tol" );
408  (void)mbf; // Not used, bad test!
409  FailedTests++;
410  }
412  tempMeth = true;
413  }
414  if (verbose) {
415  cout<< " Can we retrieve information using the WRONG variable type ... ";
416  }
417  if (tempMeth) { if (verbose) cout << "no" << std::endl; }
418  else { if (verbose) cout << "yes" << std::endl; }
419 
420  //-----------------------------------------------------------
421  // Check the templated 'getPtr' method.
422  //-----------------------------------------------------------
423 
424  //-----------------------------------------------------------
425  // Retrieve some information from the parameter list using templated "get" method.
426  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
427  // non-templated code needs ".template" before the method name )
428  //-----------------------------------------------------------
429  int *max_iters_ptr = 0;
430  const int *max_iters_ptr_again = 0;
431  std::string* nonlin_solver_ptr;
432 
433  max_iters_ptr = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER getPtr<int>("Max Iters");
434  max_iters_ptr_again = Teuchos::getConst(PL_My_Polynomial).INVALID_TEMPLATE_QUALIFIER getPtr<int>("Max Iters");
435  nonlin_solver_ptr = PL_Main.INVALID_TEMPLATE_QUALIFIER getPtr<std::string>("Nonlinear Solver");
436 
437  if (verbose) {
438  cout<< "Is the templated 'getPtr' method functional ... "<<std::endl;
439  cout<< " Can we retrieve information using the CORRECT variable type ... ";
440  }
441  if (max_iters_ptr) {
442  if ((*max_iters_ptr)==3) {
443  if (verbose) cout << "yes" << std::endl;
444  }
445  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
446  }
447  if (verbose) {
448  cout<< " Can we retrieve const information using the CORRECT variable type ... ";
449  }
450  if (max_iters_ptr_again) {
451  if ((*max_iters_ptr_again)==3) {
452  if (verbose) cout << "yes" << std::endl;
453  }
454  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
455  }
456 
457  //-----------------------------------------------------------
458  // Retrieve some information from the parameter list that we know is a bad "get".
459  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
460  // non-templated code needs ".template" before the method name )
461  //-----------------------------------------------------------
462  float* mbf_ptr = 0;
463 
464  mbf_ptr = PL_LinSol.INVALID_TEMPLATE_QUALIFIER getPtr<float>( "Tol" );
465 
466  if (mbf_ptr)
467  ++FailedTests;
468 
469  if (verbose) {
470  cout<< " Can we retrieve information using the WRONG variable type ... ";
471  }
472  if (!mbf_ptr) { if (verbose) cout << "no" << std::endl; }
473  else { if (verbose) cout << "yes" << std::endl; }
474 
475  //-----------------------------------------------------------
476  // Retrieve some information from the parameter list using templated "get" method.
477  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
478  // non-templated code needs ".template" before the method name )
479  //-----------------------------------------------------------
480 
481  max_iters_ptr = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER getPtr<int>("Max Iters");
482  nonlin_solver_ptr = PL_Main.INVALID_TEMPLATE_QUALIFIER getPtr<std::string>("Nonlinear Solver");
483  (void)nonlin_solver_ptr; // Not used, bad test!
484 
485  if (verbose) {
486  cout<< "Is the templated 'getPtr' method functional ... "<<std::endl;
487  cout<< " Can we retrieve information using the CORRECT variable type ... ";
488  }
489  if (max_iters_ptr) {
490  if ((*max_iters_ptr)==3) {
491  if (verbose) cout << "yes" << std::endl;
492  }
493  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
494  }
495 
496  //-----------------------------------------------------------
497  // Retrieve some information from the parameter list that we know is a bad "get".
498  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
499  // non-templated code needs ".template" before the method name )
500  //-----------------------------------------------------------
501 
502  mbf_ptr = PL_LinSol.INVALID_TEMPLATE_QUALIFIER getPtr<float>( "Tol" );
503 
504  if (mbf_ptr)
505  ++FailedTests;
506 
507  if (verbose) {
508  cout<< " Can we retrieve information using the WRONG variable type ... ";
509  }
510  if (!mbf_ptr) { if (verbose) cout << "no" << std::endl; }
511  else { if (verbose) cout << "yes" << std::endl; }
512 
513  //-----------------------------------------------------------
514  // Check the 'getParameter' helper function.
515  //-----------------------------------------------------------
516  int def_step = 0;
517  double alpha_fact = 0.0;
518  tempMeth = true;
519  try {
520  def_step = Teuchos::getParameter<int>(PL_Polynomial, "Default Step");
521  alpha_fact = Teuchos::getParameter<double>(PL_Polynomial, "Alpha Factor");
522  (void)alpha_fact; // Not used, bad test!
523  }
524  catch( const Teuchos::Exceptions::InvalidParameter&) { tempMeth = false; }
525  if (verbose && def_step==1) {
526  cout<< "Is the helper function 'getParameter' functional ... ";
527  }
528  if (tempMeth) { if (verbose) cout << "yes" << std::endl; }
529  else { if (verbose) cout << "no" << std::endl; FailedTests++; }
530 
531  //-----------------------------------------------------------
532  // Check templated isType functionality
533  // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a
534  // non-templated code needs ".template" before the method name )
535  //-----------------------------------------------------------
536  bool PT1, PT2, PT3;
537  PT1 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<int>("Default Step");
538  PT2 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<long int>("Default Step");
539  PT3 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<std::string>("Interpolation Type");
540  if (verbose) {
541  cout<< "Is the templated 'isType' method functional ... "<<std::endl;
542  cout<< " Is the 'Default Step' of type 'int' ... ";
543  }
544  if (PT1) { if (verbose) cout<< "yes" << std::endl; }
545  else { if (verbose) cout<< "no" << std::endl; FailedTests++; }
546  if (verbose) {
547  cout<< " Is the 'Default Step' of type 'long int' ... ";
548  }
549  if (PT2) { if (verbose) cout<< "yes" << std::endl; FailedTests++; }
550  else { if (verbose) cout<< "no (as expected)" << std::endl; }
551  if (verbose) {
552  cout<< " Is the 'Interpolation Type' of type 'std::string' ... ";
553  }
554  if (PT3) { if (verbose) cout<< "yes" << std::endl; }
555  else { if (verbose) cout<< "no" << std::endl; FailedTests++; }
556 
557  //-----------------------------------------------------------
558  // Check the 'isParameterType' helper function.
559  //-----------------------------------------------------------
560  bool PT4, PT5;
561  PT4 = Teuchos::isParameterType<double>(PL_Polynomial, "Max Bounds Factor");
562  PT5 = Teuchos::isParameterType<float>(PL_Polynomial, "Max Bounds Factor");
563  if (verbose) {
564  cout<< "Is the helper function 'isParameterType' functional ... "<<std::endl;
565  cout<< " Is the 'Max Bounds Factor' of type 'double' ... ";
566  }
567  if (PT4) { if (verbose) cout<< "yes" <<std::endl; }
568  else { if (verbose) cout<< "no" << std::endl; FailedTests++; }
569  if (verbose) {
570  cout<< " Is the 'Max Bounds Factor' of type 'float' ... ";
571  }
572  if (PT5) { if (verbose) cout<< "yes" <<std::endl; FailedTests++; }
573  else { if (verbose) cout<< "no (as expected)" << std::endl; }
574 
575  //-----------------------------------------------------------
576  // Can we pass a pointer to a std::vector to the parameter list.
577  //-----------------------------------------------------------
578  Teuchos::ArrayRCP<double> tempvec1_arcp = Teuchos::arcp<double>(10);
579  {
580  double * tempvec1 = tempvec1_arcp.get();
581  for (int i=0; i<10; i++) { tempvec1[i] = i; }
582  PL_Main.set( "Address of Norm Vector", tempvec1 );
583  double* tempvec2 = Teuchos::getParameter<double*>( PL_Main, "Address of Norm Vector" );
584  tempvec1[4] = 2.0; tempvec1[6] = 1.0;
585  if (verbose) {
586  cout<< "Can we pass a pointer to a std::vector to a parameter list ... ";
587  }
588  if ((tempvec2[4]-tempvec1[4])!=0.0 || (tempvec2[6]-tempvec1[6])!=0.0) {
589  if (verbose) { cout<<"no"<<std::endl; }
590  FailedTests++;
591  } else {
592  if (verbose) { cout<<"yes"<<std::endl; }
593  }
594  }
595 
596  //-----------------------------------------------------------
597  // We can add Array<T> objects of various types T as std::string parameters!
598  //-----------------------------------------------------------
599  if(verbose) {
600  print_break();
601  cout << "Setting int and double array objects as std::string parameters ...\n";
602  print_break();
603  }
604  const Teuchos::Array<int>
605  intArray = Teuchos::tuple<int>(0,1,2,3,4,5,6);
607  doubleArray = Teuchos::tuple<double>(0,1.0,2.0,3.0,4.0,5.0,6.0);
608  //const Teuchos::Array<bool>
609  //boolArray = Teuchos::tuple<bool>(true,true,false,false);
610  Teuchos::setStringParameterFromArray("Int Array",intArray,&PL_Main);
611  Teuchos::setStringParameterFromArray("Double Array",doubleArray,&PL_Main);
612  //Teuchos::setStringParameterFromArray("Bool Array",boolArray,&PL_Main);
613  if(verbose) {
614  print_break();
615  cout << "Testing retrieval of set array objects ...\n";
616  print_break();
617  }
618  {
619 
620  const Teuchos::Array<int>
621  readIntArray = Teuchos::getArrayFromStringParameter<int>(PL_Main,"Int Array");
622  result = readIntArray == intArray;
623  if(!result) ++FailedTests;
624  if(verbose)
625  cout
626  << "readIntArray = " << readIntArray << " == intArray = " << intArray << " ? "
627  << (result ? "passed" : "failed")
628  << "\n";
629 
630  const Teuchos::Array<int>
631  readDoubleAsIntArray = Teuchos::getArrayFromStringParameter<int>(PL_Main,"Double Array");
632  result = readDoubleAsIntArray == intArray;
633  if(!result) ++FailedTests;
634  if(verbose)
635  cout
636  << "readDoubleAsIntArray = " << readDoubleAsIntArray << " == intArray = " << intArray << " ? "
637  << (result ? "passed" : "failed")
638  << "\n";
639 
640 /*
641  const Teuchos::Array<bool>
642  readBoolArray = Teuchos::getArrayFromStringParameter<bool>(PL_Main,"Bool Array");
643  result = readBoolArray == boolArray;
644  if(!result) ++FailedTests;
645  if(verbose)
646  cout
647  << "readBoolArray = " << readBoolArray << " == boolArray = " << boolArray << " ? "
648  << (result ? "passed" : "failed")
649  << "\n";
650 */
651 
652  if(verbose) {
653  print_break();
654  }
655 
656  }
657 
658  //-----------------------------------------------------------
659  // We can directly set the array strings!
660  //-----------------------------------------------------------
661 
662  if(verbose) {
663  print_break();
664  cout << "Setting a array of doubles as a std::string parameter directly ...\n";
665  print_break();
666  }
667 
668  PL_Main.set(
669  "Double Array"
670  ," {\n"
671  " 0.00000\n"
672  " ,1.0e0\n"
673  " ,0.2e1\n"
674  " ,30.0e-1\n"
675  " ,4\n"
676  " ,5.0000\n"
677  " ,6\n"
678  " }\n "
679  );
680 
681  {
682 
684  readDoubleArray = Teuchos::getArrayFromStringParameter<double>(PL_Main,"Double Array");
686  doubleAsIntArray(readDoubleArray.size());
687  for(int i=0;i<static_cast<int>(readDoubleArray.size());++i)
688  doubleAsIntArray[i] = static_cast<int>(readDoubleArray[i]);
689  result = doubleAsIntArray == intArray;
690  if(!result) ++FailedTests;
691  if(verbose)
692  cout
693  << "doubleAsIntArray = " << doubleAsIntArray << " == intArray = " << intArray << " ? "
694  << (result ? "passed" : "failed")
695  << "\n";
696 
697  if(verbose) {
698  print_break();
699  }
700 
701  }
702 
703  //-----------------------------------------------------------
704  // Can we pass a pointer to a function to the parameter list.
705  // Use a simple function, pass it in and get it back out ...
706  // ( HKT 03/23/2004 This test is not supported on Janus )
707  //-----------------------------------------------------------
708 #ifndef JANUS_STLPORT
709  double (*pt2Function) (double, double);
710  PL_Main.set( "Address to Simple Function", &Plus );
711  pt2Function = Teuchos::getParameter<double(*)(double,double)>( PL_Main, "Address to Simple Function" );
712  if (verbose) {
713  cout<< "Can we pass a pointer to a function to a parameter list ... ";
714  }
715  if ( pt2Function( 1.0, 2.0 ) != 3.0 ) {
716  if (verbose) cout<<"no"<<std::endl;
717  FailedTests++;
718  } else {
719  if (verbose) cout<<"yes"<<std::endl;
720  }
721 #endif
722  }
723 
724  //-----------------------------------------------------------
725  // We can store and retrieve void* pointers!
726  //-----------------------------------------------------------
727 
728  {
729  ParameterList pl;
730  int someInt = 1;
731  void *someIntPtr = &someInt;
732  pl.set("Some Pointer", someIntPtr);
733  void *someIntPtrRtn = getParameter<void*>(pl, "Some Pointer");
734  TEUCHOS_TEST_FOR_EXCEPT(someIntPtrRtn != someIntPtr);
735  if (verbose)
736  cout << "someIntPtrRtn = " << someIntPtrRtn << " == " << someIntPtr << " : ";
737  if (someIntPtrRtn == someIntPtr) {
738  if (verbose) cout << "passed\n";
739  }
740  else {
741  if (verbose) cout << "failed\n";
742  FailedTests++;
743  }
744  }
745 
746  //-----------------------------------------------------------
747  // Print using the public iterators
748  // KL - 7 August 2004
749  //-----------------------------------------------------------
750  ParameterList::ConstIterator iter;
751 
752  if (verbose)
753  {
754  print_break();
755  cout << " printing using public iterators "
756  << std::endl;
757  print_break();
758  }
759  for (iter = PL_Main.begin(); iter != PL_Main.end(); ++iter)
760  {
761  const ParameterEntry& val = PL_Main.entry(iter);
762  const std::string& name = PL_Main.name(iter);
763  if (val.isList())
764  {
765  if (verbose) cout << name << std::endl;
766  const ParameterList& sublist = Teuchos::getValue<ParameterList>(val);
767  ParameterList::ConstIterator i;
768  for (i=sublist.begin(); i != sublist.end(); ++i)
769  {
770  const std::string& nm = sublist.name(i);
771  const ParameterEntry& v = sublist.entry(i);
772  if (v.isList())
773  {
774  if (verbose) cout << " " << nm << std::endl;
775  if (verbose) Teuchos::getValue<ParameterList>(v).print(cout, 6);
776  }
777  else
778  {
779  if (verbose) cout << " " << nm << " " << v << std::endl;
780  }
781  }
782  }
783  else
784  {
785  if (verbose) cout << name << " " << val << std::endl;
786  }
787  }
788 
789 
790 #if defined(HAVE_TEUCHOS_EXTENDED)
791 
792  try {
793 
794  if (verbose) {
795 
796  print_break();
797  cout << "writing to XML std::ostream" << std::endl;
798  print_break();
799  writeParameterListToXmlOStream(PL_Main,cout);
800 
801  print_break();
802  cout << "writing to XML file" << std::endl;
803  print_break();
804  writeParameterListToXmlFile(PL_Main,"PL_Main.xml");
805 
806  print_break();
807  cout << "reading from XML file" << std::endl;
808  print_break();
809  ParameterList readBack;
810  updateParametersFromXmlFile("PL_Main.xml", inoutArg(readBack));
811  if (verbose) readBack.print(cout);
812 
813  print_break();
814  cout << "reading from XML std::string" << std::endl;
815  print_break();
816  std::ifstream xmlInFile("PL_Main.xml");
817  std::string xmlStr;
818  while(!xmlInFile.eof()) {
819  std::string line;
820  std::getline(xmlInFile,line);
821  xmlStr += line + "\n";
822  }
823  readBack = ParameterList();
824  updateParametersFromXmlString(xmlStr, inoutArg(readBack));
825  if (verbose) readBack.print(cout);
826 
827  }
828 
829  }
830  catch(const std::exception& e)
831  {
832  if(verbose) {
833  std::cerr << "caught std::exception:\n\n";
834  OSTab tab(std::cerr);
835  std::cerr << e.what() << std::endl;
836  }
837  FailedTests++;
838  }
839 
840 #endif // defined(HAVE_TEUCHOS_EXTENDED)
841 
842  //-----------------------------------------------------------
843  // Print out main list
844  //-----------------------------------------------------------
845 
846  if (verbose) {
847  print_break();
848  cout << "The Final Parameter List" << std::endl;
849  print_break();
850  PL_Main.print(cout);
851  print_break();
852  cout << "The unused parameters" << std::endl;
853  PL_Main.unused(cout);
854  }
855 
856  //-----------------------------------------------------------
857  // Show error outputs
858  //-----------------------------------------------------------
859 
860  if (verbose) {
861  print_break();
862  cout << "Accessing a sublist using the wrong name (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
863  print_break();
864  }
865  try {
866  PL_Main.sublist("Direction").sublist("Newton").sublist("Linear Solvers",true);
867  if (verbose) cout << "Did not throw std::exception, error!\n";
868  ++FailedTests;
869  }
871  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
872  OSTab tab(std::cerr);
873  std::cerr << e.what() << std::endl;
874  }
875  if (verbose) {
876  print_break();
877  cout << "Accessing a parameter using the wrong name (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
878  print_break();
879  }
880  try {
881  Teuchos::getParameter<int>(PL_Main.sublist("Direction").sublist("Newton").sublist("Linear Solver"),"Tolerances");
882  if (verbose) cout << "Did not throw std::exception, error!\n";
883  ++FailedTests;
884  }
886  if(verbose) {
887  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
888  OSTab tab(std::cerr);
889  std::cerr << e.what() << std::endl;
890  }
891  }
892  catch(const std::exception &e) {
893  if(verbose) {
894  std::cerr << "caught unexpected std::exception:\n\n";
895  OSTab tab(std::cerr);
896  std::cerr << e.what() << std::endl;
897  }
898  ++FailedTests;
899  }
900 
901  if (verbose) {
902  print_break();
903  cout << "Accessing a parameter using the wrong parameter type (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
904  print_break();
905  }
906  try {
907  Teuchos::getParameter<int>(PL_Main.sublist("Direction").sublist("Newton").sublist("Linear Solver"),"Tolerance");
908  if (verbose) cout << "Did not throw std::exception, error!\n";
909  ++FailedTests;
910  }
912  if(verbose) {
913  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
914  OSTab tab(std::cerr);
915  std::cerr << e.what() << std::endl;
916  }
917  }
918  catch(const std::exception &e) {
919  if(verbose) {
920  std::cerr << "caught unexpected std::exception:\n\n";
921  OSTab tab(std::cerr);
922  std::cerr << e.what() << std::endl;
923  }
924  ++FailedTests;
925  }
926 
927  //-----------------------------------------------------------
928  // Validate the parameter list
929  //-----------------------------------------------------------
930 
931  // Create a validator version of PL_Main that we will validate against!
932  Teuchos::ParameterList PL_Main_valid("PL_Main_copy");
933  PL_Main_valid.setParameters(PL_Main);
934 
935  // Create a validator for the "Nonlinear Solver" parameter
936  Teuchos::setStringToIntegralParameter<int>(
937  "Nonlinear Solver", "Line Search Based",
938  "Selects the type of nonlinear solver to use",
939  Teuchos::tuple<std::string>("Line Search Based","Trust Region Based"),
940  &PL_Main
941  );
942 
943 /*
944  Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
945  nonlinearSolverValidator = rcp(
946  new Teuchos::StringToIntegralParameterEntryValidator<int>(
947  Teuchos::tuple<std::string>("Line Search Based","Trust Region Based")
948  ,"Nonlinear Solver"
949  )
950  );
951  PL_Main_valid.set(
952  "Nonlinear Solver", "Line Search Based"
953  ,"Selects the type of nonlinear solver to use"
954  ,nonlinearSolverValidator
955  );
956 */
957 
958  // Create a validator for the parameter "Line Search"->"Polynomial"->"Max Iters"
959  // that accepts an 'int', a 'double' or a 'std::string' value!
962  linesearchMaxItersValiator = rcp(
965  AcceptedTypes(false).allowInt(true).allowDouble(true).allowString(true)
966  )
967  );
968  PL_Main_valid.sublist("Line Search").sublist("Polynomial").set(
969  "Max Iters",3
970  ,"The maximum number of inner linear search iterations allowed."
971  ,linesearchMaxItersValiator
972  );
973 
974  // Create a validator for the parameter "Direction"->"Newton"->"Linear Solver"->"Tol"
975  // that accepts a 'double' or a 'std::string' value!
978  linSolveTolValidator = rcp(
981  AcceptedTypes(false).allowDouble(true).allowString(true)
982  )
983  );
984  PL_Main_valid.sublist("Direction",true).sublist("Newton",true)
985  .sublist("Linear Solver",true).set(
986  "Tol", double(1e-5)
987  ,"Select the linear solve tolerance"
988  ,linSolveTolValidator
989  );
990 
991  if (verbose) {
992  print_break();
993  cout << "Validating the parameter list against itself (should not throw std::exception)...\n";
994  print_break();
995  }
996  try {
997  PL_Main.validateParameters(PL_Main_valid);
998  if (verbose) cout << "Did not throw std::exception, success!\n\n";
999  }
1000  catch(const std::exception &e) {
1001  if(verbose) {
1002  std::cerr << "caught unexpected std::exception:\n\n";
1003  OSTab tab(std::cerr);
1004  std::cerr << e.what() << std::endl;
1005  }
1006  ++FailedTests;
1007  }
1008 
1009  if (verbose) {
1010  print_break();
1011  cout << "Adding an invalid parameter type then validating (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
1012  print_break();
1013  }
1014  try {
1015  PL_Main.sublist("Line Search").sublist("Polynomial").set("Max Iters",(short int)(3)); // Should be an int!
1016  PL_Main.validateParameters(PL_Main_valid);
1017  if (verbose) cout << "Did not throw std::exception, error!\n";
1018  ++FailedTests;
1019  }
1021  if(verbose) {
1022  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
1023  OSTab tab(std::cerr);
1024  std::cerr << e.what() << std::endl;
1025  }
1026  }
1027  catch(const std::exception &e) {
1028  if(verbose) {
1029  std::cerr << "caught unexpected std::exception:\n\n";
1030  OSTab tab(std::cerr);
1031  std::cerr << e.what() << std::endl;
1032  }
1033  ++FailedTests;
1034  }
1035  PL_Main.sublist("Line Search").sublist("Polynomial").set("Max Iters",3); // Put back the valid int!
1036 
1037  if (verbose) {
1038  print_break();
1039  cout << "Adding an invalid parameter name then validating (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
1040  print_break();
1041  }
1042  try {
1043  PL_Main.sublist("Line Search").sublist("Polynomial").set("Max Iter",10);
1044  PL_Main.validateParameters(PL_Main_valid);
1045  if (verbose) cout << "Did not throw std::exception, error!\n";
1046  ++FailedTests;
1047  }
1049  if(verbose) {
1050  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
1051  OSTab tab(std::cerr);
1052  std::cerr << e.what() << std::endl;
1053  }
1054  }
1055  catch(const std::exception &e) {
1056  if(verbose) {
1057  std::cerr << "caught unexpected std::exception:\n\n";
1058  OSTab tab(std::cerr);
1059  std::cerr << e.what() << std::endl;
1060  }
1061  ++FailedTests;
1062  }
1063  PL_Main.sublist("Line Search").sublist("Polynomial").remove("Max Iter");
1064 
1065  if (verbose) {
1066  print_break();
1067  cout << "Adding an invalid parameter type then validating using validator (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
1068  print_break();
1069  }
1070  try {
1071  PL_Main.set("Nonlinear Solver",int(0)); // Should be a std::string!
1072  PL_Main.validateParameters(PL_Main_valid);
1073  if (verbose) cout << "Did not throw std::exception, error!\n";
1074  ++FailedTests;
1075  }
1077  if(verbose) {
1078  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
1079  OSTab tab(std::cerr);
1080  std::cerr << e.what() << std::endl;
1081  }
1082  }
1083  catch(const std::exception &e) {
1084  if(verbose) {
1085  std::cerr << "caught unexpected std::exception:\n\n";
1086  OSTab tab(std::cerr);
1087  std::cerr << e.what() << std::endl;
1088  }
1089  ++FailedTests;
1090  }
1091  PL_Main.set("Nonlinear Solver","Line Search Based"); // Put back the valid value!
1092 
1093  if (verbose) {
1094  print_break();
1095  cout << "Adding an invalid parameter value then validating using validator (should throw a Teuchos::Exceptions::InvalidParameterValue std::exception)...\n";
1096  print_break();
1097  }
1098  try {
1099  PL_Main.set("Nonlinear Solver","LineSearch Based"); // Should be "Line Search Based"!
1100  PL_Main.validateParameters(PL_Main_valid);
1101  if (verbose) cout << "Did not throw std::exception, error!\n";
1102  ++FailedTests;
1103  }
1105  if(verbose) {
1106  std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterValue:\n\n";
1107  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1108  }
1109  }
1110  catch(const std::exception &e) {
1111  if(verbose) {
1112  std::cerr << "caught unexpected std::exception:\n\n";
1113  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1114  }
1115  ++FailedTests;
1116  }
1117  PL_Main.set("Nonlinear Solver","Line Search Based"); // Put back the valid value!
1118 
1119  if (verbose) {
1120  print_break();
1121  cout << "Use the validator to access integral value (should *not* throw std::exception)...\n";
1122  print_break();
1123  }
1124  try {
1125  const int
1126  nonlinearSolverValue = Teuchos::getIntegralValue<int>(PL_Main,"Nonlinear Solver");
1127  const bool
1128  l_result = (nonlinearSolverValue == 0);
1129  cout
1130  << "Read value = " << nonlinearSolverValue << " == 0 : "
1131  << ( l_result ? "passed" : "failed") << "\n";
1132  if(!l_result) ++FailedTests;
1133  }
1134  catch(const std::exception &e) {
1135  if(verbose) {
1136  std::cerr << "caught unexpected std::exception:\n\n";
1137  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1138  }
1139  ++FailedTests;
1140  }
1141 
1142  if (verbose) {
1143  print_break();
1144  cout << "Use the validator to access std::string value (should *not* throw std::exception)...\n";
1145  print_break();
1146  }
1147  try {
1148  const std::string
1149  nonlinearSolverValue = Teuchos::getStringValue<int>(PL_Main,"Nonlinear Solver");
1150  const bool
1151  l_result = (nonlinearSolverValue == "Line Search Based");
1152  cout
1153  << "Read value = \"" << nonlinearSolverValue << " == \"Line Search Based\" : "
1154  << ( l_result ? "passed" : "failed") << "\n";
1155  if(!l_result) ++FailedTests;
1156  }
1157  catch(const std::exception &e) {
1158  if(verbose) {
1159  std::cerr << "caught unexpected std::exception:\n\n";
1160  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1161  }
1162  ++FailedTests;
1163  }
1164 
1165  //-----------------------------------------------------------
1166  // Validate and set defaults
1167  //-----------------------------------------------------------
1168 
1169  // Set the default parameters for an emplty list
1170  ParameterList validatedPL;
1171 
1172  if (verbose) {
1173  print_break();
1174  cout << "Validating and setting defaults for an empty parameter list (should not throw) ...\n";
1175  print_break();
1176  }
1177  try {
1178  validatedPL.validateParametersAndSetDefaults(PL_Main_valid);
1179  if (verbose) cout << "Did not throw std::exception, success!\n\n";
1180  }
1181  catch(const std::exception &e) {
1182  if(verbose) {
1183  std::cerr << "caught unexpected std::exception:\n\n";
1184  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1185  }
1186  ++FailedTests;
1187  }
1188 
1189  if (verbose) {
1190  print_break();
1191  cout << "Parameter list with defaults set:" << std::endl;
1192  print_break();
1193  validatedPL.print(cout,PLPrintOptions().showTypes(true).showDoc(true));
1194  print_break();
1195  }
1196 
1197  if (verbose) {
1198  print_break();
1199  cout << "Checking that validatedPL and PL_Main_valid have the same values : ";
1200  }
1201  result = haveSameValues(validatedPL,PL_Main_valid);
1202  if(!result)
1203  ++FailedTests;
1204  if (verbose) {
1205  cout << ( result ? "passed" : "failed" ) << "\n";
1206  print_break();
1207  }
1208 
1209  //
1210  // Testing access of numbers using validator where validator is not buried
1211  // in the parameter
1212  //
1213 
1214  for( int type_i = 0; type_i < 3; ++type_i ) {
1215 
1216  ParameterList &Polynomial_sublist
1217  = PL_Main.sublist("Line Search",true).sublist("Polynomial",true);
1218 
1219  std::string typeName;
1220 
1221  // Set the input type
1222 
1223  switch(type_i) {
1224  case 0:
1225  typeName = "int";
1226  Polynomial_sublist.set("Max Iters",(int)(3));
1227  break;
1228  case 1:
1229  typeName = "double";
1230  Polynomial_sublist.set("Max Iters",(double)(3.0));
1231  break;
1232  case 2:
1233  typeName = "std::string";
1234  Polynomial_sublist.set("Max Iters",(std::string)("3"));
1235  break;
1236  default:
1238  }
1239 
1240  // Extract using external validator
1241 
1242  if (verbose) {
1243  print_break();
1244  cout << "Use the external number validator to access a "<<typeName<<" as an int ...\n";
1245  print_break();
1246  }
1247  try {
1248  const int
1249  lineserchMaxIters
1250  = linesearchMaxItersValiator->getInt(
1251  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1252  ,"Max Iters",0
1253  );
1254  const bool
1255  l_result = (lineserchMaxIters == int(3));
1256  cout
1257  << "Read value = " << lineserchMaxIters << " == 3 : "
1258  << ( l_result ? "passed" : "failed") << "\n";
1259  if(!l_result) ++FailedTests;
1260  }
1261  catch(const std::exception &e) {
1262  if(verbose) {
1263  std::cerr << "caught unexpected std::exception:\n\n";
1264  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1265  }
1266  ++FailedTests;
1267  }
1268 
1269  if (verbose) {
1270  print_break();
1271  cout << "Use the external number validator to access a "<<typeName<<" as a double ...\n";
1272  print_break();
1273  }
1274  try {
1275  const double
1276  lineserchMaxIters
1277  = linesearchMaxItersValiator->getDouble(
1278  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1279  ,"Max Iters",0.0
1280  );
1281  const bool
1282  l_result = (lineserchMaxIters == double(3.0));
1283  cout
1284  << "Read value = " << lineserchMaxIters << " == 3 : "
1285  << ( l_result ? "passed" : "failed") << "\n";
1286  if(!l_result) ++FailedTests;
1287  }
1288  catch(const std::exception &e) {
1289  if(verbose) {
1290  std::cerr << "caught unexpected std::exception:\n\n";
1291  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1292  }
1293  ++FailedTests;
1294  }
1295 
1296  if (verbose) {
1297  print_break();
1298  cout << "Use the external number validator to access a "<<typeName<<" as a std::string ...\n";
1299  print_break();
1300  }
1301  try {
1302  const std::string
1303  lineserchMaxIters
1304  = linesearchMaxItersValiator->getString(
1305  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1306  ,"Max Iters","0"
1307  );
1308  const bool
1309  l_result = (lineserchMaxIters == "3");
1310  cout
1311  << "Read value = \"" << lineserchMaxIters << "\" == \"3\" : "
1312  << ( l_result ? "passed" : "failed") << "\n";
1313  if(!l_result) ++FailedTests;
1314  }
1315  catch(const std::exception &e) {
1316  if(verbose) {
1317  std::cerr << "caught unexpected std::exception:\n\n";
1318  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1319  }
1320  ++FailedTests;
1321  }
1322 
1323  // Extract using nonmember functions
1324 
1325  if (verbose) {
1326  print_break();
1327  cout << "Use the nomember help function to access a "<<typeName<<" as an int ...\n";
1328  print_break();
1329  }
1330  try {
1331  const int
1332  lineserchMaxIters
1333  = Teuchos::getIntParameter(
1334  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1335  ,"Max Iters"
1336  );
1337  const bool
1338  l_result = (lineserchMaxIters == int(3));
1339  cout
1340  << "Read value = " << lineserchMaxIters << " == 3 : "
1341  << ( l_result ? "passed" : "failed") << "\n";
1342  if(!l_result) ++FailedTests;
1343  }
1344  catch(const std::exception &e) {
1345  if(verbose) {
1346  std::cerr << "caught unexpected std::exception:\n\n";
1347  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1348  }
1349  ++FailedTests;
1350  }
1351 
1352  if (verbose) {
1353  print_break();
1354  cout << "Use the nomember help function to access a "<<typeName<<" as a double ...\n";
1355  print_break();
1356  }
1357  try {
1358  const double
1359  lineserchMaxIters
1360  = Teuchos::getDoubleParameter(
1361  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1362  ,"Max Iters"
1363  );
1364  const bool
1365  l_result = (lineserchMaxIters == double(3.0));
1366  cout
1367  << "Read value = " << lineserchMaxIters << " == 3 : "
1368  << ( l_result ? "passed" : "failed") << "\n";
1369  if(!l_result) ++FailedTests;
1370  }
1371  catch(const std::exception &e) {
1372  if(verbose) {
1373  std::cerr << "caught unexpected std::exception:\n\n";
1374  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1375  }
1376  ++FailedTests;
1377  }
1378 
1379  if (verbose) {
1380  print_break();
1381  cout << "Use the nomember help function to access a "<<typeName<<" as a std::string ...\n";
1382  print_break();
1383  }
1384  try {
1385  const std::string
1386  lineserchMaxIters
1387  = Teuchos::getNumericStringParameter(
1388  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1389  ,"Max Iters"
1390  );
1391  const bool
1392  l_result = (lineserchMaxIters == "3");
1393  cout
1394  << "Read value = \"" << lineserchMaxIters << "\" == \"3\" : "
1395  << ( l_result ? "passed" : "failed") << "\n";
1396  if(!l_result) ++FailedTests;
1397  }
1398  catch(const std::exception &e) {
1399  if(verbose) {
1400  std::cerr << "caught unexpected std::exception:\n\n";
1401  OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1402  }
1403  ++FailedTests;
1404  }
1405 
1406  }
1407 
1408  //
1409  // Testing access of numbers using validator where validator is buried in
1410  // the parameter
1411  //
1412 
1413  for( int type_i = 0; type_i < 3; ++type_i ) {
1414 
1415  ParameterList &Polynomial_sublist
1416  = PL_Main.sublist("Line Search",true).sublist("Polynomial",true);
1417 
1418  std::string typeName;
1419 
1420  // Set the input type
1421 
1422  switch(type_i) {
1423  case 0:
1424  typeName = "int";
1425  Teuchos::setIntParameter("Max Iters",3,"",&Polynomial_sublist);
1426  break;
1427  case 1:
1428  typeName = "double";
1429  Teuchos::setDoubleParameter("Max Iters",3.0,"",&Polynomial_sublist);
1430  break;
1431  case 2:
1432  typeName = "std::string";
1433  Teuchos::setNumericStringParameter("Max Iters","3","",&Polynomial_sublist);
1434  break;
1435  default:
1437  }
1438 
1439  // Extract using nonmember functions (which should use the internal validator)
1440 
1441  if (verbose) {
1442  print_break();
1443  cout << "Use the nomember help function to access a "<<typeName<<" as an int ...\n";
1444  print_break();
1445  }
1446  try {
1447  const int
1448  lineserchMaxIters
1449  = Teuchos::getIntParameter(
1450  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1451  ,"Max Iters"
1452  );
1453  const bool
1454  l_result = (lineserchMaxIters == int(3));
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 double ...\n";
1471  print_break();
1472  }
1473  try {
1474  const double
1475  lineserchMaxIters
1476  = Teuchos::getDoubleParameter(
1477  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1478  ,"Max Iters"
1479  );
1480  const bool
1481  l_result = (lineserchMaxIters == double(3.0));
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 a std::string ...\n";
1498  print_break();
1499  }
1500  try {
1501  const std::string
1502  lineserchMaxIters
1503  = Teuchos::getNumericStringParameter(
1504  PL_Main.sublist("Line Search",true).sublist("Polynomial",true)
1505  ,"Max Iters"
1506  );
1507  const bool
1508  l_result = (lineserchMaxIters == "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 
T * get() const
Get the raw C++ pointer to the underlying object.
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...
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
int main(int argc, char *argv[])
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValues(const ParameterList &list1, const ParameterList &list2)
Returns true if two parameter lists have the same values.
ConstIterator begin() const
An iterator pointing to the first entry.
T & get(const std::string &name, T def_value)
Return the parameter&#39;s value, or the default value if it is not there.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Set a parameter whose value has type T.
This object is held as the "value" in the Teuchos::ParameterList std::map.
const ParameterEntry & entry(ConstIterator i) const
Access to ParameterEntry (i.e., returns i->second)
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...
bool isSublist(const std::string &name) const
Whether the given sublist exists in this list.
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
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.
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. HAVE_TEUCHOSCORE_CXX11 will call std::stoi otherwise we ...
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.
void unused(std::ostream &os) const
Print out unused parameters in the ParameterList.
basic_OSTab< char > OSTab
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.
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
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.
ConstIterator end() const
An iterator pointing beyond the last entry.
void print() const
Print function to use in debugging in a debugger.
bool remove(std::string const &name, bool throwIfNotExists=true)
Remove a parameter (does not depend on the type of the parameter).
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.
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)
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.
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
Parse a command line.
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
size_type size() const
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...
bool isList() const
Return whether or not the value itself is a list.
ParameterList::PrintOptions PLPrintOptions
std::string Teuchos_Version()
A list of parameters of arbitrary type.
ParameterList & setParameters(const ParameterList &source)
const std::string & name() const
The name of this ParameterList.
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
bool isParameter(const std::string &name) const
Whether the given parameter exists in this list.
std::string docString() const
Return the (optional) documentation std::string.
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...
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
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.