Source Definition in OpenMC

What you'll learn

After the first pin · 11 / 1112 min read
  • Build an IndependentSource from separate space, energy, and angle distributions.
  • Say how much the source matters in an eigenvalue run versus a fixed source run.
  • Pick an energy distribution: Discrete, Watt, Maxwell, or Tabular.
  • Combine several sources and weight them by strength.

Before you start

Introduction to Sources

The pin cell in Example: Pin Cell gets away with a plain box source in the fuel because it is an eigenvalue problem. Come back here once you need a shaped, weighted, or fixed source instead — shielding, an external beam, or several sources combined.

Sources define where particles originate in your simulation. OpenMC supports two main simulation modes:

Eigenvalue Mode

Initial source only starts the simulation. Fission sites become sources for later generations. Common for reactor calculations.

Fixed-source Mode

Source definition affects all results. Must accurately represent your physical source. Common for shielding calculations.

Basic Source Setup

A source has three main components: where particles start (space), their energy, and their direction (angle). Current OpenMC uses openmc.IndependentSource to build sources (the older openmc.Source name is not what you want in recent releases).

Simple Point Source

python
# Create point source at origin with default settings
source = openmc.IndependentSource(
    space=openmc.stats.Point((0., 0., 0.)),     # Location
    energy=openmc.stats.Discrete([1.0e6], [1.0]), # 1 MeV neutrons
    angle=openmc.stats.Isotropic()               # All directions
)

# Add to settings
settings = openmc.Settings()
settings.source = source

Tutorial snippet — no separate file in examples repo

Common Source Types

Box Source

python
# Uniform distribution in a box
box_source = openmc.IndependentSource(
    space=openmc.stats.Box(
        (-10., -10., -10.),  # Lower-left
        (10., 10., 10.)      # Upper-right
    )
)

Tutorial snippet — no separate file in examples repo

Cylindrical Source

python
import numpy as np

# Uniform in a cylinder
# (r needs a linear PDF - PowerLaw with n=1 -
#  so points are uniform per unit volume)
r = openmc.stats.PowerLaw(0., 5.0, 1)
phi = openmc.stats.Uniform(0., 2*np.pi)
z = openmc.stats.Uniform(-10., 10.)

cyl_source = openmc.IndependentSource(
    space=openmc.stats.CylindricalIndependent(
        r, phi, z
    )
)

Tutorial snippet — no separate file in examples repo

Tip: For reactor simulations, you often don't need to specify a detailed source - a simple uniform distribution in the fuel region is sufficient as the fission source will quickly converge.

Energy Distributions

Common Sources

python
# Fusion source (14.1 MeV)
fusion = openmc.stats.Discrete([14.1e6], [1.0])

# Fission spectrum
fission = openmc.stats.Watt(a=0.988e6, b=2.249e-6)

# Maxwellian fission spectrum (theta in eV)
maxwellian = openmc.stats.Maxwell(1.29e6)

Tutorial snippet — no separate file in examples repo

Custom Distribution

python
# Define energy points and probabilities
energies = [0.0, 1e6, 2e6, 3e6]  # eV
probs = [0.0, 0.5, 1.0, 0.0]

custom = openmc.stats.Tabular(energies, probs)

Tutorial snippet — no separate file in examples repo

Multiple Sources

You can combine multiple sources with different strengths:

python
# Create two sources
src1 = openmc.IndependentSource(space=openmc.stats.Point((0., 0., 0.)))
src1.strength = 2.0  # Twice as strong

src2 = openmc.IndependentSource(space=openmc.stats.Point((10., 0., 0.)))
src2.strength = 1.0

# Combine sources
settings.source = [src1, src2]

Tutorial snippet — no separate file in examples repo

Try It Yourself

openmc.Source was split into several classes. The old name survives as a shim that raises a FutureWarning and forwards to IndependentSource, so old scripts still run — which is exactly why this one is easy to miss. It is documented as going away in a future release, and a warning buried in OpenMC's startup output is not something you will notice. The settings below are otherwise fine.

Try it yourself — shielding_source.py
Swap the deprecated openmc.Source for openmc.IndependentSource. Everything inside the parentheses is already correct.
1 warningChecked by the OWEN rule set

Check yourself

  • Build an IndependentSource from separate space, energy, and angle distributions?
  • Say how much the source matters in an eigenvalue run versus a fixed source run?
  • Pick an energy distribution: Discrete, Watt, Maxwell, or Tabular?