stk::topology get_subcell_nodes(const BulkData& mesh, const Entity entity, EntityRank subcell_rank, unsigned subcell_identifier, EntityVector & subcell_nodes) { ThrowAssert(subcell_rank <= stk::topology::ELEMENT_RANK); subcell_nodes.clear(); // get cell topology stk::topology celltopology = mesh.bucket(entity).topology(); //error checking { //no celltopology defined if(celltopology == stk::topology::INVALID_TOPOLOGY) { return celltopology; } // valid ranks fall within the dimension of the cell topology const bool bad_rank = subcell_rank >= celltopology.dimension(); ThrowInvalidArgMsgIf( bad_rank, "subcell_rank is >= celltopology dimension\n"); // subcell_identifier must be less than the subcell count const bool bad_id = subcell_identifier >= celltopology.num_sub_topology(subcell_rank); ThrowInvalidArgMsgIf( bad_id, "subcell_id is >= subcell_count\n"); } // Get the cell topology of the subcell stk::topology subcell_topology = celltopology.sub_topology(subcell_rank, subcell_identifier); const int num_nodes_in_subcell = subcell_topology.num_nodes(); // For the subcell, get it's local nodes ids std::vector<unsigned> subcell_node_local_ids(num_nodes_in_subcell); celltopology.sub_topology_node_ordinals(subcell_rank, subcell_identifier, subcell_node_local_ids.begin()); Entity const *node_relations = mesh.begin_nodes(entity); subcell_nodes.reserve(num_nodes_in_subcell); for(int i = 0; i < num_nodes_in_subcell; ++i) { subcell_nodes.push_back(node_relations[subcell_node_local_ids[i]]); } return subcell_topology; }
const CellTopologyData * get_subcell_nodes(const Entity & entity , EntityRank subcell_rank , unsigned subcell_identifier , EntityVector & subcell_nodes) { subcell_nodes.clear(); // get cell topology const CellTopologyData* celltopology = get_cell_topology_new(entity).getCellTopologyData(); //error checking { //no celltopology defined if (celltopology == NULL) { return NULL; } // valid ranks fall within the dimension of the cell topology const bool bad_rank = subcell_rank >= celltopology->dimension; ThrowInvalidArgMsgIf( bad_rank, "subcell_rank is >= celltopology dimension\n"); // subcell_identifier must be less than the subcell count const bool bad_id = subcell_identifier >= celltopology->subcell_count[subcell_rank]; ThrowInvalidArgMsgIf( bad_id, "subcell_id is >= subcell_count\n"); } // Get the cell topology of the subcell const CellTopologyData * subcell_topology = celltopology->subcell[subcell_rank][subcell_identifier].topology; const int num_nodes_in_subcell = subcell_topology->node_count; // For the subcell, get it's local nodes ids const unsigned* subcell_node_local_ids = celltopology->subcell[subcell_rank][subcell_identifier].node; FEMMetaData & fem_meta = FEMMetaData::get(entity); const EntityRank node_rank = fem_meta.node_rank(); PairIterRelation node_relations = entity.relations(node_rank); subcell_nodes.reserve(num_nodes_in_subcell); for (int i = 0; i < num_nodes_in_subcell; ++i ) { subcell_nodes.push_back( node_relations[subcell_node_local_ids[i]].entity() ); } return subcell_topology; }
Part * PartRepository::declare_part( const PartVector & part_intersect ) { static const char method[] = "stk_classic::mesh::impl::PartRepository::declare_part" ; Trace_(method); PartVector pset_clean ; for ( PartVector::const_iterator i = part_intersect.begin() ; i != part_intersect.end() ; ++i ) { Part * const p = *i ; assert_superset( *m_universal_part, *p , method ); // If 'p' is a superset of another member // then it is redundant in this intersection. // Only keep non-redundant intersections. PartVector::const_iterator j = part_intersect.begin(); for ( ; j != part_intersect.end() && ! contain( (*j)->supersets() , *p ) ; ++j ); if ( j == part_intersect.end() ) { pset_clean.push_back( p ); } } // Sort and unique the intersection order( pset_clean ); Part * p = NULL ; if ( 1 == pset_clean.size() ) { // Only one remaining part, it is the subset. p = pset_clean[0] ; } else { const char separator[] = "^" ; // Generate a name and rank reflecting the intersection. // Rank is the minimum rank of the intersection members. std::string p_name ; EntityRank p_rank = InvalidEntityRank; p_name.assign("{"); for ( PartVector::iterator i = pset_clean.begin() ; i != pset_clean.end() ; ++i ) { if ( i != pset_clean.begin() ) { p_name.append( separator ); } p_name.append( (*i)->name() ); if ( (*i)->primary_entity_rank() < p_rank ) { p_rank = (*i)->primary_entity_rank(); } } p_name.append("}"); const PartVector & all_parts = get_all_parts(); p = find( all_parts, p_name ); if ( p == NULL ) { // Create the part: p = declare_part_impl( p_name , p_rank ); // Define the part to be an intersection of the given parts: p->m_partImpl.set_intersection_of( pset_clean ); for ( PartVector::iterator i = pset_clean.begin() ; i != pset_clean.end() ; ++i ) { declare_subset( **i, *p ); } } else { // This error is "inconceivable" and is // only possible by heroic malicious abuse. ThrowInvalidArgMsgIf( pset_clean != p->intersection_of(), p_name << " FAILED FROM MALICIOUS ABUSE" ); } } return p ; }
STKUNIT_UNIT_TEST(UnitTestingOfThrowMacros, testUnit) { // Setting assert handler to NULL should cause exception STKUNIT_ASSERT_THROW(stk::set_assert_handler(0), std::runtime_error); // Check that Throw*Msg works STKUNIT_ASSERT_THROW(force_throw_require_trigger(), std::logic_error); STKUNIT_ASSERT_THROW(force_throw_error_trigger(), std::runtime_error); STKUNIT_ASSERT_THROW(force_throw_invarg_trigger(), std::invalid_argument); // Check that Throw* works STKUNIT_ASSERT_THROW(force_throw_require_trigger(false), std::logic_error); STKUNIT_ASSERT_THROW(force_throw_error_trigger(false), std::runtime_error); STKUNIT_ASSERT_THROW(force_throw_invarg_trigger(false), std::invalid_argument); // Check that macro interacts appropriately with if statements STKUNIT_ASSERT_THROW(check_interaction_with_if(), std::logic_error); STKUNIT_ASSERT_THROW(check_interaction_with_if(false), std::logic_error); // Check that usage of ThrowRequireMsg/ThrowAssertMsg does not change program // semantics. Code blocks that are not contained within braces seem to be // the most likely to be problematic. bool expected_execution_path = false; if (false) ThrowRequireMsg(false, "test"); else expected_execution_path = true; STKUNIT_ASSERT(expected_execution_path); expected_execution_path = false; if (false) ThrowAssertMsg(false, "test"); else expected_execution_path = true; STKUNIT_ASSERT(expected_execution_path); expected_execution_path = false; if (false) ThrowErrorMsg("test"); else expected_execution_path = true; STKUNIT_ASSERT(expected_execution_path); // These next four statements are to check compilation success if (false) ThrowRequireMsg(false, "test"); if (false) ThrowAssertMsg(false, "test"); if (false) ThrowRequire(false); if (false) ThrowAssert(false); // Check that do-while still works, again, we are mostly checking compilation // success here. do ThrowRequireMsg(true, "test"); while (false); do ThrowAssertMsg(true, "test"); while (false); // Check that message with put-tos compiles int temp = 0; ThrowRequireMsg(true, "test: " << temp << " blah"); ThrowAssertMsg(true, "test: " << temp << " blah"); // Check that assert behaves as expected (throws in debug, not in opt) #ifdef NDEBUG force_throw_assert(); #else STKUNIT_ASSERT_THROW(force_throw_assert(), std::logic_error); #endif // Check that ThrowErrorMsg works STKUNIT_ASSERT_THROW(test_no_expr_error(), std::runtime_error); // Check that setting handler for asserts works. stk::ErrorHandler orig = stk::set_assert_handler(test_assert_handler); ThrowRequireMsg(false, "test"); STKUNIT_ASSERT(test_assert_handler_called); stk::set_assert_handler(orig); STKUNIT_ASSERT_THROW(force_throw_require_trigger(), std::logic_error); // Check that setting handler for errors works. orig = stk::set_error_handler(test_error_handler); ThrowErrorMsgIf(true, "test"); STKUNIT_ASSERT(test_error_handler_called); stk::set_error_handler(orig); STKUNIT_ASSERT_THROW(force_throw_error_trigger(), std::runtime_error); // Check that setting handler for invalid args works. orig = stk::set_invalid_arg_handler(test_invarg_handler); ThrowInvalidArgMsgIf(true, "test"); STKUNIT_ASSERT(test_invarg_handler_called); stk::set_invalid_arg_handler(orig); STKUNIT_ASSERT_THROW(force_throw_invarg_trigger(), std::invalid_argument); }