Skip to content

Commit

Permalink
Merge pull request #18640 from brandonlangley/son_definition_update_1…
Browse files Browse the repository at this point in the history
…8639

Update SONDefinitionFormatter for NEAMS input validation
  • Loading branch information
dschwen committed Aug 31, 2021
2 parents 00eb843 + be34683 commit 10ee36d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 17 deletions.
35 changes: 22 additions & 13 deletions framework/src/outputs/formatters/SONDefinitionFormatter.C
Expand Up @@ -114,14 +114,15 @@ SONDefinitionFormatter::addBlock(const std::string & block_name,
// add MaxOccurs : NoLimit because more than one block of the same name is allowed
addLine("MaxOccurs=NoLimit");

// ensure block has one string declarator node and if this is not a StarBlock then
// also ensure that the block [./declarator] is the expected block_decl from above
// ensure every block has no more than one string declarator node and if this is a
// TypeBlock but not a StarBlock then also ensure that the block [./declarator] is
// the expected block_decl from above which should be the name of the parent block
addLine("decl{");
_level++;
addLine("MinOccurs=0");
addLine("MaxOccurs=1");
addLine("ValType=String");
if (!is_starblock)
if (is_typeblock && !is_starblock)
addLine("ValEnums=[ \"" + block_decl + "\" ]");
_level--;
addLine("}");
Expand Down Expand Up @@ -182,18 +183,18 @@ SONDefinitionFormatter::addBlock(const std::string & block_name,

// add parameters ---
// if this block has a "type=" parameter with a specified default "type=" name and
// if that default is also the name of a ["types"] child block then the parameters
// belonging to that default ["types"] child block are added to this block as well
// first : start with default ["types"] child block's RegularParameters as a base
// second : add or overwrite with default ["types"] child block's ActionParameters
// if that default is also the name of a saved TypeBlock child then the parameters
// belonging to that default saved TypeBlock child are added to this block as well
// first : start with default saved TypeBlock child's RegularParameters as a base
// second : add or overwrite with default saved TypeBlock child's ActionParameters
// third : add or overwrite with parameters that were stored above for this block
// fourth : either add newly stored parameters or add previously stored parameters
if (parameters.contains("type") && parameters["type"].contains("default") &&
block.contains("types") &&
block["types"].contains(nlohmann::to_string(parameters["type"]["default"])))
parameters["type"]["default"].is_string() &&
typeblocks.contains(parameters["type"]["default"].get<std::string>()))
{
std::string type_default = nlohmann::to_string(parameters["type"]["default"]);
const nlohmann::json & default_block = block["types"][type_default];
std::string type_default = parameters["type"]["default"].get<std::string>();
const nlohmann::json & default_block = typeblocks[type_default];
if (default_block.contains("parameters"))
{
nlohmann::json default_child_params = default_block["parameters"];
Expand All @@ -207,6 +208,14 @@ SONDefinitionFormatter::addBlock(const std::string & block_name,
default_child_params[param_el.key()] = param_el.value();
}
}

// unrequire the 'file' parameter added to the Mesh via the FileMesh TypeBlock
// since MeshGenerators internally change the default block type from FileMesh
if (block_name == "Mesh" && default_child_params.contains("file") &&
default_child_params["file"].contains("required") &&
default_child_params["file"]["required"].is_boolean())
default_child_params["file"]["required"] = false;

for (const auto & el : parameters.items())
default_child_params[el.key()] = el.value();
addParameters(default_child_params);
Expand Down Expand Up @@ -310,7 +319,7 @@ SONDefinitionFormatter::addParameters(const nlohmann::json & params)
bool required = param["required"];
if (required && def.empty())
addLine("ChildAtLeastOne=[ \"" + backtrack(_level) + "GlobalParams/" + name +
"/value\" \"" + name + "\" ]");
"/value\" \"" + name + "\" ]");
}

// *** open parameter
Expand Down Expand Up @@ -361,7 +370,7 @@ SONDefinitionFormatter::addParameters(const nlohmann::json & params)

// *** ValEnums / InputChoices of parameter's value
if (basic_type.find("Boolean") != std::string::npos)
addLine("ValEnums=[ true false 1 0 ]");
addLine("ValEnums=[ true false 1 0 on off ]");
else
{
std::string options = param["options"];
Expand Down
64 changes: 60 additions & 4 deletions test/tests/outputs/format/tests
Expand Up @@ -219,7 +219,7 @@
[./definition_input_choices_test]
type = 'RunApp'
input = 'IGNORED'
expect_out = 'InputChoices=\[\s*?"all"\s*?"none"\s*?PATH:"../../../../../Outputs/["*"]/decl"\s*?\]'
expect_out = '\'outputs\'{.*?\'value\'{.*?InputChoices=\[ "all" "none" PATH:"../../../../Outputs/["*"]/decl" \].*?}.*?} % end parameter outputs\n'
cli_args = '--definition'
# suppress error checking, the word 'ERROR' shows up in the definition dump
errors = 'zzzzzzzzzz'
Expand All @@ -233,7 +233,7 @@
[./definition_childatleastone_test]
type = 'RunApp'
input = 'IGNORED'
expect_out = 'ChildAtLeastOne=\[\s*?"../../../GlobalParams/inside/value"\s*?"inside"\s*?\]'
expect_out = '\'BoundaryMarker_type\'{.*?ChildAtLeastOne=\[ "../../../GlobalParams/next_to/value" "next_to" \].*?} % end block BoundaryMarker_type\n'
cli_args = '--definition'
# suppress error checking, the word 'ERROR' shows up in the definition dump
errors = 'zzzzzzzzzz'
Expand Down Expand Up @@ -331,7 +331,7 @@
[./definition_block_type_maxoccurs_nolimit_test]
type = 'RunApp'
input = 'IGNORED'
expect_out = '\'AuxVariables\'{.*?InputTmpl=MooseBlock.*?InputName="AuxVariables".*?InputType=normal_top.*?InputDefault="AuxVariables".*?MinOccurs=0.*?MaxOccurs=NoLimit.*?decl{.*?ValEnums=\[ "AuxVariables" \]'
expect_out = '\'AuxVariables\'{.*?InputTmpl=MooseBlock.*?InputName="AuxVariables".*?InputType=normal_top.*?InputDefault="AuxVariables".*?MinOccurs=0.*?MaxOccurs=NoLimit.*?decl{.*?\'active\'{'
cli_args = '--definition'
# suppress error checking, the word 'ERROR' shows up in the definition dump
errors = 'zzzzzzzzzz'
Expand Down Expand Up @@ -373,7 +373,7 @@
[./definition_declarator_minoccurs_zero_test]
type = 'RunApp'
input = 'IGNORED'
expect_out = '\'Variables\'{.*?InputDefault="Variables".*?decl{.*?MinOccurs=0.*?ValEnums=\[ "Variables" \].*?}.*?\'active\'{.*?} % end parameter active.*?} % end block Variables'
expect_out = '\'Variables\'{.*?InputDefault="Variables".*?decl{.*?MinOccurs=0.*?}.*?\'active\'{.*?} % end parameter active.*?} % end block Variables\n'
cli_args = '--definition'
# suppress error checking, the word 'ERROR' shows up in the definition dump
errors = 'zzzzzzzzzz'
Expand All @@ -398,6 +398,62 @@
valgrind = 'NONE' # Tested in "definition_input_choices_test"
[../]

[./definition_default_types_child_parameter_promotion_test]
type = 'RunApp'
input = 'IGNORED'
expect_out = '\'Mesh\'{.*?InputName="Mesh".*?\'ghosting_patch_size\'{.*?InputName="ghosting_patch_size".*?} % end parameter ghosting_patch_size.*?} % end block Mesh\n'
cli_args = '--definition'
# suppress error checking, the word 'ERROR' shows up in the definition dump
errors = 'zzzzzzzzzz'
max_buffer_size = -1
issues = '#18639'
requirement = 'MOOSE shall be able to convert a JsonSyntaxTree into Standard Object Notation (SON) for use by the NEAMS workbench. Check default types child parameter promotion'
design = 'SONDefinitionFormatter.md'
valgrind = 'NONE' # Tested in "definition_input_choices_test"
[../]

[./definition_default_subblock_types_child_parameter_promotion_test]
type = 'RunApp'
input = 'IGNORED'
expect_out = '\'AuxVariables\'{.*?InputName="AuxVariables".*?\'["*"]\'{.*?InputName="["*"]".*?\'block\'{.*?InputName="block".*?} % end parameter block.*?} % end block ["*"].*?} % end block AuxVariables\n'
cli_args = '--definition'
# suppress error checking, the word 'ERROR' shows up in the definition dump
errors = 'zzzzzzzzzz'
max_buffer_size = -1
issues = '#18639'
requirement = 'MOOSE shall be able to convert a JsonSyntaxTree into Standard Object Notation (SON) for use by the NEAMS workbench. Check default subblock_types child parameter promotion'
design = 'SONDefinitionFormatter.md'
valgrind = 'NONE' # Tested in "definition_input_choices_test"
[../]

[./definition_mesh_file_parameter_requirement_removal_test]
type = 'RunApp'
input = 'IGNORED'
absent_out = '\'Mesh\'{.*?ChildAtLeastOne=\[ "../GlobalParams/file/value" "file" \].*?} % end block Mesh\n'
cli_args = '--definition'
# suppress error checking, the word 'ERROR' shows up in the definition dump
errors = 'zzzzzzzzzz'
max_buffer_size = -1
issues = '#18639'
requirement = 'MOOSE shall be able to convert a JsonSyntaxTree into Standard Object Notation (SON) for use by the NEAMS workbench. Check Mesh file parameter requirement removal'
design = 'SONDefinitionFormatter.md'
valgrind = 'NONE' # Tested in "definition_input_choices_test"
[../]

[./definition_boolean_type_valenum_choices_test]
type = 'RunApp'
input = 'IGNORED'
expect_out = '\'enable\'{.*?\'value\'{.*?ValEnums=\[ true false 1 0 on off \].*?}.*?} % end parameter enable\n'
cli_args = '--definition'
# suppress error checking, the word 'ERROR' shows up in the definition dump
errors = 'zzzzzzzzzz'
max_buffer_size = -1
issues = '#18639'
requirement = 'MOOSE shall be able to convert a JsonSyntaxTree into Standard Object Notation (SON) for use by the NEAMS workbench. Check Boolean type ValEnums choices'
design = 'SONDefinitionFormatter.md'
valgrind = 'NONE' # Tested in "definition_input_choices_test"
[../]

[./definition_scraping_markers]
type = 'RunApp'
input = 'IGNORED'
Expand Down

0 comments on commit 10ee36d

Please sign in to comment.