Debian Codegraph @

packages/seacas/libraries/ioss/src/main/skinner_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 <fmt/core.h>
10 #include <iostream> // for operator<<, basic_ostream, etc
11 #include <stdio.h>
12 #include <string> // for char_traits, string
13
14 #include "Ioss_GetLongOpt.h" // for GetLongOption, etc
15 #include "Ioss_Sort.h"
16 #include "Ioss_Utils.h"
17 #include "skinner_interface.h"
18 #include "tokenize.h"
19
20 Skinner::Interface::Interface(std::string app_version) : version(std::move(app_version))
21 {
22 enroll_options();
23 }
24
25 void Skinner::Interface::enroll_options()
26 {
27 options_.usage("[options] input_file[s] output_file");
28
29 options_.enroll("help", Ioss::GetLongOption::OptType::NoValue, "Print this summary and exit",
30 nullptr);
31
32 options_.enroll("version", Ioss::GetLongOption::OptType::NoValue, "Print version and exit",
33 nullptr);
34
35 options_.enroll("64-bit", Ioss::GetLongOption::OptType::NoValue, "True if using 64-bit integers",
36 nullptr);
37 options_.enroll("in_type", Ioss::GetLongOption::OptType::MandatoryValue,
38 "Database type for input file: generated"
39 #if defined(SEACAS_HAVE_PAMGEN)
40 "|pamgen"
41 #endif
42 #if defined(SEACAS_HAVE_EXODUS)
43 "|exodus"
44 #endif
45 #if defined(SEACAS_HAVE_CGNS)
46 "|cgns"
47 #endif
48 #if defined(SEACAS_HAVE_DATAWAREHOUSE)
49 "|data_warehouse"
50 #endif
51 ".\n\t\tIf not specified, guess from extension or exodus is the default.",
52 "unknown");
53
54 options_.enroll("out_type", Ioss::GetLongOption::OptType::MandatoryValue,
55 "Database type for output file:"
56 #if defined(SEACAS_HAVE_EXODUS)
57 " exodus"
58 #endif
59 #if defined(SEACAS_HAVE_CGNS)
60 " cgns"
61 #endif
62 ".\n\t\tIf not specified, guess from extension or exodus is the default.",
63 "unknown");
64
65 options_.enroll("no_output", Ioss::GetLongOption::OptType::NoValue,
66 "Do not produce output file, just generate the faces", nullptr, nullptr, true);
67
68 options_.enroll(
69 "output_transient", Ioss::GetLongOption::OptType::NoValue,
70 "Transfer nodal and element transient data from the input mesh to the output mesh.", nullptr);
71
72 options_.enroll("Maximum_Time", Ioss::GetLongOption::OptType::MandatoryValue,
73 "Maximum time on input database to transfer to output database", nullptr);
74
75 options_.enroll("Minimum_Time", Ioss::GetLongOption::OptType::MandatoryValue,
76 "Minimum time on input database to transfer to output database", nullptr);
77
78 options_.enroll("select_times", Ioss::GetLongOption::OptType::MandatoryValue,
79 "comma-separated list of times that should be transferred to output database",
80 nullptr, nullptr, true);
81
82 options_.enroll("ignore_face_hash_ids", Ioss::GetLongOption::OptType::NoValue,
83 "Don't use face ids from hash of node ids; just use 1..num_face", nullptr);
84
85 options_.enroll("blocks", Ioss::GetLongOption::OptType::NoValue,
86 "Skin block-by-block instead of entire model boundary", nullptr, nullptr, true);
87
88 options_.enroll("netcdf4", Ioss::GetLongOption::OptType::NoValue,
89 "Output database will be a netcdf4 "
90 "hdf5-based file instead of the "
91 "classical netcdf file format",
92 nullptr);
93
94 options_.enroll("shuffle", Ioss::GetLongOption::OptType::NoValue,
95 "Use a netcdf4 hdf5-based file and use hdf5s shuffle mode with compression.",
96 nullptr);
97
98 options_.enroll("compress", Ioss::GetLongOption::OptType::MandatoryValue,
99 "Specify the hdf5 compression level [0..9] to be used on the output file.",
100 nullptr, nullptr, true);
101
102 #if defined(SEACAS_HAVE_MPI)
103 options_.enroll(
104 "compose", Ioss::GetLongOption::OptType::OptionalValue,
105 "If no argument, specify single-file output; if 'external', then file-per-processor.\n"
106 "\t\tAll other options are ignored and just exist for backward-compatibility",
107 nullptr, "nullptr, true");
108
109 options_.enroll(
110 "rcb", Ioss::GetLongOption::OptType::NoValue,
111 "Use recursive coordinate bisection method to decompose the input mesh in a parallel run.",
112 nullptr);
113 options_.enroll(
114 "rib", Ioss::GetLongOption::OptType::NoValue,
115 "Use recursive inertial bisection method to decompose the input mesh in a parallel run.",
116 nullptr);
117
118 options_.enroll(
119 "hsfc", Ioss::GetLongOption::OptType::NoValue,
120 "Use hilbert space-filling curve method to decompose the input mesh in a parallel run.",
121 nullptr);
122
123 options_.enroll(
124 "metis_sfc", Ioss::GetLongOption::OptType::NoValue,
125 "Use the metis space-filling-curve method to decompose the input mesh in a parallel run.",
126 nullptr);
127
128 options_.enroll(
129 "kway", Ioss::GetLongOption::OptType::NoValue,
130 "Use the metis kway graph-based method to decompose the input mesh in a parallel run.",
131 nullptr);
132
133 options_.enroll("kway_geom", Ioss::GetLongOption::OptType::NoValue,
134 "Use the metis kway graph-based method with geometry speedup to decompose the "
135 "input mesh in a parallel run.",
136 nullptr);
137
138 options_.enroll("linear", Ioss::GetLongOption::OptType::NoValue,
139 "Use the linear method to decompose the input mesh in a parallel run.\n"
140 "\t\telements in order first n/p to proc 0, next to proc 1.",
141 nullptr);
142
143 options_.enroll("cyclic", Ioss::GetLongOption::OptType::NoValue,
144 "Use the cyclic method to decompose the input mesh in a parallel run.\n"
145 "\t\telements handed out to id % proc_count",
146 nullptr);
147
148 options_.enroll(
149 "random", Ioss::GetLongOption::OptType::NoValue,
150 "Use the random method to decompose the input mesh in a parallel run.\n"
151 "\t\telements assigned randomly to processors in a way that preserves balance (do "
152 "not use for a real run)",
153 nullptr);
154
155 options_.enroll("external", Ioss::GetLongOption::OptType::NoValue,
156 "Files are decomposed externally into a file-per-processor in a parallel run.",
157 nullptr, nullptr, true);
158 #endif
159
160 options_.enroll("debug", Ioss::GetLongOption::OptType::NoValue, "turn on debugging output",
161 nullptr);
162
163 options_.enroll("statistics", Ioss::GetLongOption::OptType::NoValue,
164 "output parallel io timing statistics", nullptr);
165
166 options_.enroll("copyright", Ioss::GetLongOption::OptType::NoValue,
167 "Show copyright and license data.", nullptr);
168 }
169
170 bool Skinner::Interface::parse_options(int argc, char **argv)
171 {
172 // Get options from environment variable also...
173 char *options = getenv("IO_SKINNER_OPTIONS");
174 if (options != nullptr) {
175 fmt::print(stderr,
176 "\nThe following options were specified via the IO_SKINNER_OPTIONS environment "
177 "variable:\n"
178 "\t{}\n\n",
179 options);
180 options_.parse(options, Ioss::GetLongOption::basename(*argv));
181 }
182
183 int option_index = options_.parse(argc, argv);
184 if (option_index < 1) {
185 return false;
186 }
187
188 if (options_.retrieve("help") != nullptr) {
189 options_.usage(std::cerr);
190 fmt::print(stderr,
191 "\n\tCan also set options via IO_SKINNER_OPTIONS environment variable.\n\n"
192 "\tDocumentation: "
193 "https://sandialabs.github.io/seacas-docs/sphinx/html/index.html#skinner\n\n"
194 "\t->->-> Send email to [email protected] for {} support.<-<-<-\n",
195 options_.program_name());
196 exit(EXIT_SUCCESS);
197 }
198
199 if (options_.retrieve("version") != nullptr) {
200 fmt::print(stderr, "skinner\tVersion: {}\n", version);
201 exit(0);
202 }
203
204 ints64Bit_ = options_.retrieve("64-bit") != nullptr;
205 netcdf4_ = options_.retrieve("netcdf4") != nullptr;
206 shuffle = options_.retrieve("shuffle") != nullptr;
207 noOutput_ = options_.retrieve("no_output") != nullptr;
208 outputTransient_ = options_.retrieve("output_transient") != nullptr;
209 useFaceHashIds_ = options_.retrieve("ignore_face_hash_ids") == nullptr;
210 debug = options_.retrieve("debug") != nullptr;
211 statistics = options_.retrieve("statistics") != nullptr;
212 blocks_ = options_.retrieve("blocks") != nullptr;
213
214 maximum_time = options_.get_option_value("Maximum_Time", maximum_time);
215 minimum_time = options_.get_option_value("Minimum_Time", minimum_time);
216
217 {
218 const char *temp = options_.retrieve("select_times");
219 if (temp != nullptr) {
220 auto time_str = Ioss::tokenize(std::string(temp), ",");
221 for (const auto &str : time_str) {
222 auto time = std::stod(str);
223 selected_times.push_back(time);
224 }
225 Ioss::sort(selected_times.begin(), selected_times.end());
226 }
227 }
228
229 {
230 const char *temp = options_.retrieve("compress");
231 if (temp != nullptr) {
232 compression_level = std::strtol(temp, nullptr, 10);
233 }
234 }
235
236 #if defined(SEACAS_HAVE_MPI)
237 if (options_.retrieve("rcb") != nullptr) {
238 decomp_method = "RCB";
239 }
240
241 if (options_.retrieve("rib") != nullptr) {
242 decomp_method = "RIB";
243 }
244
245 if (options_.retrieve("hsfc") != nullptr) {
246 decomp_method = "HSFC";
247 }
248
249 if (options_.retrieve("metis_sfc") != nullptr) {
250 decomp_method = "METIS_SFC";
251 }
252
253 if (options_.retrieve("kway") != nullptr) {
254 decomp_method = "KWAY";
255 }
256
257 if (options_.retrieve("kway_geom") != nullptr) {
258 decomp_method = "KWAY_GEOM";
259 }
260
261 if (options_.retrieve("linear") != nullptr) {
262 decomp_method = "LINEAR";
263 }
264
265 if (options_.retrieve("cyclic") != nullptr) {
266 decomp_method = "CYCLIC";
267 }
268
269 if (options_.retrieve("random") != nullptr) {
270 decomp_method = "RANDOM";
271 }
272
273 if (options_.retrieve("external") != nullptr) {
274 decomp_method = "EXTERNAL";
275 }
276
277 {
278 const char *temp = options_.retrieve("compose");
279 if (temp != nullptr) {
280 compose_output = Ioss::Utils::lowercase(temp);
281 }
282 }
283
284 #endif
285
286 {
287 const char *temp = options_.retrieve("in_type");
288 if (temp != nullptr) {
289 inFiletype_ = temp;
290 }
291 }
292
293 {
294 const char *temp = options_.retrieve("out_type");
295 if (temp != nullptr) {
296 outFiletype_ = temp;
297 }
298 }
299
300 if (options_.retrieve("copyright") != nullptr) {
301 Ioss::Utils::copyright(std::cerr, "1999-2023");
302 exit(EXIT_SUCCESS);
303 }
304
305 // Parse remaining options as directory paths.
306 if (option_index < argc) {
307 inputFile_ = argv[option_index++];
308 }
309
310 if (option_index < argc && !noOutput_) {
311 outputFile_ = argv[option_index];
312 }
313
314 if (inputFile_.empty() || (!noOutput_ && outputFile_.empty())) {
315 fmt::print(stderr, "\nERROR: input and output filename not specified\n\n");
316 return false;
317 }
318
319 // If inFileType and/or outFileType not specified, see if can infer from file suffix type...
320 if (inFiletype_ == "unknown") {
321 inFiletype_ = Ioss::Utils::get_type_from_file(inputFile_);
322 }
323 if (!noOutput_ && outFiletype_ == "unknown") {
324 outFiletype_ = Ioss::Utils::get_type_from_file(outputFile_);
325 }
326 return true;
327 }