Debian Codegraph @

packages/seacas/applications/exodiff/exodiff.C

raw
1 // Copyright(C) 1999-, 20242024 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 #include <algorithm>
7 #include <cfloat>
8 #include <cmath>
9 #include <cstdio>
10 #include <cstdlib>
11 #include <cstring>
12 #include <ctime>
13 #include <fmt/chrono.h>
14 #include <fmt/ostream.h>
15 #include <fmt/ranges.h>
16 #include <fstream>
17 #include <iostream>
18 #include <numeric>
19
20 #include <SL_tokenize.h>
21
22 #include "ED_SystemInterface.h"
23 #include "ED_Version.h"
24 #include "FileInfo.h"
25 #include "MinMaxData.h"
26 #include "Norm.h"
27 #include "Tolerance.h"
28 #include "edge_block.h"
29 #include "exo_block.h"
30 #include "exo_read.h"
31 #include "exodiff.h"
32 #include "exodusII.h"
33 #include "face_block.h"
34 #include "map.h"
35 #include "node_set.h"
36 #include "side_set.h"
37 #include "smart_assert.h"
38 #include "stringx.h"
39 #include "util.h"
40
41 #include "add_to_log.h"
42
43 SystemInterface interFace;
44
45 struct TimeInterp
46 {
47 TimeInterp() = default;
48
49 int step1{-1}; // step at beginning of interval. -1 if time prior to time at step1
50 int step2{-1}; // step at end of interval. -1 if time after time at step2
51
52 double time{0.0}; // Time being interpolated to.
53
54 // If t1 = time at step1 and t2 = time at step2,
55 // then proportion = (time-t1)/(t2-t1)
56 // Or, value at time = (1.0-proportion)*v1 + proportion*v2
57 double proportion{0.0};
58 };
59
60 std::string Date()
61 {
62 time_t calendar_time = time(nullptr);
63 #if defined __NVCC__
64 char tbuf[32];
65 struct tm *local_time = localtime(&calendar_time);
66 strftime(tbuf, 32, "%Y/%m/%d %H:%M:%S %Z", local_time);
67 std::string time_string(tbuf);
68 #else
69 auto const local_time = fmt::localtime(calendar_time);
70 auto time_string = fmt::format("{:%Y/%m/%d %H:%M:%S %Z}", local_time);
71 #endif
72 return time_string;
73 }
74
75 bool Invalid_Values(const double *values, size_t count);
76 bool Equal_Values(const double *values, size_t count, double *value);
77
78 void Print_Banner(const char *prefix)
79 {
80 fmt::print("\n"
81 "{0} *****************************************************************\n"
82 "{0} ",
83 prefix);
84 SystemInterface::show_version();
85 fmt::print("{0} Authors: Richard Drake, [email protected] \n"
86 "{0} Greg Sjaardema, [email protected] \n"
87 "{0} Run on {1}\n"
88 "{0} *****************************************************************\n\n",
89 prefix, Date());
90 }
91
92 // Issues: - When mapping element numbers, blocks are irrelevant. Problem is
93 // the variables that are determined to be stored in each file are
94 // NOT independent of blocks .. in fact, that is how it determines
95 // if the two files have the same element variable stored. The
96 // mapping will still run ok, just don't expect it to work if the
97 // blocks don't line up and different variables are stored in
98 // different blocks.
99
100 template <typename INT>
101 extern void Build_Variable_Names(Exo_Read<INT> &file1, Exo_Read<INT> &file2, bool *diff_found);
102
103 template <typename INT> extern bool Check_Global(Exo_Read<INT> &file1, Exo_Read<INT> &file2);
104
105 template <typename INT>
106 extern void Check_Compatible_Meshes(Exo_Read<INT> &file1, Exo_Read<INT> &file2, bool check_only,
107 const std::vector<INT> &node_map,
108 const std::vector<INT> &elmt_map, const INT *node_id_map);
109
110 template <typename INT>
111 int Create_File(Exo_Read<INT> &file1, Exo_Read<INT> &file2, const std::string &diffile_name,
112 bool *diff_found);
113
114 double To_Double(const std::string &str_val);
115
116 double FileDiff(double v1, double v2, ToleranceMode type);
117
118 void Die_TS(double ts);
119
120 template <typename INT> size_t global_elmt_num(Exo_Read<INT> &file, size_t b_idx, size_t e_idx);
121
122 template <typename INT> double Find_Min_Coord_Sep(Exo_Read<INT> &file);
123
124 int timeStepIsExcluded(int ts);
125
126 template <typename INT>
127 const double *get_nodal_values(Exo_Read<INT> &filen, int time_step, size_t idx, size_t fno,
128 const std::string &name, bool *diff_flag);
129 template <typename INT>
130 const double *get_nodal_values(Exo_Read<INT> &filen, const TimeInterp &t, size_t idx, size_t fno,
131 const std::string &name, bool *diff_flag);
132
133 template <typename INT>
134 void do_summaries(Exo_Read<INT> &file, int time_step, std::vector<MinMaxData> &mm_glob,
135 std::vector<MinMaxData> &mm_node, std::vector<MinMaxData> &mm_elmt,
136 std::vector<MinMaxData> &mm_ns, std::vector<MinMaxData> &mm_ss,
137 std::vector<MinMaxData> &mm_eb, std::vector<MinMaxData> &mm_fb,
138 const std::vector<INT> &elmt_map, bool *diff_flag);
139
140 template <typename INT>
141 void do_diffs(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int time_step1, const TimeInterp &t2,
142 int out_file_id, int output_step, const std::vector<INT> &node_map,
143 const INT *node_id_map, const std::vector<INT> &elmt_map, const INT *elem_id_map,
144 Exo_Block<INT> **blocks2, std::vector<double> &var_vals, bool *diff_flag);
145
146 template <typename INT>
147 bool summarize_globals(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_glob);
148 template <typename INT>
149 bool summarize_nodals(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_node);
150 template <typename INT>
151 bool summarize_element(Exo_Read<INT> &file, int step, const std::vector<INT> &elmt_map,
152 std::vector<MinMaxData> &mm_elmt);
153 template <typename INT>
154 bool summarize_nodeset(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_ns);
155 template <typename INT>
156 bool summarize_sideset(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_ss);
157 template <typename INT>
158 bool summarize_edgeblock(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_eb);
159 template <typename INT>
160 bool summarize_faceblock(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_fb);
161
162 template <typename INT>
163 bool diff_globals(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
164 int out_file_id, int output_step, std::vector<double> &gvals);
165 template <typename INT>
166 bool diff_nodals(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
167 int out_file_id, int output_step, const std::vector<INT> &node_map,
168 const INT *id_map, std::vector<double> &nvals);
169 template <typename INT>
170 bool diff_element(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
171 int out_file_id, int output_step, const std::vector<INT> &elmt_map,
172 const INT *id_map, Exo_Block<INT> **blocks2, std::vector<double> &evals);
173
174 template <typename INT>
175 bool diff_element_attributes(Exo_Read<INT> &file1, Exo_Read<INT> &file2,
176 const std::vector<INT> &elmt_map, const INT *id_map,
177 Exo_Block<INT> **blocks2);
178
179 template <typename INT>
180 bool diff_nodeset(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
181 int out_file_id, int output_step, const INT *id_map, std::vector<double> &vals);
182
183 template <typename INT>
184 bool diff_sideset(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
185 int out_file_id, int output_step, const INT *id_map, std::vector<double> &vals);
186
187 template <typename INT>
188 bool diff_sideset_df(Exo_Read<INT> &file1, Exo_Read<INT> &file2, const INT *id_map);
189
190 template <typename INT>
191 void output_summary(Exo_Read<INT> &file1, MinMaxData &mm_time, std::vector<MinMaxData> &mm_glob,
192 std::vector<MinMaxData> &mm_node, std::vector<MinMaxData> &mm_elmt,
193 std::vector<MinMaxData> &mm_ns, std::vector<MinMaxData> &mm_ss,
194 std::vector<MinMaxData> &mm_eb, std::vector<MinMaxData> &mm_fb,
195 const INT *node_id_map, const INT *elem_id_map);
196
197 #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || \
198 defined(__MINGW32__) || defined(_WIN64) || defined(__MINGW64__)
199 #define __ED_WINDOWS__ 1
200 #endif
201
202 #if !defined(__ED_WINDOWS__)
203 #include <csignal>
204 // bit of a hack to get GNU's functions to enable floating point error trapping
205 #ifdef LINUX
206 #ifdef __USE_GNU
207 #include <fenv.h>
208 #else
209 #define __USE_GNU
210 #include <fenv.h>
211 #undef __USE_GNU
212 #endif
213 #endif
214
215 struct sigaction sigact; // the signal handler & blocked signals
216
217 #endif
218
219 bool checking_invalid = false;
220 bool invalid_data = false;
221 extern "C" {
222 void floating_point_exception_handler(int signo)
223 {
224 if (!checking_invalid) {
225 Error(fmt::format("caught floating point exception ({}) bad data?\n", signo));
226 }
227 else {
228 invalid_data = true;
229 }
230 }
231 }
232
233 namespace {
234 int get_number(const std::string &str)
235 {
236 int N = -1;
237 bool all_dig = str.find_first_not_of("0123456789") == std::string::npos;
238 if (all_dig) {
239 N = std::stoi(str);
240 }
241 return N;
242 }
243
244 int get_change_set_index(const std::string &cs_name, const NameList &cs_names)
245 {
246 auto N = get_number(cs_name);
247 if (N < 0) {
248 if (no_case_equals(cs_name, "root") || no_case_equals(cs_name, "/")) {
249 return 0;
250 }
251 for (size_t i = 0; i < cs_names.size(); i++) {
252 if (no_case_equals(cs_name, cs_names[i])) {
253 return (int)i + 1;
254 }
255 }
256 Error(fmt::format(
257 "Could not find a match for the change set named {}.\nValid change set names are: {}\n",
258 cs_name, fmt::join(cs_names, ", ")));
259 }
260 return N;
261 }
262
263 template <typename INT>
264 std::pair<std::vector<int>, std::vector<int>>
265 create_change_set_list(Exo_Read<INT> &file1, Exo_Read<INT> &file2,
266 const std::string &change_set_spec)
267 {
268 // Change Sets:
269 // * User can specify diffing of specific change sets
270 // * - same change set in both files
271 // * - specified change set in one file with different specified change set in other file
272 // * - specified change set in file with change sets vs "root" in file with no change sets
273 // * If user does not specify, then do diff on all change sets in the files.
274 // * - If different count of change sets, then warn and iterate over 0..min_count
275 //
276 // User specification:
277 // * by 1-based index
278 // * by case sensitive name.
279 // * index `0` indicates root of file with no change sets
280 // * name `root` or `/` indicates root of file with no change sets
281 //
282 // User specifies: `cs1,cs2,...,csn:csa,csb,csc,...,csx`
283 // * Length of lists must be the same
284 // * `:` separates file 1 from file 2 change sets
285 // * ',' separates change sets within a file
286 // * If no ':', then the list is the change set(s) to be compared in both files.
287
288 std::vector<int> cs1;
289 std::vector<int> cs2;
290
291 // Check change_set count...
292 auto cs_cnt_1 = file1.Num_Change_Sets();
293 auto cs_cnt_2 = file2.Num_Change_Sets();
294 auto cs_cnt = interFace.summary_flag ? cs_cnt_1 : std::min(cs_cnt_1, cs_cnt_2);
295
296 if (cs_cnt_1 == 0 && cs_cnt_2 == 0) {
297 if (!change_set_spec.empty()) {
298 Warning("WARNING: Neither file contains change sets, but user specified a list of change "
299 "sets to compare. It will be ignored.\n");
300 }
301 return std::make_pair(cs1, cs2);
302 }
303
304 // At least one file has change sets...
305 if (change_set_spec.empty()) {
306 if (cs_cnt_1 != cs_cnt_2) {
307 if (!interFace.summary_flag) {
308 if (cs_cnt_1 == 0 || cs_cnt_2 == 0) {
309 if (cs_cnt_1 == 0) {
310 Warning(fmt::format(
311 "Change set count mismatch file1 does not have change sets, file2 has {}.\n"
312 " Will compare file1 with the first change set in file2.\n",
313 cs_cnt_2));
314 cs1.push_back(0);
315 cs2.push_back(1);
316 return std::make_pair(cs1, cs2);
317 }
318 else {
319 Warning(fmt::format(
320 "Change set count mismatch file2 does not have change sets, file1 has {}.\n"
321 " Will compare file2 with the first change set in file1.\n",
322 cs_cnt_1));
323 cs1.push_back(1);
324 cs2.push_back(0);
325 return std::make_pair(cs1, cs2);
326 }
327 }
328 else {
329 Warning(fmt::format("Change set count mismatch file1 has {}, file2 has {}.\n"
330 " Will compare the first {} change sets only.\n",
331 cs_cnt_1, cs_cnt_2, cs_cnt));
332 }
333 }
334 }
335 for (int i = 0; i < cs_cnt; i++) {
336 cs1.push_back(i + 1);
337 cs2.push_back(i + 1);
338 }
339 return std::make_pair(cs1, cs2);
340 }
341 else {
342 // change_set_spec is not empty -- contains list of one or more names or indices for one or
343 // both databases.
344 auto tokens = SLIB::tokenize(change_set_spec, ":");
345 if (tokens.size() == 1) {
346 // User did not specify specific change sets for both files. Parse list and apply to
347 // both...
348 auto cs_list = SLIB::tokenize(tokens[0], ",");
349 if (cs_list.size() == 1 && (cs_cnt_1 == 0 || cs_cnt_2 == 0)) {
350 // Specifies the cs to compare to a file with no change_sets...
351 auto &cs_names = cs_cnt_2 == 0 ? file1.Change_Set_Names() : file2.Change_Set_Names();
352 auto N = get_change_set_index(cs_list[0], cs_names);
353 if (N < 0) {
354 return std::make_pair(cs1, cs2);
355 }
356
357 if (cs_cnt_1 == 0) {
358 cs1.push_back(0);
359 cs2.push_back(N);
360 }
361 else {
362 cs1.push_back(N);
363 cs2.push_back(0);
364 }
365 return std::make_pair(cs1, cs2);
366 }
367 for (const auto &cs : cs_list) {
368 auto N = get_change_set_index(cs, file1.Change_Set_Names());
369 if (N >= 0 && N <= cs_cnt) {
370 cs1.push_back(N);
371 }
372 else {
373 Error(fmt::format("Change set index is invalid: {}, file1 has {}, "
374 "file2 has {}. Ignoring this entry.\n",
375 N, cs_cnt_1, cs_cnt_2));
376 }
377 }
378 cs2 = cs1;
379 }
380 else {
381 auto cs1_list = SLIB::tokenize(tokens[0], ",");
382 auto cs2_list = SLIB::tokenize(tokens[1], ",");
383 if (cs1_list.size() != cs2_list.size()) {
384 Error(fmt::format("There were {} changes sets specified for file1 and {} specified for "
385 "file2. The count must be the same.\n",
386 cs1_list.size(), cs2_list.size()));
387 return std::make_pair(cs1, cs2);
388 }
389 for (size_t i = 0; i < cs1_list.size(); i++) {
390 auto N1 = get_change_set_index(cs1_list[i], file1.Change_Set_Names());
391 auto N2 = get_change_set_index(cs2_list[i], file2.Change_Set_Names());
392
393 if (N1 >= 0 && N1 <= cs_cnt_1 && N2 >= 0 && N2 <= cs_cnt_2) {
394 cs1.push_back(N1);
395 cs2.push_back(N2);
396 }
397 else {
398 Error(fmt::format("At least one change set index is invalid: ({} {}), file1 has {}, "
399 "file2 has {}. Ignoring this entry.\n",
400 N1, N2, cs_cnt_1, cs_cnt_2));
401 }
402 }
403 }
404 }
405 return std::make_pair(cs1, cs2);
406 }
407
408 int get_int_size(const std::string &file_name)
409 {
410 if (file_name.empty()) {
411 return 0;
412 }
413
414 int ws = 0;
415 int comp_ws = 8;
416 float dumb = 0.0;
417 int exoid = ex_open(file_name.c_str(), EX_READ, &comp_ws, &ws, &dumb);
418 if (exoid < 0) {
419 Error(fmt::format("Couldn't open file \"{}\".\n", file_name));
420 }
421 int size = (ex_int64_status(exoid) & EX_ALL_INT64_DB) != 0 ? 8 : 4;
422 ex_close(exoid);
423 return size;
424 }
425
426 template <typename INT> TimeInterp get_surrounding_times(double time, Exo_Read<INT> &file)
427 {
428 TimeInterp tprop;
429 tprop.time = time;
430
431 int num_times = file.Num_Times();
432 if (num_times == 0 || time < file.Time(1)) {
433 tprop.step2 = 0;
434 return tprop;
435 }
436
437 if (time > file.Time(num_times)) {
438 tprop.step1 = 0;
439 return tprop;
440 }
441
442 int tbef = 1;
443 for (int i = 2; i <= num_times; i++) {
444 if (file.Time(i) <= time) {
445 tbef = i;
446 }
447 else if (interFace.time_tol.type != ToleranceMode::IGNORE_ &&
448 !interFace.time_tol.Diff(time, file.Time(i))) {
449 tbef = i;
450 }
451 else {
452 break;
453 }
454 }
455
456 if (!interFace.time_tol.Diff(time, file.Time(tbef))) {
457 tprop.step1 = tprop.step2 = tbef;
458 return tprop;
459 }
460
461 SMART_ASSERT(tbef + 1 <= num_times)(tbef + 1)(num_times);
462 tprop.step1 = tbef;
463 tprop.step2 = tbef + 1;
464
465 // Calculate proprtion...
466 double t1 = file.Time(tbef);
467 double t2 = file.Time(tbef + 1);
468 tprop.proportion = (time - t1) / (t2 - t1);
469 return tprop;
470 }
471
472 template <typename INT> void output_init(Exo_Read<INT> &file, int count, const char *prefix)
473 {
474 std::string cs_info{};
475 if (file.Num_Change_Sets() > 0) {
476 cs_info = fmt::format(" [Change Set {}: {}]", file.Get_Change_Set_Index() + 1,
477 file.Get_Change_Set_Name());
478 }
479 FileInfo fi(file.File_Name());
480 fmt::print(
481 "{0} FILE {19}: {1}{23}\n"
482 "{0} Title: {2}\n"
483 "{0} Dim = {3}, Nodes = {5}, Elements = {6}, Faces = {20}, Edges = {21}\n"
484 "{0} Element Blocks = {4}, Face Blocks = {10}, Edge Blocks = {9}, Nodesets = {7}, "
485 "Sidesets = {8}, Assemblies = {22}\n"
486 "{0} Vars: Global = {11}, Nodal = {12}, Element = {13}, Face = {17}, Edge = {18}, "
487 "Nodeset = {14}, Sideset = {15}, Times = {16}\n\n",
488 prefix, fi.realpath(), file.Title(), file.Dimension(), file.Num_Element_Blocks(),
489 file.Num_Nodes(), file.Num_Elements(), file.Num_Node_Sets(), file.Num_Side_Sets(),
490 file.Num_Edge_Blocks(), file.Num_Face_Blocks(), file.Num_Global_Vars(),
491 file.Num_Nodal_Vars(), file.Num_Element_Vars(), file.Num_NS_Vars(), file.Num_SS_Vars(),
492 file.Num_Times(), file.Num_FB_Vars(), file.Num_EB_Vars(), count, file.Num_Faces(),
493 file.Num_Edges(), file.Num_Assembly(), cs_info);
494 }
495
496 void initialize(std::vector<MinMaxData> &mm_entity, size_t size, const ToleranceType &ttype)
497 {
498 mm_entity.resize(size);
499 for (auto &mm : mm_entity) {
500 mm.type = ttype;
501 }
502 }
503
504 template <typename INT> bool exodiff(Exo_Read<INT> &file1, Exo_Read<INT> &file2);
505
506 template <typename INT>
507 std::pair<bool, bool> exodiff_setup(const std::string &file1_name, const std::string &file2_name,
508 INT /* dummy */)
509 {
510 // Open input files.
511 Exo_Read<INT> file1(file1_name);
512 file1.modify_time_values(interFace.time_value_scale, interFace.time_value_offset);
513
514 Exo_Read<INT> file2(file2_name);
515
516 auto [cs1, cs2] = create_change_set_list(file1, file2, interFace.change_sets);
517 SMART_ASSERT(cs1.size() == cs2.size());
518
519 bool has_change_sets = !cs1.empty() && (interFace.summary_flag || !cs2.empty());
520 interFace.has_change_sets = has_change_sets;
521 bool diff_flag = false;
522
523 if (has_change_sets) {
524 for (size_t i = 0; i < cs1.size(); i++) {
525 file1.Open_Change_Set(cs1[i] - 1);
526 if (!interFace.summary_flag) {
527 file2.Open_Change_Set(cs2[i] - 1);
528 }
529 diff_flag |= exodiff(file1, file2);
530 fmt::print("{:-<80}\n", "");
531 }
532 }
533 else {
534 file1.Get_Meta_Data();
535 if (!interFace.summary_flag) {
536 file2.Get_Meta_Data();
537 }
538 diff_flag |= exodiff(file1, file2);
539 }
540 file1.Close_File();
541 if (!interFace.summary_flag) {
542 file2.Close_File();
543 }
544 return std::make_pair(diff_flag, has_change_sets);
545 }
546 } // namespace
547
548 int main(int argc, char *argv[])
549 {
550 bool ok = interFace.parse_options(argc, argv);
551
552 if (!ok) {
553 exit(1);
554 }
555
556 checking_invalid = false;
557 invalid_data = false;
558
559 #if !defined(__ED_WINDOWS__)
560 sigfillset(&(sigact.sa_mask));
561 sigact.sa_handler = floating_point_exception_handler;
562 if (sigaction(SIGFPE, &sigact, nullptr) == -1) {
563 perror("sigaction failed");
564 }
565 #endif
566
567 #if defined(LINUX) && defined(GNU) && !defined(__ED_WINDOWS__)
568 // for GNU, this seems to be needed to turn on trapping
569 feenableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
570 #endif
571
572 std::string file1_name = interFace.file1;
573 std::string file2_name = interFace.file2;
574
575 if (interFace.summary_flag && file1_name.empty()) {
576 Error(fmt::format("Summary option specified but an exodus "
577 "file was not specified.\n"));
578 }
579
580 if (interFace.summary_flag) {
581 file2_name = "";
582 interFace.glob_var_do_all_flag = true;
583 interFace.node_var_do_all_flag = true;
584 interFace.elmt_var_do_all_flag = true;
585 interFace.elmt_att_do_all_flag = true;
586 interFace.ns_var_do_all_flag = true;
587 interFace.ss_var_do_all_flag = true;
588 interFace.eb_var_do_all_flag = true;
589 interFace.fb_var_do_all_flag = true;
590 interFace.map_flag = MapType::FILE_ORDER;
591 interFace.quiet_flag = false;
592 Print_Banner("#");
593 }
594
595 if (!interFace.quiet_flag && !interFace.summary_flag) {
596 Print_Banner(" ");
597 }
598
599 // Check integer sizes in input file(s)...
600 int int_size = 4;
601 if (interFace.ints_64_bits) {
602 int_size = 8;
603 }
604 else if (get_int_size(file1_name) == 8) {
605 int_size = 8;
606 }
607 else if (!interFace.summary_flag && get_int_size(file2_name) == 8) {
608 int_size = 8;
609 }
610
611 bool diff_flag = false;
612 bool has_change_sets = false;
613 if (int_size == 4) {
614 auto diff_change = exodiff_setup(file1_name, file2_name, int(0));
615 diff_flag = diff_change.first;
616 has_change_sets = diff_change.second;
617 }
618 else {
619 auto diff_change = exodiff_setup(file1_name, file2_name, int64_t(0));
620 diff_flag = diff_change.first;
621 has_change_sets = diff_change.second;
622 }
623
624 if (has_change_sets) {
625 if (diff_flag) {
626 DIFF_OUT("exodiff: At least one change set is different\n");
627 }
628 else {
629 DIFF_OUT("exodiff: All change sets are the same\n", fmt::color::green);
630 }
631 }
632 #if 0
633 add_to_log(argv[0], 0);
634 #else
635 // Temporarily differentiate this version from previous version in logs.
636 std::string code = "exodiff-" + version;
637 add_to_log(code.c_str(), 0);
638 #endif
639
640 if (interFace.exit_status_switch && diff_flag) {
641 return 2;
642 }
643
644 return 0;
645 }
646
647 namespace {
648 template <typename INT> bool exodiff(Exo_Read<INT> &file1, Exo_Read<INT> &file2)
649 {
650 if (!interFace.quiet_flag && !interFace.summary_flag) {
651 fmt::print("Reading first file ... \n");
652 }
653 // file1.Get_Meta_Data();
654 if (!interFace.summary_flag) {
655 if (!interFace.quiet_flag) {
656 fmt::print("Reading second file ... \n");
657 }
658 // file2.Get_Meta_Data();
659 }
660
661 if (interFace.summary_flag) {
662 output_init(file1, 1, "#");
663 }
664 else {
665 if (!interFace.quiet_flag) {
666 output_init(file1, 1, "");
667 output_init(file2, 2, "");
668 if (interFace.pedantic) {
669 fmt::print(" Pedantic Checking Enabled\n");
670 }
671 if (!interFace.command_file.empty()) {
672 FileInfo fi(interFace.command_file);
673 fmt::print(" COMMAND FILE: {}\n\n", fi.realpath());
674 }
675 }
676 }
677
678 if (!interFace.summary_flag) {
679 bool is_same = Check_Global(file1, file2);
680 if (!is_same) {
681 file1.Close_File();
682 file2.Close_File();
683 DIFF_OUT("\nexodiff: Files are different\n");
684 return interFace.exit_status_switch;
685 }
686 }
687
688 // When mapping is on ("-m"), node_map maps indexes from file1 to indexes
689 // into file2. Similarly with elmt_map.
690 std::vector<INT> node_map;
691 std::vector<INT> elmt_map;
692 if (interFace.map_flag == MapType::DISTANCE) {
693 Compute_Maps(node_map, elmt_map, file1, file2);
694 }
695 else if (interFace.map_flag == MapType::PARTIAL) {
696 // Same as distance, but ok if not all nodes/elements are matched
697 Compute_Partial_Maps(node_map, elmt_map, file1, file2);
698 }
699 else if (interFace.map_flag == MapType::USE_FILE_IDS) {
700 if (!interFace.ignore_maps) {
701 // Node/element X in file 1 matches node/element X in file 2 no matter what order they are
702 // in
703 Compute_FileId_Maps(node_map, elmt_map, file1, file2);
704 }
705 else {
706 size_t num_nodes = file1.Num_Nodes();
707 node_map.resize(num_nodes);
708 std::iota(node_map.begin(), node_map.end(), 0);
709
710 size_t num_elem = file1.Num_Elements();
711 elmt_map.resize(num_elem);
712 std::iota(elmt_map.begin(), elmt_map.end(), 0);
713 }
714 }
715 else if (interFace.map_flag == MapType::FILE_ORDER) {
716 // Match by implicit ordering... IDs in that ordering must match (checked later)
717 size_t num_nodes = file1.Num_Nodes();
718 node_map.resize(num_nodes);
719 std::iota(node_map.begin(), node_map.end(), 0);
720
721 size_t num_elem = file1.Num_Elements();
722 elmt_map.resize(num_elem);
723 std::iota(elmt_map.begin(), elmt_map.end(), 0);
724 }
725 else {
726 Error("Invalid map option.\n");
727 }
728
729 if (interFace.dump_mapping) {
730 Dump_Maps(node_map, elmt_map, file1);
731 }
732
733 bool diff_flag = false; // Set to 'true' to indicate files contain diffs
734 // Call this before checking for compatible meshes since it sets which variables
735 // are going to be compared. If no variables of a specific type, then not an error
736 // if the meshes are different in that type.
737 Build_Variable_Names(file1, file2, &diff_flag);
738
739 // Get node and element number maps which map internal implicit ids into
740 // global ids...
741 const INT *node_id_map = nullptr;
742 const INT *elem_id_map = nullptr;
743 if (!interFace.ignore_maps) {
744 file1.Load_Node_Map();
745 file1.Load_Element_Map();
746 node_id_map = file1.Get_Node_Map();
747 elem_id_map = file1.Get_Element_Map();
748 if (!interFace.summary_flag) {
749 bool diff =
750 Compare_Maps(file1, file2, node_map, elmt_map, interFace.map_flag == MapType::PARTIAL);
751 if (diff && (interFace.map_flag == MapType::FILE_ORDER)) {
752 fmt::print(stderr,
753 "exodiff: Exiting due to node/element mismatch with `-match_file_order` "
754 "option enabled.\n");
755 if (interFace.exit_status_switch) {
756 exit(2);
757 }
758 else {
759 exit(1);
760 }
761 }
762 }
763 }
764 else {
765 // Ignoring the maps from the file, so create a dummy
766 // map to make logic later in program consistent.
767 node_id_map = new INT[file1.Num_Nodes()];
768 INT *tmp_map = const_cast<INT *>(node_id_map);
769 std::iota(tmp_map, tmp_map + file1.Num_Nodes(), 1);
770
771 elem_id_map = new INT[file1.Num_Elements()];
772 tmp_map = const_cast<INT *>(elem_id_map);
773 std::iota(tmp_map, tmp_map + file1.Num_Elements(), 1);
774 }
775
776 int out_file_id = -1;
777 if (!interFace.summary_flag) {
778 std::string diffile_name = interFace.diff_file;
779 Check_Compatible_Meshes(file1, file2, (diffile_name.empty()), node_map, elmt_map,
780 node_id_map);
781 // Doesn't return if meshes are not compatible...
782
783 out_file_id = Create_File(file1, file2, diffile_name, &diff_flag);
784 }
785
786 SMART_ASSERT(!(interFace.summary_flag && out_file_id >= 0));
787
788 if (!interFace.quiet_flag || interFace.summary_flag) {
789 fmt::print("\n{0} NOTE: All node and element ids are reported as {1} ids.\n\n",
790 interFace.summary_flag ? "#" : " ", interFace.ignore_maps ? "local" : "global");
791 if (interFace.interpolating) {
792 fmt::print("{} NOTE: Interpolation mode is enabled.\n\n",
793 interFace.summary_flag ? "#" : " ");
794 }
795 }
796
797 std::vector<double> var_vals;
798 if (out_file_id >= 0) {
799 size_t max_ent = interFace.glob_var_names.size();
800 if (file1.Num_Nodes() > max_ent) {
801 max_ent = file1.Num_Nodes();
802 }
803 if (file1.Num_Elements() > max_ent) {
804 max_ent = file1.Num_Elements();
805 }
806 if (file1.Num_Faces() > max_ent) {
807 max_ent = file1.Num_Faces();
808 }
809 if (file1.Num_Edges() > max_ent) {
810 max_ent = file1.Num_Edges();
811 }
812
813 var_vals.resize(max_ent);
814 }
815
816 // When mapping is in effect, it is efficient to grab pointers to all blocks.
817 Exo_Block<INT> **blocks2 = nullptr;
818 if (!elmt_map.empty()) {
819 blocks2 = new Exo_Block<INT> *[file2.Num_Element_Blocks()];
820 for (size_t b = 0; b < file2.Num_Element_Blocks(); ++b) {
821 blocks2[b] = file2.Get_Element_Block_by_Index(b);
822 }
823 }
824
825 // Diff attributes...
826 if (!interFace.ignore_attributes && elmt_map.empty() && !interFace.summary_flag) {
827 if (diff_element_attributes(file1, file2, elmt_map, elem_id_map, blocks2)) {
828 diff_flag = true;
829 }
830 }
831
832 // Diff sideset distribution factors...
833 if (!interFace.ignore_sideset_df && !interFace.summary_flag) {
834 if (diff_sideset_df(file1, file2, elem_id_map)) {
835 diff_flag = true;
836 }
837 }
838
839 int min_num_times = file1.Num_Times();
840 int output_step = 1;
841
842 MinMaxData mm_time;
843 mm_time.type = ToleranceType::mm_time;
844 std::vector<MinMaxData> mm_glob;
845 std::vector<MinMaxData> mm_node;
846 std::vector<MinMaxData> mm_elmt;
847 std::vector<MinMaxData> mm_ns;
848 std::vector<MinMaxData> mm_ss;
849 std::vector<MinMaxData> mm_eb;
850 std::vector<MinMaxData> mm_fb;
851
852 if (interFace.summary_flag) {
853 initialize(mm_glob, interFace.glob_var_names.size(), ToleranceType::mm_global);
854 initialize(mm_node, interFace.node_var_names.size(), ToleranceType::mm_nodal);
855 initialize(mm_elmt, interFace.elmt_var_names.size(), ToleranceType::mm_element);
856 initialize(mm_ns, interFace.ns_var_names.size(), ToleranceType::mm_nodeset);
857 initialize(mm_ss, interFace.ss_var_names.size(), ToleranceType::mm_sideset);
858 initialize(mm_eb, interFace.eb_var_names.size(), ToleranceType::mm_edgeblock);
859 initialize(mm_fb, interFace.fb_var_names.size(), ToleranceType::mm_faceblock);
860 }
861 else {
862 min_num_times =
863 (file1.Num_Times() < file2.Num_Times() ? file1.Num_Times() : file2.Num_Times());
864
865 if (interFace.interpolating) {
866 min_num_times = file1.Num_Times();
867 }
868
869 if (interFace.time_step_stop > 0 && interFace.time_step_stop < min_num_times) {
870 min_num_times = interFace.time_step_stop;
871 }
872 }
873
874 // If explicit times are set, then only want to diff a single time at those
875 // specified times....
876 if (interFace.explicit_steps.first != 0 && interFace.explicit_steps.second != 0) {
877 int ts1 = interFace.explicit_steps.first;
878 if (ts1 == -1) {
879 ts1 = file1.Num_Times();
880 }
881 int ts2 = interFace.explicit_steps.second;
882 if (ts2 == -1) {
883 ts2 = file2.Num_Times();
884 }
885 TimeInterp t2;
886 t2.step1 = ts2;
887 t2.step2 = ts2;
888 t2.time = file2.Time(ts2);
889 t2.proportion = 0.0;
890
891 if (!interFace.quiet_flag) {
892 if (out_file_id >= 0) {
893 fmt::print("Processing explicit time steps. File 1 step = {} File 2 step = {}\n", ts1,
894 ts2);
895 }
896 else {
897 std::string buf =
898 fmt::format(" --------- Explicit Time step File 1: {}, {:13.7e} ~ File 2: {}, "
899 "{:13.7e} ---------",
900 ts1, file1.Time(ts1), ts2, t2.time);
901 DIFF_OUT(buf, fmt::color::green);
902 }
903 }
904
905 if (interFace.summary_flag) {
906 do_summaries(file1, ts1, mm_glob, mm_node, mm_elmt, mm_ns, mm_ss, mm_eb, mm_fb, elmt_map,
907 &diff_flag);
908 }
909 else {
910 do_diffs(file1, file2, ts1, t2, out_file_id, output_step, node_map, node_id_map, elmt_map,
911 elem_id_map, blocks2, var_vals, &diff_flag);
912 }
913 }
914 else {
915
916 // If time_step_offset == -1, then determine the offset automatically.
917 // Assumes file1 has more steps than file2 and that the last step(s)
918 // on file2 match the last step(s) on file1.
919 if (interFace.time_step_offset == -1) {
920 interFace.time_step_offset = file1.Num_Times() - file2.Num_Times();
921 if (interFace.time_step_offset < 0) {
922 Error("Second database must have less timesteps than "
923 "first database.\n");
924 }
925 }
926
927 // If time_step_offset == -2, then determine the offset automatically.
928 // Find the closest time on file1 to the first time on file2.
929 // Assumes file1 has more steps than file2.
930 if (interFace.time_step_offset == -2) {
931 if (file1.Num_Times() < file2.Num_Times()) {
932 Error("Second database must have less timesteps than "
933 "first database.\n");
934 }
935
936 double t2 = file2.Time(1);
937 double mindiff = fabs(t2 - file1.Time(1));
938 int step = 1;
939 for (int i = 2; i < file1.Num_Times(); i++) {
940 double t1 = file1.Time(i);
941 double diff = fabs(t2 - t1);
942 if (diff < mindiff) {
943 step = i;
944 mindiff = diff;
945 }
946 }
947 interFace.time_step_offset = step - 1;
948 }
949
950 if (interFace.time_step_offset > 0) {
951 if (interFace.time_step_start > 0) {
952 fmt::print(
953 "The first {} timesteps in the first database will be skipped because of time step "
954 "offset and time step start settings.\n\n",
955 interFace.time_step_offset + interFace.time_step_start - 1);
956 }
957 else {
958 fmt::print(
959 "The first {} timesteps in the first database will be skipped because of time step "
960 "offset setting.\n\n",
961 interFace.time_step_offset);
962 }
963 }
964
965 if (interFace.time_step_start == -1) {
966 // Want to compare the last timestep on both databases...
967 int time_step1 = file1.Num_Times();
968 int time_step2 = file2.Num_Times();
969 interFace.time_step_start = time_step2;
970 interFace.time_step_offset = time_step1 - time_step2;
971 min_num_times = interFace.time_step_start;
972 fmt::print("Comparing only the final step (step {} on first, step {}"
973 " on second) on each database.\n\n",
974 time_step1, time_step2);
975 }
976 else if (interFace.time_step_start < 0) {
977 interFace.time_step_start = min_num_times;
978 }
979 else if (interFace.time_step_start < 1) {
980 interFace.time_step_start = 1;
981 }
982
983 if (interFace.time_step_start > min_num_times && min_num_times > 0) {
984 Warning("Time step options resulted in no timesteps being compared.\n");
985 diff_flag = true;
986 }
987
988 for (int time_step = interFace.time_step_start; time_step <= min_num_times;
989 time_step += interFace.time_step_increment) {
990 if (timeStepIsExcluded(time_step) || interFace.ignore_steps) {
991 continue;
992 }
993
994 int time_step1 = time_step + interFace.time_step_offset;
995 int time_step2 = time_step;
996 SMART_ASSERT(time_step1 <= file1.Num_Times());
997
998 TimeInterp t2;
999 if (!interFace.summary_flag) {
1000 t2 = get_surrounding_times(file1.Time(time_step1), file2);
1001 if (!interFace.interpolating) {
1002 t2.step1 = time_step2;
1003 t2.step2 = time_step2;
1004 t2.time = file2.Time(time_step2);
1005 t2.proportion = 0.0;
1006 }
1007 SMART_ASSERT(t2.step1 <= file2.Num_Times());
1008 SMART_ASSERT(t2.step2 <= file2.Num_Times());
1009 }
1010
1011 if (interFace.summary_flag) {
1012 double t = file1.Time(time_step1);
1013 mm_time.spec_min_max(t, time_step1);
1014 }
1015 else if (out_file_id >= 0 && !interFace.quiet_flag) {
1016 fmt::print("Processing time step {} (Difference in time values = {})\n", time_step1,
1017 (file1.Time(time_step1) - file2.Time(time_step2)));
1018 }
1019 else if (out_file_id < 0) {
1020 if (!interFace.quiet_flag) {
1021 std::string buf;
1022 if (interFace.interpolating) {
1023 if (t2.step1 == -1) {
1024 buf = fmt::format(
1025 " --------- Time step {}, {:13.7e} ~ Skipping - Before all times on "
1026 "file2 (INTERPOLATING)",
1027 time_step1, file1.Time(time_step1));
1028 }
1029 else if (t2.step2 == -1) {
1030 buf = fmt::format(
1031 " --------- Time step {}, {:13.7e} ~ Skipping - After all times on "
1032 "file2 (INTERPOLATING)",
1033 time_step1, file1.Time(time_step1));
1034 }
1035 else if (t2.step1 == t2.step2) {
1036 buf = fmt::format(
1037 " --------- Time step {}, {:13.7e} ~ Matches step {}, {:13.7e} on file2 "
1038 "{} diff: {:12.5e}",
1039 time_step1, file1.Time(time_step1), t2.step1, file2.Time(t2.step1),
1040 interFace.time_tol.abrstr(),
1041 FileDiff(file1.Time(time_step1), file2.Time(t2.step1),
1042 interFace.time_tol.type));
1043 }
1044 else {
1045 buf = fmt::format(
1046 " --------- Time step {}, {:13.7e} ~ Interpolating step {}, {:13.7e} and "
1047 "step {}, {:13.7e}, proportion {:10.4e} on file2",
1048 time_step1, file1.Time(time_step1), t2.step1, file2.Time(t2.step1), t2.step2,
1049 file2.Time(t2.step2), t2.proportion);
1050 }
1051 }
1052 else {
1053 buf = fmt::format(" --------- Time step {}, {:13.7e} ~ {:13.7e}, {} diff: {:12.5e}",
1054 time_step1, file1.Time(time_step1), file2.Time(time_step2),
1055 interFace.time_tol.abrstr(),
1056 FileDiff(file1.Time(time_step1), file2.Time(time_step2),
1057 interFace.time_tol.type));
1058 }
1059 fmt::print("{}", buf);
1060 }
1061
1062 if (!interFace.interpolating &&
1063 interFace.time_tol.Diff(file1.Time(time_step1), file2.Time(time_step2))) {
1064 diff_flag = true;
1065 if (interFace.quiet_flag) {
1066 Die_TS(time_step1);
1067 }
1068 else {
1069 DIFF_OUT(" (FAILED) \n");
1070 }
1071 }
1072 else if (!interFace.quiet_flag) {
1073 fmt::print(" ---------\n");
1074 }
1075 if (interFace.interpolating && time_step == min_num_times) {
1076 // last time. Check if final database times match within specified tolerance...
1077 int final2 = file2.Num_Times();
1078 if (interFace.final_time_tol.Diff(file1.Time(time_step1), file2.Time(final2))) {
1079 diff_flag = true;
1080 std::ostringstream diff;
1081 fmt::print(diff,
1082 "\tFinal database times differ by {} which is not within specified {}"
1083 " tolerance of {} (FAILED)",
1084 FileDiff(file1.Time(time_step1), file2.Time(final2),
1085 interFace.final_time_tol.type),
1086 interFace.final_time_tol.typestr(), interFace.final_time_tol.value);
1087 DIFF_OUT(diff);
1088 }
1089 }
1090 }
1091
1092 if (out_file_id >= 0) {
1093 double t = file1.Time(time_step1);
1094 ex_put_time(out_file_id, output_step, &t);
1095 }
1096
1097 if (interFace.interpolating && (t2.step1 == -1 || t2.step2 == -1)) {
1098 continue;
1099 }
1100
1101 if (interFace.summary_flag) {
1102 do_summaries(file1, time_step1, mm_glob, mm_node, mm_elmt, mm_ns, mm_ss, mm_eb, mm_fb,
1103 elmt_map, &diff_flag);
1104 }
1105 else {
1106 do_diffs(file1, file2, time_step1, t2, out_file_id, output_step, node_map, node_id_map,
1107 elmt_map, elem_id_map, blocks2, var_vals, &diff_flag);
1108 }
1109
1110 output_step++;
1111 } // End of time step loop.
1112
1113 // Make sure there is an operation to perform (compare times, variables, ...)
1114 if (!interFace.ignore_steps) {
1115 if ((min_num_times == 0 && interFace.coord_tol.type == ToleranceMode::IGNORE_) ||
1116 (min_num_times > 0 && interFace.time_tol.type == ToleranceMode::IGNORE_ &&
1117 interFace.glob_var_names.empty() && interFace.node_var_names.empty() &&
1118 interFace.elmt_var_names.empty() && interFace.elmt_att_names.empty() &&
1119 interFace.ns_var_names.empty() && interFace.ss_var_names.empty() &&
1120 interFace.eb_var_names.empty() && interFace.fb_var_names.empty())) {
1121 DIFF_OUT("\nWARNING: No comparisons were performed during this execution.");
1122 diff_flag = true;
1123 }
1124 }
1125 }
1126
1127 if (interFace.summary_flag) {
1128 output_summary(file1, mm_time, mm_glob, mm_node, mm_elmt, mm_ns, mm_ss, mm_eb, mm_fb,
1129 node_id_map, elem_id_map);
1130 }
1131 else if (out_file_id >= 0) {
1132 ex_close(out_file_id);
1133 }
1134 else if (diff_flag) {
1135 DIFF_OUT("\nexodiff: Files are different\n");
1136 }
1137 else if (interFace.ignore_steps && (file1.Num_Times() != 0 || file2.Num_Times() != 0)) {
1138 DIFF_OUT("\nexodiff: Files are the same, but all transient data was ignored due to "
1139 "-ignore_steps option",
1140 fmt::color::green);
1141 }
1142 else if (file1.Num_Times() != file2.Num_Times()) {
1143 if ((file1.Num_Times() - interFace.time_step_offset == file2.Num_Times()) ||
1144 (interFace.time_step_stop > 0) ||
1145 (interFace.explicit_steps.first != 0 && interFace.explicit_steps.second != 0) ||
1146 (interFace.interpolating)) {
1147 std::ostringstream diff;
1148 fmt::print(diff, "\nexodiff: Files are the same\n"
1149 " The number of timesteps are different but "
1150 "the timesteps that were compared are the same.\n");
1151 DIFF_OUT(diff);
1152 }
1153 else {
1154 DIFF_OUT("\nexodiff: Files are different (# time steps differ)");
1155 diff_flag = true;
1156 }
1157 }
1158 else if (interFace.map_flag == MapType::PARTIAL) {
1159 DIFF_OUT("\nexodiff: Files are the same (partial match selected)\n", fmt::color::green);
1160 }
1161 else {
1162 DIFF_OUT("\nexodiff: Files are the same\n", fmt::color::green);
1163 }
1164
1165 if (!interFace.ignore_maps) {
1166 file1.Free_Node_Map();
1167 file1.Free_Element_Map();
1168 }
1169 else {
1170 delete[] node_id_map;
1171 delete[] elem_id_map;
1172 }
1173
1174 delete[] blocks2;
1175
1176 return diff_flag;
1177 }
1178 } // namespace
1179 double FileDiff(double v1, double v2, ToleranceMode type)
1180 {
1181 if (type == ToleranceMode::IGNORE_) { // ignore
1182 return 0.0;
1183 }
1184 if (type == ToleranceMode::RELATIVE_) { // relative diff
1185 if (v1 == 0.0 && v2 == 0.0) {
1186 return 0.0;
1187 }
1188 double max = fabs(v1) < fabs(v2) ? fabs(v2) : fabs(v1);
1189 return (v1 - v2) / max;
1190 }
1191 if (type == ToleranceMode::COMBINED_) {
1192 // if (Abs(x - y) <= Max(absTol, relTol * Max(Abs(x), Abs(y))))
1193 // In the current implementation, absTol == relTol;
1194 // In summary, use abs tolerance if both values are less than 1.0;
1195 // else use relative tolerance.
1196
1197 double max = fabs(v1) < fabs(v2) ? fabs(v2) : fabs(v1);
1198 double tol = 1.0 < max ? max : 1.0;
1199 return fabs(v1 - v2) / tol;
1200 }
1201 if (type == ToleranceMode::ABSOLUTE_) {
1202 return (v1 - v2);
1203 }
1204 if (type == ToleranceMode::EIGEN_REL_) { // relative diff
1205 if (v1 == 0.0 && v2 == 0.0) {
1206 return 0.0;
1207 }
1208 double max = fabs(v1) < fabs(v2) ? fabs(v2) : fabs(v1);
1209 return (fabs(v1) - fabs(v2)) / max;
1210 }
1211 if (type == ToleranceMode::EIGEN_COM_) {
1212 // if (Abs(x - y) <= Max(absTol, relTol * Max(Abs(x), Abs(y))))
1213 // In the current implementation, absTol == relTol;
1214 // In summary, use abs tolerance if both values are less than 1.0;
1215 // else use relative tolerance.
1216
1217 double max = fabs(v1) < fabs(v2) ? fabs(v2) : fabs(v1);
1218 double tol = 1.0 < max ? max : 1.0;
1219 return fabs(fabs(v1) - fabs(v2)) / tol;
1220 }
1221 if (type == ToleranceMode::EIGEN_ABS_) {
1222 return (fabs(v1) - fabs(v2));
1223 }
1224 return 0.0;
1225 }
1226
1227 void Die_TS(double ts)
1228 {
1229 std::ostringstream diff;
1230 fmt::print(diff, "exodiff: Files are different (time step {})", ts);
1231 DIFF_OUT(diff);
1232 if (interFace.exit_status_switch) {
1233 exit(2);
1234 }
1235 else {
1236 exit(1);
1237 }
1238 }
1239
1240 template <typename INT> size_t global_elmt_num(Exo_Read<INT> &file, size_t b_idx, size_t e_idx)
1241 {
1242 SMART_ASSERT(b_idx < file.Num_Element_Blocks());
1243
1244 size_t g = 0;
1245 for (size_t b = 0; b < file.Num_Element_Blocks(); ++b) {
1246 if (b_idx == b) {
1247 return g + e_idx + 1;
1248 }
1249
1250 SMART_ASSERT(file.Get_Element_Block_by_Index(b) != 0);
1251 g += file.Get_Element_Block_by_Index(b)->Size();
1252 }
1253 SMART_ASSERT(0);
1254 return 0;
1255 }
1256
1257 bool Invalid_Values(const double *values, size_t count)
1258 {
1259 bool valid = true;
1260 if (!interFace.ignore_nans) {
1261 checking_invalid = true;
1262 invalid_data = false;
1263
1264 SMART_ASSERT(values != nullptr);
1265
1266 for (size_t i = 0; i < count; i++) {
1267 #if defined(interix)
1268 if (values[i] != values[i])
1269 #else
1270 if (std::isnan(values[i]))
1271 #endif
1272 {
1273 valid = false;
1274 break;
1275 }
1276 if (invalid_data) { // may get set by SIGFPE handler
1277 valid = false;
1278 break;
1279 }
1280 }
1281
1282 checking_invalid = false;
1283 invalid_data = false;
1284 }
1285 return !valid;
1286 }
1287
1288 bool Equal_Values(const double *values, size_t count, double *value)
1289 {
1290 SMART_ASSERT(values != nullptr);
1291 *value = values[0];
1292 return (std::adjacent_find(values, values + count, std::not_equal_to<>()) == values + count);
1293 }
1294
1295 template <typename INT>
1296 const double *get_nodal_values(Exo_Read<INT> &filen, int time_step, size_t idx, int fno,
1297 const std::string &name, bool *diff_flag)
1298 {
1299 const double *vals = nullptr;
1300 if (fno == 1 || !interFace.summary_flag) {
1301 filen.Load_Nodal_Results(time_step, idx);
1302 vals = filen.Get_Nodal_Results(idx);
1303
1304 if (vals != nullptr) {
1305 if (Invalid_Values(vals, filen.Num_Nodes())) {
1306 Warning(fmt::format("NaN found for nodal variable '{}' in file {}\n", name, fno));
1307 *diff_flag = true;
1308 }
1309 }
1310 }
1311 return vals;
1312 }
1313
1314 template <typename INT>
1315 const double *get_nodal_values(Exo_Read<INT> &filen, const TimeInterp &t, size_t idx, int fno,
1316 const std::string &name, bool *diff_flag)
1317 {
1318 const double *vals = nullptr;
1319 if (fno == 1 || !interFace.summary_flag) {
1320 vals = filen.Get_Nodal_Results(t.step1, t.step2, t.proportion, idx);
1321
1322 if (vals != nullptr) {
1323 if (Invalid_Values(vals, filen.Num_Nodes())) {
1324 Warning(fmt::format("NaN found for nodal variable '{}' in file {}\n", name, fno));
1325 *diff_flag = true;
1326 }
1327 }
1328 }
1329 return vals;
1330 }
1331
1332 template <typename INT>
1333 bool summarize_globals(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_glob)
1334 {
1335 bool diff_flag = false;
1336 if (interFace.glob_var_names.empty()) {
1337 return diff_flag;
1338 }
1339
1340 // Global variables.
1341 file.Load_Global_Results(step);
1342 const double *vals = file.Get_Global_Results();
1343 if (vals == nullptr) {
1344 Error("Could not find global variables on file 1.\n");
1345 }
1346
1347 for (unsigned out_idx = 0; out_idx < interFace.glob_var_names.size(); ++out_idx) {
1348 const std::string &name = (interFace.glob_var_names)[out_idx];
1349 int idx = find_string(file.Global_Var_Names(), name, interFace.nocase_var_names);
1350 if (idx < 0) {
1351 Error(fmt::format("Unable to find global variable named '{}' on database.\n", name));
1352 }
1353 mm_glob[out_idx].spec_min_max(vals[idx], step);
1354 }
1355 return diff_flag;
1356 }
1357
1358 template <typename INT>
1359 bool summarize_nodals(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_node)
1360 {
1361 bool diff_flag = false;
1362 for (unsigned n_idx = 0; n_idx < interFace.node_var_names.size(); ++n_idx) {
1363 const std::string &name = (interFace.node_var_names)[n_idx];
1364 int idx = find_string(file.Nodal_Var_Names(), name, interFace.nocase_var_names);
1365 if (idx < 0) {
1366 Error(fmt::format("Unable to find nodal variable named '{}' on database.\n", name));
1367 }
1368 const double *vals = get_nodal_values(file, step, idx, 1, name, &diff_flag);
1369
1370 if (vals == nullptr) {
1371 Error("Could not find nodal variables on file 1\n");
1372 }
1373
1374 size_t ncount = file.Num_Nodes();
1375 for (size_t n = 0; n < ncount; ++n) {
1376 mm_node[n_idx].spec_min_max(vals[n], step, n);
1377 }
1378 file.Free_Nodal_Results(idx);
1379 }
1380 file.Free_Nodal_Results();
1381 return diff_flag;
1382 }
1383
1384 const double *get_validated_variable(Exo_Entity *entity, int step, int vidx,
1385 const std::string &name, bool *diff_flag)
1386 {
1387 if (entity->Size() == 0) {
1388 return nullptr;
1389 }
1390 if (!entity->is_valid_var(vidx)) {
1391 return nullptr;
1392 }
1393
1394 entity->Load_Results(step, vidx);
1395 const double *vals = entity->Get_Results(vidx);
1396 if (vals == nullptr) {
1397 Warning(fmt::format("Could not find variable '{}' in {} {}, file 1.\n", name,
1398 entity->short_label(), entity->Id()));
1399 *diff_flag = true;
1400 return vals;
1401 }
1402
1403 if (Invalid_Values(vals, entity->Size())) {
1404 Warning(fmt::format("NaN found for variable '{}' in {} {}, file 1\n", name,
1405 entity->short_label(), entity->Id()));
1406 *diff_flag = true;
1407 }
1408 return vals;
1409 }
1410
1411 const double *get_validated_variable(Exo_Entity *entity, const TimeInterp &t2, int vidx,
1412 const std::string &name, bool *diff_flag)
1413 {
1414 if (entity == nullptr) {
1415 return nullptr;
1416 }
1417 if (entity->Size() == 0) {
1418 return nullptr;
1419 }
1420 if (!entity->is_valid_var(vidx)) {
1421 return nullptr;
1422 }
1423
1424 entity->Load_Results(t2.step1, t2.step2, t2.proportion, vidx);
1425 const double *vals = entity->Get_Results(vidx);
1426 if (vals == nullptr) {
1427 Warning(fmt::format("Could not find variable '{}' in {} {}, file 2.\n", name,
1428 entity->short_label(), entity->Id()));
1429 *diff_flag = true;
1430 return vals;
1431 }
1432
1433 if (Invalid_Values(vals, entity->Size())) {
1434 Warning(fmt::format("NaN found for variable '{}' in {} {}, file 2.\n", name,
1435 entity->short_label(), entity->Id()));
1436 *diff_flag = true;
1437 }
1438 return vals;
1439 }
1440
1441 template <typename INT>
1442 bool summarize_element(Exo_Read<INT> &file, int step, const std::vector<INT> &elmt_map,
1443 std::vector<MinMaxData> &mm_elmt)
1444 {
1445 bool diff_flag = false;
1446
1447 for (unsigned e_idx = 0; e_idx < interFace.elmt_var_names.size(); ++e_idx) {
1448 const std::string &name = (interFace.elmt_var_names)[e_idx];
1449 int vidx = find_string(file.Element_Var_Names(), name, interFace.nocase_var_names);
1450 if (vidx < 0) {
1451 Error(fmt::format("Unable to find element variable named '{}' on database.\n", name));
1452 }
1453
1454 size_t global_elmt_index = 0;
1455 for (size_t b = 0; b < file.Num_Element_Blocks(); ++b) {
1456 Exo_Block<INT> *eblock = file.Get_Element_Block_by_Index(b);
1457 const double *vals = get_validated_variable(eblock, step, vidx, name, &diff_flag);
1458 if (vals == nullptr) {
1459 global_elmt_index += eblock->Size();
1460 continue;
1461 }
1462
1463 size_t ecount = eblock->Size();
1464 for (size_t e = 0; e < ecount; ++e) {
1465 INT el_flag = 1;
1466 if (!elmt_map.empty()) {
1467 el_flag = elmt_map[global_elmt_index];
1468 }
1469
1470 if (el_flag >= 0) {
1471 mm_elmt[e_idx].spec_min_max(vals[e], step, global_elmt_index, eblock->Id());
1472 }
1473 ++global_elmt_index;
1474 }
1475
1476 eblock->Free_Results();
1477 }
1478 }
1479 return diff_flag;
1480 }
1481
1482 template <typename INT>
1483 bool summarize_nodeset(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_ns)
1484 {
1485 bool diff_flag = false;
1486 for (unsigned e_idx = 0; e_idx < interFace.ns_var_names.size(); ++e_idx) {
1487 const std::string &name = (interFace.ns_var_names)[e_idx];
1488 int vidx = find_string(file.NS_Var_Names(), name, interFace.nocase_var_names);
1489 if (vidx < 0) {
1490 Error(fmt::format("Unable to find nodeset variable named '{}' on database.\n", name));
1491 }
1492
1493 for (size_t b = 0; b < file.Num_Node_Sets(); ++b) {
1494 Node_Set<INT> *nset = file.Get_Node_Set_by_Index(b);
1495
1496 const double *vals = get_validated_variable(nset, step, vidx, name, &diff_flag);
1497 if (vals == nullptr) {
1498 continue;
1499 }
1500
1501 size_t ncount = nset->Size();
1502 for (size_t e = 0; e < ncount; ++e) {
1503 int idx = nset->Node_Index(e);
1504 mm_ns[e_idx].spec_min_max(vals[idx], step, e, nset->Id());
1505 }
1506 nset->Free_Results();
1507 }
1508 }
1509 return diff_flag;
1510 }
1511
1512 template <typename INT>
1513 bool summarize_sideset(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_ss)
1514 {
1515 bool diff_flag = false;
1516 for (unsigned e_idx = 0; e_idx < interFace.ss_var_names.size(); ++e_idx) {
1517 const std::string &name = (interFace.ss_var_names)[e_idx];
1518 int vidx = find_string(file.SS_Var_Names(), name, interFace.nocase_var_names);
1519 if (vidx < 0) {
1520 Error(fmt::format("Unable to find sideset variable named '{}' on database.\n", name));
1521 }
1522
1523 for (size_t b = 0; b < file.Num_Side_Sets(); ++b) {
1524 Side_Set<INT> *sset = file.Get_Side_Set_by_Index(b);
1525
1526 const double *vals = get_validated_variable(sset, step, vidx, name, &diff_flag);
1527 if (vals == nullptr) {
1528 continue;
1529 }
1530
1531 size_t ecount = sset->Size();
1532 for (size_t e = 0; e < ecount; ++e) {
1533 size_t ind = sset->Side_Index(e);
1534 mm_ss[e_idx].spec_min_max(vals[ind], step, e, sset->Id());
1535 }
1536 sset->Free_Results();
1537 }
1538 }
1539 return diff_flag;
1540 }
1541
1542 template <typename INT>
1543 bool summarize_edgeblock(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_eb)
1544 {
1545 bool diff_flag = false;
1546 for (unsigned e_idx = 0; e_idx < interFace.eb_var_names.size(); ++e_idx) {
1547 const std::string &name = (interFace.eb_var_names)[e_idx];
1548 int vidx = find_string(file.EB_Var_Names(), name, interFace.nocase_var_names);
1549 if (vidx < 0) {
1550 Error(fmt::format("Unable to find edge block variable named '{}' on database.\n", name));
1551 }
1552
1553 for (size_t b = 0; b < file.Num_Edge_Blocks(); ++b) {
1554 Edge_Block<INT> *eblock = file.Get_Edge_Block_by_Index(b);
1555
1556 const double *vals = get_validated_variable(eblock, step, vidx, name, &diff_flag);
1557 if (vals == nullptr) {
1558 continue;
1559 }
1560
1561 size_t ecount = eblock->Size();
1562 for (size_t e = 0; e < ecount; ++e) {
1563 size_t ind = eblock->Edge_Index(e);
1564 mm_eb[e_idx].spec_min_max(vals[ind], step, e, eblock->Id());
1565 }
1566
1567 eblock->Free_Results();
1568 }
1569 }
1570 return diff_flag;
1571 }
1572
1573 template <typename INT>
1574 bool summarize_faceblock(Exo_Read<INT> &file, int step, std::vector<MinMaxData> &mm_fb)
1575 {
1576 bool diff_flag = false;
1577 for (unsigned f_idx = 0; f_idx < interFace.fb_var_names.size(); ++f_idx) {
1578 const std::string &name = (interFace.fb_var_names)[f_idx];
1579 int vidx = find_string(file.FB_Var_Names(), name, interFace.nocase_var_names);
1580 if (vidx < 0) {
1581 Error(fmt::format("Unable to find face block variable named '{}' on database.\n", name));
1582 }
1583
1584 for (size_t b = 0; b < file.Num_Face_Blocks(); ++b) {
1585 Face_Block<INT> *fblock = file.Get_Face_Block_by_Index(b);
1586
1587 const double *vals = get_validated_variable(fblock, step, vidx, name, &diff_flag);
1588 if (vals == nullptr) {
1589 continue;
1590 }
1591
1592 size_t fcount = fblock->Size();
1593 for (size_t f = 0; f < fcount; ++f) {
1594 size_t ind = fblock->Face_Index(f);
1595 mm_fb[f_idx].spec_min_max(vals[ind], step, f, fblock->Id());
1596 }
1597
1598 fblock->Free_Results();
1599 }
1600 }
1601 return diff_flag;
1602 }
1603
1604 template <typename INT>
1605 void do_diffs(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int time_step1, const TimeInterp &t2,
1606 int out_file_id, int output_step, const std::vector<INT> &node_map,
1607 const INT *node_id_map, const std::vector<INT> &elmt_map, const INT *elem_id_map,
1608 Exo_Block<INT> **blocks2, std::vector<double> &var_vals, bool *diff_flag)
1609 {
1610 SMART_ASSERT(!interFace.summary_flag);
1611 if (diff_globals(file1, file2, time_step1, t2, out_file_id, output_step, var_vals)) {
1612 *diff_flag = true;
1613 }
1614
1615 // Nodal variables.
1616 if (diff_nodals(file1, file2, time_step1, t2, out_file_id, output_step, node_map, node_id_map,
1617 var_vals)) {
1618 *diff_flag = true;
1619 }
1620
1621 // Element variables.
1622 if (diff_element(file1, file2, time_step1, t2, out_file_id, output_step, elmt_map, elem_id_map,
1623 blocks2, var_vals)) {
1624 *diff_flag = true;
1625 }
1626
1627 if (interFace.map_flag != MapType::PARTIAL) {
1628 // Nodeset variables.
1629 if (diff_nodeset(file1, file2, time_step1, t2, out_file_id, output_step, node_id_map,
1630 var_vals)) {
1631 *diff_flag = true;
1632 }
1633
1634 // Sideset variables.
1635 if (diff_sideset(file1, file2, time_step1, t2, out_file_id, output_step, elem_id_map,
1636 var_vals)) {
1637 *diff_flag = true;
1638 }
1639
1640 // Edge Block variables.
1641 if (diff_edgeblock(file1, file2, time_step1, t2, out_file_id, output_step, elem_id_map,
1642 var_vals)) {
1643 *diff_flag = true;
1644 }
1645
1646 // Face Block variables.
1647 if (diff_faceblock(file1, file2, time_step1, t2, out_file_id, output_step, elem_id_map,
1648 var_vals)) {
1649 *diff_flag = true;
1650 }
1651 }
1652 else {
1653 if (!interFace.ns_var_names.empty() || !interFace.ss_var_names.empty() ||
1654 !interFace.eb_var_names.empty() || !interFace.fb_var_names.empty()) {
1655 fmt::print("WARNING: nodeset, sideset, edge block and face block variables not (yet) "
1656 "compared for partial map\n");
1657 }
1658 }
1659 }
1660
1661 template <typename INT>
1662 void do_summaries(Exo_Read<INT> &file, int time_step, std::vector<MinMaxData> &mm_glob,
1663 std::vector<MinMaxData> &mm_node, std::vector<MinMaxData> &mm_elmt,
1664 std::vector<MinMaxData> &mm_ns, std::vector<MinMaxData> &mm_ss,
1665 std::vector<MinMaxData> &mm_eb, std::vector<MinMaxData> &mm_fb,
1666 const std::vector<INT> &elmt_map, bool *diff_flag)
1667 {
1668 SMART_ASSERT(interFace.summary_flag);
1669 if (summarize_globals(file, time_step, mm_glob)) {
1670 *diff_flag = true;
1671 }
1672 if (summarize_nodals(file, time_step, mm_node)) {
1673 *diff_flag = true;
1674 }
1675 if (summarize_element(file, time_step, elmt_map, mm_elmt)) {
1676 *diff_flag = true;
1677 }
1678 if (summarize_nodeset(file, time_step, mm_ns)) {
1679 *diff_flag = true;
1680 }
1681 if (summarize_sideset(file, time_step, mm_ss)) {
1682 *diff_flag = true;
1683 }
1684 if (summarize_edgeblock(file, time_step, mm_eb)) {
1685 *diff_flag = true;
1686 }
1687 if (summarize_faceblock(file, time_step, mm_fb)) {
1688 *diff_flag = true;
1689 }
1690 }
1691
1692 void output_norms(Norm &norm, const std::string &name)
1693 {
1694 if (interFace.doL1Norm && norm.diff(1) > 0.0) {
1695 std::string buf =
1696 fmt::format(" {:<{}} L1 norm of diff={:14.7e} ({:11.5e} ~ {:11.5e}) rel={:14.7e}", name,
1697 name_length(), norm.diff(1), norm.left(1), norm.right(1), norm.relative(1));
1698 DIFF_OUT(buf, fmt::color::green);
1699 }
1700 if (interFace.doL2Norm && norm.diff(2) > 0.0) {
1701 std::string buf =
1702 fmt::format(" {:<{}} L2 norm of diff={:14.7e} ({:11.5e} ~ {:11.5e}) rel={:14.7e}", name,
1703 name_length(), norm.diff(2), norm.left(2), norm.right(2), norm.relative(2));
1704 DIFF_OUT(buf, fmt::color::green);
1705 }
1706 }
1707
1708 template <typename INT>
1709 bool diff_globals(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
1710 int out_file_id, int output_step, std::vector<double> &gvals)
1711 {
1712 bool diff_flag = false;
1713 if (interFace.glob_var_names.empty()) {
1714 return diff_flag;
1715 }
1716
1717 // Global variables.
1718 file1.Load_Global_Results(step1);
1719 const double *vals1 = file1.Get_Global_Results();
1720 if (vals1 == nullptr) {
1721 Error("Could not find global variables on file 1.\n");
1722 }
1723
1724 file2.Load_Global_Results(t2.step1, t2.step2, t2.proportion);
1725 const double *vals2 = file2.Get_Global_Results();
1726 if (vals2 == nullptr) {
1727 Error("Could not find global variables on file 2.\n");
1728 }
1729
1730 // ----------------------------------------------------------------------
1731 // Output file containing differences...
1732 if (out_file_id >= 0) {
1733 SMART_ASSERT(!gvals.empty());
1734 for (unsigned out_idx = 0; out_idx < interFace.glob_var_names.size(); ++out_idx) {
1735 const std::string &name = (interFace.glob_var_names)[out_idx];
1736 int idx1 = find_string(file1.Global_Var_Names(), name, interFace.nocase_var_names);
1737 int idx2 = find_string(file2.Global_Var_Names(), name, interFace.nocase_var_names);
1738 if (idx1 < 0 || idx2 < 0) {
1739 Error(fmt::format("Unable to find global variable named '{}' on database.\n", name));
1740 }
1741 gvals[out_idx] = FileDiff(vals1[idx1], vals2[idx2], interFace.output_type);
1742 }
1743 ex_put_var(out_file_id, output_step, EX_GLOBAL, 1, 0, interFace.glob_var_names.size(),
1744 Data(gvals));
1745 return diff_flag;
1746 }
1747
1748 // -------------------------------------------------------------------
1749 // Determine if any diffs and output to terminal
1750 if (!interFace.quiet_flag && !interFace.glob_var_names.empty()) {
1751 fmt::print("Global variables:\n");
1752 }
1753 for (unsigned out_idx = 0; out_idx < interFace.glob_var_names.size(); ++out_idx) {
1754 const std::string &name = (interFace.glob_var_names)[out_idx];
1755 int idx1 = find_string(file1.Global_Var_Names(), name, interFace.nocase_var_names);
1756 int idx2 = find_string(file2.Global_Var_Names(), name, interFace.nocase_var_names);
1757 if (idx1 < 0 || idx2 < 0) {
1758 Error(fmt::format("Unable to find global variable named '{}' on database.\n", name));
1759 }
1760
1761 if (Invalid_Values(&vals1[idx1], 1)) {
1762 Warning(fmt::format("NaN found for global variable '{}' in file 1\n", name));
1763 diff_flag = true;
1764 }
1765
1766 if (Invalid_Values(&vals2[idx2], 1)) {
1767 Warning(fmt::format("NaN found for global variable '{}' in file 2\n", name));
1768 diff_flag = true;
1769 }
1770
1771 if (interFace.glob_var[out_idx].Diff(vals1[idx1], vals2[idx2])) {
1772 diff_flag = true;
1773
1774 if (!interFace.quiet_flag) {
1775 std::string buf =
1776 fmt::format(" {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (FAILED)", name,
1777 name_length(), interFace.glob_var[out_idx].abrstr(), vals1[idx1],
1778 vals2[idx2], interFace.glob_var[out_idx].Delta(vals1[idx1], vals2[idx2]));
1779 DIFF_OUT(buf);
1780 }
1781 else {
1782 Die_TS(step1);
1783 }
1784 }
1785 }
1786 return diff_flag;
1787 }
1788
1789 template <typename INT>
1790 bool diff_nodals(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
1791 int out_file_id, int output_step, const std::vector<INT> &node_map,
1792 const INT *id_map, std::vector<double> &nvals)
1793 {
1794 bool diff_flag = false;
1795
1796 // ---------------------------------------------------------------------
1797 // Output file containing differences...
1798 if (out_file_id >= 0) {
1799 SMART_ASSERT(!nvals.empty());
1800 int step2 = t2.step1;
1801 for (unsigned n_idx = 0; n_idx < interFace.node_var_names.size(); ++n_idx) {
1802 const std::string &name = (interFace.node_var_names)[n_idx];
1803 int idx1 = find_string(file1.Nodal_Var_Names(), name, interFace.nocase_var_names);
1804 int idx2 = find_string(file2.Nodal_Var_Names(), name, interFace.nocase_var_names);
1805 if (idx1 < 0 || idx2 < 0) {
1806 Error(fmt::format("Unable to find nodal variable named '{}' on database.\n", name));
1807 }
1808
1809 const double *vals1 = get_nodal_values(file1, step1, idx1, 1, name, &diff_flag);
1810 const double *vals2 = get_nodal_values(file2, step2, idx2, 2, name, &diff_flag);
1811
1812 if (vals1 == nullptr) {
1813 Error("Could not find nodal variables on file 1\n");
1814 }
1815
1816 if (vals2 == nullptr) {
1817 Error("Could not find nodal variables on file 2\n");
1818 }
1819
1820 size_t ncount = file1.Num_Nodes();
1821 for (size_t n = 0; n < ncount; ++n) {
1822
1823 // Should this node be processed...
1824 if (node_map.empty() || node_map[n] >= 0) {
1825 INT n2 = node_map.empty() ? n : node_map[n];
1826 nvals[n] = FileDiff(vals1[n], vals2[n2], interFace.output_type);
1827 }
1828 else {
1829 nvals[n] = 0.;
1830 }
1831 } // End of node iteration...
1832 ex_put_var(out_file_id, output_step, EX_NODAL, n_idx + 1, 0, file1.Num_Nodes(), Data(nvals));
1833 file1.Free_Nodal_Results(idx1);
1834 file2.Free_Nodal_Results(idx2);
1835 }
1836 file1.Free_Nodal_Results();
1837 file2.Free_Nodal_Results();
1838 return diff_flag;
1839 }
1840
1841 SMART_ASSERT(!interFace.summary_flag && out_file_id < 0);
1842 // ----------------------------------------------------------------------
1843 // Determine if any diffs and output to terminal
1844 if (!interFace.quiet_flag && !interFace.node_var_names.empty()) {
1845 fmt::print("Nodal variables:\n");
1846 }
1847 for (unsigned n_idx = 0; n_idx < interFace.node_var_names.size(); ++n_idx) {
1848 const std::string &name = (interFace.node_var_names)[n_idx];
1849 int idx1 = find_string(file1.Nodal_Var_Names(), name, interFace.nocase_var_names);
1850 int idx2 = find_string(file2.Nodal_Var_Names(), name, interFace.nocase_var_names);
1851 if (idx1 < 0 || idx2 < 0) {
1852 Error(fmt::format("Unable to find nodal variable named '{}' on database.\n", name));
1853 }
1854
1855 const double *vals1 = get_nodal_values(file1, step1, idx1, 1, name, &diff_flag);
1856 const double *vals2 = get_nodal_values(file2, t2, idx2, 2, name, &diff_flag);
1857
1858 if (vals1 == nullptr) {
1859 Warning(fmt::format("Could not find nodal variable '{}' on file 1.\n", name));
1860 diff_flag = true;
1861 continue;
1862 }
1863
1864 if (vals2 == nullptr) {
1865 Warning(fmt::format("Could not find nodal variable '{}' on file 2.\n", name));
1866 diff_flag = true;
1867 continue;
1868 }
1869
1870 DiffData max_diff;
1871 Norm norm;
1872
1873 size_t ncount = file1.Num_Nodes();
1874 for (size_t n = 0; n < ncount; ++n) {
1875
1876 // Should this node be processed...
1877 if (node_map.empty() || node_map[n] >= 0) {
1878 INT n2 = node_map.empty() ? n : node_map[n];
1879 double d = interFace.node_var[n_idx].Delta(vals1[n], vals2[n2]);
1880 if (interFace.show_all_diffs) {
1881 if (d > interFace.node_var[n_idx].value) {
1882 diff_flag = true;
1883 std::string buf = fmt::format(
1884 " {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (node {})", name, name_length(),
1885 interFace.node_var[n_idx].abrstr(), vals1[n], vals2[n2], d, id_map[n]);
1886 DIFF_OUT(buf);
1887 }
1888 }
1889 else {
1890 max_diff.set_max(d, vals1[n], vals2[n2], n);
1891 }
1892 norm.add_value(vals1[n], vals2[n2]);
1893 }
1894 } // End of node iteration...
1895
1896 output_norms(norm, name);
1897
1898 if (max_diff.diff > interFace.node_var[n_idx].value) {
1899 diff_flag = true;
1900 if (!interFace.quiet_flag) {
1901 std::string buf =
1902 fmt::format(" {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (node {})", name,
1903 name_length(), interFace.node_var[n_idx].abrstr(), max_diff.val1,
1904 max_diff.val2, max_diff.diff, id_map[max_diff.id]);
1905 DIFF_OUT(buf);
1906 }
1907 else {
1908 Die_TS(step1);
1909 }
1910 }
1911 file1.Free_Nodal_Results(idx1);
1912 file2.Free_Nodal_Results(idx2);
1913 }
1914 file1.Free_Nodal_Results();
1915 file2.Free_Nodal_Results();
1916 return diff_flag;
1917 }
1918
1919 template <typename INT>
1920 bool diff_element(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
1921 int out_file_id, int output_step, const std::vector<INT> &elmt_map,
1922 const INT *id_map, Exo_Block<INT> **blocks2, std::vector<double> &evals)
1923 {
1924 bool diff_flag = false;
1925
1926 if (out_file_id >= 0) {
1927 SMART_ASSERT(!evals.empty());
1928 }
1929
1930 if (out_file_id < 0 && !interFace.quiet_flag && !interFace.elmt_var_names.empty()) {
1931 fmt::print("Element variables:\n");
1932 }
1933
1934 for (unsigned e_idx = 0; e_idx < interFace.elmt_var_names.size(); ++e_idx) {
1935 const std::string &name = (interFace.elmt_var_names)[e_idx];
1936 int vidx1 = find_string(file1.Element_Var_Names(), name, interFace.nocase_var_names);
1937 int vidx2 = find_string(file2.Element_Var_Names(), name, interFace.nocase_var_names);
1938 if (vidx1 < 0 || vidx2 < 0) {
1939 Error(fmt::format("Unable to find element variable named '{}' on database.\n", name));
1940 }
1941
1942 Norm norm;
1943
1944 if (!elmt_map.empty()) { // Load variable for all blocks in file 2.
1945 for (size_t b = 0; b < file2.Num_Element_Blocks(); ++b) {
1946 Exo_Block<INT> *block2 = file2.Get_Element_Block_by_Index(b);
1947 block2->Load_Results(t2.step1, t2.step2, t2.proportion, vidx2);
1948 }
1949 }
1950
1951 size_t global_elmt_index = 0;
1952 DiffData max_diff;
1953 for (size_t b = 0; b < file1.Num_Element_Blocks(); ++b) {
1954 Exo_Block<INT> *eblock1 = file1.Get_Element_Block_by_Index(b);
1955 if (!eblock1->is_valid_var(vidx1)) {
1956 global_elmt_index += eblock1->Size();
1957 continue;
1958 }
1959 if (eblock1->Size() == 0) {
1960 continue;
1961 }
1962
1963 Exo_Block<INT> *eblock2 = nullptr;
1964 if (elmt_map.empty()) {
1965 if (interFace.by_name) {
1966 eblock2 = file2.Get_Element_Block_by_Name(eblock1->Name());
1967 }
1968 else {
1969 eblock2 = file2.Get_Element_Block_by_Id(eblock1->Id());
1970 }
1971
1972 SMART_ASSERT(eblock2 != nullptr);
1973 if (!eblock2->is_valid_var(vidx2)) {
1974 continue;
1975 }
1976 }
1977
1978 eblock1->Load_Results(step1, vidx1);
1979 const double *vals1 = eblock1->Get_Results(vidx1);
1980 if (vals1 == nullptr) {
1981 Warning(fmt::format("Could not find element variable '{}' in block {}, file 1.\n", name,
1982 eblock1->Id()));
1983 diff_flag = true;
1984 continue;
1985 }
1986
1987 if (Invalid_Values(vals1, eblock1->Size())) {
1988 Warning(fmt::format("NaN found for element variable '{}' in block {}, file 1\n", name,
1989 eblock1->Id()));
1990 diff_flag = true;
1991 }
1992
1993 double v2 = 0;
1994 const double *vals2 = nullptr;
1995
1996 if (elmt_map.empty()) {
1997 // Without mapping, get result for this block.
1998 size_t id = eblock1->Id();
1999 if (interFace.by_name) {
2000 eblock2 = file2.Get_Element_Block_by_Name(eblock1->Name());
2001 }
2002 else {
2003 eblock2 = file2.Get_Element_Block_by_Id(id);
2004 }
2005 vals2 = get_validated_variable(eblock2, t2, vidx2, name, &diff_flag);
2006 if (vals2 == nullptr) {
2007 continue;
2008 }
2009 }
2010
2011 size_t ecount = eblock1->Size();
2012 size_t block_id = eblock1->Id();
2013 for (size_t e = 0; e < ecount; ++e) {
2014 if (out_file_id >= 0) {
2015 evals[e] = 0.;
2016 }
2017 INT el_flag = 1;
2018 if (!elmt_map.empty()) {
2019 el_flag = elmt_map[global_elmt_index];
2020 }
2021
2022 if (el_flag >= 0) {
2023 if (elmt_map.empty()) {
2024 if (vals2 != nullptr) {
2025 v2 = vals2[e];
2026 }
2027 }
2028 else {
2029 // With mapping, map global index from file 1 to global index
2030 // for file 2. Then convert to block index and elmt index.
2031 auto bl_idx = file2.Global_to_Block_Local(elmt_map[global_elmt_index] + 1);
2032 SMART_ASSERT(blocks2[bl_idx.first] != nullptr);
2033 if (blocks2[bl_idx.first]->is_valid_var(vidx2)) {
2034 auto *tmp = blocks2[bl_idx.first]->Get_Results(vidx2);
2035 if (tmp != nullptr) {
2036 v2 = tmp[bl_idx.second]; // Get value from file 2.
2037 }
2038 else {
2039 v2 = vals1[e]; // Should never happen...
2040 }
2041 }
2042 else {
2043 // Easiest from logic standpoint to just set v2 equal to v1 at
2044 // this point and continue through rest of loop.
2045 v2 = vals1[e];
2046 }
2047 }
2048
2049 if (out_file_id >= 0) {
2050 evals[e] = FileDiff(vals1[e], v2, interFace.output_type);
2051 }
2052 else if (interFace.show_all_diffs) {
2053 double d = interFace.elmt_var[e_idx].Delta(vals1[e], v2);
2054 if (d > interFace.elmt_var[e_idx].value) {
2055 diff_flag = true;
2056 std::string buf = fmt::format(
2057 " {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (block {}, elmt {})", name,
2058 name_length(), interFace.elmt_var[e_idx].abrstr(), vals1[e], v2, d, block_id,
2059 id_map[global_elmt_index]);
2060 DIFF_OUT(buf);
2061 }
2062 }
2063 else {
2064 double d = interFace.elmt_var[e_idx].Delta(vals1[e], v2);
2065 max_diff.set_max(d, vals1[e], v2, global_elmt_index, block_id);
2066 }
2067 norm.add_value(vals1[e], v2);
2068 }
2069 ++global_elmt_index;
2070 }
2071
2072 if (out_file_id >= 0) {
2073 ex_put_var(out_file_id, output_step, EX_ELEM_BLOCK, e_idx + 1, eblock1->Id(),
2074 eblock1->Size(), Data(evals));
2075 }
2076
2077 eblock1->Free_Results();
2078 if (elmt_map.empty() && eblock2 != nullptr) {
2079 eblock2->Free_Results();
2080 }
2081
2082 } // End of element block loop.
2083
2084 output_norms(norm, name);
2085
2086 if (max_diff.diff > interFace.elmt_var[e_idx].value) {
2087 diff_flag = true;
2088
2089 if (!interFace.quiet_flag) {
2090 std::string buf =
2091 fmt::format(" {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (block {}, elmt {})",
2092 name, name_length(), interFace.elmt_var[e_idx].abrstr(), max_diff.val1,
2093 max_diff.val2, max_diff.diff, max_diff.blk, id_map[max_diff.id]);
2094 DIFF_OUT(buf);
2095 }
2096 else {
2097 Die_TS(step1);
2098 }
2099 }
2100
2101 } // End of element variable loop.
2102 return diff_flag;
2103 }
2104
2105 template <typename INT>
2106 bool diff_nodeset(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
2107 int out_file_id, int output_step, const INT *id_map, std::vector<double> &vals)
2108 {
2109 bool diff_flag = false;
2110
2111 if (out_file_id >= 0) {
2112 SMART_ASSERT(!vals.empty());
2113 }
2114
2115 if (out_file_id < 0 && !interFace.quiet_flag && !interFace.ns_var_names.empty()) {
2116 fmt::print("Nodeset variables:\n");
2117 }
2118 for (unsigned e_idx = 0; e_idx < interFace.ns_var_names.size(); ++e_idx) {
2119 const std::string &name = (interFace.ns_var_names)[e_idx];
2120 int vidx1 = find_string(file1.NS_Var_Names(), name, interFace.nocase_var_names);
2121 int vidx2 = find_string(file2.NS_Var_Names(), name, interFace.nocase_var_names);
2122 if (vidx1 < 0 || vidx2 < 0) {
2123 Error(fmt::format("Unable to find nodeset variable named '{}' on database.\n", name));
2124 }
2125
2126 DiffData max_diff;
2127 Norm norm;
2128
2129 for (size_t b = 0; b < file1.Num_Node_Sets(); ++b) {
2130 Node_Set<INT> *nset1 = file1.Get_Node_Set_by_Index(b);
2131 const double *vals1 = get_validated_variable(nset1, step1, vidx1, name, &diff_flag);
2132 if (vals1 == nullptr) {
2133 continue;
2134 }
2135
2136 Node_Set<INT> *nset2 = nullptr;
2137 size_t id = nset1->Id();
2138 if (interFace.by_name) {
2139 nset2 = file2.Get_Node_Set_by_Name(nset1->Name());
2140 }
2141 else {
2142 nset2 = file2.Get_Node_Set_by_Id(id);
2143 }
2144 const double *vals2 = get_validated_variable(nset2, t2, vidx2, name, &diff_flag);
2145 if (vals2 == nullptr) {
2146 continue;
2147 }
2148
2149 size_t ncount = nset1->Size();
2150 if (nset2->Size() == ncount) {
2151 for (size_t e = 0; e < ncount; ++e) {
2152 int idx1 = nset1->Node_Index(e);
2153 int idx2 = nset2->Node_Index(e);
2154
2155 if (out_file_id >= 0) {
2156 vals[idx1] = FileDiff(vals1[idx1], vals2[idx2], interFace.output_type);
2157 }
2158 else if (interFace.show_all_diffs) {
2159 double d = interFace.ns_var[e_idx].Delta(vals1[idx1], vals2[idx2]);
2160 if (d > interFace.ns_var[e_idx].value) {
2161 diff_flag = true;
2162 std::string buf =
2163 fmt::format(" {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (set {}, node {})",
2164 name, name_length(), interFace.ns_var[e_idx].abrstr(), vals1[idx1],
2165 vals2[idx2], d, nset1->Id(), e);
2166 DIFF_OUT(buf);
2167 }
2168 }
2169 else {
2170 double d = interFace.ns_var[e_idx].Delta(vals1[idx1], vals2[idx2]);
2171 max_diff.set_max(d, vals1[idx1], vals2[idx2], e, nset1->Id());
2172 }
2173 norm.add_value(vals1[idx1], vals2[idx2]);
2174 }
2175
2176 if (out_file_id >= 0) {
2177 ex_put_var(out_file_id, output_step, EX_NODE_SET, e_idx + 1, nset1->Id(), nset1->Size(),
2178 Data(vals));
2179 }
2180 }
2181 else {
2182 std::string buf =
2183 fmt::format(" {:<{}} diff: nodeset node counts differ for nodeset {}", name,
2184 name_length(), nset1->Id());
2185 DIFF_OUT(buf);
2186 diff_flag = true;
2187 }
2188
2189 nset1->Free_Results();
2190 nset2->Free_Results();
2191 } // End of nodeset loop.
2192
2193 output_norms(norm, name);
2194
2195 if (max_diff.diff > interFace.ns_var[e_idx].value) {
2196 diff_flag = true;
2197
2198 if (!interFace.quiet_flag) {
2199 Node_Set<INT> *nset = file1.Get_Node_Set_by_Id(max_diff.blk);
2200 std::string buf = fmt::format(
2201 " {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (set {}, node {})", name,
2202 name_length(), interFace.ns_var[e_idx].abrstr(), max_diff.val1, max_diff.val2,
2203 max_diff.diff, max_diff.blk, id_map[nset->Node_Id(max_diff.id) - 1]);
2204 DIFF_OUT(buf);
2205 }
2206 else {
2207 Die_TS(step1);
2208 }
2209 }
2210 } // End of nodeset variable loop.
2211 return diff_flag;
2212 }
2213
2214 template <typename INT>
2215 bool diff_sideset(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
2216 int out_file_id, int output_step, const INT *id_map, std::vector<double> &vals)
2217 {
2218 bool diff_flag = false;
2219
2220 if (out_file_id >= 0) {
2221 SMART_ASSERT(!vals.empty());
2222 }
2223
2224 if (out_file_id < 0 && !interFace.quiet_flag && !interFace.ss_var_names.empty()) {
2225 fmt::print("Sideset variables:\n");
2226 }
2227
2228 for (unsigned e_idx = 0; e_idx < interFace.ss_var_names.size(); ++e_idx) {
2229 const std::string &name = (interFace.ss_var_names)[e_idx];
2230 int vidx1 = find_string(file1.SS_Var_Names(), name, interFace.nocase_var_names);
2231 int vidx2 = find_string(file2.SS_Var_Names(), name, interFace.nocase_var_names);
2232
2233 if (vidx1 < 0 || vidx2 < 0) {
2234 Error(fmt::format("Unable to find sideset variable named '{}' on database.\n", name));
2235 }
2236
2237 DiffData max_diff;
2238 Norm norm;
2239
2240 for (size_t b = 0; b < file1.Num_Side_Sets(); ++b) {
2241 Side_Set<INT> *sset1 = file1.Get_Side_Set_by_Index(b);
2242 SMART_ASSERT(sset1 != nullptr);
2243 const double *vals1 = get_validated_variable(sset1, step1, vidx1, name, &diff_flag);
2244 if (vals1 == nullptr) {
2245 continue;
2246 }
2247
2248 Side_Set<INT> *sset2 = nullptr;
2249 if (interFace.by_name) {
2250 sset2 = file2.Get_Side_Set_by_Name(sset1->Name());
2251 }
2252 else {
2253 sset2 = file2.Get_Side_Set_by_Id(sset1->Id());
2254 }
2255 const double *vals2 = get_validated_variable(sset2, t2, vidx2, name, &diff_flag);
2256 if (vals2 == nullptr) {
2257 continue;
2258 }
2259
2260 size_t ecount = sset1->Size();
2261 if (sset2->Size() == ecount) {
2262 for (size_t e = 0; e < ecount; ++e) {
2263 size_t ind1 = sset1->Side_Index(e);
2264 size_t ind2 = sset2->Side_Index(e);
2265
2266 if (out_file_id >= 0) {
2267 vals[ind1] = FileDiff(vals1[ind1], vals2[ind2], interFace.output_type);
2268 }
2269 else if (interFace.show_all_diffs) {
2270 double d = interFace.ss_var[e_idx].Delta(vals1[ind1], vals2[ind2]);
2271 if (d > interFace.ss_var[e_idx].value) {
2272 diff_flag = true;
2273 std::string buf = fmt::format(
2274 " {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (set {}, side {}.{})", name,
2275 name_length(), interFace.ss_var[e_idx].abrstr(), vals1[ind1], vals2[ind2], d,
2276 sset1->Id(), id_map[sset1->Side_Id(e).first - 1], (int)sset1->Side_Id(e).second);
2277 DIFF_OUT(buf);
2278 }
2279 }
2280 else {
2281 double d = interFace.ss_var[e_idx].Delta(vals1[ind1], vals2[ind2]);
2282 max_diff.set_max(d, vals1[ind1], vals2[ind2], e, sset1->Id());
2283 }
2284 norm.add_value(vals1[ind1], vals2[ind2]);
2285 }
2286 if (out_file_id >= 0) {
2287 ex_put_var(out_file_id, output_step, EX_SIDE_SET, e_idx + 1, sset1->Id(), sset1->Size(),
2288 Data(vals));
2289 }
2290 }
2291 else {
2292 std::string buf =
2293 fmt::format(" {:<{}} diff: sideset side counts differ for sideset {}", name,
2294 name_length(), sset1->Id());
2295 DIFF_OUT(buf);
2296 diff_flag = true;
2297 }
2298
2299 sset1->Free_Results();
2300 sset2->Free_Results();
2301 } // End of sideset loop.
2302
2303 if (max_diff.diff > interFace.ss_var[e_idx].value) {
2304 diff_flag = true;
2305
2306 output_norms(norm, name);
2307
2308 if (!interFace.quiet_flag) {
2309 Side_Set<INT> *sset = file1.Get_Side_Set_by_Id(max_diff.blk);
2310 std::string buf = fmt::format(
2311 " {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (set {}, side {}.{})", name,
2312 name_length(), interFace.ss_var[e_idx].abrstr(), max_diff.val1, max_diff.val2,
2313 max_diff.diff, max_diff.blk, id_map[sset->Side_Id(max_diff.id).first - 1],
2314 (int)sset->Side_Id(max_diff.id).second);
2315 DIFF_OUT(buf);
2316 }
2317 else {
2318 Die_TS(step1);
2319 }
2320 }
2321
2322 } // End of sideset variable loop.
2323 return diff_flag;
2324 }
2325
2326 template <typename INT>
2327 bool diff_sideset_df(Exo_Read<INT> &file1, Exo_Read<INT> &file2, const INT *id_map)
2328 {
2329 bool diff_flag = false;
2330
2331 std::string name = "Distribution Factors";
2332 int length_name = name.length();
2333
2334 if (!interFace.quiet_flag && file1.Num_Side_Sets() > 0) {
2335 fmt::print("Sideset Distribution Factors:\n");
2336 }
2337 DiffData max_diff;
2338 for (size_t b = 0; b < file1.Num_Side_Sets(); ++b) {
2339 Side_Set<INT> *sset1 = file1.Get_Side_Set_by_Index(b);
2340 SMART_ASSERT(sset1 != nullptr);
2341
2342 Side_Set<INT> *sset2 = nullptr;
2343 if (interFace.by_name) {
2344 sset2 = file2.Get_Side_Set_by_Name(sset1->Name());
2345 }
2346 else {
2347 sset2 = file2.Get_Side_Set_by_Id(sset1->Id());
2348 }
2349 if (sset2 == nullptr) {
2350 continue;
2351 }
2352
2353 if (sset1->Distribution_Factor_Count() == 0 || sset2->Distribution_Factor_Count() == 0) {
2354 continue;
2355 }
2356
2357 const double *vals1 = sset1->Distribution_Factors();
2358
2359 if (vals1 == nullptr) {
2360 Warning(
2361 fmt::format("Could not read distribution factors in sideset {}, file 1.\n", sset1->Id()));
2362 diff_flag = true;
2363 continue;
2364 }
2365
2366 double value1 = 0.0;
2367 double value2 = 0.0;
2368 bool same1 = false;
2369 bool same2 = false;
2370
2371 size_t ecount = sset1->Size();
2372
2373 {
2374 std::pair<INT, INT> range1 = sset1->Distribution_Factor_Range(ecount - 1);
2375 if (Invalid_Values(vals1, range1.second)) {
2376 Warning(fmt::format("NaN found for distribution factors in sideset {}, file 1.\n",
2377 sset1->Id()));
2378 diff_flag = true;
2379 }
2380
2381 // See if all df are the same value:
2382 same1 = Equal_Values(vals1, range1.second, &value1);
2383 }
2384
2385 auto *vals2 = sset2->Distribution_Factors();
2386
2387 if (vals2 == nullptr) {
2388 Warning(
2389 fmt::format("Could not read distribution factors in sideset {}, file 2.\n", sset2->Id()));
2390 diff_flag = true;
2391 continue;
2392 }
2393
2394 {
2395 std::pair<INT, INT> range2 = sset2->Distribution_Factor_Range(sset2->Size() - 1);
2396 if (Invalid_Values(vals2, range2.second)) {
2397 Warning(fmt::format("NaN found for distribution factors in sideset {}, file 2.\n",
2398 sset2->Id()));
2399 diff_flag = true;
2400 }
2401
2402 // See if all df are the same value:
2403 same2 = Equal_Values(vals2, range2.second, &value2);
2404 }
2405
2406 if (same1 && same2 && (value1 == value2)) {
2407 continue;
2408 }
2409
2410 if (sset2->Size() == ecount) {
2411 for (size_t e = 0; e < ecount; ++e) {
2412 std::pair<INT, INT> range1 = sset1->Distribution_Factor_Range(e);
2413 std::pair<INT, INT> range2 = sset2->Distribution_Factor_Range(e);
2414 SMART_ASSERT(range1.second - range1.first == range2.second - range2.first);
2415
2416 for (INT i = 0; i < range1.second - range1.first; i++) {
2417 double v1 = vals1[range1.first + i];
2418 double v2 = vals2[range2.first + i];
2419
2420 if (interFace.show_all_diffs) {
2421 double d = interFace.ss_df_tol.Delta(v1, v2);
2422 if (d > interFace.ss_df_tol.value) {
2423 diff_flag = true;
2424 std::string buf = fmt::format(
2425 " {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (set {}, side {}"
2426 ".{}-{})",
2427 name, length_name, interFace.ss_df_tol.abrstr(), v1, v2, d, sset1->Id(),
2428 id_map[sset1->Side_Id(e).first - 1], (int)sset1->Side_Id(e).second, (int)i + 1);
2429 DIFF_OUT(buf);
2430 }
2431 }
2432 else {
2433 double d = interFace.ss_df_tol.Delta(v1, v2);
2434 max_diff.set_max(d, v1, v2, e, sset1->Id());
2435 }
2436 }
2437 }
2438 }
2439 else {
2440 std::string buf = fmt::format(" {:<{}} diff: sideset side counts differ for sideset {}",
2441 name, length_name, sset1->Id());
2442 DIFF_OUT(buf);
2443 diff_flag = true;
2444 }
2445
2446 sset1->Free_Distribution_Factors();
2447 sset2->Free_Distribution_Factors();
2448 } // End of sideset loop.
2449
2450 if (max_diff.diff > interFace.ss_df_tol.value) {
2451 diff_flag = true;
2452
2453 if (!interFace.quiet_flag) {
2454 Side_Set<INT> *sset = file1.Get_Side_Set_by_Id(max_diff.blk);
2455 std::string buf =
2456 fmt::format(" {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (set {}, side {}.{})", name,
2457 length_name, interFace.ss_df_tol.abrstr(), max_diff.val1, max_diff.val2,
2458 max_diff.diff, max_diff.blk, id_map[sset->Side_Id(max_diff.id).first - 1],
2459 (int)sset->Side_Id(max_diff.id).second);
2460 DIFF_OUT(buf);
2461 }
2462 else {
2463 Die_TS(-1);
2464 }
2465 }
2466
2467 return diff_flag;
2468 }
2469
2470 template <typename INT>
2471 bool diff_edgeblock(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
2472 int out_file_id, int output_step, const INT * /* id_map */,
2473 std::vector<double> &vals)
2474 {
2475 bool diff_flag = false;
2476
2477 if (out_file_id >= 0) {
2478 SMART_ASSERT(!vals.empty());
2479 }
2480
2481 if (out_file_id < 0 && !interFace.quiet_flag && !interFace.eb_var_names.empty()) {
2482 fmt::print("Edge Block variables:\n");
2483 }
2484
2485 for (unsigned e_idx = 0; e_idx < interFace.eb_var_names.size(); ++e_idx) {
2486 const std::string &name = (interFace.eb_var_names)[e_idx];
2487 int vidx1 = find_string(file1.EB_Var_Names(), name, interFace.nocase_var_names);
2488 int vidx2 = find_string(file2.EB_Var_Names(), name, interFace.nocase_var_names);
2489 if (vidx1 < 0 || vidx2 < 0) {
2490 Error(fmt::format("Unable to find edge block variable named '{}' on database.\n", name));
2491 }
2492
2493 DiffData max_diff;
2494 Norm norm;
2495
2496 for (size_t b = 0; b < file1.Num_Edge_Blocks(); ++b) {
2497 Edge_Block<INT> *eblock1 = file1.Get_Edge_Block_by_Index(b);
2498 const double *vals1 = get_validated_variable(eblock1, step1, vidx1, name, &diff_flag);
2499 if (vals1 == nullptr) {
2500 continue;
2501 }
2502
2503 Edge_Block<INT> *eblock2 = nullptr;
2504 if (interFace.by_name) {
2505 eblock2 = file2.Get_Edge_Block_by_Name(eblock1->Name());
2506 }
2507 else {
2508 eblock2 = file2.Get_Edge_Block_by_Id(eblock1->Id());
2509 }
2510 const double *vals2 = get_validated_variable(eblock2, t2, vidx2, name, &diff_flag);
2511 if (vals2 == nullptr) {
2512 continue;
2513 }
2514
2515 size_t ecount = eblock1->Size();
2516 if (eblock2->Size() == ecount) {
2517 for (size_t e = 0; e < ecount; ++e) {
2518 size_t ind1 = eblock1->Edge_Index(e);
2519 size_t ind2 = eblock2->Edge_Index(e);
2520
2521 if (out_file_id >= 0) {
2522 vals[ind1] = FileDiff(vals1[ind1], vals2[ind2], interFace.output_type);
2523 }
2524 else if (interFace.show_all_diffs) {
2525 double d = interFace.eb_var[e_idx].Delta(vals1[ind1], vals2[ind2]);
2526 if (d > interFace.eb_var[e_idx].value) {
2527 diff_flag = true;
2528 std::string buf = fmt::format(
2529 " {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (edge block {}, edge {})", name,
2530 name_length(), interFace.eb_var[e_idx].abrstr(), vals1[ind1], vals2[ind2], d,
2531 eblock1->Id(), eblock1->Edge_Index(e) + 1);
2532 DIFF_OUT(buf);
2533 }
2534 }
2535 else {
2536 double d = interFace.eb_var[e_idx].Delta(vals1[ind1], vals2[ind2]);
2537 max_diff.set_max(d, vals1[ind1], vals2[ind2], e, eblock1->Id());
2538 }
2539 norm.add_value(vals1[ind1], vals2[ind2]);
2540 }
2541 if (out_file_id >= 0) {
2542 ex_put_var(out_file_id, output_step, EX_EDGE_BLOCK, e_idx + 1, eblock1->Id(),
2543 eblock1->Size(), Data(vals));
2544 }
2545 }
2546 else {
2547 std::string buf =
2548 fmt::format(" {:<{}} diff: edge block edge counts differ for edge block {}", name,
2549 name_length(), eblock1->Id());
2550 DIFF_OUT(buf);
2551 diff_flag = true;
2552 }
2553
2554 eblock1->Free_Results();
2555 eblock2->Free_Results();
2556 } // End of edgeblock loop.
2557
2558 if (max_diff.diff > interFace.eb_var[e_idx].value) {
2559 diff_flag = true;
2560
2561 output_norms(norm, name);
2562
2563 if (!interFace.quiet_flag) {
2564 Edge_Block<INT> *eblock = file1.Get_Edge_Block_by_Id(max_diff.blk);
2565 std::string buf = fmt::format(
2566 " {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (edge block {}, edge {})", name,
2567 name_length(), interFace.eb_var[e_idx].abrstr(), max_diff.val1, max_diff.val2,
2568 max_diff.diff, max_diff.blk, eblock->Edge_Index(max_diff.id) + 1);
2569 DIFF_OUT(buf);
2570 }
2571 else {
2572 Die_TS(step1);
2573 }
2574 }
2575
2576 } // End of edgeblock variable loop.
2577 return diff_flag;
2578 }
2579
2580 template <typename INT>
2581 bool diff_faceblock(Exo_Read<INT> &file1, Exo_Read<INT> &file2, int step1, const TimeInterp &t2,
2582 int out_file_id, int output_step, const INT * /* id_map */,
2583 std::vector<double> &vals)
2584 {
2585 bool diff_flag = false;
2586
2587 if (out_file_id >= 0) {
2588 SMART_ASSERT(!vals.empty());
2589 }
2590
2591 if (out_file_id < 0 && !interFace.quiet_flag && !interFace.fb_var_names.empty()) {
2592 fmt::print("Face Block variables:\n");
2593 }
2594
2595 for (unsigned f_idx = 0; f_idx < interFace.fb_var_names.size(); ++f_idx) {
2596 const std::string &name = (interFace.fb_var_names)[f_idx];
2597 int vidx1 = find_string(file1.FB_Var_Names(), name, interFace.nocase_var_names);
2598 int vidx2 = find_string(file2.FB_Var_Names(), name, interFace.nocase_var_names);
2599 if (vidx1 < 0 || vidx2 < 0) {
2600 Error(fmt::format("Unable to find face block variable named '{}' on database.\n", name));
2601 }
2602
2603 DiffData max_diff;
2604 Norm norm;
2605
2606 for (size_t b = 0; b < file1.Num_Face_Blocks(); ++b) {
2607 Face_Block<INT> *fblock1 = file1.Get_Face_Block_by_Index(b);
2608 const double *vals1 = get_validated_variable(fblock1, step1, vidx1, name, &diff_flag);
2609 if (vals1 == nullptr) {
2610 continue;
2611 }
2612
2613 Face_Block<INT> *fblock2 = nullptr;
2614 if (interFace.by_name) {
2615 fblock2 = file2.Get_Face_Block_by_Name(fblock1->Name());
2616 }
2617 else {
2618 fblock2 = file2.Get_Face_Block_by_Id(fblock1->Id());
2619 }
2620 const double *vals2 = get_validated_variable(fblock2, t2, vidx2, name, &diff_flag);
2621 if (vals2 == nullptr) {
2622 continue;
2623 }
2624
2625 size_t fcount = fblock1->Size();
2626 if (fblock2->Size() == fcount) {
2627 for (size_t f = 0; f < fcount; ++f) {
2628 size_t ind1 = fblock1->Face_Index(f);
2629 size_t ind2 = fblock2->Face_Index(f);
2630
2631 if (out_file_id >= 0) {
2632 vals[ind1] = FileDiff(vals1[ind1], vals2[ind2], interFace.output_type);
2633 }
2634 else if (interFace.show_all_diffs) {
2635 double d = interFace.fb_var[f_idx].Delta(vals1[ind1], vals2[ind2]);
2636 if (d > interFace.fb_var[f_idx].value) {
2637 diff_flag = true;
2638 std::string buf = fmt::format(
2639 " {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (face block {}, face {})", name,
2640 name_length(), interFace.fb_var[f_idx].abrstr(), vals1[ind1], vals2[ind2], d,
2641 fblock1->Id(), fblock1->Face_Index(f) + 1);
2642 DIFF_OUT(buf);
2643 }
2644 }
2645 else {
2646 double d = interFace.fb_var[f_idx].Delta(vals1[ind1], vals2[ind2]);
2647 max_diff.set_max(d, vals1[ind1], vals2[ind2], f, fblock1->Id());
2648 }
2649 norm.add_value(vals1[ind1], vals2[ind2]);
2650 }
2651 if (out_file_id >= 0) {
2652 ex_put_var(out_file_id, output_step, EX_FACE_BLOCK, f_idx + 1, fblock1->Id(),
2653 fblock1->Size(), Data(vals));
2654 }
2655 }
2656 else {
2657 std::string buf =
2658 fmt::format(" {:<{}} diff: face block face counts differ for face block {}", name,
2659 name_length(), fblock1->Id());
2660 DIFF_OUT(buf);
2661 diff_flag = true;
2662 }
2663
2664 fblock1->Free_Results();
2665 fblock2->Free_Results();
2666 } // End of faceblock loop.
2667
2668 if (max_diff.diff > interFace.fb_var[f_idx].value) {
2669 diff_flag = true;
2670
2671 output_norms(norm, name);
2672
2673 if (!interFace.quiet_flag) {
2674 std::string buf =
2675 fmt::format(" {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (face block {}, face {})",
2676 name, name_length(), interFace.fb_var[f_idx].abrstr(), max_diff.val1,
2677 max_diff.val2, max_diff.diff, max_diff.blk, max_diff.id + 1);
2678 DIFF_OUT(buf);
2679 }
2680 else {
2681 Die_TS(step1);
2682 }
2683 }
2684
2685 } // End of faceblock variable loop.
2686 return diff_flag;
2687 }
2688
2689 template <typename INT>
2690 bool diff_element_attributes(Exo_Read<INT> &file1, Exo_Read<INT> &file2,
2691 const std::vector<INT> & /*elmt_map*/, const INT *id_map,
2692 Exo_Block<INT> ** /*blocks2*/)
2693 {
2694 if (interFace.summary_flag) {
2695 return false;
2696 }
2697
2698 if (file1.Num_Elements() == 0 || file2.Num_Elements() == 0) {
2699 return false;
2700 }
2701
2702 bool diff_was_output = false;
2703 bool diff_flag = false;
2704
2705 size_t global_elmt_offset = 0;
2706 for (size_t b = 0; b < file1.Num_Element_Blocks(); ++b) {
2707 Exo_Block<INT> *eblock1 = file1.Get_Element_Block_by_Index(b);
2708 SMART_ASSERT(eblock1 != nullptr);
2709
2710 size_t block_id = eblock1->Id();
2711
2712 Exo_Block<INT> *eblock2 = nullptr;
2713 if (interFace.by_name) {
2714 eblock2 = file2.Get_Element_Block_by_Name(eblock1->Name());
2715 }
2716 else {
2717 eblock2 = file2.Get_Element_Block_by_Id(block_id);
2718 }
2719
2720 SMART_ASSERT(eblock2 != nullptr);
2721
2722 if (!diff_was_output && (eblock1->attr_count() > 0 || eblock2->attr_count() > 0)) {
2723 diff_was_output = true;
2724 fmt::print("Element attributes:\n");
2725 }
2726
2727 for (int idx1 = 0; idx1 < eblock1->attr_count(); idx1++) {
2728 size_t global_elmt_index = global_elmt_offset;
2729
2730 DiffData max_diff;
2731 const std::string &name = eblock1->Get_Attribute_Name(idx1);
2732
2733 // Find same attribute in eblock2...
2734 int idx2 = eblock2->Find_Attribute_Index(name);
2735 if (idx2 < 0) {
2736 continue;
2737 }
2738
2739 // Find name in interFace.elmt_att_names
2740 int tol_idx = -1;
2741 for (unsigned e_idx = 0; e_idx < interFace.elmt_att_names.size(); ++e_idx) {
2742 if (name == (interFace.elmt_att_names)[e_idx]) {
2743 tol_idx = e_idx;
2744 break;
2745 }
2746 }
2747
2748 if (tol_idx == -1) {
2749 continue;
2750 }
2751
2752 Norm norm;
2753
2754 eblock1->Load_Attributes(idx1);
2755 const double *vals1 = eblock1->Get_Attributes(idx1);
2756
2757 if (vals1 == nullptr) {
2758 Warning(fmt::format("Could not find element attribute '{}' in block {}, file 1.\n", name,
2759 eblock1->Id()));
2760 diff_flag = true;
2761 continue;
2762 }
2763
2764 if (Invalid_Values(vals1, eblock1->Size())) {
2765 Warning(fmt::format("NaN found for element attribute '{}' in block {}, file 1.\n", name,
2766 eblock1->Id()));
2767 diff_flag = true;
2768 }
2769
2770 // Without mapping, get result for this block.
2771 eblock2->Load_Attributes(idx2);
2772 const double *vals2 = eblock2->Get_Attributes(idx2);
2773
2774 if (vals2 == nullptr) {
2775 Warning(fmt::format("Could not find element attribute '{}' in block {}, file 2.\n", name,
2776 eblock2->Id()));
2777 diff_flag = true;
2778 continue;
2779 }
2780
2781 if (Invalid_Values(vals2, eblock2->Size())) {
2782 Warning(fmt::format("NaN found for element attribute '{}' in block {}, file 2.\n", name,
2783 eblock2->Id()));
2784 diff_flag = true;
2785 }
2786
2787 size_t ecount = eblock1->Size();
2788 for (size_t e = 0; e < ecount; ++e) {
2789
2790 if (interFace.show_all_diffs) {
2791 double d = interFace.elmt_att[tol_idx].Delta(vals1[e], vals2[e]);
2792 if (d > interFace.elmt_att[tol_idx].value) {
2793 diff_flag = true;
2794 std::string buf =
2795 fmt::format(" {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (block {}, elmt {})",
2796 name, name_length(), interFace.elmt_att[tol_idx].abrstr(), vals1[e],
2797 vals2[e], d, block_id, id_map[global_elmt_index]);
2798 DIFF_OUT(buf);
2799 }
2800 }
2801 else {
2802 double d = interFace.elmt_att[tol_idx].Delta(vals1[e], vals2[e]);
2803 max_diff.set_max(d, vals1[e], vals2[e], global_elmt_index, block_id);
2804 }
2805 norm.add_value(vals1[e], vals2[e]);
2806 ++global_elmt_index;
2807 }
2808
2809 output_norms(norm, name);
2810
2811 if (max_diff.diff > interFace.elmt_att[tol_idx].value) {
2812 diff_flag = true;
2813
2814 if (!interFace.quiet_flag) {
2815 std::string buf =
2816 fmt::format(" {:<{}} {} diff: {:14.7e} ~ {:14.7e} ={:12.5e} (block {}, elmt {})",
2817 name, name_length(), interFace.elmt_att[tol_idx].abrstr(), max_diff.val1,
2818 max_diff.val2, max_diff.diff, max_diff.blk, id_map[max_diff.id]);
2819 DIFF_OUT(buf);
2820 }
2821 else {
2822 Die_TS(-1);
2823 }
2824 }
2825 } // End of attribute loop.
2826 eblock1->Free_Attributes();
2827 eblock2->Free_Attributes();
2828
2829 global_elmt_offset += eblock1->Size();
2830 } // End of element block loop.
2831 return diff_flag;
2832 }
2833
2834 template <typename INT>
2835 void output_summary(Exo_Read<INT> &file1, MinMaxData &mm_time, std::vector<MinMaxData> &mm_glob,
2836 std::vector<MinMaxData> &mm_node, std::vector<MinMaxData> &mm_elmt,
2837 std::vector<MinMaxData> &mm_ns, std::vector<MinMaxData> &mm_ss,
2838 std::vector<MinMaxData> &mm_eb, std::vector<MinMaxData> &mm_fb,
2839 const INT *node_id_map, const INT *elem_id_map)
2840 {
2841 int i;
2842 int n;
2843
2844 fmt::print("# NOTES: - The min/max values are reporting the min/max in absolute value.\n"
2845 "# - Time values (t) are 1-offset time step numbers.\n"
2846 "# - Element block numbers are the block ids.\n"
2847 "# - Node(n) and element(e) numbers are 1-offset.\n");
2848
2849 if (interFace.coord_sep) {
2850 double min_separation = Find_Min_Coord_Sep(file1);
2851 fmt::print("\nCOORDINATES absolute 1.e-6 # min separation = {}\n", min_separation);
2852 }
2853 else {
2854 fmt::print("\nCOORDINATES absolute 1.e-6 # min separation not calculated\n");
2855 }
2856
2857 if (file1.Num_Times() > 0) {
2858 fmt::print("\nTIME STEPS relative 1.e-6 floor 0.0 # min: ");
2859 fmt::print("{:15.8g} @ t{} max: {:15.8g} @ t{}\n", mm_time.min_val, mm_time.min_step,
2860 mm_time.max_val, mm_time.max_step);
2861 }
2862 else {
2863 fmt::print("\n# No TIME STEPS\n");
2864 }
2865
2866 n = interFace.glob_var_names.size();
2867 if (n > 0) {
2868 fmt::print("GLOBAL VARIABLES relative 1.e-6 floor 0.0\n");
2869 for (i = 0; i < n; ++i) {
2870 fmt::print("\t{:<{}} # min: {:15.8g} @ t{}\tmax: {:15.8g} @ t{}\n",
2871 ((interFace.glob_var_names)[i]), name_length(), mm_glob[i].min_val,
2872 mm_glob[i].min_step, mm_glob[i].max_val, mm_glob[i].max_step);
2873 }
2874 }
2875 else {
2876 fmt::print("\n# No GLOBAL VARIABLES\n");
2877 }
2878
2879 n = interFace.node_var_names.size();
2880 if (n > 0 && file1.Num_Nodes() > 0) {
2881 fmt::print("\nNODAL VARIABLES relative 1.e-6 floor 0.0\n");
2882 for (i = 0; i < n; ++i) {
2883 fmt::print("\t{:<{}} # min: {:15.8g} @ t{},n{}\tmax: {:15.8g} @ t{},n{}\n",
2884 ((interFace.node_var_names)[i]), name_length(), mm_node[i].min_val,
2885 mm_node[i].min_step, node_id_map[mm_node[i].min_id], mm_node[i].max_val,
2886 mm_node[i].max_step, node_id_map[mm_node[i].max_id]);
2887 }
2888 }
2889 else {
2890 fmt::print("\n# No NODAL VARIABLES and/or NODES\n");
2891 }
2892
2893 n = interFace.elmt_var_names.size();
2894 if (n > 0 && file1.Num_Elements() > 0) {
2895 fmt::print("\nELEMENT VARIABLES relative 1.e-6 floor 0.0\n");
2896 for (i = 0; i < n; ++i) {
2897 fmt::print("\t{:<{}} # min: {:15.8g} @ t{},b{},e{}\tmax: {:15.8g} @ t{},b{}"
2898 ",e{}\n",
2899 ((interFace.elmt_var_names)[i]), name_length(), mm_elmt[i].min_val,
2900 mm_elmt[i].min_step, mm_elmt[i].min_blk, elem_id_map[mm_elmt[i].min_id],
2901 mm_elmt[i].max_val, mm_elmt[i].max_step, mm_elmt[i].max_blk,
2902 elem_id_map[mm_elmt[i].max_id]);
2903 }
2904 }
2905 else {
2906 fmt::print("\n# No ELEMENT VARIABLES and/or ELEMENTS\n");
2907 }
2908
2909 n = interFace.ns_var_names.size();
2910 if (n > 0) {
2911 fmt::print("\nNODESET VARIABLES relative 1.e-6 floor 0.0\n");
2912 for (i = 0; i < n; ++i) {
2913 Node_Set<INT> *nsmin = file1.Get_Node_Set_by_Id(mm_ns[i].min_blk);
2914 Node_Set<INT> *nsmax = file1.Get_Node_Set_by_Id(mm_ns[i].max_blk);
2915 fmt::print("\t{:<{}} # min: {:15.8g} @ t{},s{},n{}\tmax: {:15.8g} @ t{},s{}"
2916 ",n{}\n",
2917 ((interFace.ns_var_names)[i]), name_length(), mm_ns[i].min_val, mm_ns[i].min_step,
2918 mm_ns[i].min_blk, node_id_map[nsmin->Node_Id(mm_ns[i].min_id) - 1],
2919 mm_ns[i].max_val, mm_ns[i].max_step, mm_ns[i].max_blk,
2920 node_id_map[nsmax->Node_Id(mm_ns[i].max_id) - 1]);
2921 }
2922 }
2923 else {
2924 fmt::print("\n# No NODESET VARIABLES\n");
2925 }
2926
2927 n = interFace.ss_var_names.size();
2928 if (n > 0) {
2929 fmt::print("\nSIDESET VARIABLES relative 1.e-6 floor 0.0\n");
2930 for (i = 0; i < n; ++i) {
2931 Side_Set<INT> *ssmin = file1.Get_Side_Set_by_Id(mm_ss[i].min_blk);
2932 Side_Set<INT> *ssmax = file1.Get_Side_Set_by_Id(mm_ss[i].max_blk);
2933 std::pair<INT, INT> min_side = ssmin->Side_Id(mm_ss[i].min_id);
2934 std::pair<INT, INT> max_side = ssmax->Side_Id(mm_ss[i].max_id);
2935 fmt::print("\t{:<{}} # min: {:15.8g} @ t{},s{},f{}.{}\tmax: {:15.8g} @ t{},s{}"
2936 ",f{}.{}\n",
2937 ((interFace.ss_var_names)[i]), name_length(), mm_ss[i].min_val, mm_ss[i].min_step,
2938 mm_ss[i].min_blk, elem_id_map[min_side.first - 1], min_side.second,
2939 mm_ss[i].max_val, mm_ss[i].max_step, mm_ss[i].max_blk,
2940 elem_id_map[max_side.first - 1], max_side.second);
2941 }
2942 }
2943 else {
2944 fmt::print("\n# No SIDESET VARIABLES\n");
2945 }
2946
2947 n = interFace.eb_var_names.size();
2948 if (n > 0) {
2949 fmt::print("\nEDGE BLOCK VARIABLES relative 1.e-6 floor 0.0\n");
2950 for (i = 0; i < n; ++i) {
2951 fmt::print("\t{:<{}} # min: {:15.8g} @ t{},b{},e{}\tmax: {:15.8g} @ t{},b{}"
2952 ",e{}\n",
2953 ((interFace.eb_var_names)[i]), name_length(), mm_eb[i].min_val, mm_eb[i].min_step,
2954 mm_eb[i].min_blk, mm_eb[i].min_id + 1, mm_eb[i].max_val, mm_eb[i].max_step,
2955 mm_eb[i].max_blk, mm_eb[i].max_id + 1);
2956 }
2957 }
2958 else {
2959 fmt::print("\n# No EDGE BLOCK VARIABLES\n");
2960 }
2961
2962 n = interFace.fb_var_names.size();
2963 if (n > 0) {
2964 fmt::print("\nFACE BLOCK VARIABLES relative 1.e-6 floor 0.0\n");
2965 for (i = 0; i < n; ++i) {
2966 fmt::print("\t{:<{}} # min: {:15.8g} @ t{},b{},f{}\tmax: {:15.8g} @ t{},b{}"
2967 ",f{}\n",
2968 ((interFace.fb_var_names)[i]), name_length(), mm_fb[i].min_val, mm_fb[i].min_step,
2969 mm_fb[i].min_blk, mm_fb[i].min_id + 1, mm_fb[i].max_val, mm_fb[i].max_step,
2970 mm_fb[i].max_blk, mm_fb[i].max_id + 1);
2971 }
2972 }
2973 else {
2974 fmt::print("\n# No FACE BLOCK VARIABLES\n");
2975 }
2976 fmt::print("\n");
2977 }
2978
2979 int timeStepIsExcluded(int ts)
2980 {
2981 for (const auto &elem : interFace.exclude_steps) {
2982 if (ts == elem) {
2983 return 1;
2984 }
2985 }
2986 return 0;
2987 }