diff --git a/include/openmc/distribution_spatial.h b/include/openmc/distribution_spatial.h index 63cbbb956..dc1d898fe 100644 --- a/include/openmc/distribution_spatial.h +++ b/include/openmc/distribution_spatial.h @@ -114,7 +114,7 @@ public: private: int32_t mesh_idx_ {C_NONE}; - UPtrDist elem_idx_; //!< Distribution of mesh element indices + UPtrDist elem_idx_dist_; //!< Distribution of mesh element indices }; //============================================================================== diff --git a/src/distribution_spatial.cpp b/src/distribution_spatial.cpp index 206f0b597..544734d3b 100644 --- a/src/distribution_spatial.cpp +++ b/src/distribution_spatial.cpp @@ -224,8 +224,15 @@ MeshSpatial::MeshSpatial(pugi::xml_node node) "not match the number of entities in mesh {} ({}).", strengths.size(), mesh_id, n_bins)); } - elem_idx_ = UPtrDist {new Discrete {strengths, n_bins}}; } + + if (get_node_value_bool(node, "volume_normalized")) { + for (int i = 0; i < n_bins; i++) { + strengths[i] *= mesh()->volume(i); + } + } + + elem_idx_dist_ = UPtrDist {new Discrete {strengths, n_bins}}; } @@ -234,7 +241,7 @@ Position MeshSpatial::sample(uint64_t* seed) const // Create random variable for sampling element from mesh double eta = prn(seed); // Sample over the CDF defined in initialization above - int32_t elem_idx = elem_idx_->sample(eta); + int32_t elem_idx = elem_idx_dist_->sample(eta); return mesh()->sample(seed, elem_idx); }