Skip to content

Commit ff954a6

Browse files
committed
APREPRO: Add basic support for change sets
1 parent ccfa0eb commit ff954a6

File tree

9 files changed

+2784
-2445
lines changed

9 files changed

+2784
-2445
lines changed

Diff for: packages/seacas/libraries/aprepro_lib/apr_aprepro.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
1+
// Copyright(C) 1999-2025 National Technology & Engineering Solutions
22
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
33
// NTESS, the U.S. Government retains certain rights in this software.
44
//
@@ -33,8 +33,8 @@
3333
#endif
3434

3535
namespace {
36-
const std::string version_short{"6.35"};
37-
const std::string version_date{"(2024/11/06)"};
36+
const std::string version_short{"6.36"};
37+
const std::string version_date{"(2025/02/05)"};
3838
const std::string version_string = version_short + " " + version_date;
3939

4040
void output_copyright();

Diff for: packages/seacas/libraries/aprepro_lib/apr_builtin.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright(C) 1999-2024 National Technology & Engineering Solutions
2+
* Copyright(C) 1999-2025 National Technology & Engineering Solutions
33
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
44
* NTESS, the U.S. Government retains certain rights in this software.
55
*
@@ -128,6 +128,7 @@ namespace SEAMS {
128128
const char *do_exodus_info_range(char *filename, char *beg, char *end);
129129
const char *do_exodus_info(char *filename, char *prefix);
130130
const char *do_exodus_meta(char *filename);
131+
const char *do_exodus_meta_cd(char *filename, double cs_index);
131132
#endif
132133

133134
array *do_csv_array(const char *filename, double skip);

Diff for: packages/seacas/libraries/aprepro_lib/apr_exodus.cc

+64-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright(C) 1999-2022 National Technology & Engineering Solutions
1+
// Copyright(C) 1999-2022, 2025 National Technology & Engineering Solutions
22
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
33
// NTESS, the U.S. Government retains certain rights in this software.
44
//
@@ -7,6 +7,7 @@
77
#if defined(EXODUS_SUPPORT)
88
#include "aprepro.h"
99
#include "exodusII.h"
10+
#include "exodusII_int.h"
1011

1112
#include "apr_symrec.h"
1213
#include "apr_util.h"
@@ -16,6 +17,7 @@
1617
#include <cctype>
1718
#include <cstdlib>
1819
#include <cstring>
20+
#include "fmt/format.h"
1921

2022
namespace {
2123
std::string LowerCase(std::string name);
@@ -53,12 +55,35 @@ namespace {
5355
names += str_name;
5456
}
5557

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+
}
5681
} // namespace
5782

5883
namespace SEAMS {
5984
extern SEAMS::Aprepro *aprepro;
6085

61-
int open_exodus_file(char *filename)
86+
int open_exodus_file(char *filename, int cs_idx)
6287
{
6388
int cpu = sizeof(double);
6489
int io = 0;
@@ -78,7 +103,31 @@ namespace SEAMS {
78103
}
79104
}
80105

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+
81128
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);
82131
return exo;
83132
}
84133

@@ -88,8 +137,8 @@ namespace SEAMS {
88137

89138
// Open the specified exodusII file, read the info records
90139
// 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) {
93142
return "";
94143
}
95144

@@ -134,8 +183,8 @@ namespace SEAMS {
134183

135184
// Open the specified exodusII file, read the info records
136185
// 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) {
139188
return "";
140189
}
141190

@@ -180,14 +229,13 @@ namespace SEAMS {
180229
return "";
181230
}
182231

183-
const char *do_exodus_meta(char *filename)
232+
const char *do_exodus_meta_cd(char *filename, double cs_index)
184233
{
185-
186234
// Open the specified exodusII file, read the metadata and set
187235
// variables for each item.
188236
// 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) {
191239
return "";
192240
}
193241

@@ -410,6 +458,12 @@ namespace SEAMS {
410458
ex_close(exoid);
411459
return "";
412460
}
461+
462+
const char *do_exodus_meta(char *filename)
463+
{
464+
return do_exodus_meta_cd(filename, 0);
465+
}
466+
413467
} // namespace SEAMS
414468

415469
namespace {

Diff for: packages/seacas/libraries/aprepro_lib/apr_init.cc

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
1+
// Copyright(C) 1999-2025 National Technology & Engineering Solutions
22
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
33
// NTESS, the U.S. Government retains certain rights in this software.
44
//
@@ -231,6 +231,13 @@ namespace SEAMS {
231231
#endif
232232
{nullptr, nullptr, nullptr, nullptr}};
233233

234+
const str_cd_init string_cd_fncts[] = {
235+
#if defined(EXODUS_SUPPORT)
236+
{"exodus_meta", do_exodus_meta_cd, "exodus_meta(filename, cs_index)",
237+
"Creates several variables and arrays related to the exodus metadata in the `cs_indexth` change set in file. "},
238+
#endif
239+
{nullptr, nullptr, nullptr, nullptr}};
240+
234241
const str_d_init string_d_fncts[] = {
235242
{"IO", do_intout, "IO(x)", "Convert x to an integer and then to a string. "},
236243
{"to_string", do_tostring, "to_string(x)",
@@ -407,6 +414,7 @@ namespace SEAMS {
407414
internal_init_table(string_fncts, strfnct, SYMBOL_TYPE::STRING_FUNCTION);
408415
internal_init_table(string_c_fncts, strfnct_c, SYMBOL_TYPE::STRING_FUNCTION);
409416
internal_init_table(string_d_fncts, strfnct_d, SYMBOL_TYPE::STRING_FUNCTION);
417+
internal_init_table(string_cd_fncts, strfnct_cd, SYMBOL_TYPE::STRING_FUNCTION);
410418
internal_init_table(string_dc_fncts, strfnct_dc, SYMBOL_TYPE::STRING_FUNCTION);
411419
internal_init_table(string_dcc_fncts, strfnct_dcc, SYMBOL_TYPE::STRING_FUNCTION);
412420
internal_init_table(string_ccc_fncts, strfnct_ccc, SYMBOL_TYPE::STRING_FUNCTION);

0 commit comments

Comments
 (0)