Skip to content

Commit f82a321

Browse files
committed
IOSS: Add select_steps option to io_shell
1 parent 1230794 commit f82a321

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed

packages/seacas/libraries/ioss/src/Ioss_CopyDatabase.C

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,21 @@ namespace {
371371
}
372372
}
373373
}
374+
else if (!options.selected_steps.empty()) {
375+
for (const auto &step : options.selected_steps) {
376+
if (step == 0 || abs(step) > step_count) {
377+
fmt::print(std::cerr, "WARNING: Step {} is out of range. Must be non-zero and maximum of {}.\n",
378+
step, step_count);
379+
continue;
380+
}
381+
if (step > 0) {
382+
selected_steps[step] = 1;
383+
}
384+
else {
385+
selected_steps[step_count + 1 + step] = 1;
386+
}
387+
}
388+
}
374389
else {
375390
// User did not select specific times to be output...
376391
// Just select them all

packages/seacas/libraries/ioss/src/Ioss_MeshCopyOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
/*
3-
* Copyright(C) 1999-2024 National Technology & Engineering Solutions
3+
* Copyright(C) 1999-2025 National Technology & Engineering Solutions
44
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
55
* NTESS, the U.S. Government retains certain rights in this software.
66
*
@@ -14,6 +14,7 @@ namespace Ioss {
1414
struct IOSS_EXPORT MeshCopyOptions
1515
{
1616
std::vector<double> selected_times{};
17+
std::vector<int> selected_steps{};
1718
std::vector<std::string> omitted_sets{};
1819
std::string selected_change_sets{};
1920
double minimum_time{0.0};

packages/seacas/libraries/ioss/src/Ioss_Region.C

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ namespace Ioss {
630630
" Element side sets = {16:{24}}\t Element sides = {22:{23}}\t Sideset = {31:{25}}\n"
631631
" Assemblies = {40:{24}}\t {38:{23}s}\t Assembly = {41:{25}}\t{54:{25}}\n"
632632
" Blobs = {42:{24}}\t {38:{23}s}\t Blob = {43:{25}}\t{55:{25}}\n\n"
633-
" Time steps = {32:{24}}\n",
633+
" Time steps = {32:{24}}",
634634
get_database()->get_filename(), mesh_type_string(), /* 0, 1 */
635635
fmt::group_digits(get_property("spatial_dimension").get_int()),
636636
fmt::group_digits(get_property("node_count").get_int()),
@@ -687,6 +687,13 @@ namespace Ioss {
687687
fmt::group_digits(num_asm_red_vars),
688688
fmt::group_digits(num_blob_red_vars),
689689
change_set_name, change_set_count);
690+
691+
if (num_ts > 0) {
692+
fmt::print("\t({} to {})\n", stateTimes[0], stateTimes[num_ts-1]);
693+
}
694+
else {
695+
fmt::print("\n");
696+
}
690697
// clang-format on
691698
}
692699

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ namespace {
5959
{
6060
Ioss::MeshCopyOptions options{};
6161
options.selected_times = interFace.selected_times;
62+
options.selected_steps = interFace.selected_steps;
6263
options.rel_tolerance = interFace.rel_tolerance;
6364
options.abs_tolerance = interFace.abs_tolerance;
6465
options.tol_floor = interFace.tol_floor;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ void IOShell::Interface::enroll_options()
285285
"comma-separated list of times that should be transferred to output database",
286286
nullptr);
287287

288+
options_.enroll("select_steps", Ioss::GetLongOption::OptType::MandatoryValue,
289+
"comma-separated list of steps that should be transferred to output database\n"
290+
"\t\tEnter a negative value to count from end. -1 is last, -2 is second last.",
291+
nullptr);
292+
288293
options_.enroll("append_after_time", Ioss::GetLongOption::OptType::MandatoryValue,
289294
"add steps on input database after specified time on output database", nullptr);
290295

@@ -793,6 +798,24 @@ bool IOShell::Interface::parse_options(int argc, char **argv, int my_processor)
793798
}
794799
}
795800

801+
{
802+
const char *temp = options_.retrieve("select_steps");
803+
if (temp != nullptr) {
804+
if (!selected_times.empty()) {
805+
if (my_processor == 0) {
806+
fmt::print(stderr, "ERROR: Can not use both select_times and select_steps.\n");
807+
}
808+
return false;
809+
}
810+
811+
auto step_str = Ioss::tokenize(std::string(temp), ",");
812+
for (const auto &str : step_str) {
813+
auto step = std::stoi(str);
814+
selected_steps.push_back(step);
815+
}
816+
}
817+
}
818+
796819
append_time = options_.get_option_value("append_after_time", append_time);
797820
flush_interval = options_.get_option_value("flush_interval", flush_interval);
798821
timestep_delay = options_.get_option_value("delay", timestep_delay);

packages/seacas/libraries/ioss/src/main/shell_interface.h

Lines changed: 5 additions & 1 deletion
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
*
@@ -61,6 +61,10 @@ namespace IOShell {
6161
//! If non-empty, then it is a list of times that should be transferred to the output file.
6262
std::vector<double> selected_times{};
6363

64+
//! If non-empty, then it is a list of steps that should be transferred to the output file.
65+
// A negative value counts from end. -1 is last, -2 is second last...
66+
std::vector<int> selected_steps{};
67+
6468
//! If non-empty, then it is a list of element blocks, nodesets,
6569
//! sidesets that should be omitted from the output file
6670
std::vector<std::string> omitted_blocks{};

0 commit comments

Comments
 (0)