10 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 11 #include <Shards_BasicTopologies.hpp> 13 #include <stk_util/parallel/Parallel.hpp> 15 #include <stk_mesh/base/MetaData.hpp> 16 #include <stk_mesh/base/BulkData.hpp> 17 #include <stk_mesh/base/Entity.hpp> 18 #include <stk_mesh/base/BulkModification.hpp> 19 #include <stk_mesh/base/GetEntities.hpp> 20 #include <stk_mesh/base/Selector.hpp> 21 #include <stk_mesh/base/GetBuckets.hpp> 23 #include <stk_mesh/fem/FEMMetaData.hpp> 25 #include <stk_mesh/fixtures/RingFixture.hpp> 32 using stk_classic::mesh::BucketIterator;
34 using stk_classic::mesh::EntityRank;
37 class UnitTestStkMeshBulkModification {
46 void test_bulkdata_not_syncronized();
47 void test_closure_of_non_locally_used_entities();
48 void test_all_local_nodes();
49 void test_all_local_edges();
50 void test_parallel_consistency();
54 m_ring_mesh.m_meta_data.commit();
55 BulkData& bulk_data = m_ring_mesh.m_bulk_data;
58 m_ring_mesh.generate_mesh( );
62 m_ring_mesh.fixup_node_ownership( );
76 const EntityRank NODE_RANK = stk_classic::mesh::fem::FEMMetaData::NODE_RANK;
78 STKUNIT_UNIT_TEST( UnitTestBulkDataNotSyrncronized , testUnit )
80 UnitTestStkMeshBulkModification unit(MPI_COMM_WORLD);
81 unit.test_bulkdata_not_syncronized();
84 STKUNIT_UNIT_TEST( UnitTestClosureOfNonLocallyUsedEntities , testUnit )
86 UnitTestStkMeshBulkModification unit(MPI_COMM_WORLD);
87 unit.test_closure_of_non_locally_used_entities();
90 STKUNIT_UNIT_TEST( UnitTestAllLocalNodes , testUnit )
92 UnitTestStkMeshBulkModification unit(MPI_COMM_WORLD);
93 unit.test_all_local_nodes();
96 STKUNIT_UNIT_TEST( UnitTestAllLocalEdges , testUnit )
98 UnitTestStkMeshBulkModification unit(MPI_COMM_WORLD);
99 unit.test_all_local_edges();
102 STKUNIT_UNIT_TEST( UnitTestParallelConsistency , testUnit )
104 UnitTestStkMeshBulkModification unit(MPI_COMM_WORLD);
105 unit.test_parallel_consistency();
110 void UnitTestStkMeshBulkModification::test_bulkdata_not_syncronized()
112 BulkData& bulk_data = initialize_ring_fixture();
116 std::vector< Entity *> entities;
117 std::vector< Entity *> entities_closure;
118 STKUNIT_ASSERT_THROW(stk_classic::mesh::find_closure(bulk_data, entities, entities_closure), std::runtime_error);
121 void UnitTestStkMeshBulkModification::test_closure_of_non_locally_used_entities()
123 BulkData& bulk_data = initialize_ring_fixture();
127 std::vector< Entity* > ghost_receive ;
131 if (!ghost_receive.empty()) {
132 std::vector< Entity *> entities;
133 std::vector< Entity *> entities_closure;
135 entities.push_back(ghost_receive.front());
137 STKUNIT_ASSERT_THROW(stk_classic::mesh::find_closure(bulk_data, entities, entities_closure), std::runtime_error);
141 void UnitTestStkMeshBulkModification::test_all_local_nodes()
143 BulkData& bulk_data = initialize_ring_fixture();
146 std::vector< Entity *> entities;
147 std::vector< Entity *> entities_closure;
148 find_closure(bulk_data, entities, entities_closure);
151 STKUNIT_EXPECT_TRUE(entities_closure.empty());
160 const std::vector<Bucket*>& node_buckets = bulk_data.
buckets(NODE_RANK);
161 std::vector<Bucket*> buckets;
165 std::vector< Entity *> universal_entities;
166 for (std::vector<Bucket*>::iterator itr = buckets.begin();
167 itr != buckets.end(); ++itr) {
169 for (BucketIterator bitr = b.
begin(); bitr != b.
end(); ++bitr) {
170 universal_entities.push_back(&(*bitr));
177 std::vector<Entity*>::iterator new_end = std::unique(universal_entities.begin(), universal_entities.end(), stk_classic::mesh::EntityEqual());
178 universal_entities.erase(new_end, universal_entities.end());
182 m_ring_mesh.m_meta_data.locally_owned_part() |
183 m_ring_mesh.m_meta_data.globally_shared_part();
188 std::vector< Entity *> entities;
189 for (std::vector<Bucket*>::iterator itr = buckets.begin();
190 itr != buckets.end(); ++itr) {
192 for (BucketIterator bitr = b.
begin(); bitr != b.
end(); ++bitr) {
193 entities.push_back(&(*bitr));
198 std::vector< Entity *> entities_closure;
199 stk_classic::mesh::find_closure(bulk_data, entities, entities_closure);
205 STKUNIT_ASSERT_TRUE(universal_entities.size() == entities_closure.size());
206 stk_classic::mesh::EntityEqual ee;
207 for (
size_t i = 0; i < entities_closure.size(); ++i) {
208 STKUNIT_EXPECT_TRUE(ee(universal_entities[i], entities_closure[i]));
213 void UnitTestStkMeshBulkModification::test_all_local_edges()
215 BulkData& bulk_data = initialize_ring_fixture();
216 const stk_classic::mesh::EntityRank element_rank = m_ring_mesh.m_meta_data.element_rank();
222 const std::vector<Bucket*>& node_buckets = bulk_data.
buckets(NODE_RANK);
223 const std::vector<Bucket*>& edge_buckets = bulk_data.
buckets(element_rank);
224 std::vector<Bucket*> buckets;
229 std::vector< Entity *> universal_entities;
230 for (std::vector<Bucket*>::iterator itr = buckets.begin();
231 itr != buckets.end(); ++itr) {
233 for (BucketIterator bitr = b.
begin(); bitr != b.
end(); ++bitr) {
234 universal_entities.push_back(&(*bitr));
242 for (std::vector<Bucket*>::iterator itr = buckets.begin();
243 itr != buckets.end(); ++itr) {
245 for (BucketIterator bitr = b.
begin(); bitr != b.
end(); ++bitr) {
246 universal_entities.push_back(&(*bitr));
254 std::vector<Entity*>::iterator new_end = std::unique(universal_entities.begin(), universal_entities.end(), stk_classic::mesh::EntityEqual());
255 universal_entities.erase(new_end, universal_entities.end());
259 m_ring_mesh.m_meta_data.locally_owned_part() |
260 m_ring_mesh.m_meta_data.globally_shared_part();
265 std::vector< Entity *> entities;
266 for (std::vector<Bucket*>::iterator itr = buckets.begin();
267 itr != buckets.end(); ++itr) {
269 for (BucketIterator bitr = b.
begin(); bitr != b.
end(); ++bitr) {
270 entities.push_back(&(*bitr));
275 std::vector< Entity *> entities_closure;
276 stk_classic::mesh::find_closure(bulk_data, entities, entities_closure);
283 STKUNIT_ASSERT_TRUE(universal_entities.size() == entities_closure.size());
284 stk_classic::mesh::EntityEqual ee;
285 for (
size_t i = 0; i < entities_closure.size(); ++i) {
286 STKUNIT_EXPECT_TRUE(ee(universal_entities[i], entities_closure[i]));
291 void UnitTestStkMeshBulkModification::test_parallel_consistency()
293 BulkData& bulk_data = initialize_ring_fixture();
295 stk_classic::CommBroadcast all(bulk_data.
parallel(), 0);
297 std::vector< Entity *> entities;
298 std::vector< Entity *> entities_closure;
303 const std::vector<Bucket*>& node_buckets = bulk_data.
buckets(NODE_RANK);
306 m_ring_mesh.m_meta_data.locally_owned_part() |
307 m_ring_mesh.m_meta_data.globally_shared_part();
309 std::vector<Bucket*> buckets;
312 for (std::vector<Bucket*>::iterator itr = buckets.begin();
313 itr != buckets.end(); ++itr) {
315 for (BucketIterator bitr = b.
begin(); bitr != b.
end(); ++bitr) {
316 entities.push_back(&(*bitr));
322 stk_classic::mesh::find_closure(bulk_data, entities, entities_closure);
328 for (std::vector<Entity*>::const_iterator
329 ep = entities.begin() ; ep != entities.end() ; ++ep ) {
333 all.allocate_buffer();
336 for (std::vector<Entity*>::const_iterator
337 ep = entities.begin() ; ep != entities.end() ; ++ep ) {
346 stk_classic::CommBuffer& buf = all.recv_buffer();
348 while ( buf.remaining() ) {
354 entities.push_back(e);
360 std::vector<Entity*>::iterator new_end = std::unique(entities.begin(), entities.end(), stk_classic::mesh::EntityEqual());
361 entities.erase(new_end, entities.end());
366 STKUNIT_ASSERT_TRUE(entities.size() == entities_closure.size());
367 stk_classic::mesh::EntityEqual ee;
368 for (
size_t i = 0; i < entities_closure.size(); ++i) {
369 STKUNIT_EXPECT_TRUE(ee(entities[i], entities_closure[i]));
Comparison operator for entities compares the entities' keys.
Data for ghosting mesh entities.
This is a class for selecting buckets based on a set of meshparts and set logic.
const std::vector< Bucket * > & buckets(EntityRank rank) const
Query all buckets of a given entity rank.
Ghosting & shared_aura() const
Query the shared-entity aura. Is likely to be stale if ownership or sharing has changed and the 'modi...
Entity * get_entity(EntityRank entity_rank, EntityId entity_id) const
Get entity with a given key.
Integer type for the entity keys, which is an encoding of the entity type and entity identifier...
An application-defined subset of a problem domain.
unsigned parallel_machine_rank(ParallelMachine parallel_machine)
Member function parallel_machine_rank ...
ParallelMachine parallel() const
The parallel machine.
void receive_list(std::vector< Entity * > &) const
Entities ghosted on this processor from the owner.
bool modification_end()
Parallel synchronization of modifications and transition to the guaranteed parallel consistent state...
bool modification_begin()
Begin a modification phase during which the mesh bulk data could become parallel inconsistent. This is a parallel synchronous call. The first time this method is called the mesh meta data is verified to be committed and parallel consistent. An exception is thrown if this verification fails.
iterator begin() const
Beginning of the bucket.
iterator end() const
End of the bucket.
unsigned parallel_machine_size(ParallelMachine parallel_machine)
Member function parallel_machine_size ...
Manager for an integrated collection of entities, entity relations, and buckets of field data...
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
AllSelectedBucketsRange get_buckets(const Selector &selector, const BulkData &mesh)
A container for the field data of a homogeneous collection of entities.