1
- // Copyright(C) 1999-2022 National Technology & Engineering Solutions
1
+ // Copyright(C) 1999-2022, 2025 National Technology & Engineering Solutions
2
2
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3
3
// NTESS, the U.S. Government retains certain rights in this software.
4
4
//
7
7
#if defined(EXODUS_SUPPORT)
8
8
#include " aprepro.h"
9
9
#include " exodusII.h"
10
+ #include " exodusII_int.h"
10
11
11
12
#include " apr_symrec.h"
12
13
#include " apr_util.h"
16
17
#include < cctype>
17
18
#include < cstdlib>
18
19
#include < cstring>
20
+ #include " fmt/format.h"
19
21
20
22
namespace {
21
23
std::string LowerCase (std::string name);
@@ -53,12 +55,35 @@ namespace {
53
55
names += str_name;
54
56
}
55
57
58
+ void get_change_set_names (int exoid, SEAMS::Aprepro *aprepro)
59
+ {
60
+ int idum;
61
+ float rdum;
62
+
63
+ // Get root of database...
64
+ int rootid = exoid & EX_FILE_ID_MASK;
65
+
66
+ std::string cs_names;
67
+
68
+ int group_name_length = ex_inquire_int (rootid, EX_INQ_GROUP_NAME_LEN);
69
+ std::vector<char > group_name (group_name_length + 1 , ' \0 ' );
70
+
71
+ int num_children = ex_inquire_int (rootid, EX_INQ_NUM_CHILD_GROUPS);
72
+ for (int i = 0 ; i < num_children; i++) {
73
+ ex_inquire (rootid + 1 + i, EX_INQ_GROUP_NAME, &idum, &rdum, group_name.data ());
74
+ if (i > 0 ) {
75
+ cs_names += " ," ;
76
+ }
77
+ cs_names += group_name.data ();
78
+ }
79
+ aprepro->add_variable (" ex_change_set_names" , cs_names);
80
+ }
56
81
} // namespace
57
82
58
83
namespace SEAMS {
59
84
extern SEAMS::Aprepro *aprepro;
60
85
61
- int open_exodus_file (char *filename)
86
+ int open_exodus_file (char *filename, int cs_idx )
62
87
{
63
88
int cpu = sizeof (double );
64
89
int io = 0 ;
@@ -78,7 +103,31 @@ namespace SEAMS {
78
103
}
79
104
}
80
105
106
+ // See if the file contains change sets. If it does, open the first one.
107
+ int num_change_sets = ex_inquire_int (exo, EX_INQ_NUM_CHILD_GROUPS);
108
+ int active_change_set = 0 ;
109
+ if (num_change_sets >= 1 ) {
110
+ if (cs_idx == 0 ) {
111
+ cs_idx = 1 ;
112
+ aprepro->warning (fmt::format (" Input database contains {} change sets. Rreading from change set {}." , num_change_sets, cs_idx));
113
+ }
114
+ if (cs_idx <= num_change_sets) {
115
+ active_change_set = cs_idx;
116
+ exo+= cs_idx;
117
+ get_change_set_names (exo, aprepro);
118
+ }
119
+ else {
120
+ yyerror (*aprepro, fmt::format (" Specified change set index {} exceeds count {}" , cs_idx, num_change_sets));
121
+ return -1 ;
122
+ }
123
+ }
124
+ if (cs_idx > 0 ) {
125
+ aprepro->warning (fmt::format (" Input database does not contain change sets, but a change set index {} was specified. Ignoring." , cs_idx));
126
+ }
127
+
81
128
aprepro->add_variable (" ex_version" , version);
129
+ aprepro->add_variable (" ex_change_set_count" , num_change_sets);
130
+ aprepro->add_variable (" ex_active_change_set" , active_change_set);
82
131
return exo;
83
132
}
84
133
@@ -88,8 +137,8 @@ namespace SEAMS {
88
137
89
138
// Open the specified exodusII file, read the info records
90
139
// then parse them as input to aprepro.
91
- int exoid = open_exodus_file (filename);
92
- if (exoid < 0 ) {
140
+ int exoid = open_exodus_file (filename, 0 );
141
+ if (exoid <= 0 ) {
93
142
return " " ;
94
143
}
95
144
@@ -134,8 +183,8 @@ namespace SEAMS {
134
183
135
184
// Open the specified exodusII file, read the info records
136
185
// then parse them as input to aprepro.
137
- int exoid = open_exodus_file (filename);
138
- if (exoid < 0 ) {
186
+ int exoid = open_exodus_file (filename, 0 );
187
+ if (exoid <= 0 ) {
139
188
return " " ;
140
189
}
141
190
@@ -180,14 +229,13 @@ namespace SEAMS {
180
229
return " " ;
181
230
}
182
231
183
- const char *do_exodus_meta (char *filename)
232
+ const char *do_exodus_meta_cd (char *filename, double cs_index )
184
233
{
185
-
186
234
// Open the specified exodusII file, read the metadata and set
187
235
// variables for each item.
188
236
// Examples include "node_count", "element_count", ...
189
- int exoid = open_exodus_file (filename);
190
- if (exoid < 0 ) {
237
+ int exoid = open_exodus_file (filename, ( int )cs_index );
238
+ if (exoid <= 0 ) {
191
239
return " " ;
192
240
}
193
241
@@ -410,6 +458,12 @@ namespace SEAMS {
410
458
ex_close (exoid);
411
459
return " " ;
412
460
}
461
+
462
+ const char *do_exodus_meta (char *filename)
463
+ {
464
+ return do_exodus_meta_cd (filename, 0 );
465
+ }
466
+
413
467
} // namespace SEAMS
414
468
415
469
namespace {
0 commit comments