00001 #include "Teuchos_ParameterList.hpp"
00002 #include "Teuchos_StandardParameterEntryValidators.hpp"
00003 #include "Teuchos_Array.hpp"
00004 #include "Teuchos_Version.hpp"
00005
00006 int main(int argc, char* argv[])
00007 {
00008 std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
00009
00010
00011 Teuchos::ParameterList My_List;
00012
00013
00014 My_List.set("Max Iters", 1550, "Determines the maximum number of iterations in the solver");
00015 My_List.set("Tolerance", 1e-10, "The tolerance used for the convergence check");
00016
00017
00018
00019 Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00020 solverValidator = Teuchos::rcp(
00021 new Teuchos::StringToIntegralParameterEntryValidator<int>(
00022 Teuchos::tuple<std::string>( "GMRES", "CG", "TFQMR" )
00023 ,"Solver"
00024 )
00025 );
00026 My_List.set(
00027 "Solver"
00028 ,"GMRES"
00029 ,"The type of solver to use."
00030 ,solverValidator
00031 );
00032
00033
00034
00035
00036
00037 My_List.set("Tolerance", (float)(1e-10), "The tolerance used for the convergence check");
00038
00039
00040
00041
00042
00043
00044
00045 Teuchos::RCP<Teuchos::Array<double> > rcp_Array =
00046 Teuchos::rcp( new Teuchos::Array<double>( 10, 0.0 ) );
00047
00048 My_List.set("Initial Guess", rcp_Array, "The initial guess as a RCP to an array object.");
00049
00050
00051
00052
00053
00054 Teuchos::ParameterList&
00055 Prec_List = My_List.sublist("Preconditioner",false,"Sublist that defines the preconditioner.");
00056
00057
00058 Prec_List.set("Type", "ILU", "The tpye of preconditioner to use");
00059 Prec_List.set("Drop Tolerance", 1e-3
00060 ,"The tolerance below which entries from the\n""factorization are left out of the factors.");
00061
00062
00063
00064 bool solver_defined = false, prec_defined = false, dtol_double = false;
00065 solver_defined = My_List.isParameter("Solver");
00066
00067 prec_defined = My_List.isSublist("Preconditioner");
00068
00069 bool tol_double = false;
00070 tol_double = My_List.INVALID_TEMPLATE_QUALIFIER isType<double>("Tolerance");
00071
00072 dtol_double = Teuchos::isParameterType<double>(Prec_List, "Drop Tolerance");
00073
00074
00075
00076
00077
00078
00079
00080
00081 int its = 0;
00082 its = My_List.get("Max Iters", 1200);
00083 float tol;
00084
00085 tol = My_List.INVALID_TEMPLATE_QUALIFIER get<float>("Tolerance");
00086
00087 std::string
00088 solver = solverValidator->validateString(
00089 Teuchos::getParameter<std::string>(My_List,"Solver")
00090 );
00091
00092
00093
00094
00095
00096
00097
00098
00099 try {
00100 tol = My_List.INVALID_TEMPLATE_QUALIFIER get<float>("Tolerance");
00101 }
00102 catch ( std::exception& e) {
00103 tol = 1e-6;
00104 }
00105
00106
00107
00108
00109
00110 try {
00111 tol = Teuchos::getParameter<float>(My_List, "Tolerance");
00112 }
00113 catch ( std::exception& e) {
00114 tol = 1e-6;
00115 }
00116
00117
00118
00119
00120 try {
00121 Teuchos::RCP<Teuchos::Array<double> > init_guess =
00122 Teuchos::getParameter<Teuchos::RCP<Teuchos::Array<double> > >(My_List, "Initial Guess");
00123 }
00124 catch ( std::exception& e) {
00125 std::cout << e.what() << std::endl;
00126 }
00127
00128 std::cout << "\n# Printing this parameter list using opeator<<(...) ...\n\n";
00129 std::cout << My_List << std::endl;
00130
00131 std::cout << "\n# Printing the parameter list only showing documentation fields ...\n\n";
00132 My_List.print(std::cout,Teuchos::ParameterList::PrintOptions().showDoc(true).indent(2).showTypes(true));
00133
00134
00135
00136
00137
00138
00139 std::cout << "\n# Showing unused parameters ...\n\n";
00140 My_List.unused( std::cout );
00141
00142 return 0;
00143 }