Skip to content

Commit 2a802a1

Browse files
committed
Add warning of possible overflow.
1 parent b7cbd59 commit 2a802a1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/openmc/constants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ enum class RunMode {
339339

340340
enum class GeometryType { CSG, DAG };
341341

342+
//==============================================================================
343+
// Volume Calculation Constants
344+
345+
constexpr size_t SIZE_T_MAX {std::numeric_limits<size_t>::max()};
346+
342347
} // namespace openmc
343348

344349
#endif // OPENMC_CONSTANTS_H

src/volume_calc.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ vector<VolumeCalculation::Result> VolumeCalculation::execute() const
225225
iterations++;
226226
size_t total_samples = iterations * n_samples_;
227227

228+
// warn user if total sample size is greater than what the size_t type can
229+
// represent
230+
if (total_samples > SIZE_T_MAX) {
231+
warning("The number of samples has exceeded the size_t type. Volume "
232+
"results may be inaccurate.");
233+
}
234+
228235
// reset
229236
double trigger_val = -INFTY;
230237

0 commit comments

Comments
 (0)