12 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 14 #include <stk_util/parallel/Parallel.hpp> 16 #include <stk_mesh/base/MetaData.hpp> 17 #include <stk_mesh/base/BulkData.hpp> 18 #include <stk_mesh/base/GetEntities.hpp> 19 #include <stk_mesh/base/Field.hpp> 20 #include <stk_mesh/base/FieldData.hpp> 21 #include <stk_mesh/base/Comm.hpp> 22 #include <stk_mesh/base/EntityComm.hpp> 23 #include <stk_mesh/base/Part.hpp> 24 #include <stk_mesh/base/Entity.hpp> 25 #include <stk_mesh/base/GetBuckets.hpp> 26 #include <stk_mesh/base/Bucket.hpp> 27 #include <stk_mesh/base/BulkModification.hpp> 28 #include <stk_mesh/base/Entity.hpp> 29 #include <stk_mesh/base/Bucket.hpp> 30 #include <stk_mesh/base/Ghosting.hpp> 32 #include <stk_mesh/baseImpl/BucketImpl.hpp> 34 #include <stk_mesh/fem/FEMHelpers.hpp> 35 #include <stk_mesh/fem/FEMMetaData.hpp> 36 #include <stk_mesh/fem/BoundaryAnalysis.hpp> 38 #include <Shards_BasicTopologies.hpp> 45 using stk_classic::mesh::EntityRank;
46 using stk_classic::mesh::EntityId;
47 using stk_classic::mesh::EntitySideComponent;
50 using stk_classic::mesh::EntityRank;
53 class TopologyHelpersTestingFixture
57 ~TopologyHelpersTestingFixture() {}
59 const int spatial_dimension;
62 const EntityRank element_rank;
63 const EntityRank side_rank;
64 Part & generic_element_part;
65 Part & element_tet_part;
66 Part & element_wedge_part;
67 Part & generic_face_part;
68 Part & another_generic_face_part;
69 Part & face_quad_part;
70 Part & another_generic_element_part;
72 EntityId nextEntityId()
75 Entity & create_entity( EntityRank rank,
Part& part_membership)
78 part_intersection.push_back ( &part_membership );
79 return bulk.
declare_entity(rank, nextEntityId(), part_intersection);
88 TopologyHelpersTestingFixture::TopologyHelpersTestingFixture(
ParallelMachine pm)
89 : spatial_dimension( 3 )
90 , meta( spatial_dimension )
92 , element_rank( meta.element_rank())
93 , side_rank( meta.side_rank())
94 , generic_element_part( meta.
declare_part(
"another part", element_rank ) )
98 , another_generic_face_part( meta.
declare_part(
"A_2", side_rank ) )
100 , another_generic_element_part( meta.
declare_part(
"B_3", element_rank ) )
110 const EntityRank NODE_RANK = FEMMetaData::NODE_RANK;
112 STKUNIT_UNIT_TEST( testTopologyHelpers, get_cell_topology_based_on_part)
114 TopologyHelpersTestingFixture fix(MPI_COMM_WORLD);
115 fix.bulk.modification_begin();
116 Entity & elem1 = fix.create_entity( fix.side_rank, fix.generic_face_part );
119 tmp[0] = & fix.face_quad_part;
120 fix.bulk.change_entity_parts ( elem1 , tmp );
121 STKUNIT_ASSERT_EQUAL( stk_classic::mesh::fem::get_cell_topology(elem1).getCellTopologyData(), shards::getCellTopologyData< shards::Quadrilateral<4> >() );
122 fix.bulk.change_entity_parts ( elem1 , tmp );
123 STKUNIT_ASSERT_EQUAL( stk_classic::mesh::fem::get_cell_topology(elem1).getCellTopologyData(), shards::getCellTopologyData< shards::Quadrilateral<4> >() );
124 tmp[0] = & fix.another_generic_face_part;
125 fix.bulk.change_entity_parts ( elem1 , tmp );
126 STKUNIT_ASSERT_EQUAL( stk_classic::mesh::fem::get_cell_topology(elem1).getCellTopologyData(), shards::getCellTopologyData< shards::Quadrilateral<4> >() );
127 STKUNIT_ASSERT_NE( stk_classic::mesh::fem::get_cell_topology( elem1).getCellTopologyData() , shards::getCellTopologyData< shards::Wedge<15> >() );
129 fix.bulk.modification_end();
132 STKUNIT_UNIT_TEST( testTopologyHelpers, get_cell_topology_multiple_topologies )
135 TopologyHelpersTestingFixture fix(MPI_COMM_WORLD);
137 fix.bulk.modification_begin();
138 Entity & elem = fix.create_entity( fix.element_rank, fix.generic_element_part );
140 add_parts.push_back( &fix.element_tet_part );
141 add_parts.push_back( &fix.element_wedge_part );
142 fix.bulk.change_entity_parts( elem, add_parts );
143 fix.bulk.modification_end();
144 STKUNIT_ASSERT_THROW( stk_classic::mesh::fem::get_cell_topology( elem ).getCellTopologyData(), std::runtime_error );
196 STKUNIT_UNIT_TEST( testTopologyHelpers, declare_element_side_no_topology )
199 TopologyHelpersTestingFixture fix(MPI_COMM_WORLD);
201 fix.bulk.modification_begin();
202 Entity & elem4 = fix.create_entity( fix.element_rank , fix.generic_element_part );
203 STKUNIT_ASSERT_THROW(
207 fix.bulk.modification_end();
211 EntityId elem_node[4];
216 fix.bulk.modification_begin();
218 STKUNIT_ASSERT_THROW(
222 fix.bulk.modification_end();
226 STKUNIT_UNIT_TEST( testTopologyHelpers, declare_element_side_wrong_bulk_data)
229 TopologyHelpersTestingFixture fix1(MPI_COMM_WORLD);
231 fix1.bulk.modification_begin();
233 TopologyHelpersTestingFixture fix2(MPI_COMM_WORLD);
234 fix2.bulk.modification_begin();
235 Entity & elem4_2 = fix2.create_entity( fix2.element_rank , fix2.generic_element_part );
236 fix2.bulk.modification_end();
238 STKUNIT_ASSERT_THROW(
242 fix1.bulk.modification_end();
245 STKUNIT_UNIT_TEST( testTopologyHelpers, declare_element_side_no_topology_2 )
248 TopologyHelpersTestingFixture fix(MPI_COMM_WORLD);
249 fix.bulk.modification_begin();
251 EntityId elem_node[4];
257 const CellTopologyData *
const elem_top = stk_classic::mesh::fem::get_cell_topology( element ).getCellTopologyData();
258 const EntityId nSideCount = elem_top->side_count + 10 ;
259 STKUNIT_ASSERT_THROW(
263 fix.bulk.modification_end();
266 STKUNIT_UNIT_TEST( testTopologyHelpers, declare_element_side_full )
269 TopologyHelpersTestingFixture fix(MPI_COMM_WORLD);
271 fix.bulk.modification_begin();
273 EntityId elem_node[4];
281 const EntityId zero_side_count = 0;
283 fix.bulk.modification_end();
285 PairIterRelation rel2 = face2.
relations(NODE_RANK);
287 STKUNIT_ASSERT_TRUE(
true );
290 STKUNIT_UNIT_TEST( testTopologyHelpers, element_side_polarity_valid )
293 TopologyHelpersTestingFixture fix(MPI_COMM_WORLD);
294 EntityId elem_node[4];
300 fix.bulk.modification_begin();
302 const EntityId zero_side_count = 0;
304 fix.bulk.modification_end();
306 const int local_side_id = 0;
311 STKUNIT_UNIT_TEST( testTopologyHelpers, element_side_polarity_invalid_1 )
313 TopologyHelpersTestingFixture fix(MPI_COMM_WORLD);
314 EntityId elem_node[4];
322 fix.bulk.modification_begin();
324 const EntityId zero_side_count = 0;
326 fix.bulk.modification_end();
328 const int invalid_local_side_id = -1;
330 STKUNIT_ASSERT_THROW(
337 STKUNIT_UNIT_TEST( testTopologyHelpers, element_side_polarity_invalid_2 )
339 TopologyHelpersTestingFixture fix(MPI_COMM_WORLD);
340 EntityId elem_node[4];
347 fix.bulk.modification_begin();
350 part_intersection.push_back ( &fix.generic_element_part);
351 Entity & element = fix.bulk.declare_entity(fix.element_rank, fix.nextEntityId(), part_intersection);
352 STKUNIT_ASSERT_TRUE( stk_classic::mesh::fem::get_cell_topology( element ).getCellTopologyData() == NULL );
355 STKUNIT_ASSERT_TRUE( stk_classic::mesh::fem::get_cell_topology( element_with_top ).getCellTopologyData() != NULL );
357 const EntityId zero_side_count = 0;
360 fix.bulk.modification_end();
362 const int valid_local_side_id = 0;
364 STKUNIT_ASSERT_TRUE( stk_classic::mesh::fem::get_cell_topology( element ).getCellTopologyData() == NULL );
365 STKUNIT_ASSERT_THROW(
Entity & declare_element(BulkData &mesh, Part &part, const EntityId elem_id, const EntityId node_id[])
Declare an element member of a Part with a CellTopology and nodes conformal to that topology...
int parallel_rank()
function parallel_rank returns the rank of this processor in the current mpi communicator.
An application-defined subset of a problem domain.
PairIterRelation relations() const
All Entity relations for which this entity is a member. The relations are ordered from lowest entity-...
Manager for an integrated collection of entities, entity relations, and buckets of field data...
EntityId entity_id(const EntityKey &key)
Given an entity key, return the identifier for the entity.
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Part & declare_part(FEMMetaData &meta_data, const std::string &name)
Declare a part with a given cell topology. This is just a convenient function that wraps FEMMetaData'...
int parallel_size()
function parallel_size returns the number of processors in the current mpi communicator.
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.
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
bool element_side_polarity(const Entity &elem, const Entity &side, int local_side_id)
Determine the polarity of the local side, more efficient if the local_side_id is known.
Entity & declare_element_side(Entity &elem, Entity &side, const unsigned local_side_id, Part *part)
Create (or find) an element side.