@@ -3238,6 +3238,43 @@ LibMesh::LibMesh(libMesh::MeshBase& input_mesh, double length_multiplier)
32383238 initialize ();
32393239}
32403240
3241+
3242+ void
3243+ LibMesh::set_mesh_tally_amalgamation (std::string cluster_element_integer_name){
3244+
3245+ cluster_element_integer_index_ = m_->has_elem_integer (cluster_element_integer_name)
3246+ ? m_->get_elem_integer_index (cluster_element_integer_name)
3247+ : -1 ;
3248+ amalgamation_ = (cluster_element_integer_index_ != -1 );
3249+
3250+ // should we add a warning if amalgamation is false?
3251+
3252+ if (amalgamation_) {
3253+
3254+ // reseve the hash map for cluster elements
3255+ clustering_element_mapping_.reserve (m_->n_active_elem ());
3256+
3257+ // adding clustering map
3258+ for (auto it = m_->active_elements_begin (); it != m_->active_elements_end (); it++) {
3259+
3260+ auto elem = *it;
3261+ auto cluster_elem = elem;
3262+ unsigned int cluster_id = elem->get_extra_integer (cluster_element_integer_index_);
3263+
3264+ if (cluster_id != -1 ) {
3265+ auto first_element_in_a_cluster = m_->elem_ptr (cluster_id);
3266+
3267+ if (first_element_in_a_cluster and first_element_in_a_cluster->active ())
3268+ cluster_elem = first_element_in_a_cluster;
3269+ }
3270+ clustering_element_mapping_.insert (std::make_pair (elem, cluster_elem));
3271+
3272+ }
3273+ }
3274+
3275+
3276+ }
3277+
32413278// create the mesh from an input file
32423279LibMesh::LibMesh (const std::string& filename, double length_multiplier)
32433280 : adaptive_(false )
@@ -3309,7 +3346,7 @@ void LibMesh::initialize()
33093346 bin_to_elem_map_.reserve (m_->n_active_elem ());
33103347 elem_to_bin_map_.resize (m_->n_elem (), -1 );
33113348 for (auto it = m_->active_elements_begin (); it != m_->active_elements_end ();
3312- it++) {
3349+ it++) {
33133350 auto elem = *it;
33143351
33153352 bin_to_elem_map_.push_back (elem->id ());
@@ -3325,6 +3362,7 @@ void LibMesh::initialize()
33253362 upper_right_ = {ur (0 ), ur (1 ), ur (2 )};
33263363}
33273364
3365+
33283366// Sample position within a tet for LibMesh type tets
33293367Position LibMesh::sample_element (int32_t bin, uint64_t * seed) const
33303368{
@@ -3468,7 +3506,7 @@ void LibMesh::set_score_data(const std::string& var_name,
34683506 unsigned int std_dev_num = variable_map_.at (std_dev_name);
34693507
34703508 for (auto it = m_->local_elements_begin (); it != m_->local_elements_end ();
3471- it++) {
3509+ it++) {
34723510 if (!(*it)->active ()) {
34733511 continue ;
34743512 }
@@ -3532,8 +3570,9 @@ int LibMesh::get_bin(Position r) const
35323570
35333571int LibMesh::get_bin_from_element (const libMesh::Elem* elem) const
35343572{
3535- int bin =
3536- adaptive_ ? elem_to_bin_map_[elem->id ()] : elem->id () - first_element_id_;
3573+ auto tally_elem = amalgamation_ ? clustering_element_mapping_.at (elem) : elem;
3574+ int bin = adaptive_ ? elem_to_bin_map_[tally_elem->id ()] : tally_elem->id () - first_element_id_;
3575+
35373576 if (bin >= n_bins () || bin < 0 ) {
35383577 fatal_error (fmt::format (" Invalid bin: {}" , bin));
35393578 }
0 commit comments