Skip to content

Commit 161bfd0

Browse files
committed
use new API for adaptive mesh
1 parent 767db7e commit 161bfd0

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

include/openmc/mesh.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,9 @@ class AdaptiveLibMesh : public LibMesh {
10411041

10421042
void write(const std::string& filename) const override;
10431043

1044+
//! setter for mesh tally amalgamtion
1045+
void set_mesh_tally_amalgamation(std::string cluster_element_integer_name);
1046+
10441047
protected:
10451048
// Overridden methods
10461049
int get_bin_from_element(const libMesh::Elem* elem) const override;
@@ -1056,6 +1059,20 @@ class AdaptiveLibMesh : public LibMesh {
10561059
//!< elements
10571060
std::vector<int> elem_to_bin_map_; //!< mapping dof indices to bin indices for
10581061
//!< active elements
1062+
1063+
bool amalgamation_ = false; //!< whether we are doing mesh and tally
1064+
//!< amalgamation by default it's turned off.
1065+
1066+
int clustering_element_integer_index_ = -1; //!< extra element integer index for
1067+
// element clustering
1068+
1069+
/*create a hash map where every element in a cluster would map to the first
1070+
* element of in that cluster if the element isn't part of a cluster then it
1071+
* will point to it self <any_element_in_a_cluster, first element in that
1072+
* cluster >
1073+
*/
1074+
std::unordered_map<const libMesh::Elem*, const libMesh::Elem*>
1075+
clustering_element_mapping_;
10591076
};
10601077

10611078
#endif

src/mesh.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
35403578
int AdaptiveLibMesh::n_bins() const
35413579
{
35423580
return num_active_;
@@ -3566,7 +3604,9 @@ void AdaptiveLibMesh::write(const std::string& filename) const
35663604

35673605
int 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

Comments
 (0)