Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/face_creation/TwoHexesTwoProcs.cpp

raw
1 #include <stk_mesh/base/GetEntities.hpp>
2 #include <stk_unit_test_utils/unittestMeshUtils.hpp>
3 #include <stk_mesh/base/Comm.hpp>
4 #include <stk_mesh/base/FEMHelpers.hpp>
5 #include <stk_mesh/base/Bucket.hpp>
6 #include <stk_unit_test_utils/BulkDataTester.hpp>
7 #include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp>
8
9 #include "FaceCreatorFixture.hpp"
10
11 namespace
12 {
13
14 class FaceCreatorUsingBulkDataFaceSharingTester : public FaceCreatorFixture
15 {
16 protected:
17
18 ~FaceCreatorUsingBulkDataFaceSharingTester()
19 {
20 bulkData.reset();
21 metaData.reset();
22 }
23
24 virtual void allocate_bulk(stk::mesh::BulkData::AutomaticAuraOption auraOption,
25 unsigned initialBucketCapacity = stk::mesh::get_default_initial_bucket_capacity(),
26 unsigned maximumBucketCapacity = stk::mesh::get_default_maximum_bucket_capacity())
27 {
28 STK_ThrowRequireMsg((initialBucketCapacity == stk::mesh::get_default_initial_bucket_capacity()) &&
29 (maximumBucketCapacity == stk::mesh::get_default_maximum_bucket_capacity()),
30 "allocate_bulk: BulkDataFaceSharingTester doesn't recognize non-default bucket capacity");
31
32 metaData = stk::mesh::MeshBuilder(communicator)
33 .set_spatial_dimension(m_spatialDim)
34 .set_entity_rank_names(m_entityRankNames)
35 .set_aura_option(auraOption).create_meta_data();
36
37 set_bulk(std::make_shared<stk::unit_test_util::BulkDataFaceSharingTester>(get_meta(), get_comm(), auraOption));
38 }
39
40 void test_elem_elem_graph_for_face_connection_info()
41 {
42 stk::mesh::ElemElemGraph egraph(get_bulk());
43 test_sides_using_graph(egraph);
44 }
45
46 private:
47
48 stk::mesh::EntityVector get_shared_sides()
49 {
50 stk::mesh::EntityVector sides;
51 stk::mesh::get_selected_entities(get_meta().globally_shared_part(), get_bulk().buckets(get_meta().side_rank()), sides);
52 EXPECT_EQ(1u, sides.size());
53 return sides;
54 }
55
56 void test_sides_using_graph(const stk::mesh::ElemElemGraph & egraph)
57 {
58 stk::mesh::EntityVector sides = get_shared_sides();
59 for(size_t i = 0;i < sides.size();++i)
60 test_graph_info_on_side(egraph, sides[i]);
61 }
62
63 void test_graph_info_on_side(const stk::mesh::ElemElemGraph& egraph, stk::mesh::Entity side)
64 {
65 unsigned num_elements = get_bulk().num_elements(side);
66 const stk::mesh::Entity* elements = get_bulk().begin_elements(side);
67 for(unsigned j=0;j<num_elements;++j)
68 check_if_remote_sides_have_consistent_parallel_info(egraph, elements[j], side);
69 }
70
71 void check_if_remote_sides_have_consistent_parallel_info(const stk::mesh::ElemElemGraph& egraph, stk::mesh::Entity element, stk::mesh::Entity side)
72 {
73 if(get_bulk().bucket(element).owned())
74 {
75 int num_connected_elems = egraph.get_num_connected_elems(element);
76 for(int k=0;k<num_connected_elems;++k)
77 check_if_remote_side_has_consistent_parallel_info(egraph, element, k, side);
78 }
79 }
80
81 void check_if_remote_side_has_consistent_parallel_info(const stk::mesh::ElemElemGraph& egraph, stk::mesh::Entity element, int element_index, stk::mesh::Entity side)
82 {
83 if(!egraph.is_connected_elem_locally_owned(element, element_index))
84 {
85 stk::mesh::impl::IdViaSidePair sidePair = egraph.get_connected_remote_id_and_via_side(element, element_index);
86 int remoteSideOrdinal = egraph.get_connected_elements_side(element, element_index);
87 const stk::mesh::impl::ParallelInfo &p_info = egraph.get_const_parallel_edge_info(element, sidePair.side, sidePair.id, remoteSideOrdinal);
88 test_parallel_info_for_side(p_info, element, side, sidePair.side);
89 }
90 }
91
92 void test_parallel_info_for_side(const stk::mesh::impl::ParallelInfo &p_info, stk::mesh::Entity element, stk::mesh::Entity side, int side_ordinal)
93 {
94 test_parallel_info(p_info);
95 stk::mesh::EntityVector side_nodes(get_bulk().begin_nodes(side),get_bulk().end_nodes(side));
96 stk::mesh::EntityVector permuted_element_side_nodes = get_permuted_element_side_nodes(element, side_ordinal, p_info.get_proc_rank_of_neighbor(), p_info.m_permutation);
97 EXPECT_TRUE(side_nodes == permuted_element_side_nodes);
98 }
99
100 stk::mesh::EntityVector get_permuted_element_side_nodes(stk::mesh::Entity element, int side_ordinal, int other_proc_id, unsigned permutation_other_proc)
101 {
102 stk::mesh::EntityVector element_nodes(get_bulk().begin_nodes(element),get_bulk().end_nodes(element));
103 stk::topology side_topology = get_side_topology(element, side_ordinal);
104 stk::mesh::EntityVector element_side_nodes = get_element_side_nodes(element, element_nodes, side_ordinal);
105 return get_permuted_nodes(side_topology, element_side_nodes, other_proc_id, permutation_other_proc);
106 }
107
108 stk::mesh::EntityVector get_element_side_nodes(stk::mesh::Entity element, const stk::mesh::EntityVector& element_nodes, int side_ordinal)
109 {
110 stk::topology element_topology = get_bulk().bucket(element).topology();
111 stk::mesh::EntityVector element_side_nodes(get_side_topology(element, side_ordinal).num_nodes());
112 element_topology.side_nodes(element_nodes.data(), side_ordinal, element_side_nodes.data());
113 return element_side_nodes;
114 }
115
116 stk::topology get_side_topology(stk::mesh::Entity element, int side_ordinal)
117 {
118 stk::topology element_topology = get_bulk().bucket(element).topology();
119 return element_topology.side_topology(side_ordinal);
120 }
121
122 stk::mesh::EntityVector get_permuted_nodes(stk::topology side_topology, const stk::mesh::EntityVector &element_side_nodes, int other_proc_id, unsigned permutation_other_proc)
123 {
124 stk::mesh::EntityVector permuted_element_side_nodes(side_topology.num_nodes());
125 unsigned permutation = get_bulk().parallel_rank()>other_proc_id ? permutation_other_proc : 0;
126 side_topology.permutation_nodes(element_side_nodes.data(), permutation, permuted_element_side_nodes.data());
127 return permuted_element_side_nodes;
128 }
129
130 void test_parallel_info(const stk::mesh::impl::ParallelInfo &p_info)
131 {
132 EXPECT_EQ(1-get_bulk().parallel_rank(), p_info.get_proc_rank_of_neighbor());
133 EXPECT_EQ(4, p_info.m_permutation);
134 EXPECT_EQ(stk::topology::HEXAHEDRON_8, p_info.m_remote_element_topology);
135 }
136 };
137
138 TEST_F(FaceCreatorUsingBulkDataFaceSharingTester, twoHexesTwoProcsCreateTwoFacesWithAura)
139 {
140 if(stk::parallel_machine_size(get_comm())==2)
141 {
142 setup_mesh("generated:1x1x2", stk::mesh::BulkData::AUTO_AURA);
143 test_that_one_face_exists_after_both_procs_create_face_on_proc_boundary();
144 }
145 }
146
147 // These two tests demonstrate that if faces are created with a permutation other than 0 then
148 // the graph parallel info is incorrect because it assumes all faces are created with permutation
149 // 0 on the originating element/side. If we can guarantee all faces are created through
150 // declare_element_side, then this issue goes away.
151 TEST_F(FaceCreatorUsingBulkDataFaceSharingTester, testFaceDataUsingElemElemGraphWithAura)
152 {
153 if(stk::parallel_machine_size(get_comm())==2)
154 {
155 setup_mesh("generated:1x1x2", stk::mesh::BulkData::AUTO_AURA);
156 test_that_one_face_exists_after_both_procs_create_face_on_proc_boundary();
157 test_elem_elem_graph_for_face_connection_info();
158 }
159 }
160
161 TEST_F(FaceCreatorUsingBulkDataFaceSharingTester, testFaceDataUsingElemElemGraphWithoutAura)
162 {
163 if(stk::parallel_machine_size(get_comm())==2)
164 {
165 setup_mesh("generated:1x1x2", stk::mesh::BulkData::NO_AUTO_AURA);
166 test_that_one_face_exists_after_both_procs_create_face_on_proc_boundary();
167 test_elem_elem_graph_for_face_connection_info();
168 }
169 }
170
171 }