@@ -3537,6 +3537,44 @@ AdaptiveLibMesh::AdaptiveLibMesh(
35373537 }
35383538}
35393539
3540+ void AdaptiveLibMesh::set_mesh_tally_amalgamation (
3541+ std::string cluster_element_integer_name)
3542+ {
3543+
3544+ clustering_element_integer_index_ =
3545+ m_->has_elem_integer (cluster_element_integer_name)
3546+ ? m_->get_elem_integer_index (cluster_element_integer_name)
3547+ : -1 ;
3548+ amalgamation_ = (clustering_element_integer_index_ != -1 );
3549+
3550+ if (amalgamation_) {
3551+ // reseve the hash map for cluster elements
3552+ clustering_element_mapping_.reserve (m_->n_active_elem ());
3553+
3554+ // adding clustering map
3555+ for (auto it = m_->active_elements_begin (); it != m_->active_elements_end ();
3556+ it++) {
3557+
3558+ auto elem = *it;
3559+ auto cluster_elem = elem;
3560+ unsigned int cluster_id =
3561+ elem->get_extra_integer (clustering_element_integer_index_);
3562+
3563+ if (cluster_id != -1 ) {
3564+ auto first_element_in_a_cluster = m_->elem_ptr (cluster_id);
3565+
3566+ if (first_element_in_a_cluster and first_element_in_a_cluster->active ())
3567+ cluster_elem = first_element_in_a_cluster;
3568+ }
3569+ clustering_element_mapping_.insert (std::make_pair (elem, cluster_elem));
3570+ }
3571+ }
3572+ else {
3573+ fatal_error (fmt::format (" No extra element integer named: {} found in the "
3574+ " mesh" , cluster_element_integer_name));
3575+ }
3576+ }
3577+
35403578int AdaptiveLibMesh::n_bins () const
35413579{
35423580 return num_active_;
@@ -3566,7 +3604,9 @@ void AdaptiveLibMesh::write(const std::string& filename) const
35663604
35673605int AdaptiveLibMesh::get_bin_from_element (const libMesh::Elem* elem) const
35683606{
3569- int bin = elem_to_bin_map_[elem->id ()];
3607+ auto tally_elem = amalgamation_ ? clustering_element_mapping_.at (elem) : elem;
3608+ int bin = adaptive_ ? elem_to_bin_map_[tally_elem->id ()]
3609+ : tally_elem->id () - first_element_id_;
35703610 if (bin >= n_bins () || bin < 0 ) {
35713611 fatal_error (fmt::format (" Invalid bin: {}" , bin));
35723612 }
0 commit comments