Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/face_creation/element_graph/BulkDataElementGraphTester.hpp

raw
1 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
2 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
3 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
4 // in this software.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // * Neither the name of NTESS nor the names of its contributors
19 // may be used to endorse or promote products derived from this
20 // software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34 #ifndef bulkdatalementgraphtester_hpp
35 #define bulkdatalementgraphtester_hpp
36
37 #include <vector>
38 #include <algorithm>
39 #include <stdlib.h>
40
41 #include <stk_topology/topology.hpp>
42 #include <stk_mesh/base/BulkData.hpp>
43 #include <stk_mesh/base/MetaData.hpp>
44 #include <stk_mesh/base/Comm.hpp>
45 #include <stk_mesh/base/GetEntities.hpp>
46 #include <stk_mesh/base/FEMHelpers.hpp>
47 #include <stk_mesh/baseImpl/MeshImplUtils.hpp>
48 #include <stk_mesh/base/Field.hpp>
49
50 #include <stk_mesh/base/SkinMesh.hpp>
51 #include <stk_mesh/base/CreateFaces.hpp>
52 #include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp>
53 #include <stk_mesh/baseImpl/elementGraph/ElemElemGraphImpl.hpp>
54
55 #include <stk_util/parallel/Parallel.hpp>
56 #include <stk_util/parallel/ParallelVectorConcat.hpp>
57 #include <stk_util/parallel/ParallelComm.hpp>
58 #include <stk_util/environment/WallTime.hpp>
59 #include <stk_util/environment/memory_util.hpp>
60 #include <stk_util/parallel/CommSparse.hpp>
61 #include <stk_util/util/ReportHandler.hpp>
62
63 #include <stk_io/IossBridge.hpp>
64 #include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker
65
66 #include <stk_unit_test_utils/ioUtils.hpp>
67 #include <stk_unit_test_utils/getOption.h>
68
69 #include "SetupKeyholeMesh.hpp"
70 #include "stk_unit_test_utils/ElemGraphTestUtils.hpp"
71 #include "stk_unit_test_utils/unittestMeshUtils.hpp"
72 #include "stk_unit_test_utils/BuildMesh.hpp"
73
74 #include <stk_mesh/baseImpl/DeletedElementInfo.hpp>
75 #include <stk_unit_test_utils/stk_mesh_fixtures/QuadFixture.hpp> // for QuadFixture
76 #include <stk_unit_test_utils/stk_mesh_fixtures/degenerate_mesh.hpp>
77 #include <stk_unit_test_utils/stk_mesh_fixtures/heterogeneous_mesh.hpp>
78
79 class BulkDataElementGraphTester : public stk::mesh::BulkData
80 {
81 public:
82 BulkDataElementGraphTester(stk::mesh::MetaData &mesh_meta_data, MPI_Comm comm)
83 : stk::mesh::BulkData(std::shared_ptr<stk::mesh::MetaData>(&mesh_meta_data, [](auto /*pointerWeWontDelete*/){}), comm)
84 {
85 }
86
87 BulkDataElementGraphTester(stk::mesh::MetaData &meta, MPI_Comm comm, enum AutomaticAuraOption autoAuraOption)
88 : stk::mesh::BulkData(std::shared_ptr<stk::mesh::MetaData>(&meta, [](auto /*pointerWeWontDelete*/){}), comm, autoAuraOption)
89 {
90 }
91
92 ~BulkDataElementGraphTester()
93 {
94 }
95
96 bool my_internal_modification_end_for_skin_mesh(stk::mesh::EntityRank entity_rank, stk::mesh::ModEndOptimizationFlag opt, stk::mesh::Selector selectedToSkin,
97 const stk::mesh::Selector * only_consider_second_element_from_this_selector = 0)
98 {
99 return this->internal_modification_end_for_skin_mesh(entity_rank, opt, selectedToSkin, only_consider_second_element_from_this_selector);
100 }
101
102 bool my_modification_end_for_entity_creation(const std::vector<stk::mesh::sharing_info>& shared_modified, stk::mesh::ModEndOptimizationFlag opt = stk::mesh::ModEndOptimizationFlag::MOD_END_SORT)
103 {
104 if ( this->in_synchronized_state() ) { return false ; }
105
106 STK_ThrowAssertMsg(stk::mesh::impl::check_for_connected_nodes(*this)==0, "BulkData::modification_end ERROR, all entities with rank higher than node are required to have connected nodes.");
107
108 if (parallel_size() > 1)
109 {
110 stk::mesh::OrdinalVector shared_part, owned_part, empty, scratch1, scratch2;
111 shared_part.push_back(mesh_meta_data().globally_shared_part().mesh_meta_data_ordinal());
112 owned_part.push_back(mesh_meta_data().locally_owned_part().mesh_meta_data_ordinal());
113
114 stk::mesh::EntityVector modified_entities(shared_modified.size());
115 for(size_t i = 0; i < shared_modified.size(); ++i)
116 {
117 stk::mesh::Entity entity = shared_modified[i].m_entity;
118 int sharing_proc = shared_modified[i].m_sharing_proc;
119 entity_comm_map_insert(entity, stk::mesh::EntityCommInfo(stk::mesh::BulkData::SHARED, sharing_proc));
120 int old_owner = parallel_owner_rank(entity);
121 int owning_proc = shared_modified[i].m_owner;
122 if (old_owner != owning_proc)
123 {
124 internal_set_owner(entity, owning_proc);
125 this->internal_change_entity_parts(entity, shared_part /*add*/, owned_part /*remove*/, scratch1, scratch2);
126 }
127 else
128 {
129 this->internal_change_entity_parts(entity, shared_part /*add*/, empty /*remove*/, scratch1, scratch2);
130 }
131 modified_entities[i] = entity;
132 }
133
134 std::sort(modified_entities.begin(), modified_entities.end(), stk::mesh::EntityLess(*this));
135 stk::mesh::EntityVector::iterator iter = std::unique(modified_entities.begin(), modified_entities.end());
136 modified_entities.resize(iter-modified_entities.begin());
137
138 add_comm_list_entries_for_entities( modified_entities );
139
140 stk::mesh::EntityVector entitiesNoLongerShared;
141 internal_resolve_shared_membership(entitiesNoLongerShared);
142
143 if ( is_automatic_aura_on() )
144 {
145 bool connectFacesToPreexistingGhosts = true;
146 resolve_incremental_ghosting_for_entity_creation_or_skin_mesh(mesh_meta_data().side_rank(), mesh_meta_data().universal_part(), connectFacesToPreexistingGhosts);
147 }
148
149 check_mesh_consistency();
150 }
151 else
152 {
153 std::vector<stk::mesh::Entity> modified_entities ;
154 internal_update_sharing_comm_map_and_fill_list_modified_shared_entities_of_rank(mesh_meta_data().side_rank(), modified_entities);
155 }
156
157 this->internal_finish_modification_end(opt);
158
159 return true ;
160 }
161
162 size_t num_entity_keys() const
163 {
164 return m_entity_keys.size();
165 }
166
167 std::vector<uint64_t> my_internal_get_ids_in_use_this_proc_for_locally_owned(stk::topology::rank_t rank) const
168 {
169 return internal_get_ids_in_use(rank);
170 }
171 };
172
173 #endif