58 #include <Teuchos_Parser.hpp>
63 namespace TeuchosTests
69 vector<string> matchStems;
70 matchStems.push_back(
"Match1");
71 matchStems.push_back(
"Match2");
72 matchStems.push_back(
"Match3");
73 matchStems.push_back(
"Match4");
74 for(
size_t i = 0; i < matchStems.size(); i++)
76 string yamlFile = matchStems[i] +
".yaml";
78 string xmlFile = matchStems[i] +
".xml";
80 TEST_EQUALITY(Teuchos::haveSameValues(*xmlList, *yamlList,
true),
true);
89 TEST_EQUALITY(Teuchos::haveSameValues(*xmlList, *yamlList),
false);
99 "My Awesome Problem:\n"
100 " Particle Periodic:\n"
101 " X: \"-1.0, 1.0\"\n"
102 " emotions: happy_sad, indifferent\n"
110 "My Awesome Problem:\n"
114 " Elements: [ 10, 10 ]\n"
121 int correctInts[5] = {2, 3, 5, 7, 11};
123 double correctDoubles[5] = {2.718, 3.14159, 1.618, 1.23456789, 42.1337};
131 for(
int i = 0; i < 5; i++)
139 std::string correctStrings[5] = {
"2",
"3",
"5",
"7",
"imastring"};
140 double correctDoubles[5] = {2, 3, 1.618, 1.23456789, 42.1337};
145 for(
int i = 0; i < 5; i++)
147 if(stringArr[i] != correctStrings[i])
149 throw std::runtime_error(std::string(
"stringArray value is incorrect."));
151 if(doubleArr[i] != correctDoubles[i])
153 throw std::runtime_error(std::string(
"doubleArray value is incorrect."));
159 std::string xmlString =
161 " <ParameterList name=\"Problem\">\n"
162 " <ParameterList name=\"Neumann BCs\">\n"
163 " <ParameterList name=\"Time Dependent NBC on SS cyl_outside for DOF all set P\">\n"
164 " <Parameter name=\"BC Values\" type=\"TwoDArray(double)\" value=\"3x1:{ 0.0, 10.0, 20.0}\"/>\n"
165 " </ParameterList>\n"
166 " </ParameterList>\n"
167 " </ParameterList>\n"
168 " <ParameterList name=\"Discretization\">\n"
169 " <Parameter name=\"Node Set Associations\" type=\"TwoDArray(string)\" value=\"2x2:{1, 2, top, bottom}\"/>\n"
170 " <Parameter name=\"Bool-looking String\" type=\"string\" value=\"TRUE\" docString=\"my docString\"/>\n"
171 " </ParameterList>\n"
172 " </ParameterList>\n";
174 std::stringstream yamlOutStream;
175 yamlOutStream << std::showpoint << std::fixed << std::setprecision(1);
177 std::string yamlString = yamlOutStream.str();
178 std::string expectedYamlString =
184 " Time Dependent NBC on SS cyl_outside for DOF all set P: \n"
185 " BC Values: [[0.0], [10.0], [20.0]]\n"
186 " Discretization: \n"
187 " Node Set Associations: [['1', '2'], [top, bottom]]\n"
188 " Bool-looking String: 'TRUE'\n"
191 std::stringstream yamlInStream(yamlString);
194 std::stringstream yamlOutStream2;
195 yamlOutStream2 << std::showpoint << std::fixed << std::setprecision(1);
197 std::string yamlString2 = yamlOutStream2.str();
206 " File Name: electrostatic.exo\n"
207 " Cell Average Quantities:\n"
208 " eblock-0_0: ES_POTENTIAL, E0\n"
211 " File Name: beam_emit2.h5part\n");
219 " File Name: beam_emit2.h5part\n"
220 "# Stride Time: 5.0e-12\n");
227 " Boundary Conditions:\n"
231 " Field: ES_POTENTIAL\n"
233 " double r_sq = xin*xin+yin*yin;\n"
234 " double factor = 0.5*1.e8*1.60217662e-19/(2*3.14159265358979323846*8.854187817e-12);\n"
235 " ES_POTENTIAL= factor*log(r_sq) +3*xin-3*yin;\n"
236 " # end Boundary Conditions\n");
238 Teuchos::getParameter<std::string>(
239 params->sublist(
"Boundary Conditions",
true)
240 .sublist(
"Bottom",
true)
241 .sublist(
"Dirichlet",
true)
243 "double r_sq = xin*xin+yin*yin;\n"
244 "double factor = 0.5*1.e8*1.60217662e-19/(2*3.14159265358979323846*8.854187817e-12);\n"
245 "ES_POTENTIAL= factor*log(r_sq) +3*xin-3*yin;\n");
257 Teuchos::ParserFail);
263 char const *
const cstr =
270 std::stringstream ss;
271 ss << std::showpoint;
281 " small number: 54\n"
282 " small double: 3.0\n"
283 " scientific: 3.123e02\n"
284 " big number: 72057594037927936\n"
290 TEST_EQUALITY(pl->get<
long long>(
"big number"), 72057594037927936ll);
297 " input_true: true\n"
298 " input_false: false\n"
299 " input_TRUE: TRUE\n"
300 " input_FALSE: FALSE\n"
301 " input_True: True\n"
302 " input_False: False\n"
328 " Fields: {rho: 0.125, px: 0., py: 0., pz: 0., rho_E: 0.25}\n");
329 auto& field_pl = pl->sublist(
"Fields");
344 auto& sublist = pl.
sublist(
"sublist");
357 #ifdef HAVE_TEUCHOSPARAMETERLIST_YAMLCPP
362 " list_of_2d_arrays:\n"
363 " - [[1,2,3], [4,5,6]]\n"
364 " - [[7,8,9], [10,11,12]]\n"
368 " line_continuation: [\n"
372 " # allow unicode comments: ±\n"
376 threeDarr_t& list_of_arrs = pl->
get<threeDarr_t>(
"list_of_2d_arrays");
377 threeDarr_t correct_list_of_arrs = {
378 {{1, 2, 3}, {4, 5, 6}},
379 {{7, 8, 9}, {10, 11, 12}}
381 for (
int i=0; i<list_of_arrs.size(); i++) {
382 for (
int j=0; j<list_of_arrs[i].size(); j++) {
383 for (
int k=0; k<list_of_arrs[i][j].size(); k++) {
384 TEST_EQUALITY(correct_list_of_arrs[i][j][k], list_of_arrs[i][j][k]);
390 twoDarr_t ragged_arr = pl->
get<twoDarr_t>(
"ragged_array");
391 twoDarr_t correct_ragged_arr = {
395 for (
int i=0; i<ragged_arr.size(); i++) {
396 for (
int j=0; j<ragged_arr[i].size(); j++) {
402 arr_t arr = pl->
get<arr_t>(
"line_continuation");
403 arr_t correct_arr = {1, 2, 3, 4, 5, 6};
404 for (
int i=0; i<arr.size(); i++) {
414 Teuchos::YamlKeyError)
420 Teuchos::YamlSequenceError)
423 Teuchos::YamlStructureError)
428 #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.