Skip to content

Commit

Permalink
IOSS: Add select_change_sets option for io_shell compare option
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed Nov 13, 2024
1 parent 53e9c39 commit 92ea44e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 39 deletions.
65 changes: 46 additions & 19 deletions packages/seacas/libraries/ioss/src/Ioss_Compare.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <assert.h>
#include <cmath>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
#include <iosfwd>
#include <stdint.h>
#include <stdlib.h>
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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 &region)
{
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 &region)
{
bool success = true;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/seacas/libraries/ioss/src/Ioss_MeshCopyOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Ioss {
{
std::vector<double> selected_times{};
std::vector<std::string> 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};
Expand Down
20 changes: 1 addition & 19 deletions packages/seacas/libraries/ioss/src/main/io_shell.C
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions packages/seacas/libraries/ioss/src/main/shell_interface.C
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions packages/seacas/libraries/ioss/src/main/shell_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down

0 comments on commit 92ea44e

Please sign in to comment.