OpenMC Guide
Running Simulations in OpenMC
Running Your First Simulation
Now that we've created our geometry, materials, and settings, let's run our simulation. The simplest way is using 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()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
You can customize how your simulation runs based on your needs:
Debug Mode
python
# Run with geometry debugging
model.run(output=True) # Show output
model.run(geometry_debug=True) # Check geometryParallel Run
python
# Run with 4 processors
model.run(mpi_args=['mpiexec', '-n', '4'])
# Set thread count
model.run(openmc_exec_kwargs={
'threads': 2
})Understanding Output
OpenMC creates several output files during and after simulation:
Key Files
statepoint.*.h5: Resultstallies.out: Tally datasummary.h5: Model infoparticles.h5: Particle tracks
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.meanBest 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