//-------------------------------------------------------------------------- void PromotedElementIO::write_coordinate_list(const stk::mesh::PartVector& superElemParts) { const auto& nodeBuckets = bulkData_.get_buckets(stk::topology::NODE_RANK, stk::mesh::selectUnion(superElemParts)); auto nodeCount = count_entities(nodeBuckets); std::vector<int64_t> node_ids; std::vector<double> coordvec; node_ids.reserve(nodeCount); coordvec.reserve(nodeCount*nDim_); size_t numCoords = nodeCount * nDim_; for (const auto* ib : nodeBuckets) { const stk::mesh::Bucket& b = *ib; const stk::mesh::Bucket::size_type length = b.size(); for (stk::mesh::Bucket::size_type k = 0; k < length; ++k) { const auto& node = b[k]; node_ids.push_back(bulkData_.identifier(node)); const double* coords = stk::mesh::field_data(coordinates_,node); for (unsigned j = 0; j < nDim_; ++j) { coordvec.push_back(coords[j]); } } } nodeBlock_->put_field_data("ids", node_ids); nodeBlock_->put_field_data("mesh_model_coordinates", coordvec.data(), numCoords * sizeof(double)); }
//-------------------------------------------------------------------------- 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()); }
//-------------------------------------------------------------------------- template<typename T> void PromotedElementIO::put_data_on_node_block( Ioss::NodeBlock& nodeBlock, const std::vector<int64_t>& ids, const stk::mesh::FieldBase& field, const stk::mesh::BucketVector& buckets) const { ThrowRequire(field.type_is<T>()); int fieldLength = field.max_size(stk::topology::NODE_RANK); std::vector<T> flatArray(count_entities(buckets)*fieldLength); size_t index = 0; for (size_t k = 0; k < ids.size(); ++k) { stk::mesh::Entity node = bulkData_.get_entity(stk::topology::NODE_RANK, ids[k]); const T* field_data = static_cast<T*>(stk::mesh::field_data(field, node)); for (int j = 0; j < fieldLength; ++j) { flatArray[index] = (field_data != nullptr) ? field_data[j] : 0.0; ++index; } } nodeBlock.put_field_data(field.name(), flatArray.data(), flatArray.size() * sizeof(T)); }
void compute_memory_usage(const BulkData& bulk, MemoryUsage& mem_usage) { mem_usage.entity_rank_names = bulk.mesh_meta_data().entity_rank_names(); const FieldVector& fields = bulk.mesh_meta_data().get_fields(); mem_usage.num_fields = fields.size(); mem_usage.field_bytes = fields.size()*sizeof(FieldBase); for(size_t i=0; i<fields.size(); ++i) { mem_usage.field_bytes += fields[i]->name().length(); mem_usage.field_bytes += sizeof(FieldRestriction)*fields[i]->restrictions().size(); } const PartVector& parts = bulk.mesh_meta_data().get_parts(); mem_usage.num_parts = parts.size(); mem_usage.part_bytes = parts.size()*sizeof(Part); for(size_t i=0; i<parts.size(); ++i) { mem_usage.part_bytes += parts[i]->name().length(); mem_usage.part_bytes += sizeof(Part*) * parts[i]->supersets().size(); mem_usage.part_bytes += sizeof(Part*) * parts[i]->subsets().size(); } size_t total_bytes = mem_usage.field_bytes + mem_usage.part_bytes; mem_usage.entity_counts.clear(); mem_usage.downward_relation_counts.clear(); mem_usage.upward_relation_counts.clear(); mem_usage.bucket_counts.clear(); mem_usage.bucket_bytes.clear(); Selector all = bulk.mesh_meta_data().universal_part(); count_entities(all, bulk, mem_usage.entity_counts); size_t nranks = mem_usage.entity_counts.size(); mem_usage.downward_relation_counts.resize(nranks, 0); mem_usage.upward_relation_counts.resize(nranks, 0); mem_usage.bucket_counts.resize(nranks, 0); mem_usage.bucket_bytes.resize(nranks, 0); std::vector<Entity> entities; for(size_t i=0; i<nranks; ++i) { EntityRank rank_i = static_cast<EntityRank>(i); total_bytes += mem_usage.entity_counts[rank_i]*sizeof(Entity); get_entities(bulk, rank_i, entities); for(size_t n=0; n<entities.size(); ++n) { Entity entity = entities[n]; for(EntityRank r=stk::topology::NODE_RANK; r<rank_i; ++r) { unsigned num_rels = bulk.num_connectivity(entity, r); mem_usage.downward_relation_counts[r] += num_rels; ThrowErrorMsg("stk::mesh::compute_memory_usage need to be largely re-written for the new Connectivity scheme but is not needed for this 4.27.7."); } for(EntityRank r=static_cast<EntityRank>(rank_i+1); r<nranks; ++r) { unsigned num_rels = bulk.num_connectivity(entity, r); mem_usage.upward_relation_counts[r] += num_rels; ThrowErrorMsg("stk::mesh::compute_memory_usage need to be largely re-written for the new Connectivity scheme but is not needed for this 4.27.7."); } } const BucketVector& buckets = bulk.buckets(rank_i); mem_usage.bucket_counts[rank_i] = buckets.size(); for(size_t b=0; b<buckets.size(); ++b) { Bucket& bucket = *buckets[b]; mem_usage.bucket_bytes[rank_i] += bucket.allocation_size(); total_bytes += bucket.allocation_size(); } } mem_usage.total_bytes = total_bytes; }