Skip to content

Commit

Permalink
IOSS: Clean up io_shell compare capability
Browse files Browse the repository at this point in the history
  • Loading branch information
gsjaardema committed Feb 14, 2024
1 parent 975029d commit 6635989
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 60 deletions.
101 changes: 65 additions & 36 deletions packages/seacas/libraries/ioss/src/Ioss_Compare.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -96,9 +96,9 @@ namespace {

bool compare_fields(const Ioss::GroupingEntity *ige_1, const Ioss::GroupingEntity *ige_2,
Ioss::Field::RoleType role, std::ostringstream &buf);
template <typename T>
bool compare_field_data(const std::vector<T *> &in_entities_1,
const std::vector<T *> &in_entities_2, Ioss::DataPool &pool,
template <typename T1, typename T2>
bool compare_field_data(const std::vector<T1 *> &in_entities_1,
const std::vector<T2 *> &in_entities_2, Ioss::DataPool &pool,
Ioss::Field::RoleType role, const Ioss::MeshCopyOptions &options,
std::ostringstream &buf);
bool compare_field_data(const std::vector<Ioss::StructuredBlock *> &in_entities_1,
Expand Down Expand Up @@ -485,7 +485,7 @@ bool Ioss::Compare::compare_database(Ioss::Region &input_region_1, Ioss::Region
}

if (it == in_fss_2.end()) {
// fmt::print(Ioss::WarnOut(), NOTFOUND_2, "SIDESET", name);
fmt::print(Ioss::WarnOut(), NOTFOUND_2, "SIDESET", name);
continue;
}

Expand Down Expand Up @@ -525,7 +525,7 @@ bool Ioss::Compare::compare_database(Ioss::Region &input_region_1, Ioss::Region
}
}
if (iter == in_sbs_2.end()) {
// fmt::print(Ioss::WarnOut(), NOTFOUND_2, "SIDEBLOCK", name);
fmt::print(Ioss::WarnOut(), NOTFOUND_2, "SIDEBLOCK", name);
continue;
}

Expand Down Expand Up @@ -1383,9 +1383,9 @@ namespace {
return result;
}

template <typename T>
bool compare_field_data(const std::vector<T *> &in_entities_1,
const std::vector<T *> &in_entities_2, Ioss::DataPool &pool,
template <typename T1, typename T2>
bool compare_field_data(const std::vector<T1 *> &in_entities_1,
const std::vector<T2 *> &in_entities_2, Ioss::DataPool &pool,
Ioss::Field::RoleType role, const Ioss::MeshCopyOptions &options,
std::ostringstream &buf)
{
Expand All @@ -1404,10 +1404,10 @@ namespace {
}

for (const auto &in_entity_1 : in_entities_1) {
const std::string &name = in_entity_1->name();
const auto &name = in_entity_1->name();

typename std::vector<T *>::const_iterator it;
for (it = in_entities_2.begin(); it != in_entities_2.end(); ++it) {
auto it = in_entities_2.begin();
for (; it != in_entities_2.end(); ++it) {
if (name == (*it)->name()) {
break;
}
Expand Down Expand Up @@ -1505,8 +1505,8 @@ namespace {
return overall_result;
}

template <typename T>
bool compare_field_data(T *data1, T *data2, size_t count, size_t component_count,
template <typename T1, typename T2>
bool compare_field_data(T1 *data1, T2 *data2, size_t count, size_t component_count,
const std::string &field_name, const std::string &entity_name,
std::ostringstream &buf)
{
Expand Down Expand Up @@ -1574,17 +1574,6 @@ namespace {
const std::string &field_name,
const Ioss::MeshCopyOptions &options, std::ostringstream &buf)
{
size_t isize = ige_1->get_field(field_name).get_size();
size_t osize = ige_2->get_field(field_name).get_size();

Ioss::DataPool in_pool_2;

if (isize != osize) {
fmt::print(buf, "\n\tFIELD size mismatch for field '{}', ({} vs. {}) on {}", field_name,
isize, osize, ige_1->name());
return false;
}

if (field_name == "mesh_model_coordinates_x") {
return true;
}
Expand Down Expand Up @@ -1628,37 +1617,77 @@ namespace {
return true;
}

size_t icount = ige_1->get_field(field_name).raw_count();
size_t ocount = ige_2->get_field(field_name).raw_count();

if (icount != ocount) {
fmt::print(buf, "\n\tFIELD count mismatch for field '{}', ({} vs. {}) on {}", field_name,
icount, ocount, ige_1->name());
return false;
}

size_t isize = ige_1->get_field(field_name).get_size();
size_t osize = ige_2->get_field(field_name).get_size();

Ioss::DataPool in_pool_2;
if (options.data_storage_type == 1 || options.data_storage_type == 2) {
if (in_pool.data.size() < isize) {
in_pool.data.resize(isize);
}
if (in_pool_2.data.size() < isize) {
in_pool_2.data.resize(isize);
if (in_pool_2.data.size() < osize) {
in_pool_2.data.resize(osize);
}
}

assert(in_pool.data.size() >= isize);
assert(in_pool_2.data.size() >= isize);
assert(in_pool_2.data.size() >= osize);

switch (options.data_storage_type) {
case 1: {
ige_1->get_field_data(field_name, in_pool.data.data(), isize);
ige_2->get_field_data(field_name, in_pool_2.data.data(), isize);
const Ioss::Field &field = ige_1->get_field(field_name);
ige_2->get_field_data(field_name, in_pool_2.data.data(), osize);
const Ioss::Field &field = ige_1->get_field(field_name);
const Ioss::Field &field2 = ige_2->get_field(field_name);

switch (field.get_type()) {
case Ioss::Field::REAL:
return compare_field_data(
(double *)in_pool.data.data(), (double *)in_pool_2.data.data(), field.raw_count(),
field.get_component_count(Ioss::Field::InOut::OUTPUT), field_name, ige_1->name(), buf);
case Ioss::Field::INTEGER:
return compare_field_data(
(int *)in_pool.data.data(), (int *)in_pool_2.data.data(), field.raw_count(),
field.get_component_count(Ioss::Field::InOut::OUTPUT), field_name, ige_1->name(), buf);
switch (field2.get_type()) {
case Ioss::Field::INTEGER:
return compare_field_data((int *)in_pool.data.data(), (int *)in_pool_2.data.data(),
field.raw_count(),
field.get_component_count(Ioss::Field::InOut::OUTPUT),
field_name, ige_1->name(), buf);
case Ioss::Field::INT64:
return compare_field_data((int *)in_pool.data.data(), (int64_t *)in_pool_2.data.data(),
field.raw_count(),
field.get_component_count(Ioss::Field::InOut::OUTPUT),
field_name, ige_1->name(), buf);
default:
fmt::print(Ioss::WarnOut(), "Field data_storage type {} not recognized for field {}.",
field.type_string(), field_name);
return false;
}
case Ioss::Field::INT64:
return compare_field_data(
(int64_t *)in_pool.data.data(), (int64_t *)in_pool_2.data.data(), field.raw_count(),
field.get_component_count(Ioss::Field::InOut::OUTPUT), field_name, ige_1->name(), buf);
switch (field2.get_type()) {
case Ioss::Field::INTEGER:
return compare_field_data((int64_t *)in_pool.data.data(), (int *)in_pool_2.data.data(),
field.raw_count(),
field.get_component_count(Ioss::Field::InOut::OUTPUT),
field_name, ige_1->name(), buf);
case Ioss::Field::INT64:
return compare_field_data((int64_t *)in_pool.data.data(),
(int64_t *)in_pool_2.data.data(), field.raw_count(),
field.get_component_count(Ioss::Field::InOut::OUTPUT),
field_name, ige_1->name(), buf);
default:
fmt::print(Ioss::WarnOut(), "Field data_storage type {} not recognized for field {}.",
field.type_string(), field_name);
return false;
}
default:
fmt::print(Ioss::WarnOut(), "Field data_storage type {} not recognized for field {}.",
field.type_string(), field_name);
Expand Down
37 changes: 19 additions & 18 deletions packages/seacas/libraries/ioss/src/Ioss_Field.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -270,70 +270,71 @@ bool Ioss::Field::transform(void *data)

bool Ioss::Field::equal_(const Ioss::Field &rhs, bool quiet) const
{
bool is_same = true;
if (!Ioss::Utils::str_equal(this->name_, rhs.name_)) {
if (!quiet) {
fmt::print(Ioss::OUTPUT(), "\n\tFIELD name mismatch ({} v. {})", this->name_, rhs.name_);
fmt::print(Ioss::OUTPUT(), "\tFIELD name mismatch ({} v. {})\n", this->name_, rhs.name_);
}
return false;
is_same = false;
}

if (this->type_ != rhs.type_) {
if (!quiet) {
fmt::print(Ioss::OUTPUT(), "\n\tFIELD type mismatch ({} v. {})", this->type_string(),
fmt::print(Ioss::OUTPUT(), "\tFIELD type mismatch ({} v. {})\n", this->type_string(),
rhs.type_string());
}
return false;
is_same = false;
}

if (this->role_ != rhs.role_) {
if (!quiet) {
fmt::print(Ioss::OUTPUT(), "\n\tFIELD role mismatch ({} v. {})", this->role_string(),
fmt::print(Ioss::OUTPUT(), "\tFIELD role mismatch ({} v. {})\n", this->role_string(),
rhs.role_string());
}
return false;
is_same = false;
}

if (this->rawCount_ != rhs.rawCount_) {
if (!quiet) {
fmt::print(Ioss::OUTPUT(), "\n\tFIELD rawCount mismatch ({} v. {})", this->rawCount_,
fmt::print(Ioss::OUTPUT(), "\tFIELD rawCount mismatch ({} v. {})\n", this->rawCount_,
rhs.rawCount_);
}
return false;
is_same = false;
}

if (this->transCount_ != rhs.transCount_) {
if (!quiet) {
fmt::print(Ioss::OUTPUT(), "\n\tFIELD transCount mismatch ({} v. {})", this->transCount_,
fmt::print(Ioss::OUTPUT(), "\tFIELD transCount mismatch ({} v. {})\n", this->transCount_,
rhs.transCount_);
}
return false;
is_same = false;
}

if (this->get_size() != rhs.get_size()) {
if (!quiet) {
fmt::print(Ioss::OUTPUT(), "\n\tFIELD size mismatch ({} v. {})", this->get_size(),
fmt::print(Ioss::OUTPUT(), "\tFIELD size mismatch ({} v. {})\n", this->get_size(),
rhs.get_size());
}
return false;
is_same = false;
}

if (this->get_suffices_uppercase() != rhs.get_suffices_uppercase()) {
if (!quiet) {
fmt::print(Ioss::OUTPUT(), "\n\tFIELD suffices_uppercase mismatch ({} v. {})",
fmt::print(Ioss::OUTPUT(), "\tFIELD suffices_uppercase mismatch ({} v. {})\n",
this->get_suffices_uppercase(), rhs.get_suffices_uppercase());
}
return false;
is_same = false;
}

if (this->zero_copy_enabled() != rhs.zero_copy_enabled()) {
if (!quiet) {
fmt::print(Ioss::OUTPUT(), "\n\tFIELD zero_copy_enabled mismatch ({} v. {})",
fmt::print(Ioss::OUTPUT(), "\tFIELD zero_copy_enabled mismatch ({} v. {})\n",
this->zero_copy_enabled(), rhs.zero_copy_enabled());
}
return false;
is_same = false;
}

return true;
return is_same;
}

bool Ioss::Field::operator==(const Ioss::Field &rhs) const { return equal_(rhs, true); }
Expand Down
4 changes: 2 additions & 2 deletions packages/seacas/libraries/ioss/src/Ioss_GroupingEntity.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -534,7 +534,7 @@ bool Ioss::GroupingEntity::equal_(const Ioss::GroupingEntity &rhs, bool quiet) c
if (rhs.field_exists(field)) {
const auto &f2 = rhs.fields.get(field);
if (!f1.equal(f2)) {
fmt::print(Ioss::OUTPUT(), "{}: FIELD ({}) mismatch\n", name(), field);
fmt::print(Ioss::OUTPUT(), "{}: FIELD ({}) mismatch\n\n", name(), field);
same = false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/seacas/libraries/ioss/src/main/io_shell.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -455,7 +455,7 @@ namespace {
// by element block, then output is much easier.
dbi1->set_surface_split_type(Ioss::SPLIT_BY_ELEMENT_BLOCK);
}
else {
else if (interFace.surface_split_type != Ioss::SPLIT_INVALID) {
dbi1->set_surface_split_type(Ioss::int_to_surface_split(interFace.surface_split_type));
}
dbi1->set_field_separator(interFace.fieldSuffixSeparator);
Expand Down Expand Up @@ -517,7 +517,7 @@ namespace {
// by element block, then output is much easier.
dbi2->set_surface_split_type(Ioss::SPLIT_BY_ELEMENT_BLOCK);
}
else {
else if (interFace.surface_split_type != Ioss::SPLIT_INVALID) {
dbi2->set_surface_split_type(Ioss::int_to_surface_split(interFace.surface_split_type));
}
dbi2->set_field_separator(interFace.fieldSuffixSeparator);
Expand Down
2 changes: 1 addition & 1 deletion packages/seacas/libraries/ioss/src/main/shell_interface.C
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void IOShell::Interface::enroll_options()

options_.enroll("surface_split_scheme", Ioss::GetLongOption::MandatoryValue,
"Method used to split sidesets into homogeneous blocks\n"
"\t\tOptions are: TOPOLOGY, BLOCK, NO_SPLIT",
"\t\tOptions are: TOPOLOGY(default), BLOCK, NO_SPLIT",
nullptr);

options_.enroll("native_variable_names", Ioss::GetLongOption::NoValue,
Expand Down

0 comments on commit 6635989

Please sign in to comment.