Skip to content

Commit

Permalink
brought hexs and tets to the modern era
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinPrivitera committed Jun 27, 2024
1 parent a84d565 commit 423447f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 158 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
- Fixed partitioner so it reverses vertex order as needed in polyhedral face definitions when extracting mesh elements.
- Changed `conduit::blueprint::mesh::partition_map_back()` function so it will attempt to reuse existing field memory when mapping fields back. This permits `partition_map_back()` to send data from a partitioned mesh into the original mesh where fields were provided from a host code using `Node::set_external()`.
- Changed `generate_sides` to be robust to the case where no fields exist.
- Deprecated braid `quads_and_tris` example in favor of `mixed_2d`.

#### Relay
- Changed `conduit::relay::mpi::communicate_using_schema` to avoid an invalid tag MPI error message on some MPI distributions.
Expand Down
184 changes: 36 additions & 148 deletions src/libs/blueprint/conduit_blueprint_mesh_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1627,134 +1627,9 @@ braid_quads_and_tris(index_t npts_x,
index_t npts_y,
Node &res)
{
// TODO make this one conform to real mixed spec
CONDUIT_INFO("This braid example is deprecated in favor of mixed_2d.")

res.reset();

int32 nele_x = (int32)(npts_x - 1);
int32 nele_y = (int32)(npts_y - 1);

braid_init_example_state(res);
braid_init_explicit_coordset(npts_x,
npts_y,
1,
res["coordsets/coords"]);

res["topologies/mesh/type"] = "unstructured";
res["topologies/mesh/coordset"] = "coords";

Node &elems = res["topologies/mesh/elements"];
elems["shape"] = "mixed";
elems["shape_map/quad"] = 9; // VTK_QUAD
elems["shape_map/tri"] = 5; // VTK_TRIANGLE

std::vector<int32> shapes;
std::vector<int32> sizes;
std::vector<int32> offsets;

// Fill in shapes, sizes, and offsets, and calculate size of the connectivity array
int32 count = 0;
int32 ielem = 0;
int32 last_offset = 0;
for(int32 j = 0; j < nele_y ; j++)
{
for(int32 i = 0; i < nele_x; i++)
{
if ( ielem % 2 == 0 )
{
// QUAD
shapes.push_back(9);
sizes.push_back(4);
offsets.push_back(last_offset);
last_offset += 4;

count += 4;
}
else
{
// TRIANGLE
shapes.push_back(5);
shapes.push_back(5);
sizes.push_back(3);
offsets.push_back(last_offset);
last_offset += 3;
sizes.push_back(3);
offsets.push_back(last_offset);
last_offset += 3;

count += 6;
}

++ielem;

} // END for all i

} // END for all j

elems["shapes"].set(shapes);
elems["sizes"].set(sizes);
elems["offsets"].set(offsets);

// Allocate connectivity array
elems["connectivity"].set(DataType::int32(count));
int32_array conn = elems["connectivity"].value();

// Fill in connectivity array
int32 idx = 0;
int32 elem = 0;
for(int32 j = 0; j < nele_y ; j++)
{
for(int32 i = 0; i < nele_x; i++)
{
int32 n1 = j * npts_x + i;
int32 n2 = j * npts_x + i + 1;
int32 n3 = (j+1) * npts_x + i + 1;
int32 n4 = (j+1) * npts_x + i;

if ( elem % 2 == 0 )
{
conn[idx ] = n1;
conn[idx+1] = n2;
conn[idx+2] = n3;
conn[idx+3] = n4;
idx+=4;
}
else
{
conn[idx ] = n1;
conn[idx+1 ] = n2;
conn[idx+2 ] = n4;
idx+=3;

conn[idx ] = n2;
conn[idx+1 ] = n3;
conn[idx+2 ] = n4;
idx+=3;
}

++elem;

} // END for all i

} // END for all j


Node &fields = res["fields"];

braid_init_example_point_scalar_field(npts_x,
npts_y,
1,
fields["braid"]);

braid_init_example_point_vector_field(npts_x,
npts_y,
1,
fields["vel"]);

// braid_init_example_element_scalar_field(nele_x,
// nele_y,
// 0,
// fields["radial"]);
// TODO remove in conduit 0.9.4
}


Expand Down Expand Up @@ -2539,13 +2414,8 @@ braid_hexs_and_tets(index_t npts_x,
index_t npts_z,
Node &res)
{
// TODO make this one conform to real mixed spec
// TODO can we delete this one


// WARNING -- The code below is UNTESTED.
// The SILO writer is missing an implementation for
// unstructured indexed_stream meshes in 3D.

res.reset();

int32 nele_hexs_x = (int32)(npts_x - 1);
Expand Down Expand Up @@ -2578,21 +2448,21 @@ braid_hexs_and_tets(index_t npts_x,
res["topologies/mesh/type"] = "unstructured";
res["topologies/mesh/coordset"] = "coords";

res["topologies/mesh/elements/element_types/hexs/stream_id"] = 0;
res["topologies/mesh/elements/element_types/hexs/shape"] = "hex";
res["topologies/mesh/elements/shape"] = "mixed";
res["topologies/mesh/elements/shape_map/hex"] = 12; // VTK_HEXAHEDRON
res["topologies/mesh/elements/shape_map/tet"] = 10; // VTK_TETRA

res["topologies/mesh/elements/element_types/tets/stream_id"] = 1;
res["topologies/mesh/elements/element_types/tets/shape"] = "tet";

res["topologies/mesh/elements/element_index/stream_ids"].set(DataType::int32(4));
std::vector<int32> shapes;
std::vector<int32> sizes;
std::vector<int32> offsets;

res["topologies/mesh/elements/stream"].set( DataType::int32(n_hexs_verts + n_tets_verts) );
int32* conn = res["topologies/mesh/elements/stream"].value();
res["topologies/mesh/elements/connectivity"].set( DataType::int32(n_hexs_verts + n_tets_verts) );
int32_array conn = res["topologies/mesh/elements/connectivity"].value();

std::vector<int32> ele_counts;
std::vector<int32> stream_ids;
int32 idx = 0;
int32 elem_count = 0;
int32 last_offset = 0;
for(int32 k = 0; k < nele_hexs_z ; k++)
{
int32 zoff = k * (nele_hexs_x+1)*(nele_hexs_y+1);
Expand Down Expand Up @@ -2632,8 +2502,11 @@ braid_hexs_and_tets(index_t npts_x,
conn[idx++] = vidx[5];
conn[idx++] = vidx[6];
conn[idx++] = vidx[7];
ele_counts.push_back(1);
stream_ids.push_back(0);

shapes.push_back(12);
sizes.push_back(8);
offsets.push_back(last_offset);
last_offset += 8;
}
else // it is a tet
{
Expand Down Expand Up @@ -2668,16 +2541,31 @@ braid_hexs_and_tets(index_t npts_x,
conn[idx++] = vidx[1];
conn[idx++] = vidx[5];
conn[idx++] = vidx[6];
ele_counts.push_back(6);
stream_ids.push_back(1);

auto add_to_arrays = [&]()
{
shapes.push_back(10);
sizes.push_back(4);
offsets.push_back(last_offset);
last_offset += 4;
};

add_to_arrays();
add_to_arrays();
add_to_arrays();
add_to_arrays();
add_to_arrays();
add_to_arrays();
}

elem_count++;
}
}
}
res["topologies/mesh/elements/element_index/element_counts"].set(ele_counts);
res["topologies/mesh/elements/element_index/stream_ids"].set(stream_ids);

res["topologies/mesh/elements/shapes"].set(shapes);
res["topologies/mesh/elements/sizes"].set(sizes);
res["topologies/mesh/elements/offsets"].set(offsets);

Node &fields = res["fields"];

Expand Down
11 changes: 1 addition & 10 deletions src/tests/blueprint/t_blueprint_mesh_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ TEST(conduit_blueprint_mesh_examples, mesh_2d)
npts_z,
dsets["quads"]);

blueprint::mesh::examples::braid("quads_and_tris",
npts_x,
npts_y,
npts_z,
dsets["quads_and_tris"]);

blueprint::mesh::examples::braid("points",
npts_x,
npts_y,
Expand Down Expand Up @@ -216,7 +210,7 @@ TEST(conduit_blueprint_mesh_examples, mesh_2d)
// std::string topo_shape = shape_block->fetch("shape").as_string();
// which does not exist for indexed_stream meshes.
// The silo writer needs to be updated for this case.
if( name == "quads_and_tris" || name == "mixed_2d")
if(name == "mixed_2d")
{
CONDUIT_INFO("\tNOTE: skipping output to SILO -- ")
CONDUIT_INFO("feature is unavailable for mixed element meshes")
Expand Down Expand Up @@ -327,9 +321,6 @@ TEST(conduit_blueprint_mesh_examples, mesh_3d)
CONDUIT_INFO(info.to_yaml());
}

// TODO: What is this mesh and how should it be rendered?
dsets.remove("hexs_and_tets");

braid_save_helper(dsets,"braid_3d_examples");
#if defined (CONDUIT_RELAY_IO_SILO_ENABLED)
if(silo_enabled)
Expand Down

0 comments on commit 423447f

Please sign in to comment.