20 #include <Teuchos_Parser.hpp>
25 namespace TeuchosTests
31 vector<string> matchStems;
32 matchStems.push_back(
"Match1");
33 matchStems.push_back(
"Match2");
34 matchStems.push_back(
"Match3");
35 matchStems.push_back(
"Match4");
36 for(
size_t i = 0; i < matchStems.size(); i++)
38 string yamlFile = matchStems[i] +
".yaml";
40 string xmlFile = matchStems[i] +
".xml";
42 TEST_EQUALITY(Teuchos::haveSameValues(*xmlList, *yamlList,
true),
true);
51 TEST_EQUALITY(Teuchos::haveSameValues(*xmlList, *yamlList),
false);
61 "My Awesome Problem:\n"
62 " Particle Periodic:\n"
64 " emotions: happy_sad, indifferent\n"
72 "My Awesome Problem:\n"
76 " Elements: [ 10, 10 ]\n"
83 int correctInts[5] = {2, 3, 5, 7, 11};
85 double correctDoubles[5] = {2.718, 3.14159, 1.618, 1.23456789, 42.1337};
93 for(
int i = 0; i < 5; i++)
101 std::string correctStrings[5] = {
"2",
"3",
"5",
"7",
"imastring"};
102 double correctDoubles[5] = {2, 3, 1.618, 1.23456789, 42.1337};
107 for(
int i = 0; i < 5; i++)
109 if(stringArr[i] != correctStrings[i])
111 throw std::runtime_error(std::string(
"stringArray value is incorrect."));
113 if(doubleArr[i] != correctDoubles[i])
115 throw std::runtime_error(std::string(
"doubleArray value is incorrect."));
121 std::string xmlString =
123 " <ParameterList name=\"Problem\">\n"
124 " <ParameterList name=\"Neumann BCs\">\n"
125 " <ParameterList name=\"Time Dependent NBC on SS cyl_outside for DOF all set P\">\n"
126 " <Parameter name=\"BC Values\" type=\"TwoDArray(double)\" value=\"3x1:{ 0.0, 10.0, 20.0}\"/>\n"
127 " </ParameterList>\n"
128 " </ParameterList>\n"
129 " </ParameterList>\n"
130 " <ParameterList name=\"Discretization\">\n"
131 " <Parameter name=\"Node Set Associations\" type=\"TwoDArray(string)\" value=\"2x2:{1, 2, top, bottom}\"/>\n"
132 " <Parameter name=\"Bool-looking String\" type=\"string\" value=\"TRUE\" docString=\"my docString\"/>\n"
133 " </ParameterList>\n"
134 " </ParameterList>\n";
136 std::stringstream yamlOutStream;
137 yamlOutStream << std::showpoint << std::fixed << std::setprecision(1);
139 std::string yamlString = yamlOutStream.str();
140 std::string expectedYamlString =
146 " Time Dependent NBC on SS cyl_outside for DOF all set P: \n"
147 " BC Values: [[0.0], [10.0], [20.0]]\n"
148 " Discretization: \n"
149 " Node Set Associations: [['1', '2'], [top, bottom]]\n"
150 " Bool-looking String: 'TRUE'\n"
153 std::stringstream yamlInStream(yamlString);
156 std::stringstream yamlOutStream2;
157 yamlOutStream2 << std::showpoint << std::fixed << std::setprecision(1);
159 std::string yamlString2 = yamlOutStream2.str();
168 " File Name: electrostatic.exo\n"
169 " Cell Average Quantities:\n"
170 " eblock-0_0: ES_POTENTIAL, E0\n"
173 " File Name: beam_emit2.h5part\n");
181 " File Name: beam_emit2.h5part\n"
182 "# Stride Time: 5.0e-12\n");
189 " Boundary Conditions:\n"
193 " Field: ES_POTENTIAL\n"
195 " double r_sq = xin*xin+yin*yin;\n"
196 " double factor = 0.5*1.e8*1.60217662e-19/(2*3.14159265358979323846*8.854187817e-12);\n"
197 " ES_POTENTIAL= factor*log(r_sq) +3*xin-3*yin;\n"
198 " # end Boundary Conditions\n");
200 Teuchos::getParameter<std::string>(
201 params->sublist(
"Boundary Conditions",
true)
202 .sublist(
"Bottom",
true)
203 .sublist(
"Dirichlet",
true)
205 "double r_sq = xin*xin+yin*yin;\n"
206 "double factor = 0.5*1.e8*1.60217662e-19/(2*3.14159265358979323846*8.854187817e-12);\n"
207 "ES_POTENTIAL= factor*log(r_sq) +3*xin-3*yin;\n");
219 Teuchos::ParserFail);
225 char const *
const cstr =
232 std::stringstream ss;
233 ss << std::showpoint;
243 " small number: 54\n"
244 " small double: 3.0\n"
245 " scientific: 3.123e02\n"
246 " big number: 72057594037927936\n"
252 TEST_EQUALITY(pl->get<
long long>(
"big number"), 72057594037927936ll);
259 " input_true: true\n"
260 " input_false: false\n"
261 " input_TRUE: TRUE\n"
262 " input_FALSE: FALSE\n"
263 " input_True: True\n"
264 " input_False: False\n"
290 " Fields: {rho: 0.125, px: 0., py: 0., pz: 0., rho_E: 0.25}\n");
291 auto& field_pl = pl->sublist(
"Fields");
306 auto& sublist = pl.
sublist(
"sublist");
319 #ifdef HAVE_TEUCHOSPARAMETERLIST_YAMLCPP
324 " list_of_2d_arrays:\n"
325 " - [[1,2,3], [4,5,6]]\n"
326 " - [[7,8,9], [10,11,12]]\n"
330 " line_continuation: [\n"
334 " # allow unicode comments: ±\n"
338 threeDarr_t& list_of_arrs = pl->
get<threeDarr_t>(
"list_of_2d_arrays");
339 threeDarr_t correct_list_of_arrs = {
340 {{1, 2, 3}, {4, 5, 6}},
341 {{7, 8, 9}, {10, 11, 12}}
343 for (
int i=0; i<list_of_arrs.size(); i++) {
344 for (
int j=0; j<list_of_arrs[i].size(); j++) {
345 for (
int k=0; k<list_of_arrs[i][j].size(); k++) {
346 TEST_EQUALITY(correct_list_of_arrs[i][j][k], list_of_arrs[i][j][k]);
352 twoDarr_t ragged_arr = pl->
get<twoDarr_t>(
"ragged_array");
353 twoDarr_t correct_ragged_arr = {
357 for (
int i=0; i<ragged_arr.size(); i++) {
358 for (
int j=0; j<ragged_arr[i].size(); j++) {
364 arr_t arr = pl->
get<arr_t>(
"line_continuation");
365 arr_t correct_arr = {1, 2, 3, 4, 5, 6};
366 for (
int i=0; i<arr.size(); i++) {
376 Teuchos::YamlKeyError)
382 Teuchos::YamlSequenceError)
385 Teuchos::YamlStructureError)
390 #endif // HAVE_TEUCHOSPARAMETERLIST_YAMLCPP
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
Teuchos::RCP< Teuchos::ParameterList > parseYamlStream(std::istream &yaml)
Functions to convert between ParameterList and YAML.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void updateParametersFromYamlCString(const char *const data, const Teuchos::Ptr< Teuchos::ParameterList > ¶mList, bool overwrite)
void writeParameterListToYamlOStream(const ParameterList ¶mList, std::ostream &yamlOut)
T & get(const std::string &name, T def_value)
Return the parameter's value, or the default value if it is not there.
#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)...
Teuchos::RCP< Teuchos::ParameterList > getParametersFromYamlString(const std::string &yamlStr)
Simple helper functions that make it easy to read and write XML to and from a parameterlist.
Templated Parameter List class.
bool isSublist(const std::string &name) const
Whether the given sublist exists in this list.
A list of parameters of arbitrary type.
void updateParametersFromYamlString(const std::string &yamlData, const Teuchos::Ptr< Teuchos::ParameterList > ¶mList, bool overwrite, const std::string &name)
TEUCHOS_UNIT_TEST(YAML, XmlEquivalence)
Defines basic traits for the scalar field type.
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.
Teuchos::RCP< Teuchos::ParameterList > getParametersFromYamlFile(const std::string &yamlFileName)
void writeYamlStream(std::ostream &yaml, const Teuchos::ParameterList &pl)
Simple helper functions that make it easy to read and write Yaml to and from a parameterlist.
Reference-counted pointer class and non-member templated function implementations.