This PR should not be merged; its source code changes have been added to Trilinos PR #12599.
Current status
I am testing these by running MiniEM with the following input files:
maxwell-pthOrder.xml
maxwell-pthOrder-oldyaml.yaml
maxwell-pthOrder-newyaml.yaml
This table represents the testing status. We expect all tests to pass except yaml-cpp Off x new yaml.
yaml-cpp On
yaml-cpp Off
new yaml
:heavy_check_mark:
:x:
old yaml
:heavy_check_mark:
:heavy_check_mark:
xml
:heavy_check_mark:
:heavy_check_mark:
The difference between the old yaml and new yaml is this block:
Wishlist:
List of lists:
- [1, 2, 3]
- [1, 2, 3, 4]
List of lists of lists:
- [[1,2,3], [4,5,6], [7,8,9]]
- [[9,7,8], [6,5,4], [3,2,1]]
Line continuation:
- [1, 2, 3, 4, 5, 6,
7, 8, 9, 10]
# allow unicode characters in comments: ±
General Notes
Many of the additions in Teuchos_YamlParser.cpp came from this commit, which removed yaml-cpp from Trilinos in 2017. I mainly "undid" these changes, with some other additions and the introduction of #ifdef directives.
It is worth noting that many of the reasons that the above commit gave for removing yaml-cpp are still valid.
yaml-cpp is only used to read in yaml (ie any functions that write out yaml are untouched)
This PR adds internal CI to run the tests in the above table. These workflows, build scripts, and dockerfiles would not be included in the final PR to Trilinos.
Regarding Teuchos::Array
The original yaml-cpp parser (referenced above) could only support 1-D or 2-D Teuchos::Arrays. This meant that ragged arrays and higher dimensional arrays could not be parsed.
In the event of the user having a simple 1- or 2-D array in the yaml, the parser will create either a standard Teuchos::Array or a Teuchos::TwoDArray.
For the other cases, I've defined functions (getYaml2DRaggedArray and getYaml3DArray) that return Teuchos::Arrays of Teuchos::Arrays (of Teuchos::Arrays, in the 3D case).
Regarding CMake
This PR adds yaml-cpp as a LIB_OPTIONAL_TPL in the TeuchosCore package.
It also creates the HAVE_TEUCHOSCORE_YAMLCPP macro, which allows for #ifdef statements.
Regarding Changes to Source Code
In order to use a yaml input file, some changes were required in the MiniEM source code.
Specifically, line 107 of MiniEM_ClosureModel_Factory_impl.hpp now reads:
// unsigned int seed = plist.get<unsigned int>("seed");
unsigned int seed = static_cast<unsigned int>(plist.get<int>("seed"));
Originally, seed was read directly in as an unsigned int, with the xml input files specifying its type. Since yaml does not allow for types besides int, double, and string, I had to change the code to accept an int and then cast it as an unsigned int.
This meant I had to change all of the xml input files to pass an int as well.
This PR implements an optional
yaml-cpp
parser.This PR should not be merged; its source code changes have been added to Trilinos PR #12599.
Current status
I am testing these by running MiniEM with the following input files:
maxwell-pthOrder.xml
maxwell-pthOrder-oldyaml.yaml
maxwell-pthOrder-newyaml.yaml
This table represents the testing status. We expect all tests to pass except
yaml-cpp Off
xnew yaml
.The difference between the old yaml and new yaml is this block:
General Notes
Teuchos_YamlParser.cpp
came from this commit, which removed yaml-cpp from Trilinos in 2017. I mainly "undid" these changes, with some other additions and the introduction of#ifdef
directives.Regarding Teuchos::Array
The original yaml-cpp parser (referenced above) could only support 1-D or 2-D Teuchos::Arrays. This meant that ragged arrays and higher dimensional arrays could not be parsed.
In the event of the user having a simple 1- or 2-D array in the yaml, the parser will create either a standard
Teuchos::Array
or aTeuchos::TwoDArray
.For the other cases, I've defined functions (
getYaml2DRaggedArray
andgetYaml3DArray
) that return Teuchos::Arrays of Teuchos::Arrays (of Teuchos::Arrays, in the 3D case).Regarding CMake
LIB_OPTIONAL_TPL
in the TeuchosCore package.HAVE_TEUCHOSCORE_YAMLCPP
macro, which allows for#ifdef
statements.Regarding Changes to Source Code
In order to use a yaml input file, some changes were required in the
MiniEM
source code.Specifically, line 107 of MiniEM_ClosureModel_Factory_impl.hpp now reads:
Originally,
seed
was read directly in as anunsigned int
, with the xml input files specifying its type. Since yaml does not allow for types besidesint
,double
, andstring
, I had to change the code to accept anint
and then cast it as anunsigned int
.This meant I had to change all of the xml input files to pass an
int
as well.The other change to source code is self-explanatory.
BlockPrec/main.cpp
now contains the option to parse yaml inputs: