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., Neronov, A., & Vazza, F.: 2024, “Resistively controlled primordial magnetic turbulence decay,” Astron. Astrophys. 687, A186 (arXiv:2401.08569, ADS, DOI, HTML, PDF, ad)
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)
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)