Skip to content

Commit

Permalink
EPU: Working with change sets now (alpha)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed Dec 10, 2024
1 parent aaf2530 commit 196abca
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 102 deletions.
90 changes: 65 additions & 25 deletions packages/seacas/applications/epu/EP_ExodusFile.C
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,34 @@ int Excn::ExodusFile::activeChangeSet_= 0;
std::string Excn::ExodusFile::outputFilename_;
bool Excn::ExodusFile::keepOpen_ = false;
bool Excn::ExodusFile::verifyValidFile_ = false;
bool Excn::ExodusFile::onlySelectedChangeSet_ = false;
int Excn::ExodusFile::maximumNameLength_ = 32;

namespace {
void create_output_change_sets()
{
int save = Excn::ExodusFile::set_active_change_set(0);
int output_id = Excn::ExodusFile::output();

Excn::ExodusFile::set_active_change_set(1);
int exoid = Excn::ExodusFile(0);
int group_name_length = ex_inquire_int(exoid, EX_INQ_GROUP_NAME_LEN);
std::vector<char> group_name(group_name_length + 1, '\0');

fmt::print("Output file id = {}\n", output_id);
for (int i = 0; i < Excn::ExodusFile::get_change_set_count(); i++) {
int idum;
float rdum;
// Get name of this group...
int ierr = ex_inquire(exoid + i, EX_INQ_GROUP_NAME, &idum, &rdum, group_name.data());

int cs_id = ex_create_group(output_id, group_name.data());
fmt::print("Change set {} is {} with exoid {}\n", i+1, group_name.data(), cs_id);
}
Excn::ExodusFile::set_active_change_set(save);
}
}

Excn::ExodusFile::ExodusFile(int processor) : myProcessor_(processor)
{
SMART_ASSERT(processor < processorCount_)(processor)(processorCount_);
Expand Down Expand Up @@ -77,15 +103,6 @@ Excn::ExodusFile::ExodusFile(int processor) : myProcessor_(processor)
}
}

// If file contains change sets, open the first child change set (assumes all
// valid data are in change sets...)
if (num_change_sets > 0) {
std::vector<int> change_set_ids;
change_set_ids.resize(num_change_sets);
ex_get_group_ids(fileids_[processor], nullptr, change_set_ids.data());
fileids_[processor] = change_set_ids[activeChangeSet_];
}

SMART_ASSERT(io_word_size_var == ioWordSize_);
SMART_ASSERT(cpu_word_size == cpuWordSize_);
}
Expand All @@ -94,13 +111,13 @@ Excn::ExodusFile::ExodusFile(int processor) : myProcessor_(processor)
int Excn::ExodusFile::output()
{
SMART_ASSERT(outputId_ >= 0);
return outputId_;
return outputId_ + (onlySelectedChangeSet_ ? 0 : activeChangeSet_);
}

Excn::ExodusFile::operator int() const
{
SMART_ASSERT(fileids_[myProcessor_] >= 0);
return fileids_[myProcessor_];
return fileids_[myProcessor_] + activeChangeSet_;
}

Excn::ExodusFile::~ExodusFile()
Expand Down Expand Up @@ -189,7 +206,10 @@ void Excn::ExodusFile::initialize(const SystemInterface &si, int start_part, int
startPart_ = start_part; // Which one to start with
SMART_ASSERT(partCount_ + startPart_ <= processorCount_)(partCount_)(startPart_)(processorCount_);

activeChangeSet_ = si.selected_change_set() - 1;
activeChangeSet_ = si.selected_change_set();
if (si.selected_change_set() > 0) {
onlySelectedChangeSet_ = true;;
}

// EPU always wants entity (block, set, map) ids as 64-bit quantities...
mode64bit_ = EX_IDS_INT64_API;
Expand Down Expand Up @@ -315,15 +335,6 @@ void Excn::ExodusFile::initialize(const SystemInterface &si, int start_part, int
}
ex_set_max_name_length(fileids_[p], maximumNameLength_);
SMART_ASSERT(ioWordSize_ == io_word_size_var)(ioWordSize_)(io_word_size_var);

// If file contains change sets, open the first child change set (assumes all
// valid data are in change sets...)
if (changeSetCount_ > 0) {
std::vector<int> change_set_ids;
change_set_ids.resize(changeSetCount_);
ex_get_group_ids(fileids_[p], nullptr, change_set_ids.data());
fileids_[p] = change_set_ids[activeChangeSet_];
}
}

if (((si.debug() & 64) != 0) || p == 0 || p == partCount_ - 1) {
Expand All @@ -342,6 +353,24 @@ void Excn::ExodusFile::initialize(const SystemInterface &si, int start_part, int
}
}

// `cs` is the 0-based change-set to select
int Excn::ExodusFile::set_active_change_set(int cs)
{
int save = activeChangeSet_;

if (changeSetCount_ < 0) {
throw std::runtime_error("ERROR: (EPU) Cannot set active change set before changes sets have been queried.\n");
}
if (cs <= changeSetCount_) {
activeChangeSet_ = cs;
}
else {
throw std::runtime_error(fmt::format("ERROR: (EPU) Active change set index {} exceeds change set count {}.\n",
cs, changeSetCount_));
}
return save;
}

void Excn::ExodusFile::create_output(const SystemInterface &si, int cycle)
// Create output file...
{
Expand All @@ -368,7 +397,11 @@ void Excn::ExodusFile::create_output(const SystemInterface &si, int cycle)
// Did user specify it via -netcdf4 or -large_model argument...
int mode = 0;

if (si.compress_data() > 0 || si.szip()) {
if (changeSetCount_ > 1 && !onlySelectedChangeSet_) {
mode |= EX_NETCDF4;
mode |= EX_NOCLASSIC;
}
else if (si.compress_data() > 0 || si.szip()) {
// Force netcdf-4 if compression is specified...
mode |= EX_NETCDF4;
}
Expand Down Expand Up @@ -426,17 +459,24 @@ void Excn::ExodusFile::create_output(const SystemInterface &si, int cycle)
}
}

// Check whether input file(s) have changesets. If they do and the `selected_change_set` is
// not `0`, then we are combining all change sets on the input to the output. Create them
// now...
if (changeSetCount_ > 1 && !onlySelectedChangeSet_) {
// Get the names of the change sets on the input file and create them on output file...
create_output_change_sets();
}

// EPU Can add a name of "processor_id_epu" which is 16 characters long.
// Make sure maximumNameLength_ is at least that long...

if (maximumNameLength_ < 16) {
maximumNameLength_ = 16;
}
ex_set_option(outputId_, EX_OPT_MAX_NAME_LENGTH, maximumNameLength_);

int int_size = si.int64() ? 8 : 4;
if (cycle == 0) {
fmt::print("IO Word sizes: {} bytes floating point and {} bytes integer.\n", ioWordSize_,
int_size);
fmt::print("IO Word sizes: {} bytes floating point and {} bytes integer.\n",
ioWordSize_, int_size);
}
}
6 changes: 6 additions & 0 deletions packages/seacas/applications/epu/EP_ExodusFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ namespace Excn {
static void create_output(const SystemInterface &si, int cycle);
static void close_all();

static int set_active_change_set(int cs);
static int get_active_change_set() {return activeChangeSet_;}
static int get_change_set_count() {return changeSetCount_;}

static int output();
static int io_word_size() { return ioWordSize_; }
operator int() const;
Expand All @@ -48,7 +52,9 @@ namespace Excn {
static int mode64bit_;
static int changeSetCount_;
static int activeChangeSet_;
static int activeOutputChangeSet_;
static bool keepOpen_;
static bool verifyValidFile_;
static bool onlySelectedChangeSet_;
};
} // namespace Excn
61 changes: 33 additions & 28 deletions packages/seacas/applications/epu/EP_Internals.C
Original file line number Diff line number Diff line change
Expand Up @@ -422,41 +422,46 @@ int Excn::Internals<INT>::put_metadata(const Mesh &mesh, const CommunicationMeta
int map_type = get_type(exodusFilePtr, EX_MAPS_INT64_DB);

std::string errmsg;
int status;

// define some attributes...
int status = nc_put_att_text(exodusFilePtr, NC_GLOBAL, ATT_TITLE, mesh.title.length() + 1,
mesh.title.c_str());
if (status != NC_NOERR) {
errmsg = fmt::format("Error: failed to define title attribute to file id {}", exodusFilePtr);
ex_err_fn(exodusFilePtr, __func__, errmsg.c_str(), status);
return EX_FATAL;
}
if (changeSetNumber <= 1) {
// define some attributes...
int rootid = exodusFilePtr & EX_FILE_ID_MASK;

// For use later to help readers know how much memory to allocate
// for name storage, we define an attribute containing the maximum
// size of any name.
{
int current_len = 0;
status = nc_put_att_int(exodusFilePtr, NC_GLOBAL, ATT_MAX_NAME_LENGTH, NC_INT, 1, &current_len);
status = nc_put_att_text(rootid, NC_GLOBAL, ATT_TITLE, mesh.title.length() + 1,
mesh.title.c_str());
if (status != NC_NOERR) {
ex_opts(EX_VERBOSE);
errmsg = fmt::format("Error: failed to define ATT_MAX_NAME_LENGTH attribute to file id {}",
exodusFilePtr);
errmsg = fmt::format("Error: failed to define title attribute to file id {}", exodusFilePtr);
ex_err_fn(exodusFilePtr, __func__, errmsg.c_str(), status);
return EX_FATAL;
}
}

// create name string length dimension
if (maximumNameLength < 32) {
maximumNameLength = 32;
}
status = nc_def_dim(exodusFilePtr, DIM_STR_NAME, maximumNameLength + 1, &namestrdim);
if (status != NC_NOERR) {
ex_opts(EX_VERBOSE);
errmsg = fmt::format("Error: failed to define name string length in file id {}", exodusFilePtr);
ex_err_fn(exodusFilePtr, __func__, errmsg.c_str(), status);
return EX_FATAL;
// For use later to help readers know how much memory to allocate
// for name storage, we define an attribute containing the maximum
// size of any name.
{
int current_len = 0;
status = nc_put_att_int(rootid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, NC_INT, 1, &current_len);
if (status != NC_NOERR) {
ex_opts(EX_VERBOSE);
errmsg = fmt::format("Error: failed to define ATT_MAX_NAME_LENGTH attribute to file id {}",
exodusFilePtr);
ex_err_fn(exodusFilePtr, __func__, errmsg.c_str(), status);
return EX_FATAL;
}
}

// create name string length dimension
if (maximumNameLength < 32) {
maximumNameLength = 32;
}
status = nc_def_dim(rootid, DIM_STR_NAME, maximumNameLength + 1, &namestrdim);
if (status != NC_NOERR) {
ex_opts(EX_VERBOSE);
errmsg = fmt::format("Error: failed to define name string length in file id {}", exodusFilePtr);
ex_err_fn(exodusFilePtr, __func__, errmsg.c_str(), status);
return EX_FATAL;
}
}

// ...and some dimensions..
Expand Down
29 changes: 4 additions & 25 deletions packages/seacas/applications/epu/EP_Internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,13 @@
#include <vector> // for vector
namespace Excn {
class Block;
} // namespace Excn
namespace Excn {
class CommunicationMetaData;
} // namespace Excn
namespace Excn {
class Mesh;
} // namespace Excn
namespace Excn {
template <typename INT> class NodeSet;
} // namespace Excn
namespace Excn {
template <typename INT> class SideSet;
} // namespace Excn
namespace Excn {
template <typename INT> class EdgeBlock;
} // namespace Excn
namespace Excn {
template <typename INT> class FaceBlock;
} // namespace Excn
namespace Excn {
} // namespace Excn
namespace Excn {
} // namespace Excn
namespace Excn {
} // namespace Excn
namespace Excn {
} // namespace Excn
namespace Excn {
} // namespace Excn
}

/*!
* This set of classes provides a thin wrapper around the exodusII
Expand Down Expand Up @@ -91,8 +69,8 @@ namespace Excn {
template <typename INT> class Internals
{
public:
Internals(int exoid, int maximum_name_length)
: exodusFilePtr(exoid), maximumNameLength(maximum_name_length)
Internals(int exoid, int maximum_name_length, int change_set_number)
: exodusFilePtr(exoid), maximumNameLength(maximum_name_length), changeSetNumber(change_set_number)
{
}

Expand Down Expand Up @@ -131,5 +109,6 @@ namespace Excn {
int commIndexVar{};
int elemCommIndexVar{};
int maximumNameLength{};
int changeSetNumber{0};
};
} // namespace Excn
4 changes: 2 additions & 2 deletions packages/seacas/applications/epu/EP_Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

static const std::array<std::string, 3> qainfo{
"epu -- E Pluribus Unum",
"6.11",
"2024/12/04",
"7.00",
"2024/12/10",
};
Loading

0 comments on commit 196abca

Please sign in to comment.