Debian Codegraph @

packages/seacas/applications/exodiff/exo_read.C

raw
1 // Copyright(C) 1999-2024 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "ED_SystemInterface.h" // for SystemInterface, etc
8 #include "assembly.h"
9 #include "edge_block.h" // for Edge_Block
10 #include "exo_block.h" // for Exo_Block
11 #include "exo_read.h"
12 #include "exodusII.h" // for ex_init_params, ex_opts, etc
13 #include "face_block.h" // for Face_Block
14 #include "fmt/ostream.h"
15 #include "fmt/ranges.h"
16 #include "node_set.h" // for Node_Set
17 #include "side_set.h" // for Side_Set
18 #include "smart_assert.h" // for SMART_ASSERT, Assert, etc
19 #include "stringx.h" // for chop_whitespace
20 #include "util.h" // for free_name_array, etc
21 #include <algorithm> // for copy
22 #include <cstdint> // for int64_t
23 #include <cstdio> // for fclose, FILE, fopen
24 #include <cstdlib> // for exit
25 #include <cstring> // for strlen
26 #include <iostream>
27 #include <set> // for set
28 #include <string> // for string, char_traits, etc
29 #include <vector> // for vector
30
31 namespace {
32 void read_vars(int file_id, EXOTYPE flag, const char *type, int num_vars, NameList &varlist);
33 void query_change_sets(int file_id, NameList &names, bool return_full_names);
34 } // namespace
35
36 template <typename INT> Exo_Read<INT>::Exo_Read(std::string fname) : file_name(std::move(fname))
37 {
38 if (!file_name.empty()) {
39 int ws = 0, comp_ws = 8;
40 float dumb = 0.0;
41 int mode = EX_READ;
42 if (sizeof(INT) == 8) {
43 mode |= EX_ALL_INT64_API;
44 }
45 auto old_opt = ex_opts(EX_VERBOSE);
46 int err = ex_open(file_name.c_str(), mode, &comp_ws, &ws, &dumb);
47 ex_opts(old_opt);
48 if (err < 0) {
49 std::ostringstream oss;
50 fmt::print(oss, "Couldn't open file \"{}\".", file_name);
51
52 // ExodusII library could not open file. See if a file (exodusII
53 // or not) exists with the specified name.
54 FILE *fid = fopen(file_name.c_str(), "r");
55 if (fid != nullptr) {
56 fmt::print(oss, " File exists, but library could not open.");
57 fclose(fid);
58 }
59 else {
60 fmt::print(oss, " File does not exist.");
61 }
62 throw std::runtime_error(oss.str());
63 }
64 file_id = err;
65 io_word_size = ws;
66
67 // See if file contains change sets... If it does, open the first child change set (assumes all
68 // valid data are in change sets...)
69 num_change_sets = ex_inquire_int(file_id, EX_INQ_NUM_CHILD_GROUPS);
70 if (num_change_sets > 0) {
71 change_set_ids.resize(num_change_sets);
72 ex_get_group_ids(file_id, nullptr, change_set_ids.data());
73
74 query_change_sets(file_id, change_set_names, false);
75
76 // current_change_set_index = 0;
77 // file_id = change_set_ids[current_change_set_index];
78 }
79 }
80 }
81
82 template <typename INT> void Exo_Read<INT>::Reset_Meta_Data()
83 {
84 delete[] eblocks;
85 eblocks = nullptr;
86 delete[] nsets;
87 nsets = nullptr;
88 delete[] ssets;
89 ssets = nullptr;
90 delete[] nodes;
91 nodes = nullptr;
92 delete[] edge_blocks;
93 edge_blocks = nullptr;
94 delete[] face_blocks;
95 face_blocks = nullptr;
96 delete[] assemblies;
97 assemblies = nullptr;
98
99 #if 1
100 if (results) {
101 for (unsigned i = 0; i < nodal_vars.size(); ++i) {
102 if (results[i]) {
103 delete[] results[i];
104 results[i] = nullptr;
105 }
106 }
107 delete[] results;
108 results = nullptr;
109 }
110 nodal_vars.clear();
111 #endif
112
113 delete[] global_vals;
114 global_vals = nullptr;
115 delete[] global_vals2;
116 global_vals2 = nullptr;
117 delete[] node_map;
118 node_map = nullptr;
119 delete[] elmt_map;
120 elmt_map = nullptr;
121
122 num_nodes = 0;
123 dimension = 0;
124 num_elmts = 0;
125 num_faces = 0;
126 num_edges = 0;
127 num_elmt_blocks = 0;
128 num_node_sets = 0;
129 num_side_sets = 0;
130 num_edge_blocks = 0;
131 num_face_blocks = 0;
132 num_assemblies = 0;
133
134 global_vars.clear();
135 nodal_vars.clear();
136 elmt_vars.clear();
137 elmt_atts.clear();
138 ns_vars.clear();
139 ss_vars.clear();
140 eb_vars.clear();
141 fb_vars.clear();
142
143 times.clear();
144 cur_time = 0;
145 }
146
147 template <typename INT> Exo_Read<INT>::~Exo_Read()
148 {
149 try {
150 SMART_ASSERT(Check_State());
151
152 if (file_id >= 0) {
153 std::string err = Close_File();
154 if (!err.empty()) {
155 Error(fmt::format("Exo_Read destructor(): closing file: \"{}\"\n", err));
156 }
157 }
158 Reset_Meta_Data();
159 }
160 catch (...) {
161 }
162 }
163
164 template <typename INT> std::string Exo_Read<INT>::Close_File()
165 {
166 SMART_ASSERT(Check_State());
167
168 if (file_id < 0) {
169 return "exodiff: ERROR: File is not open!";
170 }
171 int err = ex_close(file_id);
172
173 if (err < 0) {
174 Error(fmt::format("Exo_Read::Close_File(): {}: Unable to close file! Aborting...\n", err));
175 }
176 if (err > 0) {
177 return fmt::format("WARNING: {} issued upon close", err);
178 }
179
180 file_id = -1;
181
182 return "";
183 }
184
185 template <typename INT> double Exo_Read<INT>::Time(int time_num) const
186 {
187 SMART_ASSERT(Check_State());
188 SMART_ASSERT(time_num > 0 && time_num <= Num_Times())(time_num)(Num_Times());
189 return times[time_num - 1];
190 }
191
192 template <typename INT> const std::string &Exo_Read<INT>::Global_Var_Name(int index) const
193 {
194 SMART_ASSERT(Check_State());
195 SMART_ASSERT(index >= 0 && (unsigned)index < global_vars.size());
196 return global_vars[index];
197 }
198
199 template <typename INT> const std::string &Exo_Read<INT>::Nodal_Var_Name(int index) const
200 {
201 SMART_ASSERT(Check_State());
202 SMART_ASSERT(index >= 0 && (unsigned)index < nodal_vars.size());
203 return nodal_vars[index];
204 }
205
206 template <typename INT> const std::string &Exo_Read<INT>::Element_Var_Name(int index) const
207 {
208 SMART_ASSERT(Check_State());
209 SMART_ASSERT(index >= 0 && (unsigned)index < elmt_vars.size());
210 return elmt_vars[index];
211 }
212
213 template <typename INT> const std::string &Exo_Read<INT>::Element_Att_Name(int index) const
214 {
215 SMART_ASSERT(Check_State());
216 SMART_ASSERT(index >= 0 && (unsigned)index < elmt_atts.size());
217 return elmt_atts[index];
218 }
219
220 template <typename INT> const std::string &Exo_Read<INT>::NS_Var_Name(int index) const
221 {
222 SMART_ASSERT(Check_State());
223 SMART_ASSERT(index >= 0 && (unsigned)index < ns_vars.size());
224 return ns_vars[index];
225 }
226
227 template <typename INT> const std::string &Exo_Read<INT>::SS_Var_Name(int index) const
228 {
229 SMART_ASSERT(Check_State());
230 SMART_ASSERT(index >= 0 && (unsigned)index < ss_vars.size());
231 return ss_vars[index];
232 }
233
234 template <typename INT> const std::string &Exo_Read<INT>::EB_Var_Name(int index) const
235 {
236 SMART_ASSERT(Check_State());
237 SMART_ASSERT(index >= 0 && (unsigned)index < eb_vars.size());
238 return eb_vars[index];
239 }
240
241 template <typename INT> const std::string &Exo_Read<INT>::FB_Var_Name(int index) const
242 {
243 SMART_ASSERT(Check_State());
244 SMART_ASSERT(index >= 0 && (unsigned)index < fb_vars.size());
245 return fb_vars[index];
246 }
247
248 template <typename INT>
249 Exo_Block<INT> *Exo_Read<INT>::Get_Element_Block_by_Index(size_t block_index) const
250 {
251 SMART_ASSERT(Check_State());
252 SMART_ASSERT(block_index < num_elmt_blocks);
253 return &eblocks[block_index];
254 }
255
256 template <typename INT> Exo_Block<INT> *Exo_Read<INT>::Get_Element_Block_by_Id(size_t id) const
257 {
258 SMART_ASSERT(Check_State());
259 for (size_t i = 0; i < num_elmt_blocks; i++) {
260 if (eblocks[i].Id() == id) {
261 return &eblocks[i];
262 }
263 }
264 return nullptr;
265 }
266
267 template <typename INT>
268 Exo_Block<INT> *Exo_Read<INT>::Get_Element_Block_by_Name(const std::string &name) const
269 {
270 SMART_ASSERT(Check_State());
271 for (size_t i = 0; i < num_elmt_blocks; i++) {
272 if (eblocks[i].Name() == name) {
273 return &eblocks[i];
274 }
275 }
276 return nullptr;
277 }
278
279 template <typename INT>
280 Assembly<INT> *Exo_Read<INT>::Get_Assembly_by_Index(size_t block_index) const
281 {
282 SMART_ASSERT(Check_State());
283 SMART_ASSERT(block_index < num_assemblies);
284 return &assemblies[block_index];
285 }
286
287 template <typename INT>
288 Assembly<INT> *Exo_Read<INT>::Get_Assembly_by_Name(const std::string &name) const
289 {
290 SMART_ASSERT(Check_State());
291 for (size_t i = 0; i < num_assemblies; i++) {
292 if (assemblies[i].Name() == name) {
293 return &assemblies[i];
294 }
295 }
296 return nullptr;
297 }
298
299 template <typename INT> Assembly<INT> *Exo_Read<INT>::Get_Assembly_by_Id(size_t set_id) const
300 {
301 SMART_ASSERT(Check_State());
302 for (size_t i = 0; i < num_assemblies; i++) {
303 if (assemblies[i].Id() == set_id) {
304 return &assemblies[i];
305 }
306 }
307 return nullptr;
308 }
309
310 template <typename INT>
311 Exo_Entity *Exo_Read<INT>::Get_Entity_by_Index(EXOTYPE type, size_t block_index) const
312 {
313 SMART_ASSERT(Check_State());
314
315 switch (type) {
316 case EX_ELEM_BLOCK: SMART_ASSERT(block_index < num_elmt_blocks); return &eblocks[block_index];
317 case EX_NODE_SET: SMART_ASSERT(block_index < num_node_sets); return &nsets[block_index];
318 case EX_SIDE_SET: SMART_ASSERT(block_index < num_side_sets); return &ssets[block_index];
319 case EX_EDGE_BLOCK: SMART_ASSERT(block_index < num_edge_blocks); return &edge_blocks[block_index];
320 case EX_FACE_BLOCK: SMART_ASSERT(block_index < num_face_blocks); return &face_blocks[block_index];
321 case EX_ASSEMBLY: SMART_ASSERT(block_index < num_assemblies); return &assemblies[block_index];
322 default: return nullptr;
323 }
324 }
325
326 template <typename INT> Exo_Entity *Exo_Read<INT>::Get_Entity_by_Id(EXOTYPE type, size_t id) const
327 {
328 SMART_ASSERT(Check_State());
329 switch (type) {
330 case EX_ELEM_BLOCK:
331 for (size_t i = 0; i < num_elmt_blocks; i++) {
332 if (eblocks[i].Id() == id) {
333 return &eblocks[i];
334 }
335 }
336 break;
337 case EX_NODE_SET:
338 for (size_t i = 0; i < num_node_sets; i++) {
339 if (nsets[i].Id() == id) {
340 return &nsets[i];
341 }
342 }
343 break;
344 case EX_SIDE_SET:
345 for (size_t i = 0; i < num_side_sets; i++) {
346 if (ssets[i].Id() == id) {
347 return &ssets[i];
348 }
349 }
350 break;
351 case EX_EDGE_BLOCK:
352 for (size_t i = 0; i < num_edge_blocks; i++) {
353 if (edge_blocks[i].Id() == id) {
354 return &edge_blocks[i];
355 }
356 }
357 break;
358 case EX_FACE_BLOCK:
359 for (size_t i = 0; i < num_face_blocks; i++) {
360 if (face_blocks[i].Id() == id) {
361 return &face_blocks[i];
362 }
363 }
364 break;
365 case EX_ASSEMBLY:
366 for (size_t i = 0; i < num_assemblies; i++) {
367 if (assemblies[i].Id() == id) {
368 return &assemblies[i];
369 }
370 }
371 break;
372 default: return nullptr;
373 }
374 return nullptr;
375 }
376
377 template <typename INT>
378 Exo_Entity *Exo_Read<INT>::Get_Entity_by_Name(EXOTYPE type, const std::string &name) const
379 {
380 SMART_ASSERT(Check_State());
381 switch (type) {
382 case EX_ELEM_BLOCK:
383 for (size_t i = 0; i < num_elmt_blocks; i++) {
384 if (eblocks[i].Name() == name) {
385 return &eblocks[i];
386 }
387 }
388 break;
389 case EX_NODE_SET:
390 for (size_t i = 0; i < num_node_sets; i++) {
391 if (nsets[i].Name() == name) {
392 return &nsets[i];
393 }
394 }
395 break;
396 case EX_SIDE_SET:
397 for (size_t i = 0; i < num_side_sets; i++) {
398 if (ssets[i].Name() == name) {
399 return &ssets[i];
400 }
401 }
402 break;
403 case EX_EDGE_BLOCK:
404 for (size_t i = 0; i < num_edge_blocks; i++) {
405 if (edge_blocks[i].Name() == name) {
406 return &edge_blocks[i];
407 }
408 }
409 break;
410 case EX_FACE_BLOCK:
411 for (size_t i = 0; i < num_face_blocks; i++) {
412 if (face_blocks[i].Name() == name) {
413 return &face_blocks[i];
414 }
415 }
416 break;
417 case EX_ASSEMBLY:
418 for (size_t i = 0; i < num_assemblies; i++) {
419 if (assemblies[i].Name() == name) {
420 return &assemblies[i];
421 }
422 }
423 break;
424 default: return nullptr;
425 }
426 return nullptr;
427 }
428
429 template <typename INT> Node_Set<INT> *Exo_Read<INT>::Get_Node_Set_by_Id(size_t set_id) const
430 {
431 SMART_ASSERT(Check_State());
432 for (size_t i = 0; i < num_node_sets; i++) {
433 if (nsets[i].Id() == set_id) {
434 return &nsets[i];
435 }
436 }
437 return nullptr;
438 }
439
440 template <typename INT>
441 Node_Set<INT> *Exo_Read<INT>::Get_Node_Set_by_Name(const std::string &name) const
442 {
443 SMART_ASSERT(Check_State());
444 for (size_t i = 0; i < num_node_sets; i++) {
445 if (nsets[i].Name() == name) {
446 return &nsets[i];
447 }
448 }
449 return nullptr;
450 }
451
452 template <typename INT> Side_Set<INT> *Exo_Read<INT>::Get_Side_Set_by_Id(size_t set_id) const
453 {
454 SMART_ASSERT(Check_State());
455 for (size_t i = 0; i < num_side_sets; i++) {
456 if (ssets[i].Id() == set_id) {
457 return &ssets[i];
458 }
459 }
460 return nullptr;
461 }
462
463 template <typename INT>
464 Side_Set<INT> *Exo_Read<INT>::Get_Side_Set_by_Name(const std::string &name) const
465 {
466 SMART_ASSERT(Check_State());
467 for (size_t i = 0; i < num_side_sets; i++) {
468 if (ssets[i].Name() == name) {
469 return &ssets[i];
470 }
471 }
472 return nullptr;
473 }
474
475 template <typename INT> Edge_Block<INT> *Exo_Read<INT>::Get_Edge_Block_by_Id(size_t block_id) const
476 {
477 SMART_ASSERT(Check_State());
478 for (size_t i = 0; i < num_edge_blocks; i++) {
479 if (edge_blocks[i].Id() == block_id) {
480 return &edge_blocks[i];
481 }
482 }
483 return nullptr;
484 }
485
486 template <typename INT>
487 Edge_Block<INT> *Exo_Read<INT>::Get_Edge_Block_by_Name(const std::string &name) const
488 {
489 SMART_ASSERT(Check_State());
490 for (size_t i = 0; i < num_edge_blocks; i++) {
491 if (edge_blocks[i].Name() == name) {
492 return &edge_blocks[i];
493 }
494 }
495 return nullptr;
496 }
497
498 template <typename INT> Face_Block<INT> *Exo_Read<INT>::Get_Face_Block_by_Id(size_t block_id) const
499 {
500 SMART_ASSERT(Check_State());
501 for (size_t i = 0; i < num_face_blocks; i++) {
502 if (face_blocks[i].Id() == block_id) {
503 return &face_blocks[i];
504 }
505 }
506 return nullptr;
507 }
508
509 template <typename INT>
510 Face_Block<INT> *Exo_Read<INT>::Get_Face_Block_by_Name(const std::string &name) const
511 {
512 SMART_ASSERT(Check_State());
513 for (size_t i = 0; i < num_face_blocks; i++) {
514 if (face_blocks[i].Name() == name) {
515 return &face_blocks[i];
516 }
517 }
518 return nullptr;
519 }
520
521 template <typename INT>
522 std::string Exo_Read<INT>::Load_Element_Block_Description(size_t block_index) const
523 {
524 SMART_ASSERT(Check_State());
525 if (!Open()) {
526 return "exodiff: ERROR: Must open file before loading blocks!";
527 }
528 SMART_ASSERT(block_index < num_elmt_blocks);
529
530 eblocks[block_index].Load_Connectivity();
531 // eblocks[idx].Load_Connectivity();
532 // eblocks[idx].Load_Attributes();
533
534 return "";
535 }
536
537 template <typename INT> std::string Exo_Read<INT>::Load_Element_Block_Descriptions() const
538 {
539 SMART_ASSERT(Check_State());
540 if (!Open()) {
541 return "exodiff: ERROR: Must open file before loading blocks!";
542 }
543 for (size_t b = 0; b < num_elmt_blocks; ++b) {
544 eblocks[b].Load_Connectivity();
545 }
546
547 return "";
548 }
549
550 template <typename INT> std::string Exo_Read<INT>::Free_Element_Block(size_t block_index) const
551 {
552 SMART_ASSERT(Check_State());
553
554 SMART_ASSERT(block_index < num_elmt_blocks);
555
556 eblocks[block_index].Free_Connectivity();
557 eblocks[block_index].Free_Attributes();
558
559 return "";
560 }
561
562 template <typename INT> std::string Exo_Read<INT>::Free_Element_Blocks() const
563 {
564 SMART_ASSERT(Check_State());
565
566 for (size_t b = 0; b < num_elmt_blocks; ++b) {
567 eblocks[b].Free_Connectivity();
568 eblocks[b].Free_Attributes();
569 }
570
571 return "";
572 }
573
574 template <typename INT> size_t Exo_Read<INT>::Block_Id(size_t block_index) const
575 {
576 SMART_ASSERT(Check_State());
577 SMART_ASSERT(block_index < num_elmt_blocks);
578 return eblocks[block_index].Id();
579 }
580
581 template <typename INT> std::string Exo_Read<INT>::Load_Node_Map()
582 {
583 SMART_ASSERT(Check_State());
584
585 if (!Open()) {
586 return "WARNING: File not open!";
587 }
588 delete[] node_map;
589 node_map = nullptr;
590
591 if (num_nodes == 0) {
592 return "WARNING: There are no nodes!";
593 }
594 node_map = new INT[num_nodes];
595 SMART_ASSERT(node_map != nullptr);
596
597 ex_opts(0); // Temporarily turn off error reporting in case map isn't stored.
598 int err = ex_get_id_map(file_id, EX_NODE_MAP, node_map);
599 ex_opts(EX_VERBOSE);
600
601 if (err < 0) {
602 Error(fmt::format("Unable to load node map; Exodus error = {}. Aborting...\n", err));
603 }
604 else if (err > 0) {
605 return "WARNING: Default node map being used.";
606 }
607 return "";
608 }
609
610 template <typename INT> std::string Exo_Read<INT>::Free_Node_Map()
611 {
612 SMART_ASSERT(Check_State());
613
614 delete[] node_map;
615 node_map = nullptr;
616
617 return "";
618 }
619
620 template <typename INT> std::string Exo_Read<INT>::Load_Element_Map()
621 {
622 SMART_ASSERT(Check_State());
623
624 if (!Open()) {
625 return "WARNING: File not open!";
626 }
627 delete[] elmt_map;
628 elmt_map = nullptr;
629
630 if (num_elmts == 0) {
631 return "WARNING: There are no elements!";
632 }
633 elmt_map = new INT[num_elmts];
634 SMART_ASSERT(elmt_map != nullptr);
635
636 ex_opts(0); // Temporarily turn off error reporting in case map isn't stored.
637 int err = ex_get_id_map(file_id, EX_ELEM_MAP, elmt_map);
638 ex_opts(EX_VERBOSE);
639
640 if (err < 0) {
641 Error(fmt::format("Unable to load element map; Exodus error = {}. Aborting...\n", err));
642 }
643 else if (err > 0) {
644 return "WARNING: Default element map being used.";
645 }
646 return "";
647 }
648
649 template <typename INT> std::string Exo_Read<INT>::Free_Element_Map()
650 {
651 SMART_ASSERT(Check_State());
652
653 delete[] elmt_map;
654 elmt_map = nullptr;
655
656 return "";
657 }
658
659 template <typename INT> std::string Exo_Read<INT>::Load_Nodal_Coordinates()
660 {
661 SMART_ASSERT(Check_State());
662
663 if (!Open()) {
664 return "WARNING: File not open!";
665 }
666 if (num_nodes) {
667 size_t count = num_nodes * dimension;
668 nodes = new double[count];
669 SMART_ASSERT(nodes != nullptr);
670 double *x = nodes, *y = nodes, *z = nodes;
671 if (dimension > 1) {
672 y = nodes + num_nodes;
673 }
674 if (dimension > 2) {
675 z = nodes + (2 * num_nodes);
676 }
677
678 int err = ex_get_coord(file_id, x, y, z);
679 if (err < 0) {
680 Error("Failed to get nodal coordinates! Aborting...\n");
681 }
682 else if (err > 0) {
683 delete[] nodes;
684 nodes = nullptr;
685 return fmt::format("exodiff: WARNING: "
686 "Exodus issued warning \"{}\" on call to ex_get_coord()!"
687 " I'm not going to keep what it gave me for coordinates.",
688 err);
689 }
690 }
691 else {
692 return "WARNING: There are no nodes!";
693 }
694 return "";
695 }
696
697 template <typename INT> void Exo_Read<INT>::Free_Nodal_Coordinates()
698 {
699 SMART_ASSERT(Check_State());
700 delete[] nodes;
701 nodes = nullptr;
702 }
703
704 template <typename INT>
705 std::string Exo_Read<INT>::Load_Nodal_Results(int time_step_num, int var_index)
706 {
707 SMART_ASSERT(Check_State());
708 SMART_ASSERT(time_step_num > 0 && time_step_num <= Num_Times());
709 SMART_ASSERT(var_index >= 0 && (unsigned)var_index < nodal_vars.size());
710
711 if (!Open()) {
712 return "WARNING: File not open!";
713 }
714 if (cur_time != time_step_num) {
715 for (unsigned i = 0; i < nodal_vars.size(); ++i) {
716 if (results[i]) {
717 delete[] results[i];
718 results[i] = nullptr;
719 }
720 }
721 cur_time = time_step_num;
722 }
723
724 if (num_nodes) {
725 results[var_index] = new double[num_nodes];
726
727 int err =
728 ex_get_var(file_id, cur_time, EX_NODAL, var_index + 1, 0, num_nodes, results[var_index]);
729 if (err < 0) {
730 Error("Exo_Read::Load_Nodal_Results(): Failed to get "
731 "nodal variable values! Aborting...\n");
732 }
733 else if (err > 0) {
734 if (results[var_index]) {
735 delete[] results[var_index];
736 results[var_index] = nullptr;
737 return fmt::format("Exo_Read::Load_Nodal_Results(): WARNING: "
738 "Exodus issued warning \"{}\" on call to ex_get_var()!"
739 " I'm not going to keep what it gave me for values.",
740 err);
741 }
742 }
743 }
744 else {
745 return "WARNING: There are no nodes!";
746 }
747 return "";
748 }
749
750 template <typename INT>
751 const double *Exo_Read<INT>::Get_Nodal_Results(int t1, int t2, double proportion,
752 int var_index) const // Interpolated results.
753 {
754 static std::vector<double> st_results;
755 static std::vector<double> st_results2;
756
757 SMART_ASSERT(Check_State());
758 SMART_ASSERT(t1 > 0 && t1 <= Num_Times());
759 SMART_ASSERT(t2 > 0 && t2 <= Num_Times());
760 SMART_ASSERT(var_index >= 0 && (unsigned)var_index < nodal_vars.size());
761
762 if (!Open()) {
763 return nullptr;
764 }
765
766 st_results.resize(num_nodes);
767 int err = ex_get_var(file_id, t1, EX_NODAL, var_index + 1, 0, num_nodes, st_results.data());
768 if (err < 0) {
769 Error("Exo_Read::Get_Nodal_Results(): Failed to get "
770 "nodal variable values! Aborting...\n");
771 }
772
773 if (t1 != t2) {
774 st_results2.resize(num_nodes);
775 err = ex_get_var(file_id, t2, EX_NODAL, var_index + 1, 0, num_nodes, st_results2.data());
776 if (err < 0) {
777 Error("Exo_Read::Load_Nodal_Results(): Failed to get "
778 "nodal variable values! Aborting...\n");
779 }
780
781 // Interpolate the values...
782 for (size_t i = 0; i < num_nodes; i++) {
783 st_results[i] = (1.0 - proportion) * st_results[i] + proportion * st_results2[i];
784 }
785 }
786 return st_results.data();
787 }
788
789 template <typename INT> void Exo_Read<INT>::Free_Nodal_Results()
790 {
791 SMART_ASSERT(Check_State());
792 if (results) {
793 for (unsigned i = 0; i < nodal_vars.size(); ++i) {
794 if (results[i]) {
795 delete[] results[i];
796 results[i] = nullptr;
797 }
798 }
799 }
800 }
801
802 template <typename INT> void Exo_Read<INT>::Free_Nodal_Results(int var_index)
803 {
804 SMART_ASSERT(Check_State());
805 if (results) {
806 if (results[var_index]) {
807 delete[] results[var_index];
808 results[var_index] = nullptr;
809 }
810 }
811 }
812
813 template <typename INT> const double *Exo_Read<INT>::Get_Nodal_Results(int var_index) const
814 {
815 SMART_ASSERT(Check_State());
816 if (cur_time == 0) {
817 return nullptr;
818 }
819 SMART_ASSERT(var_index >= 0 && (unsigned)var_index < nodal_vars.size());
820
821 return results[var_index];
822 }
823
824 template <typename INT> std::string Exo_Read<INT>::Load_Global_Results(int time_step_num)
825 {
826 SMART_ASSERT(Check_State());
827 SMART_ASSERT(time_step_num > 0 && time_step_num <= Num_Times());
828
829 if (!Open()) {
830 return "WARNING: File not open!";
831 }
832 if (global_vars.empty()) {
833 return "WARNING: No global variables! (doing nothing)";
834 }
835
836 if (global_vals == nullptr) {
837 global_vals = new double[global_vars.size()];
838 SMART_ASSERT(global_vals != nullptr);
839 }
840
841 for (unsigned j = 0; j < global_vars.size(); ++j) {
842 global_vals[j] = 0.0;
843 }
844
845 int err = ex_get_var(file_id, time_step_num, EX_GLOBAL, 1, 1, global_vars.size(), global_vals);
846
847 if (err < 0) {
848 Error("Exo_Read::Load_Global_Results(): Failed to get "
849 "global variable values! Aborting...\n");
850 }
851 else if (err > 0) {
852 return fmt::format("Exo_Read::Load_Global_Results(): WARNING: "
853 "Exodus issued warning \"{}\" on call to ex_get_glob_vars()!",
854 err);
855 }
856 return "";
857 }
858
859 template <typename INT>
860 std::string Exo_Read<INT>::Load_Global_Results(int t1, int t2, double proportion)
861 {
862 SMART_ASSERT(Check_State());
863 SMART_ASSERT(t1 > 0 && t1 <= Num_Times());
864 SMART_ASSERT(t2 > 0 && t2 <= Num_Times());
865
866 if (!Open()) {
867 return "WARNING: File not open!";
868 }
869 if (global_vars.empty()) {
870 return "WARNING: No global variables! (doing nothing)";
871 }
872 if (global_vals == nullptr) {
873 global_vals = new double[global_vars.size()];
874 SMART_ASSERT(global_vals != nullptr);
875 }
876
877 if (t2 != t1 && (global_vals2 == nullptr)) {
878 global_vals2 = new double[global_vars.size()];
879 SMART_ASSERT(global_vals2 != nullptr);
880 }
881
882 for (unsigned j = 0; j < global_vars.size(); ++j) {
883 global_vals[j] = 0.0;
884 }
885
886 int err = ex_get_var(file_id, t1, EX_GLOBAL, 1, 1, global_vars.size(), global_vals);
887
888 if (err < 0) {
889 Error("Exo_Read::Load_Global_Results(): Failed to get "
890 "global variable values! Aborting...\n");
891 }
892
893 if (t2 != t1) {
894 err = ex_get_var(file_id, t2, EX_GLOBAL, 1, 1, global_vars.size(), global_vals2);
895 if (err < 0) {
896 Error("Exo_Read::Load_Global_Results(): Failed to get "
897 "global variable values! Aborting...\n");
898 }
899
900 // Do the interpolation...
901 for (size_t j = 0; j < global_vars.size(); j++) {
902 global_vals[j] = (1.0 - proportion) * global_vals[j] + proportion * global_vals2[j];
903 }
904 }
905 return "";
906 }
907
908 template <typename INT>
909 Side_Set<INT> *Exo_Read<INT>::Get_Side_Set_by_Index(size_t side_set_index) const
910 {
911 SMART_ASSERT(Check_State());
912
913 if (side_set_index >= num_side_sets) {
914 return nullptr;
915 }
916
917 return &ssets[side_set_index];
918 }
919
920 template <typename INT> Node_Set<INT> *Exo_Read<INT>::Get_Node_Set_by_Index(size_t set_index) const
921 {
922 SMART_ASSERT(Check_State());
923
924 if (set_index >= num_node_sets) {
925 return nullptr;
926 }
927
928 return &nsets[set_index];
929 }
930
931 template <typename INT>
932 Edge_Block<INT> *Exo_Read<INT>::Get_Edge_Block_by_Index(size_t edge_block_index) const
933 {
934 SMART_ASSERT(Check_State());
935
936 if (edge_block_index >= num_edge_blocks) {
937 return nullptr;
938 }
939
940 return &edge_blocks[edge_block_index];
941 }
942
943 template <typename INT>
944 Face_Block<INT> *Exo_Read<INT>::Get_Face_Block_by_Index(size_t face_block_index) const
945 {
946 SMART_ASSERT(Check_State());
947
948 if (face_block_index >= num_face_blocks) {
949 return nullptr;
950 }
951
952 return &face_blocks[face_block_index];
953 }
954
955 // ********************** Misc functions *************************** //
956
957 // This function converts an Exodus global element number (1-offset) into
958 // its block index (0-offset) and block element index (0-offset).
959 template <typename INT>
960 std::pair<int, size_t> Exo_Read<INT>::Global_to_Block_Local(size_t global_elmt_num) const
961 {
962 SMART_ASSERT(Check_State());
963
964 if (!Open()) {
965 Error("exodiff: ERROR: File not open!");
966 }
967 if (global_elmt_num < 1 || global_elmt_num > num_elmts) {
968 Error(fmt::format("exodiff: ERROR: global_elmt_num = {} is out of bounds [1, {}]!",
969 fmt::group_digits(global_elmt_num), fmt::group_digits(num_elmts)));
970 }
971
972 int block_index = 0;
973
974 size_t total = 0;
975 while (total + eblocks[block_index].Size() < global_elmt_num) {
976 total += eblocks[block_index++].Size();
977 }
978
979 return std::make_pair(block_index, global_elmt_num - total - 1);
980 }
981
982 template <typename INT> int Exo_Read<INT>::Check_State() const
983 {
984 SMART_ASSERT(file_id >= -1);
985 SMART_ASSERT(io_word_size == 0 || io_word_size == 4 || io_word_size == 8);
986
987 SMART_ASSERT(!(file_id >= 0 && io_word_size == 0));
988 SMART_ASSERT(!(file_id >= 0 && file_name.empty()));
989
990 SMART_ASSERT(!(num_elmt_blocks > 0 && !eblocks));
991 SMART_ASSERT(!(num_node_sets > 0 && !nsets));
992 SMART_ASSERT(!(num_side_sets > 0 && !ssets));
993
994 SMART_ASSERT(!(num_nodes == 0 && nodes));
995
996 SMART_ASSERT(Num_Times() >= 0);
997
998 SMART_ASSERT(cur_time >= 0 && cur_time <= Num_Times());
999 SMART_ASSERT(!(!nodal_vars.empty() && !results));
1000 SMART_ASSERT(!(nodal_vars.empty() && results));
1001
1002 return 1;
1003 }
1004
1005 template <typename INT> std::string Exo_Read<INT>::Open_Change_Set(const std::string &name)
1006 {
1007 SMART_ASSERT(Check_State());
1008
1009 if (no_case_equals(name, "root") || no_case_equals(name, "/")) {
1010 return Open_Change_Set(0);
1011 }
1012
1013 const auto &names = Change_Set_Names();
1014 for (size_t i = 0; i < names.size(); i++) {
1015 if (no_case_equals(name, names[i])) {
1016 return Open_Change_Set(i + 1);
1017 }
1018 }
1019 return fmt::format(
1020 "Could not find a match for the change set named {}.\nValid change set names are: {}\n", name,
1021 fmt::join(names, ", "));
1022 }
1023
1024 template <typename INT> std::string Exo_Read<INT>::Open_Change_Set(int index)
1025 {
1026 SMART_ASSERT(Check_State());
1027
1028 if (index >= 0) {
1029 if (index == current_change_set_index) {
1030 return "";
1031 }
1032
1033 if (index >= num_change_sets) {
1034 return fmt::format("exodiff: ERROR: Index {} is out of range. Valid range: 0 <= index < {}",
1035 index, num_change_sets);
1036 }
1037
1038 Reset_Meta_Data();
1039 current_change_set_index = index;
1040 file_id = change_set_ids[index];
1041 }
1042 Get_Meta_Data();
1043
1044 return "";
1045 }
1046
1047 template <typename INT> void Exo_Read<INT>::Get_Meta_Data()
1048 {
1049 SMART_ASSERT(Check_State());
1050 SMART_ASSERT(file_id >= 0);
1051
1052 // Determine max size of entity and variable names on the database
1053 int length_name = ex_inquire_int(file_id, EX_INQ_DB_MAX_USED_NAME_LENGTH);
1054 ex_set_max_name_length(file_id, length_name);
1055
1056 ex_init_params info{};
1057 info.title[0] = '\0';
1058
1059 int err = ex_get_init_ext(file_id, &info);
1060 if (err < 0) {
1061 Error(fmt::format("Failed to get init data!"
1062 " Error number = {}. Aborting...\n",
1063 err));
1064 }
1065
1066 dimension = info.num_dim;
1067 num_nodes = info.num_nodes;
1068 num_elmts = info.num_elem;
1069 num_faces = info.num_face;
1070 num_edges = info.num_edge;
1071 num_elmt_blocks = info.num_elem_blk;
1072 num_node_sets = info.num_node_sets;
1073 num_side_sets = info.num_side_sets;
1074 num_edge_blocks = info.num_edge_blk;
1075 num_face_blocks = info.num_face_blk;
1076 num_assemblies = info.num_assembly;
1077 title = info.title;
1078
1079 if (err > 0 && !interFace.quiet_flag) {
1080 fmt::print(stderr, "exodiff: WARNING: was issued, number = {}\n", err);
1081 }
1082 if (dimension < 1 || dimension > 3) {
1083 Error(fmt::format("Init data appears corrupt:\n"
1084 " dimension = {}\n"
1085 " num_nodes = {}\n"
1086 " num_elmts = {}\n"
1087 " num_elmt_blocks = {}\n"
1088 " num_node_sets = {}\n"
1089 " num_side_sets = {}\n"
1090 " num_edge_blocks = {}\n"
1091 " num_face_blocks = {}\n"
1092 " ... Aborting...\n",
1093 dimension, fmt::group_digits(num_nodes), fmt::group_digits(num_elmts),
1094 num_elmt_blocks, num_node_sets, num_edge_blocks, num_face_blocks,
1095 num_side_sets));
1096 }
1097
1098 int num_qa = ex_inquire_int(file_id, EX_INQ_QA);
1099 int num_info = ex_inquire_int(file_id, EX_INQ_INFO);
1100
1101 if (num_qa < 0 || num_info < 0) {
1102 Error(fmt::format("inquire data appears corrupt:\n"
1103 " num_qa = {}\n"
1104 " num_info = {}\n"
1105 " ... Aborting...\n",
1106 num_qa, num_info));
1107 }
1108
1109 // Coordinate Names...
1110
1111 char **coords = get_name_array(3, length_name);
1112 err = ex_get_coord_names(file_id, coords);
1113 if (err < 0) {
1114 Error("Failed to get coordinate names! Aborting...\n");
1115 }
1116
1117 coord_names.clear();
1118 for (int i = 0; i < dimension; ++i) {
1119 coord_names.emplace_back(coords[i]);
1120 }
1121 free_name_array(coords, 3);
1122
1123 // Assembly Data...
1124 delete[] assemblies;
1125 assemblies = nullptr;
1126 if (num_assemblies > 0) {
1127 assemblies = new Assembly<INT>[num_assemblies];
1128 SMART_ASSERT(assemblies != nullptr);
1129 std::vector<INT> ids(num_assemblies);
1130
1131 err = ex_get_ids(file_id, EX_ASSEMBLY, Data(ids));
1132
1133 if (err < 0) {
1134 Error("Failed to get assembly ids! Aborting...\n");
1135 }
1136
1137 for (size_t b = 0; b < num_assemblies; ++b) {
1138 if (ids[b] <= EX_INVALID_ID) {
1139 fmt::print(stderr,
1140 "EXODIFF WARNING: Assembly Id "
1141 "for assembly index {} is {} which is negative. This was returned by call to "
1142 "ex_get_ids().\n",
1143 b, ids[b]);
1144 }
1145
1146 assemblies[b].initialize(file_id, ids[b]);
1147 }
1148 }
1149 // Element Block Data...
1150
1151 delete[] eblocks;
1152 eblocks = nullptr;
1153 if (num_elmt_blocks > 0) {
1154 eblocks = new Exo_Block<INT>[num_elmt_blocks];
1155 SMART_ASSERT(eblocks != nullptr);
1156 std::vector<INT> ids(num_elmt_blocks);
1157
1158 err = ex_get_ids(file_id, EX_ELEM_BLOCK, Data(ids));
1159
1160 if (err < 0) {
1161 Error("Failed to get element block ids! Aborting...\n");
1162 }
1163
1164 size_t e_count = 0;
1165 for (size_t b = 0; b < num_elmt_blocks; ++b) {
1166 if (ids[b] <= EX_INVALID_ID) {
1167 fmt::print(stderr,
1168 "EXODIFF WARNING: Element block Id "
1169 "for block index {} is {} which is negative. This was returned by call to "
1170 "ex_get_elem_blk_ids().\n",
1171 b, ids[b]);
1172 }
1173
1174 eblocks[b].initialize(file_id, ids[b]);
1175 eblocks[b].offset(e_count);
1176 e_count += eblocks[b].Size();
1177 }
1178
1179 if (e_count != num_elmts && !interFace.quiet_flag) {
1180 fmt::print(stderr,
1181 "exodiff: WARNING: Total number of elements {}"
1182 " does not equal the sum of the number of elements "
1183 "in each block {}\n",
1184 fmt::group_digits(num_elmts), fmt::group_digits(e_count));
1185 }
1186
1187 // Gather the attribute names (even though not all attributes are on all blocks)
1188 std::set<std::string> names;
1189 for (size_t b = 0; b < num_elmt_blocks; ++b) {
1190 for (int a = 0; a < eblocks[b].attr_count(); a++) {
1191 names.insert(eblocks[b].Get_Attribute_Name(a));
1192 }
1193 }
1194 elmt_atts.resize(names.size());
1195 std::copy(names.begin(), names.end(), elmt_atts.begin());
1196 }
1197
1198 // Node & Side sets...
1199
1200 delete[] nsets;
1201 nsets = nullptr;
1202 if (num_node_sets > 0) {
1203 nsets = new Node_Set<INT>[num_node_sets];
1204 SMART_ASSERT(nsets != nullptr);
1205 std::vector<INT> ids(num_node_sets);
1206
1207 err = ex_get_ids(file_id, EX_NODE_SET, Data(ids));
1208
1209 if (err < 0) {
1210 Error("Failed to get nodeset ids! Aborting...\n");
1211 }
1212
1213 for (size_t nset = 0; nset < num_node_sets; ++nset) {
1214 if (ids[nset] <= EX_INVALID_ID) {
1215 fmt::print(stderr,
1216 "EXODIFF WARNING: Nodeset Id "
1217 "for nodeset index {} is {}"
1218 " which is negative. This was returned by call to ex_get_ids().\n",
1219 nset, ids[nset]);
1220 }
1221
1222 nsets[nset].initialize(file_id, ids[nset]);
1223 }
1224 }
1225
1226 delete[] ssets;
1227 ssets = nullptr;
1228 if (num_side_sets) {
1229 ssets = new Side_Set<INT>[num_side_sets];
1230 SMART_ASSERT(ssets != nullptr);
1231 std::vector<INT> ids(num_side_sets);
1232
1233 err = ex_get_ids(file_id, EX_SIDE_SET, Data(ids));
1234
1235 if (err < 0) {
1236 Error("Failed to get sideset ids! Aborting...\n");
1237 }
1238
1239 for (size_t sset = 0; sset < num_side_sets; ++sset) {
1240 if (ids[sset] <= EX_INVALID_ID) {
1241 fmt::print(stderr,
1242 "EXODIFF WARNING: Sideset Id for sideset index {} is {}"
1243 " which is negative. This was returned by call to ex_get_ids().\n",
1244 sset, ids[sset]);
1245 }
1246 ssets[sset].initialize(file_id, ids[sset]);
1247 }
1248 }
1249
1250 // Edge & Face blocks...
1251
1252 delete[] edge_blocks;
1253 edge_blocks = nullptr;
1254 if (num_edge_blocks > 0) {
1255 edge_blocks = new Edge_Block<INT>[num_edge_blocks];
1256 SMART_ASSERT(edge_blocks != nullptr);
1257 std::vector<INT> ids(num_edge_blocks);
1258
1259 err = ex_get_ids(file_id, EX_EDGE_BLOCK, Data(ids));
1260
1261 if (err < 0) {
1262 Error("Failed to get edgeblock ids! Aborting...\n");
1263 }
1264
1265 for (size_t edge_block = 0; edge_block < num_edge_blocks; ++edge_block) {
1266 if (ids[edge_block] <= EX_INVALID_ID) {
1267 fmt::print(stderr,
1268 "EXODIFF WARNING: Edgeblock Id "
1269 "for edgeblock index {} is {}"
1270 " which is negative. This was returned by call to ex_get_ids().\n",
1271 edge_block, ids[edge_block]);
1272 }
1273
1274 edge_blocks[edge_block].initialize(file_id, ids[edge_block]);
1275 }
1276 }
1277
1278 delete[] face_blocks;
1279 face_blocks = nullptr;
1280 if (num_face_blocks > 0) {
1281 face_blocks = new Face_Block<INT>[num_face_blocks];
1282 SMART_ASSERT(face_blocks != nullptr);
1283 std::vector<INT> ids(num_face_blocks);
1284
1285 err = ex_get_ids(file_id, EX_FACE_BLOCK, Data(ids));
1286
1287 if (err < 0) {
1288 Error("Failed to get faceblock ids! Aborting...\n");
1289 }
1290
1291 for (size_t face_block = 0; face_block < num_face_blocks; ++face_block) {
1292 if (ids[face_block] <= EX_INVALID_ID) {
1293 fmt::print(stderr,
1294 "EXODIFF WARNING: Faceblock Id "
1295 "for faceblock index {} is {}"
1296 " which is negative. This was returned by call to ex_get_ids().\n",
1297 face_block, ids[face_block]);
1298 }
1299
1300 face_blocks[face_block].initialize(file_id, ids[face_block]);
1301 }
1302 }
1303
1304 // ************** RESULTS info *************** //
1305
1306 int num_global_vars, num_nodal_vars, num_elmt_vars, num_ns_vars, num_ss_vars, num_edge_vars,
1307 num_face_vars;
1308
1309 err = ex_get_variable_param(file_id, EX_GLOBAL, &num_global_vars);
1310 if (err < 0) {
1311 Error("Failed to get number of global variables! Aborting...\n");
1312 }
1313
1314 err = ex_get_variable_param(file_id, EX_NODAL, &num_nodal_vars);
1315 if (err < 0) {
1316 Error("Failed to get number of nodal variables! Aborting...\n");
1317 }
1318
1319 err = ex_get_variable_param(file_id, EX_ELEM_BLOCK, &num_elmt_vars);
1320 if (err < 0) {
1321 Error("Failed to get number of element variables! Aborting...\n");
1322 }
1323
1324 err = ex_get_variable_param(file_id, EX_NODE_SET, &num_ns_vars);
1325 if (err < 0) {
1326 Error("Failed to get number of nodeset variables! Aborting...\n");
1327 }
1328
1329 err = ex_get_variable_param(file_id, EX_SIDE_SET, &num_ss_vars);
1330 if (err < 0) {
1331 Error("Failed to get number of sideset variables! Aborting...\n");
1332 }
1333
1334 err = ex_get_variable_param(file_id, EX_EDGE_BLOCK, &num_edge_vars);
1335 if (err < 0) {
1336 Error("Failed to get number of edgeblock variables! Aborting...\n");
1337 }
1338
1339 err = ex_get_variable_param(file_id, EX_FACE_BLOCK, &num_face_vars);
1340 if (err < 0) {
1341 Error("Failed to get number of faceblock variables! Aborting...\n");
1342 }
1343
1344 if (num_global_vars < 0 || num_nodal_vars < 0 || num_elmt_vars < 0 || num_ns_vars < 0 ||
1345 num_ss_vars < 0 || num_edge_vars < 0 || num_face_vars < 0) {
1346 Error(fmt::format("Data appears corrupt for"
1347 " number of variables !\n"
1348 "\tnum global vars = {}\n"
1349 "\tnum nodal vars = {}\n"
1350 "\tnum element vars = {}\n"
1351 "\tnum nodeset vars = {}\n"
1352 "\tnum sideset vars = {}\n"
1353 "\tnum edgeblock vars = {}\n"
1354 "\tnum faceblock vars = {}\n"
1355 " ... Aborting...\n",
1356 num_global_vars, num_nodal_vars, num_elmt_vars, num_ns_vars, num_ss_vars,
1357 num_edge_vars, num_face_vars));
1358 }
1359
1360 read_vars(file_id, EX_GLOBAL, "Global", num_global_vars, global_vars);
1361 read_vars(file_id, EX_NODAL, "Nodal", num_nodal_vars, nodal_vars);
1362 read_vars(file_id, EX_ELEM_BLOCK, "Element", num_elmt_vars, elmt_vars);
1363 read_vars(file_id, EX_NODE_SET, "Nodeset", num_ns_vars, ns_vars);
1364 read_vars(file_id, EX_SIDE_SET, "Sideset", num_ss_vars, ss_vars);
1365 read_vars(file_id, EX_EDGE_BLOCK, "Edgeblock", num_edge_vars, eb_vars);
1366 read_vars(file_id, EX_FACE_BLOCK, "Faceblock", num_face_vars, fb_vars);
1367
1368 // Times:
1369 int num_times = ex_inquire_int(file_id, EX_INQ_TIME);
1370 if (num_times < 0) {
1371 Error(fmt::format("Number of time steps came back negative ({})! Aborting...\n", num_times));
1372 }
1373
1374 if ((num_global_vars > 0 || num_nodal_vars > 0 || num_elmt_vars > 0 || num_ns_vars > 0 ||
1375 num_ss_vars > 0 || num_edge_vars > 0 || num_face_vars > 0) &&
1376 num_times == 0) {
1377 Warning("Consistency error -- The database contains transient variables, but no "
1378 "timesteps!\n");
1379 }
1380
1381 if (num_times) {
1382 times.resize(num_times);
1383 ex_get_all_times(file_id, times.data());
1384 if (time_scale != 1.0 || time_offset != 0.0) {
1385 for (int i = 0; i < num_times; i++) {
1386 times[i] = time_scale * times[i] + time_offset;
1387 }
1388 }
1389 }
1390
1391 if (num_nodal_vars != 0) {
1392 if (num_times == 0) {
1393 Warning(fmt::format("Consistency error--The database contains {}"
1394 " nodal variables, but there are no time steps defined.\n",
1395 num_nodal_vars));
1396 }
1397 if (num_times) {
1398 results = new double *[num_nodal_vars];
1399 for (int i = 0; i < num_nodal_vars; ++i) {
1400 results[i] = nullptr;
1401 }
1402 }
1403 }
1404
1405 } // End of EXODIFF
1406
1407 namespace {
1408 void query_change_sets(int file_id, NameList &names, bool return_full_names)
1409 {
1410 int idum;
1411 float rdum;
1412
1413 int group_name_length = ex_inquire_int(file_id, EX_INQ_GROUP_NAME_LEN);
1414 std::vector<char> group_name(group_name_length + 1, '\0');
1415
1416 // Get name of this group...
1417 int ierr = ex_inquire(file_id, EX_INQ_GROUP_NAME, &idum, &rdum, group_name.data());
1418 if (ierr < 0) {
1419 Error("Unable to query group name.\n");
1420 }
1421
1422 if (group_name[0] != '/') {
1423 if (return_full_names) {
1424 std::fill(group_name.begin(), group_name.end(), '\0');
1425 ierr = ex_inquire(file_id, EX_INQ_FULL_GROUP_NAME, &idum, &rdum, group_name.data());
1426 if (ierr < 0) {
1427 Error("Unable to query full group name.\n");
1428 }
1429 names.push_back(std::string(group_name.data()));
1430 }
1431 else {
1432 names.push_back(std::string(group_name.data()));
1433 }
1434 }
1435
1436 int num_children = ex_inquire_int(file_id, EX_INQ_NUM_CHILD_GROUPS);
1437 std::vector<int> children(num_children);
1438 ierr = ex_get_group_ids(file_id, nullptr, Data(children));
1439 if (ierr < 0) {
1440 Error("Unable to query group ids.\n");
1441 }
1442
1443 for (int i = 0; i < num_children; i++) {
1444 query_change_sets(children[i], names, return_full_names);
1445 }
1446 }
1447
1448 void read_vars(int file_id, EXOTYPE flag, const char *type, int num_vars, NameList &varlist)
1449 {
1450 if (num_vars != 0) {
1451 int name_size = ex_inquire_int(file_id, EX_INQ_MAX_READ_NAME_LENGTH);
1452 char **varnames = get_name_array(num_vars, name_size);
1453 int err = ex_get_variable_names(file_id, flag, num_vars, varnames);
1454
1455 if (err < 0) {
1456 Error(fmt::format("Failed to get {} variable names! Aborting...\n", type));
1457 }
1458 else if (err > 0 && !interFace.quiet_flag) {
1459 fmt::print(
1460 stderr,
1461 "exodiff: WARNING: Exodus issued warning \"{}\" on call to ex_get_var_names()!\n", err);
1462 }
1463 for (int vg = 0; vg < num_vars; ++vg) {
1464 SMART_ASSERT(varnames[vg] != nullptr);
1465 if (std::strlen(varnames[vg]) == 0 ||
1466 static_cast<int>(std::strlen(varnames[vg])) > name_size) {
1467 std::ostringstream out;
1468 fmt::print(out,
1469 "exodiff: ERROR: {} variable names appear corrupt\n"
1470 " A length is 0 or greater than name_size({})\n"
1471 " Here are the names that I received from"
1472 " a call to ex_get_var_names(...):\n",
1473 type, name_size);
1474 for (int k = 1; k <= num_vars; ++k) {
1475 fmt::print(out, "\t\t{}) \"{}\"\n", k, varnames[k - 1]);
1476 }
1477 fmt::print(out, " Aborting...\n");
1478 Error(out);
1479 }
1480
1481 std::string n(varnames[vg]);
1482 chop_whitespace(n);
1483 varlist.push_back(n);
1484 }
1485 free_name_array(varnames, num_vars);
1486 }
1487 }
1488 } // namespace
1489 template class Exo_Read<int>;
1490 template class Exo_Read<int64_t>;