| 1 |
// Copyright(C) 1999-2021, 2023, 2024 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#include <algorithm> |
| 8 |
#include <cstdio> |
| 9 |
#include <cstdlib> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
#include "ED_SystemInterface.h" |
| 13 |
#include "Tolerance.h" |
| 14 |
#include "assembly.h" |
| 15 |
#include "exo_block.h" |
| 16 |
#include "exo_read.h" |
| 17 |
#include "exodusII.h" |
| 18 |
#include "fmt/ostream.h" |
| 19 |
#include "fmt/ranges.h" |
| 20 |
#include "node_set.h" |
| 21 |
#include "side_set.h" |
| 22 |
#include "smart_assert.h" |
| 23 |
#include "stringx.h" |
| 24 |
|
| 25 |
namespace { |
| 26 |
|
| 27 |
template <typename INT> |
| 28 |
bool Check_Nodal(Exo_Read<INT> &file1, Exo_Read<INT> &file2, const std::vector<INT> &node_map, |
| 29 |
const INT *id_map, bool check_only); |
| 30 |
template <typename INT> |
| 31 |
bool Check_Element_Block(Exo_Read<INT> &file1, Exo_Read<INT> &file2, |
| 32 |
const std::vector<INT> &elmt_map, const std::vector<INT> &node_map); |
| 33 |
template <typename INT> |
| 34 |
bool Check_Nodeset(Exo_Read<INT> &file1, Exo_Read<INT> &file2, const std::vector<INT> &node_map, |
| 35 |
bool check_only); |
| 36 |
template <typename INT> |
| 37 |
bool Check_Sideset(Exo_Read<INT> &file1, Exo_Read<INT> &file2, const std::vector<INT> &elmt_map, |
| 38 |
bool check_only); |
| 39 |
|
| 40 |
template <typename INT> |
| 41 |
bool Check_Element_Block_Params(const Exo_Block<INT> *block1, const Exo_Block<INT> *block2); |
| 42 |
template <typename INT> |
| 43 |
bool Check_Element_Block_Connectivity(Exo_Block<INT> *block1, Exo_Block<INT> *block2, |
| 44 |
const std::vector<INT> &elmt_map, |
| 45 |
const std::vector<INT> &node_map); |
| 46 |
template <typename INT> bool Check_Assembly(Exo_Read<INT> &file1, Exo_Read<INT> &file2); |
| 47 |
template <typename INT> |
| 48 |
bool Check_Assembly_Params(const Assembly<INT> *assembly1, const Assembly<INT> *assembly2); |
| 49 |
bool close_compare(const std::string &st1, const std::string &st2); |
| 50 |
} // namespace |
| 51 |
|
| 52 |
template <typename INT> bool Check_Global(Exo_Read<INT> &file1, Exo_Read<INT> &file2) |
| 53 |
{ |
| 54 |
bool is_same = true; |
| 55 |
if (file1.Dimension() != file2.Dimension()) { |
| 56 |
Warning(".. Dimension doesn't agree.\n"); |
| 57 |
is_same = false; |
| 58 |
} |
| 59 |
if (file1.Num_Nodes() != file2.Num_Nodes()) { |
| 60 |
if (interFace.map_flag != MapType::PARTIAL) { |
| 61 |
Warning(".. Number of nodes doesn't agree.\n"); |
| 62 |
is_same = false; |
| 63 |
} |
| 64 |
} |
| 65 |
if (file1.Num_Elements() != file2.Num_Elements()) { |
| 66 |
if (interFace.map_flag != MapType::PARTIAL) { |
| 67 |
Warning(".. Number of elements doesn't agree.\n"); |
| 68 |
is_same = false; |
| 69 |
} |
| 70 |
} |
| 71 |
if (file1.Num_Element_Blocks() != file2.Num_Element_Blocks()) { |
| 72 |
if (interFace.map_flag != MapType::PARTIAL) { |
| 73 |
Warning(".. Number of element blocks doesn't agree.\n"); |
| 74 |
is_same = false; |
| 75 |
} |
| 76 |
} |
| 77 |
if (file1.Num_Times() != file2.Num_Times() && !interFace.quiet_flag && !interFace.ignore_steps) { |
| 78 |
Warning(fmt::format(".. First file has {} result times while the second file has {}.\n", |
| 79 |
file1.Num_Times(), file2.Num_Times())); |
| 80 |
} |
| 81 |
return is_same; |
| 82 |
} |
| 83 |
|
| 84 |
template <typename INT> |
| 85 |
void Check_Compatible_Meshes(Exo_Read<INT> &file1, Exo_Read<INT> &file2, bool check_only, |
| 86 |
const std::vector<INT> &node_map, const std::vector<INT> &elmt_map, |
| 87 |
const INT *node_id_map) |
| 88 |
{ |
| 89 |
bool is_diff = false; |
| 90 |
// NOTE: Check_Global is called earlier. Don't repeat call here. |
| 91 |
if (!Check_Nodal(file1, file2, node_map, node_id_map, check_only)) { |
| 92 |
Warning(".. Differences found in mesh nodal coordinates.\n"); |
| 93 |
is_diff = true; |
| 94 |
} |
| 95 |
|
| 96 |
if (!Check_Element_Block(file1, file2, elmt_map, node_map)) { |
| 97 |
Warning(".. Differences found in element block metadata or connectivity.\n"); |
| 98 |
is_diff = true; |
| 99 |
} |
| 100 |
|
| 101 |
if (!Check_Nodeset(file1, file2, node_map, check_only)) { |
| 102 |
Warning(".. Differences found in node set metadata or node lists.\n"); |
| 103 |
is_diff = true; |
| 104 |
} |
| 105 |
|
| 106 |
if (!Check_Sideset(file1, file2, elmt_map, check_only)) { |
| 107 |
Warning(".. Differences found in side set metadata or side lists.\n"); |
| 108 |
is_diff = true; |
| 109 |
} |
| 110 |
|
| 111 |
if (!Check_Assembly(file1, file2)) { |
| 112 |
Warning(fmt::format(".. Differences found in assembly metadata or assembly entity lists. {}\n", |
| 113 |
interFace.pedantic ? "" : "[ignored]")); |
| 114 |
if (interFace.pedantic) { |
| 115 |
is_diff = true; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
if (is_diff) { |
| 120 |
Warning(".. Differences found in mesh (non-transient) data. Aborting...\n"); |
| 121 |
exit(1); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
namespace { |
| 126 |
template <typename INT> |
| 127 |
bool Check_Nodal(Exo_Read<INT> &file1, Exo_Read<INT> &file2, const std::vector<INT> &node_map, |
| 128 |
const INT *id_map, bool check_only) |
| 129 |
{ |
| 130 |
bool is_same = true; |
| 131 |
|
| 132 |
if (interFace.coord_tol.type == ToleranceMode::IGNORE_ || !check_only) { |
| 133 |
return is_same; |
| 134 |
} |
| 135 |
|
| 136 |
file1.Load_Nodal_Coordinates(); |
| 137 |
file2.Load_Nodal_Coordinates(); |
| 138 |
|
| 139 |
const auto *x1 = file1.X_Coords(); |
| 140 |
const double *y1 = x1; |
| 141 |
const double *z1 = x1; |
| 142 |
if (file1.Dimension() > 1) { |
| 143 |
y1 = file1.Y_Coords(); |
| 144 |
} |
| 145 |
if (file1.Dimension() > 2) { |
| 146 |
z1 = file1.Z_Coords(); |
| 147 |
} |
| 148 |
|
| 149 |
const auto *x2 = file2.X_Coords(); |
| 150 |
const double *y2 = x2; |
| 151 |
const double *z2 = x2; |
| 152 |
if (file2.Dimension() > 1) { |
| 153 |
y2 = file2.Y_Coords(); |
| 154 |
} |
| 155 |
if (file2.Dimension() > 2) { |
| 156 |
z2 = file2.Z_Coords(); |
| 157 |
} |
| 158 |
|
| 159 |
double max = 0.0; |
| 160 |
double norm; |
| 161 |
for (size_t n = 0; n < file1.Num_Nodes() && (is_same || interFace.show_all_diffs); ++n) { |
| 162 |
// Should this node be processed... |
| 163 |
if (node_map.empty() || node_map[n] >= 0) { |
| 164 |
INT n2 = node_map.empty() ? n : node_map[n]; |
| 165 |
double dx = interFace.coord_tol.Delta(x1[n], x2[n2]); |
| 166 |
if (dx > interFace.coord_tol.value) { |
| 167 |
fmt::print(" x coord {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (node {})\n", |
| 168 |
interFace.coord_tol.abrstr(), x1[n], x2[n2], dx, (size_t)id_map[n]); |
| 169 |
is_same = false; |
| 170 |
} |
| 171 |
norm = (x1[n] - x2[n2]) * (x1[n] - x2[n2]); |
| 172 |
|
| 173 |
if (file1.Dimension() > 1 && file2.Dimension() > 1) { |
| 174 |
double dy = interFace.coord_tol.Delta(y1[n], y2[n2]); |
| 175 |
if (dy > interFace.coord_tol.value) { |
| 176 |
fmt::print(" y coord {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (node {})\n", |
| 177 |
interFace.coord_tol.abrstr(), y1[n], y2[n2], dy, (size_t)id_map[n]); |
| 178 |
is_same = false; |
| 179 |
} |
| 180 |
norm += (y1[n] - y2[n2]) * (y1[n] - y2[n2]); |
| 181 |
} |
| 182 |
|
| 183 |
if (file1.Dimension() > 2 && file2.Dimension() > 2) { |
| 184 |
double dz = interFace.coord_tol.Delta(z1[n], z2[n2]); |
| 185 |
if (dz > interFace.coord_tol.value) { |
| 186 |
fmt::print(" z coord {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (node {})\n", |
| 187 |
interFace.coord_tol.abrstr(), z1[n], z2[n2], dz, (size_t)id_map[n]); |
| 188 |
is_same = false; |
| 189 |
} |
| 190 |
norm += (z1[n] - z2[n2]) * (z1[n] - z2[n2]); |
| 191 |
} |
| 192 |
max = max < norm ? norm : max; |
| 193 |
} // End of node iteration... |
| 194 |
} |
| 195 |
|
| 196 |
if (!interFace.quiet_flag && is_same && max > 0.0) { |
| 197 |
max = sqrt(max); |
| 198 |
fmt::print("Maximum difference between nodal coordinates = {}\n", max); |
| 199 |
} |
| 200 |
|
| 201 |
file1.Free_Nodal_Coordinates(); |
| 202 |
file2.Free_Nodal_Coordinates(); |
| 203 |
return is_same; |
| 204 |
} |
| 205 |
|
| 206 |
template <typename INT> |
| 207 |
bool Check_Element_Block(Exo_Read<INT> &file1, Exo_Read<INT> &file2, |
| 208 |
const std::vector<INT> &elmt_map, const std::vector<INT> &node_map) |
| 209 |
{ |
| 210 |
bool is_same = true; |
| 211 |
// Verify that element blocks match in the two files... |
| 212 |
for (size_t b = 0; b < file1.Num_Element_Blocks(); ++b) { |
| 213 |
Exo_Block<INT> *block1 = file1.Get_Element_Block_by_Index(b); |
| 214 |
Exo_Block<INT> *block2 = nullptr; |
| 215 |
if (interFace.map_flag != MapType::DISTANCE && interFace.map_flag != MapType::PARTIAL) { |
| 216 |
if (block1 != nullptr) { |
| 217 |
if (interFace.by_name) { |
| 218 |
block2 = file2.Get_Element_Block_by_Name(block1->Name()); |
| 219 |
} |
| 220 |
else { |
| 221 |
block2 = file2.Get_Element_Block_by_Id(block1->Id()); |
| 222 |
} |
| 223 |
if (block2 == nullptr) { |
| 224 |
Warning(fmt::format(".. Block id {} with name {} exists in first " |
| 225 |
"file but not the second.\n", |
| 226 |
block1->Id(), block1->Name())); |
| 227 |
is_same = false; |
| 228 |
} |
| 229 |
else { |
| 230 |
if (!Check_Element_Block_Params(block1, block2)) { |
| 231 |
is_same = false; |
| 232 |
} |
| 233 |
else { |
| 234 |
// Only do this check if Check_Element_Block_Params does not fail. |
| 235 |
// TODO(gdsjaar): Pass in node_map and node_id_map... |
| 236 |
if (!Check_Element_Block_Connectivity(block1, block2, elmt_map, node_map)) { |
| 237 |
is_same = false; |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
return is_same; |
| 245 |
} |
| 246 |
|
| 247 |
template <typename INT> bool Check_Assembly(Exo_Read<INT> &file1, Exo_Read<INT> &file2) |
| 248 |
{ |
| 249 |
bool is_same = true; |
| 250 |
if (file1.Num_Assembly() != file2.Num_Assembly()) { |
| 251 |
Warning(fmt::format(".. The number of assemblies ({}) in the first file does not match the " |
| 252 |
"number ({}) in the second file.\n", |
| 253 |
file1.Num_Assembly(), file2.Num_Assembly())); |
| 254 |
is_same = false; |
| 255 |
} |
| 256 |
|
| 257 |
// Verify that assemblies match in the two files... |
| 258 |
size_t matched = 0; |
| 259 |
for (size_t b = 0; b < file1.Num_Assembly(); ++b) { |
| 260 |
Assembly<INT> *assembly1 = file1.Get_Assembly_by_Index(b); |
| 261 |
if (assembly1 != nullptr) { |
| 262 |
Assembly<INT> *assembly2 = nullptr; |
| 263 |
assembly2 = file2.Get_Assembly_by_Name(assembly1->Name()); |
| 264 |
if (assembly2 == nullptr) { |
| 265 |
Warning(fmt::format(".. Assembly '{}' with id {} exists in first " |
| 266 |
"file but not the second.\n", |
| 267 |
assembly1->Name(), assembly1->Id())); |
| 268 |
is_same = false; |
| 269 |
} |
| 270 |
else { |
| 271 |
matched++; |
| 272 |
if (!Check_Assembly_Params(assembly1, assembly2)) { |
| 273 |
is_same = false; |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
if (matched != file2.Num_Assembly()) { |
| 279 |
for (size_t b = 0; b < file2.Num_Assembly(); ++b) { |
| 280 |
Assembly<INT> *assembly2 = file2.Get_Assembly_by_Index(b); |
| 281 |
if (assembly2 != nullptr) { |
| 282 |
Assembly<INT> *assembly1 = nullptr; |
| 283 |
assembly1 = file1.Get_Assembly_by_Name(assembly2->Name()); |
| 284 |
if (assembly1 == nullptr) { |
| 285 |
Warning(fmt::format(".. Assembly '{}' with id {} exists in second " |
| 286 |
"file but not the first.\n", |
| 287 |
assembly2->Name(), assembly2->Id())); |
| 288 |
is_same = false; |
| 289 |
} |
| 290 |
else { |
| 291 |
if (!Check_Assembly_Params(assembly2, assembly1)) { |
| 292 |
is_same = false; |
| 293 |
} |
| 294 |
} |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
return is_same; |
| 299 |
} |
| 300 |
|
| 301 |
template <typename INT> |
| 302 |
bool Check_Element_Block_Connectivity(Exo_Block<INT> *block1, Exo_Block<INT> *block2, |
| 303 |
const std::vector<INT> &elmt_map, |
| 304 |
const std::vector<INT> &node_map) |
| 305 |
{ |
| 306 |
|
| 307 |
bool is_same = true; |
| 308 |
SMART_ASSERT(block1 != nullptr && block2 != nullptr); |
| 309 |
|
| 310 |
block1->Load_Connectivity(); |
| 311 |
block2->Load_Connectivity(); |
| 312 |
const auto &conn1 = block1->Connectivity(); |
| 313 |
const auto &conn2 = block2->Connectivity(); |
| 314 |
|
| 315 |
SMART_ASSERT(block1->Size() == 0 || block1->Num_Nodes_per_Element() == 0 || !conn1.empty()); |
| 316 |
SMART_ASSERT(block2->Size() == 0 || block2->Num_Nodes_per_Element() == 0 || !conn2.empty()); |
| 317 |
|
| 318 |
if (interFace.map_flag == MapType::FILE_ORDER || elmt_map.empty()) { |
| 319 |
size_t node_count = block1->Size() * block1->Num_Nodes_per_Element(); |
| 320 |
SMART_ASSERT(node_count == block2->Size() * block2->Num_Nodes_per_Element()); |
| 321 |
|
| 322 |
if (interFace.map_flag != MapType::FILE_ORDER && !node_map.empty()) { |
| 323 |
for (size_t e = 0; e < node_count; ++e) { |
| 324 |
if (node_map[conn1[e] - 1] + 1 != conn2[e]) { |
| 325 |
size_t elem = e / block2->Num_Nodes_per_Element(); |
| 326 |
size_t node = e % block2->Num_Nodes_per_Element(); |
| 327 |
Warning( |
| 328 |
fmt::format(".. Connectivities in block id {} are not the same.\n" |
| 329 |
" First difference is node {} of local element {}\n", |
| 330 |
block1->Id(), node + 1, elem + 1)); |
| 331 |
is_same = false; |
| 332 |
break; |
| 333 |
} |
| 334 |
} |
| 335 |
} |
| 336 |
else { |
| 337 |
for (size_t e = 0; e < node_count; ++e) { |
| 338 |
if (conn1[e] != conn2[e]) { |
| 339 |
size_t elem = e / block2->Num_Nodes_per_Element(); |
| 340 |
size_t node = e % block2->Num_Nodes_per_Element(); |
| 341 |
Warning( |
| 342 |
fmt::format(".. Connectivities in block id {} are not the same.\n" |
| 343 |
" First difference is node {} of local element {}\n", |
| 344 |
block1->Id(), node + 1, elem + 1)); |
| 345 |
is_same = false; |
| 346 |
break; |
| 347 |
} |
| 348 |
} |
| 349 |
} |
| 350 |
} |
| 351 |
else { |
| 352 |
auto offset1 = block1->offset(); |
| 353 |
auto offset2 = block2->offset(); |
| 354 |
size_t num_element = block1->Size(); |
| 355 |
size_t nnpe = block1->Num_Nodes_per_Element(); |
| 356 |
for (size_t e1 = 0; is_same && e1 < num_element; e1++) { |
| 357 |
for (size_t n = 0; is_same && n < nnpe; ++n) { |
| 358 |
size_t off1 = e1 * nnpe + n; |
| 359 |
auto e2 = elmt_map[offset1 + e1]; |
| 360 |
if (e2 >= 0) { // If doing partial map, not all elements have a match |
| 361 |
e2 -= offset2; |
| 362 |
size_t off2 = e2 * nnpe + n; |
| 363 |
auto n1 = conn1[off1]; |
| 364 |
auto map_n1 = node_map.empty() ? n1 : node_map[n1 - 1] + 1; |
| 365 |
if (map_n1 != conn2[off2]) { |
| 366 |
Warning( |
| 367 |
fmt::format(".. Connectivities in block id {} are not the same.\n" |
| 368 |
" First difference is node {} of local element {} " |
| 369 |
"(file1) {} (file2)\n", |
| 370 |
block1->Id(), n + 1, e1 + 1, e2 + 1)); |
| 371 |
is_same = false; |
| 372 |
break; |
| 373 |
} |
| 374 |
} |
| 375 |
} |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
block2->Free_Connectivity(); |
| 380 |
block1->Free_Connectivity(); |
| 381 |
return is_same; |
| 382 |
} |
| 383 |
|
| 384 |
template <typename INT> |
| 385 |
bool Check_Assembly_Params(const Assembly<INT> *assembly1, const Assembly<INT> *assembly2) |
| 386 |
{ |
| 387 |
bool is_same = true; |
| 388 |
SMART_ASSERT(assembly1 && assembly2); |
| 389 |
|
| 390 |
if (interFace.by_name && assembly1->Id() != assembly2->Id()) { |
| 391 |
Warning(fmt::format(".. Assembly '{}' ids don't agree ({} != {}).\n", assembly1->Name(), |
| 392 |
assembly1->Id(), assembly2->Id())); |
| 393 |
is_same = false; |
| 394 |
} |
| 395 |
if (!interFace.by_name && assembly1->Name() != assembly2->Name()) { |
| 396 |
if (!assembly1->generatedName_ && !assembly2->generatedName_) { |
| 397 |
Warning(fmt::format(".. Assembly {} names don't agree ('{}' != '{}').\n", assembly1->Id(), |
| 398 |
assembly1->Name(), assembly2->Name())); |
| 399 |
is_same = false; |
| 400 |
} |
| 401 |
} |
| 402 |
if (assembly1->Type() != assembly2->Type()) { |
| 403 |
Warning(fmt::format(".. Assembly '{}': entity types don't agree ({} != {}).\n", |
| 404 |
assembly1->Name(), ex_name_of_object(assembly1->Type()), |
| 405 |
ex_name_of_object(assembly2->Type()))); |
| 406 |
is_same = false; |
| 407 |
} |
| 408 |
if (assembly1->Size() != assembly2->Size()) { |
| 409 |
Warning(fmt::format(".. Assembly '{}': number of entities doesn't agree ({} != {}).\n", |
| 410 |
assembly1->Name(), assembly1->Entities().size(), |
| 411 |
assembly2->Entities().size())); |
| 412 |
is_same = false; |
| 413 |
} |
| 414 |
if ((assembly1->Type() == assembly2->Type()) && |
| 415 |
(assembly1->Entities().size() == assembly2->Entities().size())) { |
| 416 |
// Check membership of the entities list... |
| 417 |
if (!std::is_permutation(assembly1->Entities().begin(), assembly1->Entities().end(), |
| 418 |
assembly2->Entities().begin())) { |
| 419 |
Warning(fmt::format(".. Assembly '{}': entity list on first file ({}) does not match " |
| 420 |
"entity list on second file ({}).\n", |
| 421 |
assembly1->Name(), fmt::join(assembly1->Entities(), ", "), |
| 422 |
fmt::join(assembly2->Entities(), ", "))); |
| 423 |
is_same = false; |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
return is_same; |
| 428 |
} |
| 429 |
|
| 430 |
template <typename INT> |
| 431 |
bool Check_Element_Block_Params(const Exo_Block<INT> *block1, const Exo_Block<INT> *block2) |
| 432 |
{ |
| 433 |
bool is_same = true; |
| 434 |
SMART_ASSERT(block1 && block2); |
| 435 |
|
| 436 |
if (interFace.by_name && block1->Id() != block2->Id()) { |
| 437 |
Warning(fmt::format(".. Block '{}' ids don't agree ({} != {}).\n", block1->Name(), |
| 438 |
block1->Id(), block2->Id())); |
| 439 |
if (interFace.pedantic) { |
| 440 |
is_same = false; |
| 441 |
} |
| 442 |
} |
| 443 |
if (!interFace.by_name && block1->Name() != block2->Name()) { |
| 444 |
if (!block1->generatedName_ && !block2->generatedName_) { |
| 445 |
Warning(fmt::format(".. Block {} names don't agree ({} != {}).\n", block1->Id(), |
| 446 |
block1->Name(), block2->Name())); |
| 447 |
if (interFace.pedantic) { |
| 448 |
is_same = false; |
| 449 |
} |
| 450 |
} |
| 451 |
} |
| 452 |
if (!(no_case_equals(block1->Element_Type(), block2->Element_Type()))) { |
| 453 |
if (!interFace.short_block_check || |
| 454 |
!close_compare(block1->Element_Type(), block2->Element_Type())) { |
| 455 |
Warning(fmt::format(".. Block {}: element types don't agree ({} != {}).\n", block1->Name(), |
| 456 |
block1->Element_Type(), block2->Element_Type())); |
| 457 |
is_same = false; |
| 458 |
} |
| 459 |
} |
| 460 |
if (block1->Size() != block2->Size()) { |
| 461 |
Warning(fmt::format(".. Block {}: number of elements doesn't agree ({} != {}).\n", |
| 462 |
block1->Name(), block1->Size(), block2->Size())); |
| 463 |
is_same = false; |
| 464 |
} |
| 465 |
if (block1->Num_Nodes_per_Element() != block2->Num_Nodes_per_Element()) { |
| 466 |
Warning(fmt::format(".. Block {}: number of nodes per element doesn't agree ({} != {}).\n", |
| 467 |
block1->Name(), block1->Num_Nodes_per_Element(), |
| 468 |
block2->Num_Nodes_per_Element())); |
| 469 |
is_same = false; |
| 470 |
} |
| 471 |
#if 0 |
| 472 |
if (block1->Num_Attributes() != block2->Num_Attributes()) { |
| 473 |
Warning(fmt::format(".. Block {}: number of attributes doesn't agree ({} != {}).\n" |
| 474 |
block1->Name(), block1->Num_Attributes(), block2->Num_Attributes()); |
| 475 |
is_same = false; |
| 476 |
} |
| 477 |
#endif |
| 478 |
return is_same; |
| 479 |
} |
| 480 |
|
| 481 |
template <typename INT> |
| 482 |
bool Check_Nodeset(Exo_Read<INT> &file1, Exo_Read<INT> &file2, const std::vector<INT> &node_map, |
| 483 |
bool /*unused*/) |
| 484 |
{ |
| 485 |
// Currently don't set diff flag for most of these since we |
| 486 |
// can continue (somewhat) with these differences... |
| 487 |
// As get more usage of nodeset/sideset variables, may revisit |
| 488 |
// what is a diff. |
| 489 |
bool is_same = true; |
| 490 |
if (file1.Num_Node_Sets() != file2.Num_Node_Sets()) { |
| 491 |
if (interFace.map_flag != MapType::PARTIAL) { |
| 492 |
Warning(".. Number of nodesets doesn't agree...\n"); |
| 493 |
if (interFace.pedantic) { |
| 494 |
is_same = false; |
| 495 |
} |
| 496 |
} |
| 497 |
} |
| 498 |
// Check that the files both contain the same nodesets... |
| 499 |
for (size_t b = 0; b < file1.Num_Node_Sets(); ++b) { |
| 500 |
Node_Set<INT> *set1 = file1.Get_Node_Set_by_Index(b); |
| 501 |
Node_Set<INT> *set2 = nullptr; |
| 502 |
if (interFace.by_name) { |
| 503 |
set2 = file2.Get_Node_Set_by_Name(set1->Name()); |
| 504 |
} |
| 505 |
else { |
| 506 |
set2 = file2.Get_Node_Set_by_Id(set1->Id()); |
| 507 |
} |
| 508 |
|
| 509 |
if (set2 == nullptr) { |
| 510 |
Warning( |
| 511 |
fmt::format(".. Nodeset id {} exists in first file but not the second.\n", set1->Id())); |
| 512 |
if (interFace.pedantic) { |
| 513 |
is_same = false; |
| 514 |
} |
| 515 |
} |
| 516 |
else { |
| 517 |
if (set1->Size() != set2->Size()) { |
| 518 |
Warning(fmt::format( |
| 519 |
".. The node count for nodeset id {} is not the same in the two files ({} != {}).\n", |
| 520 |
set1->Id(), set1->Size(), set2->Size())); |
| 521 |
if (interFace.pedantic) { |
| 522 |
is_same = false; |
| 523 |
} |
| 524 |
} |
| 525 |
if (interFace.by_name && set1->Id() != set2->Id()) { |
| 526 |
Warning(fmt::format(".. Nodeset '{}' ids don't agree ({} != {}).\n", set1->Name(), |
| 527 |
set1->Id(), set2->Id())); |
| 528 |
if (interFace.pedantic) { |
| 529 |
is_same = false; |
| 530 |
} |
| 531 |
} |
| 532 |
if (!interFace.by_name && set1->Name() != set2->Name()) { |
| 533 |
if (!set1->generatedName_ && !set2->generatedName_) { |
| 534 |
Warning(fmt::format(".. Nodeset {} names don't agree ({} != {}).\n", set1->Id(), |
| 535 |
set1->Name(), set2->Name())); |
| 536 |
if (interFace.pedantic) { |
| 537 |
is_same = false; |
| 538 |
} |
| 539 |
} |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
// Check that can access all nodesets in file2. |
| 545 |
// This should never fail if the above tests pass... |
| 546 |
for (size_t b = 0; b < file2.Num_Node_Sets(); ++b) { |
| 547 |
Node_Set<INT> *set2 = file2.Get_Node_Set_by_Index(b); |
| 548 |
if (set2 == nullptr) { |
| 549 |
Warning( |
| 550 |
fmt::format(".. Could not access the Nodeset with index {} in the second file.\n", b)); |
| 551 |
if (interFace.pedantic) { |
| 552 |
is_same = false; |
| 553 |
} |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
// Do the following check(s) only if there are nodeset variables... |
| 558 |
// For each nodeset, check that the order of the nodeset nodes is the same. |
| 559 |
// Eventually need to be able to map the order... |
| 560 |
if (!interFace.ns_var_names.empty() || interFace.pedantic) { |
| 561 |
for (size_t b = 0; b < file1.Num_Node_Sets(); ++b) { |
| 562 |
Node_Set<INT> *set1 = file1.Get_Node_Set_by_Index(b); |
| 563 |
Node_Set<INT> *set2 = nullptr; |
| 564 |
if (interFace.by_name) { |
| 565 |
set2 = file2.Get_Node_Set_by_Name(set1->Name()); |
| 566 |
} |
| 567 |
else { |
| 568 |
set2 = file2.Get_Node_Set_by_Id(set1->Id()); |
| 569 |
} |
| 570 |
|
| 571 |
if (set2 == nullptr) { |
| 572 |
continue; |
| 573 |
} |
| 574 |
|
| 575 |
if (!node_map.empty()) { |
| 576 |
set1->apply_map(node_map); |
| 577 |
} |
| 578 |
|
| 579 |
if ((interFace.pedantic || set1->var_count() > 0) && (set1->Size() == set2->Size())) { |
| 580 |
size_t node_count = set1->Size(); |
| 581 |
int64_t diff = -1; |
| 582 |
for (size_t i = 0; i < node_count; i++) { |
| 583 |
if (set1->Node_Id(i) != set2->Node_Id(i)) { |
| 584 |
diff = i; |
| 585 |
break; |
| 586 |
} |
| 587 |
} |
| 588 |
if (diff >= 0) { |
| 589 |
Warning(fmt::format( |
| 590 |
".. The nodelists for nodeset id {} are not the same in the two files.\n" |
| 591 |
"\t\tThe first difference is at position {}: Node {} vs. Node {}.\n", |
| 592 |
set1->Id(), set1->Node_Index(diff) + 1, set1->Node_Id(diff), set2->Node_Id(diff))); |
| 593 |
if (interFace.map_flag != MapType::PARTIAL) { |
| 594 |
is_same = false; |
| 595 |
} |
| 596 |
else { |
| 597 |
Warning(".. The nodelist differences are ignored for the " |
| 598 |
"partial_map case.\n"); |
| 599 |
} |
| 600 |
} |
| 601 |
} |
| 602 |
} |
| 603 |
} |
| 604 |
return is_same; |
| 605 |
} |
| 606 |
|
| 607 |
template <typename INT> |
| 608 |
bool Check_Sideset(Exo_Read<INT> &file1, Exo_Read<INT> &file2, const std::vector<INT> &elmt_map, |
| 609 |
bool /*unused*/) |
| 610 |
{ |
| 611 |
// Currently don't set diff flag for most of these since we |
| 612 |
// can continue (somewhat) with these differences... |
| 613 |
// As get more usage of nodeset/sideset variables, may revisit |
| 614 |
// what is a diff. |
| 615 |
bool is_same = true; |
| 616 |
if (file1.Num_Side_Sets() != file2.Num_Side_Sets()) { |
| 617 |
if (interFace.map_flag != MapType::PARTIAL) { |
| 618 |
Warning(".. Number of sidesets doesn't agree...\n"); |
| 619 |
if (interFace.pedantic) { |
| 620 |
is_same = false; |
| 621 |
} |
| 622 |
} |
| 623 |
} |
| 624 |
// Check that the files both contain the same sidesets... |
| 625 |
for (size_t b = 0; b < file1.Num_Side_Sets(); ++b) { |
| 626 |
Side_Set<INT> *set1 = file1.Get_Side_Set_by_Index(b); |
| 627 |
Side_Set<INT> *set2 = nullptr; |
| 628 |
if (interFace.by_name) { |
| 629 |
set2 = file2.Get_Side_Set_by_Name(set1->Name()); |
| 630 |
} |
| 631 |
else { |
| 632 |
set2 = file2.Get_Side_Set_by_Id(set1->Id()); |
| 633 |
} |
| 634 |
|
| 635 |
if (set2 == nullptr) { |
| 636 |
Warning( |
| 637 |
fmt::format(".. Sideset id {} exists in first file but not the second.\n", set1->Id())); |
| 638 |
if (interFace.pedantic) { |
| 639 |
is_same = false; |
| 640 |
} |
| 641 |
} |
| 642 |
else { |
| 643 |
if (set1->Size() != set2->Size()) { |
| 644 |
Warning(fmt::format( |
| 645 |
".. The side count for sideset id {} is not the same in the two files ({} != {}).\n", |
| 646 |
set1->Id(), set1->Size(), set2->Size())); |
| 647 |
if (interFace.pedantic) { |
| 648 |
is_same = false; |
| 649 |
} |
| 650 |
} |
| 651 |
if (interFace.by_name && set1->Id() != set2->Id()) { |
| 652 |
Warning(fmt::format(".. Sideset '{}' ids don't agree ({} != {}).\n", set1->Name(), |
| 653 |
set1->Id(), set2->Id())); |
| 654 |
if (interFace.pedantic) { |
| 655 |
is_same = false; |
| 656 |
} |
| 657 |
} |
| 658 |
if (!interFace.by_name && set1->Name() != set2->Name()) { |
| 659 |
if (!set1->generatedName_ && !set2->generatedName_) { |
| 660 |
Warning(fmt::format(".. Sideset {} names don't agree ({} != {}).\n", set1->Id(), |
| 661 |
set1->Name(), set2->Name())); |
| 662 |
if (interFace.pedantic) { |
| 663 |
is_same = false; |
| 664 |
} |
| 665 |
} |
| 666 |
} |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
for (size_t b = 0; b < file2.Num_Side_Sets(); ++b) { |
| 671 |
Side_Set<INT> *set2 = file2.Get_Side_Set_by_Index(b); |
| 672 |
if (set2 == nullptr) { |
| 673 |
Warning( |
| 674 |
fmt::format(".. Could not access the Sideset with index {} in the second file.\n", b)); |
| 675 |
if (interFace.pedantic) { |
| 676 |
is_same = false; |
| 677 |
} |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
// Do the following check(s) only if there are sideset variables... (or -pedantic) |
| 682 |
// For each sideset, check that the order of the sideset sides is the same. |
| 683 |
// Eventually need to be able to map the order... |
| 684 |
if (!interFace.ss_var_names.empty() || interFace.pedantic || !interFace.ignore_sideset_df) { |
| 685 |
for (size_t b = 0; b < file1.Num_Side_Sets(); ++b) { |
| 686 |
Side_Set<INT> *set1 = file1.Get_Side_Set_by_Index(b); |
| 687 |
Side_Set<INT> *set2 = nullptr; |
| 688 |
if (interFace.by_name) { |
| 689 |
set2 = file2.Get_Side_Set_by_Name(set1->Name()); |
| 690 |
} |
| 691 |
else { |
| 692 |
set2 = file2.Get_Side_Set_by_Id(set1->Id()); |
| 693 |
} |
| 694 |
|
| 695 |
if (set2 == nullptr) { |
| 696 |
continue; |
| 697 |
} |
| 698 |
|
| 699 |
if (!elmt_map.empty()) { |
| 700 |
set1->apply_map(elmt_map); |
| 701 |
} |
| 702 |
|
| 703 |
// Don't care if sidesets don't match if there are no variables... |
| 704 |
// If different sizes and pedantic, difference caught above. |
| 705 |
if ((interFace.pedantic || set1->var_count() > 0) && (set1->Size() == set2->Size())) { |
| 706 |
size_t side_count = set1->Size(); |
| 707 |
int64_t diff = -1; |
| 708 |
for (size_t i = 0; i < side_count; i++) { |
| 709 |
if (set1->Side_Id(i) != set2->Side_Id(i)) { |
| 710 |
diff = i; |
| 711 |
break; |
| 712 |
} |
| 713 |
} |
| 714 |
if (diff >= 0) { |
| 715 |
// If `elmt_map` is not null, then need to unmap the set1 ids to get the local id that |
| 716 |
// appears in the file. If don't do this, error message is very confusing for the |
| 717 |
// user... |
| 718 |
auto set1_id = set1->Side_Id(diff).first; |
| 719 |
if (!elmt_map.empty()) { |
| 720 |
// Iterate map to find an entry equal to `set1_id`. Its position is then the file1 id |
| 721 |
// of the element. |
| 722 |
for (size_t i = 0; i < file1.Num_Elements(); i++) { |
| 723 |
if (elmt_map[i] == set1_id - 1) { |
| 724 |
set1_id = i + 1; |
| 725 |
break; |
| 726 |
} |
| 727 |
} |
| 728 |
} |
| 729 |
|
| 730 |
Warning(fmt::format( |
| 731 |
".. The sidelists for sideset id {} are not the same in the two files.\n" |
| 732 |
"\t\tThe first difference is at position {}: Side {}.{} .vs. Side {}.{}.\n", |
| 733 |
set1->Id(), set1->Side_Index(diff) + 1, set1_id, set1->Side_Id(diff).second, |
| 734 |
set2->Side_Id(diff).first, set2->Side_Id(diff).second)); |
| 735 |
if (interFace.map_flag != MapType::PARTIAL) { |
| 736 |
is_same = false; |
| 737 |
} |
| 738 |
else { |
| 739 |
Warning(".. The sidelist differences are ignored for the " |
| 740 |
"partial_map case.\n"); |
| 741 |
} |
| 742 |
} |
| 743 |
} |
| 744 |
} |
| 745 |
} |
| 746 |
return is_same; |
| 747 |
} |
| 748 |
|
| 749 |
bool close_compare(const std::string &st1, const std::string &st2) |
| 750 |
{ |
| 751 |
auto len1 = st1.size(); |
| 752 |
auto len2 = st2.size(); |
| 753 |
|
| 754 |
// Check that digits (if any) at end of names match |
| 755 |
while ((isdigit(st1[len1 - 1]) != 0) && (isdigit(st2[len2 - 1]) != 0)) { |
| 756 |
if (st1[len1 - 1] != st2[len2 - 1]) { |
| 757 |
return false; |
| 758 |
} |
| 759 |
len1--; |
| 760 |
len2--; |
| 761 |
} |
| 762 |
|
| 763 |
// Skip any digits at the end. It's OK if only one name has |
| 764 |
// digits since we want 'tri' and 'triangle6' to match, but not |
| 765 |
// tri6 and tri3 nor quad9 and tri9 |
| 766 |
while (isdigit(st1[len1 - 1]) != 0) { |
| 767 |
len1--; |
| 768 |
} |
| 769 |
|
| 770 |
while (isdigit(st2[len2 - 1]) != 0) { |
| 771 |
len2--; |
| 772 |
} |
| 773 |
|
| 774 |
unsigned length = (len1 < len2) ? len1 : len2; |
| 775 |
for (unsigned i = 0; i < length; ++i) { |
| 776 |
if (toupper(st1[i]) != toupper(st2[i])) { |
| 777 |
return false; |
| 778 |
} |
| 779 |
} |
| 780 |
return true; |
| 781 |
} |
| 782 |
} // namespace |
| 783 |
|
| 784 |
template bool Check_Global(Exo_Read<int> &file1, Exo_Read<int> &file2); |
| 785 |
template void Check_Compatible_Meshes(Exo_Read<int> &file1, Exo_Read<int> &file2, bool check_only, |
| 786 |
const std::vector<int> &node_map, |
| 787 |
const std::vector<int> &elmt_map, const int *node_id_map); |
| 788 |
|
| 789 |
template bool Check_Global(Exo_Read<int64_t> &file1, Exo_Read<int64_t> &file2); |
| 790 |
template void Check_Compatible_Meshes(Exo_Read<int64_t> &file1, Exo_Read<int64_t> &file2, |
| 791 |
bool check_only, const std::vector<int64_t> &node_map, |
| 792 |
const std::vector<int64_t> &elmt_map, |
| 793 |
const int64_t *node_id_map); |