OpenMHD code

Japanese | English


OpenMHD is a two-dimensional finite-volume code for magnetohydrodynamics (MHD). The code is written in Fortran 90. It is parallelized by using MPI-2 and OpenMP.

OpenMHD was originally developed for my studies on magnetic reconnection [1,2]. In addition, substantial improvements have been made since then. The code has been made publicly available in the hope that others may find it useful.

Obtaining the code

The following versions are available in .tar.gz format.

The source code is hosted on GitHub.

Basic equations

OpenMHD solves the following equations of magnetohydrodynamics. \begin{align} \frac{\partial \rho}{\partial t} &+ \nabla \cdot ( \rho \vec{v} ) = 0, \\ \frac{\partial \rho \vec{v}}{\partial t} &+ \nabla \cdot ( \rho\vec{v}\vec{v} + p_T\overleftrightarrow{I} - \vec{B}\vec{B} ) = 0, \\ \frac{\partial e}{\partial t} &+ \nabla \cdot \Big( (e+p_T )\vec{v} - (\vec{v}\cdot\vec{B}) \vec{B} + \eta \vec{j} \times \vec{B} \Big) = 0, \\ \frac{\partial \vec{B}}{\partial t} &+ \nabla \cdot ( \vec{v}\vec{B} - \vec{B}\vec{v} ) + \nabla \times (\eta \vec{j}) + \nabla \psi = 0, \\ \frac{\partial \psi}{\partial t} &+ c_h^2 \nabla \cdot \vec{B} = - \Big(\frac{c_h^2}{c_p^2}\Big) \psi, \end{align} where $p_T=p+B^2/2$ is the total pressure, $\overleftrightarrow{I}$ is the unit tensor, $e=p/(\Gamma-1) + \rho v^2/2 + B^2/2$ is the energy density, $\Gamma=5/3$ is the adiabatic index, and $\psi$ is a virtual potential for hyperbolic divergence cleaning [3]. The second-order Runge=Kutta methods and second-order MUSCL scheme are employed. The source term for $\psi$ is handled by the Strang splitting and an analytic solution $\psi = \psi_0 \exp [ - ({c_h^2}/{c_p^2}) t ]$. Other numerical techniques are documented in Ref. [1] and references therein. In addition, the latest version contains the HLLD flux solver [4,2] and other improvements such as the parallel I/O.

  1. S. Zenitani & T. Miyoshi, Phys. Plasmas 18, 022105 (2011)
  2. S. Zenitani, Phys. Plasmas 22, 032114 (2015)
  3. A. Dedner et al., J. Comput. Phys. 175, 645 (2002)
  4. T. Miyoshi & K. Kusano, J. Comput. Phys. 208, 315 (2005)
Presentation file

Q & A

  1. How to visualize the data?

    Sample IDL and Python/matplotlib routines are provided. For IDL, please run the 'batch' script in the following way.

    $ idl
    IDL> .r batch

    For Python 3, please run the '' script in the following way.

    $ ipython3 --pylab
    In [1]: %run
  2. How to set up boundary conditions?

    The user needs to set up boundary conditions for both conserved variables (U) and MUSCL-interporlated primitive variables (VL and VR). One might want to modify the boundary conditions in the following files:

    • [mpi]bc*.f90
    • [mpi]bc_vlvr_*.f90

  3. How to reload the previous data?

    Set the n_start parameter to non-zero.

  4. What is the most costly part?

    The HLLD flux solver. Here is a benchmark.

  5. What is the best URL for a reference?

    Please refer a link ( at Astrophysics Source Code Library (ASCL) or the github URL (, because this URL ( may not be stable.

    Here are snippets for your convenience.

    S. Zenitani, Phys. Plasmas, 22, 032114 (2015).
    S. Zenitani, Astrophysics Source Code Library, record ascl:1604.001 (2016).
    Zenitani, S. 2015, Phys. Plasmas, 22, 032114
    Zenitani, S. 2016, Astrophysics Source Code Library, record ascl:1604.001

Test problems

The following problems are pre-configured.


  • Added a new problem on a relativistic jet.
  • Added a relativistic HLL/HLLD solver for transverse propagation.
  • Updated IDL/Python3 routines.
  • Changed the binary file format: We removed the fortran record markers. (Courtesy of Dr. Kondoh, Dr. Hotta, and Prof. Matsumoto)
  • Updated IDL/Python3 routines.
  • Temporally removed the Mathematica notebook.
  • Updated IDL/Python3 routines.
  • Added a sample Mathematica notebook.
  • Revised slope limiters with OpenMP directives.
  • Revised flux solvers in the X/Y (and Z) directions.
  • New resistive-term and GLM-term solvers.
  • Improved performance.
  • Fixed a bug in the energy state in the HLLC solver in X.
  • Changes in initial parameters. (Courtesy of Mr. Hino)
  • Added sample Python3 (matplotlib) codes.
  • Changed the directory layout.
  • Fixed initial and boundary conditions in magnetic reconnection. (Courtesy of Dr. Kondoh)
  • Added sample idl codes.
  • Added a sample gnuplot code. (Courtesy of Dr. Wada)
  • Improved the HLLC solver and the Koren limiter.
  • Added OpenMP directives to the flux solvers.
  • Parallel I/O.
  • Modified resistive terms in the HLL solver.
  • Optimized the LLF/HLL/HLLC solvers and the minmod/MC limiters, in particular on SPARC processors.
  • Fixed a bug in the energy state in the HLLC solver in X.
  • Updated initial settings of the reconnection problem (ref. [2]).
  • Reorganized BC subroutines.
  • Improved performance.
  • Added a resistive HLLD solver.
  • The code can restart from the output file(s).
  • Fixed a NaN issue in the fast-mode speed.
  • The code is now hosted on GitHub.
  • Added a test problem on "CIR".
  • Added a Koren limiter.
  • Added test problems: magnetic reconnection [1] and the Kelvin-Helmholtz instability.
  • Added a resistive HLL solver.
  • The code is parallelized by using MPI.
  • Employed a Strang-splitting method for the GLM term.
  • Publicly available.
  • Employed hyperbolic divergence cleaning.
  • Wrote HLLC-G (and then HLLD) Riemann solvers.
  • Added 1D and 2D test problems.