| 1 |
#include <unistd.h> |
| 2 |
#include <gtest/gtest.h> |
| 3 |
#include <stk_mesh/base/MetaData.hpp> |
| 4 |
#include <stk_mesh/base/BulkData.hpp> |
| 5 |
#include <stk_mesh/base/Comm.hpp> |
| 6 |
#include <stk_unit_test_utils/getOption.h> |
| 7 |
#include <stk_io/StkMeshIoBroker.hpp> |
| 8 |
#include <stk_io/WriteMesh.hpp> |
| 9 |
#include <stk_unit_test_utils/ioUtils.hpp> |
| 10 |
#include <stk_unit_test_utils/stk_mesh_fixtures/QuadFixture.hpp> |
| 11 |
#include <stk_mesh/base/CreateEdges.hpp> |
| 12 |
#include <stk_mesh/base/SkinBoundary.hpp> |
| 13 |
#include <stk_mesh/base/GetEntities.hpp> |
| 14 |
#include <stk_mesh/base/MeshBuilder.hpp> |
| 15 |
|
| 16 |
namespace |
| 17 |
{ |
| 18 |
|
| 19 |
TEST(StkIoHowTo, WriteMeshWithEdges) |
| 20 |
{ |
| 21 |
std::string filename = "output.exo"; |
| 22 |
{ |
| 23 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 24 |
builder.set_spatial_dimension(3); |
| 25 |
std::shared_ptr<stk::mesh::BulkData> bulk = builder.create(); |
| 26 |
stk::mesh::MetaData& meta = bulk->mesh_meta_data(); |
| 27 |
|
| 28 |
stk::mesh::Part* edgeBlockPart = &meta.declare_part_with_topology("edgeBlock", stk::topology::LINE_2); |
| 29 |
stk::io::put_edge_block_io_part_attribute(*edgeBlockPart); |
| 30 |
stk::io::fill_mesh("generated:1x1x1", *bulk); |
| 31 |
stk::mesh::create_edges(*bulk, meta.universal_part(), edgeBlockPart); |
| 32 |
|
| 33 |
unsigned numEdges = stk::mesh::count_selected_entities(meta.universal_part(), bulk->buckets(stk::topology::EDGE_RANK)); |
| 34 |
EXPECT_EQ(12u, numEdges); |
| 35 |
|
| 36 |
stk::io::StkMeshIoBroker ioBroker; |
| 37 |
ioBroker.set_bulk_data(bulk); |
| 38 |
stk::io::write_mesh(filename, ioBroker, stk::io::WRITE_RESULTS); |
| 39 |
} |
| 40 |
|
| 41 |
{ |
| 42 |
std::shared_ptr<stk::mesh::BulkData> bulk = stk::mesh::MeshBuilder(MPI_COMM_WORLD).create(); |
| 43 |
stk::mesh::MetaData& meta = bulk->mesh_meta_data(); |
| 44 |
stk::io::fill_mesh(filename, *bulk); |
| 45 |
|
| 46 |
const stk::mesh::Part* edgeBlockPart = meta.get_part("edgeBlock"); |
| 47 |
ASSERT_FALSE(edgeBlockPart == nullptr); |
| 48 |
EXPECT_TRUE(stk::io::is_part_io_part(*edgeBlockPart)); |
| 49 |
EXPECT_TRUE(stk::io::is_part_edge_block_io_part(*edgeBlockPart)); |
| 50 |
|
| 51 |
std::vector<size_t> entityCounts; |
| 52 |
stk::mesh::comm_mesh_counts(*bulk, entityCounts); |
| 53 |
EXPECT_EQ(12u, entityCounts[stk::topology::EDGE_RANK]); |
| 54 |
EXPECT_EQ(1u, entityCounts[stk::topology::ELEM_RANK]); |
| 55 |
|
| 56 |
stk::mesh::EntityVector edges; |
| 57 |
stk::mesh::get_entities(*bulk, stk::topology::EDGE_RANK, edges); |
| 58 |
stk::mesh::EntityVector elems; |
| 59 |
stk::mesh::get_entities(*bulk, stk::topology::ELEM_RANK, elems); |
| 60 |
|
| 61 |
for(stk::mesh::Entity edge : edges) { |
| 62 |
const stk::mesh::Entity* edgeElement = bulk->begin_elements(edge); |
| 63 |
EXPECT_EQ(1u, bulk->num_elements(edge)); |
| 64 |
EXPECT_EQ(edgeElement[0], elems[0]); |
| 65 |
} |
| 66 |
|
| 67 |
EXPECT_EQ(12u, bulk->num_edges(elems[0])); |
| 68 |
} |
| 69 |
|
| 70 |
unlink(filename.c_str()); |
| 71 |
} |
| 72 |
|
| 73 |
TEST(StkIoHowTo, Write2DMeshWithEdges) |
| 74 |
{ |
| 75 |
std::string filename = "output2D.exo"; |
| 76 |
{ |
| 77 |
unsigned nx = 2, ny = 2; |
| 78 |
stk::mesh::fixtures::QuadFixture quadFixture(MPI_COMM_WORLD, nx, ny); |
| 79 |
stk::mesh::Part& sidesetPart = quadFixture.m_meta.declare_part("surface_1", stk::topology::EDGE_RANK); |
| 80 |
stk::mesh::Part& edgeBlockPart = quadFixture.m_meta.declare_part_with_topology("edgeBlock", stk::topology::LINE_2); |
| 81 |
|
| 82 |
stk::io::put_io_part_attribute(sidesetPart); |
| 83 |
stk::io::put_edge_block_io_part_attribute(edgeBlockPart); |
| 84 |
stk::io::put_io_part_attribute(quadFixture.m_quad_part); |
| 85 |
|
| 86 |
quadFixture.generate_mesh(); |
| 87 |
|
| 88 |
stk::mesh::BulkData& bulk = quadFixture.m_bulk_data; |
| 89 |
|
| 90 |
stk::mesh::create_edges(bulk, quadFixture.m_quad_part, &edgeBlockPart); |
| 91 |
stk::mesh::create_exposed_block_boundary_sides(bulk, quadFixture.m_quad_part, {&sidesetPart}); |
| 92 |
|
| 93 |
unsigned numSidesetEdges = stk::mesh::count_selected_entities(sidesetPart, bulk.buckets(stk::topology::EDGE_RANK)); |
| 94 |
unsigned expectedNumSidesetEdges = (nx + ny) * 2; |
| 95 |
EXPECT_EQ(expectedNumSidesetEdges, numSidesetEdges); |
| 96 |
|
| 97 |
unsigned numEdgeBlockEdges = stk::mesh::count_selected_entities(edgeBlockPart, bulk.buckets(stk::topology::EDGE_RANK)); |
| 98 |
unsigned expectedNumEdgeBlockEdges = ny*(nx+1) + nx*(ny+1); |
| 99 |
EXPECT_EQ(expectedNumEdgeBlockEdges, numEdgeBlockEdges); |
| 100 |
|
| 101 |
stk::io::StkMeshIoBroker ioBroker; |
| 102 |
ioBroker.set_bulk_data(bulk); |
| 103 |
stk::io::write_mesh(filename, ioBroker, stk::io::WRITE_RESULTS); |
| 104 |
} |
| 105 |
|
| 106 |
{ |
| 107 |
std::shared_ptr<stk::mesh::BulkData> bulk = stk::mesh::MeshBuilder(MPI_COMM_WORLD).create(); |
| 108 |
stk::mesh::MetaData& meta = bulk->mesh_meta_data(); |
| 109 |
stk::io::fill_mesh(filename, *bulk); |
| 110 |
|
| 111 |
EXPECT_EQ(2u, meta.spatial_dimension()); |
| 112 |
|
| 113 |
const stk::mesh::Part* edgeBlockPart = meta.get_part("edgeBlock"); |
| 114 |
ASSERT_FALSE(edgeBlockPart == nullptr); |
| 115 |
EXPECT_TRUE(stk::io::is_part_io_part(*edgeBlockPart)); |
| 116 |
EXPECT_TRUE(stk::io::is_part_edge_block_io_part(*edgeBlockPart)); |
| 117 |
|
| 118 |
const stk::mesh::Part* sidesetPart = meta.get_part("surface_1"); |
| 119 |
ASSERT_FALSE(sidesetPart == nullptr); |
| 120 |
EXPECT_TRUE(stk::io::is_part_io_part(*sidesetPart)); |
| 121 |
EXPECT_FALSE(stk::io::is_part_edge_block_io_part(*sidesetPart)); |
| 122 |
|
| 123 |
std::vector<size_t> entityCounts; |
| 124 |
stk::mesh::comm_mesh_counts(*bulk, entityCounts); |
| 125 |
EXPECT_EQ(12u, entityCounts[stk::topology::EDGE_RANK]); |
| 126 |
EXPECT_EQ(4u, entityCounts[stk::topology::ELEM_RANK]); |
| 127 |
} |
| 128 |
|
| 129 |
unlink(filename.c_str()); |
| 130 |
} |
| 131 |
|
| 132 |
} |