Debian Codegraph @

packages/seacas/applications/exodiff/ED_SystemInterface.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"
8
9 #include <algorithm>
10 #include <fstream>
11 #include <functional>
12 #include <iostream>
13 #include <vector>
14
15 #include <climits>
16 #include <cstdlib>
17 #include <cstring>
18
19 #include "ED_Version.h"
20 #include "copy_string_cpp.h"
21 #include "copyright.h"
22 #include "fmt/ostream.h"
23 #include "stringx.h"
24 #include <SL_tokenize.h>
25
26 namespace {
27 [[noreturn]] void Parse_Die(std::string &sline)
28 {
29 chop_whitespace(sline);
30 Error(fmt::format("parsing input file, currently at \"{}\".\n", sline));
31 }
32
33 std::string Parse_Variables(std::string xline, std::ifstream &cmd_file, bool &all_flag,
34 Tolerance &def_tol, NameList &names, std::vector<Tolerance> &toler);
35
36 bool str_equal(const std::string &s1, const std::string &s2)
37 {
38 return (s1.size() == s2.size()) &&
39 std::equal(s1.begin(), s1.end(), s2.begin(),
40 [](char a, char b) { return std::tolower(a) == std::tolower(b); });
41 }
42
43 void file_help();
44 void tolerance_help();
45
46 double To_Double(const std::string &str_val)
47 {
48 SMART_ASSERT(!str_val.empty());
49
50 double val = 0;
51 try {
52 val = std::stod(str_val);
53 }
54 catch (...) {
55 Error(fmt::format(" Problem converting the string '{}'"
56 " to a double value while parsing tolerance. Aborting...\n",
57 str_val));
58 }
59
60 if (val < 0.0) {
61 Error(fmt::format(" Parsed a negative value \"{}\". Aborting...\n", val));
62 }
63 return val;
64 }
65
66 int File_Exists(const std::string &fname)
67 {
68 if (fname.empty()) {
69 return 0;
70 }
71 std::ifstream file_check(fname, std::ios::in);
72 if (file_check.fail()) {
73 return 0;
74 }
75 file_check.close();
76 return 1;
77 }
78
79 void Parse_Steps_Option(const std::string &option, int &start, int &stop, int &increment)
80 {
81 //: The defined formats for the count attribute are:<br>
82 //: <ul>
83 //: <li><missing> -- default -- 1 <= count <= oo (all steps)</li>
84 //: <li>"X" -- X <= count <= X (just step X)</li>
85 //: <li>"X:Y" -- X to Y by 1</li>
86 //: <li>"X:" -- X to oo by 1</li>
87 //: <li>":Y" -- 1 to Y by 1</li>
88 //: <li>"::Z" -- 1 to oo by Z</li>
89 //: </ul>
90 //: The count and step must always be >= 0
91
92 // Break into tokens separated by ":"
93
94 // Default is given in constructor above...
95
96 if (option == "last" || option == "LAST") {
97 start = -1;
98 return;
99 }
100 const char *tokens = option.c_str();
101 if (strchr(tokens, ':') != nullptr) {
102 // The string contains a separator
103
104 int vals[3];
105 vals[0] = start;
106 vals[1] = stop;
107 vals[2] = increment;
108
109 int j = 0;
110 for (auto &val : vals) {
111 // Parse 'i'th field
112 char tmp_str[128];
113 ;
114 int k = 0;
115
116 while (tokens[j] != '\0' && tokens[j] != ':') {
117 tmp_str[k++] = tokens[j++];
118 }
119
120 tmp_str[k] = '\0';
121 if (strlen(tmp_str) > 0) {
122 val = strtol(tmp_str, nullptr, 0);
123 }
124
125 if (tokens[j++] == '\0') {
126 break; // Reached end of string
127 }
128 }
129 start = vals[0];
130 stop = vals[1];
131 increment = vals[2];
132 }
133 else {
134 // Does not contain a separator, min == max
135 start = stop = strtol(tokens, nullptr, 0);
136 }
137 }
138
139 void Check_Parsed_Names(const NameList &names, bool &all_flag)
140 {
141 int num_include = 0;
142 int num_exclude = 0;
143 for (const auto &name : names) {
144 SMART_ASSERT(!name.empty());
145 if (name[0] == '!') {
146 ++num_exclude;
147 }
148 else {
149 ++num_include;
150 }
151 }
152 if (!all_flag && num_include > 0 && num_exclude > 0) {
153 Error(fmt::format("Parsing error: Cannot specify both "
154 "variables to include and exclude without using the "
155 "'(all)' specifier. Aborting...\n"));
156 }
157 if (num_include == 0 && num_exclude > 0) {
158 all_flag = true;
159 }
160 }
161
162 void parseExcludeTimes(std::string exclude_arg, std::vector<int> &exclude_steps)
163 {
164 std::string arg_copy = exclude_arg;
165
166 int num_excluded_steps = 0;
167
168 // first pass just counts the number of excluded time steps:
169
170 std::string tok = extract_token(exclude_arg, ",");
171 while (!tok.empty()) {
172 std::string subtok = extract_token(tok, "-");
173 SMART_ASSERT(!subtok.empty());
174
175 errno = 0;
176 int ival1 = std::stoi(subtok);
177 SMART_ASSERT(errno == 0);
178
179 if (ival1 < 1) {
180 Error(fmt::format("parsing exclusion times from command "
181 "line .. value was less than 1\n"));
182 }
183
184 ++num_excluded_steps;
185
186 subtok = extract_token(tok, "-");
187 if (!subtok.empty()) {
188 errno = 0;
189 int ival2 = std::stoi(subtok);
190 SMART_ASSERT(errno == 0);
191
192 if (ival2 < 1) {
193 Error(fmt::format("parsing exclusion times from command "
194 "line .. value was less than 1\n"));
195 }
196
197 if (ival1 < ival2) {
198 for (int i = ival1 + 1; i <= ival2; ++i) {
199 ++num_excluded_steps;
200 }
201 }
202 else if (ival1 > ival2) {
203 Error(fmt::format("parsing exclusion times from command "
204 "line .. first value in a range was greater than the "
205 "second.\n"));
206 }
207 }
208
209 tok = extract_token(exclude_arg, ",");
210 }
211
212 if (num_excluded_steps > 0) {
213 exclude_steps.resize(num_excluded_steps);
214
215 // second pass collects the excluded time steps
216
217 exclude_arg = std::move(arg_copy);
218 num_excluded_steps = 0;
219
220 tok = extract_token(exclude_arg, ",");
221 while (!tok.empty()) {
222 std::string subtok = extract_token(tok, "-");
223 SMART_ASSERT(!subtok.empty());
224
225 errno = 0;
226 int ival1 = std::stoi(subtok);
227 SMART_ASSERT(errno == 0);
228
229 exclude_steps[num_excluded_steps++] = ival1;
230
231 subtok = extract_token(tok, "-");
232 if (!subtok.empty()) {
233 errno = 0;
234 int ival2 = std::stoi(subtok);
235 SMART_ASSERT(errno == 0);
236
237 for (int i = ival1 + 1; i <= ival2; ++i) {
238 exclude_steps[num_excluded_steps++] = i;
239 }
240 }
241
242 tok = extract_token(exclude_arg, ",");
243 }
244 }
245 }
246 } // namespace
247
248 SystemInterface::SystemInterface() { enroll_options(); }
249
250 void SystemInterface::show_version()
251 {
252 fmt::print("EXODIFF\t(Version: {}) Modified: {}\n", version, verdate);
253 }
254
255 void SystemInterface::enroll_options()
256 {
257 options_.usage("[options] file1.exo file2.exo [diffile.exo] \n"
258 "\tor: exodiff -summary <file.exo> (create variable summary) \n"
259 "\tor: exodiff [-help] [tolerance|file] (usage) \n"
260 "\tor: exodiff [-version] \n");
261
262 options_.enroll(
263 "help", GetLongOption::OptionalValue,
264 "Print this summary and exit.\n"
265 "\t\tEnter \"-help file\" for the syntax of the command file\n"
266 "\t\t \"-help tolerance\" for information on the supported tolerance options.",
267 nullptr, "usage");
268
269 options_.enroll("Help", GetLongOption::NoValue, "Print this summary and exit.", nullptr);
270 options_.enroll("file", GetLongOption::MandatoryValue,
271 "Use the given file to specify the variables to be considered and to\n"
272 "\t\twhat tolerances. Enter \"-help file\" for the syntax of the command file",
273 nullptr);
274 options_.enroll("summary", GetLongOption::NoValue,
275 "Produce a summary in exodiff input format.\n"
276 "\t\tThis will create output with max/min statistics on the data in the format\n"
277 "\t\tof an exodiff input file.",
278 nullptr);
279 options_.enroll("change_sets", GetLongOption::MandatoryValue,
280 "Specify the change_set(s) to be compared in the two files.\n"
281 "\t\tSeparate change set names/indices with a comma ',';\n"
282 "\t\tSeparate file1 cs from file2 cs with colon ':' if they are different.\n"
283 "\t\tCan use 1-based index or names. Use index 0 or name 'root' if file doesn't "
284 "have change sets.\n"
285 "\t\tIf not specified, diff all change sets (if any) in files.",
286 nullptr, nullptr, true);
287
288 // Tolerance options...
289 options_.enroll("tolerance", GetLongOption::MandatoryValue,
290 "Overrides the default tolerance of 1.0E-6.", "1.0E-6");
291
292 options_.enroll("Floor", GetLongOption::MandatoryValue,
293 "Overrides the default floor tolerance of 0.0.", "0.0");
294
295 options_.enroll("absolute", GetLongOption::NoValue,
296 "Default tolerance is absolute difference. |a-b| > tolerance", nullptr);
297 options_.enroll("relative", GetLongOption::NoValue,
298 "Default tolerance is relative difference. |a-b| > max(|a|,|b|)*tolerance",
299 nullptr);
300 options_.enroll("combined", GetLongOption::NoValue,
301 "Default tolerance is combined difference. (-help tolerance for info)", nullptr);
302 options_.enroll("ulps_float", GetLongOption::NoValue,
303 "Default tolerance if number of ulps (units last position) of difference\n"
304 "\t\twhen values converted to floats.",
305 nullptr);
306 options_.enroll("ulps_double", GetLongOption::NoValue,
307 "Default tolerance is number of ulps (units last position) of difference.",
308 nullptr);
309 options_.enroll("eigen_absolute", GetLongOption::NoValue,
310 "Default tolerance is absolute differences of the absolute value of the values.",
311 nullptr);
312 options_.enroll("eigen_relative", GetLongOption::NoValue,
313 "Default tolerance is relative differences of the absolute value of the values.",
314 nullptr);
315 options_.enroll("eigen_combined", GetLongOption::NoValue,
316 "Default tolerance is combined differences of the absolute value of the values.",
317 nullptr);
318 options_.enroll("ignore", GetLongOption::NoValue,
319 "Default tolerance is ignored (turn off all checking by default).", nullptr);
320 options_.enroll("coordinate_tolerance", GetLongOption::MandatoryValue,
321 "Overrides the default coordinate comparison tolerance of 1.0E-6.", "1.0E-6",
322 nullptr, true);
323
324 options_.enroll("pedantic", GetLongOption::NoValue, "Be more picky about what is a difference.",
325 nullptr);
326 options_.enroll("quiet", GetLongOption::NoValue,
327 "Quiet. Only errors will be sent to stdout. Comparison mode will echo\n"
328 "\t\t\"exodiff: Files are the same.\" or \"exodiff: Files are different.\"",
329 nullptr);
330 options_.enroll("show_all_diffs", GetLongOption::NoValue,
331 "Show all differences for all variables, not just the maximum.", nullptr, nullptr,
332 true);
333
334 options_.enroll("ignore_steps", GetLongOption::NoValue,
335 "Don't compare any transient data; compare mesh only.", nullptr);
336 options_.enroll(
337 "exclude", GetLongOption::MandatoryValue,
338 "Exclude time steps. Does not consider the time steps given in the list of integers.\n"
339 "\t\tThe format is comma-separated and ranged integers (with no spaces), such as "
340 "\"1,5-9,28\".\n"
341 "\t\tThe first time step is the number '1'.",
342 nullptr);
343 options_.enroll("steps", GetLongOption::MandatoryValue,
344 "Specify subset of steps to consider. Syntax is beg:end:increment,\n"
345 "\t\tEnter '-steps last' for just the last step. If only beg set, end=beg",
346 nullptr);
347 options_.enroll("explicit", GetLongOption::MandatoryValue,
348 "Specify an explicit match of a step on database 1 with a step on database 2.\n"
349 "\t\tSyntax is '-explicit db1_step:db2_step' where 'db*_step' is either\n"
350 "\t\tthe 1-based step number or 'last' for the last step on the database.\n"
351 "\t\tExample: '-explicit 42:last' to match step 42 on database 1 with last step "
352 "on database 2",
353 nullptr);
354 options_.enroll("TimeStepOffset", GetLongOption::MandatoryValue,
355 "Timestep 'x+offset' in first file matches timestep 'x' in second file.",
356 nullptr);
357 options_.enroll("TA", GetLongOption::NoValue,
358 "Automatic determination of timestep offset -- end at same step.", nullptr);
359 options_.enroll(
360 "TM", GetLongOption::NoValue,
361 "Automatic determination of timestep offset -- closest match to first step on file2.",
362 nullptr);
363 options_.enroll("interpolate", GetLongOption::NoValue,
364 "Interpolate times on file2 to match times on file1.", nullptr);
365 options_.enroll(
366 "final_time_tolerance", GetLongOption::MandatoryValue,
367 "Tolerance on matching of final times on database when interpolate option specified.\n"
368 "\t\tIf final times do not match within this tolerance, files are different.",
369 nullptr, nullptr, true);
370
371 options_.enroll("time_scale", GetLongOption::MandatoryValue,
372 "Scale the time values on the input database by the specified value.", nullptr);
373 options_.enroll(
374 "time_offset", GetLongOption::MandatoryValue,
375 "Offset the (possibly scaled) time values on the input database by the specified value.",
376 nullptr, nullptr, true);
377
378 options_.enroll("map", GetLongOption::NoValue,
379 "Invokes a matching algorithm to create a mapping between the\n"
380 "\t\tnodes and elements of the two files. The topology must still be\n"
381 "\t\tthe same (within tolerance), but can be ordered differently.",
382 nullptr);
383 options_.enroll("dumpmap", GetLongOption::NoValue,
384 "If the -map switch used, print the resulting node and element maps.", nullptr);
385 options_.enroll("partial", GetLongOption::NoValue,
386 "Invokes a matching algorithm similar to the -m option. However \n"
387 "\t\tthis option ignores unmatched nodes and elements. This allows \n"
388 "\t\tcomparison of files that only partially overlap.",
389 nullptr);
390 options_.enroll("show_unmatched", GetLongOption::NoValue,
391 "If the -partial switch used, print the elements that did not match.", nullptr);
392 options_.enroll("ignore_dups", GetLongOption::NoValue,
393 "If two elements/nodes are in the same location in map or partial\n"
394 " map case, just return first match instead of aborting.",
395 nullptr);
396 options_.enroll("match_ids", GetLongOption::NoValue,
397 "Invokes a matching algorithm using the node and element global id\n"
398 "\t\tmaps in the two files.",
399 nullptr);
400 options_.enroll("match_file_order", GetLongOption::NoValue,
401 "Verifies that node and element ids match and are in same order\n"
402 "\t\tin the two files.",
403 nullptr);
404 options_.enroll("match_by_name", GetLongOption::NoValue,
405 "Match element blocks, nodesets, and sidesets by name instead of by id.",
406 nullptr);
407 options_.enroll("nsmap", GetLongOption::NoValue,
408 "Creates a map between the nodeset nodes in the two files\n"
409 "\t\tif they include the same nodes, but are in different order.",
410 nullptr);
411 options_.enroll("ssmap", GetLongOption::NoValue,
412 "Creates a map between the sideset faces in the two files\n"
413 "\t\tif they include the same sides, but are in different order.",
414 nullptr);
415 options_.enroll("no_nsmap", GetLongOption::NoValue,
416 "Compare nodeset nodes based on file order only", nullptr);
417 options_.enroll("no_ssmap", GetLongOption::NoValue,
418 "Compare sideset faces based on file order only", nullptr, nullptr, true);
419
420 options_.enroll("short", GetLongOption::NoValue,
421 "Short block type compare. Forces element block type strings to\n"
422 "\t\tbe compared only up to the shortest string length. For example,\n"
423 "\t\t\"HEX\" and \"HEX8\" will be considered the same. (default)",
424 nullptr);
425 options_.enroll("no_short", GetLongOption::NoValue,
426 "Do not do short block type compare. Forces element block\n"
427 "\t\ttype strings to fully match. For example, \"HEX\" and \"HEX8\"\n"
428 "\t\twill be considered different.",
429 nullptr);
430 options_.enroll("ignore_case", GetLongOption::NoValue,
431 "Ignore case. Variable names are compared case in-sensitive (default).",
432 nullptr);
433 options_.enroll("case_sensitive", GetLongOption::NoValue,
434 "Variable names are compared case sensitive.", nullptr);
435 options_.enroll("nosymmetric_name_check", GetLongOption::NoValue,
436 "No symmetric variable name checking. By default, a warning will\n"
437 "\t\tbe produced if a name that is not to be excluded is contained\n"
438 "\t\tin the second file given on the command line but not the first.\n"
439 "\t\tThis \"symmetric\" check can be turned off with this option.",
440 nullptr);
441 options_.enroll("allow_name_mismatch", GetLongOption::NoValue,
442 "Allow a variable name that is in the first database to not be in the\n"
443 "\t\tsecond database",
444 nullptr, nullptr, true);
445
446 options_.enroll("ignore_maps", GetLongOption::NoValue,
447 "Output node and element diff summaries using file local implicit ids\n"
448 "\t\tinstead of global ids.",
449 nullptr);
450 options_.enroll("ignore_nans", GetLongOption::NoValue, "Don't check data for NaNs", nullptr);
451 options_.enroll("ignore_attributes", GetLongOption::NoValue,
452 "Don't compare element attribute values.", nullptr);
453 options_.enroll("ignore_sideset_df", GetLongOption::NoValue,
454 "Don't compare sideset distribution factors.", nullptr, nullptr, true);
455
456 options_.enroll("norms", GetLongOption::NoValue,
457 "Calculate L1 and L2 norms of variable differences and output if > 0.0", nullptr);
458 options_.enroll("l2norms", GetLongOption::NoValue,
459 "Calculate L2 norm of variable differences and output if > 0.0", nullptr);
460 options_.enroll("l1norms", GetLongOption::NoValue,
461 "Calculate L1 norm of variable differences and output if > 0.0", nullptr);
462
463 options_.enroll("status", GetLongOption::NoValue,
464 "Return exit status of 2 if the files are different. (default).", nullptr);
465 options_.enroll("ignore_status", GetLongOption::NoValue,
466 "The exit status is always zero unless an error occurs.", nullptr);
467
468 options_.enroll(
469 "max_warnings", GetLongOption::MandatoryValue,
470 "Maximum number of warnings to output during element/node matching process. Default 100.",
471 "100");
472 options_.enroll("use_old_floor", GetLongOption::NoValue,
473 "use the older definition of the floor tolerance.\n"
474 "\t\tOLD: ignore if |a-b| < floor.\n"
475 "\t\tNEW: ignore if |a| < floor && |b| < floor.",
476 nullptr);
477 options_.enroll("64-bit", GetLongOption::NoValue,
478 "True if forcing the use of 64-bit integers for the output file in summary mode",
479 nullptr);
480 options_.enroll("min_coordinate_separation", GetLongOption::NoValue,
481 "In summary mode, calculate the minimum distance between any two nodes", nullptr);
482 options_.enroll("copyright", GetLongOption::NoValue, "Output copyright and license information.",
483 nullptr);
484 options_.enroll("version", GetLongOption::NoValue, "Output code version", nullptr);
485
486 options_.enroll("maxnames", GetLongOption::MandatoryValue, "[deprecated -- no longer needed]",
487 "1000");
488 options_.enroll("t", GetLongOption::MandatoryValue, "Backward-compatible option for -tolerance",
489 "1.0E-6");
490 options_.enroll("m", GetLongOption::NoValue, "Backward-compatible option for -map", nullptr);
491 options_.enroll("p", GetLongOption::NoValue, "Backward-compatible option for -partial.", nullptr);
492 options_.enroll("s", GetLongOption::NoValue, "Backward-compatible option for -short", nullptr);
493 options_.enroll("i", GetLongOption::NoValue, "Backward-compatible option for -ignore_case.",
494 nullptr);
495 options_.enroll("f", GetLongOption::MandatoryValue, "Backward-compatible option for -file",
496 nullptr);
497 options_.enroll("T", GetLongOption::MandatoryValue,
498 "Backward-compatible option for -TimeStepOffset", nullptr);
499 options_.enroll("x", GetLongOption::MandatoryValue, "Backward-compatible option for -exclude",
500 nullptr);
501 }
502
503 bool SystemInterface::parse_options(int argc, char **argv)
504 {
505 int option_index = options_.parse(argc, argv);
506 if (option_index < 1) {
507 return false;
508 }
509
510 {
511 const char *temp = options_.retrieve("help");
512 if (temp != nullptr) {
513 if ((str_equal("usage", temp)) || (str_equal("all", temp))) {
514 options_.usage();
515 }
516 if ((str_equal("file", temp)) || (str_equal("all", temp))) {
517 file_help();
518 }
519 if ((str_equal("tolerance", temp)) || (str_equal("all", temp))) {
520 tolerance_help();
521 }
522 fmt::print("\n\t\tCan also set options via EXODIFF_OPTIONS environment variable.\n");
523 fmt::print("\n\t\tDocumentation: "
524 "https://sandialabs.github.io/seacas-docs/sphinx/html/index.html#exodiff\n");
525 fmt::print("\t\t->->-> Send email to [email protected] for exodiff support.<-<-<-\n");
526 exit(EXIT_SUCCESS);
527 }
528 }
529
530 if (options_.retrieve("Help") != nullptr) {
531 options_.usage();
532 fmt::print("\n\t\tCan also set options via EXODIFF_OPTIONS environment variable.\n");
533 fmt::print("\n\t\tDocumentation: "
534 "https://sandialabs.github.io/seacas-docs/sphinx/html/index.html#exodiff\n");
535 fmt::print("\t\t->->-> Send email to [email protected] for exodiff support.<-<-<-\n");
536 exit(EXIT_SUCCESS);
537 }
538
539 if (options_.retrieve("version") != nullptr) {
540 show_version();
541 exit(EXIT_SUCCESS);
542 }
543
544 if (options_.retrieve("copyright") != nullptr) {
545 fmt::print("{}", copyright("2008-2021"));
546 exit(EXIT_SUCCESS);
547 }
548
549 // Parse remaining options as filenames
550 if (option_index < argc) {
551 file1 = argv[option_index++];
552 if (option_index < argc) {
553 file2 = argv[option_index++];
554 }
555 if (option_index < argc) {
556 if (option_index + 1 == argc) {
557 diff_file = argv[option_index++];
558 }
559 else {
560 // Check for additional unknown arguments...
561 std::ostringstream out;
562 fmt::print(
563 out,
564 "\nexodiff: ERROR: Too many file arguments specified.\n"
565 " Probably caused by options following filenames which is no longer allowed.\n"
566 " Unknown options are: ");
567 while (option_index < argc) {
568 fmt::print(out, "'{}' ", argv[option_index++]);
569 }
570 fmt::print(out, "\n\n");
571 ERR_OUT(out);
572 return false;
573 }
574 }
575 }
576 else {
577 Error("no files specified\n\n");
578 }
579
580 // Get options from environment variable also...
581 char *options = getenv("EXODIFF_OPTIONS");
582 if (options != nullptr) {
583 fmt::print(
584 "\nThe following options were specified via the EXODIFF_OPTIONS environment variable:\n"
585 "\t\t{}\n\n",
586 options);
587 options_.parse(options, GetLongOption::basename(*argv));
588 }
589
590 if (options_.retrieve("summary") != nullptr) {
591 summary_flag = true;
592 }
593
594 if (options_.retrieve("min_coordinate_separation") != nullptr) {
595 coord_sep = true;
596 }
597
598 {
599 const char *temp = options_.retrieve("exclude");
600 if (temp != nullptr) {
601 parseExcludeTimes(temp, exclude_steps);
602 }
603 }
604
605 {
606 const char *temp = options_.retrieve("x");
607 if (temp != nullptr) {
608 parseExcludeTimes(temp, exclude_steps);
609 }
610 }
611
612 {
613 auto t1 = options_.get_option_value("t", default_tol.value);
614 auto t2 = options_.get_option_value("tolerance", default_tol.value);
615 if (t1 != default_tol.value) {
616 default_tol.value = t1;
617 }
618 else if (t2 != default_tol.value) {
619 default_tol.value = t2;
620 }
621 }
622
623 coord_tol.value = options_.get_option_value("coordinate_tolerance", coord_tol.value);
624 default_tol.floor = options_.get_option_value("Floor", default_tol.floor);
625 final_time_tol.value = options_.get_option_value("final_time_tolerance", final_time_tol.value);
626
627 time_value_offset = options_.get_option_value("time_offset", time_value_offset);
628 time_value_scale = options_.get_option_value("time_scale", time_value_scale);
629
630 {
631 const char *temp = options_.retrieve("TimeStepOffset");
632 if (temp != nullptr) {
633 errno = 0;
634 time_step_offset = strtol(temp, nullptr, 10);
635 SMART_ASSERT(errno == 0);
636 }
637 else {
638 const char *temp2 = options_.retrieve("T");
639 if (temp2 != nullptr) {
640 errno = 0;
641 time_step_offset = strtol(temp2, nullptr, 10);
642 SMART_ASSERT(errno == 0);
643 }
644 }
645 }
646
647 if (options_.retrieve("TA") != nullptr) {
648 time_step_offset = -1; // Signifies automatic offset calculation.
649 }
650
651 if (options_.retrieve("TM") != nullptr) {
652 time_step_offset = -2; // Signifies automatic offset calculation -- closest match
653 }
654
655 {
656 const char *temp = options_.retrieve("change_sets");
657 if (temp != nullptr) {
658 change_sets = temp;
659 }
660 }
661
662 {
663 const char *temp = options_.retrieve("steps");
664 if (temp != nullptr) {
665 Parse_Steps_Option(temp, time_step_start, time_step_stop, time_step_increment);
666 }
667 }
668
669 {
670 const char *temp = options_.retrieve("explicit");
671 if (temp != nullptr) {
672 // temp should be of the form <ts1>:<ts2> where ts# is either a timestep number
673 // (1-based) or 'last'
674 NameList tokens = SLIB::tokenize(temp, ":");
675 if (tokens.size() == 2) {
676 if (str_equal(tokens[0], "last")) {
677 explicit_steps.first = -1;
678 }
679 else {
680 // Try to convert to integer...
681 explicit_steps.first = std::stoi(tokens[0]);
682 }
683
684 if (str_equal(tokens[1], "last")) {
685 explicit_steps.second = -1;
686 }
687 else {
688 // Try to convert to integer...
689 explicit_steps.second = std::stoi(tokens[1]);
690 }
691 }
692 else {
693 Error(fmt::format("parse error for -explicit keyword. "
694 "Expected '<int|last>:<int|last>', found '{}' Aborting...\n",
695 temp));
696 }
697 }
698 }
699
700 if (options_.retrieve("quiet") != nullptr) {
701 quiet_flag = true;
702 }
703
704 if (options_.retrieve("show_all_diffs") != nullptr) {
705 show_all_diffs = true;
706 }
707
708 if ((options_.retrieve("partial") != nullptr) || (options_.retrieve("p") != nullptr)) {
709 map_flag = MapType::PARTIAL;
710 }
711
712 if (options_.retrieve("match_ids") != nullptr) {
713 map_flag = MapType::USE_FILE_IDS;
714 }
715
716 if (options_.retrieve("match_file_order") != nullptr) {
717 map_flag = MapType::FILE_ORDER;
718 }
719
720 if (options_.retrieve("match_by_name") != nullptr) {
721 by_name = true;
722 }
723
724 if ((options_.retrieve("map") != nullptr) || (options_.retrieve("m") != nullptr)) {
725 map_flag = MapType::DISTANCE;
726 }
727 if (options_.retrieve("nsmap") != nullptr) {
728 nsmap_flag = true;
729 }
730 if (options_.retrieve("no_nsmap") != nullptr) {
731 nsmap_flag = false;
732 }
733 if (options_.retrieve("ssmap") != nullptr) {
734 ssmap_flag = true;
735 }
736 if (options_.retrieve("no_ssmap") != nullptr) {
737 ssmap_flag = false;
738 }
739 if ((options_.retrieve("short") != nullptr) || (options_.retrieve("s") != nullptr)) {
740 short_block_check = true;
741 }
742 if (options_.retrieve("no_short") != nullptr) {
743 short_block_check = false;
744 }
745 if (options_.retrieve("nosymmetric_name_check") != nullptr) {
746 noSymmetricNameCheck = true;
747 }
748 if (options_.retrieve("norms") != nullptr) {
749 doL1Norm = true;
750 doL2Norm = true;
751 }
752 if (options_.retrieve("l2norms") != nullptr) {
753 doL2Norm = true;
754 }
755 if (options_.retrieve("l1norms") != nullptr) {
756 doL1Norm = true;
757 }
758 if (options_.retrieve("pedantic") != nullptr) {
759 pedantic = true;
760 }
761 if (options_.retrieve("interpolate") != nullptr) {
762 interpolating = true;
763 }
764
765 if (options_.retrieve("allow_name_mismatch") != nullptr) {
766 allowNameMismatch = true;
767 }
768 if ((options_.retrieve("ignore_case") != nullptr) || (options_.retrieve("i") != nullptr)) {
769 nocase_var_names = true;
770 }
771 if (options_.retrieve("case_sensitive") != nullptr) {
772 nocase_var_names = false;
773 }
774 if (options_.retrieve("ignore_maps") != nullptr) {
775 ignore_maps = true;
776 }
777 if (options_.retrieve("ignore_nans") != nullptr) {
778 ignore_nans = true;
779 }
780 if (options_.retrieve("ignore_dups") != nullptr) {
781 ignore_dups = true;
782 }
783 if (options_.retrieve("ignore_steps") != nullptr) {
784 ignore_steps = true;
785 }
786 if (options_.retrieve("64-bit") != nullptr) {
787 ints_64_bits = true;
788 }
789 if (options_.retrieve("ignore_attributes") != nullptr) {
790 ignore_attributes = true;
791 }
792 if (options_.retrieve("ignore_sideset_df") != nullptr) {
793 ignore_sideset_df = true;
794 }
795 if (options_.retrieve("relative") != nullptr) {
796 output_type = ToleranceMode::RELATIVE_; // Change type to relative.
797 default_tol.type = ToleranceMode::RELATIVE_;
798 }
799 if (options_.retrieve("ignore") != nullptr) {
800 output_type = ToleranceMode::IGNORE_; // Change type to ignored
801 default_tol.type = ToleranceMode::IGNORE_;
802 }
803 if (options_.retrieve("absolute") != nullptr) {
804 output_type = ToleranceMode::ABSOLUTE_; // Change type to absolute
805 default_tol.type = ToleranceMode::ABSOLUTE_;
806 }
807 if (options_.retrieve("combined") != nullptr) {
808 output_type = ToleranceMode::COMBINED_; // Change type to combine
809 default_tol.type = ToleranceMode::COMBINED_;
810 }
811 if (options_.retrieve("ulps_float") != nullptr) {
812 output_type = ToleranceMode::ULPS_FLOAT_;
813 default_tol.type = ToleranceMode::ULPS_FLOAT_;
814 }
815 if (options_.retrieve("ulps_double") != nullptr) {
816 output_type = ToleranceMode::ULPS_DOUBLE_;
817 default_tol.type = ToleranceMode::ULPS_DOUBLE_;
818 }
819 if (options_.retrieve("eigen_relative") != nullptr) {
820 output_type = ToleranceMode::EIGEN_REL_; // Change type to relative.
821 default_tol.type = ToleranceMode::EIGEN_REL_;
822 }
823 if (options_.retrieve("eigen_absolute") != nullptr) {
824 output_type = ToleranceMode::EIGEN_ABS_; // Change type to absolute
825 default_tol.type = ToleranceMode::EIGEN_ABS_;
826 }
827 if (options_.retrieve("eigen_combined") != nullptr) {
828 output_type = ToleranceMode::EIGEN_COM_; // Change type to combine
829 default_tol.type = ToleranceMode::EIGEN_COM_;
830 }
831 if (options_.retrieve("dumpmap") != nullptr) {
832 dump_mapping = true;
833 }
834 if (options_.retrieve("show_unmatched") != nullptr) {
835 show_unmatched = true;
836 }
837
838 {
839 const char *temp = options_.retrieve("max_warnings");
840 if (temp != nullptr) {
841 errno = 0;
842 max_warnings = strtol(temp, nullptr, 10);
843 SMART_ASSERT(errno == 0);
844 }
845 }
846
847 if (options_.retrieve("status") != nullptr) {
848 exit_status_switch = true;
849 }
850
851 if (options_.retrieve("ignore_status") != nullptr) {
852 exit_status_switch = false;
853 }
854
855 if (options_.retrieve("use_old_floor") != nullptr) {
856 Tolerance::use_old_floor = true; // Change type to relative.
857 }
858
859 {
860 // Reset default tolerances in case the -t flag was given.
861 time_tol = default_tol;
862 glob_var_default = default_tol;
863 node_var_default = default_tol;
864 elmt_var_default = default_tol;
865 elmt_att_default = default_tol;
866 ns_var_default = default_tol;
867 ss_var_default = default_tol;
868 eb_var_default = default_tol;
869 fb_var_default = default_tol;
870
871 const char *temp = options_.retrieve("file");
872 if (temp != nullptr) {
873 command_file = temp;
874 if (!summary_flag && (File_Exists(command_file) == 0)) {
875 Error(fmt::format("Can't open file \"{}\".\n", command_file));
876 }
877
878 // Command file exists, parse contents...
879 Parse_Command_File();
880 }
881 else {
882 const char *t2 = options_.retrieve("f");
883 if (t2 != nullptr) {
884 command_file = t2;
885 if (!summary_flag && (File_Exists(command_file) == 0)) {
886 Error(fmt::format("Can't open file \"{}\".\n", command_file));
887 }
888
889 // Command file exists, parse contents...
890 Parse_Command_File();
891 }
892 else {
893 glob_var_do_all_flag = true;
894 node_var_do_all_flag = true;
895 elmt_var_do_all_flag = true;
896 elmt_att_do_all_flag = true;
897 ns_var_do_all_flag = true;
898 ss_var_do_all_flag = true;
899 eb_var_do_all_flag = true;
900 fb_var_do_all_flag = true;
901 }
902 }
903 }
904 return true;
905 }
906
907 void SystemInterface::Parse_Command_File()
908 {
909 int default_tol_specified = 0;
910
911 std::ifstream cmd_file(command_file, std::ios::in);
912 SMART_ASSERT(cmd_file.good());
913
914 std::string line;
915 std::string xline, tok2, tok3;
916 std::getline(cmd_file, line);
917 xline = line;
918 while (!cmd_file.eof()) {
919 std::string tok1;
920 // Skip blank lines and comment lines.
921 if (count_tokens(xline, " \t") > 0 && (tok1 = extract_token(xline, " \t"))[0] != '#') {
922 to_lower(tok1); // Make case insensitive.
923 tok2 = extract_token(xline, " \t");
924 to_lower(tok2);
925
926 if (abbreviation(tok1, "default", 3) && abbreviation(tok2, "tolerance", 3)) {
927 std::string tok = extract_token(xline, " \n\t=,");
928 to_lower(tok);
929 if (tok.empty()) {
930 Parse_Die(line);
931 }
932
933 if (abbreviation(tok, "relative", 3)) {
934 default_tol.type = ToleranceMode::RELATIVE_;
935 tok = extract_token(xline, " \n\t=,");
936 }
937 else if (abbreviation(tok, "absolute", 3)) {
938 default_tol.type = ToleranceMode::ABSOLUTE_;
939 tok = extract_token(xline, " \n\t=,");
940 }
941 else if (abbreviation(tok, "combine", 3)) {
942 default_tol.type = ToleranceMode::COMBINED_;
943 tok = extract_token(xline, " \n\t=,");
944 }
945 else if (abbreviation(tok, "eigen_relative", 7)) {
946 default_tol.type = ToleranceMode::EIGEN_REL_;
947 tok = extract_token(xline, " \n\t=,");
948 }
949 else if (abbreviation(tok, "eigen_absolute", 7)) {
950 default_tol.type = ToleranceMode::EIGEN_ABS_;
951 tok = extract_token(xline, " \n\t=,");
952 }
953 else if (abbreviation(tok, "eigen_combine", 7)) {
954 default_tol.type = ToleranceMode::EIGEN_COM_;
955 tok = extract_token(xline, " \n\t=,");
956 }
957 else if (abbreviation(tok, "ignore", 3)) {
958 default_tol.type = ToleranceMode::IGNORE_;
959 tok = extract_token(xline, " \n\t=,");
960 }
961 if (tok.empty()) {
962 Parse_Die(line);
963 }
964
965 default_tol.value = To_Double(tok);
966
967 tok = extract_token(xline, " \n\t=,");
968 to_lower(tok);
969 if (abbreviation(tok, "floor", 3)) {
970 tok = extract_token(xline, " \n\t=,");
971 if (tok.empty()) {
972 Parse_Die(line);
973 }
974 default_tol.floor = To_Double(tok);
975 }
976 default_tol_specified = 1;
977 }
978 else if (abbreviation(tok1, "max", 3) && abbreviation(tok2, "names", 3)) {
979 ; // Ignored -- no longer needed.
980 }
981 else if (abbreviation(tok1, "final", 3) && abbreviation(tok2, "time", 3)) {
982 tok3 = extract_token(xline, " \t");
983 to_lower(tok3);
984 if (!abbreviation(tok3, "tolerance", 3)) {
985 Error(fmt::format(" expected \"TOLERANCE\" after the \"FINAL TIME\" keyword. "
986 "Found \"{}\" instead. Aborting...\n",
987 tok3));
988 }
989 std::string tok = extract_token(xline, " \n\t=,");
990 if (tok.empty()) {
991 Parse_Die(line);
992 }
993 final_time_tol.value = To_Double(tok);
994 }
995 else if (abbreviation(tok1, "return", 3) && abbreviation(tok2, "status", 3)) {
996 exit_status_switch = true;
997 }
998 else if (abbreviation(tok1, "ignore", 3) && abbreviation(tok2, "status", 3)) {
999 exit_status_switch = false;
1000 }
1001 else if (abbreviation(tok1, "exclude", 3) && abbreviation(tok2, "times", 3)) {
1002 std::string tok = extract_token(xline, " \n\t=");
1003 if (!tok.empty() && tok[0] != '#') {
1004 parseExcludeTimes(tok, exclude_steps);
1005 }
1006 }
1007 else if (abbreviation(tok1, "apply", 3) && abbreviation(tok2, "matching", 3)) {
1008 map_flag = MapType::DISTANCE;
1009 }
1010 else if (abbreviation(tok1, "calculate", 3) && abbreviation(tok2, "norms", 3)) {
1011 doL2Norm = true;
1012 doL1Norm = true;
1013 }
1014 else if (abbreviation(tok1, "calculate", 3) && abbreviation(tok2, "l2norms", 3)) {
1015 doL2Norm = true;
1016 }
1017 else if (abbreviation(tok1, "calculate", 3) && abbreviation(tok2, "l1norms", 3)) {
1018 doL1Norm = true;
1019 }
1020 else if (tok1 == "nodeset" && abbreviation(tok2, "match", 3)) {
1021 nsmap_flag = true;
1022 }
1023 else if (tok1 == "pedantic") {
1024 pedantic = true;
1025 }
1026 else if (tok1 == "interpolate") {
1027 interpolating = true;
1028 }
1029 else if (tok1 == "sideset" && abbreviation(tok2, "match", 3)) {
1030 ssmap_flag = true;
1031 }
1032 else if (abbreviation(tok1, "short", 3) && abbreviation(tok2, "blocks", 3)) {
1033 short_block_check = true;
1034 }
1035 else if (tok1 == "no" && abbreviation(tok2, "short", 3)) {
1036 short_block_check = false;
1037 }
1038 else if (abbreviation(tok1, "ignore", 3) && abbreviation(tok2, "case", 3)) {
1039 nocase_var_names = true;
1040 }
1041 else if (abbreviation(tok1, "case", 3) && abbreviation(tok2, "sensitive", 3)) {
1042 nocase_var_names = false;
1043 }
1044 else if (abbreviation(tok1, "ignore", 3) && abbreviation(tok2, "maps", 3)) {
1045 ignore_maps = true;
1046 }
1047 else if (abbreviation(tok1, "ignore", 3) && abbreviation(tok2, "nans", 3)) {
1048 ignore_nans = true;
1049 }
1050 else if (abbreviation(tok1, "ignore", 3) && abbreviation(tok2, "dups", 3)) {
1051 ignore_dups = true;
1052 }
1053 else if (abbreviation(tok1, "ignore", 3) && abbreviation(tok2, "attributes", 3)) {
1054 ignore_attributes = true;
1055 }
1056 else if (abbreviation(tok1, "ignore", 3) && abbreviation(tok2, "sideset", 3)) {
1057 tok3 = extract_token(xline, " \t");
1058 to_lower(tok3);
1059 if (abbreviation(tok3, "distribution", 3)) {
1060 ignore_sideset_df = true;
1061 }
1062 }
1063 else if (tok1 == "step" && tok2 == "offset") {
1064 std::string tok = extract_token(xline, " \n\t=");
1065 if (abbreviation(tok, "automatic", 4)) {
1066 time_step_offset = -1;
1067 }
1068 else if (abbreviation(tok, "match", 4)) {
1069 time_step_offset = -2;
1070 }
1071 else {
1072 errno = 0;
1073 time_step_offset = std::stoi(tok);
1074 SMART_ASSERT(errno == 0);
1075 }
1076 }
1077 else if (abbreviation(tok1, "coordinates", 4)) {
1078 if (default_tol_specified != 0) {
1079 coord_tol = default_tol;
1080 }
1081 else {
1082 coord_tol.type = ToleranceMode::ABSOLUTE_; // These should correspond to
1083 coord_tol.value = 1.e-6; // the defaults at the top of
1084 coord_tol.floor = 0.0; // this file.
1085 }
1086
1087 if (!tok2.empty() && tok2[0] != '#') {
1088 // If rel or abs is specified, then the tolerance must
1089 // be specified.
1090 if (abbreviation(tok2, "relative", 3)) {
1091 coord_tol.type = ToleranceMode::RELATIVE_;
1092 tok2 = extract_token(xline, " \n\t=");
1093 if (tok2.empty()) {
1094 Parse_Die(line);
1095 }
1096 coord_tol.value = To_Double(tok2);
1097 }
1098 else if (abbreviation(tok2, "absolute", 3)) {
1099 coord_tol.type = ToleranceMode::ABSOLUTE_;
1100 tok2 = extract_token(xline, " \n\t=");
1101 if (tok2.empty()) {
1102 Parse_Die(line);
1103 }
1104 coord_tol.value = To_Double(tok2);
1105 }
1106 else if (abbreviation(tok2, "combine", 3)) {
1107 coord_tol.type = ToleranceMode::COMBINED_;
1108 tok2 = extract_token(xline, " \n\t=");
1109 if (tok2.empty()) {
1110 Parse_Die(line);
1111 }
1112 coord_tol.value = To_Double(tok2);
1113 }
1114 else if (abbreviation(tok2, "eigen_relative", 7)) {
1115 coord_tol.type = ToleranceMode::EIGEN_REL_;
1116 tok2 = extract_token(xline, " \n\t=");
1117 if (tok2.empty()) {
1118 Parse_Die(line);
1119 }
1120 coord_tol.value = To_Double(tok2);
1121 }
1122 else if (abbreviation(tok2, "eigen_absolute", 7)) {
1123 coord_tol.type = ToleranceMode::EIGEN_ABS_;
1124 tok2 = extract_token(xline, " \n\t=");
1125 if (tok2.empty()) {
1126 Parse_Die(line);
1127 }
1128 coord_tol.value = To_Double(tok2);
1129 }
1130 else if (abbreviation(tok2, "eigen_combine", 7)) {
1131 coord_tol.type = ToleranceMode::EIGEN_COM_;
1132 tok2 = extract_token(xline, " \n\t=");
1133 if (tok2.empty()) {
1134 Parse_Die(line);
1135 }
1136 coord_tol.value = To_Double(tok2);
1137 }
1138 else if (abbreviation(tok2, "ignore", 3)) {
1139 coord_tol.type = ToleranceMode::IGNORE_;
1140 coord_tol.value = 0.0;
1141 }
1142 else if (abbreviation(tok2, "floor", 3)) {
1143 tok2 = extract_token(xline, " \n\t=");
1144 if (tok2.empty()) {
1145 Parse_Die(line);
1146 }
1147 coord_tol.floor = To_Double(tok2);
1148 }
1149
1150 tok2 = extract_token(xline, " \n\t=,");
1151 to_lower(tok2);
1152 if (abbreviation(tok2, "floor", 3)) {
1153 tok2 = extract_token(xline, " \n\t=,");
1154 if (tok2.empty()) {
1155 Parse_Die(line);
1156 }
1157 coord_tol.floor = To_Double(tok2);
1158 }
1159 }
1160 }
1161 else if (tok1 == "time" && abbreviation(tok2, "steps", 4)) {
1162 time_tol = default_tol;
1163
1164 std::string tok = extract_token(xline, " \n\t=");
1165 to_lower(tok);
1166 if (!tok.empty() && tok[0] != '#') {
1167 // If rel or abs is specified, then the tolerance
1168 // must be specified.
1169 if (abbreviation(tok, "relative", 3)) {
1170 time_tol.type = ToleranceMode::RELATIVE_;
1171 tok = extract_token(xline, " \n\t=");
1172 if (tok.empty()) {
1173 Parse_Die(line);
1174 }
1175 time_tol.value = To_Double(tok);
1176 }
1177 else if (abbreviation(tok, "absolute", 3)) {
1178 time_tol.type = ToleranceMode::ABSOLUTE_;
1179 tok = extract_token(xline, " \n\t=");
1180 if (tok.empty()) {
1181 Parse_Die(line);
1182 }
1183 time_tol.value = To_Double(tok);
1184 }
1185 else if (abbreviation(tok, "combine", 3)) {
1186 time_tol.type = ToleranceMode::COMBINED_;
1187 tok = extract_token(xline, " \n\t=");
1188 if (tok.empty()) {
1189 Parse_Die(line);
1190 }
1191 time_tol.value = To_Double(tok);
1192 }
1193 else if (abbreviation(tok, "ignore", 3)) {
1194 time_tol.type = ToleranceMode::IGNORE_;
1195 time_tol.value = 0.0;
1196 }
1197 else if (abbreviation(tok, "floor", 3)) {
1198 tok = extract_token(xline, " \n\t=");
1199 if (tok.empty()) {
1200 Parse_Die(line);
1201 }
1202 time_tol.floor = To_Double(tok);
1203 }
1204
1205 tok2 = extract_token(xline, " \n\t=,");
1206 to_lower(tok2);
1207 if (abbreviation(tok2, "floor", 3)) {
1208 tok2 = extract_token(xline, " \n\t=,");
1209 if (tok2.empty()) {
1210 Parse_Die(line);
1211 }
1212 time_tol.floor = To_Double(tok2);
1213 }
1214 }
1215 }
1216 else if (abbreviation(tok1, "global", 4) && abbreviation(tok2, "variables", 3)) {
1217 glob_var_default = default_tol;
1218 xline = Parse_Variables(xline, cmd_file, glob_var_do_all_flag, glob_var_default,
1219 glob_var_names, glob_var);
1220
1221 Check_Parsed_Names(glob_var_names, glob_var_do_all_flag);
1222
1223 line = xline;
1224 continue;
1225 }
1226 else if (abbreviation(tok1, "nodal", 4) && abbreviation(tok2, "variables", 3)) {
1227 node_var_default = default_tol;
1228 xline = Parse_Variables(xline, cmd_file, node_var_do_all_flag, node_var_default,
1229 node_var_names, node_var);
1230
1231 Check_Parsed_Names(node_var_names, node_var_do_all_flag);
1232
1233 line = xline;
1234 continue;
1235 }
1236 else if (abbreviation(tok1, "element", 4) && abbreviation(tok2, "variables", 3)) {
1237 elmt_var_default = default_tol;
1238 xline = Parse_Variables(xline, cmd_file, elmt_var_do_all_flag, elmt_var_default,
1239 elmt_var_names, elmt_var);
1240
1241 Check_Parsed_Names(elmt_var_names, elmt_var_do_all_flag);
1242
1243 line = xline;
1244 continue;
1245 }
1246 else if (tok1 == "nodeset" && abbreviation(tok2, "variables", 3)) {
1247 ns_var_default = default_tol;
1248 xline = Parse_Variables(xline, cmd_file, ns_var_do_all_flag, ns_var_default, ns_var_names,
1249 ns_var);
1250
1251 Check_Parsed_Names(ns_var_names, ns_var_do_all_flag);
1252
1253 line = xline;
1254 continue;
1255 }
1256 else if (abbreviation(tok1, "sideset", 4) && abbreviation(tok2, "variables", 3)) {
1257 ss_var_default = default_tol;
1258 xline = Parse_Variables(xline, cmd_file, ss_var_do_all_flag, ss_var_default, ss_var_names,
1259 ss_var);
1260
1261 Check_Parsed_Names(ss_var_names, ss_var_do_all_flag);
1262
1263 line = xline;
1264 continue;
1265 }
1266 else if (abbreviation(tok1, "sideset", 4) && abbreviation(tok2, "distribution", 4)) {
1267 if (default_tol_specified != 0) {
1268 ss_df_tol = default_tol;
1269 }
1270 else {
1271 ss_df_tol.type = ToleranceMode::ABSOLUTE_; // These should correspond to
1272 ss_df_tol.value = 1.e-6; // the defaults at the top of
1273 ss_df_tol.floor = 0.0; // this file.
1274 }
1275
1276 if (!tok2.empty() && tok2[0] != '#') {
1277 // If rel or abs is specified, then the tolerance must
1278 // be specified.
1279 if (abbreviation(tok2, "relative", 3)) {
1280 ss_df_tol.type = ToleranceMode::RELATIVE_;
1281 tok2 = extract_token(xline, " \n\t=");
1282 if (tok2.empty()) {
1283 Parse_Die(line);
1284 }
1285 ss_df_tol.value = To_Double(tok2);
1286 }
1287 else if (abbreviation(tok2, "absolute", 3)) {
1288 ss_df_tol.type = ToleranceMode::ABSOLUTE_;
1289 tok2 = extract_token(xline, " \n\t=");
1290 if (tok2.empty()) {
1291 Parse_Die(line);
1292 }
1293 ss_df_tol.value = To_Double(tok2);
1294 }
1295 else if (abbreviation(tok2, "combine", 3)) {
1296 ss_df_tol.type = ToleranceMode::COMBINED_;
1297 tok2 = extract_token(xline, " \n\t=");
1298 if (tok2.empty()) {
1299 Parse_Die(line);
1300 }
1301 ss_df_tol.value = To_Double(tok2);
1302 }
1303 else if (abbreviation(tok2, "eigen_relative", 7)) {
1304 ss_df_tol.type = ToleranceMode::EIGEN_REL_;
1305 tok2 = extract_token(xline, " \n\t=");
1306 if (tok2.empty()) {
1307 Parse_Die(line);
1308 }
1309 ss_df_tol.value = To_Double(tok2);
1310 }
1311 else if (abbreviation(tok2, "eigen_absolute", 7)) {
1312 ss_df_tol.type = ToleranceMode::EIGEN_ABS_;
1313 tok2 = extract_token(xline, " \n\t=");
1314 if (tok2.empty()) {
1315 Parse_Die(line);
1316 }
1317 ss_df_tol.value = To_Double(tok2);
1318 }
1319 else if (abbreviation(tok2, "eigen_combine", 7)) {
1320 ss_df_tol.type = ToleranceMode::EIGEN_COM_;
1321 tok2 = extract_token(xline, " \n\t=");
1322 if (tok2.empty()) {
1323 Parse_Die(line);
1324 }
1325 ss_df_tol.value = To_Double(tok2);
1326 }
1327 else if (abbreviation(tok2, "ignore", 3)) {
1328 ss_df_tol.type = ToleranceMode::IGNORE_;
1329 ss_df_tol.value = 0.0;
1330 }
1331 else if (abbreviation(tok2, "floor", 3)) {
1332 tok2 = extract_token(xline, " \n\t=");
1333 if (tok2.empty()) {
1334 Parse_Die(line);
1335 }
1336 ss_df_tol.floor = To_Double(tok2);
1337 }
1338
1339 tok2 = extract_token(xline, " \n\t=,");
1340 to_lower(tok2);
1341 if (abbreviation(tok2, "floor", 3)) {
1342 tok2 = extract_token(xline, " \n\t=,");
1343 if (tok2.empty()) {
1344 Parse_Die(line);
1345 }
1346 ss_df_tol.floor = To_Double(tok2);
1347 }
1348 }
1349 }
1350 else if (abbreviation(tok1, "edgeblock", 4) && abbreviation(tok2, "variables", 3)) {
1351 eb_var_default = default_tol;
1352 xline = Parse_Variables(xline, cmd_file, eb_var_do_all_flag, eb_var_default, eb_var_names,
1353 eb_var);
1354
1355 Check_Parsed_Names(eb_var_names, eb_var_do_all_flag);
1356
1357 line = xline;
1358 continue;
1359 }
1360 else if (abbreviation(tok1, "faceblock", 4) && abbreviation(tok2, "variables", 3)) {
1361 fb_var_default = default_tol;
1362 xline = Parse_Variables(xline, cmd_file, fb_var_do_all_flag, fb_var_default, fb_var_names,
1363 fb_var);
1364
1365 Check_Parsed_Names(fb_var_names, fb_var_do_all_flag);
1366
1367 line = xline;
1368 continue;
1369 }
1370 else if (abbreviation(tok1, "element", 4) && abbreviation(tok2, "attributes", 3)) {
1371 elmt_att_default = default_tol;
1372 xline = Parse_Variables(xline, cmd_file, elmt_att_do_all_flag, elmt_att_default,
1373 elmt_att_names, elmt_att);
1374
1375 Check_Parsed_Names(elmt_att_names, elmt_att_do_all_flag);
1376
1377 line = xline;
1378 continue;
1379 }
1380 else {
1381 Parse_Die(line);
1382 }
1383 }
1384
1385 std::getline(cmd_file, line);
1386 xline = line;
1387 }
1388 }
1389
1390 namespace {
1391 std::string Parse_Variables(std::string xline, std::ifstream &cmd_file, bool &all_flag,
1392 Tolerance &def_tol, NameList &names, std::vector<Tolerance> &toler)
1393 {
1394 toler.clear();
1395 names.clear();
1396
1397 std::string tok = extract_token(xline, " \n\t=,");
1398 to_lower(tok);
1399 if (!tok.empty()) {
1400 if (tok != "(all)" && tok != "all" && !abbreviation(tok, "relative", 3) &&
1401 !abbreviation(tok, "absolute", 3) && !abbreviation(tok, "combine", 3) &&
1402 !abbreviation(tok, "ulps_float", 6) && !abbreviation(tok, "ulps_double", 6) &&
1403 !abbreviation(tok, "eigen_relative", 7) && !abbreviation(tok, "eigen_absolute", 7) &&
1404 !abbreviation(tok, "eigen_combine", 7) && !abbreviation(tok, "ignore", 3) &&
1405 !abbreviation(tok, "floor", 3)) {
1406 Error(fmt::format("in parsing command file: unrecognized keyword \"{}\"\n", tok));
1407 }
1408
1409 if (tok == "(all)" || tok == "all") {
1410 all_flag = true;
1411 tok = extract_token(xline, " \n\t=,");
1412 }
1413
1414 // If rel or abs is specified, then the tolerance must be specified.
1415 if (abbreviation(tok, "relative", 3)) {
1416 def_tol.type = ToleranceMode::RELATIVE_;
1417 tok = extract_token(xline, " \n\t=,");
1418 if (tok == "floor" || tok.empty()) {
1419 Error(" Input file specifies a tolerance type "
1420 "but no tolerance\n");
1421 }
1422 def_tol.value = To_Double(tok);
1423 tok = extract_token(xline, " \n\t=,");
1424 to_lower(tok);
1425 }
1426 else if (abbreviation(tok, "absolute", 3)) {
1427 def_tol.type = ToleranceMode::ABSOLUTE_;
1428 tok = extract_token(xline, " \n\t=,");
1429 if (tok == "floor" || tok.empty()) {
1430 Error("Input file specifies a tolerance type "
1431 "but no tolerance\n");
1432 }
1433 def_tol.value = To_Double(tok);
1434 tok = extract_token(xline, " \n\t=,");
1435 to_lower(tok);
1436 }
1437 else if (abbreviation(tok, "combine", 3)) {
1438 def_tol.type = ToleranceMode::COMBINED_;
1439 tok = extract_token(xline, " \n\t=,");
1440 if (tok == "floor" || tok.empty()) {
1441 Error("Input file specifies a tolerance type "
1442 "but no tolerance\n");
1443 }
1444 def_tol.value = To_Double(tok);
1445 tok = extract_token(xline, " \n\t=,");
1446 to_lower(tok);
1447 }
1448 else if (abbreviation(tok, "ulps_float", 6)) {
1449 def_tol.type = ToleranceMode::ULPS_FLOAT_;
1450 tok = extract_token(xline, " \n\t=,");
1451 if (tok == "floor" || tok.empty()) {
1452 Error("Input file specifies a tolerance type "
1453 "but no tolerance\n");
1454 }
1455 def_tol.value = To_Double(tok);
1456 tok = extract_token(xline, " \n\t=,");
1457 to_lower(tok);
1458 }
1459 else if (abbreviation(tok, "ulps_double", 6)) {
1460 def_tol.type = ToleranceMode::ULPS_DOUBLE_;
1461 tok = extract_token(xline, " \n\t=,");
1462 if (tok == "floor" || tok.empty()) {
1463 Error("Input file specifies a tolerance type "
1464 "but no tolerance\n");
1465 }
1466 def_tol.value = To_Double(tok);
1467 tok = extract_token(xline, " \n\t=,");
1468 to_lower(tok);
1469 }
1470 else if (abbreviation(tok, "eigen_relative", 7)) {
1471 def_tol.type = ToleranceMode::EIGEN_REL_;
1472 tok = extract_token(xline, " \n\t=,");
1473 if (tok == "floor" || tok.empty()) {
1474 Error("Input file specifies a tolerance type "
1475 "but no tolerance\n");
1476 }
1477 def_tol.value = To_Double(tok);
1478 tok = extract_token(xline, " \n\t=,");
1479 to_lower(tok);
1480 }
1481 else if (abbreviation(tok, "eigen_absolute", 7)) {
1482 def_tol.type = ToleranceMode::EIGEN_ABS_;
1483 tok = extract_token(xline, " \n\t=,");
1484 if (tok == "floor" || tok.empty()) {
1485 Error("Input file specifies a tolerance type "
1486 "but no tolerance\n");
1487 }
1488 def_tol.value = To_Double(tok);
1489 tok = extract_token(xline, " \n\t=,");
1490 to_lower(tok);
1491 }
1492 else if (abbreviation(tok, "eigen_combine", 7)) {
1493 def_tol.type = ToleranceMode::EIGEN_COM_;
1494 tok = extract_token(xline, " \n\t=,");
1495 if (tok == "floor" || tok.empty()) {
1496 Error("Input file specifies a tolerance type "
1497 "but no tolerance\n");
1498 }
1499 def_tol.value = To_Double(tok);
1500 tok = extract_token(xline, " \n\t=,");
1501 to_lower(tok);
1502 }
1503 else if (abbreviation(tok, "ignore", 3)) {
1504 def_tol.type = ToleranceMode::IGNORE_;
1505 def_tol.value = 0.0;
1506 tok = extract_token(xline, " \n\t=,");
1507 to_lower(tok);
1508 }
1509
1510 if (abbreviation(tok, "floor", 3)) {
1511 tok = extract_token(xline, " \n\t=,");
1512 if (tok.empty() || tok[0] == '#') {
1513 Error("Floor specified but couldn't find value\n");
1514 }
1515 def_tol.floor = To_Double(tok);
1516 }
1517 }
1518
1519 std::string line{};
1520 std::getline(cmd_file, line);
1521 xline = line;
1522 while (!cmd_file.eof()) {
1523 if (xline.empty() ||
1524 ((xline[0] != '\t' && xline[0] != ' ') && first_character(xline) != '#')) {
1525 break;
1526 }
1527
1528 if (first_character(xline) != '#') {
1529 tok = extract_token(xline);
1530 chop_whitespace(tok);
1531 if (tok.empty()) {
1532 continue; // Found tab but no name given.
1533 }
1534
1535 if (tok[0] == '!') {
1536 // A "!" in front of a name means to exclude the name so no
1537 // need to look for difference type and tolerance.
1538 std::string tmp = tok;
1539 if (!extract_token(tmp, "!").empty()) {
1540 names.push_back(tok);
1541 toler.push_back(def_tol);
1542 }
1543 std::getline(cmd_file, line);
1544 xline = line;
1545 continue;
1546 }
1547
1548 int idx = names.size();
1549 names.push_back(tok);
1550 toler.push_back(def_tol);
1551
1552 tok = extract_token(xline);
1553 to_lower(tok);
1554
1555 if (!tok.empty() && tok[0] != '#') {
1556 if (abbreviation(tok, "relative", 3)) {
1557 toler[idx].type = ToleranceMode::RELATIVE_;
1558 tok = extract_token(xline, " \n\t=,");
1559 }
1560 else if (abbreviation(tok, "absolute", 3)) {
1561 toler[idx].type = ToleranceMode::ABSOLUTE_;
1562 tok = extract_token(xline, " \n\t=,");
1563 }
1564 else if (abbreviation(tok, "combine", 3)) {
1565 toler[idx].type = ToleranceMode::COMBINED_;
1566 tok = extract_token(xline, " \n\t=,");
1567 }
1568 else if (abbreviation(tok, "eigen_relative", 7)) {
1569 toler[idx].type = ToleranceMode::EIGEN_REL_;
1570 tok = extract_token(xline, " \n\t=,");
1571 }
1572 else if (abbreviation(tok, "eigen_absolute", 7)) {
1573 toler[idx].type = ToleranceMode::EIGEN_ABS_;
1574 tok = extract_token(xline, " \n\t=,");
1575 }
1576
1577 else if (abbreviation(tok, "eigen_com", 7)) {
1578 toler[idx].type = ToleranceMode::EIGEN_COM_;
1579 tok = extract_token(xline, " \n\t=,");
1580 }
1581
1582 if (abbreviation(tok, "floor", 3)) {
1583 toler[idx].value = def_tol.value;
1584
1585 tok = extract_token(xline, " \n\t=,");
1586 if (tok.empty()) {
1587 Parse_Die(line);
1588 }
1589 toler[idx].floor = To_Double(tok);
1590 }
1591 else {
1592 if (tok.empty()) {
1593 Parse_Die(line);
1594 }
1595 toler[idx].value = To_Double(tok);
1596
1597 tok = extract_token(xline, " \n\t=,");
1598 to_lower(tok);
1599 if (abbreviation(tok, "floor", 3)) {
1600 tok = extract_token(xline, " \n\t=,");
1601 if (tok.empty()) {
1602 Parse_Die(line);
1603 }
1604 toler[idx].floor = To_Double(tok);
1605 }
1606 else {
1607 toler[idx].floor = def_tol.floor;
1608 }
1609 }
1610 }
1611 else {
1612 toler[idx] = def_tol;
1613 }
1614 }
1615
1616 std::getline(cmd_file, line);
1617 xline = line;
1618 }
1619
1620 if (names.empty()) {
1621 all_flag = true;
1622 }
1623
1624 return xline;
1625 }
1626
1627 void tolerance_help()
1628 {
1629 fmt::print(
1630 "\n Tolerance Help:\n"
1631 "\n"
1632 "\t Relative difference |val1 - val2| / max(|val1|, |val2|)\n"
1633 "\t Absolute difference |val1 - val2|\n"
1634 "\t Combined difference |val1 - val2| / max(tol, tol * max(|val1|, |val2|))\n"
1635 "\t Eigen_relative difference ||val1| - |val2|| / max(|val1|,|val2|)\n"
1636 "\t Eigen_absolute difference ||val1| - |val2||\n"
1637 "\t Eigen_combined difference ||val1| - |val2|| / max(tol, tol * max(|val1|, |val2|))\n"
1638 "\t Ulps_float difference -- Calculate number of representable floats between the two "
1639 "values\n"
1640 "\t Ulps_double difference -- Calculate number of representable doubles between the "
1641 "two values\n"
1642 "\n"
1643 "\t Values are considered equal if |val1| <= floor and |val2| <= floor;\n"
1644 "\t where floor is a user-specified value (-Floor option). Otherwise the difference is\n"
1645 "\t computed using one of the above formulas and compared to a tolerance.\n"
1646 "\t If the difference is greater than the tolerance, then the databases\n"
1647 "\t are different. At the end of execution, a summary of the differences\n"
1648 "\t found is output.\n"
1649 "\t \n"
1650 "\t By default:\n"
1651 "\t * All results variables and attributes are compared using a relative difference\n"
1652 "\t of 10^{{-6}} (about 6 significant digits) and a floor of 0.0.\n"
1653 "\t * Nodal locations are compared using {{absolute difference}} with\n"
1654 "\t a tolerance of 10^{{-6}} and a floor of 0.0.\n"
1655 "\t * Time step values are compared using relative difference tolerance of 10^{{-6}}\n"
1656 "\t and a floor of 10^{{-15}}.\n"
1657 "\n\n");
1658 }
1659
1660 void file_help()
1661 {
1662 fmt::print(
1663 "\n Command file syntax:\n"
1664 "\n"
1665 " # Anything following a # is a comment.\n"
1666 " DEFAULT TOLERANCE relative 1.E-8 floor 1.E-14\n"
1667 " COORDINATES absolute 1.E-12\n"
1668 " TIME STEPS absolute 1.E-14\n"
1669 " GLOBAL VARIABLES relative 1.E-4 floor 1.E-12\n"
1670 " NODAL VARIABLES absolute 1.E-8\n"
1671 " <tab> DISPLX\n"
1672 " <tab> VELX absolute 1.E-6\n"
1673 " <tab> VELY relative 1.E-6 floor 1.e-10\n"
1674 " ELEMENT VARIABLES\n"
1675 " <tab> !SIGYY\n"
1676 " <tab> !SIGZZ\n"
1677 "\n"
1678 " - The variable names are case insensitive (unless or CASE SENSITIVE "
1679 "specified),\n"
1680 " All other comparisons are also case insensitive. Abbreviations can be used. "
1681 "\n"
1682 " - All comparisons use the default of relative 1.e-6 for\n"
1683 " variables and absolute 1.e-6 for coordinates. This is overridden\n"
1684 " with the DEFAULT TOLERANCE line. The DEFAULT TOLERANCE values\n"
1685 " are overridden by the values given on the VARIABLES line and apply\n"
1686 " only to those variables. Each variable can override all values\n"
1687 " by following its name with a value.\n"
1688 " - A variable name must start with a tab character. Only those\n"
1689 " variables listed will be considered (unless \"(all)\") specified.\n"
1690 " The NOT symbol \"!\" means do not include this variable.\n"
1691 " Mixing non-! and ! is not allowed without the \"(all)\" specifier, e.g.:\n\n"
1692 " NODAL VARIABLES (all) absolute 1.E-8\n"
1693 " <tab> DISPLX\n"
1694 " <tab> !VELX\n"
1695 " <tab> VELY relative 1.E-6 floor 1.e-10\n\n"
1696 " In this case, all variables are considered that are not prepended\n"
1697 " with a \"!\" symbol.\n"
1698 " - If a variable type (e.g. NODAL VARIABLES) is not specified, no\n"
1699 " variables of that type will be considered.\n"
1700 "\n"
1701 " Other Keywords:\n"
1702 " - EXCLUDE TIMES <list>: \"-exclude\" Specify the time step exclusion option.\n"
1703 " <list> has the same format as in the command line option.\n"
1704 " - APPLY MATCHING: \"-map\" matching algorithm.\n"
1705 " - NODESET MATCH: \"-nsmap\", nodeset mapping algorithm.\n"
1706 " - SIDESET MATCH: \"-ssmap\", sideset mapping algorithm.\n"
1707 " - SHORT BLOCKS: \"-short\", short block type compare.\n"
1708 " - NO SHORT BLOCKS: \"-no_short\", do not do short block type compare.\n"
1709 " - CASE_SENSITIVE: \"-case_sensitive\", variable names are compared case "
1710 "sensitive.\n"
1711 " - IGNORE CASE: \"-ignore_case\", variable names compared case insensitive "
1712 "[default].\n"
1713 " - IGNORE MAPS: \"-ignore_maps\", use local implicit instead of global ids.\n"
1714 " - IGNORE NANS: \"-ignore_nans\", do not check data for NaNs\n"
1715 " - IGNORE DUPLICATES: \"-ignore_dups\", ignore two elements/nodes in same "
1716 "position...\n"
1717 " - STEP OFFSET <val>: \"-TimeStepOffset\", timestep 'val+offset' in file1 matches "
1718 "'val' in file2.\n"
1719 " - STEP OFFSET AUTOMATIC: \"-TA\", automatic determination of timestep offset, "
1720 "end at same step.\n"
1721 " - STEP OFFSET MATCH: \"-TM\", automatic determination of timestep offset, start "
1722 "at same step.\n"
1723 " - INTERPOLATE: \"-interpolate\", interpolate times on file2 to match times on "
1724 "file1.\n"
1725 " - FINAL TIME TOLERANCE <tol>: \"-final_time_tolerance <tol>\", used with "
1726 "interpolation.\n"
1727 " - CALCULATE NORMS: \"-norms\", calculate L1 and L2 norms of variable differences "
1728 "and output if > 0.0.\n"
1729 " - RETURN STATUS: \"-stat\", return exit status of 2 if the files are different. "
1730 "(default).\n"
1731 " - IGNORE STATUS: \"-ignore_status\", exit status is always zero unless an error "
1732 "occurs.\n"
1733 " - PEDANTIC: \"-pedantic\", be more picky about what is a difference.\n\n");
1734 }
1735 } // namespace