forked from trilinos/Trilinos
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
ADD_SUBDIRECTORIES( | ||
unit | ||
partition | ||
parser | ||
order | ||
TpetraCrsColorer | ||
color | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
TRIBITS_ADD_EXECUTABLE_AND_TEST( | ||
test_parser | ||
SOURCES test_parser.cpp | ||
COMM serial mpi | ||
) | ||
|
||
TRIBITS_COPY_FILES_TO_BINARY_DIR(ParserTestFiles | ||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} | ||
SOURCE_FILES config.yaml | ||
EXEDEPS test_parser | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Snippet from Trilinos/packages/panzer/mini-em/example/BlockPrec/maxwell2D.xml (below) | ||
# Converted from xml to yaml using ChatGPT | ||
|
||
Physics Blocks: | ||
Maxwell Physics: | ||
Maxwell Physics: | ||
Type: Maxwell | ||
Basis Order: 1 | ||
Integration Order: 2 | ||
Model ID: electromagnetics | ||
Permittivity: epsilon | ||
Conductivity: sigma | ||
Permeability: mu | ||
Current: J | ||
Auxiliary Physics Block: | ||
Auxiliary Gradient Physics: | ||
Type: Auxiliary Weak Gradient | ||
Vector Name: AUXILIARY_EDGE | ||
Scalar Name: AUXILIARY_NODE | ||
Basis Order: 1 | ||
Integration Order: 2 | ||
|
||
Wishlist: | ||
Indentation: | ||
- a | ||
- b | ||
Wrong indentation: | ||
- c | ||
- d | ||
- e | ||
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: ± | ||
|
||
# <ParameterList name="Physics Blocks"> | ||
# <ParameterList name="Maxwell Physics"> | ||
# <ParameterList name="Maxwell Physics"> | ||
# <Parameter name="Type" type="string" value="Maxwell"/> | ||
# <Parameter name="Basis Order" type="int" value="1"/> | ||
# <Parameter name="Integration Order" type="int" value="2"/> | ||
# <Parameter name="Model ID" type="string" value="electromagnetics"/> | ||
# <Parameter name="Permittivity" type="string" value="epsilon"/> | ||
# <Parameter name="Conductivity" type="string" value="sigma"/> | ||
# <Parameter name="Permeability" type="string" value="mu"/> | ||
# <Parameter name="Current" type="string" value="J"/> | ||
# </ParameterList> | ||
# </ParameterList> | ||
# <!-- Auxiliary operators for the solve --> | ||
# <!-- Gets dt, 1/dt, mu and 1/mu from closure model 'electromagnetics_aux' --> | ||
# <ParameterList name="Auxiliary Physics Block"> | ||
# <!-- Weak gradient used by augmentation preconditioner --> | ||
# <ParameterList name="Auxiliary Gradient Physics"> | ||
# <Parameter name="Type" type="string" value="Auxiliary Weak Gradient"/> | ||
# <Parameter name="Vector Name" type="string" value="AUXILIARY_EDGE"/> | ||
# <Parameter name="Scalar Name" type="string" value="AUXILIARY_NODE"/> | ||
# <Parameter name="Basis Order" type="int" value="1"/> | ||
# <Parameter name="Integration Order" type="int" value="2"/> | ||
# </ParameterList> | ||
# </ParameterList> | ||
# </ParameterList> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
#include <filesystem> | ||
#include "yaml-cpp/yaml.h" | ||
|
||
|
||
void parse_mini_em_sample(std::string filename) { | ||
|
||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// ------------------------------------------------- Trilinos/packages/panzer/mini-em/example/BlockPrec/main.cpp (line 195) --------------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
|
||
// Using yaml-cpp // Using Teuchos::ParameterList | ||
|
||
YAML::Node input_params = YAML::LoadFile(filename); // Teuchos::RCP<Teuchos::ParameterList> input_params = Teuchos::rcp(new Teuchos::ParameterList("User_App Parameters")); | ||
YAML::Node physicsBlock_pl = input_params["Physics Blocks"]; // Teuchos::ParameterList &physicsBlock_pl = input_params->sublist("Physics Blocks"); | ||
|
||
YAML::Node physicsEqSet = physicsBlock_pl["Maxwell Physics"]["Maxwell Physics"]; // Teuchos::ParameterList& physicsEqSet = physicsBlock_pl.sublist("Maxwell Physics").sublist("Maxwell Physics"); | ||
|
||
const std::string physicsTypeStr = physicsEqSet["Type"].as<std::string>(); // const std::string physicsTypeStr = physicsEqSet.get<std::string>("Type"); | ||
|
||
std::string physics; // physicsType physics; (for demonstration purposes, we replace physicsType with std::string); | ||
|
||
if (physicsTypeStr == "Maxwell") { // if (physicsTypeStr == "Maxwell") | ||
physics = "MAXWELL"; // physics = MAXWELL; | ||
} else if (physicsTypeStr == "Darcy") { // else if (physicsTypeStr == "Darcy") | ||
physics = "DARCY"; // physics = DARCY; | ||
} else { // else | ||
std::cout << "Error: invalid physicsTypeStr" << std::endl; // TEUCHOS_ASSERT(false); | ||
} | ||
|
||
int basis_order = physicsEqSet["Basis Order"].as<int>(); // basis_order = physicsEqSet.get("Basis Order", basis_order); | ||
|
||
physicsEqSet["Integration Order"] = 2 * basis_order; // physicsEqSet.set("Integration Order", 2*basis_order); | ||
|
||
std::cout << "Physics Type: " << physics << std::endl; | ||
std::cout << "Basis Order: " << basis_order << std::endl; | ||
std::cout << "Integration Order: " << physicsEqSet["Integration Order"].as<int>() << std::endl; | ||
} | ||
|
||
void parse_wishlist(std::string filename) { | ||
YAML::Node input_file = YAML::LoadFile(filename); | ||
YAML::Node wishlist = input_file["Wishlist"]; | ||
|
||
// Check Indentation | ||
const std::vector<std::string> indentation = wishlist["Indentation"].as<std::vector<std::string>>(); | ||
std::cout << "\nCheck correct indentation:" << std::endl; | ||
for (const auto& element : indentation) { | ||
std::cout << element << " "; | ||
} std::cout << std::endl; | ||
|
||
// Check Wrong indentation | ||
const std::vector<std::string> wrong_indentation = wishlist["Wrong indentation"].as<std::vector<std::string>>(); | ||
std::cout << "\nCheck incorrect indetation:" << std::endl; | ||
for (const auto& element : wrong_indentation) { | ||
std::cout << element << " "; | ||
} std::cout << std::endl; | ||
|
||
// List of lists | ||
const std::vector<std::vector<int>> list_of_lists = wishlist["List of lists"].as<std::vector<std::vector<int>>>(); | ||
std::cout << "\nCheck list of lists:" << std::endl; | ||
for (const auto& list : list_of_lists) { | ||
for (const auto& elt : list) { | ||
std::cout << elt << " "; | ||
} std::cout << std::endl; | ||
} | ||
|
||
// List of lists of lists | ||
const std::vector<std::vector<std::vector<int>>> list_of_lists_of_lists = wishlist["List of lists of lists"].as<std::vector<std::vector<std::vector<int>>>>(); | ||
std::cout << "\nCheck list of lists:" << std::endl; | ||
for (const auto& lists : list_of_lists_of_lists) { | ||
for (const auto& list : lists) { | ||
std::cout << "[ "; | ||
for (const auto& elt : list) { | ||
std::cout << elt << " "; | ||
} std::cout << "]"; | ||
} std::cout << std::endl; | ||
} | ||
|
||
// Line continuation | ||
const std::vector<std::vector<int>> line_continuation = wishlist["Line continuation"].as<std::vector<std::vector<int>>>(); | ||
std::cout << "\nCheck line continuation:" << std::endl; | ||
for (const auto& list : line_continuation) { | ||
for (const auto& elt : list) { | ||
std::cout << elt << " "; | ||
} std::cout << std::endl; | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
|
||
std::string executable_path = std::filesystem::path(argv[0]).parent_path().string(); | ||
std::string filename = executable_path + "/config.yaml"; | ||
|
||
// std::string filename = "config.yaml" // doesn't work | ||
std::cout << "Parsing " << filename << "\n" << std::endl; | ||
|
||
parse_mini_em_sample(filename); | ||
parse_wishlist(filename); | ||
|
||
return 0; | ||
} |