Skip to content

Commit 416417e

Browse files
authored
adding the base structure for on the fly amalgamation (#4)
* fix constructor issue * not avoiding code repetation * addressing suggestion from @gonuke * addresing suggestions * fix cluster_element_integer_index_ name * better variable name * better variable name * fix get bin from elem method * api change * API change * allow mesh amalgamation with/without AMR
1 parent a343653 commit 416417e

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

include/openmc/mesh.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,10 @@ class LibMesh : public UnstructuredMesh {
991991

992992
libMesh::MeshBase* mesh_ptr() const { return m_; };
993993

994+
995+
//!setter for mesh tally amalgamtion
996+
void set_mesh_tally_amalgamation(std::string cluster_element_integer_name);
997+
994998
private:
995999
void initialize() override;
9961000
void set_mesh_pointer_from_filename(const std::string& filename);
@@ -1030,6 +1034,17 @@ class LibMesh : public UnstructuredMesh {
10301034
//!< elements
10311035
std::vector<int> elem_to_bin_map_; //!< mapping dof indices to bin indices for
10321036
//!< active elements
1037+
1038+
bool amalgamation_ = false ; //!< whether we are doing mesh and tally amalgamation
1039+
//!< by default it's turned off.
1040+
1041+
int cluster_element_integer_index_ = -1 ; //!< extra element integer index for element clustering
1042+
/*create a hash map where every element in a cluster would map to the first element of in that cluster
1043+
* if the element isn't part of a cluster then it will point to it self
1044+
* <any_element_in_a_cluster, first element in that cluster >
1045+
*/
1046+
std::unordered_map<const libMesh::Elem*, const libMesh::Elem*> clustering_element_mapping_;
1047+
10331048
};
10341049

10351050
#endif

src/mesh.cpp

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
32423279
LibMesh::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
33293367
Position 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

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

Comments
 (0)