Excellent reviews on the subject are those by Subramanian (2010, 2016):
For Pencil Code installation etc., please see Alberto's website on the Pencil Code School in Early Universe Physics
One often thinks that magnetic field generation involves charge separation, but this is mostly not true. An exception are battery mechanisms such as the Biermann battery. (The term battery refers to a growth that is linear in time, as opposed to an exponential growth, for example.) The following handout discusses this in more detail.
There are both specific run directories for exercises, but also others related to earlier papers (below) and to samples used in the Pencil Code for testing purposes.
Brandenburg, A., & Protiti, N. N.: 2023, “Electromagnetic conversion into kinetic and thermal energies,” Entropy 25, 1270
(arXiv:2308.00662, ADS, DOI, HTML, PDF)
Brandenburg, A., & Protiti, N. N.: 2023, Datasets for “Electromagnetic conversion into kinetic and thermal energies” v2023.08.01. Zenodo, DOI:10.5281/zenodo.8203242
(HTML, DOI)
The Klein-Gordon equation governs the evolution of scalar or pseudoscalar fields. The cosine potential plays a special role for axion inflation. This form of the potential make the equation nonlinear and can lead to very interesting solutions in their own right. To check how the code solves such cases, we begin with a 1+1 dimensional example, the
Try an run the code with slightly modified parameters. An experiment of general interest is to run the code with lower or higher time discretization that the standard 6th order one.
Iarygina, O., Sfakianakis, E. I., & Brandenburg, A.: 2025, “Schwinger effect in axion inflation on a lattice,” Phys. Rev. Lett., submitted
(arXiv:2506.20538, ADS, HTML, PDF)
Iarygina, O., Sfakianakis, E. I., & Brandenburg, A.: 2025, Datasets for “Schwinger effect in axion inflation on a lattice” v2025.06.24.
(HTML).
In the early universe, primordial magnetic fields are likely of sufficient energy that the associated magnetic stress must have driven relic gravitational waves. They would not have decayed since their generation, so their detection would reveal an independent picture of what happened early on.
Again, there is a gravitational waves sample, GravitationalWaves, directly as part of the Pencil Code. As usual, it is usually not good to work in that directory if you want to modify thing. It is better to have your own directory, so say something like "pc_newrun ~/axels_runs/16a". I call it like so, because I want to work with 163 mesh points. But I also want to change a few other things, like the number of timesteps or the Courant condition.
Roper Pol, A., Brandenburg, A., Kahniashvili, T., Kosowsky, A., & Mandal, S.: 2020, “The timestep constraint in solving the gravitational wave equations sourced by hydromagnetic turbulence,” Geophys. Astrophys. Fluid Dyn. 114, 130–161 (arXiv:1807.05479, ADS, HTML, DOI, PDF)
Roper Pol, A., Mandal, S., Brandenburg, A., Kahniashvili, T., & Kosowsky, A.: 2020, Datasets for “Numerical Simulations of Gravitational Waves from Early-Universe Turbulence”' v2020.02.28. DOI:10.5281/zenodo.3692072 (HTML, DOI)
Brandenburg, A., He, Y., Kahniashvili, T., Rheinhardt, M., & Schober, J.: 2021, “Gravitational waves from the chiral magnetic effect,” Astrophys. J. 911, 110 (arXiv:2101.08178, ADS, DOI, HTML, PDF)
As emphasized in the introduction, an important problem in primordial magnetogenesis is the small length scale of such fields. But there were still many gaps in our initial understanding of the importance of turbulent inverse cacades.
In the exercises, we consider low-resolution 2-D runs, which can easily be run on a laptop. In that case, the conserved quantity is the anastrophy. Conserved quantities can play a crucial role in determining the decay behavior. In helical turbulence, the conserved quantity is the mean magnetic helicity density, $\bra{\AAA\cdot\BB}$. However, even in nonhelical turbulence with a strong magnetic field (compared to kinetic energy), there can be an inverse cascade (Kahniashvili, et al., 2013). It is believed that it is explained by the conservation of magnetic helicity fluctuations, which are quantified by the Hosking integral.
Kahniashvili, T., Tevzadze, A. G., Brandenburg, A., & Neronov, A.: 2013, “Evolution of primordial magnetic fields from phase transitions,” Phys. Rev. D 87, 083007 (arXiv:1212.0596, ADS, DOI, PDF)
Brandenburg, A., Kahniashvili, T., & Tevzadze, A. G.: 2015, “Nonhelical inverse transfer of a decaying turbulent magnetic field,” Phys. Rev. Lett. 114, 075001 (arXiv:1404.2238, ADS, DOI, PDF, Supp)
Brandenburg, A., & Kahniashvili, T.: 2017, “Classes of hydrodynamic and magnetohydrodynamic turbulent decay,” Phys. Rev. Lett. 118, 055102 (arXiv:1607.01360, ADS, DOI, PDF, Supp)
Zhou, H., Sharma, R., & Brandenburg, A.: 2022, “Scaling of the Hosking integral in decaying magnetically-dominated turbulence,” J. Plasma Phys. 88, 905880602 (arXiv:2206.07513, ADS, DOI, HTML, PDF)
Brandenburg, A., Neronov, A., & Vazza, F.: 2024, “Resistively controlled primordial magnetic turbulence decay,” Astron. Astrophys. 687, A186 (arXiv:2401.08569, ADS, DOI, HTML, PDF, ad)
Brandenburg, A., & Banerjee, A.: 2025, “Turbulent magnetic decay controlled by two conserved quantities,” J. Plasma Phys. 91, E5 (arXiv:2406.11798, ADS, DOI, HTML, PDF)
Brandenburg, A., Yi, L., & Wu, X.: 2025, “Inverse cascade from helical and nonhelical decaying columnar magnetic fields,” J. Plasma Phys. 91, E113 arXiv:2501.12200, ADS, DOI, HTML, PDF)
Zhang, J., & Brandenburg, A.: 2025, “Resistive scaling in the magnetic helicity-driven inverse cascade,” Astrophys. J., submitted (arXiv:2509.21141, ADS, PDF)
Dynamos generally convert kinetic energy into magnetic energy. This is possible through the dynamo instability, which refers to an instability of the zero magnetic field state (B=0). It is clear that this requires the existence of a seed magnetic field, but the existence of a perturbation (here of the B=0 state) is true of any instability.
Brandenburg, A., & Subramanian, K.: 2005, “Astrophysical magnetic fields and nonlinear dynamo theory,” Phys. Rep. 417, 1–209 (astro-ph/0405052, ADS, DOI, PDF)
Rheinhardt, M., Devlen, E., Rädler, K.-H., & Brandenburg, A.: 2014, “Mean-field dynamo action from delayed transport,” Mon. Not. Roy. Astron. Soc. 441, 116–126 (arXiv:1401.5026, ADS, DOI, PDF)
Shchutskyi, N., Schaller, M., Karapiperis, O. A., Stasyszyn, F. A., & Brandenburg, A.: 2025, “Kinematic dynamos and resolution limits for Smoothed Particle Magnetohydrodynamics,” Mon. Not. Roy. Astron. Soc. 541, 3427–3444 (arXiv:2505.13305, ADS, DOI, HTML, PDF)
How much magnetic field will have survived and what is its length scale today? To answer these questions, we have to understand how the physics changes during this time and how this affects the inverse cascade behavior.
We know the conformal time and comoving coordinates, but there are also supercomoving coordinates defined with higher powers of a (Martel & Shapiro 1998). In the exercises, we compare different cases.
The Pencil Code (Pencil Code Collaboration 2021) is constantly developing since it started. The organic growth is reflected in the style of the manual (link below), where new things are constantly being added, but old things are hardly deleted. It is important to watch the autotests (link below) to make sure nothing bad has happened.
Pencil Code Collaboration: Brandenburg, A., Johansen, A., Bourdin, P. A., Dobler, W., Lyra, W., Rheinhardt, M., Bingert, S., Haugen, N. E. L., Mee, A., Gent, F., Babkovskaia, N., Yang, C.-C., Heinemann, T., Dintrans, B., Mitra, D., Candelaresi, S., Warnecke, J., Käpylä, P. J., Schreiber, A., Chatterjee, P., Käpylä, M. J., Li, X.-Y., Krüger, J., Aarnes, J. R., Sarson, G. R., Oishi, J. S., Schober, J., Plasson, R., Sandin, C., Karchniwy, E., Rodrigues, L. F. S., Hubbard, A., Guerrero, G., Snodin, A., Losada, I. R., Pekkilä, J., & Qian, C.: 2021, “The Pencil Code, a modular MPI code for partial differential equations and particles: multipurpose and multiuser-maintained,” J. Open Source Softw. 6, 2807 (arXiv:2009.08231, ADS, DOI, HTML, PDF)