63 virtual void printDoc(std::string
const& docString, std::ostream &out)
const {}
67 std::string
const& paramName,
68 std::string
const& sublistName
78 SimpleModifier() : Teuchos::ParameterListModifier(
"Simple Modifier"){}
89 std::logic_error,
"Parameters A and B can't both be less than 0.0");
98 SimpleSubModifier() : Teuchos::ParameterListModifier(
"Simple Sub Modifier"){}
107 const int max_CD = 10;
109 std::logic_error,
"Parameters C and D can't both be greater than 10")
117 ReconciliationModifier1() : Teuchos::ParameterListModifier(
"Reconciliation Modifier 1"){}
123 pl.
set(
"b", subA.
get<
int>(
"e"));
131 ReconciliationModifier2() : Teuchos::ParameterListModifier(
"Reconciliation Modifier 2"){}
135 pl.
set(
"e", pl.
get<
int>(
"c") + pl.
get<
int>(
"d"));
154 const std::string Direction_Doc =
"This sublist controls how direction is computed.";
157 PL_Newton.
sublist(
"Linear Solver");
158 PL_Main.
sublist(
"Line Search");
171 setStringToIntegralParameter<int>(
174 "Selects the type of nonlinear solver to use",
175 tuple<std::string>(
"Line Search Based",
"Trust Region Based"),
183 linesearchMaxItersValidator =
rcp(
186 AcceptedTypes(
false).allowInt(
true).allowDouble(
true).allowString(
true)
191 ,
"The maximum number of inner linear search iterations allowed."
192 ,linesearchMaxItersValidator
198 linSolveTolValidator =
rcp(
201 AcceptedTypes(
false).allowDouble(
true).allowString(
true)
207 ,
"Select the linear solve tolerance"
208 ,linSolveTolValidator
214 elementsValidator =
rcp(
217 AcceptedTypes(
false).allowInt(
true).allowLongLong(
true).allowString(
true)
220 typedef long long LL;
222 "Elements", LL(72057594037927936ll)
223 ,
"Number of finite elements to generate"
227 return PL_Main_valid;
284 ECHO(
const bool param_isType_int1 = my_int_c_param.isType<
int>());
286 ECHO(
const bool param_isType_double1 = my_int_c_param.isType<
double>());
294 ECHO(
const int my_int = pl.
get<
int>(
"my int"));
335 pl_expected.
sublist(
"SubA", modifier1).
set(
"B", 2).
set(
"A", 1);
344 ECHO(
const int my_int = pl.
get<
int>(
"my int"));
361 ECHO(
const int my_int =
getConst(pl).sublist(
"my sublist").get<int>(
"my int"));
376 ECHO(pl.
set(
"my int", 3,
"Some documentation"));
386 ECHO(pl.
set(
"my int", 3,
"Some documentation",
rcp(
new DummyValidator)));
389 TEST_NOTHROW(rcp_dynamic_cast<const DummyValidator>(my_int_param.validator(),
true));
423 ECHO(
const int my_int_1 = my_int_param.getValue<
int>(0));
453 ECHO(
char dummy_str_1[] =
"dummy str 1");
454 ECHO(pl.
set(
"dummy 1", dummy_str_1));
455 ECHO(
const std::string dummy_1 = pl.
get<std::string>(
"dummy 1"));
458 ECHO(
const char dummy_str_const_2[] =
"dummy str 2");
459 ECHO(pl.
set(
"dummy 2", dummy_str_const_2));
460 ECHO(
const std::string dummy_2 = pl.
get<std::string>(
"dummy 2"));
470 ECHO(
const std::string dummy_str =
"dummy str");
471 ECHO(pl.
set(
"my str", dummy_str));
472 ECHO(
const std::string my_str = pl.
get<std::string>(
"my str"));
486 ECHO(
char raw_str[] =
"dummy");
488 ECHO(
const char raw_c_str[] =
"dummy");
490 ECHO(
const std::string str =
"dummy");
546 ECHO(
int &my_int = pl.
get(
"my int", 3));
561 ECHO(
const bool param_was_removed_1 = pl.
remove(
"my int"));
566 ECHO(
const bool param_was_removed_2 = pl.
remove(
"my int",
false));
587 ECHO(pl.
sublist(
"my sublist",
false,
"My great sublist"));
618 ECHO(
const int my_int = pl.
sublist(
"my sublist").
get<
int>(
"my int"));
627 ECHO(
const int my_int =
getConst(pl).sublist(
"my sublist").get<int>(
"my int"));
652 const std::string Direction_Doc =
"This sublist controls how direction is computed.";
655 out <<
"PL_Main=\n" << PL_Main <<
"\n";
673 const std::string Direction_Doc =
"This sublist controls how direction is computed.";
678 out <<
"PL_Main=\n" << PL_Main <<
"\n";
698 ECHO(pl1.set(
"my int", 2));
708 ECHO(pl1.set(
"my int", 2));
724 ConstIter pl_itr = pl.
begin();
745 ConstIter pl_itr = pl.
begin();
769 A.
set(
"Hello",
"World");
771 B.
set(
"Hello",
"World");
883 #if defined(HAVE_TEUCHOS_MODIFY_DEFAULTS_DURING_VALIDATION)
893 PL_Main.
set(
"Nonlinear Solver",
"Trust Region Based");
899 #if defined(HAVE_TEUCHOS_MODIFY_DEFAULTS_DURING_VALIDATION)
909 ECHO(PL_Main.
set(
"Nonlinear Solver",
"Line Search Based"));
911 ECHO(
const int lineSearchValue = getIntegralValue<int>(PL_Main,
"Nonlinear Solver"));
913 ECHO(PL_Main.
set(
"Nonlinear Solver",
"Trust Region Based"));
914 ECHO(
const int trustRegionValue = getIntegralValue<int>(PL_Main,
"Nonlinear Solver"));
921 const int a_val = 2, b_val = 3;
924 replaceParameterWithArray<int>(
"A",
"A array", pl);
925 replaceParameterWithArray<int>(
"B",
"B", pl);
927 Array<int> a_array = tuple<int>(a_val), b_array = tuple<int>(b_val);
928 expected_pl.set(
"A array", a_array);
929 expected_pl.set(
"B", b_array);
930 TEST_ASSERT(haveSameValuesSorted(expected_pl, pl,
true));
934 TEST_THROW(replaceParameterWithArray<int>(
"C",
"B", pl), std::logic_error);
942 ParameterList valid_pl(
"My Valid Parameter List with a Modifier", modifier);
948 valid_pl.
set(
"A", 1.0);
949 valid_pl.
set(
"B", 0.1);
957 expected_valid_pl.
remove(
"SubA");
958 expected_valid_pl.
sublist(
"SubA 1").
set(
"C", 1);
959 expected_valid_pl.
sublist(
"SubA 2").
set(
"C", 1);
985 input.sublist(
"A").sublist(
"B");
986 valid.sublist(
"A", mod_A);
987 valid.sublist(
"A").sublist(
"B", mod_B);
988 input.modifyParameterList(valid);
999 valid_pl.
set(
"A", 1.0);
1000 valid_pl.
set(
"B", 1.0);
1022 expected_valid_pl.
set(
"A", 1.0);
1023 expected_valid_pl.
set(
"B", 1.0);
1024 expected_valid_pl.
sublist(
"SubA 1").
set(
"C", 3);
1025 expected_valid_pl.
sublist(
"SubA 1").
set(
"D", 4);
1030 expected_valid_pl.
sublist(
"SubA 2").
set(
"C", 3);
1031 expected_valid_pl.
sublist(
"SubA 2").
set(
"D", 4);
1039 TEST_ASSERT(haveSameValuesSorted(expected_valid_pl, valid_pl,
true));
1044 TEST_ASSERT(haveSameModifiers(valid_pl, expected_valid_pl));
1058 valid_pl.
set(
"A", 1.0);
1059 valid_pl.
set(
"B", 1.0);
1075 expected_valid_pl.
set(
"A", 1.0);
1076 expected_valid_pl.
set(
"B", 1.0);
1077 expected_valid_pl.
sublist(
"SubA 1").
set(
"C", 3.0);
1078 expected_valid_pl.
sublist(
"SubA 1").
set(
"D", 4);
1091 TEST_ASSERT(haveSameValuesSorted(expected_valid_pl, valid_pl,
true));
1096 TEST_ASSERT(haveSameValuesSorted(pl, copy_pl,
true));
1102 valid_pl.
set(
"A", 1);
1108 validated_pl.
set(
"A", 1.0);
1118 TEST_ASSERT(haveSameValuesSorted(validated_pl, pl,
true));
1126 valid_pl.
set(
"a", 1);
1136 reconciled_pl.
set(
"a", 1);
1137 reconciled_pl.
set(
"b", 5);
1142 TEST_ASSERT(haveSameValuesSorted(reconciled_pl, pl,
true));
1148 valid_pl.
set(
"a", 0.);
1158 validated_pl.
set(
"a", 1.);
1172 TEST_ASSERT(haveSameValuesSorted(validated_pl, pl,
true));
1180 valid_pl.
set(
"a", 0.);
1188 std::ostringstream ss;
1189 pl.
print(ss, printOptions);
1190 std::cout << ss.str();
1198 std::ostringstream ss;
1199 pl.
print(ss, printOptions);
1200 std::cout << ss.str();
1205 pl.
print(ss, printOptions);
1206 std::cout << ss.str();
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.
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.
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.
#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.
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 ...