52 #ifdef HAVE_TEUCHOS_EXTENDED 62 using Teuchos::getParameter;
67 using Teuchos::inoutArg;
69 void print_break() { std::cout <<
"---------------------------------------------------" << std::endl; }
70 double Plus (
double a,
double b ) {
return a+b; }
72 int main(
int argc,
char *argv[] )
91 clp.
setOption(
"verbose",
"quiet", &verbose,
"Set if output is printed or not." );
92 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.
parse(argc,argv);
93 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
94 cout <<
"Processor "<< procRank <<
", parse_return "<< parse_return << std::endl;
95 cout <<
"End Result: TEST FAILED" << std::endl;
100 if (procRank != 0 && verbose)
111 const std::string Direction_Doc =
"This sublist controls how direction is computed.";
122 cout <<
"Empty Parameter List Structure" << std::endl;
124 cout<<PL_Main<< std::endl;
126 if (verbose) cout <<
"Is 'Direction' recognized as a sublist of 'Main' ... ";
127 if ( PL_Main.
isSublist(
"Direction" ) ) {
128 if (verbose) cout <<
"yes"<< std::endl;
130 if (verbose) cout <<
"no"<< std::endl;
133 if (verbose) cout <<
"Is 'Newton' recognized as a sublist of 'Direction' ... ";
134 if ( PL_Direction.
isSublist(
"Newton" ) ) {
135 if (verbose) cout <<
"yes"<< std::endl;
137 if (verbose) cout <<
"no"<< std::endl;
140 if (verbose) cout <<
"Is 'Linear Solver' recognized as a sublist of 'Newton' ... ";
141 if ( PL_Newton.
isSublist(
"Linear Solver" ) ) {
142 if (verbose) cout <<
"yes"<< std::endl;
144 if (verbose) cout <<
"no"<< std::endl;
147 if (verbose) cout <<
"Is 'Line Search' recognized as a sublist of 'Main' ... ";
148 if ( PL_Main.
isSublist(
"Line Search" ) ) {
149 if (verbose) cout <<
"yes"<< std::endl;
151 if (verbose) cout <<
"no"<< std::endl;
155 if (verbose) cout <<
"Is subist documentation std::string maintained ...\n";
161 const std::string extracted_Direction_Doc = paramEntry->
docString();
162 if (verbose)
tab.o() <<
"Expected doc std::string = \"" << Direction_Doc <<
"\"\n";
163 if (verbose)
tab.o() <<
"Extracted doc std::string = \"" << extracted_Direction_Doc <<
"\"\n";
164 if (extracted_Direction_Doc == Direction_Doc) {
165 if (verbose)
tab.o() <<
"passed! They match :-)\n";
168 if (verbose)
tab.o() <<
"failed! They do not match :-("<< std::endl;
180 PL_Direction.
get(
"Method",
"Newton");
181 PL_LinSol.
set(
"Tol",1e-5);
182 tol = PL_LinSol.
get(
"Tolerance",1e-10);
184 RBNS = PL_Newton.
get(
"Rescue Bad Newton Solve",
true );
192 cout <<
"Direction Parameter List" << std::endl;
194 PL_Direction.
print(cout);
196 if (verbose) cout <<
"Is 'Newton' recognized as a parameter of 'Direction' ... ";
198 if (verbose) cout <<
"yes"<< std::endl;
200 if (verbose) cout <<
"no"<< std::endl;
203 if (verbose) cout <<
"Is 'Tolerance' recognized as a parameter of 'Newton' ... ";
205 if (verbose) cout <<
"yes (should be no)"<< std::endl;
208 if (verbose) cout <<
"no (as expected)"<< std::endl;
210 if (verbose) cout <<
"Is 'Tolerance' recognized as a parameter of 'Linear Solver' ... ";
212 if (verbose) cout <<
"yes"<< std::endl;
214 if (verbose) cout <<
"no"<< std::endl;
217 if (verbose) cout <<
"Is 'Rescue Bad Newton Solve' recognized as a parameter of 'Newton' ... ";
218 if ( PL_Newton.
isParameter(
"Rescue Bad Newton Solve" ) ) {
219 if (verbose) cout <<
"yes"<< std::endl;
221 if (verbose) cout <<
"no"<< std::endl;
230 int ARI = 0, default_step = 0, max_iter_inc = 0, rec_step = 0;
231 double alpha_factor = 0.0, min_bnds_factor = 0.0, max_bnds_factor = 0.0;
232 bool force_interp =
true, use_cntrs =
false;
233 std::string ls_method =
"Polynomial";
236 char* ls_method_char =
const_cast<char *
>(ls_method.c_str());
238 ls_method = PL_My_LineSearch.
get(
"Method", ls_method_char);
240 ARI = PL_Polynomial.
get(
"Allowed Relative Increase", 100 );
242 alpha_factor = PL_Polynomial.
get(
"Alpha Factor", 0.0001 );
244 default_step = PL_Polynomial.
get(
"Default Step", 1 );
246 force_interp = PL_Polynomial.
get(
"Force Interpolation",
false );
248 std::string interp_type = PL_Polynomial.
get(
"Interpolation Type",
"Cubic" );
249 max_bnds_factor = PL_Polynomial.
get(
"Max Bounds Factor", 0.5 );
250 (void)max_bnds_factor;
251 PL_Polynomial.
set(
"Max Iters", 3 );
252 max_iter_inc = PL_Polynomial.
get(
"Maximum Iteration for Increase", 0 );
254 min_bnds_factor = PL_Polynomial.
get(
"Min Bounds Factor", 0.1 );
255 (void)min_bnds_factor;
256 rec_step = PL_Polynomial.
get(
"Recovery Step", 1 );
258 std::string rec_step_type = PL_Polynomial.
get(
"Recovery Step Type",
"Constant");
259 std::string suff_dec_cond = PL_Polynomial.
get(
"Sufficient Decrease Condition",
"Armijo-Goldstein" );
260 use_cntrs = PL_Polynomial.
get(
"Use Counters",
true );
262 PL_Main.
set(
"Nonlinear Solver",
"Line Search Based");
269 if (verbose) cout<<
"Is 'operator=' functional ... ";
270 if ( PL_My_Polynomial.
isParameter(
"Recovery Step Type") ) {
271 if (verbose) cout<<
"yes" << std::endl;
273 if (verbose) cout<<
"no" << std::endl;
283 if (verbose) cout <<
"Test copying of sublist\n";
285 PL_Direction.
print(cout);
291 linearSolverPL_copy(linearSolverPL);
292 if (verbose) cout <<
"linearSolverPL.name() = " << linearSolverPL.
name() << endl;
293 if (verbose) cout <<
"linearSolverPL_copy.name() = " << linearSolverPL_copy.
name() << endl;
294 if (verbose) cout <<
"linearSolverPL_copy == linearSolverPL.name() : ";
295 if (linearSolverPL_copy == linearSolverPL.
name()) {
296 if (verbose) cout <<
"passed" << endl;
299 if (verbose) cout <<
"failed" << endl;
306 if (verbose) cout <<
"General tests\n";
308 PL_Direction.
print(cout);
313 if (verbose) cout <<
"Copied_PL_Main.name() == PL_Main.name() : ";
314 if (Copied_PL_Main.
name() == PL_Main.
name()) {
315 if (verbose) cout <<
"passed" << endl;
318 if (verbose) cout <<
"failed" << endl;
320 if (verbose) cout <<
"Copyed_PL_Main.name() = " << Copied_PL_Main.
name() << endl;
323 if (verbose) cout<<
"Is the copy constructor functional ... ";
324 if ( Copied_PL_Main.
isParameter(
"Nonlinear Solver") ) {
325 if (verbose) cout<<
"yes" << std::endl;
327 if (verbose) cout<<
"no" << std::endl;
331 bool tempMeth =
true;
342 int max_iters = 0, max_iters_again = 0;
343 std::string nonlin_solver;
346 max_iters = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER get<int>(
"Max Iters");
347 max_iters_again =
Teuchos::getConst(PL_My_Polynomial).INVALID_TEMPLATE_QUALIFIER get<int>(
"Max Iters");
348 nonlin_solver = PL_Main.INVALID_TEMPLATE_QUALIFIER get<std::string>(
"Nonlinear Solver");
352 cout<<
"Is the templated 'get' method functional ... "<<std::endl;
353 cout<<
" Can we retrieve information using the CORRECT variable type ... ";
355 if (tempMeth && max_iters==3) {
if (verbose) cout <<
"yes" << std::endl; }
356 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
358 cout<<
" Can we retrieve const information using the CORRECT variable type ... ";
360 if (tempMeth && max_iters_again==3) {
if (verbose) cout <<
"yes" << std::endl; }
361 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
371 mbf = PL_LinSol.INVALID_TEMPLATE_QUALIFIER get<float>(
"Tol" );
379 cout<<
" Can we retrieve information using the WRONG variable type ... ";
381 if (tempMeth) {
if (verbose) cout <<
"no" << std::endl; }
382 else {
if (verbose) cout <<
"yes" << std::endl; }
391 max_iters = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER get<int>(
"Max Iters");
392 nonlin_solver = PL_Main.INVALID_TEMPLATE_QUALIFIER get<std::string>(
"Nonlinear Solver");
396 cout<<
"Is the templated 'get' method functional ... "<<std::endl;
397 cout<<
" Can we retrieve information using the CORRECT variable type ... ";
399 if (tempMeth && max_iters==3) {
if (verbose) cout <<
"yes" << std::endl; }
400 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
407 mbf = PL_LinSol.INVALID_TEMPLATE_QUALIFIER get<float>(
"Tol" );
415 cout<<
" Can we retrieve information using the WRONG variable type ... ";
417 if (tempMeth) {
if (verbose) cout <<
"no" << std::endl; }
418 else {
if (verbose) cout <<
"yes" << std::endl; }
429 int *max_iters_ptr = 0;
430 const int *max_iters_ptr_again = 0;
431 std::string* nonlin_solver_ptr;
433 max_iters_ptr = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER getPtr<int>(
"Max Iters");
434 max_iters_ptr_again =
Teuchos::getConst(PL_My_Polynomial).INVALID_TEMPLATE_QUALIFIER getPtr<int>(
"Max Iters");
435 nonlin_solver_ptr = PL_Main.INVALID_TEMPLATE_QUALIFIER getPtr<std::string>(
"Nonlinear Solver");
438 cout<<
"Is the templated 'getPtr' method functional ... "<<std::endl;
439 cout<<
" Can we retrieve information using the CORRECT variable type ... ";
442 if ((*max_iters_ptr)==3) {
443 if (verbose) cout <<
"yes" << std::endl;
445 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
448 cout<<
" Can we retrieve const information using the CORRECT variable type ... ";
450 if (max_iters_ptr_again) {
451 if ((*max_iters_ptr_again)==3) {
452 if (verbose) cout <<
"yes" << std::endl;
454 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
464 mbf_ptr = PL_LinSol.INVALID_TEMPLATE_QUALIFIER getPtr<float>(
"Tol" );
470 cout<<
" Can we retrieve information using the WRONG variable type ... ";
472 if (!mbf_ptr) {
if (verbose) cout <<
"no" << std::endl; }
473 else {
if (verbose) cout <<
"yes" << std::endl; }
481 max_iters_ptr = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER getPtr<int>(
"Max Iters");
482 nonlin_solver_ptr = PL_Main.INVALID_TEMPLATE_QUALIFIER getPtr<std::string>(
"Nonlinear Solver");
483 (void)nonlin_solver_ptr;
486 cout<<
"Is the templated 'getPtr' method functional ... "<<std::endl;
487 cout<<
" Can we retrieve information using the CORRECT variable type ... ";
490 if ((*max_iters_ptr)==3) {
491 if (verbose) cout <<
"yes" << std::endl;
493 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
502 mbf_ptr = PL_LinSol.INVALID_TEMPLATE_QUALIFIER getPtr<float>(
"Tol" );
508 cout<<
" Can we retrieve information using the WRONG variable type ... ";
510 if (!mbf_ptr) {
if (verbose) cout <<
"no" << std::endl; }
511 else {
if (verbose) cout <<
"yes" << std::endl; }
517 double alpha_fact = 0.0;
520 def_step = Teuchos::getParameter<int>(PL_Polynomial,
"Default Step");
521 alpha_fact = Teuchos::getParameter<double>(PL_Polynomial,
"Alpha Factor");
525 if (verbose && def_step==1) {
526 cout<<
"Is the helper function 'getParameter' functional ... ";
528 if (tempMeth) {
if (verbose) cout <<
"yes" << std::endl; }
529 else {
if (verbose) cout <<
"no" << std::endl; FailedTests++; }
537 PT1 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<int>(
"Default Step");
538 PT2 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<long int>(
"Default Step");
539 PT3 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<std::string>(
"Interpolation Type");
541 cout<<
"Is the templated 'isType' method functional ... "<<std::endl;
542 cout<<
" Is the 'Default Step' of type 'int' ... ";
544 if (PT1) {
if (verbose) cout<<
"yes" << std::endl; }
545 else {
if (verbose) cout<<
"no" << std::endl; FailedTests++; }
547 cout<<
" Is the 'Default Step' of type 'long int' ... ";
549 if (PT2) {
if (verbose) cout<<
"yes" << std::endl; FailedTests++; }
550 else {
if (verbose) cout<<
"no (as expected)" << std::endl; }
552 cout<<
" Is the 'Interpolation Type' of type 'std::string' ... ";
554 if (PT3) {
if (verbose) cout<<
"yes" << std::endl; }
555 else {
if (verbose) cout<<
"no" << std::endl; FailedTests++; }
561 PT4 = Teuchos::isParameterType<double>(PL_Polynomial,
"Max Bounds Factor");
562 PT5 = Teuchos::isParameterType<float>(PL_Polynomial,
"Max Bounds Factor");
564 cout<<
"Is the helper function 'isParameterType' functional ... "<<std::endl;
565 cout<<
" Is the 'Max Bounds Factor' of type 'double' ... ";
567 if (PT4) {
if (verbose) cout<<
"yes" <<std::endl; }
568 else {
if (verbose) cout<<
"no" << std::endl; FailedTests++; }
570 cout<<
" Is the 'Max Bounds Factor' of type 'float' ... ";
572 if (PT5) {
if (verbose) cout<<
"yes" <<std::endl; FailedTests++; }
573 else {
if (verbose) cout<<
"no (as expected)" << std::endl; }
580 double * tempvec1 = tempvec1_arcp.
get();
581 for (
int i=0; i<10; i++) { tempvec1[i] = i; }
582 PL_Main.
set(
"Address of Norm Vector", tempvec1 );
583 double* tempvec2 = Teuchos::getParameter<double*>( PL_Main,
"Address of Norm Vector" );
584 tempvec1[4] = 2.0; tempvec1[6] = 1.0;
586 cout<<
"Can we pass a pointer to a std::vector to a parameter list ... ";
588 if ((tempvec2[4]-tempvec1[4])!=0.0 || (tempvec2[6]-tempvec1[6])!=0.0) {
589 if (verbose) { cout<<
"no"<<std::endl; }
592 if (verbose) { cout<<
"yes"<<std::endl; }
601 cout <<
"Setting int and double array objects as std::string parameters ...\n";
605 intArray = Teuchos::tuple<int>(0,1,2,3,4,5,6);
607 doubleArray = Teuchos::tuple<double>(0,1.0,2.0,3.0,4.0,5.0,6.0);
610 Teuchos::setStringParameterFromArray(
"Int Array",intArray,&PL_Main);
611 Teuchos::setStringParameterFromArray(
"Double Array",doubleArray,&PL_Main);
615 cout <<
"Testing retrieval of set array objects ...\n";
621 readIntArray = Teuchos::getArrayFromStringParameter<int>(PL_Main,
"Int Array");
622 result = readIntArray == intArray;
623 if(!result) ++FailedTests;
626 <<
"readIntArray = " << readIntArray <<
" == intArray = " << intArray <<
" ? " 627 << (result ?
"passed" :
"failed")
631 readDoubleAsIntArray = Teuchos::getArrayFromStringParameter<int>(PL_Main,
"Double Array");
632 result = readDoubleAsIntArray == intArray;
633 if(!result) ++FailedTests;
636 <<
"readDoubleAsIntArray = " << readDoubleAsIntArray <<
" == intArray = " << intArray <<
" ? " 637 << (result ?
"passed" :
"failed")
664 cout <<
"Setting a array of doubles as a std::string parameter directly ...\n";
684 readDoubleArray = Teuchos::getArrayFromStringParameter<double>(PL_Main,
"Double Array");
686 doubleAsIntArray(readDoubleArray.
size());
687 for(
int i=0;i<static_cast<int>(readDoubleArray.
size());++i)
688 doubleAsIntArray[i] = static_cast<int>(readDoubleArray[i]);
689 result = doubleAsIntArray == intArray;
690 if(!result) ++FailedTests;
693 <<
"doubleAsIntArray = " << doubleAsIntArray <<
" == intArray = " << intArray <<
" ? " 694 << (result ?
"passed" :
"failed")
708 #ifndef JANUS_STLPORT 709 double (*pt2Function) (double, double);
710 PL_Main.
set(
"Address to Simple Function", &
Plus );
711 pt2Function = Teuchos::getParameter<double(*)(double,double)>( PL_Main,
"Address to Simple Function" );
713 cout<<
"Can we pass a pointer to a function to a parameter list ... ";
715 if ( pt2Function( 1.0, 2.0 ) != 3.0 ) {
716 if (verbose) cout<<
"no"<<std::endl;
719 if (verbose) cout<<
"yes"<<std::endl;
731 void *someIntPtr = &someInt;
732 pl.
set(
"Some Pointer", someIntPtr);
733 void *someIntPtrRtn = getParameter<void*>(pl,
"Some Pointer");
736 cout <<
"someIntPtrRtn = " << someIntPtrRtn <<
" == " << someIntPtr <<
" : ";
737 if (someIntPtrRtn == someIntPtr) {
738 if (verbose) cout <<
"passed\n";
741 if (verbose) cout <<
"failed\n";
750 ParameterList::ConstIterator iter;
755 cout <<
" printing using public iterators " 759 for (iter = PL_Main.
begin(); iter != PL_Main.
end(); ++iter)
762 const std::string& name = PL_Main.
name(iter);
765 if (verbose) cout << name << std::endl;
767 ParameterList::ConstIterator i;
770 const std::string& nm =
sublist.name(i);
774 if (verbose) cout <<
" " << nm << std::endl;
775 if (verbose) Teuchos::getValue<ParameterList>(v).print(cout, 6);
779 if (verbose) cout <<
" " << nm <<
" " << v << std::endl;
785 if (verbose) cout << name <<
" " << val << std::endl;
790 #if defined(HAVE_TEUCHOS_EXTENDED) 797 cout <<
"writing to XML std::ostream" << std::endl;
802 cout <<
"writing to XML file" << std::endl;
807 cout <<
"reading from XML file" << std::endl;
811 if (verbose) readBack.
print(cout);
814 cout <<
"reading from XML std::string" << std::endl;
816 std::ifstream xmlInFile(
"PL_Main.xml");
818 while(!xmlInFile.eof()) {
820 std::getline(xmlInFile,line);
821 xmlStr += line +
"\n";
825 if (verbose) readBack.
print(cout);
830 catch(
const std::exception& e)
833 std::cerr <<
"caught std::exception:\n\n";
835 std::cerr << e.what() << std::endl;
840 #endif // defined(HAVE_TEUCHOS_EXTENDED) 848 cout <<
"The Final Parameter List" << std::endl;
852 cout <<
"The unused parameters" << std::endl;
862 cout <<
"Accessing a sublist using the wrong name (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
867 if (verbose) cout <<
"Did not throw std::exception, error!\n";
871 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
873 std::cerr << e.what() << std::endl;
877 cout <<
"Accessing a parameter using the wrong name (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
881 Teuchos::getParameter<int>(PL_Main.
sublist(
"Direction").
sublist(
"Newton").
sublist(
"Linear Solver"),
"Tolerances");
882 if (verbose) cout <<
"Did not throw std::exception, error!\n";
887 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
889 std::cerr << e.what() << std::endl;
892 catch(
const std::exception &e) {
894 std::cerr <<
"caught unexpected std::exception:\n\n";
896 std::cerr << e.what() << std::endl;
903 cout <<
"Accessing a parameter using the wrong parameter type (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
907 Teuchos::getParameter<int>(PL_Main.
sublist(
"Direction").
sublist(
"Newton").
sublist(
"Linear Solver"),
"Tolerance");
908 if (verbose) cout <<
"Did not throw std::exception, error!\n";
913 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
915 std::cerr << e.what() << std::endl;
918 catch(
const std::exception &e) {
920 std::cerr <<
"caught unexpected std::exception:\n\n";
922 std::cerr << e.what() << std::endl;
936 Teuchos::setStringToIntegralParameter<int>(
937 "Nonlinear Solver",
"Line Search Based",
938 "Selects the type of nonlinear solver to use",
939 Teuchos::tuple<std::string>(
"Line Search Based",
"Trust Region Based"),
962 linesearchMaxItersValiator =
rcp(
965 AcceptedTypes(
false).allowInt(
true).allowDouble(
true).allowString(
true)
970 ,
"The maximum number of inner linear search iterations allowed." 971 ,linesearchMaxItersValiator
978 linSolveTolValidator =
rcp(
981 AcceptedTypes(
false).allowDouble(
true).allowString(
true)
987 ,
"Select the linear solve tolerance" 988 ,linSolveTolValidator
993 cout <<
"Validating the parameter list against itself (should not throw std::exception)...\n";
998 if (verbose) cout <<
"Did not throw std::exception, success!\n\n";
1000 catch(
const std::exception &e) {
1002 std::cerr <<
"caught unexpected std::exception:\n\n";
1004 std::cerr << e.what() << std::endl;
1011 cout <<
"Adding an invalid parameter type then validating (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
1015 PL_Main.
sublist(
"Line Search").
sublist(
"Polynomial").
set(
"Max Iters",(
short int)(3));
1017 if (verbose) cout <<
"Did not throw std::exception, error!\n";
1022 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
1024 std::cerr << e.what() << std::endl;
1027 catch(
const std::exception &e) {
1029 std::cerr <<
"caught unexpected std::exception:\n\n";
1031 std::cerr << e.what() << std::endl;
1039 cout <<
"Adding an invalid parameter name then validating (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
1045 if (verbose) cout <<
"Did not throw std::exception, error!\n";
1050 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
1052 std::cerr << e.what() << std::endl;
1055 catch(
const std::exception &e) {
1057 std::cerr <<
"caught unexpected std::exception:\n\n";
1059 std::cerr << e.what() << std::endl;
1067 cout <<
"Adding an invalid parameter type then validating using validator (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n";
1071 PL_Main.
set(
"Nonlinear Solver",
int(0));
1073 if (verbose) cout <<
"Did not throw std::exception, error!\n";
1078 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterType:\n\n";
1080 std::cerr << e.what() << std::endl;
1083 catch(
const std::exception &e) {
1085 std::cerr <<
"caught unexpected std::exception:\n\n";
1087 std::cerr << e.what() << std::endl;
1091 PL_Main.
set(
"Nonlinear Solver",
"Line Search Based");
1095 cout <<
"Adding an invalid parameter value then validating using validator (should throw a Teuchos::Exceptions::InvalidParameterValue std::exception)...\n";
1099 PL_Main.
set(
"Nonlinear Solver",
"LineSearch Based");
1101 if (verbose) cout <<
"Did not throw std::exception, error!\n";
1106 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterValue:\n\n";
1107 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1110 catch(
const std::exception &e) {
1112 std::cerr <<
"caught unexpected std::exception:\n\n";
1113 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1117 PL_Main.
set(
"Nonlinear Solver",
"Line Search Based");
1121 cout <<
"Use the validator to access integral value (should *not* throw std::exception)...\n";
1126 nonlinearSolverValue = Teuchos::getIntegralValue<int>(PL_Main,
"Nonlinear Solver");
1128 l_result = (nonlinearSolverValue == 0);
1130 <<
"Read value = " << nonlinearSolverValue <<
" == 0 : " 1131 << ( l_result ?
"passed" :
"failed") <<
"\n";
1132 if(!l_result) ++FailedTests;
1134 catch(
const std::exception &e) {
1136 std::cerr <<
"caught unexpected std::exception:\n\n";
1137 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1144 cout <<
"Use the validator to access std::string value (should *not* throw std::exception)...\n";
1149 nonlinearSolverValue = Teuchos::getStringValue<int>(PL_Main,
"Nonlinear Solver");
1151 l_result = (nonlinearSolverValue ==
"Line Search Based");
1153 <<
"Read value = \"" << nonlinearSolverValue <<
" == \"Line Search Based\" : " 1154 << ( l_result ?
"passed" :
"failed") <<
"\n";
1155 if(!l_result) ++FailedTests;
1157 catch(
const std::exception &e) {
1159 std::cerr <<
"caught unexpected std::exception:\n\n";
1160 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1174 cout <<
"Validating and setting defaults for an empty parameter list (should not throw) ...\n";
1179 if (verbose) cout <<
"Did not throw std::exception, success!\n\n";
1181 catch(
const std::exception &e) {
1183 std::cerr <<
"caught unexpected std::exception:\n\n";
1184 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1191 cout <<
"Parameter list with defaults set:" << std::endl;
1199 cout <<
"Checking that validatedPL and PL_Main_valid have the same values : ";
1205 cout << ( result ?
"passed" :
"failed" ) <<
"\n";
1214 for(
int type_i = 0; type_i < 3; ++type_i ) {
1217 = PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true);
1226 Polynomial_sublist.
set(
"Max Iters",(
int)(3));
1230 Polynomial_sublist.
set(
"Max Iters",(
double)(3.0));
1234 Polynomial_sublist.
set(
"Max Iters",(std::string)(
"3"));
1244 cout <<
"Use the external number validator to access a "<<
typeName<<
" as an int ...\n";
1250 = linesearchMaxItersValiator->
getInt(
1255 l_result = (lineserchMaxIters == int(3));
1257 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1258 << ( l_result ?
"passed" :
"failed") <<
"\n";
1259 if(!l_result) ++FailedTests;
1261 catch(
const std::exception &e) {
1263 std::cerr <<
"caught unexpected std::exception:\n\n";
1264 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1271 cout <<
"Use the external number validator to access a "<<
typeName<<
" as a double ...\n";
1277 = linesearchMaxItersValiator->
getDouble(
1282 l_result = (lineserchMaxIters == double(3.0));
1284 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1285 << ( l_result ?
"passed" :
"failed") <<
"\n";
1286 if(!l_result) ++FailedTests;
1288 catch(
const std::exception &e) {
1290 std::cerr <<
"caught unexpected std::exception:\n\n";
1291 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1298 cout <<
"Use the external number validator to access a "<<
typeName<<
" as a std::string ...\n";
1304 = linesearchMaxItersValiator->
getString(
1309 l_result = (lineserchMaxIters ==
"3");
1311 <<
"Read value = \"" << lineserchMaxIters <<
"\" == \"3\" : " 1312 << ( l_result ?
"passed" :
"failed") <<
"\n";
1313 if(!l_result) ++FailedTests;
1315 catch(
const std::exception &e) {
1317 std::cerr <<
"caught unexpected std::exception:\n\n";
1318 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1327 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as an int ...\n";
1333 = Teuchos::getIntParameter(
1338 l_result = (lineserchMaxIters == int(3));
1340 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1341 << ( l_result ?
"passed" :
"failed") <<
"\n";
1342 if(!l_result) ++FailedTests;
1344 catch(
const std::exception &e) {
1346 std::cerr <<
"caught unexpected std::exception:\n\n";
1347 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1354 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as a double ...\n";
1360 = Teuchos::getDoubleParameter(
1365 l_result = (lineserchMaxIters == double(3.0));
1367 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1368 << ( l_result ?
"passed" :
"failed") <<
"\n";
1369 if(!l_result) ++FailedTests;
1371 catch(
const std::exception &e) {
1373 std::cerr <<
"caught unexpected std::exception:\n\n";
1374 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1381 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as a std::string ...\n";
1387 = Teuchos::getNumericStringParameter(
1392 l_result = (lineserchMaxIters ==
"3");
1394 <<
"Read value = \"" << lineserchMaxIters <<
"\" == \"3\" : " 1395 << ( l_result ?
"passed" :
"failed") <<
"\n";
1396 if(!l_result) ++FailedTests;
1398 catch(
const std::exception &e) {
1400 std::cerr <<
"caught unexpected std::exception:\n\n";
1401 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1413 for(
int type_i = 0; type_i < 3; ++type_i ) {
1416 = PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true);
1425 Teuchos::setIntParameter(
"Max Iters",3,
"",&Polynomial_sublist);
1429 Teuchos::setDoubleParameter(
"Max Iters",3.0,
"",&Polynomial_sublist);
1433 Teuchos::setNumericStringParameter(
"Max Iters",
"3",
"",&Polynomial_sublist);
1443 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as an int ...\n";
1449 = Teuchos::getIntParameter(
1454 l_result = (lineserchMaxIters == int(3));
1456 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1457 << ( l_result ?
"passed" :
"failed") <<
"\n";
1458 if(!l_result) ++FailedTests;
1460 catch(
const std::exception &e) {
1462 std::cerr <<
"caught unexpected std::exception:\n\n";
1463 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1470 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as a double ...\n";
1476 = Teuchos::getDoubleParameter(
1481 l_result = (lineserchMaxIters == double(3.0));
1483 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1484 << ( l_result ?
"passed" :
"failed") <<
"\n";
1485 if(!l_result) ++FailedTests;
1487 catch(
const std::exception &e) {
1489 std::cerr <<
"caught unexpected std::exception:\n\n";
1490 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1497 cout <<
"Use the nomember help function to access a "<<
typeName<<
" as a std::string ...\n";
1503 = Teuchos::getNumericStringParameter(
1508 l_result = (lineserchMaxIters ==
"3");
1510 <<
"Read value = \"" << lineserchMaxIters <<
"\" == \"3\" : " 1511 << ( l_result ?
"passed" :
"failed") <<
"\n";
1512 if(!l_result) ++FailedTests;
1514 catch(
const std::exception &e) {
1516 std::cerr <<
"caught unexpected std::exception:\n\n";
1517 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1529 for(
int type_i = 0; type_i < 3; ++type_i ) {
1534 = PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true);
1543 Teuchos::setIntParameter(
"Max Iters",3,
"",&Polynomial_sublist);
1547 Teuchos::setDoubleParameter(
"Max Iters",3.0,
"",&Polynomial_sublist);
1551 Teuchos::setNumericStringParameter(
"Max Iters",
"3",
"",&Polynomial_sublist);
1561 cout <<
"Use validateParemetersAndSetDefaults(...) to access a "<<
typeName<<
" as an int ...\n";
1565 Teuchos::setIntParameter(
1567 &valid_PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true)
1570 copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main);
1573 = Teuchos::getParameter<int>(
1574 copied_PL_Main.sublist(
"Line Search",
true).sublist(
"Polynomial",
true)
1578 l_result = (lineserchMaxIters == int(3));
1580 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1581 << ( l_result ?
"passed" :
"failed") <<
"\n";
1582 if(!l_result) ++FailedTests;
1584 catch(
const std::exception &e) {
1586 std::cerr <<
"caught unexpected std::exception:\n\n";
1587 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1594 cout <<
"Use validateParemetersAndSetDefaults(...) to access a "<<
typeName<<
" as a double ...\n";
1598 Teuchos::setDoubleParameter(
1599 "Max Iters", 0.0,
"",
1600 &valid_PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true)
1603 copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main);
1606 = Teuchos::getParameter<double>(
1607 copied_PL_Main.sublist(
"Line Search",
true).sublist(
"Polynomial",
true)
1611 l_result = (lineserchMaxIters == double(3.0));
1613 <<
"Read value = " << lineserchMaxIters <<
" == 3 : " 1614 << ( l_result ?
"passed" :
"failed") <<
"\n";
1615 if(!l_result) ++FailedTests;
1617 catch(
const std::exception &e) {
1619 std::cerr <<
"caught unexpected std::exception:\n\n";
1620 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1627 cout <<
"Use validateParemetersAndSetDefaults(...) to access a "<<
typeName<<
" as a std::string ...\n";
1631 Teuchos::setNumericStringParameter(
1632 "Max Iters",
"0",
"",
1633 &valid_PL_Main.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true)
1636 copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main);
1639 = Teuchos::getParameter<std::string>(
1640 copied_PL_Main.sublist(
"Line Search",
true).sublist(
"Polynomial",
true)
1644 l_result = (lineserchMaxIters ==
"3");
1646 <<
"Read value = \"" << lineserchMaxIters <<
"\" == \"3\" : " 1647 << ( l_result ?
"passed" :
"failed") <<
"\n";
1648 if(!l_result) ++FailedTests;
1650 catch(
const std::exception &e) {
1652 std::cerr <<
"caught unexpected std::exception:\n\n";
1653 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1662 cout <<
"Adding an invalid sublist then validating (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n";
1668 if (verbose) cout <<
"Did not throw std::exception, error!\n";
1673 std::cerr <<
"caught expected Teuchos::Exceptions::InvalidParameterName:\n\n";
1674 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1677 catch(
const std::exception &e) {
1679 std::cerr <<
"caught unexpected std::exception:\n\n";
1680 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1688 cout <<
"Validating only the top level list (should not throw std::exception)...\n";
1693 if (verbose) cout <<
"Did not throw std::exception, success!\n\n";
1695 catch(
const std::exception &e) {
1697 std::cerr <<
"caught unexpected std::exception:\n\n";
1698 OSTab tab(std::cerr); std::cerr << e.what() << std::endl;
1709 cout <<
"Checking that PL_Main == PL_Main == true : ";
1711 result = (PL_Main == PL_Main);
1715 cout << ( result ?
"passed" :
"failed" ) <<
"\n";
1721 cout <<
"Checking that PL_Main != PL_Main == false : ";
1723 result = !(PL_Main != PL_Main);
1727 cout << ( result ?
"passed" :
"failed" ) <<
"\n";
1733 cout <<
"Checking that PL_Main and PL_Main have the same values : ";
1739 cout << ( result ?
"passed" :
"failed" ) <<
"\n";
1745 cout <<
"Create copy PL_Main_copy, change PL_Main_copy, and check that PL_Main != PL_Main == true : ";
1748 PL_Main_copy.
sublist(
"Line Search",
true).
sublist(
"Polynomial",
true).
set(
"Max Iters",100);
1749 result = (PL_Main_copy != PL_Main);
1753 cout << ( result ?
"passed" :
"failed" ) <<
"\n";
1763 cout <<
"The Final Parameter List with Types and Documentation" << std::endl;
1767 cout <<
"The unused parameters" << std::endl;
1770 cout <<
"Number of Failed Tests : " << FailedTests << std::endl;
1781 if(!success) ++FailedTests;
1783 if ( FailedTests > 0 ) {
1784 cout <<
"End Result: TEST FAILED" << std::endl;
1788 if ( FailedTests == 0 )
1789 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.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValues(const ParameterList &list1, const ParameterList &list2)
Returns true if two parameter lists have the same values.
ConstIterator begin() const
An iterator pointing to the first entry.
T & get(const std::string &name, T def_value)
Return the parameter's value, or the default value if it is not there.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Set a parameter whose value has type T.
This object is held as the "value" in the Teuchos::ParameterList std::map.
const ParameterEntry & entry(ConstIterator i) const
Access to ParameterEntry (i.e., returns i->second)
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void updateParametersFromXmlFile(const std::string &xmlFileName, const Ptr< ParameterList > ¶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. HAVE_TEUCHOSCORE_CXX11 will call std::stoi otherwise we ...
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
Initialize, finalize, and query the global MPI session.
Simple helper functions that make it easy to read and write XML to and from a parameterlist.
void unused(std::ostream &os) const
Print out unused parameters in the ParameterList.
basic_OSTab< char > OSTab
double getDouble(const ParameterEntry &entry, const std::string ¶mName="", const std::string &sublistName="", const bool activeQuery=true) const
Get a double value from a parameter entry.
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Validate the parameters in this list given valid selections in the input list.
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.