If you've ever opened classics like Introduction to Nuclear Engineering by Lamarsh or Nuclear Reactor Analysis by Duderstadt & Hamilton, you've probably admired the elegance of reactor physics.
You'll derive the neutron transport equation, study diffusion theory, analyze reactor criticality, and work through sophisticated mathematical models.
But the moment you open VS Code, PyCharm, or Jupyter Notebook and try to build even a simple reactor simulator, you encounter something textbooks rarely discuss:
A massive engineering gap.
The gap isn't in the physics.
It's in translating mathematical models into reliable numerical software.
The journey actually looks like this:
Continuous Physics
↓
Numerical Discretization
↓
Linear Algebra
↓
Algorithms
↓
Working Python Code
Most classical textbooks master the first step.
Scientific software lives in the last four.
From Differential Equations to Numerical Algorithms
Consider one of the most fundamental equations in reactor physics: the one-dimensional steady-state neutron diffusion equation with an external source.
[
D\frac{d^2\phi}{dx^2}-\Sigma_a\phi+S=0
]
where
- D is the diffusion coefficient
- φ is the neutron flux
- Σa is the macroscopic absorption cross section
- S is the external neutron source
Beautiful.
Elegant.
Impossible for a computer to solve directly.
Computers don't understand derivatives.
They understand numbers.
Step 1 — Discretize the Reactor
Instead of treating space as continuous, we divide the reactor into equally spaced nodes.
Using the finite difference approximation,
[
\frac{d^2\phi}{dx^2}
\approx
\frac{\phi_{i+1}-2\phi_i+\phi_{i-1}}{\Delta x^2}
]
the governing equation becomes
[
D
\left(
\frac{\phi_{i+1}-2\phi_i+\phi_{i-1}}
{\Delta x^2}
\right)
\Sigma_a\phi_i
+
S_i
0
]
The differential equation has now become a collection of algebraic equations.
Step 2 — Build a Linear System
Rearranging the terms gives
[
\left(\frac{D}{\Delta x^2}\right)\phi_{i-1}
\left(
\frac{2D}{\Delta x^2}
+\Sigma_a
\right)\phi_i
+
\left(\frac{D}{\Delta x^2}\right)\phi_{i+1}
-S_i
]
Instead of solving calculus,
we solve
[
A\Phi=B
]
where
- A is a tridiagonal matrix representing neutron leakage and absorption,
- Φ is the unknown neutron flux vector,
- B contains the external source.
This is where reactor physics becomes numerical linear algebra.
Step 3 — Solve the System in Python
Once the mathematical model has been transformed into matrix form, implementing the solver becomes straightforward.
import numpy as np
def solve_1d_reactor_flux(core_length,
num_nodes,
D,
Sigma_a,
source_strength):
dx = core_length / (num_nodes - 1)
x = np.linspace(0, core_length, num_nodes)
A = np.zeros((num_nodes, num_nodes))
B = np.zeros(num_nodes)
leakage = D / dx**2
center = -(2*leakage + Sigma_a)
for i in range(1, num_nodes-1):
A[i,i-1] = leakage
A[i,i] = center
A[i,i+1] = leakage
B[i] = -source_strength
# Vacuum boundary conditions
A[0,0] = 1
A[-1,-1] = 1
flux = np.linalg.solve(A,B)
return x, flux
Notice something important.
We are not performing matrix inversion.
numpy.linalg.solve() uses optimized LAPACK routines to solve the linear system directly, which is both faster and numerically more stable than explicitly computing an inverse matrix.
That distinction matters in scientific computing.
Where Classical Textbooks and Scientific Software Meet
Today's learning resources usually fall into one of two categories.
Classical reactor physics textbooks
Books by Lamarsh, Duderstadt & Hamilton, and Stacey provide the theoretical foundation needed to understand diffusion theory, neutron transport, reactor kinetics, and nuclear engineering.
They explain why the equations work.
Production simulation codes
Projects like OpenMC, Serpent, and MCNP are industrial-strength scientific codes capable of solving extremely sophisticated neutron transport problems.
They demonstrate how professionals simulate reactors.
However, for many students and software engineers, there is still a missing middle layer:
How do you build a simulator yourself?
How do you translate equations into maintainable Python code?
How do you organize numerical algorithms into software architecture?
That bridge is rarely discussed.
A Different Learning Perspective
Instead of replacing classical reactor physics books, numerical programming complements them.
| Resource | Primary Focus |
|---|---|
| Lamarsh | Reactor physics fundamentals |
| Duderstadt & Hamilton | Mathematical reactor analysis |
| Stacey | Advanced reactor engineering |
| Practical Python implementations | Numerical algorithms and simulator architecture |
These aren't competing approaches.
They're different layers of the same discipline.
Physics explains the model.
Numerical analysis transforms the model.
Software engineering turns the numerical method into a maintainable simulator.
Final Thoughts
Writing code forces us to confront every assumption hidden inside an equation.
Boundary conditions.
Grid spacing.
Matrix assembly.
Numerical stability.
Data structures.
Algorithmic complexity.
That is why implementing a physical model is often the deepest form of understanding it.
Equations describe reality.
Algorithms make them computable.
Software makes them useful.
If you're interested in exploring this bridge between reactor physics and practical scientific programming, I've been documenting my own approach in a Leanpub book focused on building reactor simulators from scratch using Python and NumPy.
I hope it helps make the transition from equations on paper to working simulation software a little less intimidating.
Top comments (0)