31 virtual void printDoc(std::string
const& docString, std::ostream &out)
const {}
35 std::string
const& paramName,
36 std::string
const& sublistName
46 SimpleModifier() : Teuchos::ParameterListModifier(
"Simple Modifier"){}
57 std::logic_error,
"Parameters A and B can't both be less than 0.0");
66 SimpleSubModifier() : Teuchos::ParameterListModifier(
"Simple Sub Modifier"){}
75 const int max_CD = 10;
77 std::logic_error,
"Parameters C and D can't both be greater than 10")
85 ReconciliationModifier1() : Teuchos::ParameterListModifier(
"Reconciliation Modifier 1"){}
91 pl.
set(
"b", subA.
get<
int>(
"e"));
99 ReconciliationModifier2() : Teuchos::ParameterListModifier(
"Reconciliation Modifier 2"){}
103 pl.
set(
"e", pl.
get<
int>(
"c") + pl.
get<
int>(
"d"));
122 const std::string Direction_Doc =
"This sublist controls how direction is computed.";
125 PL_Newton.
sublist(
"Linear Solver");
126 PL_Main.
sublist(
"Line Search");
139 setStringToIntegralParameter<int>(
142 "Selects the type of nonlinear solver to use",
143 tuple<std::string>(
"Line Search Based",
"Trust Region Based"),
151 linesearchMaxItersValidator =
rcp(
154 AcceptedTypes(
false).allowInt(
true).allowDouble(
true).allowString(
true)
159 ,
"The maximum number of inner linear search iterations allowed."
160 ,linesearchMaxItersValidator
166 linSolveTolValidator =
rcp(
169 AcceptedTypes(
false).allowDouble(
true).allowString(
true)
175 ,
"Select the linear solve tolerance"
176 ,linSolveTolValidator
182 elementsValidator =
rcp(
185 AcceptedTypes(
false).allowInt(
true).allowLongLong(
true).allowString(
true)
188 typedef long long LL;
190 "Elements", LL(72057594037927936ll)
191 ,
"Number of finite elements to generate"
195 return PL_Main_valid;
252 ECHO(
const bool param_isType_int1 = my_int_c_param.isType<
int>());
254 ECHO(
const bool param_isType_double1 = my_int_c_param.isType<
double>());
262 ECHO(
const int my_int = pl.
get<
int>(
"my int"));
303 pl_expected.
sublist(
"SubA", modifier1).
set(
"B", 2).
set(
"A", 1);
312 ECHO(
const int my_int = pl.
get<
int>(
"my int"));
329 ECHO(
const int my_int =
getConst(pl).sublist(
"my sublist").get<int>(
"my int"));
344 ECHO(pl.
set(
"my int", 3,
"Some documentation"));
354 ECHO(pl.
set(
"my int", 3,
"Some documentation",
rcp(
new DummyValidator)));
357 TEST_NOTHROW(rcp_dynamic_cast<const DummyValidator>(my_int_param.validator(),
true));
391 ECHO(
const int my_int_1 = my_int_param.getValue<
int>(0));
421 ECHO(
char dummy_str_1[] =
"dummy str 1");
422 ECHO(pl.
set(
"dummy 1", dummy_str_1));
423 ECHO(
const std::string dummy_1 = pl.
get<std::string>(
"dummy 1"));
426 ECHO(
const char dummy_str_const_2[] =
"dummy str 2");
427 ECHO(pl.
set(
"dummy 2", dummy_str_const_2));
428 ECHO(
const std::string dummy_2 = pl.
get<std::string>(
"dummy 2"));
438 ECHO(
const std::string dummy_str =
"dummy str");
439 ECHO(pl.
set(
"my str", dummy_str));
440 ECHO(
const std::string my_str = pl.
get<std::string>(
"my str"));
449 ECHO(std::string my_str_1{
"my text 1"});
450 ECHO(pl.
set(
"my string 1", std::move(my_str_1)));
466 ECHO(std::string my_str_2{
"my text 2"});
467 ECHO(pl.
set<std::string>(
"my string 2", std::move(my_str_2)));
473 ECHO(std::string my_str_3{
"my text 3"});
474 ECHO(pl.
set<std::string>(
"my string 3", my_str_3));
478 ECHO(
const std::string my_str_4{
"my text 4"});
479 ECHO(pl.
set<std::string>(
"my string 4", my_str_4));
483 ECHO(pl.
set<std::string>(
"my string 5",
"my text 5"));
489 operator const int&()
const {
return value; }
501 ECHO(pl.
set<
int>(
"my int", my_wrapped_int));
513 ECHO(
char raw_str[] =
"dummy");
515 ECHO(
const char raw_c_str[] =
"dummy");
517 ECHO(
const std::string str =
"dummy");
573 ECHO(
int &my_int = pl.
get(
"my int", 3));
588 ECHO(
const bool param_was_removed_1 = pl.
remove(
"my int"));
593 ECHO(
const bool param_was_removed_2 = pl.
remove(
"my int",
false));
614 ECHO(pl.
sublist(
"my sublist",
false,
"My great sublist"));
645 ECHO(
const int my_int = pl.
sublist(
"my sublist").
get<
int>(
"my int"));
654 ECHO(
const int my_int =
getConst(pl).sublist(
"my sublist").get<int>(
"my int"));
679 const std::string Direction_Doc =
"This sublist controls how direction is computed.";
682 out <<
"PL_Main=\n" << PL_Main <<
"\n";
700 const std::string Direction_Doc =
"This sublist controls how direction is computed.";
705 out <<
"PL_Main=\n" << PL_Main <<
"\n";
725 ECHO(pl1.set(
"my int", 2));
735 ECHO(pl1.set(
"my int", 2));
751 ConstIter pl_itr = pl.
begin();
772 ConstIter pl_itr = pl.
begin();
796 A.
set(
"Hello",
"World");
798 B.
set(
"Hello",
"World");
910 #if defined(HAVE_TEUCHOS_MODIFY_DEFAULTS_DURING_VALIDATION)
920 PL_Main.
set(
"Nonlinear Solver",
"Trust Region Based");
926 #if defined(HAVE_TEUCHOS_MODIFY_DEFAULTS_DURING_VALIDATION)
936 ECHO(PL_Main.
set(
"Nonlinear Solver",
"Line Search Based"));
938 ECHO(
const int lineSearchValue = getIntegralValue<int>(PL_Main,
"Nonlinear Solver"));
940 ECHO(PL_Main.
set(
"Nonlinear Solver",
"Trust Region Based"));
941 ECHO(
const int trustRegionValue = getIntegralValue<int>(PL_Main,
"Nonlinear Solver"));
948 const int a_val = 2, b_val = 3;
951 replaceParameterWithArray<int>(
"A",
"A array", pl);
952 replaceParameterWithArray<int>(
"B",
"B", pl);
954 Array<int> a_array = tuple<int>(a_val), b_array = tuple<int>(b_val);
955 expected_pl.set(
"A array", a_array);
956 expected_pl.set(
"B", b_array);
957 TEST_ASSERT(haveSameValuesSorted(expected_pl, pl,
true));
961 TEST_THROW(replaceParameterWithArray<int>(
"C",
"B", pl), std::logic_error);
969 ParameterList valid_pl(
"My Valid Parameter List with a Modifier", modifier);
975 valid_pl.
set(
"A", 1.0);
976 valid_pl.
set(
"B", 0.1);
984 expected_valid_pl.
remove(
"SubA");
985 expected_valid_pl.
sublist(
"SubA 1").
set(
"C", 1);
986 expected_valid_pl.
sublist(
"SubA 2").
set(
"C", 1);
1012 input.sublist(
"A").sublist(
"B");
1013 valid.sublist(
"A", mod_A);
1014 valid.sublist(
"A").sublist(
"B", mod_B);
1015 input.modifyParameterList(valid);
1026 valid_pl.
set(
"A", 1.0);
1027 valid_pl.
set(
"B", 1.0);
1049 expected_valid_pl.
set(
"A", 1.0);
1050 expected_valid_pl.
set(
"B", 1.0);
1051 expected_valid_pl.
sublist(
"SubA 1").
set(
"C", 3);
1052 expected_valid_pl.
sublist(
"SubA 1").
set(
"D", 4);
1057 expected_valid_pl.
sublist(
"SubA 2").
set(
"C", 3);
1058 expected_valid_pl.
sublist(
"SubA 2").
set(
"D", 4);
1066 TEST_ASSERT(haveSameValuesSorted(expected_valid_pl, valid_pl,
true));
1071 TEST_ASSERT(haveSameModifiers(valid_pl, expected_valid_pl));
1085 valid_pl.
set(
"A", 1.0);
1086 valid_pl.
set(
"B", 1.0);
1102 expected_valid_pl.
set(
"A", 1.0);
1103 expected_valid_pl.
set(
"B", 1.0);
1104 expected_valid_pl.
sublist(
"SubA 1").
set(
"C", 3.0);
1105 expected_valid_pl.
sublist(
"SubA 1").
set(
"D", 4);
1118 TEST_ASSERT(haveSameValuesSorted(expected_valid_pl, valid_pl,
true));
1123 TEST_ASSERT(haveSameValuesSorted(pl, copy_pl,
true));
1129 valid_pl.
set(
"A", 1);
1135 validated_pl.
set(
"A", 1.0);
1145 TEST_ASSERT(haveSameValuesSorted(validated_pl, pl,
true));
1153 valid_pl.
set(
"a", 1);
1163 reconciled_pl.
set(
"a", 1);
1164 reconciled_pl.
set(
"b", 5);
1169 TEST_ASSERT(haveSameValuesSorted(reconciled_pl, pl,
true));
1175 valid_pl.
set(
"a", 0.);
1185 validated_pl.
set(
"a", 1.);
1199 TEST_ASSERT(haveSameValuesSorted(validated_pl, pl,
true));
1207 valid_pl.
set(
"a", 0.);
1215 std::ostringstream ss;
1216 pl.
print(ss, printOptions);
1217 std::cout << ss.str();
1225 std::ostringstream ss;
1226 pl.
print(ss, printOptions);
1227 std::cout << ss.str();
1232 pl.
print(ss, printOptions);
1233 std::cout << ss.str();
1241 enum class Shape : int { CIRCLE, SQUARE, TRIANGLE };
1247 std::vector<int> testVec = {1};
1249 paramList.
set(
"My std::vector<int>", testVec);
1256 std::string actualMessage = except.what();
1257 std::string expectedMessage =
"Trying to print type std::vector<int, std::allocator<int> > "
1258 "which is not printable (i.e. does not have operator<<() defined)!";
1259 TEST_ASSERT(actualMessage.find(expectedMessage) != std::string::npos);
1266 paramList.
set(
"My enum class", Shape::SQUARE);
1273 std::string actualMessage = except.what();
1274 std::string expectedMessage =
1275 "Trying to print type Teuchos::(anonymous namespace)::Shape which is not printable "
1276 "(i.e. does not have operator<<() defined)!";
1277 TEST_ASSERT(actualMessage.find(expectedMessage) != std::string::npos);
ParameterList createMainPL()
void print() const
Print function to use in debugging in a debugger.
const std::string & name() const
The name of this ParameterList.
C++ Standard Library compatable filtered iterator.
#define TEST_ASSERT(v1)
Assert the given statement is true.
ParameterList & setEntry(const std::string &name, U &&entry)
Set a parameter directly as a ParameterEntry.
ConstIterator end() const
An iterator pointing beyond the last entry.
#define TEST_INEQUALITY_CONST(v1, v2)
Assert the inequality of v1 and constant v2.
RCP< ParameterEntry > getEntryRCP(const std::string &name)
Retrieves the RCP for an entry with the name name if it exists.
ParameterList & disableRecursiveValidation()
#define TEST_NOTHROW(code)
Asserr that the statement 'code' does not thrown any excpetions.
#define ECHO(statement)
Echo the given statement before it is executed.
void setValidator(RCP< const ParameterEntryValidator > const &validator)
Set the validator.
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
T & get(const std::string &name, T def_value)
Return the parameter's value, or the default value if it is not there.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
This object is held as the "value" in the Teuchos::ParameterList std::map.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
virtual void printDoc(std::string const &docString, std::ostream &out) const =0
Print documentation for this parameter.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
#define TEST_ITER_EQUALITY(iter1, iter2)
Assert that two iterators are equal.
Exception class for non-printable parameter types, such as enum class/std::vector and many more which...
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEST_THROW(code, ExceptType)
Assert that the statement 'code' throws the exception 'ExceptType' (otherwise the test fails)...
virtual const std::string getXMLTypeName() const =0
Get a string that should be used as a value of the type attribute when serializing it to XML...
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
Ordinal numParams() const
Get the number of stored parameters.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method.
Abstract interface for an object that can modify both a parameter list and the parameter list being u...
void recursivelySetValidator(RCP< const ParameterEntryValidator > const &validator, int const depth=1000)
Recursively attach a validator to parameters of type T.
bool isDefault() const
Indicate whether this entry takes on the default value.
ParameterList createValidMainPL()
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
PrintOptions & showDefault(bool _showDefault)
Determines the types that are accepted.
bool isParameter(const std::string &name) const
Whether the given parameter exists in this list.
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
bool remove(std::string const &name, bool throwIfNotExists=true)
Remove a parameter (does not depend on the type of the parameter).
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
virtual void modify(ParameterList ¶mList, ParameterList &validParamList) const
Modify a parameter list and/or the valid parameter list being used to validate it and throw std::exce...
bool isSublist(const std::string &name) const
Whether the given sublist exists in this list.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
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...
int expandSublistsUsingBaseName(const std::string &baseName, ParameterList ¶mList, ParameterList &validParamList, const bool &allowBaseName=true) const
Create sublists in the valid parameter list using a base name and the corresponding sublists in the p...
Utility class for setting and passing in print options.
virtual ValidStringsList validStringValues() const =0
Return an array of strings of valid values if applicable.
ConstIterator begin() const
An iterator pointing to the first entry.
T * getPtr(const std::string &name)
Retrieves the pointer for parameter name of type T from a list. A null pointer is returned if this pa...
A list of parameters of arbitrary type.
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.
ParameterList & setParameters(const ParameterList &source)
Parameter List Modifier class.
void modifyParameterList(ParameterList &validParamList, int const depth=1000)
Modify the valid parameter list prior to validation.
Abstract interface for an object that can validate a ParameterEntry's value.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
RCP< const ParameterListModifier > getModifier() const
Return the optional modifier object.
ParameterList & setParametersNotAlreadySet(const ParameterList &source)
Class uesd to validate a particular type of number.
virtual void reconcile(ParameterList ¶mList) const
Reconcile a parameter list and/or the valid parameter list being used to validate it and throw std::e...
bool isType(const std::string &name) const
Whether the given parameter exists in this list and has type T.
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.
bool isUsed() const
Return whether or not the value has been used; i.e., whether or not the value has been retrieved via ...
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
ParameterEntry & getEntry(const std::string &name)
Retrieves an entry with the name name.
ParameterList & disableRecursiveModification()
Definition of Teuchos::as, for conversions between types.
void reconcileParameterList(ParameterList &validParamList, const bool left_to_right=true)
Reconcile a parameter list after validation.
void setModifier(RCP< const ParameterListModifier > const &modifier)
virtual void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const =0
Validate a parameter entry value and throw std::exception (with a great error message) if validation ...