Skip to content

Commit

Permalink
CONJOIN: first handling of change set files
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed Jan 16, 2025
1 parent aae51dc commit 6e28a82
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 25 deletions.
95 changes: 80 additions & 15 deletions packages/seacas/applications/conjoin/CJ_ExodusFile.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2021, 2023, 2024 National Technology & Engineering Solutions
// Copyright(C) 1999-2021, 2023, 2024, 2025 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -26,6 +26,7 @@ int Excn::ExodusFile::ioWordSize_ = 0;
int Excn::ExodusFile::cpuWordSize_ = 0;
std::string Excn::ExodusFile::outputFilename_;
bool Excn::ExodusFile::keepOpen_ = false;
bool Excn::ExodusFile::usingChangeSets_ = false;
int Excn::ExodusFile::maximumNameLength_ = 32;
int Excn::ExodusFile::exodusMode_ = 0;

Expand Down Expand Up @@ -78,11 +79,16 @@ Excn::ExodusFile::~ExodusFile()

void Excn::ExodusFile::close_all()
{
for (auto &elem : fileids_) {
if (elem > 0) {
ex_close(elem);
if (usingChangeSets_) {
ex_close(fileids_[0]);
}
else {
for (auto &elem : fileids_) {
if (elem > 0) {
ex_close(elem);
}
elem = -1;
}
elem = -1;
}
ex_close(outputId_);
outputId_ = -1;
Expand All @@ -104,16 +110,73 @@ bool Excn::ExodusFile::initialize(const SystemInterface &si)
}

float version = 0.0;
int overall_max_name_length = 32;

// create exo names
filenames_.resize(si.inputFiles_.size());
fileids_.resize(si.inputFiles_.size(), -1);
if (si.inputFiles_.size() == 1) {
// The file should contain multiple change sets which will be concatenated...
int cpu_word_size = sizeof(double);
int io_wrd_size = sizeof(double);
std::string name = si.inputFiles_[0];
int exoid = ex_open(name.c_str(), EX_READ, &cpu_word_size, &io_wrd_size, &version);
if (exoid < 0) {
fmt::print(stderr, "ERROR: Cannot open file '{}'\n", name);
return false;
}

int overall_max_name_length = 32;
for (size_t p = 0; p < si.inputFiles_.size(); p++) {
std::string name = si.inputFiles_[p];
int num_change_sets = ex_inquire_int(exoid, EX_INQ_NUM_CHILD_GROUPS);
if (num_change_sets <= 1) {
fmt::print(stderr, "WARNING: File '{}' does not contain change sets and only a single file was specified.\n\tNothing to be done. Exiting\n", name);
return false;
}
usingChangeSets_ = true;

if (io_wrd_size < static_cast<int>(sizeof(float))) {
io_wrd_size = sizeof(float);
}

ioWordSize_ = io_wrd_size;
cpuWordSize_ = io_wrd_size;

if (((ex_int64_status(exoid) & EX_ALL_INT64_DB) != 0) || si.ints_64_bit()) {
exodusMode_ = EX_ALL_INT64_API;
}

int name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
if (name_length > overall_max_name_length) {
overall_max_name_length = name_length;
}

// create exo names
filenames_.resize(num_change_sets);
fileids_.resize(num_change_sets, exoid);

// Get names of change sets...
int group_name_length = ex_inquire_int(exoid, EX_INQ_GROUP_NAME_LEN);
std::vector<char> group_name(group_name_length + 1, '\0');

for (int i = 1; i <= num_change_sets; i++) {
int idum = 0;
float rdum = 0.0;
// Get name of this group...
int ierr = ex_inquire(exoid + i, EX_INQ_GROUP_NAME, &idum, &rdum, group_name.data());
if (ierr != EX_NOERR) {
fmt::print(stderr, "ERROR: Could not get name for group {} in input file '{}'\n", i+1, name);
return false;
}
filenames_[i-1] = std::string(group_name.data());
fileids_[i-1] = exoid + i;
fmt::print("Part {}: '{}'\n", i, filenames_[i-1]);
}
}
else {
// create exo names
filenames_.resize(si.inputFiles_.size());
fileids_.resize(si.inputFiles_.size(), -1);

for (size_t p = 0; p < si.inputFiles_.size(); p++) {
std::string name = si.inputFiles_[p];

filenames_[p] = name;
filenames_[p] = name;

if (p == 0) {
int cpu_word_size = sizeof(float);
Expand All @@ -129,6 +192,10 @@ bool Excn::ExodusFile::initialize(const SystemInterface &si)
overall_max_name_length = name_length;
}

if (((ex_int64_status(exoid) & EX_ALL_INT64_DB) != 0) || si.ints_64_bit()) {
exodusMode_ = EX_ALL_INT64_API;
}

ex_close(exoid);

if (io_wrd_size < static_cast<int>(sizeof(float))) {
Expand All @@ -138,9 +205,6 @@ bool Excn::ExodusFile::initialize(const SystemInterface &si)
ioWordSize_ = io_wrd_size;
cpuWordSize_ = io_wrd_size;

if ((ex_int64_status(exoid & EX_ALL_INT64_DB) != 0) || si.ints_64_bit()) {
exodusMode_ = EX_ALL_INT64_API;
}
}

if (keepOpen_ || p == 0) {
Expand All @@ -158,6 +222,7 @@ bool Excn::ExodusFile::initialize(const SystemInterface &si)

fmt::print("Part {}: '{}'\n", p + 1, name);
}
}

maximumNameLength_ = overall_max_name_length;
if (keepOpen_) {
Expand Down
11 changes: 7 additions & 4 deletions packages/seacas/applications/conjoin/CJ_ExodusFile.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2020, 2022, 2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2020, 2022, 2023, 2024, 2025 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand All @@ -21,6 +21,7 @@ namespace Excn {
ExodusFile(const ExodusFile &) = delete;
ExodusFile operator=(const ExodusFile &) = delete;

static size_t part_count() {return filenames_.size();}
static bool initialize(const SystemInterface &si);
static bool create_output(const SystemInterface &si);
static void close_all();
Expand All @@ -32,14 +33,16 @@ namespace Excn {

private:
size_t myLocation_;
static std::vector<std::string> filenames_;
static std::vector<std::string> filenames_; // If using changesets, these are the changeset names.
static std::vector<int> fileids_;
static std::string baseFilename_; // If using changesets, this is the filename
static std::string outputFilename_;
static int outputId_;
static int ioWordSize_;
static int cpuWordSize_;
static std::string outputFilename_;
static bool keepOpen_;
static int maximumNameLength_;
static int exodusMode_;
static bool keepOpen_;
static bool usingChangeSets_;
};
} // namespace Excn
6 changes: 3 additions & 3 deletions packages/seacas/applications/conjoin/CJ_Version.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2023, 2025 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand All @@ -9,6 +9,6 @@

static const std::array<std::string, 3> qainfo{
"conjoin",
"1.5.00",
"2023/12/19",
"1.6.00",
"2025/01/16",
};
6 changes: 3 additions & 3 deletions packages/seacas/applications/conjoin/Conjoin.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
// Copyright(C) 1999-2025 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -418,7 +418,7 @@ int conjoin(Excn::SystemInterface &interFace, T /* dummy */, INT /* dummy int */
SMART_ASSERT(sizeof(T) == Excn::ExodusFile::io_word_size());

const T alive = interFace.alive_value();
size_t part_count = interFace.inputFiles_.size();
size_t part_count = Excn::ExodusFile::part_count();

std::array<char, MAX_LINE_LENGTH + 1> mytitle{};

Expand Down Expand Up @@ -1733,7 +1733,7 @@ namespace {
fmt::print(
stderr,
"WARNING: Duplicate node ids were found. Their ids have been renumbered to remove "
"duplicates. If the part meshes should be identical, maybe use the "
"duplicates.\n\tIf the part meshes should be identical, maybe use the "
"--ignore_coordinate option.\n");
}
}
Expand Down

0 comments on commit 6e28a82

Please sign in to comment.