[Paper Review] Hydromagnetic waves in an expanding universe -- cosmological MHD code tests using analytic solutions
This paper presents analytic and numerical solutions for linear hydromagnetic waves in comoving coordinates to test cosmological MHD codes. It derives exact solutions for Alfvén and magnetosonic waves in an Einstein-de-Sitter universe and uses them to validate the arepo code, demonstrating excellent agreement when sufficient resolution is used. The key contribution is a framework for detecting subtle coding errors related to the scale factor and its derivative through wave damping analysis.
We describe how analytic solutions for linear hydromagnetic waves can be used for testing cosmological magnetohydrodynamic (MHD) codes. We start from the comoving MHD equations and derive analytic solutions for the amplitude evolution of linear hydromagnetic waves in a matter-dominated, flat Einstein-de-Sitter (EdS) universe. The waves considered are comoving, linearly polarized Alfv\'en waves and comoving, magnetosonic (fast) waves modified by self-gravity. The solution for compressible waves is found for a general adiabatic index and we consider the limits of hydrodynamics without self-gravity in addition to the full solution. In addition to these analytic solutions, the linearized equations are solved numerically for a $\Lambda$CDM cosmology. We use the analytic and numeric solutions to compare with results obtained using the cosmological MHD code AREPO and find good agreement when using a sufficient number of grid points. We interpret the numerical damping clearly evident in simulations with few grid points by further deriving the Alfv\'en wave solution including physical Navier-Stokes viscosity. A comparison between Alfv\'en wave simulations and theory reveals that the dissipation can be described by a numerical viscosity coefficient $\eta_\mathrm{num} \propto a^{-5/2}$ where $a$ is the scale factor. We envision that our examples could be useful when developing a new cosmological MHD code or for regression testing of existing codes.
Motivation & Objective
- To develop a rigorous testing framework for cosmological MHD codes that specifically targets errors arising from the scale factor $a$ and its time derivative $\dot{a}$.
- To provide analytic solutions for linear hydromagnetic waves in a matter-dominated, flat Einstein-de-Sitter (EdS) universe to serve as reference benchmarks.
- To extend the test suite to include numerical solutions for waves in a $\Lambda$CDM cosmology for broader applicability.
- To demonstrate that numerical damping in simulations with few grid points can be interpreted as numerical viscosity with $\eta_{\text{num}} \propto a^{-5/2}$, enabling error diagnosis.
- To advocate for the integration of these wave-based tests into automated regression testing pipelines for cosmological MHD codes.
Proposed method
- Derive analytic solutions for comoving Alfvén waves and gravity-modified magnetosonic waves in an Einstein-de-Sitter (EdS) cosmology using the linearized comoving MHD equations.
- Solve the linearized equations numerically for a $\Lambda$CDM cosmology using a fourth-order Runge-Kutta method with adaptive time stepping.
- Transform standard MHD equations into comoving coordinates by introducing the scale factor $a$ and its derivative $\dot{a}$, modifying the momentum and induction equations accordingly.
- Implement the wave solutions in a 1D periodic domain to enable fast, computationally cheap tests on standard hardware.
- Compare simulation results from the arepo code against both analytic and numeric reference solutions to assess accuracy and convergence.
- Analyze numerical damping by deriving the Alfvén wave solution with physical Navier-Stokes viscosity and fitting the resulting effective viscosity to $\eta_{\text{num}} \propto a^{-5/2}$.
Experimental results
Research questions
- RQ1How can analytic solutions for hydromagnetic waves in comoving coordinates be derived to serve as reference solutions for cosmological MHD code testing?
- RQ2What is the behavior of Alfvén and magnetosonic wave amplitudes in an Einstein-de-Sitter universe, and how do they evolve with the scale factor $a$?
- RQ3How do numerical simulations of these waves in $\Lambda$CDM cosmology compare to high-precision numerical solutions?
- RQ4Can numerical damping in low-resolution simulations be quantitatively linked to a numerical viscosity coefficient, and what is its dependence on the scale factor?
- RQ5To what extent can these wave-based tests detect subtle implementation errors in cosmological MHD codes, especially those involving $a$ and $\dot{a}$?
Key findings
- The analytic solutions for Alfvén and magnetosonic waves in an EdS universe show excellent agreement with arepo simulations when sufficient grid resolution is used.
- Numerical damping in simulations with few grid points is well described by a numerical viscosity coefficient $\eta_{\text{num}} \propto a^{-5/2}$, which matches the derived physical scaling.
- The comparison between arepo simulations and high-precision numerical solutions for $\Lambda$CDM shows that waves oscillate more frequently than in EdS due to the longer cosmic time span between $a_i = 1/128$ and $a = 1$.
- Intentionally introduced bugs in the arepo code—such as incorrect scaling of the $\dot{a}$ term—were successfully detected by comparing simulation outputs with analytic solutions, even when no obvious numerical failure occurred.
- The wave-based test suite is effective at identifying subtle coding errors, such as incorrect scaling of viscosity terms in comoving coordinates, which would otherwise go undetected.
- The authors conclude that these tests should be integrated into automated regression testing frameworks for cosmological MHD codes to improve code reliability and prevent regressions.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.