9 #include <use_cases/UseCase_Rebal_2.hpp> 11 #include <stk_util/parallel/Parallel.hpp> 12 #include <stk_util/parallel/ParallelReduce.hpp> 14 #include <stk_mesh/base/Comm.hpp> 15 #include <stk_mesh/base/FieldData.hpp> 16 #include <stk_mesh/base/GetEntities.hpp> 17 #include <stk_mesh/base/Types.hpp> 18 #include <stk_mesh/fem/CreateAdjacentEntities.hpp> 24 #include <stk_rebalance_utils/RebalanceUtils.hpp> 38 void sum_element_weights_through_relations( stk_classic::mesh::EntityVector & elements,
39 ScalarField & field,
const std::vector<stk_classic::mesh::EntityRank> & ranks )
41 for(
size_t i = 0; i < ranks.size(); ++i )
43 for(
size_t ielem = 0; ielem < elements.size(); ++ielem )
46 double * elem_weight =
field_data( field , *elem );
48 const unsigned num_entities = rel.size();
50 for (
unsigned j = 0 ; j < num_entities ; ++j )
53 const double * entity_weight =
field_data( field , entity );
54 elem_weight[0] += entity_weight[0];
77 const stk_classic::mesh::EntityRank element_rank = fem_meta.
element_rank();
78 const stk_classic::mesh::EntityRank face_rank = fem_meta.
face_rank();
79 const stk_classic::mesh::EntityRank edge_rank = fem_meta.
edge_rank();
80 const stk_classic::mesh::EntityRank node_rank = fem_meta.
node_rank();
90 std::vector<stk_classic::mesh::EntityId> my_element_ids;
93 for (
unsigned i = 0 ; i < nx*ny*nz; ++i )
94 my_element_ids.push_back(i+1);
97 fixture.generate_mesh(my_element_ids);
101 stk_classic::mesh::create_adjacent_entities(bulk, add_parts);
109 stk_classic::mesh::EntityVector selected_nodes;
110 stk_classic::mesh::EntityVector selected_faces;
111 stk_classic::mesh::EntityVector one_face;
112 for (
unsigned j = 0 ; j < ny; ++j )
113 for (
unsigned k = 0 ; k < nz; ++k )
115 selected_nodes.clear();
116 selected_nodes.push_back( fixture.node(0, j, k ) );
117 selected_nodes.push_back( fixture.node(0, j+1, k ) );
118 selected_nodes.push_back( fixture.node(0, j, k+1) );
119 selected_nodes.push_back( fixture.node(0, j+1, k+1) );
121 selected_faces.push_back(one_face[0]);
124 for(
size_t iface = 0; iface < selected_faces.size(); ++iface )
132 stk_classic::mesh::EntityVector selected_edges;
133 stk_classic::mesh::EntityVector one_edge;
134 for (
unsigned j = 0 ; j < ny; ++j )
136 selected_nodes.clear();
137 selected_nodes.push_back( fixture.node(0, j, 0) );
138 selected_nodes.push_back( fixture.node(0, j+1, 0) );
140 selected_edges.push_back(one_edge[0]);
141 selected_nodes.clear();
142 selected_nodes.push_back( fixture.node(0, j, nz) );
143 selected_nodes.push_back( fixture.node(0, j+1, nz) );
145 selected_edges.push_back(one_edge[0]);
147 for (
unsigned k = 0 ; k < nz; ++k )
149 selected_nodes.clear();
150 selected_nodes.push_back( fixture.node(0, 0, k) );
151 selected_nodes.push_back( fixture.node(0, 0, k+1) );
153 selected_edges.push_back(one_edge[0]);
154 selected_nodes.clear();
155 selected_nodes.push_back( fixture.node(0, ny, k) );
156 selected_nodes.push_back( fixture.node(0, ny, k+1) );
158 selected_edges.push_back(one_edge[0]);
160 for(
size_t iedge = 0; iedge < selected_edges.size(); ++iedge )
168 selected_nodes.clear();
179 for(
size_t i = 0; i < my_element_ids.size(); ++i )
187 selected_nodes.clear();
188 for (
unsigned j = 0 ; j < ny+1; ++j )
189 for (
unsigned k = 0 ; k < nz+1; ++k )
190 selected_nodes.push_back( fixture.node(0, j, k) );
192 std::vector<stk_classic::mesh::EntityRank> ranks;
193 ranks.push_back(face_rank);
194 ranks.push_back(edge_rank);
195 ranks.push_back(node_rank);
196 stk_classic::mesh::EntityVector selected_elems;
197 for (
unsigned j = 0 ; j < ny; ++j )
198 for (
unsigned k = 0 ; k < nz; ++k )
200 selected_nodes.clear();
201 selected_nodes.push_back( fixture.node(0, j, k ) );
202 selected_nodes.push_back( fixture.node(0, j+1, k ) );
203 selected_nodes.push_back( fixture.node(0, j, k+1) );
204 selected_nodes.push_back( fixture.node(0, j+1, k+1) );
206 selected_elems.push_back(one_face[0]);
208 sum_element_weights_through_relations(selected_elems, weight_field, ranks);
214 Teuchos::ParameterList emptyList;
215 stk_classic::rebalance::Zoltan zoltan_partition(pm, fixture.m_spatial_dimension, emptyList);
219 const double imbalance_threshold = ( 3 == p_size )? 1.45
221 const bool do_rebal = imbalance_threshold < stk_classic::rebalance::check_balance(bulk, &weight_field, element_rank);
224 std::cerr << std::endl
225 <<
"imbalance_threshold after rebalance = " << imbalance_threshold <<
", " << do_rebal << std::endl;
229 bool result = !do_rebal;
233 stk_classic::mesh::EntityVector entities;
237 result &= verify_dependent_ownership(element_rank, entities);
240 result &= verify_dependent_ownership(element_rank, entities);
243 result &= verify_dependent_ownership(element_rank, entities);
bool rebalance(mesh::BulkData &bulk_data, const mesh::Selector &selector, const VectorField *coord_ref, const ScalarField *elem_weight_ref, Partition &partition, const stk_classic::mesh::EntityRank rank=stk_classic::mesh::InvalidEntityRank)
Rebalance with a Partition object.
FieldTraits< field_type >::data_type * field_data(const field_type &f, const Bucket::iterator i)
Pointer to the field data array.
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.
field_type & put_field(field_type &field, EntityRank entity_rank, const Part &part, const void *init_value=NULL)
Declare a field to exist for a given entity type and Part.
Entity * get_entity(EntityRank entity_rank, EntityId entity_id) const
Get entity with a given key.
void get_selected_entities(const Selector &selector, const std::vector< Bucket * > &input_buckets, std::vector< Entity * > &entities)
Get entities in selected buckets (selected by the given selector instance), and sorted by ID...
unsigned parallel_machine_rank(ParallelMachine parallel_machine)
Member function parallel_machine_rank ...
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.
PairIterRelation relations() const
All Entity relations for which this entity is a member. The relations are ordered from lowest entity-...
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...
void get_entities_through_relations(const std::vector< Entity *> &entities, std::vector< Entity *> &entities_related)
Query which mesh entities have a relation to all of the input mesh entities.
For partitioning of mesh entities over a processing grid.
Static functions for dynamic load balancing.
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.