OpenMC Guide
Running Simulations in OpenMC
Running Your First Simulation
The simplest way to run a simulation is through OpenMC's Model class:
Basic Run
python
# Create model from components we made earlier
model = openmc.Model(
geometry=geometry, # From geometry creation
materials=materials, # From materials definition
settings=settings, # From settings setup
tallies=tallies # From tallies setup
)
# Run the simulation
model.run()Tutorial snippet — no separate file in examples repo
Tip: Always start with a small number of particles (e.g., 1000) to test your model before running long simulations. This helps catch errors quickly.
Common Run Options
Several run-time options are available:
Debug Mode
python
# Run with geometry debugging
model.run(output=True) # Show output
model.run(geometry_debug=True) # Check geometryTutorial snippet — no separate file in examples repo
Parallel Run
python
# Run with 4 processors
model.run(mpi_args=['mpiexec', '-n', '4'])
# Set thread count
model.run(threads=2)Tutorial snippet — no separate file in examples repo
Understanding Output
OpenMC produces several output files:
Key Files
statepoint.*.h5: Resultstallies.out: Tally datasummary.h5: Model info
Optional Output Files
particle_*.h5: Particle tracks (only created when particle tracking is enabled viasettings.track = [...])
Common Issues
- Geometry errors
- Lost particles
- Memory limits
- Convergence issues
Reading Results
python
# Load results (from previous section)
sp = openmc.StatePoint('statepoint.100.h5')
# Get k-effective (for criticality runs)
keff = sp.keff
print(f'k-effective = {keff.nominal_value:.5f} ± {keff.std_dev:.5f}')
# Get tally results
tally = sp.get_tally(name='flux')
mean = tally.mean
rel_err = tally.std_dev / tally.meanTutorial snippet — no separate file in examples repo
Best Practices
Running Tips
- Start with few particles to test setup
- Use geometry debug mode to check for errors
- Monitor memory usage for large models
- Save statepoints periodically for long runs
- Use parallel processing for speed when needed