# How can I define multiple sources

**URL:** <https://openmc.discourse.group/t/how-can-i-define-multiple-sources/2807>\
**Category:** User Support\
**Created:** [March 7, 2023, 10:37pm UTC](https://openmc.discourse.group/t/how-can-i-define-multiple-sources/2807 "2023-03-07T22:37:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![A66](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@A66](https://openmc.discourse.group/u/A66)\
**Post date:** [March 7, 2023, 10:37pm UTC](https://openmc.discourse.group/t/how-can-i-define-multiple-sources/2807/1 "2023-03-07T22:37:10Z")

</div>

Hi all,In this example, I want to draw this graph for two sources. However, when I add the 2nd source in this way, the graph does not change. How can I add the 2nd source? Could you help me?  
import openmc

# MATERIALS

# Tungsten is a very good photon shield, partly due to its high Z number and electrons

my\_material = openmc.Material(name=‘tungsten’)

my\_material.add\_element(‘W’, 1, percent\_type=‘ao’)

my\_material.set\_density(‘g/cm3’, 19)

mats = openmc.Materials([my\_material])

# GEOMETRY

# surfaces

vessel\_inner\_surface = openmc.Sphere(r=500)

vessel\_rear\_surface = openmc.Sphere(r=530)

# Currently it is not possible to tally on boundary\_type=‘vacuum’ surfaces

outer\_surface = openmc.Sphere(r=550, boundary\_type=‘vacuum’)

# cells

inner\_vessel\_cell = openmc.Cell(region=-vessel\_inner\_surface)

# inner\_vessel\_cell is filled with a void / vacuum by default

blanket\_cell = openmc.Cell(region=-vessel\_rear\_surface & +vessel\_inner\_surface)

blanket\_cell.fill = my\_material

outer\_vessel\_cell = openmc.Cell(region=+vessel\_rear\_surface & -outer\_surface)

# this is filled with a void / vacuum by default

universe = openmc.Universe(cells=[inner\_vessel\_cell,blanket\_cell, outer\_vessel\_cell])

geom = openmc.Geometry(universe)

# SIMULATION SETTINGS

# Instantiate a Settings object

sett = openmc.Settings()

sett.batches = 100

sett.inactive = 0 # the default is 10, which would be wasted computing for us

sett.particles = 1000

sett.run\_mode = ‘fixed source’

sett.photon\_transport = True # This line is required to switch on photons tracking

# Create a DT point source

source = openmc.Source()

source.space = openmc.stats.Point((0, 0, 0))

source.angle = openmc.stats.Isotropic()

source.energy = openmc.stats.Discrete([14e6], [1])

sett.source = source

source2 = openmc.Source()

source2.space = openmc.stats.Point((0, 0, 0))

source2.angle = openmc.stats.Isotropic()

source2.energy = openmc.stats.Discrete([20e6], [1])

# combine all the required parts to make a model

model = openmc.model.Model(geom, mats, sett, tallies)

# remove old files and runs OpenMC

!rm \*.h5

results\_filename = model.run()

from plotting\_utils import create\_plotly\_figure, add\_trace\_to\_figure

# open the results file

results = openmc.StatePoint(results\_filename)

#extracts the tally values from the simulation results

cell\_tally = results.get\_tally(name=‘cell\_spectra\_tally’)

cell\_tally = cell\_tally.get\_pandas\_dataframe()

fig = create\_plotly\_figure(y\_axis\_label=‘Neutrons per cm2 per source neutron’)

add\_trace\_to\_figure(

figure=fig,

energy\_bins=energy\_bins,

values=cell\_tally[‘mean’],

std\_dev=cell\_tally[‘std. dev.’]

)

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [March 8, 2023, 7:48pm UTC](https://openmc.discourse.group/t/how-can-i-define-multiple-sources/2807/2 "2023-03-08T19:48:29Z")

</div>

Hi A66

I noticed you have a line in your code that defines the source attribute for the settings

```auto
sett.source = source

```

This should be changed to include both sources

```auto
sett.source = [source, source2]

```

The line will also need to be moved lower in the script so that source2 has been defined before it is used.

By the way [this source plotting package](https://github.com/fusion-energy/openmc_source_plotter/) might be of interest

---

<div class="post-metadata">

**Author:** ![A66](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@A66](https://openmc.discourse.group/u/A66)\
**Post date:** [March 8, 2023, 10:39pm UTC](https://openmc.discourse.group/t/how-can-i-define-multiple-sources/2807/3 "2023-03-08T22:39:39Z")

</div>

Thanks for your information. I want to draw a graph like this.  
 ![image](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/f/f54a0575f550f6e32f7631b66ad9fecfcb03bd1e.png)

---

<div class="post-metadata">

**Author:** ![A66](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@A66](https://openmc.discourse.group/u/A66)\
**Post date:** [March 10, 2023, 11:01am UTC](https://openmc.discourse.group/t/how-can-i-define-multiple-sources/2807/4 "2023-03-10T11:01:32Z")

</div>

If I want to take dose results for two source, can I write this code?  
import math

# open the results file

sp = openmc.StatePoint(sp\_filename)

# access the tally using pandas dataframes

tally = sp.get\_tally(name=‘dose\_tally\_on\_surface’)  
df = tally.get\_pandas\_dataframe()

tally\_result = df[‘mean’].sum()  
tally\_std\_dev = df[‘std. dev.’].sum()

# convert from the tally output units of pSv cm² to pSv by dividing by the surface area of the surface

dose\_in\_pSv = tally\_result / (4 \* math.pi \* math.pow(200, 2))

source\_activity = 56000 # in decays per second (Bq)  
emission\_rate = 2 # the number of gammas emitted per decay which is approximately 2 for Co60  
gamma\_per\_second = source\_activity \* emission\_rate  
dose\_rate\_in\_pSv = dose\_in\_pSv \* gamma\_per\_second

source2\_activity = 114190 # in decays per second (Bq)  
emission\_rate = 2 # the number of gammas emitted per decay which is approximately 2 for Co60  
gamma\_per\_second = source\_activity \* emission\_rate  
dose\_rate\_in\_pSv = dose\_in\_pSv \* gamma\_per\_second

# print results

print('The surface dose = ', dose\_rate\_in\_pSv, ‘pico Sv per second’)

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [March 10, 2023, 11:11am UTC](https://openmc.discourse.group/t/how-can-i-define-multiple-sources/2807/5 "2023-03-10T11:11:01Z")

</div>

Prior to extracting the results if your sources have different strengths you might want to set the `source.strength` for each source so that they are sampled relative to their strengths when the simulation is run.

---

<div class="post-metadata">

**Author:** ![A66](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@A66](https://openmc.discourse.group/u/A66)\
**Post date:** [March 10, 2023, 12:35pm UTC](https://openmc.discourse.group/t/how-can-i-define-multiple-sources/2807/6 "2023-03-10T12:35:02Z")

</div>

> [@A66](#):
>
> source\_activity = 56000 # in decays per second (Bq)

Isn’t it enough just to describe theiracrivities int his way?  
source\_activity = 56000 # in decays per second (Bq)  
source2\_activity = 114190 # in decays per second (Bq)

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [March 10, 2023, 1:15pm UTC](https://openmc.discourse.group/t/how-can-i-define-multiple-sources/2807/7 "2023-03-10T13:15:40Z")

</div>

I think you want to **simulate** more particles from the stronger source that the other weaker source.

---

<div class="post-metadata">

**Author:** ![A66](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@A66](https://openmc.discourse.group/u/A66)\
**Post date:** [March 10, 2023, 2:12pm UTC](https://openmc.discourse.group/t/how-can-i-define-multiple-sources/2807/8 "2023-03-10T14:12:44Z")

</div>

Yes I want this so do I set the source.strength?
