Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestCEOME.cpp

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
35 #include "Setup8Quad4ProcMesh.hpp"
36 #include "UnitTestCEO2Elem.hpp"
37 #include "UnitTestCEO3Elem.hpp"
38 #include "UnitTestCEO4ElemEdge.hpp"
39 #include "UnitTestCEO4ElemRotate.hpp"
40 #include "UnitTestCEO8Elem.hpp"
41 #include "UnitTestCEOCommonUtils.hpp"
42 #include "UnitTestRingFixture.hpp" // for test_shift_ring
43 #include "stk_io/StkMeshIoBroker.hpp"
44 #include "stk_mesh/base/Bucket.hpp" // for Bucket, has_superset
45 #include "stk_mesh/base/Entity.hpp" // for Entity
46 #include "stk_mesh/base/EntityKey.hpp" // for stk::mesh::EntityKey
47 #include "stk_mesh/base/Field.hpp" // for Field
48 #include "stk_mesh/base/FieldBase.hpp" // for field_data, etc
49 #include "stk_mesh/base/Ghosting.hpp" // for Ghosting
50 #include "stk_mesh/base/MetaData.hpp" // for MetaData, entity_rank_names, etc
51 #include "stk_mesh/base/Part.hpp" // for Part
52 #include "stk_mesh/base/Relation.hpp"
53 #include "stk_mesh/base/Selector.hpp" // for Selector, operator|
54 #include "stk_mesh/base/Types.hpp" // for EntityProc, EntityVector, etc
55 #include "stk_mesh/baseImpl/MeshImplUtils.hpp"
56 #include "stk_topology/topology.hpp" // for topology, etc
57 #include "stk_unit_test_utils/stk_mesh_fixtures/BoxFixture.hpp" // for BoxFixture
58 #include "stk_unit_test_utils/stk_mesh_fixtures/QuadFixture.hpp" // for QuadFixture
59 #include "stk_unit_test_utils/stk_mesh_fixtures/RingFixture.hpp" // for RingFixture
60 #include "stk_util/util/PairIter.hpp" // for PairIter
61 #include <algorithm> // for sort
62 #include <exception> // for exception
63 #include <gtest/gtest.h>
64 #include <iostream> // for ostringstream, etc
65 #include <iterator> // for distance
66 #include <map> // for _Rb_tree_const_iterator, etc
67 #include <stddef.h> // for size_t
68 #include <stdexcept> // for logic_error, runtime_error
69 #include <stdlib.h> // for exit
70 #include <stk_mesh/base/BulkData.hpp> // for BulkData, etc
71 #include <stk_mesh/base/Comm.hpp>
72 #include <stk_mesh/base/FieldParallel.hpp> // for communicate_field_data, etc
73 #include <stk_mesh/base/GetEntities.hpp> // for count_entities, etc
74 #include <stk_unit_test_utils/BulkDataTester.hpp>
75 #include <stk_util/environment/WallTime.hpp>
76 #include <stk_util/environment/memory_util.hpp>
77 #include <stk_util/parallel/Parallel.hpp> // for ParallelMachine, etc
78 #include <string> // for string, basic_string, etc
79 #include <utility> // for pair
80 #include <vector> // for vector, etc
81
82 namespace stk
83 {
84 namespace mesh
85 {
86 class FieldBase;
87 }
88 }
89
90 using stk::mesh::Part;
91 using stk::mesh::MetaData;
92 using stk::mesh::BulkData;
93 using stk::mesh::Selector;
94 using stk::mesh::PartVector;
95 using stk::mesh::PairIterRelation;
96 using stk::mesh::EntityProc;
97 using stk::mesh::Entity;
98 using stk::mesh::EntityId;
99 using stk::mesh::EntityKey;
100 using stk::mesh::EntityVector;
101 using stk::mesh::EntityRank;
102 using stk::mesh::fixtures::RingFixture;
103 using stk::mesh::fixtures::BoxFixture;
104
105 void printMemoryStats(MPI_Comm comm)
106 {
107 size_t maxHwm = 0, minHwm = 0, avgHwm = 0;
108 stk::get_memory_high_water_mark_across_processors(comm, maxHwm, minHwm, avgHwm);
109
110 int proc=-1;
111 MPI_Comm_rank(comm, &proc);
112
113 int numProcs=0;
114 MPI_Comm_size(comm, &numProcs);
115
116 if (proc == 0)
117 {
118 std::ostringstream os;
119 const double bytesInMegabyte = 1024*1024;
120 os << std::setw(6) << std::fixed << std::setprecision(1) << "Max HWM: "<<double(maxHwm)/double(bytesInMegabyte)
121 <<", Min HWM: "<<double(minHwm)/double(bytesInMegabyte)<<", Avg HWM: "<<avgHwm/bytesInMegabyte<<std::endl;
122
123 std::cerr << os.str();
124 }
125 }
126
127 void printPeformanceStats(double elapsedTime, MPI_Comm comm)
128 {
129 size_t maxHwm = 0, minHwm = 0, avgHwm = 0;
130 stk::get_memory_high_water_mark_across_processors(comm, maxHwm, minHwm, avgHwm);
131
132 int proc=-1;
133 MPI_Comm_rank(comm, &proc);
134
135 int numProcs=0;
136 MPI_Comm_size(comm, &numProcs);
137
138 double minTime = 0, maxTime = 0, avgTime = 0;
139 MPI_Allreduce(&elapsedTime, &maxTime, 1, MPI_DOUBLE, MPI_MAX, comm);
140 MPI_Allreduce(&elapsedTime, &minTime, 1, MPI_DOUBLE, MPI_MIN, comm);
141 double elapsedTimeDivided = elapsedTime/numProcs;
142 MPI_Allreduce(&elapsedTimeDivided, &avgTime, 1, MPI_DOUBLE, MPI_SUM, comm);
143
144 if (proc == 0)
145 {
146 std::ostringstream os;
147 const double bytesInMegabyte = 1024*1024;
148 os << "Max time: " << maxTime << ", Min time: " << minTime << ", Avg time: " << avgTime << std::endl;
149 os << std::setw(6) << std::fixed << std::setprecision(1) << "Max HWM: "<<double(maxHwm)/double(bytesInMegabyte)
150 <<", Min HWM: "<<double(minHwm)/double(bytesInMegabyte)<<", Avg HWM: "<<avgHwm/bytesInMegabyte<<std::endl;
151 std::cerr << os.str();
152 }
153 }
154
155 namespace
156 {
157 //==============================================================================
158
159 void updateSharingAndPrintStats(stk::unit_test_util::BulkDataTester &bulk)
160 {
161 printMemoryStats(bulk.parallel());
162 double startTime = stk::wall_time();
163
164 bulk.my_update_sharing_after_change_entity_owner();
165 bulk.my_internal_modification_end_for_change_entity_owner(stk::mesh::impl::MeshModification::MOD_END_SORT);
166
167 double elapsedTime = stk::wall_time() - startTime;
168 printPeformanceStats(elapsedTime, bulk.parallel());
169
170 bulk.modification_begin();
171 bulk.my_internal_modification_end_for_change_entity_owner(stk::mesh::impl::MeshModification::MOD_END_SORT);
172 }
173
174 TEST(CEOME, change_entity_owner_2Elem2ProcMove)
175 {
176 stk::ParallelMachine pm = MPI_COMM_WORLD;
177 const int p_rank = stk::parallel_machine_rank(pm);
178 const int p_size = stk::parallel_machine_size(pm);
179
180 if(p_size != 2)
181 {
182 return;
183 }
184
185 const int spatial_dimension = 2;
186 stk::mesh::MetaData meta(spatial_dimension);
187 stk::unit_test_util::BulkDataTester bulk(meta, pm);
188
189 stk::mesh::EntityVector elems;
190 CEOUtils::fillMeshfor2Elem2ProcMoveAndTest(bulk, meta, elems);
191
192 stk::mesh::EntityProcVec entity_procs;
193 if(p_rank == 0)
194 {
195 entity_procs.push_back(stk::mesh::EntityProc(elems[1], 1));
196 entity_procs.push_back(stk::mesh::EntityProc(bulk.get_entity(stk::topology::NODE_RANK, 4), 1));
197 entity_procs.push_back(stk::mesh::EntityProc(bulk.get_entity(stk::topology::NODE_RANK, 5), 1));
198 entity_procs.push_back(stk::mesh::EntityProc(bulk.get_entity(stk::topology::NODE_RANK, 6), 1));
199 }
200
201 bulk.modification_begin("change_entity_owner");
202 bulk.my_internal_change_entity_owner(entity_procs);
203
204 CEOUtils::checkStatesAfterCEO_2Elem2ProcMove(bulk);
205
206 ////////////////////////////////////////////////////////////////////////////
207
208 updateSharingAndPrintStats(bulk);
209
210 ////////////////////////////////////////////////////////////////////////////
211
212 CEOUtils::checkStatesAfterCEOME_2Elem2ProcMove(bulk);
213 }
214
215 TEST(CEOME, change_entity_owner_2Elem2ProcFlip)
216 {
217 stk::ParallelMachine pm = MPI_COMM_WORLD;
218 const int p_rank = stk::parallel_machine_rank(pm);
219 const int p_size = stk::parallel_machine_size(pm);
220
221 if(p_size != 2)
222 {
223 return;
224 }
225 const int spatial_dimension = 2;
226 stk::mesh::MetaData meta(spatial_dimension);
227 stk::unit_test_util::BulkDataTester mesh(meta, pm);
228
229 CEOUtils::fillMeshfor2Elem2ProcFlipAndTest(mesh, meta);
230
231 //okay now flip
232 // 1/0---4/0---5/1 1/1---4/0---5/0
233 // | | | | | |
234 // | 1/0 | 2/1 | => | 1/1 | 2/0 |
235 // | | | | | |
236 // 2/0---3/0---6/1 2/1---3/0---6/0
237
238 stk::mesh::EntityProcVec entity_procs_flip;
239 if(p_rank == 0)
240 {
241 entity_procs_flip.push_back(stk::mesh::EntityProc(mesh.get_entity(stk::topology::ELEMENT_RANK, 1), 1));
242 entity_procs_flip.push_back(stk::mesh::EntityProc(mesh.get_entity(stk::topology::NODE_RANK, 1), 1));
243 entity_procs_flip.push_back(stk::mesh::EntityProc(mesh.get_entity(stk::topology::NODE_RANK, 2), 1));
244 }
245 else
246 {
247 entity_procs_flip.push_back(stk::mesh::EntityProc(mesh.get_entity(stk::topology::ELEMENT_RANK, 2), 0));
248 entity_procs_flip.push_back(stk::mesh::EntityProc(mesh.get_entity(stk::topology::NODE_RANK, 5), 0));
249 entity_procs_flip.push_back(stk::mesh::EntityProc(mesh.get_entity(stk::topology::NODE_RANK, 6), 0));
250 }
251
252 mesh.modification_begin("change_entity_owner");
253
254 mesh.my_internal_change_entity_owner(entity_procs_flip);
255
256 CEOUtils::checkStatesAfterCEO_2Elem2ProcFlip(mesh);
257
258 ////////////////////////////////////////////////////////////////////////////
259
260 updateSharingAndPrintStats(mesh);
261
262 ////////////////////////////////////////////////////////////////////////////
263
264 CEOUtils::checkStatesAfterCEOME_2Elem2ProcFlip(mesh);
265 }
266
267 TEST(CEOME, change_entity_owner_3Elem2ProcMoveRight)
268 {
269 // id/owner_proc
270 //
271 // 1/0---3/0---5/0---7/1 1/0---3/0---5/1---7/1
272 // | | | | | | | |
273 // | 1/0 | 2/0 | 3/1 | => | 1/0 | 2/1 | 3/1 |
274 // | | | | | | | |
275 // 2/0---4/0---6/0---8/1 2/0---4/0---6/1---8/1
276
277 stk::ParallelMachine pm = MPI_COMM_WORLD;
278
279 // Set up meta and bulk data
280 const unsigned spatial_dim = 2;
281 MetaData meta_data(spatial_dim);
282 stk::unit_test_util::BulkDataTester mesh(meta_data, pm);
283 int p_rank = mesh.parallel_rank();
284 int p_size = mesh.parallel_size();
285
286 if(p_size != 2)
287 {
288 return;
289 }
290
291 EntityVector nodes;
292 EntityVector elements;
293
294 CEOUtils::fillMeshfor3Elem2ProcMoveRightAndTest(mesh, meta_data, nodes, elements);
295
296 std::vector<EntityProc> change;
297 if(p_rank == 0)
298 {
299 change.push_back(EntityProc(elements[1], 1));
300 change.push_back(EntityProc(nodes[4], 1));
301 change.push_back(EntityProc(nodes[5], 1));
302 }
303
304 mesh.modification_begin("change_entity_owner");
305
306 mesh.my_internal_change_entity_owner(change);
307
308 CEOUtils::checkStatesAfterCEO_3Elem2ProcMoveRight(mesh);
309
310 ////////////////////////////////////////////////////////////////////////////
311
312 updateSharingAndPrintStats(mesh);
313
314 ////////////////////////////////////////////////////////////////////////////
315
316 CEOUtils::checkStatesAfterCEOME_3Elem2ProcMoveRight(mesh);
317 }
318
319 TEST(CEOME, change_entity_owner_3Elem2ProcMoveLeft)
320 {
321 // id/owner_proc
322 //
323 // 1/0---3/0---5/1---7/1 1/0---3/0---5/0---7/1
324 // | | | | | | | |
325 // | 1/0 | 2/1 | 3/1 | => | 1/0 | 2/0 | 3/1 |
326 // | | | | | | | |
327 // 2/0---4/0---6/1---8/1 2/0---4/0---6/0---8/1
328
329 stk::ParallelMachine pm = MPI_COMM_WORLD;
330
331 // Set up meta and bulk data
332 const unsigned spatial_dim = 2;
333 MetaData meta_data(spatial_dim);
334 stk::unit_test_util::BulkDataTester mesh(meta_data, pm);
335 int p_rank = mesh.parallel_rank();
336 int p_size = mesh.parallel_size();
337
338 if(p_size != 2)
339 {
340 return;
341 }
342
343 EntityVector nodes;
344 EntityVector elements;
345
346 CEOUtils::fillMeshfor3Elem2ProcMoveLeftAndTest(mesh, meta_data, nodes, elements);
347
348 std::vector<EntityProc> change;
349 if(p_rank == 1)
350 {
351 change.push_back(EntityProc(elements[0], 0));
352 change.push_back(EntityProc(nodes[2], 0));
353 change.push_back(EntityProc(nodes[3], 0));
354 }
355
356 mesh.modification_begin("change_entity_owner");
357
358 mesh.my_internal_change_entity_owner(change);
359
360 CEOUtils::checkStatesAfterCEO_3Elem2ProcMoveLeft(mesh);
361
362 ////////////////////////////////////////////////////////////////////////////
363
364 updateSharingAndPrintStats(mesh);
365
366 ////////////////////////////////////////////////////////////////////////////
367
368 CEOUtils::checkStatesAfterCEOME_3Elem2ProcMoveLeft(mesh);
369 }
370
371 TEST(CEOME, TwoElemGiveAllEntitiesToOneProcAndCheckParts)
372 {
373 stk::ParallelMachine pm = MPI_COMM_WORLD;
374
375 // Set up meta and bulk data
376 const unsigned spatial_dim = 2;
377 MetaData meta(spatial_dim);
378 stk::unit_test_util::BulkDataTester mesh(meta, pm);
379 int p_rank = mesh.parallel_rank();
380 int p_size = mesh.parallel_size();
381
382 if(p_size == 2)
383 {
384 CEOUtils::fillMeshfor2Elem2ProcFlipAndTest(mesh, meta);
385
386 stk::mesh::EntityProcVec entitiesToChangeOwner;
387 if(p_rank == 1)
388 {
389 entitiesToChangeOwner.push_back(stk::mesh::EntityProc(mesh.get_entity(stk::topology::ELEMENT_RANK, 2), 0));
390 entitiesToChangeOwner.push_back(stk::mesh::EntityProc(mesh.get_entity(stk::topology::NODE_RANK, 5), 0));
391 entitiesToChangeOwner.push_back(stk::mesh::EntityProc(mesh.get_entity(stk::topology::NODE_RANK, 6), 0));
392 }
393
394 stk::mesh::Part * universal_part = &meta.universal_part();
395 stk::mesh::Part * owned_part = &meta.locally_owned_part();
396 stk::mesh::Part * aura_part = &meta.aura_part();
397 stk::mesh::Part * elem_part = meta.get_part("elem_part");
398 stk::mesh::Part * topo_part = &meta.get_topology_root_part(stk::topology::QUAD_4_2D);
399 if(p_rank == 0)
400 {
401 EXPECT_TRUE(CEOUtils::check_parts(mesh, stk::mesh::EntityKey(stk::topology::ELEMENT_RANK, 2), universal_part, aura_part, elem_part, topo_part));
402 EXPECT_TRUE(CEOUtils::check_parts(mesh, stk::mesh::EntityKey(stk::topology::NODE_RANK, 6), universal_part, aura_part, elem_part, topo_part));
403 }
404
405 mesh.change_entity_owner(entitiesToChangeOwner);
406
407 if(p_rank == 0)
408 {
409 EXPECT_TRUE(CEOUtils::check_parts(mesh, stk::mesh::EntityKey(stk::topology::ELEMENT_RANK, 2), universal_part, owned_part, elem_part, topo_part));
410 EXPECT_TRUE(CEOUtils::check_parts(mesh, stk::mesh::EntityKey(stk::topology::NODE_RANK, 6), universal_part, owned_part, elem_part, topo_part));
411 }
412 }
413 }
414
415 TEST(CEOME, change_entity_owner_4Elem4ProcEdge)
416 {
417 // This unit-test is designed to test the conditions that resulted
418 // in the difficult-to-fix rebalance use-case bug. Specifically,
419 // it will test the changing-of-ownership of a shared edge to a proc that
420 // either ghosted it or did not know about it.
421 //
422 // id/proc id/proc
423 // 1/0---3/0---5/1---7/2---9/3 1/0---3/0---5/1---7/0---9/3
424 // | | | || | | | | || |
425 // | 1/0 | 2/1 | 3/2|| 4/3 | | 1/0 | 2/1 | 3/0|| 4/3 |
426 // | | | || | | | | || |
427 // 2/0---4/0---6/1---8/2---10/3 2/0---4/0---6/1---8/0---10/3
428 // this edge moves to p0 --^
429 // element 3 moves to proc 0.
430 // nodes 7&8 move to proc 0.
431 // proc 2 forgets everything.
432 //
433 // To test this, we use the mesh above, with each elem going on a separate
434 // proc, one elem per proc. We will take the edge shared by the last
435 // two (rightmost) elements and change the ownership to proc 0.
436
437 stk::ParallelMachine pm = MPI_COMM_WORLD;
438
439 // Set up meta and bulk data
440 const unsigned spatial_dim = 2;
441 MetaData meta_data(spatial_dim);
442 stk::unit_test_util::BulkDataTester mesh(meta_data, pm);
443 int p_rank = mesh.parallel_rank();
444 int p_size = mesh.parallel_size();
445
446 if(p_size != 4)
447 {
448 return;
449 }
450
451 stk::mesh::EntityKey elem_key_chg_own;
452 CEOUtils::fillMeshfor4Elem4ProcEdgeAndTest(mesh, meta_data, elem_key_chg_own);
453
454 if (p_rank == 1 || p_rank == 2) {
455 // Fill elem_field data on nodes 5 and 6 with data.
456 Entity node5 = mesh.get_entity(stk::topology::NODE_RANK,5);
457 Entity node6 = mesh.get_entity(stk::topology::NODE_RANK,6);
458 stk::mesh::FieldBase* elem_field = meta_data.get_field(stk::topology::NODE_RANK, "elem_field");
459 double * elem_field_data_node5 = static_cast<double*>(stk::mesh::field_data(*elem_field,node5));
460 *elem_field_data_node5 = 5.0;
461 double * elem_field_data_node6 = static_cast<double*>(stk::mesh::field_data(*elem_field,node6));
462 *elem_field_data_node6 = 6.0;
463 }
464
465 std::vector<EntityProc> change;
466 if(p_rank == 2)
467 {
468 // Change ownership of changing elem and all entities in it's closure that
469 // we own to proc 0.
470 // Inspecting the ascii-art in the above mesh setup function reveals that
471 // P2 doesn't own nodes 5 and 6, so the field-data for those won't be sent
472 // to P0.
473
474 Entity changing_elem = mesh.get_entity(elem_key_chg_own);
475 ASSERT_TRUE( mesh.is_valid(changing_elem));
476 EntityProc eproc(changing_elem, 0 /*new owner*/);
477 change.push_back(eproc);
478
479 const stk::mesh::EntityRank end_rank = static_cast<stk::mesh::EntityRank>(mesh.mesh_meta_data().entity_rank_count());
480 for(stk::mesh::EntityRank irank = stk::topology::BEGIN_RANK; irank < end_rank; ++irank)
481 {
482 stk::mesh::Entity const *to_i = mesh.begin(changing_elem, irank);
483 stk::mesh::Entity const *to_e = mesh.end(changing_elem, irank);
484 for (; to_i != to_e; ++to_i)
485 {
486 if (mesh.parallel_owner_rank(*to_i) == p_rank)
487 {
488 EntityProc eproc_new(*to_i, 0 /*new owner*/);
489 change.push_back(eproc_new);
490 }
491 }
492 }
493 }
494
495 stk::mesh::Entity node = mesh.get_entity(stk::topology::NODE_RANK, 5);
496 EXPECT_TRUE(mesh.is_valid(node)) << " is not valid on processor " << p_rank;
497
498 mesh.modification_begin("change_entity_owner");
499
500 mesh.my_internal_change_entity_owner(change);
501
502 CEOUtils::checkStatesAfterCEO_4Elem4ProcEdge(mesh);
503
504 if (p_rank == 1 || p_rank == 0) {
505 Entity node5 = mesh.get_entity(stk::topology::NODE_RANK,5);
506 Entity node6 = mesh.get_entity(stk::topology::NODE_RANK,6);
507 stk::mesh::FieldBase* elem_field = meta_data.get_field(stk::topology::NODE_RANK, "elem_field");
508 double * elem_field_data_node5 = static_cast<double*>(stk::mesh::field_data(*elem_field,node5));
509 const double expectedNode5Data = 5.0;
510 EXPECT_EQ( expectedNode5Data, *elem_field_data_node5 );
511 double * elem_field_data_node6 = static_cast<double*>(stk::mesh::field_data(*elem_field,node6));
512 const double expectedNode6Data = 6.0;
513 EXPECT_EQ( expectedNode6Data, *elem_field_data_node6 );
514 }
515
516 ////////////////////////////////////////////////////////////////////////////
517
518 updateSharingAndPrintStats(mesh);
519
520 ////////////////////////////////////////////////////////////////////////////
521
522 CEOUtils::checkStatesAfterCEOME_4Elem4ProcEdge(mesh);
523
524 if (p_rank == 1 || p_rank == 0) {
525 Entity node5 = mesh.get_entity(stk::topology::NODE_RANK,5);
526 Entity node6 = mesh.get_entity(stk::topology::NODE_RANK,6);
527 stk::mesh::FieldBase* elem_field = meta_data.get_field(stk::topology::NODE_RANK, "elem_field");
528 double * elem_field_data_node5 = static_cast<double*>(stk::mesh::field_data(*elem_field,node5));
529 const double expectedNode5Data = 5.0;
530 EXPECT_EQ( expectedNode5Data, *elem_field_data_node5 );
531 double * elem_field_data_node6 = static_cast<double*>(stk::mesh::field_data(*elem_field,node6));
532 const double expectedNode6Data = 6.0;
533 EXPECT_EQ( expectedNode6Data, *elem_field_data_node6 );
534 }
535
536 }
537
538 TEST(CEOME, change_entity_owner_8Elem4ProcMoveTop)
539 {
540 //
541 // id/proc id/proc
542 // 11/0--12/0--13/1--14/2--15/3 11/0--12/0--13/3--14/0--15/3
543 // | | | | | | | | | |
544 // | 5/0 | 6/1 | 7/2 | 8/3 | | 5/0 | 6/3 | 7/0 | 8/3 |
545 // | | | | | | | | | |
546 // 6/0---7/0---8/1---9/2--10/3 --> 6/0---7/0---8/3---9/0--10/3
547 // | | | | | | | | | |
548 // | 1/0 | 2/1 | 3/2 | 4/3 | | 1/0 | 2/1 | 3/2 | 4/3 |
549 // | | | | | | | | | |
550 // 1/0---2/0---3/1---4/2---5/3 1/0---2/0---3/1---4/2---5/3
551 //
552 // This test moves ownership of elements 6 and 7 (as well as their locally-owned
553 // nodes) to procs 3 and 0, respectively.
554 //
555
556 stk::ParallelMachine pm = MPI_COMM_WORLD;
557 int numProcs = stk::parallel_machine_size(pm);
558 if(numProcs != 4)
559 {
560 return;
561 }
562
563 unsigned spatialDim = 2;
564 stk::mesh::MetaData meta(spatialDim);
565 stk::unit_test_util::BulkDataTester mesh(meta, pm);
566
567 CEOUtils::fillMeshfor8Elem4ProcMoveTopAndTest(mesh, meta);
568
569 std::vector<stk::mesh::EntityProc> entities_to_move;
570 if(mesh.parallel_rank() == 1)
571 {
572 stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 6);
573 int dest_proc = 3;
574 entities_to_move.push_back(stk::mesh::EntityProc(elem, dest_proc));
575 CEOUtils::add_nodes_to_move(mesh, elem, dest_proc, entities_to_move);
576 }
577 if(mesh.parallel_rank() == 2)
578 {
579 stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 7);
580 int dest_proc = 0;
581 entities_to_move.push_back(stk::mesh::EntityProc(elem, dest_proc));
582 CEOUtils::add_nodes_to_move(mesh, elem, dest_proc, entities_to_move);
583 }
584
585 mesh.modification_begin("change_entity_owner");
586
587 mesh.my_internal_change_entity_owner(entities_to_move);
588
589 CEOUtils::checkStatesAfterCEO_8Elem4ProcMoveTop(mesh);
590
591 ////////////////////////////////////////////////////////////////////////////
592
593 updateSharingAndPrintStats(mesh);
594
595 ////////////////////////////////////////////////////////////////////////////
596
597 CEOUtils::checkStatesAfterCEOME_8Elem4ProcMoveTop(mesh);
598 }
599
600 TEST(CEOME, change_entity_owner_4Elem4ProcRotate)
601 {
602 //
603 // id/proc id/proc
604 // 7/3---8/2---9/2 7/2---8/1---9/1
605 // | | | | | |
606 // | 4/3 | 3/2 | | 4/2 | 3/1 |
607 // | | | | | |
608 // 4/0---5/0---6/1 --> 4/3---5/3---6/0
609 // | | | | | |
610 // | 1/0 | 2/1 | | 1/3 | 2/0 |
611 // | | | | | |
612 // 1/0---2/0---3/1 1/3---2/3---3/0
613
614 stk::ParallelMachine pm = MPI_COMM_WORLD;
615 int numProcs = stk::parallel_machine_size(pm);
616 if(numProcs != 4)
617 {
618 return;
619 }
620
621 unsigned spatialDim = 2;
622 stk::mesh::MetaData meta(spatialDim);
623 stk::unit_test_util::BulkDataTester mesh(meta, pm);
624 const int p_rank = mesh.parallel_rank();
625 CEOUtils::fillMeshfor4Elem4ProcRotateAndTest(mesh, meta);
626
627 std::vector<stk::mesh::EntityProc> entities_to_move;
628 if(p_rank == 0)
629 {
630 stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 1);
631 int dest_proc = 3;
632 entities_to_move.push_back(stk::mesh::EntityProc(elem, dest_proc));
633 CEOUtils::add_nodes_to_move(mesh, elem, dest_proc, entities_to_move);
634 }
635 else if(p_rank == 1)
636 {
637 stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 2);
638 int dest_proc = 0;
639 entities_to_move.push_back(stk::mesh::EntityProc(elem, dest_proc));
640 CEOUtils::add_nodes_to_move(mesh, elem, dest_proc, entities_to_move);
641 }
642 else if(p_rank == 2)
643 {
644 stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 3);
645 int dest_proc = 1;
646 entities_to_move.push_back(stk::mesh::EntityProc(elem, dest_proc));
647 CEOUtils::add_nodes_to_move(mesh, elem, dest_proc, entities_to_move);
648 }
649 else if(p_rank == 3)
650 {
651 stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 4);
652 int dest_proc = 2;
653 entities_to_move.push_back(stk::mesh::EntityProc(elem, dest_proc));
654 CEOUtils::add_nodes_to_move(mesh, elem, dest_proc, entities_to_move);
655 }
656
657 mesh.modification_begin("change_entity_owner");
658
659 mesh.my_internal_change_entity_owner(entities_to_move);
660
661 CEOUtils::checkStatesAfterCEO_4Elem4ProcRotate(mesh, meta);
662
663 ////////////////////////////////////////////////////////////////////////////
664
665 updateSharingAndPrintStats(mesh);
666
667 ////////////////////////////////////////////////////////////////////////////
668
669 CEOUtils::checkStatesAfterCEOME_4Elem4ProcRotate(mesh, meta);
670 }
671
672 TEST(CEOME, change_entity_owner_3Elem4Proc1Edge3D)
673 {
674 // ID.proc
675 // 15.2--------16.2 15.1--------16.1
676 // /| /| /| /|
677 // / | / | / | / |
678 // 7.2---------8.2 | 7.1---------8.1 |
679 // | | 3.2 | | | | 3.1 | |
680 // | | | | | | | |
681 // 12.0-------|13.0-------|14.1 12.3-------|13.3-------|14.0
682 // /| | *| | /| --> /| | *| | /|
683 // / | |* | |/ | / | |* | |/ |
684 // 4.0---------5.0---------6.1 | 4.3---------5.3---------6.0 |
685 // | | 1.0 | | 2.1 | | | | 1.3 | | 2.0 | |
686 // | | | | | | | | | | | |
687 // | 9.0-------|10.0-------|11.1 | 9.3-------|10.3-------|11.0
688 // | / | / | / | / | / | /
689 // |/ |/ |/ |/ |/ |/
690 // 1.0---------2.0---------3.1 1.3---------2.3---------3.0
691 //
692 // (*)edge: 1.0 (*)edge: 1.1
693
694 stk::ParallelMachine pm = MPI_COMM_WORLD;
695 int numProcs = stk::parallel_machine_size(pm);
696 if(numProcs != 4)
697 {
698 return;
699 }
700
701 unsigned spatialDim = 3;
702 stk::mesh::MetaData meta(spatialDim);
703 stk::unit_test_util::BulkDataTester mesh(meta, pm);
704 const int p_rank = mesh.parallel_rank();
705 CEOUtils::fillMeshfor3Elem4Proc1Edge3DAndTest(mesh, meta);
706
707 std::vector<stk::mesh::EntityProc> entities_to_move;
708 if(p_rank == 0)
709 {
710 Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 1);
711 int dest_proc = 3;
712 entities_to_move.push_back(stk::mesh::EntityProc(elem, dest_proc));
713 CEOUtils::add_nodes_to_move(mesh, elem, dest_proc, entities_to_move);
714
715 elem = mesh.get_entity(stk::topology::EDGE_RANK, 1);
716 dest_proc = 1;
717 entities_to_move.push_back(stk::mesh::EntityProc(elem, dest_proc));
718 }
719 else if(p_rank == 1)
720 {
721 Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 2);
722 int dest_proc = 0;
723 entities_to_move.push_back(stk::mesh::EntityProc(elem, dest_proc));
724 CEOUtils::add_nodes_to_move(mesh, elem, dest_proc, entities_to_move);
725 }
726 else if(p_rank == 2)
727 {
728 Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 3);
729 int dest_proc = 1;
730 entities_to_move.push_back(stk::mesh::EntityProc(elem, dest_proc));
731 CEOUtils::add_nodes_to_move(mesh, elem, dest_proc, entities_to_move);
732 }
733
734 mesh.modification_begin("change_entity_owner");
735
736 mesh.my_internal_change_entity_owner(entities_to_move);
737
738 CEOUtils::checkStatesAfterCEO_3Elem4Proc1Edge3D(mesh);
739
740 ////////////////////////////////////////////////////////////////////////////
741
742 updateSharingAndPrintStats(mesh);
743
744 ////////////////////////////////////////////////////////////////////////////
745
746 CEOUtils::checkStatesAfterCEOME_3Elem4Proc1Edge3D(mesh);
747 }
748
749 TEST(CEOME, test_node_ownership_change_that_causes_ghosted_node_to_be_marked_as_modified)
750 {
751 MPI_Comm communicator = MPI_COMM_WORLD;
752 int psize = stk::parallel_machine_size(communicator);
753
754 if(psize == 2)
755 {
756 stk::io::StkMeshIoBroker stkMeshIoBroker(communicator);
757 const std::string generatedMeshSpecification = "generated:1x2x2";
758 stkMeshIoBroker.add_mesh_database(generatedMeshSpecification, stk::io::READ_MESH);
759 stkMeshIoBroker.create_input_mesh();
760 stkMeshIoBroker.populate_bulk_data();
761 stk::mesh::BulkData &stkMeshBulkData = stkMeshIoBroker.bulk_data();
762
763 std::vector<stk::mesh::EntityProc> entities_to_move;
764
765 stk::mesh::EntityKey node11(stk::topology::NODE_RANK, 11);
766 if ( stkMeshBulkData.parallel_rank() == 0 )
767 {
768 stk::mesh::Entity entity = stkMeshBulkData.get_entity(node11);
769 int destProc = 1;
770 entities_to_move.push_back(stk::mesh::EntityProc(entity, destProc));
771 }
772
773 stkMeshBulkData.change_entity_owner(entities_to_move);
774
775 stk::mesh::Entity entity = stkMeshBulkData.get_entity(node11);
776 EXPECT_TRUE(stkMeshBulkData.parallel_owner_rank(entity) == 1);
777 }
778 }
779
780 }