Skip to content

Commit

Permalink
IOSS: Catalyst API 2 (#466)
Browse files Browse the repository at this point in the history
Create the cell_ids and cell_node_ids fields for
a StructuredBlock when asked for by a reading
application, if these fields are not already stored in
the Conduit data. Uses the get_cell_ids() and
get_cell_node_ids() methods on StructuredBlock.
  • Loading branch information
tjotaha authored and gdsjaar committed Jul 8, 2024
1 parent 6c13cc2 commit 72a485b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ namespace Iocatalyst {
inline static const std::string CATCONDNODE = "CATALYST_CONDUIT_NODE";
inline static const std::string CATDUMPDIR = "CATALYST_DATA_DUMP_DIRECTORY";
inline static const std::string CATREADTIMESTEP = "CATALYST_READER_TIME_STEP";
inline static const std::string CELLIDS = "cell_ids";
inline static const std::string CELLNODEIDS = "cell_node_ids";
inline static const std::string COMPONENTCOUNT = "component_count";
inline static const std::string COMPONENTDEGREE = "component_degree";
inline static const std::string COUNT = "count";
Expand Down Expand Up @@ -587,6 +589,41 @@ namespace Iocatalyst {

std::string getTimePath() { return detail::DATABASE + detail::FS + detail::TIME; }

int64_t getStructuredBlockIDS(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
void *data, size_t data_size)
{
auto num_to_get = field.verify(data_size);

if (num_to_get > 0) {
switch (field.get_type()) {
case Ioss::Field::BasicType::INT32:
copyIDS(sb, field, reinterpret_cast<int32_t *>(data));
break;

case Ioss::Field::BasicType::INT64:
copyIDS(sb, field, reinterpret_cast<int64_t *>(data));
break;
default:
std::ostringstream errmsg;
fmt::print(errmsg, "ERROR in {}: {} ({}), unsupported field type: {}\n", __func__,
field.get_name(), num_to_get, field.type_string());
IOSS_ERROR(errmsg);
}
}
return num_to_get;
}

template <typename INT_t>
void copyIDS(const Ioss::StructuredBlock *sb, const Ioss::Field &field, INT_t *data)
{
if (field.get_name() == detail::CELLIDS) {
sb->get_cell_ids(data, true);
}
else {
sb->get_cell_node_ids(data, true);
}
}

Ioss::Map &get_node_map(const Ioss::DatabaseIO *dbase) const
{
if (this->NodeMap.defined()) {
Expand Down Expand Up @@ -1679,6 +1716,9 @@ namespace Iocatalyst {
if (impl.hasField(blockPath, sb, field.get_name())) {
return impl.getField(blockPath, sb, field, data, data_size);
}
else if (field.get_name() == detail::CELLIDS || field.get_name() == detail::CELLNODEIDS) {
return impl.getStructuredBlockIDS(sb, field, data, data_size);
}
else if ((field.get_name() == detail::MESHMODCO) &&
(impl.hasField(blockPath, sb, detail::MESHMODCOX) &&
impl.hasField(blockPath, sb, detail::MESHMODCOY) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <Ioss_StructuredBlock.h>
#include <catalyst/Iocatalyst_DatabaseIO.h>
#include <catalyst_tests/Iocatalyst_DatabaseIOTest.h>
#include <cstdint>

TEST_F(Iocatalyst_DatabaseIOTest, ReadConduitCanExo)
{
Expand Down Expand Up @@ -97,4 +98,37 @@ TEST_F(Iocatalyst_DatabaseIOTest, SetRankNumRanksSerialParallel)

auto db = getCatalystDatabaseFromConduitFiles("Iocatalyst_can_ex2_MPI_1", iossProp);
ASSERT_TRUE(db != nullptr);
}

TEST_F(Iocatalyst_DatabaseIOTest, CellIdsAndCellNodeIds)
{
setenv("CATALYST_READER_TIME_STEP", "1", 1);

auto db = getCatalystDatabaseFromConduitFiles("Iocatalyst_sparc1_cgns_MPI_1");
ASSERT_TRUE(db != nullptr);

Ioss::Region reg(db);

auto sb = reg.get_structured_block("blk-1");

EXPECT_TRUE(sb->field_exists("cell_ids"));
EXPECT_TRUE(sb->field_exists("cell_node_ids"));

auto cids = sb->get_fieldref("cell_ids");
EXPECT_TRUE(cids.get_type() == Ioss::Field::INTEGER);
std::vector<int32_t> cidBuff(cids.raw_count());
EXPECT_EQ(sb->get_field_data("cell_ids", Data(cidBuff), sizeof(int32_t) * cidBuff.size()),
cids.raw_count());
EXPECT_EQ(cidBuff[0], 1);
EXPECT_EQ(cidBuff[cids.raw_count() - 1], 256);


auto cnids = sb->get_fieldref("cell_node_ids");
EXPECT_TRUE(cnids.get_type() == Ioss::Field::INTEGER);
std::vector<int32_t> cnidsBuff(cnids.raw_count());
EXPECT_EQ(
sb->get_field_data("cell_node_ids", Data(cnidsBuff), sizeof(int32_t) * cnidsBuff.size()),
cnids.raw_count());
EXPECT_EQ(cnidsBuff[0], 1);
EXPECT_EQ(cnidsBuff[cnids.raw_count() - 1], 594);
}

0 comments on commit 72a485b

Please sign in to comment.