Skip to content

Huq2090/OpenFRC

Repository files navigation

OpenFRC Logo

OpenFRC

A GPU-Accelerated 2D FRC MHD Solver

OpenFRC A GPU-Accelerated 2D FRC MHD Solver

A lightweight, research-grade simulation framework for studying Field-Reversed Configuration (FRC) dynamics, built for plasma physics education, algorithm development, and fusion interview preparation (Helion Energy, CFS, General Fusion, etc.).

License Python GPU Status


Overview

OpenFRC is a 2D Magnetohydrodynamics (MHD) solver implementing:

  • Helion-style FRC magnetic topology
  • Strong axial magnetic field reversal
  • Poloidal flux function initialization
  • FFT-based ∇·B cleaning (projection method)
  • Hybrid NumPy/CuPy backend for GPU acceleration
  • Multiple physics modes:
    ✓ FRC formation
    ✓ Magnetic reconnection
    ✓ Alfvén wave propagation
  • Visualization + MP4 animation exports

The solver is intentionally compact, readable, and modular — ideal for:

  • learning plasma & MHD theory
  • testing numerical algorithms
  • fusion interview preparation
  • use as a starting point for Hall-MHD or 2-fluid extensions

Why This Project Exists

FRCs are among the most compact and promising fusion configurations.
Helion Energy uses Merging-FRC (MIF) to achieve fusion-relevant conditions.

This project recreates core FRC physics in a clean 2D MHD framework:

  • Axisymmetric flux rings
  • Strong field reversal
  • Current sheet formation
  • Magnetic reconnection
  • Plasmoid structures
  • Outward magnetic pressure balance
  • Lorentz-force-driven acceleration

This is conceptually aligned with the physics in Helion’s formation region.


Physics Model

The solver integrates the ideal MHD equations with resistive diffusion:

$$ \frac{\partial \rho}{\partial t} = 0 \quad (\text{constant density}) $$

$$ \frac{\partial \mathbf{v}}{\partial t} = -\frac{1}{\rho}\nabla p + \frac{1}{\rho} (\mathbf{J} \times \mathbf{B}) $$

$$ \mathbf{J} = \nabla \times \mathbf{B} $$

$$ \frac{\partial \mathbf{B}}{\partial t} = -\nabla \times \mathbf{E} + \eta \nabla^2 \mathbf{B} $$

$$ \mathbf{E} = -\mathbf{v} \times \mathbf{B} $$

Divergence Cleaning

We enforce:

$$ \nabla \cdot \mathbf{B} = 0 $$

using FFT-based Poisson projection:

$$ \nabla^2 \phi = \nabla \cdot \mathbf{B} \quad\Rightarrow\quad \mathbf{B} \leftarrow \mathbf{B} - \nabla \phi $$

This method is:

  • fast
  • GPU-accelerated
  • stable
  • common in modern MHD codes (Athena++, Dedner schemes)

FRC Initial Conditions

We initialize a long, slender FRC, similar to Helion's confinement geometry.

Flux function:

$$ \Psi(x,y) = \exp\left(-\frac{x^2}{a^2} - \frac{y^2}{L^2}\right) $$

Poloidal magnetic field:

$$ B_x = -\frac{\partial \Psi}{\partial y}, \quad B_y = \frac{\partial \Psi}{\partial x} $$

Axial field reversal:

$$ B_z = B_0 \left(1 - 2 e^{-(x^2 + y^2)/R_0^2} \right) $$

This produces:

  • a magnetic null line along the axis
  • a strongly reversed core
  • closed poloidal flux surfaces
  • current sheet regions

Project Structure

OpenFRC/
│── backend.py              # NumPy/CuPy backend (hybrid GPU/CPU)
│── config.py               # Grid parameters, timestep, resistivity
│── initial_conditions.py   # Alfven, Reconnection, FRC setups
│── solver.py               # MHD evolution + FFT divergence cleaning
│── visualize.py            # Frame generation + MP4 animation
│── main.py                 # CLI interface
│── README.md
│── LICENSE
│── requirements.txt
│── environment.yml
│── .gitignore
│── media/                  # Logo and favicon
│── frames/                 # Auto-generated output (ignored by git)
│── animation.mp4           # Optional animation output

Installation

Clone the repo:

git clone https://github.com/Huq2090/OpenFRC.git
cd OpenFRC

Install dependencies:

pip install -r requirements.txt

Optional: GPU support

pip install cupy-cuda12x

Running Simulations

▶ Run FRC Simulation (with divergence cleaning)

python3 main.py --mode frc --cleaning projection --animate

▶ Run on GPU

python3 main.py --mode frc --gpu --animate

▶ Magnetic Reconnection

python3 main.py --mode reconnection --animate

▶ Alfvén Wave Test

python3 main.py --mode alfven --animate

Animations will appear in:

frames/
animation.mp4

Example Output (FRC Evolution)

(Add images/GIFs after running the simulation)
Example placeholders:

  • FRC poloidal field loops
  • Axial field reversal
  • Magnetic island formation
  • Current sheet thinning
  • Reconnection dynamics

Future Roadmap

Numerical / Physics Upgrades

  • ☐ Hall-MHD (whistler waves + FRC tilt physics)
  • ☐ Two-fluid / gyrofluid extensions
  • ☐ Cylindrical (r-z) geometry
  • ☐ Shock-capturing Riemann solvers (HLL/HLLD)
  • ☐ Dedner hyperbolic divergence cleaning

Software Engineering

  • ☐ Sphinx documentation
  • ☐ Unit tests (pytest)
  • ☐ GitHub Actions CI
  • ☐ Docker image
  • ☐ Jupyter notebook demos

Citation (Optional)

If you use this project:

@software{OpenFRC2025,
  author = {Md Fazlul Huq},
  title = {OpenFRC: A GPU-Accelerated 2D FRC MHD Solver},
  year = {2025},
  url = {https://github.com/Huq2090/OpenFRC}
}

Acknowledgements

Developed by Md Fazlul Huq
As part of self learning of Computational plasma physics of Field-Reversed Configuration (FRC) in MHD.

Special thanks to open-source plasma physics projects and the wider fusion community.

May your fields stay divergence-free and your plasmoids stable!

About

Open Source Software for MHD Simulation of Field Reversed Configuration.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages