Skip to content

Commit

Permalink
IOSS: io_shell - compare selected change_sets; clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Greg Sjaardema <gdsjaar@sandia.gov>
  • Loading branch information
gdsjaar committed Nov 13, 2024
1 parent 680bdb6 commit a7b0e47
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 59 deletions.
39 changes: 22 additions & 17 deletions packages/seacas/libraries/ioss/src/Ioss_Compare.C
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ namespace {
const std::string &field_name,
const Ioss::MeshCopyOptions &options, std::ostringstream &buf);

bool open_change_set(const std::string &cs_name, const Ioss::Region &region)
bool open_change_set(const std::string &cs_name, Ioss::Region &region)
{
bool success = true;
if (!cs_name.empty()) {
success = region.get_database()->open_internal_change_set(cs_name);
success = region.load_internal_change_set_mesh(cs_name);
if (!success) {
fmt::print(stderr, "ERROR: Unable to open change_set '{}' in file '{}'\n", cs_name,
region.get_database()->get_filename());
Expand All @@ -143,7 +143,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()) {
std::ostringstream buf;
fmt::print(buf, "CHANGE SET mismatch.");
if (!compare_change_sets(input_region_1, input_region_2, buf)) {
Expand All @@ -163,24 +163,29 @@ bool Ioss::Compare::compare_database(Ioss::Region &input_region_1, Ioss::Region
}
}

auto cs1_names = input_region_1.get_database()->internal_change_set_describe();
auto cs2_names = input_region_2.get_database()->internal_change_set_describe();
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;
}
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;
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);
}
overall_result &= compare_database_internal(input_region_1, input_region_2, options);
return overall_result;
}
else {
return compare_database_internal(input_region_1, input_region_2, options);
}
return overall_result;
}

namespace {
Expand Down
1 change: 1 addition & 0 deletions packages/seacas/libraries/ioss/src/Ioss_MeshCopyOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Ioss {
{
std::vector<double> selected_times{};
std::vector<std::string> omitted_sets{};
std::string selected_change_set{};
double minimum_time{0.0};
double maximum_time{0.0};
double delay{0.0};
Expand Down
103 changes: 65 additions & 38 deletions packages/seacas/libraries/ioss/src/main/io_shell.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <exception>
#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/ranges.h>
#include <limits>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -46,34 +47,35 @@ namespace {

bool mem_stats = false;

void file_copy(IOShell::Interface &interFace, int rank);
bool file_copy(IOShell::Interface &interFace, int rank);
bool file_compare(IOShell::Interface &interFace, int rank);

Ioss::PropertyManager set_properties(IOShell::Interface &interFace);
Ioss::MeshCopyOptions set_mesh_copy_options(IOShell::Interface &interFace)
{
Ioss::MeshCopyOptions options{};
options.selected_times = interFace.selected_times;
options.rel_tolerance = interFace.rel_tolerance;
options.abs_tolerance = interFace.abs_tolerance;
options.tol_floor = interFace.tol_floor;
options.verbose = !interFace.quiet;
options.output_summary = true;
options.memory_statistics = interFace.memory_statistics;
options.debug = interFace.debug;
options.ints_64_bit = interFace.ints_64_bit;
options.delete_timesteps = interFace.delete_timesteps;
options.minimum_time = interFace.minimum_time;
options.maximum_time = interFace.maximum_time;
options.time_scale = interFace.time_scale;
options.time_offset = interFace.time_offset;
options.data_storage_type = interFace.data_storage_type;
options.delay = interFace.timestep_delay;
options.reverse = interFace.reverse;
options.add_proc_id = interFace.add_processor_id_field;
options.boundary_sideset = interFace.boundary_sideset;
options.ignore_qa_info = interFace.ignore_qa_info;
options.omitted_blocks = !interFace.omitted_blocks.empty();
options.selected_times = interFace.selected_times;
options.rel_tolerance = interFace.rel_tolerance;
options.abs_tolerance = interFace.abs_tolerance;
options.tol_floor = interFace.tol_floor;
options.verbose = !interFace.quiet;
options.output_summary = true;
options.memory_statistics = interFace.memory_statistics;
options.debug = interFace.debug;
options.ints_64_bit = interFace.ints_64_bit;
options.delete_timesteps = interFace.delete_timesteps;
options.minimum_time = interFace.minimum_time;
options.maximum_time = interFace.maximum_time;
options.time_scale = interFace.time_scale;
options.time_offset = interFace.time_offset;
options.data_storage_type = interFace.data_storage_type;
options.delay = interFace.timestep_delay;
options.reverse = interFace.reverse;
options.add_proc_id = interFace.add_processor_id_field;
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.omitted_sets = interFace.omitted_sets;
Ioss::sort(options.omitted_sets);
Expand All @@ -83,6 +85,22 @@ namespace {
return options;
}

bool check_valid_change_set_name(const std::string &cs_name, const Ioss::Region &region, int rank)
{
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()) {
if (rank == 0) {
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, int rank)
{
bool success = true;
Expand Down Expand Up @@ -181,7 +199,7 @@ int main(int argc, char *argv[])
success = file_compare(interFace, rank);
}
else {
file_copy(interFace, rank);
success = file_copy(interFace, rank);
}
}
catch (std::exception &e) {
Expand Down Expand Up @@ -228,14 +246,15 @@ int main(int argc, char *argv[])
#endif
}
if (rank == 0) {
fmt::print(stderr, "\n{} execution successful.\n", codename);
fmt::print(stderr, "\n{} execution {}.\n", codename, success ? "successful" : "failed");
}
return success ? EXIT_SUCCESS : EXIT_FAILURE;
}

namespace {
void file_copy(IOShell::Interface &interFace, int rank)
bool file_copy(IOShell::Interface &interFace, int rank)
{
bool success = true;
Ioss::PropertyManager properties = set_properties(interFace);

for (const auto &inpfile : interFace.inputFile) {
Expand Down Expand Up @@ -283,9 +302,12 @@ namespace {

// Change_set specified... We will read the specified changeSet from the input file
if (!interFace.changeSetName.empty()) {
bool success = open_change_set(interFace.changeSetName, region, rank);
success = check_valid_change_set_name(interFace.changeSetName, region, rank);
if (success) {
success = open_change_set(interFace.changeSetName, region, rank);
}
if (!success) {
return;
return success;
}
}

Expand All @@ -296,7 +318,7 @@ namespace {
"'Structured' mesh is supported at this time.\n",
region.mesh_type_string());
}
return;
return success;
}

// Get length of longest name on input file...
Expand Down Expand Up @@ -378,26 +400,26 @@ namespace {
// The name of the change_set will be the basename portion of the filename...
Ioss::FileInfo file(inpfile);

bool success = dbo->create_internal_change_set(file.tailname());
success = dbo->create_internal_change_set(file.tailname());
if (!success) {
if (rank == 0) {
fmt::print(stderr, "ERROR: Unable to create change set {} in output file.\n",
file.tailname());
}
return;
return success;
}
}

if (change_set_count > 1 && interFace.changeSetName.empty()) {
bool first = true;
auto cs_names = dbi->internal_change_set_describe();
for (const auto &cs_name : cs_names) {
bool success = region.load_internal_change_set_mesh(cs_name);
success = region.load_internal_change_set_mesh(cs_name);
if (!success) {
if (rank == 0) {
fmt::print(stderr, "ERROR: Unable to open change set {} in input file.\n", cs_name);
}
return;
return success;
}
// NEED TO FIX set_id as blocks are incrementing ids each group
// NEED TO FIX reset_region() is private -- exposed here for proof of concept.
Expand All @@ -409,7 +431,7 @@ namespace {
fmt::print(stderr, "ERROR: Unable to create change set {} in output file.\n",
cs_name);
}
return;
return success;
}
fmt::print(stderr, "Copying change set {}\n", cs_name);
if (!first) {
Expand Down Expand Up @@ -508,6 +530,7 @@ namespace {
dbi->progress("Memory Released... ");
}
} // loop over input files
return true;
}

bool file_compare(IOShell::Interface &interFace, int rank)
Expand Down Expand Up @@ -610,15 +633,19 @@ namespace {
return false;
}

{
bool success = open_change_set(interFace.changeSetName, input_region1, rank);
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;
}
}

{
bool success = open_change_set(interFace.changeSetName, input_region2, rank);
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;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/seacas/libraries/ioss/src/main/io_shell_ts.C
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@

#include "shell_interface.h"

#ifdef SEACAS_HAVE_KOKKOS
#include <Kokkos_Core.hpp> // for Kokkos::View
#endif

#define DO_OUTPUT \
if (rank == 0) \
std::cerr
Expand Down

0 comments on commit a7b0e47

Please sign in to comment.