Skip to content

Commit

Permalink
fixed the remainder of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinPrivitera committed Jul 19, 2021
1 parent 7b57c9e commit bc2bcd1
Showing 1 changed file with 193 additions and 182 deletions.
375 changes: 193 additions & 182 deletions src/tests/blueprint/t_blueprint_mesh_generate_map_fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using namespace conduit;
using namespace conduit::blueprint::mesh;

//-----------------------------------------------------------------------------
TEST(conduit_blueprint_generate_unstructured, generate_sides_and_map_fields_2D)
TEST(conduit_blueprint_generate_unstructured, generate_sides_2D)
{
index_t nlevels = 2;
Node n, side_mesh, info;
Expand Down Expand Up @@ -105,184 +105,195 @@ TEST(conduit_blueprint_generate_unstructured, generate_sides_and_map_fields_2D)
}
}

// //-----------------------------------------------------------------------------
// TEST(conduit_blueprint_generate_unstructured, generate_sides_and_map_fields_3D)
// {
// index_t length = 1;
// Node n, side_mesh, info;

// // create a polychain of length 1
// examples::polychain(length, n);
// EXPECT_TRUE(verify(n, info));

// Node s2dmap, d2smap;
// Node &side_coords = side_mesh["coordsets/coords"];
// Node &side_topo = side_mesh["topologies/topo"];
// blueprint::mesh::topology::unstructured::generate_sides(n["topologies/topo"],
// side_topo,
// side_coords,
// s2dmap,
// d2smap);
// topology::unstructured::map_fields_to_generated_sides(n, d2smap, side_mesh, "topo");
// EXPECT_TRUE(verify(side_mesh, info));

// EXPECT_EQ(side_mesh["fields/chain/topology"].as_string(), "topo");
// EXPECT_EQ(side_mesh["fields/chain/association"].as_string(), "element");
// EXPECT_EQ(side_mesh["fields/chain/volume_dependent"].as_string(), "false");

// index_t num_tets_in_hex = 24;
// index_t num_tets_in_triprism = 18;

// index_t num_field_values = num_tets_in_hex + 2 * num_tets_in_triprism;
// EXPECT_EQ(side_mesh["fields/chain/values"].dtype().number_of_elements(), num_field_values);

// int64 *chain_values = side_mesh["fields/chain/values"].value();

// for (int i = 0; i < num_field_values; i ++)
// {
// if (i < num_tets_in_hex)
// {
// EXPECT_EQ(chain_values[i], 0);
// }
// else
// {
// EXPECT_EQ(chain_values[i], 1);
// }
// }

// EXPECT_EQ(side_mesh["fields/original_element_ids/topology"].as_string(), "topo");
// EXPECT_EQ(side_mesh["fields/original_element_ids/association"].as_string(), "element");
// EXPECT_EQ(side_mesh["fields/original_element_ids/volume_dependent"].as_string(), "false");

// EXPECT_EQ(side_mesh["fields/original_element_ids/values"].dtype().number_of_elements(), num_field_values);

// uint32 *id_values = side_mesh["fields/original_element_ids/values"].value();

// for (int i = 0; i < num_field_values; i ++)
// {
// if (i < num_tets_in_hex)
// {
// EXPECT_EQ(id_values[i], 0);
// }
// else if (i < num_tets_in_hex + num_tets_in_triprism)
// {
// EXPECT_EQ(id_values[i], 1);
// }
// else
// {
// EXPECT_EQ(id_values[i], 2);
// }
// }
// }

// //-----------------------------------------------------------------------------
// TEST(conduit_blueprint_generate_unstructured, generate_sides_and_map_fields_exceptions)
// {
// index_t nlevels = 2;
// Node n, side_mesh, info;

// // create polytessalation with two levels
// examples::polytess(nlevels, n);
// EXPECT_TRUE(verify(n, info));

// Node s2dmap, d2smap;
// Node &side_coords = side_mesh["coordsets/coords"];
// Node &side_topo = side_mesh["topologies/topo"];

// // catch float64 error
// blueprint::mesh::topology::unstructured::generate_sides(n["topologies/topo"],
// side_topo,
// side_coords,
// s2dmap,
// d2smap);
// d2smap["values"].set(conduit::DataType::float64(1));
// try
// {
// blueprint::mesh::topology::unstructured::map_fields_to_generated_sides(n, d2smap, side_mesh, "topo");
// FAIL();
// }
// catch(const std::exception& err)
// {
// std::string msg = "Unsupported field type in dtype: \"float64\"";
// std::string actual = err.what();
// EXPECT_TRUE(actual.find(msg) != std::string::npos);
// }

// // catch if shape is not tet or tri
// blueprint::mesh::topology::unstructured::generate_sides(n["topologies/topo"],
// side_topo,
// side_coords,
// s2dmap,
// d2smap);
// side_mesh["topologies/topo/elements/shape"] = "strange_shape";
// try
// {
// blueprint::mesh::topology::unstructured::map_fields_to_generated_sides(n, d2smap, side_mesh, "topo");
// FAIL();
// }
// catch(const std::exception& err)
// {
// std::string msg = "Bad shape in strange_shape";
// std::string actual = err.what();
// EXPECT_TRUE(actual.find(msg) != std::string::npos);
// }

// // catch if field is vertex associated
// blueprint::mesh::topology::unstructured::generate_sides(n["topologies/topo"],
// side_topo,
// side_coords,
// s2dmap,
// d2smap);
// n["fields/level/association"] = "vertex";
// try
// {
// blueprint::mesh::topology::unstructured::map_fields_to_generated_sides(n, d2smap, side_mesh, "topo");
// FAIL();
// }
// catch(const std::exception& err)
// {
// std::string msg = "Vertex associated fields are not supported.";
// std::string actual = err.what();
// EXPECT_TRUE(actual.find(msg) != std::string::npos);
// }
// n["fields/level/association"] = "element";

// // catch if field is volume dependent
// blueprint::mesh::topology::unstructured::generate_sides(n["topologies/topo"],
// side_topo,
// side_coords,
// s2dmap,
// d2smap);
// n["fields/level/volume_dependent"] = "true";
// try
// {
// blueprint::mesh::topology::unstructured::map_fields_to_generated_sides(n, d2smap, side_mesh, "topo");
// FAIL();
// }
// catch(const std::exception& err)
// {
// std::string msg = "Volume dependent fields are not supported.";
// std::string actual = err.what();
// EXPECT_TRUE(actual.find(msg) != std::string::npos);
// }
// n["fields/level/volume_dependent"] = "false";

// // catch if field has wrong data type
// blueprint::mesh::topology::unstructured::generate_sides(n["topologies/topo"],
// side_topo,
// side_coords,
// s2dmap,
// d2smap);
// n["fields/level/values"].set(conduit::DataType::int8(1));
// try
// {
// blueprint::mesh::topology::unstructured::map_fields_to_generated_sides(n, d2smap, side_mesh, "topo");
// FAIL();
// }
// catch(const std::exception& err)
// {
// std::string msg = "Unsupported field type in dtype: \"int8\"";
// std::string actual = err.what();
// EXPECT_TRUE(actual.find(msg) != std::string::npos);
// }
// }
//-----------------------------------------------------------------------------
TEST(conduit_blueprint_generate_unstructured, generate_sides_3D)
{
index_t length = 1;
Node n, side_mesh, info;

// create a polychain of length 1
examples::polychain(length, n);
EXPECT_TRUE(verify(n, info));

Node s2dmap, d2smap;
Node &side_coords = side_mesh["coordsets/coords"];
Node &side_topo = side_mesh["topologies/topo"];
Node &side_fields = side_mesh["fields"];
Node options;
options["field_names"] = "chain";

blueprint::mesh::topology::unstructured::generate_sides(n["topologies/topo"],
n["fields"],
side_topo,
side_coords,
side_fields,
s2dmap,
d2smap,
options);
EXPECT_TRUE(verify(side_mesh, info));

EXPECT_EQ(side_mesh["fields/chain/topology"].as_string(), "topo");
EXPECT_EQ(side_mesh["fields/chain/association"].as_string(), "element");
EXPECT_EQ(side_mesh["fields/chain/volume_dependent"].as_string(), "false");

index_t num_tets_in_hex = 24;
index_t num_tets_in_triprism = 18;

index_t num_field_values = num_tets_in_hex + 2 * num_tets_in_triprism;
EXPECT_EQ(side_mesh["fields/chain/values"].dtype().number_of_elements(), num_field_values);

int64 *chain_values = side_mesh["fields/chain/values"].value();

for (int i = 0; i < num_field_values; i ++)
{
if (i < num_tets_in_hex)
{
EXPECT_EQ(chain_values[i], 0);
}
else
{
EXPECT_EQ(chain_values[i], 1);
}
}

EXPECT_EQ(side_mesh["fields/original_element_ids/topology"].as_string(), "topo");
EXPECT_EQ(side_mesh["fields/original_element_ids/association"].as_string(), "element");
EXPECT_EQ(side_mesh["fields/original_element_ids/volume_dependent"].as_string(), "false");

EXPECT_EQ(side_mesh["fields/original_element_ids/values"].dtype().number_of_elements(), num_field_values);

uint32 *id_values = side_mesh["fields/original_element_ids/values"].value();

for (int i = 0; i < num_field_values; i ++)
{
if (i < num_tets_in_hex)
{
EXPECT_EQ(id_values[i], 0);
}
else if (i < num_tets_in_hex + num_tets_in_triprism)
{
EXPECT_EQ(id_values[i], 1);
}
else
{
EXPECT_EQ(id_values[i], 2);
}
}
}

//-----------------------------------------------------------------------------
TEST(conduit_blueprint_generate_unstructured, generate_sides_vertex_ex)
{
index_t nlevels = 2;
Node n, side_mesh, info;

// create polytessalation with two levels
examples::polytess(nlevels, n);
EXPECT_TRUE(verify(n, info));

Node s2dmap, d2smap;
Node &side_coords = side_mesh["coordsets/coords"];
Node &side_topo = side_mesh["topologies/topo"];
Node &side_fields = side_mesh["fields"];
Node options;
options["field_names"] = "level";

// catch if field is vertex associated
try
{
n["fields/level/association"] = "vertex";
blueprint::mesh::topology::unstructured::generate_sides(n["topologies/topo"],
n["fields"],
side_topo,
side_coords,
side_fields,
s2dmap,
d2smap,
options);
FAIL();
}
catch(const std::exception& err)
{
std::string msg = "Vertex associated fields are not supported.";
std::string actual = err.what();
EXPECT_TRUE(actual.find(msg) != std::string::npos);
}
}

//-----------------------------------------------------------------------------
TEST(conduit_blueprint_generate_unstructured, generate_sides_vol_dep_ex)
{
index_t nlevels = 2;
Node n, side_mesh, info;

// create polytessalation with two levels
examples::polytess(nlevels, n);
EXPECT_TRUE(verify(n, info));

Node s2dmap, d2smap;
Node &side_coords = side_mesh["coordsets/coords"];
Node &side_topo = side_mesh["topologies/topo"];
Node &side_fields = side_mesh["fields"];
Node options;
options["field_names"] = "level";

// catch if field is volume dependent
try
{
n["fields/level/volume_dependent"] = "true";
blueprint::mesh::topology::unstructured::generate_sides(n["topologies/topo"],
n["fields"],
side_topo,
side_coords,
side_fields,
s2dmap,
d2smap,
options);
FAIL();
}
catch(const std::exception& err)
{
std::string msg = "Volume dependent fields are not supported.";
std::string actual = err.what();
EXPECT_TRUE(actual.find(msg) != std::string::npos);
}
}

//-----------------------------------------------------------------------------
TEST(conduit_blueprint_generate_unstructured, generate_sides_field_datatype_ex)
{
index_t nlevels = 2;
Node n, side_mesh, info;

// create polytessalation with two levels
examples::polytess(nlevels, n);
EXPECT_TRUE(verify(n, info));

Node s2dmap, d2smap;
Node &side_coords = side_mesh["coordsets/coords"];
Node &side_topo = side_mesh["topologies/topo"];
Node &side_fields = side_mesh["fields"];
Node options;
options["field_names"] = "level";

// catch if field has wrong data type
try
{
n["fields/level/values"].set(conduit::DataType::int8(1));
blueprint::mesh::topology::unstructured::generate_sides(n["topologies/topo"],
n["fields"],
side_topo,
side_coords,
side_fields,
s2dmap,
d2smap,
options);
FAIL();
}
catch(const std::exception& err)
{
std::string msg = "Unsupported field type in dtype: \"int8\"";
std::string actual = err.what();
EXPECT_TRUE(actual.find(msg) != std::string::npos);
}
}

0 comments on commit bc2bcd1

Please sign in to comment.