9 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
10 #include <Shards_BasicTopologies.hpp>
12 #include <stk_util/parallel/Parallel.hpp>
14 #include <stk_mesh/base/MetaData.hpp>
15 #include <stk_mesh/base/BulkData.hpp>
16 #include <stk_mesh/base/Entity.hpp>
17 #include <stk_mesh/base/GetEntities.hpp>
18 #include <stk_mesh/base/Selector.hpp>
19 #include <stk_mesh/base/GetBuckets.hpp>
21 #include <stk_mesh/fem/BoundaryAnalysis.hpp>
22 #include <stk_mesh/fem/FEMHelpers.hpp>
24 #include <stk_mesh/fixtures/GridFixture.hpp>
29 static const size_t NODE_RANK = stk::mesh::fem::FEMMetaData::NODE_RANK;
31 class UnitTestStkMeshBoundaryAnalysis {
39 void test_boundary_analysis();
40 void test_boundary_analysis_null_topology();
49 STKUNIT_UNIT_TEST( UnitTestStkMeshBoundaryAnalysis , testUnit )
51 UnitTestStkMeshBoundaryAnalysis unit(MPI_COMM_WORLD);
52 unit.test_boundary_analysis();
55 STKUNIT_UNIT_TEST( UnitTestStkMeshBoundaryAnalysis , testNullTopology )
57 UnitTestStkMeshBoundaryAnalysis unit(MPI_COMM_WORLD);
58 unit.test_boundary_analysis_null_topology();
63 void UnitTestStkMeshBoundaryAnalysis::test_boundary_analysis()
86 if (m_num_procs > 1) {
91 stk::mesh::fixtures::GridFixture grid_mesh(MPI_COMM_WORLD);
96 const stk::mesh::EntityRank element_rank = fem_meta.
element_rank();
99 stk::mesh::fem::CellTopology line_top(shards::getCellTopologyData<shards::ShellLine<2> >());
105 grid_mesh.generate_grid();
108 const unsigned num_shells = 4;
111 std::vector<unsigned>
count;
114 const unsigned num_entities = count[NODE_RANK] + count[element_rank];
117 std::vector<stk::mesh::Entity*> shells;
119 shell_parts.push_back(&shell_part);
120 for (
unsigned i = 1; i <= num_shells; ++i) {
124 shells.push_back(&new_shell);
128 unsigned node_list[5] = {20, 25, 30, 35, 40};
129 for (
unsigned i = 0; i < num_shells; ++i) {
140 std::vector<stk::mesh::Entity*> closure;
141 unsigned num_elems_in_closure = 6;
142 stk::mesh::EntityId ids_of_entities_in_closure[] =
143 {6, 7, 10, 11, 14, 15, 23, 24, 25, 28, 29, 30, 33, 34, 35, 38, 39, 40};
145 i <
sizeof(ids_of_entities_in_closure)/
sizeof(stk::mesh::EntityId);
147 stk::mesh::EntityRank rank_of_entity;
148 if (i < num_elems_in_closure) {
149 rank_of_entity = element_rank;
152 rank_of_entity = NODE_RANK;
155 bulk_data.
get_entity(rank_of_entity, ids_of_entities_in_closure[i]);
156 closure.push_back(closure_entity);
162 stk::mesh::EntitySideVector boundary;
163 stk::mesh::boundary_analysis(bulk_data, closure, element_rank, boundary);
164 STKUNIT_EXPECT_TRUE(!boundary.empty());
172 typedef std::pair<stk::mesh::EntityId, stk::mesh::Ordinal> BoundaryItem;
173 typedef std::pair<BoundaryItem, BoundaryItem> BoundaryPair;
178 BoundaryPair results[] = {
179 BoundaryPair(BoundaryItem(6, 0), BoundaryItem(5, 2)),
181 BoundaryPair(BoundaryItem(6, 3), BoundaryItem(2, 1)),
183 BoundaryPair(BoundaryItem(7, 2), BoundaryItem(8, 0)),
184 BoundaryPair(BoundaryItem(7, 2), BoundaryItem(43, 0)),
186 BoundaryPair(BoundaryItem(7, 3), BoundaryItem(3, 1)),
188 BoundaryPair(BoundaryItem(10, 0), BoundaryItem(9, 2)),
190 BoundaryPair(BoundaryItem(11, 2), BoundaryItem(12, 0)),
191 BoundaryPair(BoundaryItem(11, 2), BoundaryItem(44, 0)),
193 BoundaryPair(BoundaryItem(14, 0), BoundaryItem(13, 2)),
195 BoundaryPair(BoundaryItem(14, 1), BoundaryItem(0, 0)),
197 BoundaryPair(BoundaryItem(15, 1), BoundaryItem(0, 0)),
199 BoundaryPair(BoundaryItem(15, 2), BoundaryItem(16, 0)),
200 BoundaryPair(BoundaryItem(15, 2), BoundaryItem(45, 0))
206 BoundaryPair expected_results[
sizeof(results)/
sizeof(BoundaryPair)];
209 stk::mesh::EntitySideVector::iterator itr = boundary.begin();
211 for (; itr != boundary.end(); ++itr, ++i)
213 stk::mesh::EntitySide& side = *itr;
214 stk::mesh::EntitySideComponent& inside_closure = side.inside;
215 stk::mesh::EntityId inside_id = inside_closure.entity != NULL ? inside_closure.entity->identifier() : 0;
216 stk::mesh::EntityId inside_side = inside_closure.entity != NULL ? inside_closure.side_ordinal : 0;
217 stk::mesh::EntitySideComponent& outside_closure = side.outside;
218 stk::mesh::EntityId outside_id = outside_closure.entity != NULL ? outside_closure.entity->identifier() : 0;
219 stk::mesh::EntityId outside_side = outside_closure.entity != NULL ? outside_closure.side_ordinal : 0;
221 expected_results[i] = BoundaryPair(BoundaryItem(inside_id, inside_side),
222 BoundaryItem(outside_id, outside_side));
227 STKUNIT_EXPECT_EQ(
sizeof(results),
sizeof(expected_results));
229 for (i = 0; i <
sizeof(results)/
sizeof(BoundaryPair); ++i) {
230 STKUNIT_EXPECT_TRUE(results[i] == expected_results[i]);
234 void UnitTestStkMeshBoundaryAnalysis::test_boundary_analysis_null_topology()
239 const int spatial_dimension = 3;
241 fem_meta.
FEM_initialize(spatial_dimension, stk::mesh::fem::entity_rank_names(spatial_dimension));
243 const stk::mesh::EntityRank side_rank = fem_meta.
side_rank();
253 stk::mesh::EntitySideVector boundary;
254 std::vector<stk::mesh::Entity*> newclosure;
257 face_parts.push_back(&quad_part);
259 bulk.modification_begin();
262 newclosure.push_back(&new_face);
265 stk::mesh::boundary_analysis(bulk, newclosure, side_rank, boundary);
270 bulk.modification_end();
std::vector< Part * > PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
This is a class for selecting buckets based on a set of meshparts and set logic.
void declare_relation(Entity &e_from, Entity &e_to, const RelationIdentifier local_id)
Declare a relation and its converse between entities in the same mesh.
unsigned parallel_machine_size(ParallelMachine parallel_machine)
Member function parallel_machine_size ...
Entity * get_entity(EntityRank entity_rank, EntityId entity_id) const
Get entity with a given key.
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
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...
An application-defined subset of a problem domain.
Manager for an integrated collection of entities, entity relations, and buckets of field data...
Entity & declare_entity(EntityRank ent_rank, EntityId ent_id, const PartVector &parts)
Create or retrieve a locally owned entity of a given rank and id.
void count_entities(const Selector &selector, const BulkData &mesh, std::vector< EntityRank > &count)
Local count selected entities of each type.
Comparison operator for entities compares the entities' keys.
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.
eastl::iterator_traits< InputIterator >::difference_type count(InputIterator first, InputIterator last, const T &value)