Debian Codegraph @

packages/seacas/libraries/ioss/src/main/info_interface.C

raw
1 /*
2 * Copyright(C) 1999-2025 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8 #include <cstdlib> // for exit, EXIT_SUCCESS, getenv
9 #include <cstring>
10 #include <fmt/core.h>
11 #include <iostream> // for operator<<, basic_ostream, etc
12 #include <stdio.h>
13 #include <string> // for char_traits, string
14
15 #include "Ioss_GetLongOpt.h" // for GetLongOption, etc
16 #include "Ioss_Utils.h"
17 #include "info_interface.h"
18
19 Info::Interface::Interface(std::string app_version) : version(std::move(app_version))
20 {
21 enroll_options();
22 }
23
24 void Info::Interface::enroll_options()
25 {
26 options_.usage("[options] basename");
27
28 options_.enroll("help", Ioss::GetLongOption::OptType::NoValue, "Print this summary and exit",
29 nullptr);
30
31 options_.enroll("configuration", Ioss::GetLongOption::OptType::NoValue,
32 "Show configuration of IOSS library (TPL versions)", nullptr);
33
34 options_.enroll("db_type", Ioss::GetLongOption::OptType::MandatoryValue,
35 "Database Type: generated"
36 #if defined(SEACAS_HAVE_PAMGEN)
37 ", pamgen"
38 #endif
39 #if defined(SEACAS_HAVE_EXODUS)
40 ", exodus"
41 #endif
42 #if defined(SEACAS_HAVE_CGNS)
43 ", cgns"
44 #endif
45 #if defined(SEACAS_HAVE_FAODEL)
46 ", faodel"
47 #endif
48 ".",
49 "unknown");
50 options_.enroll("in_type", Ioss::GetLongOption::OptType::MandatoryValue, "(alias for db_type)",
51 nullptr, nullptr, true);
52
53 options_.enroll("summary", Ioss::GetLongOption::OptType::NoValue,
54 "Only output counts of nodes, elements, and entities", nullptr);
55
56 options_.enroll("check_node_status", Ioss::GetLongOption::OptType::NoValue,
57 "Check whether there are any nodes not connected to any elements", nullptr);
58 options_.enroll("adjacencies", Ioss::GetLongOption::OptType::NoValue,
59 "Calculate which element blocks touch which surfaces and other element blocks",
60 nullptr);
61 options_.enroll("compute_volume", Ioss::GetLongOption::OptType::NoValue,
62 "Compute the volume of all hex elements in the mesh. Outputs min/max and count",
63 nullptr);
64 options_.enroll("compute_bbox", Ioss::GetLongOption::OptType::NoValue,
65 "Compute the bounding box of all element blocks in the mesh.", nullptr, nullptr,
66 true);
67
68 options_.enroll("disable_field_recognition", Ioss::GetLongOption::OptType::NoValue,
69 "Do not combine fields into vector, tensor fields based on basename and suffix.\n"
70 "\t\tKeep all fields on database as scalars",
71 nullptr);
72
73 options_.enroll("field_suffix_separator", Ioss::GetLongOption::OptType::MandatoryValue,
74 "Character used to separate a field suffix from the field basename\n"
75 "\t\t when recognizing vector, tensor fields. Enter '0' for no separaor",
76 "_");
77
78 options_.enroll("custom_field", Ioss::GetLongOption::OptType::MandatoryValue,
79 "A comma-separated list of field suffices defining a custom field that should be "
80 "recognized.\n"
81 "\t\tPrimarily used for testing",
82 nullptr);
83
84 options_.enroll("detailed_field_info", Ioss::GetLongOption::OptType::NoValue,
85 "Output very detailed information about each field", nullptr);
86
87 options_.enroll("use_generic_names", Ioss::GetLongOption::OptType::NoValue,
88 "Use generic names (type_id) instead of names in database", nullptr);
89
90 options_.enroll("surface_split_scheme", Ioss::GetLongOption::OptType::MandatoryValue,
91 "Method used to split sidesets into homogeneous blocks\n"
92 "\t\tOptions are: TOPOLOGY, BLOCK, NO_SPLIT",
93 nullptr, nullptr, true);
94
95 #if defined(SEACAS_HAVE_MPI)
96 #if !defined(NO_ZOLTAN_SUPPORT)
97 options_.enroll(
98 "rcb", Ioss::GetLongOption::OptType::NoValue,
99 "Use recursive coordinate bisection method to decompose the input mesh in a parallel run.",
100 nullptr);
101 options_.enroll(
102 "rib", Ioss::GetLongOption::OptType::NoValue,
103 "Use recursive inertial bisection method to decompose the input mesh in a parallel run.",
104 nullptr);
105
106 options_.enroll(
107 "hsfc", Ioss::GetLongOption::OptType::NoValue,
108 "Use hilbert space-filling curve method to decompose the input mesh in a parallel run.",
109 nullptr);
110 #endif
111
112 #if !defined(NO_PARMETIS_SUPPORT)
113 options_.enroll(
114 "metis_sfc", Ioss::GetLongOption::OptType::NoValue,
115 "Use the metis space-filling-curve method to decompose the input mesh in a parallel run.",
116 nullptr);
117
118 options_.enroll(
119 "kway", Ioss::GetLongOption::OptType::NoValue,
120 "Use the metis kway graph-based method to decompose the input mesh in a parallel run.",
121 nullptr);
122
123 options_.enroll("kway_geom", Ioss::GetLongOption::OptType::NoValue,
124 "Use the metis kway graph-based method with geometry speedup to decompose the "
125 "input mesh in a parallel run.",
126 nullptr);
127 #endif
128
129 options_.enroll("linear", Ioss::GetLongOption::OptType::NoValue,
130 "Use the linear method to decompose the input mesh in a parallel run.\n"
131 "\t\tElements in order first n/p to proc 0, next to proc 1.",
132 nullptr);
133
134 options_.enroll("cyclic", Ioss::GetLongOption::OptType::NoValue,
135 "Use the cyclic method to decompose the input mesh in a parallel run.\n"
136 "\t\tElements handed out to id % proc_count",
137 nullptr);
138
139 options_.enroll("random", Ioss::GetLongOption::OptType::NoValue,
140 "Use the random method to decompose the input mesh in a parallel run.\n"
141 "\t\tElements assigned randomly to processors in a way that preserves balance.\n"
142 "\t\t(do not use for a real run)",
143 nullptr);
144 options_.enroll("serialize_io_size", Ioss::GetLongOption::OptType::MandatoryValue,
145 "Number of processors that can perform simultaneous IO operations in "
146 "a parallel run; 0 to disable",
147 nullptr, nullptr, true);
148
149 #endif
150
151 options_.enroll(
152 "list_change_sets", Ioss::GetLongOption::OptType::NoValue,
153 "Print a list of the names of all change_sets (previosly groups) in this file and then exit.",
154 nullptr);
155 options_.enroll("list_groups", Ioss::GetLongOption::OptType::NoValue,
156 "[deprecated] Use --list_change_sets", nullptr);
157
158 options_.enroll("change_set_name", Ioss::GetLongOption::OptType::MandatoryValue,
159 "List information only for the specified comma-separated list of change_set(s) "
160 "or `ALL` to list for all.",
161 nullptr);
162 options_.enroll("group_name", Ioss::GetLongOption::OptType::MandatoryValue,
163 "[deprecated] Use --change_set_name.", nullptr, nullptr, true);
164
165 options_.enroll("query_timesteps_only", Ioss::GetLongOption::OptType::NoValue,
166 "Only read and output the timestep data on the file", nullptr);
167 options_.enroll("64-bit", Ioss::GetLongOption::OptType::NoValue, "Use 64-bit integers", nullptr);
168 options_.enroll("version", Ioss::GetLongOption::OptType::NoValue, "Print version and exit",
169 nullptr);
170
171 options_.enroll("copyright", Ioss::GetLongOption::OptType::NoValue,
172 "Show copyright and license data.", nullptr);
173 }
174
175 bool Info::Interface::parse_options(int argc, char **argv)
176 {
177 // Get options from environment variable also...
178 char *options = getenv("IO_INFO_OPTIONS");
179 if (options != nullptr) {
180 fmt::print(
181 stderr,
182 "\nThe following options were specified via the IO_INFO_OPTIONS environment variable:\n"
183 "\t{}\n\n",
184 options);
185 options_.parse(options, Ioss::GetLongOption::basename(*argv));
186 }
187
188 int option_index = options_.parse(argc, argv);
189 if (option_index < 1) {
190 return false;
191 }
192
193 if (options_.retrieve("help") != nullptr) {
194 options_.usage(std::cerr);
195 fmt::print(stderr,
196 "\n\tCan also set options via IO_INFO_OPTIONS environment variable.\n\n"
197 "\tDocumentation: "
198 "https://sandialabs.github.io/seacas-docs/sphinx/html/index.html#io-info\n\n"
199 "\t->->-> Send email to [email protected] for {} support.<-<-<-\n",
200 options_.program_name());
201 exit(EXIT_SUCCESS);
202 }
203
204 if (options_.retrieve("version") != nullptr) {
205 fmt::print(stderr, "IO_INFO\tVersion: {}\n", version);
206 exit(0);
207 }
208
209 checkNodeStatus_ = options_.retrieve("check_node_status") != nullptr;
210 adjacencies_ = options_.retrieve("adjacencies") != nullptr;
211 ints64Bit_ = options_.retrieve("64-bit") != nullptr;
212 computeVolume_ = options_.retrieve("compute_volume") != nullptr;
213 computeBBox_ = options_.retrieve("compute_bbox") != nullptr;
214 listChangeSets_ = options_.retrieve("list_change_sets") != nullptr ||
215 options_.retrieve("list_groups") != nullptr;
216 useGenericNames_ = options_.retrieve("use_generic_names") != nullptr;
217 summary_ = options_.retrieve("summary") != nullptr;
218 showConfig_ = options_.retrieve("configuration") != nullptr;
219 queryTimeOnly_ = options_.retrieve("query_timesteps_only") != nullptr;
220 fieldDetails_ = options_.retrieve("detailed_field_info") != nullptr;
221
222 filetype_ = options_.get_option_value("db_type", filetype_);
223 filetype_ = options_.get_option_value("in_type", filetype_);
224 changeSetName_ = options_.get_option_value("change_set_name", changeSetName_);
225 changeSetName_ = options_.get_option_value("group_name", changeSetName_);
226
227 {
228 const char *temp = options_.retrieve("surface_split_scheme");
229 if (temp != nullptr) {
230 if (std::strcmp(temp, "TOPOLOGY") == 0) {
231 surfaceSplitScheme_ = 1;
232 }
233 else if (std::strcmp(temp, "ELEMENT_BLOCK") == 0) {
234 surfaceSplitScheme_ = 2;
235 }
236 else if (std::strcmp(temp, "BLOCK") == 0) {
237 surfaceSplitScheme_ = 2;
238 }
239 else if (std::strcmp(temp, "NO_SPLIT") == 0 || std::strcmp(temp, "NOSPLIT") == 0) {
240 // Backward compatibility using "NOSPLIT" after bug fix...
241 surfaceSplitScheme_ = 3;
242 }
243 }
244 }
245
246 disableFieldRecognition_ = options_.retrieve("disable_field_recognition") != nullptr;
247
248 {
249 const char *temp = options_.retrieve("custom_field");
250 if (temp != nullptr) {
251 customField_ = temp;
252 }
253 }
254
255 {
256 const char *temp = options_.retrieve("field_suffix_separator");
257 if (temp != nullptr) {
258 fieldSuffixSeparator_ = temp[0];
259 }
260 }
261
262 #if defined(SEACAS_HAVE_MPI)
263 #if !defined(NO_ZOLTAN_SUPPORT)
264 if (options_.retrieve("rcb") != nullptr) {
265 decompMethod_ = "RCB";
266 }
267
268 if (options_.retrieve("rib") != nullptr) {
269 decompMethod_ = "RIB";
270 }
271
272 if (options_.retrieve("hsfc") != nullptr) {
273 decompMethod_ = "HSFC";
274 }
275 #endif
276
277 #if !defined(NO_PARMETIS_SUPPORT)
278 if (options_.retrieve("metis_sfc") != nullptr) {
279 decompMethod_ = "METIS_SFC";
280 }
281
282 if (options_.retrieve("kway") != nullptr) {
283 decompMethod_ = "KWAY";
284 }
285
286 if (options_.retrieve("kway_geom") != nullptr) {
287 decompMethod_ = "KWAY_GEOM";
288 }
289 #endif
290
291 if (options_.retrieve("linear") != nullptr) {
292 decompMethod_ = "LINEAR";
293 }
294
295 if (options_.retrieve("cyclic") != nullptr) {
296 decompMethod_ = "CYCLIC";
297 }
298
299 if (options_.retrieve("random") != nullptr) {
300 decompMethod_ = "RANDOM";
301 }
302 #endif
303
304 if (options_.retrieve("copyright") != nullptr) {
305 Ioss::Utils::copyright(std::cerr, "1999-2022");
306 exit(EXIT_SUCCESS);
307 }
308
309 // Parse remaining options as directory paths.
310 if (!show_config()) {
311 if (option_index < argc) {
312 filename_ = argv[option_index];
313 }
314 else {
315 fmt::print(stderr, "\nERROR: filename not specified\n\n");
316 return false;
317 }
318
319 if (filetype_ == "unknown") {
320 filetype_ = Ioss::Utils::get_type_from_file(filename_);
321 }
322 }
323
324 return true;
325 }