Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/face_creation/skin_mesh/UnitTestSkinMeshShell.cpp

raw
1 #include <gtest/gtest.h>
2
3 #include <stk_unit_test_utils/BuildMesh.hpp>
4 #include "UnitTestSkinMeshUseCaseUtils.hpp"
5
6 namespace {
7
8 using namespace stk::mesh::impl;
9 using namespace stk::mesh;
10 using stk::unit_test_util::build_mesh;
11
12 TEST(ElementGraph, two_wedge_sandwich_with_quad_shell)
13 {
14 stk::ParallelMachine comm = MPI_COMM_WORLD;
15
16 if(stk::parallel_machine_size(comm) <= 3)
17 {
18 std::string fileName("made_up.g");
19 {
20 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(3, MPI_COMM_SELF, stk::mesh::BulkData::NO_AUTO_AURA);
21 stk::mesh::MetaData& meta_data = bulkPtr->mesh_meta_data();
22 stk::mesh::BulkData& bulk_data = *bulkPtr;
23 stk::mesh::fixtures::VectorFieldType & node_coord =
24 meta_data.declare_field<double>(stk::topology::NODE_RANK, "coordinates");
25 stk::mesh::put_field_on_mesh(node_coord, meta_data.universal_part(), 3, nullptr);
26
27 stk::io::put_io_part_attribute(meta_data.declare_part_with_topology("wedges", stk::topology::WEDGE_6));
28 stk::io::put_io_part_attribute(meta_data.declare_part_with_topology("quad_shells", stk::topology::SHELL_QUAD_4));
29
30 meta_data.commit();
31
32 static const char method[] =
33 "stk_mesh::fixtures::heterogenous_mesh_bulk_data";
34 ////////////////////////////////
35
36 bulk_data.modification_begin();
37
38 stk::mesh::Part & wedge_block = *meta_data.get_part("wedges", method);
39 stk::mesh::Part & quad_shell_block = *meta_data.get_part("quad_shells", method);
40
41 unsigned elem_id = 1;
42
43 unsigned number_wedge = 2;
44
45 stk::mesh::EntityIdVector wedge_node_ids[2] = {
46 {1, 7, 3, 2, 8, 4},
47 {7, 5, 3, 8, 6, 4}
48 };
49
50 for(unsigned i = 0; i < number_wedge; ++i, ++elem_id)
51 {
52 stk::mesh::declare_element(bulk_data, wedge_block, elem_id, wedge_node_ids[i]);
53 }
54
55 stk::mesh::EntityIdVector shell_quad_node_ids = {3, 4, 8, 7};
56
57 stk::mesh::declare_element(bulk_data, quad_shell_block, elem_id, shell_quad_node_ids);
58
59 const unsigned node_count = 8;
60 static const double node_coord_data[node_count][3] = {
61 {0, 0, 0}, {0, 0, 1}, {1, 0, 0}, {1, 0, 1},
62 {1, 1, 0}, {1, 1, 1}, {0, 1, 0}, {0, 1, 1}};
63
64 for(unsigned i = 0; i < node_count; ++i)
65 {
66 stk::mesh::Entity const node = bulk_data.get_entity(stk::topology::NODE_RANK, i + 1);
67
68 double * const coord = stk::mesh::field_data(node_coord, node);
69
70 coord[0] = node_coord_data[i][0];
71 coord[1] = node_coord_data[i][1];
72 coord[2] = node_coord_data[i][2];
73 }
74
75 bulk_data.modification_end();
76 ////////////////////////////////
77
78 if(stk::parallel_machine_rank(comm) == 0)
79 {
80 stk::io::write_mesh(fileName, bulk_data);
81 }
82 }
83 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(3, comm, stk::mesh::BulkData::NO_AUTO_AURA);
84 stk::mesh::MetaData& meta_data = bulkPtr->mesh_meta_data();
85 stk::mesh::BulkData& bulk_data = *bulkPtr;
86 stk::mesh::Part &skin = meta_data.declare_part("skin", meta_data.side_rank());
87 stk::io::put_io_part_attribute(skin);
88 stk::unit_test_util::read_from_serial_file_and_decompose(fileName, bulk_data, "RIB");
89 unlink(fileName.c_str());
90 EXPECT_NO_FATAL_FAILURE(ElemGraphTestUtils::skin_boundary(bulk_data, meta_data.locally_owned_part(), {&skin}));
91 std::vector<size_t> mesh_counts;
92 stk::mesh::comm_mesh_counts(bulk_data, mesh_counts);
93 EXPECT_EQ(8u, mesh_counts[meta_data.side_rank()]);
94
95 std::vector<std::pair<stk::mesh::EntityId, int>> id_and_num_faces = {
96 {1, 4},
97 {2, 4},
98 {3, 0}
99 };
100
101 for(size_t i = 0; i < id_and_num_faces.size(); ++i)
102 {
103 stk::mesh::EntityId id = id_and_num_faces[i].first;
104 int gold_num_faces = id_and_num_faces[i].second;
105 stk::mesh::Entity elem = bulk_data.get_entity(stk::topology::ELEM_RANK, id);
106 if(bulk_data.is_valid(elem))
107 {
108 int num_faces = bulk_data.num_sides(elem);
109 EXPECT_EQ(gold_num_faces, num_faces)<< "element " << id << " has topology " << bulk_data.bucket(elem).topology() << " with num faces " << num_faces << " not same as gold value " << gold_num_faces << std::endl;
110 }
111 }
112 }
113 }
114
115 }