A numerical code to simulate the interaction of a stellar wind with a planetary magnetosphere (downloadable on this site)

Last update: 16 August 2023 (updated version of the code)

PLANET_MAG_AMRVAC is a code which numerically simulates the interaction of a supersonic stellar wind with the magnetosphere of a magnetized planet. The code can be applied to the case of the solar wind interacting with Mercury, the Earth or with one of the giant planets of the solar system. The code is flexible and can be used to simulate the interaction of a generic stellar wind with the magnetosphere of an arbitrary exoplanet.

Depending on the configuration, a simulation may last less than one hour on a laptop or several days on a supercomputer offering hundreds of cores.

The code solves the time-dependent 3D magnetohydrodynamic (MHD) equations. It can be downloaded here (size < 1 MB). The code is MPI-parallelized and runs on Linux (potentially also on Mac OSX).

Windows users may run the code within a Linux virtual machine. Various sites explain how to install a virtual machine (see e.g. here).

Simulation de la magnéosphère de Mercure avec le code PLANET_MAG_AMRVAC
Mercury’s magnetosphere simulated with PLANET_MAG_AMRVAC

Installing and testing the code:

Some software may not be installed on your Linux. Most of the time, problems during installation or execution of the code are due to missing software. So, please verify that at least the following ones are installed gfortran, mpirun, make, perl, bash, csh, sed, awk. If necessary, install the missing ones.

1 – Download the compressed folder with all the required files from here

2 – Expand the folder in a place of your choice on your computer (in a place where you have write access). To do so, you may open a terminal in the folder with the downloaded file and type (NB: adapt instruction with name of downloaded file):

tar zxvf planet_mag_amrvac_2023-02-29_18-42-25.tar.gz

3 – Enter into the newly created folder and proceed to the sub-folder /Mysimulations/Planet_mag/. To do so, in the terminal, type successively, e.g. :

cd ./planet_mag_amrvac_2023-02-29_18-42-25
cd ./Mysimulations/Planet_mag/

4 – In the terminal, type:


5 – And, if no errors, type :


Answer “y” (without quotation marks) to the question. Verify that the code compiles with no errors. Compiling can last a few minutes.

NB: Errors are most offen due to one ore more missing software. If everything goes as expected you should see the following message in your terminal:

 Finished AMRVAC in : 9.427 sec

6 – Simulation results are stored in a sub-folder of ./datamr a series of files of the type *0000.dat, *0001.dat, …

NB: Verify that the folder with at least two files *.dat in it has effectively been created.

If you passed all the above steps, the code is in principle correctly installed and working on your machine.

Visualizing results

To visualize the results of your simulation, it is necessary to transform the *.dat files into a format readable by some 3D visualization software. We recommend using the VTU format for importing into the open-source software ParaView (see paraview.org) which is available for Linux, macOS and Windows platforms.

1 – To convert *.dat files to *.vtu files, go to the directory with the *.dat files (a subdirectory of ./datamr ) and use the aiconvert script which is located in the tools subdirectory of the upper folder of the installed tree. So, for example, to convert all *0000.dat, *0001.dat, …, *0008.dat you should type:

  ../../../../../tools/aiconvert 0 8                        

2 – To import the *.vtu files into ParaView do the following: Start ParaView (e.g. by typing paraview in a terminal). In the ParaView upper bar select File -> Open, mouse-left-click on the list of the corresponding *.vtu files and click on OK. This will load all files at once into ParaView.

NB: The target format of the conversion is specified in the amrvac.par file on the line with convert_type=’vtumpi’. You may find here a list with the accepted formats.

Adapt the simulation parameters to your needs

You can modify the simulation parameters by modifying the input_parameters file which is located in the directory /Mysimulations/Planet_mag/, ie the same one from which you launched the previous simulation. In this file you can specify the parameters of the stellar wind, the planetary parameters, the size of the simulation domain, the coarseness of the numerical grid, the duration of the simulation, etc. Most parameters should be understandable without special explanations. On each line of the file, the text after one or more # is a comment.

The simulation domain corresponds to the volume enclosed by two spherical shells with the same centre and radius xprobmin1 (inner boundary of the simulation) and xprobmax1 (outer boundary of the simulation). The numerical grid is structured in spherical geometry (r, theta, phi) with the planet’s centre located at r=0.

The conditions at the inner boundary (at r=xprobmin1) for the 3 components of the fluid momentum (m_r_inner_boundary, m_theta_inner_boundary, m_phi_inner_boundary) can be adapted to some extent as described here. Pressure and density are user defined constant values for the whole boundary, whereas the magnetic field is defined by the user defined multipolar coefficients and magnetic axis orientation in the Planetary parameters section of the input_parameters file.

When satisfied with the settings in input_parameters just repeat steps 4 and 5 to start a new simulation.

NB 1: The stellar wind does always flow parallel to the z-axis, towards negative z values.

NB 2: At the outer boundary, along its intersection with a cone with its vertex in r=0 and an opening angle of 160 deg with respect to the negative z-axis, the conditions are of the type “free outflow” with the radial variation equals to zero for all fields (i.e. ∂/∂r =0). On the remaining portion of the outer boundary stellar wind values are imposed.  

Download planet_mag_amrvac

About Filippo Pantellini

Researcher at Paris Observatory (an institution of PSL university)
This entry was posted in Magnetohydrodynamics, Planetary magnetospheres, Solar wind and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.