# Negative volume value

**URL:** <https://openmc.discourse.group/t/negative-volume-value/832>\
**Category:** User Support\
**Created:** [October 26, 2020, 7:42am UTC](https://openmc.discourse.group/t/negative-volume-value/832 "2020-10-26T07:42:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingyue](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/kingyue/32/507_2.png) [@kingyue](https://openmc.discourse.group/u/kingyue)\
**Post date:** [October 26, 2020, 7:42am UTC](https://openmc.discourse.group/t/negative-volume-value/832/1 "2020-10-26T07:42:07Z")

</div>

There is a negative value in the result obtained by OpenMC’s volume calculation shown below. The trigger of the calculation is 1E-3 relative error.  
The volume of this cell is much larger than other cells’. If I remove the smallest cells from the list of cell to calculate, the result becomes correct.  
Could this be due to an overflow?

 ![volume_bug](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/c/ceb066979ccec64a91962e128c360e8a43bd0491.png)

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [October 28, 2020, 3:20am UTC](https://openmc.discourse.group/t/negative-volume-value/832/2 "2020-10-28T03:20:15Z")

</div>

Thanks for reporting @kingyue. Do you have a script/model you can share that can reproduce this behavior?

---

<div class="post-metadata">

**Author:** ![kingyue](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/kingyue/32/507_2.png) [@kingyue](https://openmc.discourse.group/u/kingyue)\
**Post date:** [November 2, 2020, 7:33am UTC](https://openmc.discourse.group/t/negative-volume-value/832/3 "2020-11-02T07:33:33Z")

</div>

I’m not allowed to upload this model. I will try to reproduce this behavior with other models.

---

<div class="post-metadata">

**Author:** ![LucasB](https://avatars.discourse-cdn.com/v4/letter/l/aeb1de/32.png) [@LucasB](https://openmc.discourse.group/u/LucasB)\
**Post date:** [September 23, 2022, 11:59pm UTC](https://openmc.discourse.group/t/negative-volume-value/832/4 "2022-09-23T23:59:19Z")

</div>

I wanted to add something here since I was having the same issue. I found that commenting out the set\_trigger line in Python fixed it. Furthermore, when I had the std\_dev trigger set, the volume calculation would take about an hour, regardless of how many samples I used (I tried 100 to 1,000,000), or what I set the std\_dev to (tried 1e-2 to 1e-5). I also tried it with and without a defined bounding box, which made no difference. After commenting that line out, it only took a few seconds, even with 1,000,000 samples. I can’t share my model, but I hope this is helpful.

---

<div class="post-metadata">

**Author:** ![pshriwise](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/pshriwise/32/3863_2.png) [@pshriwise](https://openmc.discourse.group/u/pshriwise)\
**Post date:** [October 19, 2022, 6:59pm UTC](https://openmc.discourse.group/t/negative-volume-value/832/5 "2022-10-19T18:59:56Z")

</div>

Hi @kingyue, @LucasB

Thanks for reporting this issue! I took a look at this using the BEAVRS benchmark (found [here](https://github.com/mit-crpg/beavrs)) and could reproduce the negative volume values. This was caused by overflow in the `int` type used to track the total number of hits for a given cell/material/universe during the volume calculation process. I’ve created [this pr](https://github.com/openmc-dev/openmc/pull/2270) to address that.

The other side of this is that the number of samples, N, required to reach the value specified on the trigger may be very, very large. Like any value computed in a Monte Carlo process the std. dev. will decrease as 1/\sqrt{N}. As an example, one of the cells in the BEAVRS model had a result of

```auto
 Cell 76: 37701.4920406969 +/- 11.265745477911146

```

after 3.18 \times 10^{10} samples, so a std. dev. of 1e-2 would take an estimated 4 \times 10^{16} samples 🤯. While using relative error as the trigger type is probably more tractable, even that can result in some really large sample sizes – as we see in @kingyue’s case.

The updates I’ve made allow for a much higher number of samples and I’ve added a warning if the number of samples exceeds the max value of the C++ type we’re using now (`uint64_t`) to count samples and hits in cells/materials/universes, but this _can_ still happen. Just something to keep in mind when using the triggers in the volume calculations.

-Patrick

---

<div class="post-metadata">

**Author:** ![pshriwise](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/pshriwise/32/3863_2.png) [@pshriwise](https://openmc.discourse.group/u/pshriwise)\
**Post date:** [October 22, 2022, 3:20am UTC](https://openmc.discourse.group/t/negative-volume-value/832/6 "2022-10-22T03:20:33Z")

</div>

Just wanted to note here that this fix is part of the latest OpenMC release and is ready for use [Release OpenMC 0.13.2 · openmc-dev/openmc · GitHub](https://github.com/openmc-dev/openmc/releases/tag/v0.13.2)
