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"));
304 ECHO(
const int my_int = pl.
get<
int>(
"my int"));
321 ECHO(
const int my_int =
getConst(pl).sublist(
"my sublist").get<int>(
"my int"));
336 ECHO(pl.
set(
"my int", 3,
"Some documentation"));
346 ECHO(pl.
set(
"my int", 3,
"Some documentation",
rcp(
new DummyValidator)));
349 TEST_NOTHROW(rcp_dynamic_cast<const DummyValidator>(my_int_param.validator(),
true));
383 ECHO(
const int my_int_1 = my_int_param.getValue<
int>(0));
413 ECHO(
char dummy_str_1[] =
"dummy str 1");
414 ECHO(pl.
set(
"dummy 1", dummy_str_1));
415 ECHO(
const std::string dummy_1 = pl.
get<std::string>(
"dummy 1"));
418 ECHO(
const char dummy_str_const_2[] =
"dummy str 2");
419 ECHO(pl.
set(
"dummy 2", dummy_str_const_2));
420 ECHO(
const std::string dummy_2 = pl.
get<std::string>(
"dummy 2"));
430 ECHO(
const std::string dummy_str =
"dummy str");
431 ECHO(pl.
set(
"my str", dummy_str));
432 ECHO(
const std::string my_str = pl.
get<std::string>(
"my str"));
446 ECHO(
char raw_str[] =
"dummy");
448 ECHO(
const char raw_c_str[] =
"dummy");
450 ECHO(
const std::string str =
"dummy");
506 ECHO(
int &my_int = pl.
get(
"my int", 3));
521 ECHO(
const bool param_was_removed_1 = pl.
remove(
"my int"));
526 ECHO(
const bool param_was_removed_2 = pl.
remove(
"my int",
false));
547 ECHO(pl.
sublist(
"my sublist",
false,
"My great sublist"));
578 ECHO(
const int my_int = pl.
sublist(
"my sublist").
get<
int>(
"my int"));
587 ECHO(
const int my_int =
getConst(pl).sublist(
"my sublist").get<int>(
"my int"));
612 const std::string Direction_Doc =
"This sublist controls how direction is computed.";
615 out <<
"PL_Main=\n" << PL_Main <<
"\n";
633 const std::string Direction_Doc =
"This sublist controls how direction is computed.";
638 out <<
"PL_Main=\n" << PL_Main <<
"\n";
658 ECHO(pl1.set(
"my int", 2));
668 ECHO(pl1.set(
"my int", 2));
684 ConstIter pl_itr = pl.
begin();
705 ConstIter pl_itr = pl.
begin();
729 A.
set(
"Hello",
"World");
731 B.
set(
"Hello",
"World");
844 ECHO(PL_Main.
set(
"Nonlinear Solver",
"Line Search Based"));
846 ECHO(
const int lineSearchValue = getIntegralValue<int>(PL_Main,
"Nonlinear Solver"));
848 ECHO(PL_Main.
set(
"Nonlinear Solver",
"Trust Region Based"));
849 ECHO(
const int trustRegionValue = getIntegralValue<int>(PL_Main,
"Nonlinear Solver"));
856 const int a_val = 2, b_val = 3;
859 replaceParameterWithArray<int>(
"A",
"A array", pl);
860 replaceParameterWithArray<int>(
"B",
"B", pl);
862 Array<int> a_array = tuple<int>(a_val), b_array = tuple<int>(b_val);
863 expected_pl.set(
"A array", a_array);
864 expected_pl.set(
"B", b_array);
865 TEST_ASSERT(haveSameValuesSorted(expected_pl, pl,
true));
869 TEST_THROW(replaceParameterWithArray<int>(
"C",
"B", pl), std::logic_error);
877 ParameterList valid_pl(
"My Valid Parameter List with a Modifier", modifier);
883 valid_pl.
set(
"A", 1.0);
884 valid_pl.
set(
"B", 0.1);
892 expected_valid_pl.
remove(
"SubA");
893 expected_valid_pl.
sublist(
"SubA 1").
set(
"C", 1);
894 expected_valid_pl.
sublist(
"SubA 2").
set(
"C", 1);
920 valid_pl.
set(
"A", 1.0);
921 valid_pl.
set(
"B", 1.0);
943 expected_valid_pl.
set(
"A", 1.0);
944 expected_valid_pl.
set(
"B", 1.0);
945 expected_valid_pl.
sublist(
"SubA 1").
set(
"C", 3);
946 expected_valid_pl.
sublist(
"SubA 1").
set(
"D", 4);
951 expected_valid_pl.
sublist(
"SubA 2").
set(
"C", 3);
952 expected_valid_pl.
sublist(
"SubA 2").
set(
"D", 4);
960 TEST_ASSERT(haveSameValuesSorted(expected_valid_pl, valid_pl,
true));
965 TEST_ASSERT(haveSameModifiers(valid_pl, expected_valid_pl));
979 valid_pl.
set(
"A", 1.0);
980 valid_pl.
set(
"B", 1.0);
996 expected_valid_pl.
set(
"A", 1.0);
997 expected_valid_pl.
set(
"B", 1.0);
998 expected_valid_pl.
sublist(
"SubA 1").
set(
"C", 3.0);
999 expected_valid_pl.
sublist(
"SubA 1").
set(
"D", 4);
1012 TEST_ASSERT(haveSameValuesSorted(expected_valid_pl, valid_pl,
true));
1017 TEST_ASSERT(haveSameValuesSorted(pl, copy_pl,
true));
1023 valid_pl.
set(
"A", 1);
1029 validated_pl.
set(
"A", 1.0);
1039 TEST_ASSERT(haveSameValuesSorted(validated_pl, pl,
true));
1047 valid_pl.
set(
"a", 1);
1057 reconciled_pl.
set(
"a", 1);
1058 reconciled_pl.
set(
"b", 5);
1063 TEST_ASSERT(haveSameValuesSorted(reconciled_pl, pl,
true));
1069 valid_pl.
set(
"a", 0.);
1079 validated_pl.
set(
"a", 1.);
1093 TEST_ASSERT(haveSameValuesSorted(validated_pl, pl,
true));
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.
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.
ParameterList createValidMainPL()
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
ParameterList & setEntry(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
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...
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.
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.
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 ...