//-------------------------------------------------------------------------- void PromotedElementIO::write_elem_block_definitions( const stk::mesh::PartVector& baseParts) { for(const auto* ip : baseParts) { if (ip->topology().rank() == stk::topology::ELEM_RANK) { const auto& selector = *ip & metaData_.locally_owned_part(); const auto& elemBuckets = bulkData_.get_buckets( stk::topology::ELEM_RANK, selector); const size_t numSubElems = num_sub_elements(nDim_,elemBuckets, elem_.polyOrder); const auto* baseElemPart = base_elem_part_from_super_elem_part(*ip); auto block = make_unique<Ioss::ElementBlock>( databaseIO, baseElemPart->name(), baseElemPart->topology().name(), numSubElems ); ThrowRequireMsg(block != nullptr, "Element block creation failed"); auto result = elementBlockPointers_.insert({ip, block.get()}); ThrowRequireMsg(result.second, "Attempted to add redundant part"); output_->add(block.release()); } } }
void verify_parallel_consistency( const MetaData & s , ParallelMachine pm ) { const unsigned p_rank = parallel_machine_rank( pm ); const bool is_root = 0 == p_rank ; CommBroadcast comm( pm , 0 ); if ( is_root ) { pack( comm.send_buffer() , s.get_parts() ); pack( comm.send_buffer() , s.get_fields() ); } comm.allocate_buffer(); if ( is_root ) { pack( comm.send_buffer() , s.get_parts() ); pack( comm.send_buffer() , s.get_fields() ); } comm.communicate(); int ok[ 2 ]; ok[0] = unpack_verify( comm.recv_buffer() , s.get_parts() ); ok[1] = unpack_verify( comm.recv_buffer() , s.get_fields() ); all_reduce( pm , ReduceMin<2>( ok ) ); ThrowRequireMsg(ok[0], "P" << p_rank << ": FAILED for Parts"); ThrowRequireMsg(ok[1], "P" << p_rank << ": FAILED for Fields"); }
Partition *BucketRepository::get_or_create_partition( const EntityRank arg_entity_rank , const OrdinalVector &parts) { enum { KEY_TMP_BUFFER_SIZE = 64 }; ThrowRequireMsg(MetaData::get(m_mesh).check_rank(arg_entity_rank), "Entity rank " << arg_entity_rank << " is invalid"); if (m_buckets.empty()) { size_t entity_rank_count = m_mesh.mesh_meta_data().entity_rank_count(); ThrowRequireMsg( entity_rank_count > 0, "MetaData doesn't have any entity-ranks! Did you forget to initialize MetaData before creating BulkData?"); m_buckets.resize(entity_rank_count); m_partitions.resize(entity_rank_count); m_need_sync_from_partitions.resize(entity_rank_count, false); } std::vector<Partition *> & partitions = m_partitions[ arg_entity_rank ]; const size_t part_count = parts.size(); std::vector<unsigned> key(2 + part_count) ; //---------------------------------- // Key layout: // { part_count + 1 , { part_ordinals } , partition_count } // Thus partition_count = key[ key[0] ] // // for upper bound search use the maximum key for a bucket in the partition. const unsigned max = static_cast<unsigned>(-1); key[0] = part_count+1; key[ key[0] ] = max ; { for ( unsigned i = 0 ; i < part_count ; ++i ) { key[i+1] = parts[i] ; } } // If the partition is found, the iterator will be right after it, thanks to the // trickiness above. const std::vector<Partition *>::iterator ik = lower_bound( partitions , &key[0] ); const bool partition_exists = (ik != partitions.begin()) && raw_part_equal( ik[-1]->key() , &key[0] ); if (partition_exists) { return ik[-1]; } key[key[0]] = 0; Partition *partition = new Partition(m_mesh, this, arg_entity_rank, key); ThrowRequire(partition != NULL); m_need_sync_from_partitions[arg_entity_rank] = true; partitions.insert( ik , partition ); return partition ; }
Partition *BucketRepository::get_or_create_partition( const EntityRank arg_entity_rank , const OrdinalVector &parts) { enum { KEY_TMP_BUFFER_SIZE = 64 }; TraceIf("stk::mesh::impl::BucketRepository::get_or_create_partition", LOG_BUCKET); ThrowRequireMsg(MetaData::get(m_mesh).check_rank(arg_entity_rank), "Entity rank " << arg_entity_rank << " is invalid"); // Somehow, this can happen. ThrowRequireMsg( !m_buckets.empty(), "m_buckets is empty! Did you forget to initialize MetaData before creating BulkData?"); std::vector<Partition *> & partitions = m_partitions[ arg_entity_rank ]; const size_t part_count = parts.size(); std::vector<unsigned> key(2 + part_count) ; //---------------------------------- // Key layout: // { part_count + 1 , { part_ordinals } , partition_count } // Thus partition_count = key[ key[0] ] // // for upper bound search use the maximum key for a bucket in the partition. const unsigned max = static_cast<unsigned>(-1); key[0] = part_count+1; key[ key[0] ] = max ; { for ( unsigned i = 0 ; i < part_count ; ++i ) { key[i+1] = parts[i] ; } } // If the partition is found, the iterator will be right after it, thanks to the // trickiness above. const std::vector<Partition *>::iterator ik = lower_bound( partitions , &key[0] ); const bool partition_exists = (ik != partitions.begin()) && raw_part_equal( ik[-1]->key() , &key[0] ); if (partition_exists) { return ik[-1]; } key[key[0]] = 0; typedef tracking_allocator<Partition, PartitionTag> partition_allocator; Partition *partition = partition_allocator().allocate(1); ThrowRequire(partition != NULL); partition = new (partition) Partition(m_mesh, this, arg_entity_rank, key); m_need_sync_from_partitions[arg_entity_rank] = true; partitions.insert( ik , partition ); return partition ; }
void BulkData::require_good_rank_and_id(EntityRank ent_rank, EntityId ent_id) const { const size_t rank_count = m_mesh_meta_data.entity_rank_count(); const bool ok_id = entity_id_valid(ent_id); const bool ok_rank = ent_rank < rank_count ; ThrowRequireMsg( ok_rank, "Bad key rank: " << ent_rank << " for id " << ent_id ); ThrowRequireMsg( ok_id, "Bad key id for key: " << print_entity_key(m_mesh_meta_data, EntityKey(ent_rank, ent_id) ) ); }
void Entity::internal_verify_meshobj_invariant() const { PairIterRelation stk_relations = relations(); for ( ; !stk_relations.empty(); ++stk_relations ) { ThrowRequireMsg(stk_relations->getMeshObj() != NULL, "Problem with: " << *stk_relations); } RelationVector& aux_relations = m_fmwk_attrs->aux_relations; for (RelationVector::const_iterator itr = aux_relations.begin(), end = aux_relations.end(); itr != end; ++itr) { ThrowRequireMsg(itr->getMeshObj() != NULL, "Problem with: " << *itr); } }
OrdinalAndPermutation get_ordinal_and_permutation(const stk::mesh::BulkData& mesh, stk::mesh::Entity parent_entity, stk::mesh::EntityRank to_rank, const stk::mesh::EntityVector &nodes_of_sub_rank) { std::pair<stk::mesh::ConnectivityOrdinal, stk::mesh::Permutation> ordinalAndPermutation = std::make_pair(stk::mesh::INVALID_CONNECTIVITY_ORDINAL, stk::mesh::INVALID_PERMUTATION); unsigned nodes_of_sub_rank_size = nodes_of_sub_rank.size(); const Entity* elemNodes = mesh.begin_nodes(parent_entity); stk::topology elemTopology = mesh.bucket(parent_entity).topology(); unsigned num_entities_of_sub_topology = elemTopology.num_sub_topology(to_rank); unsigned max_nodes_possible = 100; stk::mesh::EntityVector nodes_of_sub_topology; nodes_of_sub_topology.reserve(max_nodes_possible); std::pair<bool, unsigned> result; for (unsigned i=0;i<num_entities_of_sub_topology;++i) { stk::topology sub_topology = elemTopology.sub_topology(to_rank, i); unsigned num_nodes = sub_topology.num_nodes(); if (num_nodes != nodes_of_sub_rank_size) { continue; } ThrowRequireMsg(num_nodes == nodes_of_sub_rank.size(), "AHA! num_nodes != nodes_of_sub_rank.size()"); ThrowRequireMsg(num_nodes<=max_nodes_possible, "Program error. Exceeded expected array dimensions. Contact sierra-help for support."); nodes_of_sub_topology.resize(num_nodes); elemTopology.sub_topology_nodes(elemNodes, to_rank, i, nodes_of_sub_topology.begin()); if (!elemTopology.is_shell() || (to_rank == stk::topology::EDGE_RANK)) { result = sub_topology.equivalent(nodes_of_sub_rank, nodes_of_sub_topology); } else { result = sub_topology.equivalent(nodes_of_sub_rank, nodes_of_sub_topology); if (result.first && result.second >= sub_topology.num_positive_permutations()) { result.first = false; } } if (result.first == true) { ordinalAndPermutation.first = static_cast<stk::mesh::ConnectivityOrdinal>(i); ordinalAndPermutation.second = static_cast<stk::mesh::Permutation>(result.second); } } return ordinalAndPermutation; }
void ScratchViews::create_needed_master_element_views(const TeamHandleType& team, const ElemDataRequests& dataNeeded, int nDim, int nodesPerElem, int numScsIp, int numScvIp) { bool needDeriv = false; bool needDetj = false; const std::set<ELEM_DATA_NEEDED>& dataEnums = dataNeeded.get_data_enums(); for(ELEM_DATA_NEEDED data : dataEnums) { switch(data) { case SCS_AREAV: ThrowRequireMsg(numScsIp > 0, "ERROR, meSCS must be non-null if SCS_AREAV is requested."); scs_areav = get_shmem_view_2D(team, numScsIp, nDim); break; case SCS_GRAD_OP: ThrowRequireMsg(numScsIp > 0, "ERROR, meSCS must be non-null if SCS_GRAD_OP is requested."); dndx = get_shmem_view_3D(team, numScsIp, nodesPerElem, nDim); needDeriv = true; needDetj = true; break; case SCS_SHIFTED_GRAD_OP: ThrowRequireMsg(numScsIp > 0, "ERROR, meSCS must be non-null if SCS_SHIFTED_GRAD_OP is requested."); dndx_shifted = get_shmem_view_3D(team, numScsIp, nodesPerElem, nDim); needDeriv = true; needDetj = true; break; case SCS_GIJ: ThrowRequireMsg(numScsIp > 0, "ERROR, meSCS must be non-null if SCS_GIJ is requested."); gijUpper = get_shmem_view_3D(team, numScsIp, nDim, nDim); gijLower = get_shmem_view_3D(team, numScsIp, nDim, nDim); needDeriv = true; break; case SCV_VOLUME: ThrowRequireMsg(numScvIp > 0, "ERROR, meSCV must be non-null if SCV_VOLUME is requested."); scv_volume = get_shmem_view_1D(team, numScvIp); break; default: break; } } if (needDeriv) deriv = get_shmem_view_1D(team, numScsIp*nodesPerElem*nDim); if (needDetj) det_j = get_shmem_view_1D(team, numScsIp); }
std::map<stk::mesh::EntityId, std::pair<stk::mesh::EntityId, int> > get_split_coincident_elements(stk::mesh::BulkData& bulkData) { stk::mesh::Selector sel = bulkData.mesh_meta_data().locally_owned_part(); ElemGraphForDiagnostics graph(bulkData, sel); const stk::mesh::impl::SparseGraph& coingraph = graph.get_coincident_graph(); std::map<stk::mesh::EntityId, std::pair<stk::mesh::EntityId, int> > badElements; for(const stk::mesh::impl::SparseGraph::value_type& extractedEdgesForElem : coingraph) { const std::vector<stk::mesh::GraphEdge>& coincidentEdgesForElem = extractedEdgesForElem.second; for(const stk::mesh::GraphEdge& edge : coincidentEdgesForElem) { if(edge.elem2 < 0) { stk::mesh::Entity entity = graph.get_entity(edge.elem1); stk::mesh::EntityId id = bulkData.identifier(entity); stk::mesh::impl::ParallelGraphInfo& par_info = graph.get_parallel_info(); stk::mesh::impl::ParallelGraphInfo::iterator iter = par_info.find(edge); ThrowRequireMsg(iter!=par_info.end(), "Program error. Contact [email protected] for support."); badElements[id] = std::make_pair(-edge.elem2, iter->second.m_other_proc); } } } return badElements; }
TensorProductQuadratureRule::TensorProductQuadratureRule(std::string type, int polyOrder) { scsLoc_ = gauss_legendre_rule(polyOrder).first; // pad the scs surfaces with the end-points of the element (-1 and +1) scsEndLoc_ = pad_end_points(scsLoc_, -1, +1); if (type == "GaussLegendre") { numQuad_ = (polyOrder % 2 == 0) ? polyOrder/2 + 1 : (polyOrder+1)/2; std::tie(abscissae_, weights_) = gauss_legendre_rule(numQuad_); double isoparametricFactor = 0.5; for (auto& weight : weights_) { weight *= isoparametricFactor; } useSGL_ = false; } else if (type == "SGL") { int numNodes = polyOrder+1; numQuad_ = 1; // only 1 quadrature point per scv std::tie(abscissae_, weights_) = SGL_quadrature_rule(numNodes, scsEndLoc_); useSGL_ = true; } else { ThrowRequireMsg(false, "Invalid quadrature type"); } }
bool BulkData::modification_begin() { Trace_("stk_classic::mesh::BulkData::modification_begin"); parallel_machine_barrier( m_parallel_machine ); ThrowRequireMsg( m_mesh_finalized == false, "Unable to modifiy, BulkData has been finalized."); if ( m_sync_state == MODIFIABLE && m_mesh_finalized == false ) return false ; if ( ! m_meta_data_verified ) { require_metadata_committed(); if (parallel_size() > 1) { verify_parallel_consistency( m_mesh_meta_data , m_parallel_machine ); } m_meta_data_verified = true ; m_bucket_repository.declare_nil_bucket(); } else { ++m_sync_count ; // Clear out the previous transaction information // m_transaction_log.flush(); m_entity_repo.clean_changes(); } m_sync_state = MODIFIABLE ; return true ; }
void EntityRepository::update_entity_key(EntityKey key, Entity & entity) { EntityKey old_key = entity.key(); EntityMap::iterator old_itr = m_entities.find( old_key ); EntityMap::iterator itr = m_entities.find(key); if (itr != m_entities.end()) { Entity* key_entity = itr->second; ThrowRequireMsg( key_entity->log_query() == EntityLogDeleted, "update_entity_key ERROR: non-deleted entity already present for new key (" << key.rank()<<","<<key.id()<<")"); //We found an entity with 'key', we'll change its key to old_key and then //entity (old_itr) will adopt key. key_entity->m_entityImpl.update_key(old_key); //key_entity is already marked for deletion old_itr->second->m_entityImpl.update_key(key); //We also need to swap the entities on these map iterators so that //they map to the right keys: itr->second = old_itr->second; old_itr->second = key_entity; } else { m_entities.insert(std::make_pair(key,&entity)); entity.m_entityImpl.update_key(key); old_itr->second = internal_allocate_entity(old_key); old_itr->second->m_entityImpl.log_deleted(); } }
//-------------------------------------------------------------------------- void PromotedElementIO::write_sideset_definitions( const stk::mesh::PartVector& baseParts) { for(const auto* ip : baseParts) { const auto& part = *ip; stk::mesh::PartVector subsets = part.subsets(); if (subsets.empty()) { continue; } auto sideset = make_unique<Ioss::SideSet>(databaseIO, part.name()); ThrowRequireMsg(sideset != nullptr, "Sideset creation failed"); for (const auto* subpartPtr : subsets) { const auto& subpart = *subpartPtr; const auto subpartTopology = subpart.topology(); if (subpartTopology.rank() != metaData_.side_rank()) { continue; } auto selector = metaData_.locally_owned_part() & subpart; const auto& sideBuckets = bulkData_.get_buckets( metaData_.side_rank(), selector ); const size_t numSubElemsInPart = num_sub_elements(nDim_, sideBuckets, elem_.polyOrder); auto block = make_unique<Ioss::SideBlock>( databaseIO, subpart.name(), subpartTopology.name(), part.topology().name(), numSubElemsInPart ); ThrowRequireMsg(block != nullptr, "Sideblock creation failed"); auto result = sideBlockPointers_.insert({ subpartPtr, block.get() }); ThrowRequireMsg(result.second, "Attempted to add redundant subpart"); sideset->add(block.release()); } output_->add(sideset.release()); } }
void HexFixture::generate_mesh(std::vector<EntityId> & element_ids_on_this_processor, const CoordinateMapping & coordMap) { { //sort and unique the input elements std::vector<EntityId>::iterator ib = element_ids_on_this_processor.begin(); std::vector<EntityId>::iterator ie = element_ids_on_this_processor.end(); std::sort( ib, ie); ib = std::unique( ib, ie); element_ids_on_this_processor.erase(ib, ie); } m_bulk_data.modification_begin(); { // Declare the elements that belong on this process std::vector<EntityId>::iterator ib = element_ids_on_this_processor.begin(); const std::vector<EntityId>::iterator ie = element_ids_on_this_processor.end(); stk::mesh::EntityIdVector elem_nodes(8); for (; ib != ie; ++ib) { EntityId entity_id = *ib; size_t ix = 0, iy = 0, iz = 0; elem_x_y_z(entity_id, ix, iy, iz); elem_nodes[0] = node_id( ix , iy , iz ); elem_nodes[1] = node_id( ix+1 , iy , iz ); elem_nodes[2] = node_id( ix+1 , iy+1 , iz ); elem_nodes[3] = node_id( ix , iy+1 , iz ); elem_nodes[4] = node_id( ix , iy , iz+1 ); elem_nodes[5] = node_id( ix+1 , iy , iz+1 ); elem_nodes[6] = node_id( ix+1 , iy+1 , iz+1 ); elem_nodes[7] = node_id( ix , iy+1 , iz+1 ); stk::mesh::declare_element( m_bulk_data, m_elem_parts, elem_id( ix , iy , iz ) , elem_nodes); for (size_t i = 0; i<8; ++i) { EntityId node_id = elem_nodes[i]; stk::mesh::Entity const node = m_bulk_data.get_entity( stk::topology::NODE_RANK , node_id ); m_bulk_data.change_entity_parts(node, m_node_parts); DoAddNodeSharings(m_bulk_data, m_nodes_to_procs, node_id, node); ThrowRequireMsg( m_bulk_data.is_valid(node), "This process should know about the nodes that make up its element"); // Compute and assign coordinates to the node size_t nx = 0, ny = 0, nz = 0; node_x_y_z(elem_nodes[i], nx, ny, nz); Scalar * data = stk::mesh::field_data( m_coord_field , node ); coordMap.getNodeCoordinates(data, nx, ny, nz); } } } m_bulk_data.modification_end(); }
void MetaData::require_not_relation_target( const Part * const part ) const { std::vector<PartRelation>::const_iterator i_end = part->relations().end(); std::vector<PartRelation>::const_iterator i = part->relations().begin(); for ( ; i != i_end ; ++i ) { ThrowRequireMsg( part != i->m_target, "Part[" << part->name() << "] is a PartRelation target"); } }
void BulkData::require_entity_owner( const Entity & entity , unsigned owner ) const { const bool error_not_owner = owner != entity.owner_rank() ; ThrowRequireMsg( !error_not_owner, "Entity " << print_entity_key(entity) << " owner is " << entity.owner_rank() << ", expected " << owner); }
void copy_mesh_subset(stk::mesh::BulkData &inputBulk, stk::mesh::Selector selectedElems, stk::mesh::BulkData &outputBulk) { ThrowRequireMsg(&inputBulk != &outputBulk, "Can't copy to same mesh."); stk::mesh::MetaData &inputMeta = inputBulk.mesh_meta_data(); stk::mesh::MetaData &outputMeta = outputBulk.mesh_meta_data(); outputMeta.initialize(inputMeta.spatial_dimension(), inputMeta.entity_rank_names()); copy_parts(inputMeta, outputMeta); copy_fields(inputMeta, outputMeta); }
template <class MESHA, class MESHB> void FEInterpolate<MESHA,MESHB>::apply ( MeshB &meshb, const MeshA &mesha, const EntityKeyMap &RangeToDomain){ typedef typename EntityKeyMap::const_iterator const_iterator; const unsigned numValsa = mesha.num_values(); const unsigned numValsb = meshb.num_values(); ThrowRequireMsg (numValsb == numValsa, __FILE__<<":"<<__LINE__<<" Found "<<numValsa<<" values for mesh a and "<<numValsb<<" for mesh b." <<" These should be the same."); for (const_iterator j,i=RangeToDomain.begin(); i!=RangeToDomain.end(); i=j) { j = i; while (j != RangeToDomain.end() && i->first == j->first) ++j; const unsigned num_relations = distance(i, j); const EntityKeyB to_key = i->first; ThrowRequireMsg (1 == num_relations, __FILE__<<":"<<__LINE__<<" Expected "<<1<<" relation."<<" Found:"<<num_relations<<" for Key:"<<to_key); const EntityKeyA domain_index = i->second; const Record *record = meshb.template database<Record>(to_key); const std::vector<double> ¶metric = record->P; std::vector<std::vector<double> > val; mesha.eval_parametric(val, parametric, domain_index); for (unsigned f=0; f<numValsb; ++f) { const unsigned to_field_size = meshb.value_size(to_key, f); const unsigned from_field_size = mesha.value_size(domain_index, f); const unsigned field_size = std::min(to_field_size, from_field_size); double *c = meshb.value(to_key, f); for (unsigned n=0; n<field_size; ++n) c[n] = val[f][n]; } } }
BucketVector const& Selector::get_buckets(EntityRank entity_rank) const { static BucketVector emptyBucketVector; if (m_expr.empty()) { return emptyBucketVector; } BulkData* mesh = find_mesh(); ThrowRequireMsg(mesh != NULL, "ERROR, Selector::get_buckets not available if selector expression does not involve any mesh Parts."); return mesh->get_buckets(entity_rank, *this); }
void MeshDiagnosticObserver::gather_new_errors(std::ofstream & out, const std::vector<std::string> & errorList) { for (const std::string & error : errorList) { std::pair<std::unordered_set<std::string>::iterator, bool> result = m_errorDatabase.insert(error); if (result.second) { out << error; if(m_throwOnError) ThrowRequireMsg( false, "Mesh diagnostic rule failure: " + error ); } } }
//-------------------------------------------------------------------------- void PromotedElementIO::write_node_block_definitions( const stk::mesh::PartVector& superElemParts) { const auto& nodeBuckets = bulkData_.get_buckets( stk::topology::NODE_RANK, stk::mesh::selectUnion(superElemParts)); auto nodeCount = count_entities(nodeBuckets); auto nodeBlock = make_unique<Ioss::NodeBlock>( databaseIO, "nodeblock", nodeCount, nDim_); ThrowRequireMsg(nodeBlock != nullptr, "Node block creation failed"); nodeBlock_ = nodeBlock.get(); output_->add(nodeBlock.release()); }
// This code was copied from bulk data and used to remove entities // from buckets. In order to remove an entity, an appropriate entity // must be found to copy into the hole. This logic will find the // appropriate bucket which has an entity to copy into the bucket. void Transaction::remove_entity_from_bucket ( Entity &e , BucketList &buckets ) { Bucket *k = e.m_trans_bucket; unsigned i = e.m_trans_bucket_ord; Bucket * const first = k->m_key[ *k->m_key ] ? k->m_bucket : k ; Bucket * const last = first->m_bucket ; // Only move if not the last entity being removed if ( last != k || k->m_size != i + 1 ) { // Not the same bucket or not the last entity // Copy last entity in last to ik slot i Entity * const entity = last->m_entities[ last->m_size - 1 ]; k->m_entities[i] = entity ; entity->m_trans_bucket = k ; entity->m_trans_bucket_ord = i ; } --( last->m_size ); if ( last->m_size != 0 ) { last->m_entities[ last->m_size ] = NULL ; } else { // The current 'last' bucket is to be deleted. // The previous 'last' bucket becomes the // new 'last' bucket in the family: std::vector<Bucket*>::iterator ik = lower_bound(buckets, last->m_key); ThrowRequireMsg( ik != buckets.end() && last == *ik, "Internal failure during removal of entity " << print_entity_key(e) ); ik = buckets.erase( ik ); if ( first != last ) { first->m_bucket = *--ik ; } Bucket::destroy_bucket( last ); } e.m_trans_bucket = NULL; }
unsigned value_size(const EntityKey k, const unsigned i=0) const { const mesh::Entity e = entity(k); const mesh::FieldBase &field = *m_values_field[i]; const mesh::Bucket &bucket= m_bulk_data.bucket(e); const unsigned bytes = field_bytes_per_entity(field, bucket); const unsigned bytes_per_entry = field.data_traits().size_of; const unsigned num_entry = bytes/bytes_per_entry; ThrowRequireMsg (bytes == num_entry * bytes_per_entry, __FILE__<<":"<<__LINE__<<" Error:" <<" bytes:" <<bytes<<" num_entry:" <<num_entry <<" bytes_per_entry:" <<bytes_per_entry); return num_entry; }
std::vector<std::pair<uint64_t, uint64_t> > GenerateGlobalPairedList(std::vector<uint64_t>& localOrderArray, std::vector<uint64_t>& newIdsLocal, stk::ParallelMachine comm) { ThrowRequireMsg(localOrderArray.size() == newIdsLocal.size(),"Inconsistent Sizes in GenerateGlobalPairedList"); std::vector<std::pair<uint64_t, uint64_t> > idOrderPairsLocal; std::vector<std::pair<uint64_t, uint64_t> > idOrderPairsGlobal; for(uint64_t i = 0; i < localOrderArray.size(); ++i) { idOrderPairsLocal.push_back(std::pair<uint64_t, uint64_t>(localOrderArray[i], newIdsLocal[i])); } stk::parallel_vector_concat(comm, idOrderPairsLocal, idOrderPairsGlobal); std::sort(idOrderPairsGlobal.begin(), idOrderPairsGlobal.end()); return idOrderPairsGlobal; }
inline void createBoundingBoxesForSidesInSidesets(const stk::mesh::BulkData& bulk, std::vector<FloatBox>& domainBoxes) { stk::mesh::ExodusTranslator exoTranslator(bulk); size_t numberBoundingBoxes = 0; std::vector<int64_t> sidesetIds; exoTranslator.fill_side_set_ids(sidesetIds); for (size_t i=0;i<sidesetIds.size();i++) { numberBoundingBoxes += exoTranslator.get_local_num_entities_for_id(sidesetIds[i], bulk.mesh_meta_data().side_rank()); } domainBoxes.resize(numberBoundingBoxes); stk::mesh::FieldBase const * coords = bulk.mesh_meta_data().coordinate_field(); size_t boxCounter = 0; std::vector<double> boxCoordinates(6); for (size_t ssetCounter=0;ssetCounter<sidesetIds.size();ssetCounter++) { const stk::mesh::Part* sideset = exoTranslator.get_exodus_part_of_rank(sidesetIds[ssetCounter], bulk.mesh_meta_data().side_rank()); stk::mesh::EntityVector sides; stk::mesh::Selector sel = bulk.mesh_meta_data().locally_owned_part() & *sideset; stk::mesh::get_selected_entities(sel, bulk.buckets(bulk.mesh_meta_data().side_rank()), sides); for(size_t j=0;j<sides.size();++j) { unsigned num_nodes_per_side = bulk.num_nodes(sides[j]); const stk::mesh::Entity* nodes = bulk.begin_nodes(sides[j]); std::vector<double> coordinates(3*num_nodes_per_side,0); for(unsigned k=0;k<num_nodes_per_side;++k) { double *data = static_cast<double*>(stk::mesh::field_data(*coords, nodes[k])); coordinates[3*k] = data[0]; coordinates[3*k+1] = data[1]; coordinates[3*k+2] = data[2]; } findBoundingBoxCoordinates(coordinates, boxCoordinates); domainBoxes[boxCounter].set_box(boxCoordinates[0], boxCoordinates[1], boxCoordinates[2], boxCoordinates[3], boxCoordinates[4], boxCoordinates[5]); boxCounter++; } } ThrowRequireMsg(boxCounter == numberBoundingBoxes, "Program error. Please contact sierra-help for support"); }
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."); } } }
inline stk::search::SearchMethod mapSearchMethodToStk( NewSearchMethod method ) { if ( method == BOOST_RTREE ) { return stk::search::BOOST_RTREE; } else if ( method == OCTREE ) { return stk::search::OCTREE; } else if ( method == GTK ) { return stk::search::KDTREE; } else { ThrowRequireMsg(false, "GTK method not implemented for this."); } return stk::search::BOOST_RTREE; }
bool Selector::is_empty(EntityRank entity_rank) const { if (m_expr.empty()) { return true; } BulkData * mesh = this->find_mesh(); ThrowRequireMsg(mesh != NULL, "ERROR, Selector::empty not available if selector expression does not involve any mesh Parts."); if (mesh->in_modifiable_state()) { BucketVector const& buckets = this->get_buckets(entity_rank); for(size_t i=0; i<buckets.size(); ++i) { if (buckets[i]->size() >0) { return false; } } return true; } return get_buckets(entity_rank).empty(); }
//-------------------------------------------------------------------------- void PromotedElementIO::add_fields(const std::vector<stk::mesh::FieldBase*>& fields) { output_->begin_mode(Ioss::STATE_DEFINE_TRANSIENT); for (const auto* fieldPtr : fields) { if (fieldPtr == nullptr) { continue; } const auto& field = *fieldPtr; auto result = fields_.insert({fieldPtr->name(),fieldPtr}); bool wasFieldAdded = result.second; if (wasFieldAdded) { int nb_size = nodeBlock_->get_property("entity_count").get_int(); auto iossType = Ioss::Field::DOUBLE; if (field.type_is<uint32_t>() || field.type_is<int32_t>()) { iossType = Ioss::Field::INT32; } else if (field.type_is<uint64_t>() || field.type_is<int64_t>()) { iossType = Ioss::Field::INT64; } else { ThrowRequireMsg(field.type_is<double>(), "Only (u)int32, (u)int64, and double fields supported"); } nodeBlock_->field_add( Ioss::Field( field.name(), iossType, storage_name(field), Ioss::Field::TRANSIENT, nb_size ) ); } } output_->end_mode(Ioss::STATE_DEFINE_TRANSIENT); }
//-------------------------------------------------------------------------- void PromotedElementIO::write_database_data(double currentTime) { output_->begin_mode(Ioss::STATE_TRANSIENT); int current_output_step = output_->add_state(currentTime); output_->begin_state(current_output_step); stk::mesh::BucketVector const& nodeBuckets = bulkData_.get_buckets( stk::topology::NODE_RANK, stk::mesh::selectUnion(superElemParts_)); std::vector<int64_t> ids; nodeBlock_->get_field_data("ids", ids); for (const auto& pair : fields_) { ThrowRequire(pair.second != nullptr); const stk::mesh::FieldBase& field = *pair.second; if (field.type_is<int>()) { put_data_on_node_block<int32_t>(*nodeBlock_, ids, field, nodeBuckets); } else if (field.type_is<uint32_t>()) { put_data_on_node_block<uint32_t>(*nodeBlock_, ids, field, nodeBuckets); } else if (field.type_is<int64_t>()) { put_data_on_node_block<int64_t>(*nodeBlock_, ids, field, nodeBuckets); } else if (field.type_is<uint64_t>()) { put_data_on_node_block<uint64_t>(*nodeBlock_, ids, field, nodeBuckets); } else if (field.type_is<double>()) { put_data_on_node_block<double>(*nodeBlock_, ids, field, nodeBuckets); } else { ThrowRequireMsg(false, "Unsupported type for output"); } } output_->end_state(current_output_step); output_->end_mode(Ioss::STATE_TRANSIENT); }