void BucketRepository::deallocate_bucket(Bucket *b) { ThrowAssertMsg(b != NULL, "BucketRepository::deallocate_bucket(.) m_buckets invariant broken."); const unsigned bucket_id = b->bucket_id(); const EntityRank bucket_rank = b->entity_rank(); ThrowAssertMsg(b == m_buckets[bucket_rank][bucket_id], "BucketRepository::deallocate_bucket(.) m_buckets invariant broken."); m_buckets[bucket_rank][bucket_id] = NULL; // space will be reclaimed by sync_from_partitions m_need_sync_from_partitions[bucket_rank] = true; delete b; }
inline typename FieldTraits<FieldType>::data_type* field_data(const FieldType & f, const unsigned bucket_id, Bucket::size_type bucket_ord, const int knownSize) { ThrowAssertMsg(f.get_meta_data_for_field()[bucket_id].m_bytes_per_entity >= knownSize, "field name= " << f.name() << "knownSize= " << knownSize << ", m_bytes_per_entity= " << f.get_meta_data_for_field()[bucket_id].m_bytes_per_entity); ThrowAssert(f.get_meta_data_for_field()[bucket_id].m_data != NULL); return reinterpret_cast<typename FieldTraits<FieldType>::data_type*>(f.get_meta_data_for_field()[bucket_id].m_data + knownSize * bucket_ord); }
void internal_check_size_invariant() const { #ifndef NDEBUG size_t sum = 0; for (size_t i = 0, e = m_buckets.size(); i < e; ++i) { sum += m_buckets[i]->size(); m_buckets[i]->check_size_invariant(); } ThrowAssertMsg(sum == m_size, "Inconsistent sizes, bucket sum is " << sum << ", m_size is " << m_size); #endif }
bool Entity::update_relation( const RelationIterator ir , const bool back_rel_flag) const { const Relation::RelationType relType = ir->getRelationType(); ThrowAssert(verify_relation_ordering(internal_begin_relation(relType), internal_end_relation(relType))); ThrowAssertMsg(!internal_is_handled_generically(relType), "update_relation should not be called for STK-managed relations"); Entity & meshObj = *ir->getMeshObj() ; const Relation::RelationType backRelType = back_relation_type(relType); ThrowAssert(verify_relation_ordering(meshObj.internal_begin_relation(backRelType), meshObj.internal_end_relation(backRelType))); // Create the corresponding back relation to ir Relation backRel_obj(const_cast<Entity*>(this), backRelType, ir->getOrdinal(), ir->getOrientation()); RelationIterator backRel_itr = meshObj.find_relation(backRel_obj); const bool exists = backRel_itr != meshObj.internal_end_relation(backRelType) && *backRel_itr == backRel_obj; if (exists && !back_rel_flag) { // Remove back relation and increment the counter meshObj.erase_and_clear_if_empty(backRel_itr); //ThrowAssert(sierra::Fmwk::get_derived_type(meshObj) != Entity::ELEMENT); meshObj.inc_connection(); } else if (!exists && back_rel_flag) { // Insert back relation const unsigned k = backRel_itr - meshObj.internal_begin_relation(backRelType) ; meshObj.reserve_relation(meshObj.aux_relations().size() + 1); meshObj.aux_relations().insert(meshObj.aux_relations().begin() + k, backRel_obj); //ThrowAssert(sierra::Fmwk::get_derived_type(meshObj) != Entity::ELEMENT); meshObj.dec_connection(); } ThrowAssert(verify_relation_ordering(meshObj.internal_begin_relation(relType), meshObj.internal_end_relation(relType))); return true; }
void BucketRepository::sync_bucket_ids(EntityRank entity_rank) { BucketVector &buckets = m_buckets[entity_rank]; unsigned num_buckets = buckets.size(); std::vector<unsigned> id_map(num_buckets); for (unsigned i = 0; i < num_buckets; ++i) { ThrowAssertMsg(buckets[i] != NULL, "BucketRepository::sync_bucket_ids() called when m_buckets[" << entity_rank << "] is not dense."); id_map[i] = buckets[i]->bucket_id(); buckets[i]->m_bucket_id = i; } m_mesh.reorder_buckets_callback(entity_rank, id_map); }
void ScratchViews::create_needed_field_views(const TeamHandleType& team, const ElemDataRequests& dataNeeded, const stk::mesh::BulkData& bulkData, int nodesPerElem) { const stk::mesh::MetaData& meta = bulkData.mesh_meta_data(); unsigned numFields = meta.get_fields().size(); fieldViews.resize(numFields, nullptr); const FieldSet& neededFields = dataNeeded.get_fields(); for(const FieldInfo& fieldInfo : neededFields) { stk::mesh::EntityRank fieldEntityRank = fieldInfo.field->entity_rank(); ThrowAssertMsg(fieldEntityRank == stk::topology::NODE_RANK || fieldEntityRank == stk::topology::ELEM_RANK, "Currently only node and element fields are supported."); unsigned scalarsDim1 = fieldInfo.scalarsDim1; unsigned scalarsDim2 = fieldInfo.scalarsDim2; if (fieldEntityRank==stk::topology::ELEM_RANK) { if (scalarsDim2 == 0) { fieldViews[fieldInfo.field->mesh_meta_data_ordinal()] = new ViewT<SharedMemView<double*>>(get_shmem_view_1D(team, scalarsDim1)); } else { fieldViews[fieldInfo.field->mesh_meta_data_ordinal()] = new ViewT<SharedMemView<double**>>(get_shmem_view_2D(team, scalarsDim1, scalarsDim2)); } } else if (fieldEntityRank==stk::topology::NODE_RANK) { if (scalarsDim2 == 0) { if (scalarsDim1 == 1) { fieldViews[fieldInfo.field->mesh_meta_data_ordinal()] = new ViewT<SharedMemView<double*>>(get_shmem_view_1D(team, nodesPerElem)); } else { fieldViews[fieldInfo.field->mesh_meta_data_ordinal()] = new ViewT<SharedMemView<double**>>(get_shmem_view_2D(team, nodesPerElem, scalarsDim1)); } } else { fieldViews[fieldInfo.field->mesh_meta_data_ordinal()] = new ViewT<SharedMemView<double***>>(get_shmem_view_3D(team, nodesPerElem, scalarsDim1, scalarsDim2)); } } else { ThrowRequireMsg(false,"Only elem-rank and node-rank fields supported for scratch-views currently."); } } }
/** \brief Query the i^th entity */ Entity operator[] ( size_t i ) const { ThrowAssertMsg( i < m_entities.size(), "Index " << i << " is out of bounds"); return m_entities[i]; }
Entity declare_element_to_entity(BulkData & mesh, Entity elem, Entity entity, const unsigned relationOrdinal, const PartVector& parts, stk::topology entity_top) { stk::topology elem_top = mesh.bucket(elem).topology(); std::vector<unsigned> entity_node_ordinals(entity_top.num_nodes()); elem_top.sub_topology_node_ordinals(mesh.entity_rank(entity), relationOrdinal, entity_node_ordinals.begin()); const stk::mesh::Entity *elem_nodes = mesh.begin_nodes(elem); EntityVector entity_top_nodes(entity_top.num_nodes()); elem_top.sub_topology_nodes(elem_nodes, mesh.entity_rank(entity), relationOrdinal, entity_top_nodes.begin()); Permutation perm = mesh.find_permutation(elem_top, elem_nodes, entity_top, &entity_top_nodes[0], relationOrdinal); OrdinalVector ordinal_scratch; ordinal_scratch.reserve(64); PartVector part_scratch; part_scratch.reserve(64); if(!parts.empty()) { mesh.change_entity_parts(entity, parts); } const stk::mesh::ConnectivityOrdinal *side_ordinals = mesh.begin_ordinals(elem, mesh.entity_rank(entity)); unsigned num_sides = mesh.count_valid_connectivity(elem, mesh.entity_rank(entity)); bool elem_to_side_exists = false; for(unsigned i = 0; i < num_sides; ++i) { if(side_ordinals[i] == relationOrdinal) { elem_to_side_exists = true; break; } } if(!elem_to_side_exists) { mesh.declare_relation(elem, entity, relationOrdinal, perm, ordinal_scratch, part_scratch); } const unsigned num_side_nodes = mesh.count_valid_connectivity(entity, stk::topology::NODE_RANK); if(0 == num_side_nodes) { Permutation node_perm = stk::mesh::Permutation::INVALID_PERMUTATION; Entity const *elem_nodes_local = mesh.begin_nodes(elem); for(unsigned i = 0; i < entity_top.num_nodes(); ++i) { Entity node = elem_nodes_local[entity_node_ordinals[i]]; mesh.declare_relation(entity, node, i, node_perm, ordinal_scratch, part_scratch); } } else { ThrowAssertMsg(num_side_nodes == entity_top.num_nodes(), "declare_element_to_entity: " << mesh.entity_key(entity) << " already exists with different number of nodes."); } return entity; }
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); }
int get_num_bytes_pre_req_data(ElemDataRequests& dataNeededBySuppAlgs, int nDim) { /* master elements are allowed to be null if they are not required */ MasterElement *meSCS = dataNeededBySuppAlgs.get_cvfem_surface_me(); MasterElement *meSCV = dataNeededBySuppAlgs.get_cvfem_volume_me(); const int nodesPerElem = meSCS != nullptr ? meSCS->nodesPerElement_ : 0; const int numScsIp = meSCS != nullptr ? meSCS->numIntPoints_ : 0; const int numScvIp = meSCV != nullptr ? meSCV->numIntPoints_ : 0; int numBytes = 0; const FieldSet& neededFields = dataNeededBySuppAlgs.get_fields(); for(const FieldInfo& fieldInfo : neededFields) { stk::mesh::EntityRank fieldEntityRank = fieldInfo.field->entity_rank(); ThrowAssertMsg(fieldEntityRank == stk::topology::NODE_RANK || fieldEntityRank == stk::topology::ELEM_RANK, "Currently only node and element fields are supported."); unsigned scalarsPerEntity = fieldInfo.scalarsDim1; unsigned entitiesPerElem = fieldEntityRank==stk::topology::ELEM_RANK ? 1 : nodesPerElem; if (fieldInfo.scalarsDim2 > 1) { scalarsPerEntity *= fieldInfo.scalarsDim2; } numBytes += entitiesPerElem*scalarsPerEntity*sizeof(double); } const std::set<ELEM_DATA_NEEDED>& dataEnums = dataNeededBySuppAlgs.get_data_enums(); int dndxLength = 0, gUpperLength = 0, gLowerLength = 0; // Updated logic for data sharing of deriv and det_j bool needDeriv = false; bool needDetj = false; for(ELEM_DATA_NEEDED data : dataEnums) { switch(data) { case SCS_AREAV: numBytes += nDim * numScsIp * sizeof(double); break; case SCS_GRAD_OP: case SCS_SHIFTED_GRAD_OP: dndxLength = nodesPerElem*numScsIp*nDim; needDeriv = true; needDetj = true; numBytes += dndxLength * sizeof(double); break; case SCV_VOLUME: numBytes += numScvIp * sizeof(double); break; case SCS_GIJ: gUpperLength = nDim*nDim*numScsIp; gLowerLength = nDim*nDim*numScsIp; needDeriv = true; numBytes += (gUpperLength + gLowerLength ) * sizeof(double); break; default: break; } } if (needDeriv) numBytes += nodesPerElem*numScsIp*nDim * sizeof(double); if (needDetj) numBytes += numScsIp * sizeof(double); return numBytes*2; }
inline void parallel_sum_including_ghosts( const BulkData & mesh , const std::vector< const FieldBase *> & fields ) { if ( fields.empty() ) { return; } const int parallel_size = mesh.parallel_size(); const int parallel_rank = mesh.parallel_rank(); const std::vector<const FieldBase *>::const_iterator fe = fields.end(); const std::vector<const FieldBase *>::const_iterator fb = fields.begin(); std::vector<const FieldBase *>::const_iterator fi ; // Sizing for send and receive const unsigned zero = 0 ; std::vector<unsigned> send_size( parallel_size , zero ); std::vector<unsigned> recv_size( parallel_size , zero ); const EntityCommListInfoVector& comm_info_vec = mesh.internal_comm_list(); size_t comm_info_vec_size = comm_info_vec.size(); for ( fi = fb ; fi != fe ; ++fi ) { const FieldBase & f = **fi ; for (size_t i=0; i<comm_info_vec_size; ++i) { if (!mesh.is_valid(comm_info_vec[i].entity)) { ThrowAssertMsg(mesh.is_valid(comm_info_vec[i].entity),"parallel_sum_including_ghosts found invalid entity"); } const Bucket* bucket = comm_info_vec[i].bucket; unsigned e_size = 0 ; if(is_matching_rank(f, *bucket)) { const unsigned bucketId = bucket->bucket_id(); e_size += field_bytes_per_entity( f , bucketId ); } if (e_size == 0) { continue; } const bool owned = comm_info_vec[i].owner == parallel_rank ; if ( !owned ) { send_size[ comm_info_vec[i].owner ] += e_size ; } else { const EntityCommInfoVector& infovec = comm_info_vec[i].entity_comm->comm_map; size_t info_vec_size = infovec.size(); for (size_t j=0; j<info_vec_size; ++j ) { recv_size[ infovec[j].proc ] += e_size ; } } } } // Allocate send and receive buffers: CommAll sparse ; { const unsigned * const snd_size = & send_size[0] ; const unsigned * const rcv_size = & recv_size[0] ; sparse.allocate_buffers( mesh.parallel(), snd_size, rcv_size); } // Send packing: for (int phase = 0; phase < 2; ++phase) { for ( fi = fb ; fi != fe ; ++fi ) { const FieldBase & f = **fi ; for (size_t i=0; i<comm_info_vec_size; ++i) { const bool owned = comm_info_vec[i].owner == parallel_rank; if ( (!owned && phase == 0) || (owned && phase == 1) ) { const Bucket* bucket = comm_info_vec[i].bucket; if(!is_matching_rank(f, *bucket)) continue; const unsigned bucketId = bucket->bucket_id(); const size_t bucket_ordinal = comm_info_vec[i].bucket_ordinal; const unsigned scalars_per_entity = field_scalars_per_entity(f, bucketId); if ( scalars_per_entity > 0 ) { int owner = comm_info_vec[i].owner; if (f.data_traits().is_floating_point && f.data_traits().size_of == 8) { send_or_recv_field_data_for_assembly<double>(sparse, phase, f, owner, comm_info_vec[i].entity_comm->comm_map, scalars_per_entity, bucketId, bucket_ordinal); } else if (f.data_traits().is_floating_point && f.data_traits().size_of == 4) { send_or_recv_field_data_for_assembly<float>(sparse, phase, f, owner, comm_info_vec[i].entity_comm->comm_map, scalars_per_entity, bucketId, bucket_ordinal); } else if (f.data_traits().is_integral && f.data_traits().size_of == 4 && f.data_traits().is_unsigned) { send_or_recv_field_data_for_assembly<unsigned>(sparse, phase, f, owner, comm_info_vec[i].entity_comm->comm_map, scalars_per_entity, bucketId, bucket_ordinal); } else if (f.data_traits().is_integral && f.data_traits().size_of == 4 && f.data_traits().is_signed) { send_or_recv_field_data_for_assembly<int>(sparse, phase, f, owner, comm_info_vec[i].entity_comm->comm_map, scalars_per_entity, bucketId, bucket_ordinal); } else { ThrowRequireMsg(false,"Unsupported field type in parallel_sum_including_ghosts"); } } } } } if (phase == 0) { sparse.communicate(); } } copy_from_owned(mesh, fields); }