rename variable for clarity; re-add volume normalization

This commit is contained in:
Paul P.H. Wilson 2023-03-16 17:51:41 -05:00
parent ee6975767d
commit db92a64ec9
2 changed files with 10 additions and 3 deletions

View file

@ -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
};
//==============================================================================

View file

@ -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);
}