9 #include <stk_util/parallel/Parallel.hpp>
10 #include <stk_util/parallel/ParallelReduce.hpp>
11 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
13 #include <stk_mesh/base/Types.hpp>
14 #include <stk_mesh/base/MetaData.hpp>
15 #include <stk_mesh/base/BulkData.hpp>
16 #include <stk_mesh/base/FieldData.hpp>
17 #include <stk_mesh/base/GetEntities.hpp>
19 #include <stk_mesh/fem/CreateAdjacentEntities.hpp>
20 #include <stk_mesh/fem/TopologyDimensions.hpp>
21 #include <stk_mesh/fem/FEMMetaData.hpp>
22 #include <stk_mesh/fem/FEMHelpers.hpp>
28 #include <stk_rebalance_utils/RebalanceUtils.hpp>
30 static const size_t NODE_RANK = stk_classic::mesh::fem::FEMMetaData::NODE_RANK;
35 enum { nx = 2, ny = 2 };
37 STKUNIT_UNIT_TEST(UnitTestZoltanSimple, testUnit)
45 unsigned spatial_dimension = 2;
46 std::vector<std::string> rank_names = stk_classic::mesh::fem::entity_rank_names(spatial_dimension);
47 const stk_classic::mesh::EntityRank constraint_rank = rank_names.size();
48 rank_names.push_back(
"Constraint");
54 const stk_classic::mesh::EntityRank element_rank = fem_meta.
element_rank();
56 stk_classic::mesh::fem::CellTopology quad_top(shards::getCellTopologyData<shards::Quadrilateral<4> >());
66 const unsigned p_size = bulk_data.parallel_size();
67 const unsigned p_rank = bulk_data.parallel_rank();
69 bulk_data.modification_begin();
73 std::vector<std::vector<stk_classic::mesh::Entity*> > quads(nx);
74 for (
unsigned ix = 0 ; ix < nx ; ++ix ) quads[ix].resize(ny);
76 const unsigned nnx = nx + 1 ;
77 const unsigned nny = ny + 1 ;
78 for (
unsigned iy = 0 ; iy < ny ; ++iy ) {
79 for (
unsigned ix = 0 ; ix < nx ; ++ix ) {
80 stk_classic::mesh::EntityId elem = 1 + ix + iy * nx ;
81 stk_classic::mesh::EntityId nodes[4] ;
82 nodes[0] = 1 + ix + iy * nnx ;
83 nodes[1] = 2 + ix + iy * nnx ;
84 nodes[2] = 2 + ix + ( iy + 1 ) * nnx ;
85 nodes[3] = 1 + ix + ( iy + 1 ) * nnx ;
92 for (
unsigned iy = 0 ; iy < ny ; ++iy ) {
93 for (
unsigned ix = 0 ; ix < nx ; ++ix ) {
94 stk_classic::mesh::EntityId elem = 1 + ix + iy * nx ;
101 for (
unsigned iy = 0 ; iy <= ny ; ++iy ) {
102 for (
unsigned ix = 0 ; ix <= nx ; ++ix ) {
103 stk_classic::mesh::EntityId nid = 1 + ix + iy * nnx ;
113 const unsigned iy_left = 0;
114 const unsigned iy_right = ny;
116 for (
unsigned ix = 0 ; ix <= nx ; ++ix ) {
117 stk_classic::mesh::EntityId nid_left = 1 + ix + iy_left * nnx ;
118 stk_classic::mesh::EntityId nid_right = 1 + ix + iy_right * nnx ;
121 const stk_classic::mesh::EntityId constraint_entity_id = 1 + ix + nny * nnx;
123 bulk_data.declare_relation( c , *n_left , 0 );
124 bulk_data.declare_relation( c , *n_right , 1 );
132 STKUNIT_ASSERT( ! bulk_data.buckets( NODE_RANK ).empty() );
133 STKUNIT_ASSERT( ! bulk_data.buckets( element_rank ).empty() );
136 STKUNIT_ASSERT( bulk_data.buckets( NODE_RANK ).empty() );
137 STKUNIT_ASSERT( bulk_data.buckets( element_rank ).empty() );
141 bulk_data.modification_end();
145 stk_classic::mesh::create_adjacent_entities(bulk_data, add_parts);
149 Teuchos::ParameterList emptyList;
150 stk_classic::rebalance::Zoltan zoltan_partition(comm, spatial_dimension, emptyList);
158 const double imbalance_threshold = stk_classic::rebalance::check_balance(bulk_data, &weight_field, element_rank);
159 const bool do_rebal = 1.5 < imbalance_threshold;
162 STKUNIT_ASSERT( !do_rebal );
163 if( (2 == p_size) || (4 == p_size) )
165 STKUNIT_ASSERT_NEAR(imbalance_threshold, 1.0, 1.e-8);
169 STKUNIT_ASSERT_LE(imbalance_threshold, 1.5);
174 stk_classic::mesh::EntityVector entities;
178 bool result = stk_classic::rebalance::verify_dependent_ownership(element_rank, entities);
181 STKUNIT_ASSERT( result );