How can I define multiple sources

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.’]

)

Hi A66

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

sett.source = source

This should be changed to include both sources

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 might be of interest

1 Like

Thanks for your information. I want to draw a graph like this.
image

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’)

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.

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)

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

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