Back to projects
C++17 / FFTW3 / OpenGL 4.x

Quantum Tunnel

3D quantum tunneling simulator with split-operator FFT

Overview

A real-time 3D quantum tunneling simulator that solves the time-dependent Schrodinger equation and renders the wavefunction as it passes through potential barriers. Built to understand computational quantum mechanics from the math to the GPU.

Architecture

1

The solver uses Strang splitting (split-operator method): half-potential phase, FFT forward, full kinetic phase, FFT inverse, half-potential phase. This second-order symmetric decomposition preserves unitarity exactly -- verified by tests tolerating only 1e-6 norm drift over 1000 steps.

2

FFTW3 handles 3D fast Fourier transforms with FFTW_MEASURE for runtime-optimized plans. Kinetic and potential phase operators are precomputed once as complex exponentials, so each timestep is three element-wise multiplies plus two FFTs.

3

Two rendering modes toggled at runtime: marching cubes isosurface extraction (CPU-side triangulation with Phong shading, two-pass glow) and volume raycasting (3D texture upload, GPU raymarching with 1D transfer function). Barrier potentials render as wireframe boxes.

4

OpenMP parallelism on all N^3 element-wise loops with collapse(3) for k-space precomputation. FFTW itself uses fftw_plan_with_nthreads for threaded transforms.

5

Four potential types: single barrier, double barrier (resonant tunneling), screened Coulomb with soft-core regularization, and free particle. Complex absorbing potential at boundaries uses quadratic ramp to prevent reflections.

6

Adaptive quality control: physics steps per frame decrease when FPS drops below 25, increase above 50. Frame export captures PNG sequences for video.

Design Decisions

Marching cubes vs volume raycasting as default
Marching cubes gives sharp, well-defined surfaces but requires CPU mesh extraction every frame. Volume raycasting is GPU-native and smoother but more expensive per pixel. Both are implemented -- the user toggles with V key based on what they want to see.
Default grid N=64 (262K points) over higher resolution
N=128 would give 8x more points and much smoother visuals, but FFT scales as N^3*log(N) and rendering doubles. N=64 keeps real-time performance on consumer hardware while capturing the essential physics.
Precomputed phase operators over per-step computation
The potential and kinetic operators don't change between timesteps (for static potentials). Precomputing exp(-iV*dt/2) and exp(-iT*dt) once eliminates redundant complex exponential evaluation at every step.

Tech Stack

C++17FFTW3OpenGL 4.xGLSL shadersOpenMPSDL2GLMMarching cubesVolume raycasting