# Photon flux with NaN value

**URL:** <https://openmc.discourse.group/t/photon-flux-with-nan-value/1122>\
**Category:** User Support\
**Created:** [April 11, 2021, 3:26pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122 "2021-04-11T15:26:24Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaryAAZ](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/maryaaz/32/1244_2.png) [@MaryAAZ](https://openmc.discourse.group/u/MaryAAZ)\
**Post date:** [April 11, 2021, 3:26pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/1 "2021-04-11T15:26:24Z")

</div>

Hello all,

I am having an issue in a shielding simulation. My model consists of different cylinders, each one filled with a different material (see figure). In the center, I have positioned two point sources, one neutron source and the other is a photon source. As I have both energy spectra, I am using openmc.stats.Tabular to inform them (following the recommendations in this [post](https://openmc.discourse.group/t/source-energy-distribution-for-neutron-of-different-energy-group/477)). I wish to tally the fluxes, then I created a mesh (101 x 101 elements) and particle filters.

![image](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/5/5dd4f6ac7e7a642b6b6e171b57907730c3ff3e2f.png)

The mesh has 10 201 elements. Then, the number of particles (200 000) divided by the total number of mesh elements is around 20 (following the recommendations in this [post](https://openmc.discourse.group/t/source-convergence-problem/869)). The simulation went okay. I tried to load the results by using:

sp = openmc.StatePoint(‘statepoint.300.h5’)  
tally\_flux\_photons = sp.get\_tally(name=‘Half Domain Photons’).get\_pandas\_dataframe()

but in the ‘tally\_flux\_photons’ DataFrame the ‘mean’ column does not appear. Then, looking at the ‘tallies.out’ file, I realized that I am getting a photon flux equals to ‘NaN’. However, when doing the same simulation using 25 000 particles l do not have this issue. The number of batches is 300 in both cases.

[Here](https://drive.google.com/drive/folders/1o4vgzEDG6wYBXaaxwHUGLUGwBsme57h8?usp=sharing) are the two ‘tallies.out’ files.

Please, someone could tell what is causing this issue?

Thank you,  
Maria

---

<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:** [April 12, 2021, 11:55am UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/2 "2021-04-12T11:55:40Z")

</div>

Hi @MaryAAZ. This sounds like it could potentially be a bug in the code if you are getting NaNs. Are you able to share the model or a simplified version that shows the same behavior? Unfortunately with just the talles.out files, there’s not much I can do to diagnose the problem.

---

<div class="post-metadata">

**Author:** ![MaryAAZ](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/maryaaz/32/1244_2.png) [@MaryAAZ](https://openmc.discourse.group/u/MaryAAZ)\
**Post date:** [April 13, 2021, 7:50pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/3 "2021-04-13T19:50:46Z")

</div>

Hello @paulromano. Thanks for your reply. Unfortunately, I cannot share publicly the files. I sent you a message with the xml files. Please, let me know if you need more information about my model.

Thank you,  
Maria

---

<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:** [April 14, 2021, 3:39pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/4 "2021-04-14T15:39:17Z")

</div>

Thanks for sharing the model Maria. I was able to track down the issue and have a fix [submitted for review](https://github.com/openmc-dev/openmc/pull/1816). Unfortunately I don’t have a good workaround for your model; the best I can suggest is to install the developmental version of the code once the above fix has been merged.

---

<div class="post-metadata">

**Author:** ![MaryAAZ](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/maryaaz/32/1244_2.png) [@MaryAAZ](https://openmc.discourse.group/u/MaryAAZ)\
**Post date:** [April 14, 2021, 7:45pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/5 "2021-04-14T19:45:17Z")

</div>

Thank you @paulromano

---

<div class="post-metadata">

**Author:** ![MaryAAZ](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/maryaaz/32/1244_2.png) [@MaryAAZ](https://openmc.discourse.group/u/MaryAAZ)\
**Post date:** [April 24, 2021, 2:31pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/6 "2021-04-24T14:31:50Z")

</div>

Hello all,

Thanks @paulromano. I was able to run my simulations in the development branch and I did not get ‘NaN’ values. My simulations are with 500 000 particles and 300 batches.

I have a few questions:

1. The number of particles divided by the total number of mesh elements (101x101) is around 49. Should I adjust the number of particles or the number of elements in the mesh to obtain a ratio ~20, or I can keep the settings previously mentioned?

2. I would like to know how the software treats a problem where two point sources (neutron and Gamma sources) are defined, and the photon transport is activated?

3. I created a mesh in 2D (model in 2D) to define a mesh filter. For example:

Thanks in advance,

Maria

---

<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:** [April 28, 2021, 3:00pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/7 "2021-04-28T15:00:11Z")

</div>

Hi Maria. To address your questions:

1. That recommendation of 20 particles per mesh element mostly has to do with the source distribution for a k-eigenvalue calculation, as opposed to tally results on a mesh. In your case, the number of particles that you should run is really dictated by the level of uncertainty that is acceptable to you for these tallies. If the uncertainty is too high, increase the number of particles. Generally speaking, decreasing the standard deviation by a factor of 2 will require a factor of 4 more particles (the variance decreases as 1/N).
2. Tally results are always normalized “per source particle” so if your source distribution contains two separate sources, you’ll have to account for the relative source strength of these two sources. Assuming the strength of the neutron and photon source were the same, this means that if you wanted tally results _per source neutron_ or _per source photon_, you’d need to multiply the results by two.
3. The one element in the z-direction extends infinitely in both the -z and +z directions.

---

<div class="post-metadata">

**Author:** ![MaryAAZ](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/maryaaz/32/1244_2.png) [@MaryAAZ](https://openmc.discourse.group/u/MaryAAZ)\
**Post date:** [April 29, 2021, 8:14pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/8 "2021-04-29T20:14:01Z")

</div>

Hi Paul. I am a little bit confused with your second answer.

My source distribution does contain two separate sources (neutron and photon sources). Each source has the same strength (1, strength value by default).

Defining the sources:  
neutron\_source = openmc.Source()  
neutron\_source.space = openmc.stats.Point(xyz=(0.0,0.0,0.0))  
neutron\_source.energy = openmc.stats.Tabular(NE,NP,interpolation=‘histogram’)

photon\_source = openmc.Source()  
photon\_source.space = openmc.stats.Point(xyz=(0.0,0.0,0.0))  
photon\_source.energy = openmc.stats.Tabular(GE,GP,interpolation=‘histogram’)  
photon\_source.particle = ‘photon’

settings.source = [neutron\_source,photon\_source]

I am tallying the neutron and photon fluxes using particle and mesh filters. Then, loading the results as follows (ne is the number of mesh elements that is the same in _x_ and _y_ directions):

sp = openmc.StatePoint(‘statepoint.300.h5’)  
flux\_neutrons = sp.get\_tally(name=‘Neutrons’).get\_pandas\_dataframe()  
flux\_neutrons = flux\_neutrons[‘mean’].values.reshape((ne,ne))

flux\_photons = sp.get\_tally(name=‘Photons’).get\_pandas\_dataframe()  
flux\_photons = flux\_photons[‘mean’].values.reshape((ne,ne))

If I understood correctly, these results are normalized “per source particle”. Then, multiplying the neutron and photon flux values by 2, I will get the results normalized “per source neutron” and “per source photon”, respectively.

neutrons\_flux = 2\*flux\_neutrons

photon\_flux = 2\*flux\_photons

After that, I can transform the flux units to conventional units using the equation described in a previous [post](https://openmc.discourse.group/t/unit-transformation-in-a-fixed-source-problem/1135) considering the neutron and photon source intensities with the respective flux values.

Is this the correct procedure?

Thanks,  
Maria

---

<div class="post-metadata">

**Author:** ![MaryAAZ](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/maryaaz/32/1244_2.png) [@MaryAAZ](https://openmc.discourse.group/u/MaryAAZ)\
**Post date:** [May 17, 2021, 6:33pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/9 "2021-05-17T18:33:28Z")

</div>

Please @paulromano, do you have any comments on this?

Thank you,  
Maria

---

<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:** [June 2, 2021, 11:59am UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/10 "2021-06-02T11:59:07Z")

</div>

@MaryAAZ Sorry for the delayed response, just catching up on all the messages here. Yes, what you described looks correct to me. One sanity check you can do is to set the source for your problem to be only neutrons or only photons and confirm that the results that you get are consistent with the case where you have both sources and results multiplied by two.

---

<div class="post-metadata">

**Author:** ![MaryAAZ](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/maryaaz/32/1244_2.png) [@MaryAAZ](https://openmc.discourse.group/u/MaryAAZ)\
**Post date:** [June 2, 2021, 11:04pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/11 "2021-06-02T23:04:39Z")

</div>

Hi @paulromano. Indeed, I had done that test you mentioned. I did a case with only the neutron source and a second case with both sources (500 000 particles and 300 batches in both cases). Comparing both results, I see that they are almost the same. I was expecting that the neutron flux obtained using two sources was going to be half of the value obtained when just one source was used. Am I doing something wrong here or missed something?

I sent you an excel file with the results. Please, I appreciate if you can take a look.

Thanks,  
Maria

---

<div class="post-metadata">

**Author:** ![MaryAAZ](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/maryaaz/32/1244_2.png) [@MaryAAZ](https://openmc.discourse.group/u/MaryAAZ)\
**Post date:** [June 4, 2021, 3:46pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/12 "2021-06-04T15:46:40Z")

</div>

Hi @paulromano. I forgot to mention that the results were obtained using a mesh filter (101 x 101 elements).

Maria

---

<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:** [June 7, 2021, 10:06am UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/13 "2021-06-07T10:06:14Z")

</div>

Sorry for misleading you here! The multiplication by two would actually only be needed if the total source strength were 1.0. However, when you add two separate sources (one neutron and one photon), each of them has a source strength of 1.0 by default, so the total source strength is 2.0. Said another way, introducing a second source doesn’t change the strength of the first source, so the flux of neutrons you get is the same even if you add in a separate photon source. So, in you case, the tally values are already normalized correctly according to what you want.

---

<div class="post-metadata">

**Author:** ![MaryAAZ](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/maryaaz/32/1244_2.png) [@MaryAAZ](https://openmc.discourse.group/u/MaryAAZ)\
**Post date:** [June 7, 2021, 4:02pm UTC](https://openmc.discourse.group/t/photon-flux-with-nan-value/1122/14 "2021-06-07T16:02:52Z")

</div>

Hi @paulromano. Thank you very much for your reply.
