From 92ea44e529f0f9e5849d365588e209df1f72cdfb Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Wed, 13 Nov 2024 13:28:48 -0700 Subject: [PATCH] IOSS: Add select_change_sets option for io_shell compare option --- .../seacas/libraries/ioss/src/Ioss_Compare.C | 65 +++++++++++++------ .../libraries/ioss/src/Ioss_MeshCopyOptions.h | 2 +- .../seacas/libraries/ioss/src/main/io_shell.C | 20 +----- .../libraries/ioss/src/main/shell_interface.C | 4 ++ .../libraries/ioss/src/main/shell_interface.h | 1 + 5 files changed, 53 insertions(+), 39 deletions(-) diff --git a/packages/seacas/libraries/ioss/src/Ioss_Compare.C b/packages/seacas/libraries/ioss/src/Ioss_Compare.C index b067f95936..aacb204026 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_Compare.C +++ b/packages/seacas/libraries/ioss/src/Ioss_Compare.C @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ #include "Ioss_SideSet.h" #include "Ioss_StructuredBlock.h" #include "Ioss_Utils.h" +#include "tokenize.h" /* These messages indicate a structural difference between the files * being compared. Use Ioss::WarnOut(). @@ -116,6 +118,20 @@ namespace { const std::string &field_name, const Ioss::MeshCopyOptions &options, std::ostringstream &buf); + bool check_valid_change_set_name(const std::string &cs_name, const Ioss::Region ®ion) + { + auto cs_names = region.get_database()->internal_change_set_describe(); + auto it = std::find(cs_names.cbegin(), cs_names.cend(), cs_name); + if (it == cs_names.cend()) { + fmt::print(stderr, + "ERROR: Change set {}, not found in database {}. Valid change sets are:\n" + " {}\n", + cs_name, region.get_database()->get_filename(), fmt::join(cs_names, ", ")); + return false; + } + return true; + } + bool open_change_set(const std::string &cs_name, Ioss::Region ®ion) { bool success = true; @@ -143,7 +159,7 @@ bool Ioss::Compare::compare_database(Ioss::Region &input_region_1, Ioss::Region tol_floor = options.tol_floor; // COMPARE change_sets in the databases... - if (!options.selected_change_set.empty()) { + if (options.selected_change_sets.empty()) { std::ostringstream buf; fmt::print(buf, "CHANGE SET mismatch."); if (!compare_change_sets(input_region_1, input_region_2, buf)) { @@ -163,29 +179,40 @@ bool Ioss::Compare::compare_database(Ioss::Region &input_region_1, Ioss::Region } } - if (options.selected_change_set.empty()) { - auto cs1_names = input_region_1.get_database()->internal_change_set_describe(); - auto cs2_names = input_region_2.get_database()->internal_change_set_describe(); - - for (const auto &cs1_name : cs1_names) { - auto it = std::find(cs2_names.cbegin(), cs2_names.cend(), cs1_name); - if (it == cs2_names.cend()) { - fmt::print(Ioss::WarnOut(), "Skipping change set {}, not found in input #2.\n", cs1_name); - continue; - } + Ioss::NameList cs1_names; + Ioss::NameList cs2_names; - bool success1 = open_change_set(cs1_name, input_region_1); - bool success2 = open_change_set(cs1_name, input_region_2); - if (!success1 || !success2) { - continue; - } - overall_result &= compare_database_internal(input_region_1, input_region_2, options); + if (!options.selected_change_sets.empty() && options.selected_change_sets != "ALL") { + cs1_names = Ioss::tokenize(options.selected_change_sets, ","); + bool success = true; + for (const auto &cs_name : cs1_names) { + success &= check_valid_change_set_name(cs_name, input_region_1); } - return overall_result; + if (!success) { + return false; + } + cs2_names = cs1_names; } else { - return compare_database_internal(input_region_1, input_region_2, options); + cs1_names = input_region_1.get_database()->internal_change_set_describe(); + cs2_names = input_region_2.get_database()->internal_change_set_describe(); + } + + for (const auto &cs1_name : cs1_names) { + auto it = std::find(cs2_names.cbegin(), cs2_names.cend(), cs1_name); + if (it == cs2_names.cend()) { + fmt::print(Ioss::WarnOut(), "Skipping change set {}, not found in input #2.\n", cs1_name); + continue; + } + + bool success1 = open_change_set(cs1_name, input_region_1); + bool success2 = open_change_set(cs1_name, input_region_2); + if (!success1 || !success2) { + continue; + } + overall_result &= compare_database_internal(input_region_1, input_region_2, options); } + return overall_result; } namespace { diff --git a/packages/seacas/libraries/ioss/src/Ioss_MeshCopyOptions.h b/packages/seacas/libraries/ioss/src/Ioss_MeshCopyOptions.h index 7862dcb222..25681acc32 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_MeshCopyOptions.h +++ b/packages/seacas/libraries/ioss/src/Ioss_MeshCopyOptions.h @@ -15,7 +15,7 @@ namespace Ioss { { std::vector selected_times{}; std::vector omitted_sets{}; - std::string selected_change_set{}; + std::string selected_change_sets{}; double minimum_time{0.0}; double maximum_time{0.0}; double delay{0.0}; diff --git a/packages/seacas/libraries/ioss/src/main/io_shell.C b/packages/seacas/libraries/ioss/src/main/io_shell.C index de97741fde..07ce94c0af 100644 --- a/packages/seacas/libraries/ioss/src/main/io_shell.C +++ b/packages/seacas/libraries/ioss/src/main/io_shell.C @@ -75,7 +75,7 @@ namespace { options.boundary_sideset = interFace.boundary_sideset; options.ignore_qa_info = interFace.ignore_qa_info; options.omitted_blocks = !interFace.omitted_blocks.empty(); - options.selected_change_set = interFace.changeSetName; + options.selected_change_sets = interFace.selectedChangeSets; options.omitted_sets = interFace.omitted_sets; Ioss::sort(options.omitted_sets); @@ -633,24 +633,6 @@ namespace { return false; } - if (!interFace.changeSetName.empty()) { - bool success = check_valid_change_set_name(interFace.changeSetName, input_region1, rank); - if (success) { - success = open_change_set(interFace.changeSetName, input_region1, rank); - } - if (!success) { - return false; - } - - success = check_valid_change_set_name(interFace.changeSetName, input_region2, rank); - if (success) { - success = open_change_set(interFace.changeSetName, input_region2, rank); - } - if (!success) { - return false; - } - } - // Get integer size being used on input file #1 and set it in // the interFace. int_byte_size_api = dbi2->int_byte_size_api(); diff --git a/packages/seacas/libraries/ioss/src/main/shell_interface.C b/packages/seacas/libraries/ioss/src/main/shell_interface.C index 666daa9831..ea57f83559 100644 --- a/packages/seacas/libraries/ioss/src/main/shell_interface.C +++ b/packages/seacas/libraries/ioss/src/main/shell_interface.C @@ -241,6 +241,9 @@ void IOShell::Interface::enroll_options() nullptr, nullptr, true); #endif + options_.enroll( + "select_change_sets", Ioss::GetLongOption::MandatoryValue, + "Read the specified change set(s) (comma-separated list) from the input file. Use \"ALL\" for all change sets (default).", nullptr); options_.enroll( "extract_change_set", Ioss::GetLongOption::MandatoryValue, "Write the data from the specified change_set (formerly group) to the output file.", nullptr); @@ -679,6 +682,7 @@ bool IOShell::Interface::parse_options(int argc, char **argv, int my_processor) } } + selectedChangeSets = options_.get_option_value("select_change_sets", selectedChangeSets); changeSetName = options_.get_option_value("extract_group", changeSetName); changeSetName = options_.get_option_value("extract_change_set", changeSetName); diff --git a/packages/seacas/libraries/ioss/src/main/shell_interface.h b/packages/seacas/libraries/ioss/src/main/shell_interface.h index f78b19c094..6b781b0d3c 100644 --- a/packages/seacas/libraries/ioss/src/main/shell_interface.h +++ b/packages/seacas/libraries/ioss/src/main/shell_interface.h @@ -36,6 +36,7 @@ namespace IOShell { std::string inFiletype{"unknown"}; std::string outFiletype{"unknown"}; std::string changeSetName; + std::string selectedChangeSets; std::string decomp_method; std::string decomp_extra{"processor_id"}; std::string compose_output{"default"};