52 #ifdef HAVE_TEUCHOS_EXTENDED 63 using Teuchos::getParameter;
68 using Teuchos::inoutArg;
70 void print_break() { std::cout <<
"---------------------------------------------------" << std::endl; }
71 double Plus (
double a,
double b ) {
return a+b; }
73 int main(
int argc,
char *argv[] )
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;
101 if (procRank != 0 && verbose)
112 const std::string Direction_Doc =
"This sublist controls how direction is computed.";
123 cout <<
"Empty Parameter List Structure" << std::endl;
125 cout<<PL_Main<< std::endl;
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;
131 if (verbose) cout <<
"no"<< std::endl;
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;
138 if (verbose) cout <<
"no"<< std::endl;
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;
145 if (verbose) cout <<
"no"<< std::endl;
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;
152 if (verbose) cout <<
"no"<< std::endl;
156 if (verbose) cout <<
"Is subist documentation std::string maintained ...\n";
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";
169 if (verbose)
tab.o() <<
"failed! They do not match :-("<< std::endl;
181 PL_Direction.
get(
"Method",
"Newton");
182 PL_LinSol.
set(
"Tol",1e-5);
183 tol = PL_LinSol.
get(
"Tolerance",1e-10);
185 RBNS = PL_Newton.
get(
"Rescue Bad Newton Solve",
true );
193 cout <<
"Direction Parameter List" << std::endl;
195 PL_Direction.
print(cout);
197 if (verbose) cout <<
"Is 'Newton' recognized as a parameter of 'Direction' ... ";
199 if (verbose) cout <<
"yes"<< std::endl;
201 if (verbose) cout <<
"no"<< std::endl;
204 if (verbose) cout <<
"Is 'Tolerance' recognized as a parameter of 'Newton' ... ";
206 if (verbose) cout <<
"yes (should be no)"<< std::endl;
209 if (verbose) cout <<
"no (as expected)"<< std::endl;
211 if (verbose) cout <<
"Is 'Tolerance' recognized as a parameter of 'Linear Solver' ... ";
213 if (verbose) cout <<
"yes"<< std::endl;
215 if (verbose) cout <<
"no"<< std::endl;
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;
222 if (verbose) cout <<
"no"<< std::endl;
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";
237 char* ls_method_char =
const_cast<char *
>(ls_method.c_str());
239 ls_method = PL_My_LineSearch.
get(
"Method", ls_method_char);
241 ARI = PL_Polynomial.
get(
"Allowed Relative Increase", 100 );
243 alpha_factor = PL_Polynomial.
get(
"Alpha Factor", 0.0001 );
245 default_step = PL_Polynomial.
get(
"Default Step", 1 );
247 force_interp = PL_Polynomial.
get(
"Force Interpolation",
false );
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;
252 PL_Polynomial.
set(
"Max Iters", 3 );
253 max_iter_inc = PL_Polynomial.
get(
"Maximum Iteration for Increase", 0 );
255 min_bnds_factor = PL_Polynomial.
get(
"Min Bounds Factor", 0.1 );
256 (void)min_bnds_factor;
257 rec_step = PL_Polynomial.
get(
"Recovery Step", 1 );
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 );
263 PL_Main.
set(
"Nonlinear Solver",
"Line Search Based");
270 if (verbose) cout<<
"Is 'operator=' functional ... ";
271 if ( PL_My_Polynomial.
isParameter(
"Recovery Step Type") ) {
272 if (verbose) cout<<
"yes" << std::endl;
274 if (verbose) cout<<
"no" << std::endl;
284 if (verbose) cout <<
"Test copying of sublist\n";
286 PL_Direction.
print(cout);
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;
300 if (verbose) cout <<
"failed" << endl;
307 if (verbose) cout <<
"General tests\n";
309 PL_Direction.
print(cout);
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;
319 if (verbose) cout <<
"failed" << endl;
321 if (verbose) cout <<
"Copyed_PL_Main.name() = " << Copied_PL_Main.
name() << endl;
324 if (verbose) cout<<
"Is the copy constructor functional ... ";
325 if ( Copied_PL_Main.
isParameter(
"Nonlinear Solver") ) {
326 if (verbose) cout<<
"yes" << std::endl;
328 if (verbose) cout<<
"no" << std::endl;
332 bool tempMeth =
true;
343 int max_iters = 0, max_iters_again = 0;
344 std::string nonlin_solver;
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");
353 cout<<
"Is the templated 'get' method functional ... "<<std::endl;
354 cout<<
" Can we retrieve information using the CORRECT variable type ... ";
356 if (tempMeth && max_iters==3) {
if (verbose) cout <<
"yes" << std::endl; }
357 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
359 cout<<
" Can we retrieve const information using the CORRECT variable type ... ";
361 if (tempMeth && max_iters_again==3) {
if (verbose) cout <<
"yes" << std::endl; }
362 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
372 mbf = PL_LinSol.INVALID_TEMPLATE_QUALIFIER get<float>(
"Tol" );
380 cout<<
" Can we retrieve information using the WRONG variable type ... ";
382 if (tempMeth) {
if (verbose) cout <<
"no" << std::endl; }
383 else {
if (verbose) cout <<
"yes" << std::endl; }
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");
397 cout<<
"Is the templated 'get' method functional ... "<<std::endl;
398 cout<<
" Can we retrieve information using the CORRECT variable type ... ";
400 if (tempMeth && max_iters==3) {
if (verbose) cout <<
"yes" << std::endl; }
401 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
408 mbf = PL_LinSol.INVALID_TEMPLATE_QUALIFIER get<float>(
"Tol" );
416 cout<<
" Can we retrieve information using the WRONG variable type ... ";
418 if (tempMeth) {
if (verbose) cout <<
"no" << std::endl; }
419 else {
if (verbose) cout <<
"yes" << std::endl; }
430 int *max_iters_ptr = 0;
431 const int *max_iters_ptr_again = 0;
432 std::string* nonlin_solver_ptr;
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");
439 cout<<
"Is the templated 'getPtr' method functional ... "<<std::endl;
440 cout<<
" Can we retrieve information using the CORRECT variable type ... ";
443 if ((*max_iters_ptr)==3) {
444 if (verbose) cout <<
"yes" << std::endl;
446 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
449 cout<<
" Can we retrieve const information using the CORRECT variable type ... ";
451 if (max_iters_ptr_again) {
452 if ((*max_iters_ptr_again)==3) {
453 if (verbose) cout <<
"yes" << std::endl;
455 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
465 mbf_ptr = PL_LinSol.INVALID_TEMPLATE_QUALIFIER getPtr<float>(
"Tol" );
471 cout<<
" Can we retrieve information using the WRONG variable type ... ";
473 if (!mbf_ptr) {
if (verbose) cout <<
"no" << std::endl; }
474 else {
if (verbose) cout <<
"yes" << std::endl; }
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;
487 cout<<
"Is the templated 'getPtr' method functional ... "<<std::endl;
488 cout<<
" Can we retrieve information using the CORRECT variable type ... ";
491 if ((*max_iters_ptr)==3) {
492 if (verbose) cout <<
"yes" << std::endl;
494 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
503 mbf_ptr = PL_LinSol.INVALID_TEMPLATE_QUALIFIER getPtr<float>(
"Tol" );
509 cout<<
" Can we retrieve information using the WRONG variable type ... ";
511 if (!mbf_ptr) {
if (verbose) cout <<
"no" << std::endl; }
512 else {
if (verbose) cout <<
"yes" << std::endl; }
518 double alpha_fact = 0.0;
521 def_step = Teuchos::getParameter<int>(PL_Polynomial,
"Default Step");
522 alpha_fact = Teuchos::getParameter<double>(PL_Polynomial,
"Alpha Factor");
526 if (verbose && def_step==1) {
527 cout<<
"Is the helper function 'getParameter' functional ... ";
529 if (tempMeth) {
if (verbose) cout <<
"yes" << std::endl; }
530 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
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");
542 cout<<
"Is the templated 'isType' method functional ... "<<std::endl;
543 cout<<
" Is the 'Default Step' of type 'int' ... ";
545 if (PT1) {
if (verbose) cout<<
"yes" << std::endl; }
546 else {
if (verbose) cout<<
"no" << std::endl; FailedTests++; }
548 cout<<
" Is the 'Default Step' of type 'long int' ... ";
550 if (PT2) {
if (verbose) cout<<
"yes" << std::endl; FailedTests++; }
551 else {
if (verbose) cout<<
"no (as expected)" << std::endl; }
553 cout<<
" Is the 'Interpolation Type' of type 'std::string' ... ";
555 if (PT3) {
if (verbose) cout<<
"yes" << std::endl; }
556 else {
if (verbose) cout<<
"no" << std::endl; FailedTests++; }
562 PT4 = Teuchos::isParameterType<double>(PL_Polynomial,
"Max Bounds Factor");
563 PT5 = Teuchos::isParameterType<float>(PL_Polynomial,
"Max Bounds Factor");
565 cout<<
"Is the helper function 'isParameterType' functional ... "<<std::endl;
566 cout<<
" Is the 'Max Bounds Factor' of type 'double' ... ";
568 if (PT4) {
if (verbose) cout<<
"yes" <<std::endl; }
569 else {
if (verbose) cout<<
"no" << std::endl; FailedTests++; }
571 cout<<
" Is the 'Max Bounds Factor' of type 'float' ... ";
573 if (PT5) {
if (verbose) cout<<
"yes" <<std::endl; FailedTests++; }
574 else {
if (verbose) cout<<
"no (as expected)" << std::endl; }
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;
587 cout<<
"Can we pass a pointer to a std::vector to a parameter list ... ";
589 if ((tempvec2[4]-tempvec1[4])!=0.0 || (tempvec2[6]-tempvec1[6])!=0.0) {
590 if (verbose) { cout<<
"no"<<std::endl; }
593 if (verbose) { cout<<
"yes"<<std::endl; }
602 cout <<
"Setting int and double array objects as std::string parameters ...\n";
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);
611 Teuchos::setStringParameterFromArray(
"Int Array",intArray,&PL_Main);
612 Teuchos::setStringParameterFromArray(
"Double Array",doubleArray,&PL_Main);
616 cout <<
"Testing retrieval of set array objects ...\n";
622 readIntArray = Teuchos::getArrayFromStringParameter<int>(PL_Main,
"Int Array");
623 result = readIntArray == intArray;
624 if(!result) ++FailedTests;
627 <<
"readIntArray = " << readIntArray <<
" == intArray = " << intArray <<
" ? " 628 << (result ?
"passed" :
"failed")
632 readDoubleAsIntArray = Teuchos::getArrayFromStringParameter<int>(PL_Main,
"Double Array");
633 result = readDoubleAsIntArray == intArray;
634 if(!result) ++FailedTests;
637 <<
"readDoubleAsIntArray = " << readDoubleAsIntArray <<
" == intArray = " << intArray <<
" ? " 638 << (result ?
"passed" :
"failed")
665 cout <<
"Setting a array of doubles as a std::string parameter directly ...\n";
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;
694 <<
"doubleAsIntArray = " << doubleAsIntArray <<
" == intArray = " << intArray <<
" ? " 695 << (result ?
"passed" :
"failed")
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" );
714 cout<<
"Can we pass a pointer to a function to a parameter list ... ";
716 if ( pt2Function( 1.0, 2.0 ) != 3.0 ) {
717 if (verbose) cout<<
"no"<<std::endl;
720 if (verbose) cout<<
"yes"<<std::endl;
732 void *someIntPtr = &someInt;
733 pl.
set(
"Some Pointer", someIntPtr);
734 void *someIntPtrRtn = getParameter<void*>(pl,
"Some Pointer");
737 cout <<
"someIntPtrRtn = " << someIntPtrRtn <<
" == " << someIntPtr <<
" : ";
738 if (someIntPtrRtn == someIntPtr) {
739 if (verbose) cout <<
"passed\n";
742 if (verbose) cout <<
"failed\n";
751 ParameterList::ConstIterator iter;
756 cout <<
" printing using public iterators " 760 for (iter = PL_Main.
begin(); iter != PL_Main.
end(); ++iter)
763 const std::string& name = PL_Main.
name(iter);
766 if (verbose) cout << name << std::endl;
768 ParameterList::ConstIterator i;
771 const std::string& nm =
sublist.name(i);
775 if (verbose) cout <<
" " << nm << std::endl;
776 if (verbose) Teuchos::getValue<ParameterList>(v).print(cout, 6);
780 if (verbose) cout <<
" " << nm <<
" " << v << std::endl;
786 if (verbose) cout << name <<
" " << val << std::endl;
791 #if defined(HAVE_TEUCHOS_EXTENDED) 798 cout <<
"writing to XML std::ostream" << std::endl;
803 cout <<
"writing to XML file" << std::endl;
808 cout <<
"reading from XML file" << std::endl;
812 if (verbose) readBack.
print(cout);
815 cout <<
"reading from XML std::string" << std::endl;
817 std::ifstream xmlInFile(
"PL_Main.xml");
819 while(!xmlInFile.eof()) {
821 std::getline(xmlInFile,line);
822 xmlStr += line +
"\n";
826 if (verbose) readBack.
print(cout);
831 catch(
const std::exception& e)
834 std::cerr <<
"caught std::exception:\n\n";
836 std::cerr << e.what() << std::endl;
841 #endif // defined(HAVE_TEUCHOS_EXTENDED) 849 cout <<
"The Final Parameter List" << std::endl;
853 cout <<
"The unused parameters" << std::endl;
863 cout <<
"Accessing a sublist using the wrong name (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
868 if (verbose) cout <<
"Did not throw std::exception, error!\n";
872 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
874 std::cerr << e.what() << std::endl;
878 cout <<
"Accessing a parameter using the wrong name (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
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";
888 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
890 std::cerr << e.what() << std::endl;
893 catch(
const std::exception &e) {
895 std::cerr <<
"caught unexpected std::exception:\n\n";
897 std::cerr << e.what() << std::endl;
904 cout <<
"Accessing a parameter using the wrong parameter type (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
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";
914 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
916 std::cerr << e.what() << std::endl;
919 catch(
const std::exception &e) {
921 std::cerr <<
"caught unexpected std::exception:\n\n";
923 std::cerr << e.what() << std::endl;
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"),
963 linesearchMaxItersValiator =
rcp(
966 AcceptedTypes(
false).allowInt(
true).allowDouble(
true).allowString(
true)
971 ,
"The maximum number of inner linear search iterations allowed." 972 ,linesearchMaxItersValiator
979 linSolveTolValidator =
rcp(
982 AcceptedTypes(
false).allowDouble(
true).allowString(
true)
988 ,
"Select the linear solve tolerance" 989 ,linSolveTolValidator
994 cout <<
"Validating the parameter list against itself (should not throw std::exception)...\n";
999 if (verbose) cout <<
"Did not throw std::exception, success!\n\n";
1001 catch(
const std::exception &e) {
1003 std::cerr <<
"caught unexpected std::exception:\n\n";
1005 std::cerr << e.what() << std::endl;
1012 cout <<
"Adding an invalid parameter type then validating (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
1016 PL_Main.
sublist(
"Line Search").
sublist(
"Polynomial").
set(
"Max Iters",(
short int)(3));
1018 if (verbose) cout <<
"Did not throw std::exception, error!\n";
1023 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
1025 std::cerr << e.what() << std::endl;
1028 catch(
const std::exception &e) {
1030 std::cerr <<
"caught unexpected std::exception:\n\n";
1032 std::cerr << e.what() << std::endl;
1040 cout <<
"Adding an invalid parameter name then validating (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
1046 if (verbose) cout <<
"Did not throw std::exception, error!\n";
1051 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
1053 std::cerr << e.what() << std::endl;
1056 catch(
const std::exception &e) {
1058 std::cerr <<
"caught unexpected std::exception:\n\n";
1060 std::cerr << e.what() << std::endl;
1068 cout <<
"Adding an invalid parameter type then validating using validator (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
1072 PL_Main.
set(
"Nonlinear Solver",
int(0));
1074 if (verbose) cout <<
"Did not throw std::exception, error!\n";
1079 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
1081 std::cerr << e.what() << std::endl;
1084 catch(
const std::exception &e) {
1086 std::cerr <<
"caught unexpected std::exception:\n\n";
1088 std::cerr << e.what() << std::endl;
1092 PL_Main.
set(
"Nonlinear Solver",
"Line Search Based");
1096 cout <<
"Adding an invalid parameter value then validating using validator (should throw a Teuchos::Exceptions::InvalidParameterValue std::exception)...\n";
1100 PL_Main.
set(
"Nonlinear Solver",
"LineSearch Based");
1102 if (verbose) cout <<
"Did not throw std::exception, error!\n";
1107 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterValue:\n\n";
1108 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1111 catch(
const std::exception &e) {
1113 std::cerr <<
"caught unexpected std::exception:\n\n";
1114 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1118 PL_Main.
set(
"Nonlinear Solver",
"Line Search Based");
1122 cout <<
"Use the validator to access integral value (should *not* throw std::exception)...\n";
1127 nonlinearSolverValue = Teuchos::getIntegralValue<int>(PL_Main,
"Nonlinear Solver");
1129 l_result = (nonlinearSolverValue == 0);
1131 <<
"Read value = " << nonlinearSolverValue <<
" == 0 : " 1132 << ( l_result ?
"passed" :
"failed") <<
"\n";
1133 if(!l_result) ++FailedTests;
1135 catch(
const std::exception &e) {
1137 std::cerr <<
"caught unexpected std::exception:\n\n";
1138 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1145 cout <<
"Use the validator to access std::string value (should *not* throw std::exception)...\n";
1150 nonlinearSolverValue = Teuchos::getStringValue<int>(PL_Main,
"Nonlinear Solver");
1152 l_result = (nonlinearSolverValue ==
"Line Search Based");
1154 <<
"Read value = \"" << nonlinearSolverValue <<
" == \"Line Search Based\" : " 1155 << ( l_result ?
"passed" :
"failed") <<
"\n";
1156 if(!l_result) ++FailedTests;
1158 catch(
const std::exception &e) {
1160 std::cerr <<
"caught unexpected std::exception:\n\n";
1161 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1175 cout <<
"Validating and setting defaults for an empty parameter list (should not throw) ...\n";
1180 if (verbose) cout <<
"Did not throw std::exception, success!\n\n";
1182 catch(
const std::exception &e) {
1184 std::cerr <<
"caught unexpected std::exception:\n\n";
1185 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1192 cout <<
"Parameter list with defaults set:" << std::endl;
1200 cout <<
"Checking that validatedPL and PL_Main_valid have the same values : ";
1206 cout << ( result ?
"passed" :
"failed" ) <<
"\n";
1215 for(
int type_i = 0; type_i < 3; ++type_i ) {
1218 = PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true);
1227 Polynomial_sublist.
set(
"Max Iters",(
int)(3));
1231 Polynomial_sublist.
set(
"Max Iters",(
double)(3.0));
1235 Polynomial_sublist.
set(
"Max Iters",(std::string)(
"3"));
1245 cout <<
"Use the external number validator to access a "<<
typeName<<
" as an int ...\n";
1251 = linesearchMaxItersValiator->
getInt(
1256 l_result = (lineserchMaxIters == int(3));
1258 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1259 << ( l_result ?
"passed" :
"failed") <<
"\n";
1260 if(!l_result) ++FailedTests;
1262 catch(
const std::exception &e) {
1264 std::cerr <<
"caught unexpected std::exception:\n\n";
1265 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1272 cout <<
"Use the external number validator to access a "<<
typeName<<
" as a double ...\n";
1278 = linesearchMaxItersValiator->
getDouble(
1283 l_result = (lineserchMaxIters == double(3.0));
1285 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1286 << ( l_result ?
"passed" :
"failed") <<
"\n";
1287 if(!l_result) ++FailedTests;
1289 catch(
const std::exception &e) {
1291 std::cerr <<
"caught unexpected std::exception:\n\n";
1292 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1299 cout <<
"Use the external number validator to access a "<<
typeName<<
" as a std::string ...\n";
1305 = linesearchMaxItersValiator->
getString(
1310 l_result = (lineserchMaxIters ==
"3");
1312 <<
"Read value = \"" << lineserchMaxIters <<
"\" == \"3\" : " 1313 << ( l_result ?
"passed" :
"failed") <<
"\n";
1314 if(!l_result) ++FailedTests;
1316 catch(
const std::exception &e) {
1318 std::cerr <<
"caught unexpected std::exception:\n\n";
1319 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1328 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as an int ...\n";
1334 = Teuchos::getIntParameter(
1339 l_result = (lineserchMaxIters == int(3));
1341 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1342 << ( l_result ?
"passed" :
"failed") <<
"\n";
1343 if(!l_result) ++FailedTests;
1345 catch(
const std::exception &e) {
1347 std::cerr <<
"caught unexpected std::exception:\n\n";
1348 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1355 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as a double ...\n";
1361 = Teuchos::getDoubleParameter(
1366 l_result = (lineserchMaxIters == double(3.0));
1368 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1369 << ( l_result ?
"passed" :
"failed") <<
"\n";
1370 if(!l_result) ++FailedTests;
1372 catch(
const std::exception &e) {
1374 std::cerr <<
"caught unexpected std::exception:\n\n";
1375 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1382 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as a std::string ...\n";
1388 = Teuchos::getNumericStringParameter(
1393 l_result = (lineserchMaxIters ==
"3");
1395 <<
"Read value = \"" << lineserchMaxIters <<
"\" == \"3\" : " 1396 << ( l_result ?
"passed" :
"failed") <<
"\n";
1397 if(!l_result) ++FailedTests;
1399 catch(
const std::exception &e) {
1401 std::cerr <<
"caught unexpected std::exception:\n\n";
1402 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1414 for(
int type_i = 0; type_i < 3; ++type_i ) {
1417 = PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true);
1426 Teuchos::setIntParameter(
"Max Iters",3,
"",&Polynomial_sublist);
1430 Teuchos::setDoubleParameter(
"Max Iters",3.0,
"",&Polynomial_sublist);
1434 Teuchos::setNumericStringParameter(
"Max Iters",
"3",
"",&Polynomial_sublist);
1444 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as an int ...\n";
1450 = Teuchos::getIntParameter(
1455 l_result = (lineserchMaxIters == int(3));
1457 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1458 << ( l_result ?
"passed" :
"failed") <<
"\n";
1459 if(!l_result) ++FailedTests;
1461 catch(
const std::exception &e) {
1463 std::cerr <<
"caught unexpected std::exception:\n\n";
1464 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1471 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as a double ...\n";
1477 = Teuchos::getDoubleParameter(
1482 l_result = (lineserchMaxIters == double(3.0));
1484 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1485 << ( l_result ?
"passed" :
"failed") <<
"\n";
1486 if(!l_result) ++FailedTests;
1488 catch(
const std::exception &e) {
1490 std::cerr <<
"caught unexpected std::exception:\n\n";
1491 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1498 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as a std::string ...\n";
1504 = Teuchos::getNumericStringParameter(
1509 l_result = (lineserchMaxIters ==
"3");
1511 <<
"Read value = \"" << lineserchMaxIters <<
"\" == \"3\" : " 1512 << ( l_result ?
"passed" :
"failed") <<
"\n";
1513 if(!l_result) ++FailedTests;
1515 catch(
const std::exception &e) {
1517 std::cerr <<
"caught unexpected std::exception:\n\n";
1518 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1530 for(
int type_i = 0; type_i < 3; ++type_i ) {
1535 = PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true);
1544 Teuchos::setIntParameter(
"Max Iters",3,
"",&Polynomial_sublist);
1548 Teuchos::setDoubleParameter(
"Max Iters",3.0,
"",&Polynomial_sublist);
1552 Teuchos::setNumericStringParameter(
"Max Iters",
"3",
"",&Polynomial_sublist);
1562 cout <<
"Use validateParemetersAndSetDefaults(...) to access a "<<
typeName<<
" as an int ...\n";
1566 Teuchos::setIntParameter(
1568 &valid_PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true)
1571 copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main);
1574 = Teuchos::getParameter<int>(
1575 copied_PL_Main.sublist(
"Line Search",
true).sublist(
"Polynomial",
true)
1579 l_result = (lineserchMaxIters == int(3));
1581 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1582 << ( l_result ?
"passed" :
"failed") <<
"\n";
1583 if(!l_result) ++FailedTests;
1585 catch(
const std::exception &e) {
1587 std::cerr <<
"caught unexpected std::exception:\n\n";
1588 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1595 cout <<
"Use validateParemetersAndSetDefaults(...) to access a "<<
typeName<<
" as a double ...\n";
1599 Teuchos::setDoubleParameter(
1600 "Max Iters", 0.0,
"",
1601 &valid_PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true)
1604 copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main);
1607 = Teuchos::getParameter<double>(
1608 copied_PL_Main.sublist(
"Line Search",
true).sublist(
"Polynomial",
true)
1612 l_result = (lineserchMaxIters == double(3.0));
1614 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1615 << ( l_result ?
"passed" :
"failed") <<
"\n";
1616 if(!l_result) ++FailedTests;
1618 catch(
const std::exception &e) {
1620 std::cerr <<
"caught unexpected std::exception:\n\n";
1621 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1628 cout <<
"Use validateParemetersAndSetDefaults(...) to access a "<<
typeName<<
" as a std::string ...\n";
1632 Teuchos::setNumericStringParameter(
1633 "Max Iters",
"0",
"",
1634 &valid_PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true)
1637 copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main);
1640 = Teuchos::getParameter<std::string>(
1641 copied_PL_Main.sublist(
"Line Search",
true).sublist(
"Polynomial",
true)
1645 l_result = (lineserchMaxIters ==
"3");
1647 <<
"Read value = \"" << lineserchMaxIters <<
"\" == \"3\" : " 1648 << ( l_result ?
"passed" :
"failed") <<
"\n";
1649 if(!l_result) ++FailedTests;
1651 catch(
const std::exception &e) {
1653 std::cerr <<
"caught unexpected std::exception:\n\n";
1654 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1663 cout <<
"Adding an invalid sublist then validating (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
1669 if (verbose) cout <<
"Did not throw std::exception, error!\n";
1674 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
1675 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1678 catch(
const std::exception &e) {
1680 std::cerr <<
"caught unexpected std::exception:\n\n";
1681 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1689 cout <<
"Validating only the top level list (should not throw std::exception)...\n";
1694 if (verbose) cout <<
"Did not throw std::exception, success!\n\n";
1696 catch(
const std::exception &e) {
1698 std::cerr <<
"caught unexpected std::exception:\n\n";
1699 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1710 cout <<
"Checking that PL_Main == PL_Main == true : ";
1712 result = (PL_Main == PL_Main);
1716 cout << ( result ?
"passed" :
"failed" ) <<
"\n";
1722 cout <<
"Checking that PL_Main != PL_Main == false : ";
1724 result = !(PL_Main != PL_Main);
1728 cout << ( result ?
"passed" :
"failed" ) <<
"\n";
1734 cout <<
"Checking that PL_Main and PL_Main have the same values : ";
1740 cout << ( result ?
"passed" :
"failed" ) <<
"\n";
1746 cout <<
"Create copy PL_Main_copy, change PL_Main_copy, and check that PL_Main != PL_Main == true : ";
1749 PL_Main_copy.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true).
set(
"Max Iters",100);
1750 result = (PL_Main_copy != PL_Main);
1754 cout << ( result ?
"passed" :
"failed" ) <<
"\n";
1764 cout <<
"The Final Parameter List with Types and Documentation" << std::endl;
1768 cout <<
"The unused parameters" << std::endl;
1771 cout <<
"Number of Failed Tests : " << FailedTests << std::endl;
1782 if(!success) ++FailedTests;
1784 if ( FailedTests > 0 ) {
1785 cout <<
"End Result: TEST FAILED" << std::endl;
1789 if ( FailedTests == 0 )
1790 cout <<
"End Result: TEST PASSED" << std::endl;
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'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 > ¶mList)
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 > ¶mList, 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 ¶mName="", 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 ¶mName="", 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.
Determines the types that are accepted.
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 ¶mName="", 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 ¶mList, 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.
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 ¶mList, 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 > ¶mList, 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.