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