Skip to content

Commit

Permalink
Overlink IO: Write Padding Dimensions for Structured Meshes (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinPrivitera committed Dec 4, 2023
1 parent f570d0d commit 5b87b2b
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/libs/relay/conduit_relay_io_silo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4542,6 +4542,51 @@ write_multimats(DBfile *dbfile,
}
}

//-----------------------------------------------------------------------------
// only for overlink
void
write_pad_dims(DBfile *dbfile,
const std::string &opts_mesh_name,
const Node &root)
{
// TODO_PADDIMS add tests for this

const Node &n_mesh = root["blueprint_index"][opts_mesh_name];
// this only applies to structured topos
// (quadmeshes, so rectilinear, uniform, and structured)
// we can grab the "first" topo because we know there is only one.
const std::string topo_type = n_mesh["topologies"][0]["type"].as_string();
if (topo_type == "structured" ||
topo_type == "rectilinear" ||
topo_type == "uniform")
{
char const *elemname = "paddims";
const int elemlength = 6;
const int nelems = 1;
const int nvalues = 6;

// we do not have a way to record ghost nodes in blueprint
// so we just write out all zeroes to make overlink happy
std::vector<int> paddim_vals;
paddim_vals.push_back(0);
paddim_vals.push_back(0);
paddim_vals.push_back(0);
paddim_vals.push_back(0);
paddim_vals.push_back(0);
paddim_vals.push_back(0);

DBPutCompoundarray(dbfile, // dbfile
"PAD_DIMS", // name
&elemname, // elemnames
&elemlength, // elemlengths
nelems, // nelems
static_cast<void *>(paddim_vals.data()), // values
nvalues, // nvalues
DB_INT, // datatype
NULL); // optlist
}
}

//-----------------------------------------------------------------------------
// only for overlink
void
Expand Down Expand Up @@ -6009,6 +6054,10 @@ void CONDUIT_RELAY_API write_mesh(const Node &mesh,
write_var_attributes(dbfile.getSiloObject(),
opts_out_mesh_name,
root);

write_pad_dims(dbfile.getSiloObject(),
opts_out_mesh_name,
root);
}
}

Expand Down
Binary file removed src/tests/relay/data/silo/overlink/c36_m5.tar
Binary file not shown.
Binary file removed src/tests/relay/data/silo/overlink/tetra8.tar
Binary file not shown.
71 changes: 69 additions & 2 deletions src/tests/relay/t_relay_io_silo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ TEST(conduit_relay_io_silo, round_trip_save_option_overlink1)
}

//-----------------------------------------------------------------------------
// this tests var attributes
// this tests var attributes and padding dimensions
TEST(conduit_relay_io_silo, round_trip_save_option_overlink2)
{
const std::string basename = "silo_save_option_overlink_basic";
Expand Down Expand Up @@ -1304,6 +1304,73 @@ TEST(conduit_relay_io_silo, round_trip_save_option_overlink2)
EXPECT_EQ(load_mesh[0].number_of_children(), save_mesh.number_of_children());

EXPECT_FALSE(load_mesh[0].diff(save_mesh, info));

// open silo file and do some checks

DBfile *dbfile = DBOpen(filename.c_str(), DB_UNKNOWN, DB_READ);
EXPECT_TRUE(DBInqVarExists(dbfile, "VAR_ATTRIBUTES"));
EXPECT_TRUE(DBInqVarType(dbfile, "VAR_ATTRIBUTES") == DB_ARRAY);

DBcompoundarray *var_attr = DBGetCompoundarray(dbfile, "VAR_ATTRIBUTES");

// fetch pointers to elements inside the compound array
char **elemnames = var_attr->elemnames;
int *elemlengths = var_attr->elemlengths;
int nelems = var_attr->nelems;
int *values = static_cast<int *>(var_attr->values);
int nvalues = var_attr->nvalues;
int datatype = var_attr->datatype;

EXPECT_EQ(std::string(elemnames[0]), "field");
EXPECT_EQ(std::string(elemnames[1]), "field2");
EXPECT_EQ(elemlengths[0], 5);
EXPECT_EQ(elemlengths[1], 5);
EXPECT_EQ(nelems, 2);
// for first var
EXPECT_EQ(values[0], 1);
EXPECT_EQ(values[1], 0);
EXPECT_EQ(values[2], 1);
EXPECT_EQ(values[3], 0);
EXPECT_EQ(values[4], 1);
// for second var
EXPECT_EQ(values[5], 1);
EXPECT_EQ(values[6], 1);
EXPECT_EQ(values[7], 1);
EXPECT_EQ(values[8], 0);
EXPECT_EQ(values[9], 1);
EXPECT_EQ(nvalues, 10);
EXPECT_EQ(datatype, DB_INT);

DBFreeCompoundarray(var_attr);

EXPECT_TRUE(DBInqVarExists(dbfile, "PAD_DIMS"));
EXPECT_TRUE(DBInqVarType(dbfile, "PAD_DIMS") == DB_ARRAY);

DBcompoundarray *pad_dims = DBGetCompoundarray(dbfile, "PAD_DIMS");

// fetch pointers to elements inside the compound array
elemnames = pad_dims->elemnames;
elemlengths = pad_dims->elemlengths;
nelems = pad_dims->nelems;
values = static_cast<int *>(pad_dims->values);
nvalues = pad_dims->nvalues;
datatype = pad_dims->datatype;

EXPECT_EQ(std::string(elemnames[0]), "paddims");
EXPECT_EQ(elemlengths[0], 6);
EXPECT_EQ(nelems, 1);
EXPECT_EQ(values[0], 0);
EXPECT_EQ(values[1], 0);
EXPECT_EQ(values[2], 0);
EXPECT_EQ(values[3], 0);
EXPECT_EQ(values[4], 0);
EXPECT_EQ(values[5], 0);
EXPECT_EQ(nvalues, 6);
EXPECT_EQ(datatype, DB_INT);

DBFreeCompoundarray(pad_dims);

DBClose(dbfile);
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1588,6 +1655,6 @@ TEST(conduit_relay_io_silo, read_overlink_directly)
// - units once they are supported
// - etc.

// TODO what are those bonus tar files doing in the overlink data dir?
// TODO add tetra8 and c36_m5 to all the overlink i/o tests

// TODO somewhere I need to error on overlink when there are different var or mesh types across domains

0 comments on commit 5b87b2b

Please sign in to comment.