# Cylinder source in fixed source mode

**URL:** https://openmc.discourse.group/t/cylinder-source-in-fixed-source-mode/4337
**Category:** User Support
**Created:** [May 31, 2024, 6:42pm UTC](https://openmc.discourse.group/t/cylinder-source-in-fixed-source-mode/4337 "2024-05-31T18:42:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Richard](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@Richard](https://openmc.discourse.group/u/Richard)
#### Post date: [May 31, 2024, 6:42pm UTC](https://openmc.discourse.group/t/cylinder-source-in-fixed-source-mode/4337/1 "2024-05-31T18:42:40Z")

</div>

Hello, I am now trying to create multiple cylindrical sources in the mode ‘fixed source’, those sources are are just different in coordinates x,y and the other settings are totatly same. And I met two problems:  
Here are my code:

```auto
radius=0.25
r=openmc.stats.PowerLaw(0.0,radius,1.0)
phi=openmc.stats.Uniform(0.0,2*pi)
z=openmc.stats.Uniform(-fuelLength/2,fuelLength/2)
x=[]
y=[]
m=12
for n in range(17-m):
    for i in range(5):
        for j in range(9-i):
            if i==0:
                x.append((3 ** 0.5) * m * L2 / 2 + (j - (8 - i) / 2) * L1)
                y.append((n - 8 + 0.5 * m) * L2 + (3 ** 0.5) * i * L1 / 2)
            else:
                x.append((3 ** 0.5) * m * L2 / 2 + (j - (8 - i) / 2) * L1)
                y.append((n - 8 + 0.5 * m) * L2 + (3 ** 0.5) * i * L1 / 2)
                x.append((3 ** 0.5) * m * L2 / 2 + (j - (8 - i) / 2) * L1)
                y.append((n - 8 + 0.5 * m) * L2 - (3 ** 0.5) * i * L1 / 2)

energy_bins = [1.00E-05, 0.625, 100, 1000, 5.00E+03, 10000, 50000, 1.00E+05, 200000, 300000, 4.00E+05,
               500000, 600000, 700000, 800000, 900000, 1000000, 2000000, 3000000, 4000000, 5000000,
               6000000, 7000000, 8000000, 9000000, 10000000, 20000000]
probability_density = [0.114804354, 0.130632628, 0.073037242, 0.056694686, 0.025809602, 0.06903753,
                       0.038666972, 0.051744062, 0.041062851, 0.034657177, 0.02416415, 0.027668522,
                       0.027214132, 0.025025168, 0.021317823, 0.015144402, 0.108801774, 0.059257734,
                       0.026894671, 0.014246912, 0.007213418, 0.003657553, 0.001703832, 0.00081529,
                       0.00038822, 0.000339297]

sources=[]
for i in range(len(x)):
    source = openmc.Source()
    source = openmc.stats.CylindricalIndependent(r, phi, z, origin=(x[i], y[i], 0.0))
    source.angle = openmc.stats.Isotropic()
    source.energy = openmc.stats.Tabular(energy_bins, probability_density)
    sources.append(source)

# Indicate how many particles to run
settings = openmc.Settings()
settings.run_mode = 'fixed source'
settings.batches = 100
settings.inactive = 50
settings.particles = 1000
settings.temperature = {"method":"interpolation","range":(280+273.15,320+273.15),"multipole":True}
settings.source = sources
settings.export_to_xml()

```

Firstly, i dont konw why it made an error as follow:

> Blockquote  
> TypeError: Unable to set “source distributions” to \<openmc.stats.multivariate.CylindricalIndependent object at 0x7f8e02374e80\>" which is not of type:“SourceBase”

what should i modify my code?

Secondly, for the energy spectrum of my source, I have a series of continuous energy intervals and their probability density:

| energy low [eV] | energy high [eV] | probability\_density |
| --- | --- | --- |
| 1.00E-05 | 0.625 | 0.114804354 |
| 0.625 | 100 | 0.130632628 |
| 100 | 1000 | 0.073037242 |
| 1.00E+03 | 5.00E+03 | 0.056694686 |
| 5000 | 10000 | 0.025809602 |
| 10000 | 50000 | 0.06903753 |
| 5.00E+04 | 1.00E+05 | 0.038666972 |
| 100000 | 200000 | 0.051744062 |
| 200000 | 300000 | 0.041062851 |
| 3.00E+05 | 4.00E+05 | 0.034657177 |
| 400000 | 500000 | 0.02416415 |
| 500000 | 600000 | 0.027668522 |
| 600000 | 700000 | 0.027214132 |
| 700000 | 800000 | 0.025025168 |
| 800000 | 900000 | 0.021317823 |
| 900000 | 1000000 | 0.015144402 |
| 1000000 | 2000000 | 0.108801774 |
| 2000000 | 3000000 | 0.059257734 |
| 3000000 | 4000000 | 0.026894671 |
| 4000000 | 5000000 | 0.014246912 |
| 5000000 | 6000000 | 0.007213418 |
| 6000000 | 7000000 | 0.003657553 |
| 7000000 | 8000000 | 0.001703832 |
| 8000000 | 9000000 | 0.00081529 |
| 9000000 | 10000000 | 0.00038822 |
| 10000000 | 20000000 | 0.000339297 |

I am not sure the setting ‘source.energy’ in my code is correct. If not, how can i do it?

Thanks,  
Richard

---

<div class="post-metadata">

### Author: ![thilagam](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@thilagam](https://openmc.discourse.group/u/thilagam)
#### Post date: [June 3, 2024, 12:26pm UTC](https://openmc.discourse.group/t/cylinder-source-in-fixed-source-mode/4337/2 "2024-06-03T12:26:32Z")

</div>

Sir, Have you resolved your issue? I am facing the same problem for defining multiple sources. If possible, kindly guide me.  
With thanks & best regards,  
L Thilagam

---

<div class="post-metadata">

### Author: ![Richard](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@Richard](https://openmc.discourse.group/u/Richard)
#### Post date: [June 4, 2024, 3:38am UTC](https://openmc.discourse.group/t/cylinder-source-in-fixed-source-mode/4337/3 "2024-06-04T03:38:21Z")

</div>

For the first problem, that is my mistake. It must be:

```auto
source.space = openmc.stats.CylindricalIndependent(r, phi, z, origin=(x[i], y[i], 0.0))

```

And for the second one, my mentor told me that it should be set up this way:

```auto
energy_bins = [1.00E-05, 0.625, 100, 1000, 5.00E+03, 10000, 50000, 1.00E+05, 200000, 300000, 4.00E+05,
               500000, 600000, 700000, 800000, 900000, 1000000, 2000000, 3000000, 4000000, 5000000,
               6000000, 7000000, 8000000, 9000000, 10000000, 20000000]
probability_density = [0.114804354, 0.130632628, 0.073037242, 0.056694686, 0.025809602, 0.06903753,
                       0.038666972, 0.051744062, 0.041062851, 0.034657177, 0.02416415, 0.027668522,
                       0.027214132, 0.025025168, 0.021317823, 0.015144402, 0.108801774, 0.059257734,
                       0.026894671, 0.014246912, 0.007213418, 0.003657553, 0.001703832, 0.00081529,
                       0.00038822, 0.000339297,0]
source.energy = openmc.stats.Tabular(energy_bins, probability_density,'histogram')

```

Hope that helpful for you

---

<div class="post-metadata">

### Author: ![ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@ron](https://openmc.discourse.group/u/ron)
#### Post date: [June 5, 2024, 1:32pm UTC](https://openmc.discourse.group/t/cylinder-source-in-fixed-source-mode/4337/4 "2024-06-05T13:32:45Z")

</div>

Richard  
This worked for me. Note the use of openmc\_source\_plotter to actually view the source configuration and energy.  
I left a number of your steps in (as comments) to help clarify the changes that I made.  
I did not try to make the input neat or concise, so there may be code that is unneeded or redundant.  
I wasn’t sure what you were trying to do with the variables L1 & L2, so I assumed the had something to do with the source length.

Thanks for posting the question. It helped me learn OpenMC a little better.

from math import pi, sin, cos  
import numpy as np  
import openmc  
from openmc\_source\_plotter import plot\_source\_position

radius=0.25  
pi=np.pi  
fuelLength=10.0  
L1=fuelLength/2.5  
L2=fuelLength/2.0

source = openmc.IndependentSource()

r=openmc.stats.PowerLaw(0.0,radius,1.0)  
phi=openmc.stats.Uniform(0.0,2\*pi)  
z=openmc.stats.Uniform(-fuelLength/2,fuelLength/2)

x=  
y=  
m=12

# for n in range(17-m):

# for i in range(5):

# for j in range(9-i):

# if i==0:

# x.append((3 \*\* 0.5) \* m \* L2 / 2 + (j - (8 - i) / 2) \* L1)

# y.append((n - 8 + 0.5 \* m) \* L2 + (3 \*\* 0.5) \* i \* L1 / 2)

# else:

# x.append((3 \*\* 0.5) \* m \* L2 / 2 + (j - (8 - i) / 2) \* L1)

# y.append((n - 8 + 0.5 \* m) \* L2 + (3 \*\* 0.5) \* i \* L1 / 2)

# x.append((3 \*\* 0.5) \* m \* L2 / 2 + (j - (8 - i) / 2) \* L1)

# y.append((n - 8 + 0.5 \* m) \* L2 - (3 \*\* 0.5) \* i \* L1 / 2)

energy\_bins = [1.00E-05, 0.625, 100, 1000, 5.00E+03, 10000,  
50000, 1.00E+05, 200000, 300000, 4.00E+05, 500000,  
600000, 700000, 800000, 900000, 1000000, 2000000,  
3000000, 4000000, 5000000, 6000000, 7000000, 8000000,  
9000000, 10000000, 20000000]  
probability\_density = [0.114804354, 0.130632628, 0.073037242, 0.056694686, 0.025809602, 0.06903753,  
0.038666972, 0.051744062, 0.041062851, 0.034657177, 0.02416415, 0.027668522,  
0.027214132, 0.025025168, 0.021317823, 0.015144402, 0.108801774, 0.059257734,  
0.026894671, 0.014246912, 0.007213418, 0.003657553, 0.001703832, 0.00081529,  
0.00038822, 0.000339297, 0]

# sources=

# for i in range(len(x)):

# sources = openmc.stats.CylindricalIndependent(r, phi, z, origin=(x[i], y[i], 0.0))

# sources.angle = openmc.stats.Isotropic()

# sources.energy = openmc.stats.Tabular(energy\_bins, probability\_density,‘histogram’)

# sources.append(source)

spatial\_dist = openmc.stats.CylindricalIndependent(r, phi, z)

source.angle = openmc.stats.Isotropic()  
source.energy = openmc.stats.Tabular(energy\_bins, probability\_density,‘histogram’)  
source.space=spatial\_dist

settings = openmc.Settings()  
settings.source = source

settings.export\_to\_xml()

# Indicate how many particles to run

settings = openmc.Settings()  
settings.run\_mode = ‘fixed source’  
settings.batches = 100  
settings.inactive = 50  
settings.particles = 1000

settings.temperature = {“method”:“interpolation”,“range”:(280+273.15,320+273.15),“multipole”:True}

settings.source = source

settings.export\_to\_xml()

# plots the particle energy distribution

plot = plot\_source\_position(source)

plot.show()

---

<div class="post-metadata">

### Author: ![Richard](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@Richard](https://openmc.discourse.group/u/Richard)
#### Post date: [June 5, 2024, 2:22pm UTC](https://openmc.discourse.group/t/cylinder-source-in-fixed-source-mode/4337/5 "2024-06-05T14:22:12Z")

</div>

Thanks for your suggestion. I will check it with openmc\_source\_plotter.  
Best regards
