Add warning of possible overflow.

This commit is contained in:
Patrick Shriwise 2022-10-19 13:23:26 -05:00
parent b7cbd59a13
commit 2a802a11a4
2 changed files with 12 additions and 0 deletions

View file

@ -339,6 +339,11 @@ enum class RunMode {
enum class GeometryType { CSG, DAG };
//==============================================================================
// Volume Calculation Constants
constexpr size_t SIZE_T_MAX {std::numeric_limits<size_t>::max()};
} // namespace openmc
#endif // OPENMC_CONSTANTS_H

View file

@ -225,6 +225,13 @@ vector<VolumeCalculation::Result> VolumeCalculation::execute() const
iterations++;
size_t total_samples = iterations * n_samples_;
// warn user if total sample size is greater than what the size_t type can
// represent
if (total_samples > SIZE_T_MAX) {
warning("The number of samples has exceeded the size_t type. Volume "
"results may be inaccurate.");
}
// reset
double trigger_val = -INFTY;