User Guide
User Guide
2 (Aug 2015)
User’s Guide
(http://plutocode.ph.unito.it)
1 Dipartimento di Fisica, Turin University, Via P. Giuria 1 - 10125 Torino (TO), Italy
2 INAF Osservatorio Astronomico di Torino, Via Osservatorio, 20 10025 Pino Torinese (TO), Italy
3 Dept. of Astronomy & Astrophysics, University of Chicago, 5640 S. Ellis Ave Chicago, IL 60637, USA
4 Consorzio Interuniversitario CINECA, via Magnanelli, 6/3, 40033 Casalecchio di Reno (Bologna), Italy
5 FLASH Center, University of Chicago, USA
6 Department of Physics, University of Bucharest, Str. Atomistilor nr. 405, RO-077125 Magurele, Ilfov, Romania
Terms & Conditions of Use
PLUTO is distributed freely under the GNU general public license. Code’s development and support
requires a great deal of work and for this reason we expect PLUTO to be referenced and acknowledged
by authors who use it for their publications. Co-authorship may be solicited for those publications
demanding considerable additional support and/or changes to the code.
1
Contents
0 Quick Start 6
0.1 Downloading and unpacking PLUTO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
0.2 Running a simple shock-tube problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
0.3 Running the Orszag-Tang MHD vortex test . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
0.4 Setting up your own test problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
0.5 Supplied test problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
0.6 Migrating from PLUTO 4.1 to PLUTO 4.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1 Introduction 12
1.1 System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2 Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3 Configuring PLUTO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.4 Compiling & Running the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.4.1 Command line options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.5 Modifying the Distribution Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2
3 Makefile Selection: makefile 29
3.1 MPI Library (Parallel) Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.1.1 Asynchrounous I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2 HDF5 Library Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.3 PNG Library Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.4 Including Additional Files: local make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7 Equation of State 67
7.1 The ISOTHERMAL Equation of State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
7.2 The IDEAL Equation of State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
7.3 The PVTE LAW Equation of State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
7.3.1 Example: EOS for a Partially Ionized Hydrogen Gas in LTE . . . . . . . . . . . . . 69
7.3.2 Analytic vs. tabulated approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
7.4 The TAUB Equation of state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
8 Dissipative Effects 72
8.1 Viscosity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
8.2 Resistivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
8.3 Thermal Conduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
8.3.1 Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
8.4 Numerical Integration of Diffusion Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.4.1 Explicit Time Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3
8.4.2 Super-Time-Stepping (STS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10 Additional Modules 86
10.1 The ShearingBox Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
10.1.1 Using the module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
10.2 The FARGO Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
10.2.1 Using the Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
10.2.2 A Note on Parallelization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
10.3 High-order Finite Difference Schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
10.3.1 WENO schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
10.3.2 LimO3 & MP5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4
A.2.3 Spherical Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
5
0. Quick Start
this will create the folder PLUTO/ in your home directory. At this point, we advise to set the environment
variable PLUTO DIR to point to your code directory. Depending on your shell (e.g. tcsh or bash) use
either one of
˜> export PLUTO_DIR=/home/user/PLUTO # If you’re using the bash shell;
˜> setenv PLUTO_DIR /home/user/PLUTO # If you’re using the tcsh shell;
˜> cd $PLUTO_DIR/Test_Problems/HD/Sod
2. Copy the header and initialization files from a configuration of our choice (e.g. #01):
and select “Setup problem” from the main menu, see Fig. 1.2. You can choose (by pressing Enter)
or modify the default setting using the arrow keys.
4. Once you return to the main menu, select “Change makefile”, choose a suitable makefile (e.g.
Linux.gcc.defs) and press enter.
All the information relevant to the specific problem should now be stored in the four files init.c
(assigns initial condition and user-supplied boundary conditions), pluto.ini (sets the number of
grid zones, Riemann solver, output frequency, etc.), definitions.h (specifies the geometry, number
of dimensions, interpolation, time stepping scheme, and so forth) and the makefile.
5. Exit from the main menu (“Quit” or press ’q’) and type
˜/PLUTO/Test_Problems/HD/Sod> make
6
CHAPTER 0. QUICK START 7
˜/PLUTO/Test_Problems/HD/Sod> ./pluto
At this point, PLUTO reads the initialization file pluto.ini and starts integrating. The run should
take a few seconds (or less) and the integration log should be dumped to screen.
Data can be displayed in a number of different ways. If you have, for example, Gnuplot (v 4.2 or higher)
you can display the density output from the last written file using
gnuplot> plot "data.0001.dbl" bin array=400:400:400 form="%double" ind 0
where ind 0,1,2 may be used to select density, velocity or pressure. If you have IDL installed on your
system, you can easily plot the density by1 :
IDL> pload,1
IDL> plot,x1,rho
The IDL procedure pload is provided along with the code distribution.
˜/PLUTO/Test_Problems/MHD/Orszag_Tang> make
7. If compilation was successful, you can now run the code by typing
˜/PLUTO/Test_Problems/MHD/Orszag_Tang> ./pluto
At this point, PLUTO reads the initialization file pluto.ini and starts integrating. The run should
take a few minutes (depending on the machine you’re running on) and the integration log should
be dumped to screen.
You can display data (e.g. density) with Gnuplot (v 4.2 or higher) from the last written file using
gnuplot> set pm3d map # set map style drawing
gnuplot> set palette gray # set color to black and white
gnuplot> splot "data.0001.dbl" bin array=200x200 format="%double"
If you have IDL installed, you can easily display pressure from the last written output files with
IDL> pload,1
IDL> display,x1=x1,x2=x2,prs
Several other visualization options are described in more details in §11.3.
1 You need to include PLUTO/Tools/IDL into your IDL search path, §11.3.2
CHAPTER 0. QUICK START 8
1. First, in your home or work directory, you need to create a folder which will contain the necessary
files for the test. For instance,
2. You can now start the setup process by invoking the Python script to set dimensions, geometry,
numerical scheme and so on:
4. Finally, we complete the python session by setting the architecture for the makefile. In the makefile
menu choose your system configuration (e.g. Linux.gcc.defs for Linux). Press enter to confirm.
You are now done with the Python script and can exit by pressing either “q” or selecting quit. At this
point you should find the following four files inside your Blastwave folder: definitions.h, init.c, makefile,
pluto.ini, sysconf.out
Next, we need to edit the two files pluto.ini and init.c. The first one defines the computational domain
and certain properties of the run (i.e. time of integration, first timestep etc). The second one sets the
initial conditions for the blast wave problem: a circular region of high pressure in a lower pressure
ambient.
Edit pluto.ini to make the following changes:
• The domain should span from -1 to 1 in both dimensions with 200 points in each direction.
tstop 0.04
first_dt 1.e-6
Save the files every t=0.004, in double precision and in multiple files format.
• At the end of the file, set the numerical values for the 3 parameters P IN (the high pressure of a
region yet to be specified), P OUT (the ambient pressure) and GAMMA (polytropic index):
CHAPTER 0. QUICK START 9
P_IN 8.e2
P_OUT 8.0
GAMMA 1.666666666666667
double r;
• Set the global variable g gamma (polytropic index) and the radius r. Define the initial ambient
pressure (P OUT) and put an IF statement to specify the high pressure region inside a circle of r=
0.3 (P IN):
g_gamma = g_inputParam[GAMMA]; /* calls the auxiliary parameter GAMMA*/
r = x1*x1 + x2*x2;
r = sqrt(r);
Save and exit the editor. Compile the code and run PLUTO with a the following set of commands:
˜/Blastwave> make
˜/Blastwave> ./pluto
In order to visualize the results follow the instructions described in the two previous sections.
Structural Changes:
===================
- User defined constants have been removed from the python script and
can now be added manually by editing a dedicated section in definitions.h.
- The old array indexing style using a two-letter index (e.g. DN, PR, VX,...)
is no longer supported. Use RHO, PRS, VX1, ... instead.
- The macro STS_nu has been changed to STS_NU, it has been removed from the
python script and it can be inserted manually in the user-defined
constant section of definitions.h
- ENTROPY_SWITCH does not take the value YES/NO anymore but it has more
options, see the documentation.
- RHD primitive variables always contain the 3 velocity although 4-vel can
CHAPTER 0. QUICK START 11
- The HD/ and MHD/ modules share the same RightHandSide() function inside
MHD/rhs.c. Likewise, source terms have been separately implemented in
MHD/rhs_source.c
Fixed Bugs:
===========
- IDL pload function with var=".." now works also for multiple files;
- Fixed a number of minor bugs in H2_COOL module and improved
CompEquil() function;
- PPM method works correctly for non-uniform grid in any coordinate system;
- FlagShock now called when using chombo (MULTID shock flattening and
ENTROPY_SWITCH)
- PLUTO-Chombo now writes plotfiles correctly when restarting from a
checkpoint file (changed AMR.cpp in library)
- GLM complained with Background field splitting: print removed;
- Resistivity + background can be used (removed QUIT statement from
MHD/bckgrnd_file.c);
- PathCTU.1D has been removed and all 1D AMR computations are done
with PatchCTU.cpp or PatchEuler.cpp;
- VTK files can now be visualized with PARAVIEW;
- PVTE_LAW now uses cubic spline interpolation rather than linear
along the temperature axis;
- Chombo "LevelPluto::step: alpha < 0" crash has been partially solved.
- Tabulated cooling takes into account the mean molecular weight.
1. Introduction
PLUTO adopts a structured mesh approach for the solution of the system of conservation laws (1.1).
Flow quantities are discretized on a logically rectangular computational grid enclosed by a boundary
and augmented with guard cells or ghost points in order to implement boundary conditions on a given
computational stencil. Computations are done using double precision arithmetic.
The grid can be either static or dynamically adaptive as the flow evolves. In the static grid version
PLUTO comes as a stand-alone package entirely written in the C programming language, see [MBM+ 07]
for a comprehensive description. In the adaptive grid version the code relies on the Chombo library for
adaptive mesh refinement (AMR) written in C++ and Fortran (Chapter 12). A detailed description of
the AMR implementation is given in [MZT+ 12].
Doxygen is used as the standard documentation system and the Application Programming Interface
(API) reference guide can be found in Doc/API-ReferenceGuide.html.
PLUTO has been successfully ported to several parallel platforms including Linux, Windows/Cyg-
win, Mac OS X, Beowulf clusters, IBM power4 / power5 / power6, SGI Irix, IBM BluGene/P and several
others. Figure 1.1 shows the strong scaling on a BlueGene/P machine up to 32, 768 processors on a pe-
riodic domain with 5123 computational grid zones.
12
CHAPTER 1. INTRODUCTION 13
Table 1.1: Software requirements for different applications of PLUTO. Here “opt” stands for optional, ”serial“ refers to single-
processor runs and ”parallel“ to multiple-processor architectures.
Starting with PLUTO 4 parallelization is handled internally and ArrayLib, used in previous versions
of the code, is no longer necessary. The Chombo library is required for computations making use of
Adaptive Mesh Refinement (Chapter 12), while the PNG library should be installed only if PNG output
is desired. The HDF5 library is required for I/O with the Chombo library and may also be used with
the static grid version of the code.
Option Description
- -with-chombo enables support for adaptive mesh refinement (AMR) using the Chombo library, Chapter 12;
Table 1.2: Command line options available when running the Python setup script.
Command line options are listed in Table 1.2 or can be briefly described by invoking setup.py with
- -help. By default the Python script uses the ncurses library for enhanced terminal control. However,
this option may be turned off by invoking the setup script with the - -no-curses switch. You should
then1 see the menu shown in Fig. 1.2. Additional menus, depending on the physics module, will display
later.
1 Python will first create an architecture-dependent file named sysconf.out containing system-related information: this file does
not have any specific purpose but may be helpful for the user. Whenever an internet connection is available, Python will also
notify if new versions of the code are available.
CHAPTER 1. INTRODUCTION 15
where step gives the current integration step, t is the current integration time, dt is the current time
step, n% is the percentage of integration. The two numbers in square brackets are, respectively, the max-
imum Mach number and maximum number of iterations required by the Riemann solver (if iterative,
e.g. two shock) during the previous step. For non-iterative Riemann solvers, the last number will al-
ways display 0. The maximum Mach number is a very sensitive function of the numerical method it
may be used as a “robustness” indicator. Very large Mach numbers or rapid variations usually indicate
problems and/or fixes during the computation.
Table 1.3: Command line options available when running PLUTO . Compatibility with AMR version is given in the last column.
†: on parallel architectures only
Note: Header files (*.h or *.H) do not follow the same convention and must not be copied to
the local working directory. Modifications to header files must therefore be done in the original
directory.
2. Problem Header File: definitions.h
This chapter explains how to create the configuration header file definitions.h for a specific problem.
The header file definitions.h also contains other more advanced switches that are not accessible via the
Python script (§2.4) and should be changed manually. We now describe the options accessible through
the Python script.
2.1.1 PHYSICS
Specifies the fluid equations to be solved. The available options are:
• HD: classical hydrodynamics described by the Euler equations, §6.1;
17
CHAPTER 2. PROBLEM HEADER FILE: DEFINITIONS.H 18
direction as well (say ∂vz /∂x, ∂vz /∂y 6= 0). An example is an axisymmetric 2-D cylindrical problem
(such as a disk or a torus) in the (r, z) plane with a uniform rotation in the azimuthal direction φ (where
it is assumed ∂/∂φ = 0). In all cases it is required that DIMENSIONS ≤ COMPONENTS.
2.1.3 GEOMETRY
Sets the geometry of the problem. Spatial coordinates are generically labeled with x1 , x2 and x3 and
their physical meaning depends on the value assigned to GEOMETRY:
• CARTESIAN : Cartesian coordinates {x1 , x2 , x3 } = {x, y, z};
• CYLINDRICAL: cylindrical axisymmetric coordinates {x1 , x2 } = {r, z} (1 or 2 dimensions);
2.1.5 COOLING
Optically thin thermal losses can be included by appropriately setting this flag to one of the following:
• POWER LAW : radiative losses are proportional to ρ2 T α (§9.1);
• TABULATED: radiative losses are computed as n2 Λ(T ), where Λ(T ) is a user-supplied tabulated
function of temperature, see §9.2. Alternatively, this module can be used to provide user-defined
cooling functions;
• SNEq: simplified non-equilibrium cooling function for atomic hydrogen. See §9.3 for more details;
• H2 COOL: optically thin cooling function for molecular and atomic hydrogen. See §9.4.
• MINEq: multi-ion non-equilibrium cooling model. It evolves the standard equations augmented
with a chemical network of 29 ions, see §9.5 and the work by [TMM08].
CHAPTER 2. PROBLEM HEADER FILE: DEFINITIONS.H 19
2.1.6 RECONSTRUCTION
Sets the spatial order of integration. In the standard (finite volume) version of the code, the following
options are available:
• LimO3: provides 3rd order limiter function [ČT09] based on a 3-point stencil.
• PARABOLIC: piecewise parabolic method (PPM) as implemented by [Mig14]. The stencil requires
5 zones.
The default is LINEAR. Both WENO3 and LimO3 employ a local three-point stencil to achieve piecewise-
quadratic reconstruction for smooth data and preserves their accuracy at local extrema thus avoiding
clipping of classical second-order TVD limiters and PPM. Non-uniform grid spacing and curvilinear
coordinates are handled more correctly with LINEAR and PARABOLIC using the approach presented in
[Mig14].
Note that although 3rd -order reconstructions are available, the finite volume version of the code
retains a global 2nd -order accuracy as fluxes are computed at the interface midpoint. On the contrary,
genuine 3rd and 5th order accurate schemes can be employed using the conservative finite difference
framework, §10.3.
U n+1 = U n + ∆tn Ln
• RK2, RK3: 2nd or 3rd -order TVD Runge Kutta is used to advance the solution to the next time level:
RK2 RK3
U ∗ = U n + ∆tn Ln U ∗ = U n + ∆tn Ln
(2.1)
− U ∗∗ = 14 3U n + U ∗ + ∆tn L∗
U n+1 = 1
2 U n + U ∗ + ∆tn L∗ U n+1 = 13 U n + 2U ∗∗ + 2∆tn L∗∗
When DIMENSIONAL SPLITTING = YES, the operator L in Eq. (2.1) is one-dimensional. Setting
DIMENSIONAL SPLITTING to NO makes the scheme dimensionally unsplit and the right hand side
include contributions from all directions simultaneously. Unsplit implementation of the Runge-
Kutta algorithms usually requires a more restrictive CFL condition, see Table 2.1.
• CHARACTERISTIC TRACING, HANCOCK: they evolve U n according to
1
U n+1 = U n + ∆tn L(V n+ 2 )
1
where V n+ 2 is computed by suitable Taylor expansion. Although the final step is in diver-
gence form, these methods require the primitive formulation of the equations, not yet available
CHAPTER 2. PROBLEM HEADER FILE: DEFINITIONS.H 20
for all modules. They are 2nd order accurate in space and time and less dissipative than the
previous multi-step algorithms. HANCOCK should be combined with linear reconstruction while
CHARACTERISTIC TRACING which does a more sophisticated characteristic limiting, can be com-
bined with all reconstruction algorithms. The original PPM scheme of [CW84, MM96] is available
for the HD, MHD and RHD modules by selecting TIME STEPPING to CHARACTERISTIC TRACING,
together with RECONSTRUCTION to PARABOLIC and a two-shock Riemann solver (Roe or hlld
alternatively).
Setting DIMENSIONAL SPLITTING = NO yields the spatially unsplit fully corner-coupled method
of [Col90, MPB05]. This scheme is stable under the condition CFL . 1 (in 2D) and CFL . 1/2 (in
3D) and it is slightly more expensive than RK2.
Time Step Determination. The time step ∆tn is computed using the information available from the
previous integration step and it can be controlled by the Courant-Friedrichs-Lewy (CFL) number Ca
within the limits suggested in Table 2.1, see [Bec92]. Thus one immediately sees that, if ∆l is the cell
physical length, the time step roughly scales as ∼ ∆l for hyperbolic problems and as ∼ ∆l2 when
parabolic terms are included (§8.4.1). On the contrary, when parabolic terms are included via Super-
Time-Stepping integration (§8.4.2) the time step can be much larger being computed solely from the
advection time scale (i.e. τd = 0 in the table below).
Multi-step algorithms (RK2, RK3) work in all system of coordinates and are the default choice. Single-
step schemes (HANCOCK, CHARACTERISTIC TRACING) are more sophisticated, have less dissipation
and have been tested mainly on Cartesian and cylindrical grids. Have a look at Table 2.2 for a compari-
son between different (suggested) integration schemes commonly adopted in testing the code.
Table 2.1: CFL conditions used by PLUTO for different explicit time stepping methods. For a given direction d, ∆ld represents
the cell physical length in that direction, λd provides the largest signal speed while τd accounts for diffusion processes. Here HNCK
and ChTr stand for HANCOCK and CHARACTERISTIC TRACING, respectively. These limits are based on a stability analysis on the
constant coefficient advection-diffusion equation by by Beckers (1992), [Bec92].
Table 2.2: Suggested algorithm configurations. The cost (4th column) is given in terms of number of Riemann problems per cell
per step. Ndim is the number of spatial dimensions. ChTr stands for CHARACTERISTIC TRACING.
CHAPTER 2. PROBLEM HEADER FILE: DEFINITIONS.H 22
2.1.9 NTRACER
The number of passive scalars or ”colors” (denoted with Qk ) obeying simple advection equations of the
form:
∂Qk ∂(ρQk )
+ v · ∇Qk = 0 ⇐⇒ + ∇ · ρQk v = 0 (2.2)
∂t ∂t
The second form gives the conservative equation and it is the one actually being discretized by the code.
The array index used to access tracer variables (§5.1,§5.2) is TRC for the first tracer, TRC+1 for the second
one and so on. The maximum number is 4.
Sets the number of user-defined parameters that can be changed at runtime and accessed from any-
where in the code. The explicit numerical value is read at runtime from pluto.ini and can be changed
before execution without re-compiling the code. The parameters are identified by means of a label
corresponding to an index of the global array g inputParam visible anywhere in the program. If,
for instance, USER DEF PARAMETERS has been set equal to 3, you will be prompted to define 3 differ-
ent “labels”, say FOO 1, FOO 2 and FOO 3, as in Fig. 2.2. These names are the integer indexes of the
g inputParam array: g inputParam[FOO 1] will contain the actual value of the first user-defined
parameter, g inputParam[FOO 2] the second one and so forth.
The maximum number is 31 and parameter names should be chosen with care in order to avoid
overlapping conflicts with names that are already defined in the code. Although there are no strict
rules, we strongly advise to use capital letters, to avoid short labels such as “V0” or “VX” and to choose
a more representative name that explains the use of the variable on its own, e.g., PAR INFLOW VEL.
Parameter names (and values) are automatically inserted inside pluto.ini in the correct order after the
execution of the python script. However, if you use a different initialization file than pluto.ini, you may
have to set the parameter names together with their values manually.
CHAPTER 2. PROBLEM HEADER FILE: DEFINITIONS.H 23
• EIGHT WAVES
magnetic fields retain a cell average representation and the eight wave formulation introduced by
Powell [Pow94] is used, see §6.2.3.1;
• DIV CLEANING
magnetic fields retain a cell average representation and the mixed hyperbolic/parabolic diver-
gence cleaning technique of [DKK+ 02, MTB10] is used, see §6.2.3.2. A new scalar variable, the
generalized Lagrange multiplier ψ (PSI GLM) is introduced.
• CONSTRAINED TRANSPORT
the magnetic field has a staggered representation and the constrained transport is used, see §6.2.3.3.
2.2.3 EOS
Select the equation of state (EOS):
• IDEAL
use the perfect gas law with constant specific heat ratio. This EOS is available for all physics
module and it is described in §7.2.
• ISOTHERMAL
use an isothermal equation of state (§7.1). In this case, the energy equation is not included.
• PVTE LAW
allows the user to employ / implement more complex equations of state by specifying the caloric
EOS as e = e(ρ, T ). This EoS works for the HD and MHD module and is described in §7.3.
• TAUB
use the Taub-Matthews equation of state (only for relativistic modules), see §7.4.
Please refer to Chapter 7 for a detailed description.
CHAPTER 2. PROBLEM HEADER FILE: DEFINITIONS.H 24
Here F(σ) tells if a zone has been flagged with FLAG ENTROPY at the beginning of the step and it
depends on the value assigned to ENTROPY SWITCH:
• NO
the entropy equation is not included;
• SELECTIVE
by enabling this option a selective update is employed. By default, all zones are flagged to be
updated using the entropy equation unless they lie in proximity of a shock wave. Thus for each
zone, we evaluate
˜ · v < 0 and k∇pk/p
˜
(
0 if ∇ > p
F(σ) = (2.6)
1 otherwise,
˜ is a three-point undivided difference operator and p sets the shock strength threshold
where ∇
(see EPS PSHOCK ENTROPY in Appendix B.3). The first criterion acts as shock detector. The
implementation can be found in the source file Src/flag shock.c.
Note that by enabling this selective update, neither the total energy nor the entropy will generally
be conserved at the numerical level.
• ALWAYS
the entropy equation is used everywhere in the computational domain to update the solution
array, i.e., F(σ) = 1 always in Eq. (2.5). This choice is consistent only with smooth flows.
• CHOMBO REGRID
the energy equation is used everywhere in the computational domain, that is, F(σ) = 0 in Eq. (2.5).
However, pressure is still computed from entropy after projection, coarse-to-fine prolongation and
restriction operations (AMR only). This option violates energy conservation but has the advantage
of preserving entropy and pressure positivity in those situations where kinetic and/or magnetic
energies are the dominant contributions to the total energy density.
The ENTROPY SWITCH is also compatible with super-time-stepping although it will only be used
during the hydro steps.
Also, beware that in the current code release, the ENTROPY SWITCH may not compatible with all
divergence control methods in resistive MHD.
CHAPTER 2. PROBLEM HEADER FILE: DEFINITIONS.H 25
2.2.5 RESISTIVITY
Include resistive terms in the MHD equations, see §8.2. The available options are
∂ ∂p ρ(vφ + w)2
(ρvR ) + ∇ · (ρvR v) + =
∂t ∂R R
∂ ∂p
Rρ(vφ + wz ) + ∇ · [Rρ(vφ + w)v] + = 0 (2.7)
∂t ∂φ
2 2
∂ w w
E + z ρ + wρvφ + ∇ · F E + ρv + wρvφ v = 0
∂t 2 2
where w = RΩz , R is the cylindrical radius and F E is the standard energy flux and body force terms
have been omitted only for the sake of exposition.
Note that the source term in the radial component of the momentum equation implicitly contains
the Coriolis force and centrifugal terms:
2.2.8 VISCOSITY
Include viscous terms, see §8.1. Options are
of this file. Only lines beginning with #define should appear in this section as they will not be changed
by the python script. The value of a symbolic constant can be either a number or another symbolic
constant previously defined by the code (e.g. YES or NO) and cannot be changed at runtime.
User-defined symbolic constants are useful in the following circumstances:
1. Conditional compilation: useful when your initial configuration contains computationally expen-
sive code blocks that should be compiled separately. As an example, define (in your definitions.h)
the symbolic constant name as SETUP VERSION and give it the value of 0 or 1:
/* [Beg] user-defined constants (do not change this line) */
#define SETUP_VERSION 1
This symbolic macro name can then be used inside init.c (or any other source file) for conditional
compilation:
#if SETUP_VERSION == 0
{
/* implements version 0... */
}
#elif SETUP_VERSION == 1
{
/* implements version 1... */
}
#endif
2. Advanced options (expert users): override the default value of special constant macros used through-
out the code, a comprehensive list of which is given in Appendix B.3. This gives the user more
control on the code and it avoids copying and modifying source files in the local working directory.
A simple example is given by configuration #04 in the Test Problems/MHD/Rayleigh Taylor/ problem
where the symbolic constants
/* [Beg] user-defined constants (do not change this line) */
#define USE_RANDOM_PERTURBATION NO
#define CHOMBO_REF_VAR RHO
are be used in init.c to enable/disable a random perturbation and to tell PLUTO-Chombo that density
must be used as the refinement variable. Another typical example is provided by the CGS physical units
described §5.1.1.
CHAPTER 2. PROBLEM HEADER FILE: DEFINITIONS.H 27
where MINMOD LIM is the most diffusive and MC LIM is the least diffusive limiter. The TVD dia-
gram for the various limiter functions is shown in Fig 2.3.
All of the above limiters employ a 3-point stencil.
• CT EMF AVERAGE (string)
Control how the electromotive force (EMF) is integrated from the face center to the edges. This is
discussed in more detailed in §6.2.3.3.
• CT EN CORRECTION (YES/NO)
This option is available only in the MHD and RMHD modules. The default is NO, implying that
energy is not corrected after the conservative update. However, for low-beta plasma one may find
useful to switch this option to YES, as described in [BS99].
The makefile contains instructions to compile and link C source code files and produce the executable
pluto. The Python script creates a new makefile every time you choose Change makefile from the
menu; otherwise, it automatically updates the existing one after you have finished the problem setup.
If you choose to create a new makefile, Python will ask you to select an appropriate .defs file con-
taining architecture-dependent flags from the Config/ directory. The template Config/Template.defs can
be used to create a new configuration from scratch.
The simplest example is a definition file for a single-processor without any additional library. In this
case it suffices to set:
CC = cc
CFLAGS = -c -O
LDFLAGS = -lm
where CC is the name of your C compiler (cc, gcc, mpicc, etc...), CFLAGS are command line options
(such as optimization, search path, etc...) and LDFLAGS contains options to be passed to the linker.
The variables PARALLEL, USE HDF5 and USE PNG can be set to either TRUE or FALSE to enable or
disable parallel mode, support for HDF5 library and support for PNG library respectively in the static
grid version of PLUTO . When set to TRUE the same variable name is passed to PLUTO as a #define
directive with value 1.
As an example, if USE HDF5 is set to TRUE inside a .defs file then any C source file containing instruc-
tions inside a preprocessor directive #ifdef USE HDF5 ... #endif statement will be compiled.
Note: These switches are effective only in the static grid version of the code and have no effect
when creating a PLUTO-Chombo makefile, §12.2.
PARALLEL = TRUE
...
###############################
# MPI additional spefications
###############################
In this case, you may also modify existing variables or add new ones inside the conditional statement
beginning with ifeq.
When parallel mode is enabled, C source code sections that are specific to MPI should be enclosed
inside #ifdef PARALLEL ... #endif statements.
29
CHAPTER 3. MAKEFILE SELECTION: MAKEFILE 30
Note: This is an experimental feature that can be used, in the current version of the code, only for .flt
or .dbl binary files for saving cell-centered data.
###############################
# HDF5 library options
###############################
Note: PLUTO uses the HDF5 1.6 API although it may be linked with HDF5 1.8.x without any
problem since the H5 USE 16 API macro (defined in hdf5 io.c) forces the library to use HDF5 1.6
macro definitions.
1 Contrary to a blocking call which will not return until the I/O request is completed, a non-blocking call initiates an I/O
###############################
# PNG library options
###############################
This will instruct make that PLUTO has to be compiled and linked together with the (user-supplied) file
myfile.c which depends on myheader.h. This is particularly useful when the user wants to compile and
link the code together with supplementary routines contained in external files.
4. Runtime initialization file: pluto.ini
At start-up, the code checks for the pluto.ini input file (or a different one if the -i command flag is given)
that contains all the run-time information necessary for integration. A template for this file can be found
in the Src/Templates directory.
The initialization file is divided into eight different “blocks” enclosed by a
pair of square brackets · · · . Each block contains a set of labels and associated (mandatory or optional)
fields:
[Grid]
[Chombo Refinement]
Levels 4
Ref_ratio 2 2 2 2 2
Regrid_interval 2 2 2 2
Refine_thresh 0.3
Tag_buffer_size 3
Block_factor 4
Max_grid_size 32
Fill_ratio 0.75
[Time]
CFL 0.4
CFL_max_var 1.1
CFL_par 0.3 # optional
rmax_par 40.0 # optional
tstop 1.0
first_dt 1.e-4
[Solver]
Solver tvdlf
[Boundary]
X1-beg outflow
X1-end outflow
X2-beg outflow
X2-end outflow
X3-beg outflow
X3-end outflow
uservar 0
output_dir ./ # optional
dbl 1.0 -1 single_file
flt -1.0 -1 single_file
vtk -1.0 -1 single_file # optional
dbl.h5 1.0 2.40h # optional
flt.h5 1.0 -1 # optional
tab -1.0 -1 # optional
ppm -1.0 -1 # optional
png -1.0 -1 # optional
log 1
analysis -1.0 -1 # optional
Output_dir ./ # optional
Checkpoint_interval -1.0 0
Plot_interval 1.0 0
[Parameters]
SCRH 0
32
CHAPTER 4. RUNTIME INITIALIZATION FILE: PLUTO.INI 33
Tag labels on the left side identify appropriate field(s) following on the same line and must not
be changed. Block ordering is irrelevant. Runtime parameters can be accessed anywhere in the code
through the members of the Runtime structure, (see Doc/Doxygen/html/structs 8h.html) using the func-
tion RuntimeGet(), e.g.
cfl = RuntimeGet()->cfl; /* Obtain the cfl number */
char fname[64];
sprintf (fname,"%s/mydata.dat",RuntimeGet()->output_dir); /* Prepend output dir to file name */
The quantities (and related data-types) read from the file are now described.
For each dimension: the first (integer) defines the number of non-overlapping, adjacent one-
dimensional grid patches making up the computational domain (Note: this has nothing to do with
parallel decomposition which is separately carried out by MPI).
If, say, a uniform grid covers the whole physical domain this number should be set to 1. If two consec-
utive adjacent grids are used, then 2 is the correct choice and so on. For each patch, the triplet (double)
(integer) (char) specifies, respectively, the leftmost node coordinate value, number of points and grid
type for that patch; there must be as many triplets (...) as the number of patches. Since patches do
not overlap, the rightmost node value of one grid defines the leftmost node value of the next adjacent
one. The last (double) specify the rightmost node coordinate value of the last segment, which is also
the rightmost node value in that direction. If a dimension is ignored, then 1 grid-point only should be
assigned to that grid.
The global domain therefore extends, in each direction, from the first (double) node coordinate to
the last (double) node coordinate. These values can be accessed from anywhere in the code using
the global variables g domBeg[d] and g domEnd[d], where d=IDIR,JDIR,KDIR is used to select the
direction.
The grid-type (char) entry can take the following values:
• u or uniform: A uniform grid patch is constructed; if xL and xR are the leftmost and rightmost
point of the patch, the grid spacing becomes:
xR − xL
∆x =
N
• s or stretched: a stretched grid is generated. Stretched grids can be used only if at least one
uniform grid is present. The stretching ratio r is computed as follows:
1 − rN xR − xL
∆x r + r2 + · · · + rN = xR − xL
=⇒ r =
1−r ∆x
where ∆x is taken from the closest uniform grid, N is the number of points in the stretched grid
and xL and xR are the leftmost and rightmost points of the patch.
• l±: a logarithmic grid is generated. When l+ is invoked, the mesh size is increasing with the
coordinate:
1 xR + |xL | − xL
∆xi = xi− 12 + |xL | − xL (10∆ξ − 1) , ∆ξ = log
N |xL |
CHAPTER 4. RUNTIME INITIALIZATION FILE: PLUTO.INI 34
Note: The interval should not include the origin when using a logarithmic grid.
In CYLINDRICAL or SPHERICAL coordinates, a radial logarithmic grid has the advantage of pre-
serving the cell aspect ratio at any distance from the origin. In addition, the condition toobtain
approximately squared cells (aspect ratio ≈ 1) is ∆r1 ≈ r1 ∆φ where ∆r1 = rL e∆ξ − 1 is the
radial spacing of the first active computational zone. This condition can be be used to determine
either the number of points in the radial direction or the endpoint:
rR 2 + ∆φ
log = Nr log .
rL 2 − ∆φ
Beware that non-uniform grids may introduce extra dissipation in the algorithm. Changes in the grid
spacing are correctly accounted for when RECONSTRUCTION is set to either LINEAR, PARABOLIC or
WENO3.
Example # 1: A simple uniform grid extending from xL = 0.0 to xR = 10.0 with 128 zones can be
specified using:
X1-grid 1 0.0 128 u 10.0
Example # 2: consider a one-dimensional physical domain extending from 0.0 to 10.0 with a total
of 18 zones, but a finer grid is required for 0 ≤ x ≤ 3. Then one might specify
X1-grid 2 0.0 12 u 3.0 6 s 10.0
which generates a uniform grid with 12 zones for 0 ≤ x ≤ 3, and a stretched grid with 6 zones for
3 ≤ x ≤ 10, see Fig.4.1
When the computational grid is generated, each processor owns a domain portion defined by the
global integer variables IBEG ≤ i ≤ IEND, JBEG ≤ j ≤ JEND and KBEG ≤ k ≤ KEND. Ghost cells are
added outside the local computational domain to complete the stencil at the boundaries, see Fig. 4.2.
The global variables NX1, NX2 and NX3 define the total number of points (boundaries excluded) such
that IEND - IBEG + 1 = NX1, JEND - JBEG + 1 = NX2, KEND - KBEG + 1 = NX3. The total
number of zones (for a given processor, boundaries included) is given by the global variables NX1 TOT,
NX2 TOT and NX3 TOT, see Fig. 4.2.
However, the cell aspect ratio can be different from unity, that is, rectangular cells are allowed. The
grid type u, s or l± is ignored and a uniform grid is always assumed unless the CHOMBO LOGR switch
is enabled to generate a logarithmic radial grid, see Appendix B.3. Cells must not necessarily have the
same physical length in each direction (e.g., squares in 2D, cubes in 3D) and can have an aspect ratio
different from 1. The refinement options are set in the Chombo Refinement section, §4.2.
CHAPTER 4. RUNTIME INITIALIZATION FILE: PLUTO.INI 35
NX1_TOT
IEND,
JEND
NX2_TOT
NX2
IBEG,
JBEG
j
Figure 4.2: Computational grid in 2 dimensions with
i NX1 = NX2 = 4 and 1 ghost zone. Internal zones (solid
boxed) are spanned by IBEG ≤ i ≤ IEND, JBEG ≤ j ≤
NX1
JEND. Dashed boxes represent boundary ghost zones.
• tstop (double)
Integration ends when t = tstop, unless a maximum number of steps (§1.4) is given. tstop has
to be > 0.0.
• first dt (double)
The initial time step. A typical value is 10−6 .
CHAPTER 4. RUNTIME INITIALIZATION FILE: PLUTO.INI 37
Table 4.1: Available Riemann solvers for the different physics module.
– two shock: The Riemann problem is solved exactly or approximately (depending on the
particular solver implemented for a given physics module) at every interface; this is usually
more accurate, but computationally intensive. See [CW84] for the HD module, and [MB05]
for the relativistic hydro equations;
– roe: Linearized Roe Riemann solver based on characteristic decomposition of the Roe matrix,
[Roe81].
– ausm+: Advection Upstream Splitting Method of [Lio96] (only for the HD module);
– hlld: The hlld approximate Riemann solver of [MK05] (for the adiabatic case), [Mig07] (for
the isothermal case) and [MUB09] for the relativistic MHD equations;
– hllc: Harten, Lax, Van Leer approximate Riemann Solver that restores with the middle con-
tact discontinuity;
– hll: Harten, Lax, Van Leer approximate Riemann Solver;
– tvdlf: A simple Lax-Friedrichs scheme is used.
Note that not all solvers are available for a given physics module, see Table 4.1. We warn the
user that, under some circumstances (high Mach number flows, low density plasmas), more dif-
fusive solvers such as HLL or TVDLF turn out to be more robust than accurate solvers. However,
hybrid/adaptive strategies can be turned on when SHOCK FLATTENING is set to MULTID, §2.4.
CHAPTER 4. RUNTIME INITIALIZATION FILE: PLUTO.INI 38
- periodic
Sets periodic boundary conditions on both sides of the computational domain.
- shearingbox
Shearingbox boundary conditions are similar to periodic, except that they are sheared in one di-
rection (only X1-beg and X1-end support this type at this moment). This particular boundary
condition can be used only if the ShearingBox module (described in §10.1) is enabled.
- userdef
User-supplied boundary conditions (it requires coding your own boundary conditions in the func-
tion UserDefBoundary() in init.c, see §5.2).
Like the [Grid] block, you should include the x3 boundaries for 2D runs, even if they will not be consid-
ered.
CHAPTER 4. RUNTIME INITIALIZATION FILE: PLUTO.INI 39
– The first field (double) specifies the time interval (in code units) between consecutive out-
puts.
– The second field can be an integer giving the number of steps between consecutive outputs
or a string giving the wall-clock time between consecutive outputs. A value, for instance,
of 2.40h tells PLUTO to write one .dbl file every two hours and 40 minutes. Negative values
will be ignored for this control parameter.
– The last field (string) can be either single file (one single output file per time step con-
taining all of the variables) or multiple files (different variables are written to different
files).
When asynchronous I/O is enabled (§3.1.1), a third option single file async is permitted
for .flt or .dbl binary files to specify that asynchrounous binary output has to be performed.
Double-precision format files can be used to restart the code using the -restart n command
line argument.
• flt (double) (integer/string) (string) [cgs]
Like dbl, but for single-precision (4 bytes) data files. The last value (cgs) is optional and can be
given to save datafiles directly in cgs physical units rather than in code units.
– The first field (double) can be used to set the time interval (or period) in code units.
– The second field can be either an integer or a string.
An integer value determines the number of steps between consecutive outputs.
Alternatively, a string value can be used to set the wall-clock time between successive out-
puts: a value of 3.55h, for instance, means that a checkpoint file is saved every 3 hours and
55 minutes.
Checkpoints files contain conservative variables.
• Plot interval (double) (integer)
Sets the output frequency for plot (data) files. The meaning of the fields is the same used for
Checkpoint interval except that no wall-clock interval is permitted. Output files are stored
using the HDF5 file format and numbered as data.nnnn.hdf5 where n is a zero-padded, sequentially
increasing integer. Data files contain primitive variables.
Note that a negative number means that checkpoint- or plot-files are never written, 0 means that
checkpoint files are written before the initial timestep and after the final one.
CHAPTER 4. RUNTIME INITIALIZATION FILE: PLUTO.INI 41
User-defined parameter values are read at runtime in this section. The labels on the left identify the
parameter labels (i.e. the corresponding indices of the array g inputParam) while the (double) values
on the right are the actual user-defined parameter values. The number of parameters specified in this
section must exactly match the number and the order given in definitions.h
5. Initial and Boundary Conditions:
init.c
The source file init.c provides a set of functions that are used to define, set and configure your own
specific problem. These include:
• Init(): sets initial conditions as functions of the spatial coordinates x1 , x2 , x3 ;
Syntax:
void Init (double *v, double x1, double x2, double x2)
Arguments:
Note: PLUTO 3 Users: The old array indexing style using DN, VX, VY and VZ, etc... used in previous
versions of the code is no longer supported.
Example #1:
The following code sets a disk with radius 1 centered around the origin in a 2D Cartesian domain.
The flow is stationary and the disk has higher density and pressure (ρ = 10, p = 30) with respect
to the background state (ρ = 1, p = 1):
42
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 43
void Init (double *v, double x1, double x2, double x3)
{
double r;
r = sqrt(x1*x1 + x2*x2);
v[VX1] = v[VX2] = 0.0;
if (r < 1.0){
v[RHO] = 10.0;
v[PRS] = 30.0;
}else{
v[RHO] = 1.0;
v[PRS] = 1.0;
}
}
With a small modification, the same initial condition can be written in a dimension-independent
way (e.g. a line in 1D, a disk in 2D and a sphere in 3D):
void Init (double *v, double x1, double x2, double x3)
{
double r2,r;
if (r < 1.0){
v[RHO] = 10.0;
v[PRS] = 30.0;
}else{
v[RHO] = 1.0;
v[PRS] = 1.0;
}
}
Table 5.1: Array indices used for labeling primitive variables. Staggered components (“s” suffix) are used only for magnetic
fields in the boundary conditions, see §6.2.3.3.
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 44
All other units are derived from a combination of the previous three: time is measured in units of
t0 = L0 /v0 , pressure
√ in units of p0 = ρ0 v02 , while magnetic field (for the MHD module only, see §6.2) in
units of B0 = v0 4πρ0 , i.e.:
ρcgs vcgs pcgs Bcgs
ρ= , v= , p= , B=p . (5.1)
ρ0 v0 ρ0 v02 4πρ0 v02
If not specified, the default values of UNIT DENSITY, UNIT LENGTH, UNIT VELOCITY are, respectively,
ρ0 = 1 mp gr/cm3 , L0 = 1 AU and v0 = 1 Km/s. The values of the three fundamental units can be
changed by redefining them in your definitions.h, e.g.,
/* [Beg] user-defined constants (do not change this line) */
Note that, when the relativistic modules are used, v0 must be the speed of light.
Output files can be directly saved in cgs units using the .flt or .vtk data format, see §4.6.
Example #2:
Consider a flow with typical number densities of the order of n ≈ 10 cm−3 , temperatures T ≈
104 K (corresponding to typical sound speeds of cs0 ≈ 10 Km/s). Suppose, also, that the flow
propagates with uniform speed v ≈ 50 Km/s and the typical scale size of the problem is L ≈
1 pc ≈ 3.1 · 1018 cm. Then one may choose
3
ρ0 = n0 mp ≈ 1.67 · 10−23 gr/cm , v0 = 1 Km/s = 105 cm/s , L0 = 3.1 · 1018 cm
From the python script, this is done by including the following line in definitions.h:
/* [Beg] user-defined constants (do not change this line) */
v[RHO] = 1.0; /* means 1 * [1.67 10ˆ{-23} gr/cmˆ3 or 10/cmˆ3] */
v[VX1] = 50.0; /* means 50 * [1 Km/sec] */
cs = 10.0; /* means 10 * [1 Km/sec] */
where CONST PI (= π) is another pre-defined constant. With this initialization, the sound speed
is exactly cs = 10 Km/s.
p µmu v02 p
T = = Kµ , (5.2)
ρ kB ρ
where kB is the Boltzmann constant, mu is the atomic mass unit, µ is the mean molecular weight while p
and ρ are in “code” (i.e. non-dimensional) units. The conversion factor K depends on UNIT VELOCITY
and it is provided by the macro KELVIN .
Eq. (5.2) can be easily used to determine pressure once the temperature is known, for instance:
v[RHO] = 0.5; /* Density in code units */
T = 1.e3; /* Temperature in KELVIN */
mu = MeanMolecularWeight();
v[PRS] = v[RHO]*T/(KELVIN*mu); /* Obtain pressure in code units */
where µ is the mean molecular weight:
ρ = µntot mu (5.3)
while ntot is the total number density of particle and it depends, in general, on the composition of the
gas. The mean molecular weight may be computed:
• by calling the MeanMolecularWeight() function when the gas composition does not explicitly
depend on temperature and density, e.g.
mu = MeanMolecularWeight(v);
where v is an array of primitive variables of which only ion fractions need to be defined (den-
sity and pressure are ignored). The mean molecular weight is implemented in the source file
mean mol weight.c for a variety of different cooling/reaction network (Ch. 9) and also when no
cooling is used.
For the SNEq cooling module, for instance, the mean molecular weight is computed as
AH + AHe fHe + AZ fZ
µ= (5.4)
2 − fHI + fHe + 2fZ
where each metal contributes for one electron. In the previous equation, AH (CONST AH) and AHe
(CONST He) are the atomic mass numbers of hydrogen and helium whereas fHI , fHe and fZ are
the number fractions of neutral hydrogen helium and metals with respect to hydrogen:
NHI NHe Y AH NZ Z AH
fHI = , fHe = = , fZ = = ,
NH NH AHe X NH AZ X
where X = mu nH AH /ρ, Y = mu nHe AHe /ρ while Z = 1 − X − Y . Notice that while fHe and fZ
are fixed, fHI is a time-dependent quantity that evolves with flow variables.
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 46
Without any cooling / network, the mean molecular weight is computed from the given mass
fractions assuming a fully ionized gas (fHI = 0):
AH + AHe fHe + AZ fZ
µ= ,
2 + fHe + fZ (1 + AZ /2)
where AZ NZ /2 is the number of electrons due to metals.
The value of X and Y can be specified through the user-defined constants H MASS FRAC and
He MASS FRAC which, by default, are set to be equal to solar abundances (X = 0.711, Y = 0.2741,
see also Appendix B.3).
• by calling the GetMu() function when the PVTE LAW equation of state is adopted with equili-
brum ionization, see §7.3. In this case temperature (in Kelvin) and density (in code units) must be
supplied as input arguments:
T = 2.5e3; /* In Kelvin */
rho = 1.0; /* In code units. Means rho*UNIT_DENSITY in cgs units */
GetMu(T, rho, &mu);
Example #3:
Consider a flow with typical number densities of the order of n ≈ 4 × 103 cm−3 , temperature
T = 2.5 × 103 K and Mach number M = v/cs = 15 while the typical length scale is L0 ≈ 10
AU. Suppose also that a magnetic field with strength of 10 µG is also present. Units can be set in
definitions.h:
/* [Beg] user-defined constants (do not change this line) */
v[BX1] = 1.e-5/sqrt(4.0*CONST_PI*UNIT_DENSITY)/UNIT_VELOCITY;
The CompEquil() function is not strictly necessary but it has been introduced to compute ioniza-
tion equilibrium values for a given reference temperature and number density. Its implementation
may differ depending on the cooling module. In alternative, the fraction of neutrals could have
been specified directly, .e.g, v[X HI] = 0.6;.
Finally, we notice that it is customary, sometimes, to assign magnetic field values in terms of the
plasma β = 2p/B 2 . Since β is already a dimensionless parameter, one should not worry about proper
dimensionalization, and the line defining the magnetic field must be replaced by
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 47
beta = 4.0; /* this is my plasma beta = 2p/Bˆ2 */
v[BX1] = sqrt(2.0*v[PRS]/beta); /* in units of v_0\sqrt{4\pi\rho_0} */
where the first argument grid file is a string giving the name of the input grid file while input var
is an array of integers specifying which variables are contained in the input data file. The input grid file
should be written using the same format employed by PLUTO , see §11.1.6.
After initialization, any subsequent call to
InputDataRead (data_file, string);
will read and store into memory the values of the variables contained in the input data file data file.
The second argument specifies the endianity of the input data files, i.e., string="little","big",
" ". An empty string does not change anything. Please note that, unless the input data file is changed,
this function should also be called only once.
The data file should be written using binary format using either single or double precision with
extensions ”.flt” (for the former) or ”.dbl” (for the latter). Variables should be stored sequentially and
their order is specified by the elements of the array input var until the value -1 is encountered. You
may provide only some of the variables used by PLUTO and not necessarily all of them. The number of
elements per variable should exactly match the number of grid points defined by the input grid.
Finally, the function InputDataInterpolate() is used to map the values of the variables con-
tained in the input binary data on the grid employed by PLUTO using bi- or tri-linear interpolation at
the desired coordinate location:
InputDataInterpolate (v, x1, x2, x3);
where v is the same array of primitive variables used in the Init() function and x1,x2,x3 are the
coordinates at which interpolates are required.
In the example below, density and velocity components are assigned from the input binary file tmp/-
data.0010.dbl defined on the computational domain specified in tmp/grid.out:
void Init (double *v, double x1, double x2, double x3)
{
static int first_call = 1;
if (first_call){
int k, input_var[256];
for (k = 0; k < 256; k++) input_var[k] = -1;
input_var[0] = RHO;
input_var[1] = VX1;
input_var[2] = VX2;
input_var[3] = VX3;
input_var[4] = -1;
Beware that interpolation is performed only on the variables specified by the array input var[]. The
remaining variables (if any) must still be set inside Init().
Note: When the input geometry differs from the one used by PLUTO , vector components are not
automatically transformed to the current geometry.
A configuration example may be found in the Test Problems/HD/Blast/ directory, where the initial
condition sets an isothermal blast wave propagating in a non-uniform density medium. The inital den-
sity distribution is created by the separate file Turbulence.c in the same directory and interpolated at
runtime by PLUTO using the method outlined above.
Note: Staggered magnetic fields may not be assigned in this way since the divergence free condi-
tion is not necessarily maintained. Using the vector potential components is more advisable.
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 49
Syntax:
void UserDefBoundary (const Data *d, RBox *box, int side, Grid *grid)
Arguments:
Important: Face-centered (staggered) magnetic fields and cell-centered fluid variables are defined
on different zone stencils, see Figure 5.1. The zone-centering and the corresponding index range
is encoded in the box structure (see below).
All variables must be assigned at a user-defined boundary with the exception of the staggered
component of magnetic field normal to the interface if you are using the Constrained Transport
(CT) method, see §6.2.3.3.
• *box: a pointer to a RBox structure, defining the rectangular portion of the domain over which
ghost zone values should be assigned. Since cell-centered and face-centered data are defined on
different box structures, its usage is maily intended to
– discriminate between cell-centered variables and face-centered variables using the structure
member box->vpos which specifies the location of the variable inside the cell (=CENTER,
X1FACE, X2FACE, X3FACE);
– provide an efficient way of looping through the ghost boundary zones using the macro
BOX LOOP(box,k,j,i) which automatically takes care of the index range of definition.
Note: Using the box structure is not strictly mandatory and the usual macros X1 BEG LOOP()
, ..., X3 END LOOP() may still be employed without any modifications. However, these macros
perform loops over cell-centered data stencils and staggered field are not completely defined since
the loops do not include one row of zones at the furthest left edges of the boundary zones. On the
contrary, the BOX LOOP() macro takes into account the full range of definition of the variable and
should be used whenever possible.
• side: an input integer label specifying on which side of the physical domain user-defined values
should be prescribed. It can take on the following values:
– X1 BEG, X1 END: boundary conditions can be assigned in the ghost zones at the beginning
and end of the physical domain in the x1 direction
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 50
Figure 5.1: Schematic representation of cell-centered (left panel) and face-centered (right panel) collocation of physical variables
on a 2D grid. X and Y-face centered staggered quantities are shown by squares and triangles, respectively. Filled symbols (circles,
boxes and triangles) are considered interior values part of the solution, whereas boundary values are identified by empty symbols
and must be prescribed by the user if the boundary is userdef.
– X2 BEG, X2 END: boundary conditions can be assigned in the ghost zones at the beginning
and end of the physical domain in the x2 direction
– X3 BEG, X3 END boundary conditions can be assigned in the ghost zones at the beginning
and end of the physical domain in the x3 direction
– 0 (zero): change/control the solution inside the computational domain. This feature can be
used only if the macro INTERNAL BOUNDARY has been enabled in your definitions.h, see §5.2.1.
If, say, X1-beg has been tagged userdef inside your pluto.ini, the user has to specify the boundary
values at the beginning of the x1 direction when side==X1 BEG.
• *grid: a pointer to an array of Grid structures containing all the relevant grid information. In
this case, grid[IDIR] is the structure relevant to the x1 direction, grid[JDIR] to the x2 direction
and grid[KDIR] pertains to the x3 direction. See the code documentation for more details on the
members of the Grid structure.
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 51
Example #1:
As a first example we show how to prescribe a fixed inflow boundary condition for a jet model. The
computational domain is a 2D box in cylindrical geometry, so that x1 ≡ R, x2 ≡ z. A constant inflow is
prescribed a the jet nozzle located at the z = 0 boundary for R ≤ 1 while reflective boundary conditions
are assigned for R > 1. The inflow values are specified as
ρ 1 ρ(R, −z) ρ(R, z)
vR 0 vR (R, −z) vR (R, z)
= for R ≤ 1 , = for R > 1
vz M vz (R, −z) −vz (R, z)
p 1/Γ p(R, −z) p(R, z)
The previous piece of code is executed only if you have selected userdef at the X2-beg boundary
inside your pluto.ini.
The macro BOX LOOP(box,k,j,i) performs a loop over the bottom boundary zones and, for cell-
centered data, it is equivalent to the macro X2 BEG LOOP(k,j,i) . Similar macros may be used at any
of the other boundaries (X1 BEG, X1 END, X2 END, X3 BEG, X3 END), although the BOX LOOP()
macro has the advantage of being more general since it automatically embeds the stencil index range
for the corresponding variable position (i.e. centered or staggered).
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 52
Example #2:
As a second example, we discuss the user-defined boundary condition employed in the shock-cloud
problem (Test Problems/MHD/Shock Cloud/). Here we want to prescribe, at the X1-end boundary, con-
stant pre-shock values on both cell-centered quantities and staggered magnetic fields. The variable
box->vpos is used to select the desired data set.
void UserDefBoundary (const Data *d, RBox *box, int side, Grid *grid)
{
int i, j, k;
As in the previous example, the macro BOX LOOP() is interchangable, for cell-centered data (box->vpos
== CENTER), with the macro X1 END LOOP(k,j,i) but not rigorously for staggered magnetic fields
which are defined on a larger stencil.
Function-like macros are described in the code documentation: ./Doc/Doxygen/html/macros 8h.html
if (side == 0){
TOT_LOOP(k,j,i){
if (d->Vc[RHO][k][j][i] < 1.e-3) {
d->Vc[RHO][k][j][i] = 1.e-3;
}
}
}
...
A more complex example consists of a time-independent region of space where variables are fixed
in time and should not be evolved by the algorithm. If this is the case, you may additionally tell PLUTO
not to update the solution in the specified computational zones during the current time step by enabling
the FLAG INTERNAL BOUNDARY flag.
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 53
Example:
The following example (taken from Test Problems/HD/Stellar Wind ) shows how to set up a radially sym-
metric spherical wind in cylindrical coordinates inside a small spherical region of radius 1 centered
around the origin. This is achieved by prescribing fixed inflow values for density, pressure and velocity:
void UserDefBoundary (const Data *d, RBox *box, int side, Grid *grid)
{
int i, j, k, nv;
double *x1, *x2, *x3;
double r, r0, cs;
double Vwind = 1.0, rho, vr;
x1 = grid[IDIR].xgc;
x2 = grid[JDIR].xgc;
x3 = grid[KDIR].xgc;
if (side == 0){
r0 = 1.0;
cs = g_inputParam[CS_WIND];
TOT_LOOP(k,j,i){
r = sqrt(x1[i]*x1[i] + x2[j]*x2[j]);
if (r <= r0){
vr = tanh(r/r0/0.1)*Vwind;
rho = Vwind*r0*r0/(vr*r*r);
d->Vc[RHO][k][j][i] = rho;
d->Vc[VX1][k][j][i] = Vwind*x1[i]/r;
d->Vc[VX2][k][j][i] = Vwind*x2[j]/r;
d->Vc[PRS][k][j][i] = cs*cs/g_gamma*pow(rho,g_gamma);
d->flag[k][j][i] |= FLAG_INTERNAL_BOUNDARY;
}
}
}
...
The symbol |= (a combination of the bitwise OR operator | followed by the equal sign) turns the
FLAG INTERNAL BOUNDARY bit on in the 3D array d->flag[][][]. This is used by the code to reset
the right hand side of the conservative equations in the selected zones to zero. These computational
cells are thus not evolved in time by PLUTO .
Note: The *box structure should not be used here and staggered magnetic field variables should
not be altered.
• The scalar potential can be employed when the BODY FORCE flag is set to POTENTIAL in your
definitions.h. In this case, g = 0 and the function BodyForcePotential() should be used to
prescribe the analytical form of Φ ≡ Φ(x1 , x2 , x3 ):
where x1,x2,x3 are the local zone coordinates and the return value of the function gives the
potential. In this way, PLUTO employs a conservative discretization that conserves total en-
ergy+gravitational energy, see Eq. (6.1) and Eq. (6.4). The gravitational potential, however, must
not change in time.
As an example, a spherically symmetric point-mass potential Φ = −1/r can be defined using
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 54
double BodyForcePotential(double x1, double x2, double x3)
{
#if GEOMETRY == CARTESIAN
return -1.0/sqrt(x1*x1 + x2*x2 + x3*x3);
#elif GEOMETRY == CYLINDRICAL
return -1.0/sqrt(x1*x1 + x2*x2);
#elif GEOMETRY == SPHERICAL
return -1.0/x1;
#endif
}
where
– *v: a pointer to a vector of primitive quantities (e.g., v[RHO], v[VX1], etc...);
– *g: a three-component array (g[IDIR], g[JDIR], g[KDIR]) specifying the gravity vector g
components along the coordinate directions;
– x1,x2,x3: local zone coordinates.
As an example, let’s consider again a point-mass source located at the origin of coordinates. Then
one needs to define, depending on the geometry (= CARTESIAN , CYLINDRICAL or SPHERICAL),
void BodyForceVector(double *v, double *g, double x1, double x2, double x3)
{
double gs, rs;
It is also possible to prescribe the body force in terms of a vector and a potential by setting, in your
definitions.h, BODY FORCE to (VECTOR+POTENTIAL).
Beware that non-intertial effects due to a rotating frame of reference (such as Coriolis and centrifugal
forces) should not be specified here since they are automatically handled by PLUTO by enabling the
ROTATING FRAME flag in the HD and MHD module, see §2.2.6.
A word of caution about using reflective, equatorial symmetric (or similar) boundary conditions:
strictly speaking, gravity should be defined consistently with the antisymmmetric behavior of the veloc-
ity component normal to the given boundary plane. More precisely, the normal component of g should
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 55
be antisymmetric while the potential should be an even function about the boundary plane. Consider,
for instance, a reflective (or equatorial symmetric) conditions at the lower and upper boundaries zb and
ze in the z direction. Then one should have:
( (
gz (x, y, zb − z) = −gz (x, y, zb + z) gz (x, y, ze + z) = −gz (x, y, ze − z)
,
Φ(z, y, zb − z) = Φ(x, y, zb + z) Φ(z, y, ze + z) = Φ(x, y, ze − z)
If gravity does not satisfy this property then it must be imposed manually. As an example you can look at
the Test Problems/MHD/Rayleigh Taylor or Test Problems/MHD/Shearing Box setups where reflective and
equatorial symmetric boundaries are used in the y- and z- directions.
Note: Relativistic flows: Body forces are marginally compatible with the relativistic modules.
Only VECTOR may be used.
Arguments:
Example:
In the next example we show how to compute, at run-time, the total integrated kinetic energy and the
maximum internal energy:
Z
1 1 2 1 X1 p
hEkin i ≡ ρv dx dy dz = ρi,j,k v 2i,j,k ∆Vi,j,k (ρe)max = max
∆V 2 ∆V 2 i,j,k Γ−1
i,j,k
where ∆V is the total volume of the computational domain, ∆Vi,j,k = ∆xi ∆yj ∆zk is the volume of
a single cell, (i, j, k) extend over the entire computational domain (a Cartesian 3D domain is used for
simplicity). The output file name is averages.dat and it is written as a 4-column tabulated ascii file con-
taining the current integration time, the time step, the volume-integrated kinetic energy and maximum
internal energy for the required time level. The example works also for parallel computations and can
be safely used at restart since the last position of the file is automatically searched for and subsequent
writing is appended starting from the correct row.
CHAPTER 5. INITIAL AND BOUNDARY CONDITIONS: INIT.C 56
void Analysis (const Data *d, Grid *grid)
{
int i, j, k;
double dV, vol, scrh;
double Ekin, Eth_max, vx2, vy2, vz2;
double *dx, *dy, *dz;
dx = grid[IDIR].dx;
dy = grid[JDIR].dx;
dz = grid[KDIR].dx;
#ifdef PARALLEL
MPI_Allreduce (&Ekin, &scrh, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
Ekin = scrh;
MPI_Barrier (MPI_COMM_WORLD);
#endif
if (prank == 0){
char fname[512];
static double tpos = -1.0;
FILE *fp;
6. Basic Physics Modules
In this chapter we describe the basic equation modules available in the PLUTO code for the solution of
the fluid equations under different regimes: HydroDynamics (HD), MagnetoHydroDynamics (MHD)
and their relativistic extensions (RHD and RMHD).
We remind that only first-order spatial derivatives accounting for the hyperbolic part of the equations
are described in this chapter whereas the reader is referred to Chap. 8 for a comprehensive description
of the diffusion terms (thermal conduction, viscosity and magnetic resistivity) and cooling.
6.1.1 Equations
With the HD module, PLUTO evolves in time following system of conservation laws:
T
ρ ρv 0
∂
+∇·
= −ρ∇Φ + ρg
m mv + pI (6.1)
∂t
E + ρΦ (E + p + ρΦ)v m·g
where ρ is the mass density, m = ρv is the momentum density, v is the velocity, p is the thermal pressure
and E is the total energy density:
m2
E = ρe + . (6.2)
2ρ
An equation of state provides the closure ρe = ρe(p, ρ).
The source term on the right includes contributions from body forces and is written in terms of the
(time-independent) gravitational potential Φ and and the acceleration vector g (§5.3).
The right hand side of the system of Eqns (6.1) is implemented in the RightHandSide() function
inside Src/MHD/rhs.c employing a conservative discretization that closely follows the expression given
in §A.1.1, §A.1.2 and §A.1.3 for Cartesian, polar and spherical geometries (without magnetic fields).
Primitive variables are defined by V = (ρ, v, p)T , where v = m/ρ while p = p(ρ, ρe) depends on
the equation of state, see Chapter 7. The maps U (V ) and its inverse are provided by the functions
PrimToCons() and ConsToPrim().
Primitive variables are generally more convenient and preferred when assigning initial/boundary
conditions and in the interpolation algorithms. The vector of primitive quantities V obeys the quasi-
linear form of the equations:
∂ρ
+ v · ∇ρ + ρ∇ · v = 0
∂t
∂v ∇p
+ v · ∇v + = −∇Φ + g (6.3)
∂t ρ
∂p
+ v · ∇p + ρc2s ∇ · v = 0,
∂t
p
where cs = Γp/ρ is the adiabatic speed of sound for an ideal EOS. The quasi-linear form (6.3) is
implemented in the Src/HD/prim eqn.c source file and it is required during the predictor stages of the
HANCOCK or CHARACTERISTIC TRACING time-stepping schemes.
57
CHAPTER 6. BASIC PHYSICS MODULES 58
6.2.1 Equations
With the MHD module, PLUTO solves the following system of conservation laws:
T
ρ ρv 0
∂ m mv − BB + Ipt −ρ∇Φ + ρg
+∇· = (6.4)
∂t E + ρΦ
(E + pt + ρΦ)v − B (v · B) m·g
B vB − Bv 0
where ρ is the mass density, m = ρv is the momentum density, v is the velocity, pt = p + B 2 /2 is the
total pressure (thermal + magnetic), B is the magnetic field1 and E is the total energy density:
m2 B2
E = ρe + + . (6.5)
2ρ 2
where an additional equation of state provides the closure ρe = ρe(p, ρ) (see Chapter 7). The source term
on the right includes contributions from body forces and is written in terms of the (time-independent)
gravitational potential Φ and and the acceleration vector g (§5.3).
Note that the induction equation may equivalently be written as
∂B
+ ∇ × E = 0, (6.6)
∂t
where E = −v × B + η · J is the electric field and η is the resistivity tensor, §8.2.
The right hand side of the system of Eqns (6.4) is implemented in the RightHandSide() function
inside Src/MHD/rhs.c employing a conservative discretization that closely follows the expression given
in §A.1.1, §A.1.2 and §A.1.3 for Cartesian, polar and spherical geometries.
The sets of conservative and primitive variables U and V are given by:
T T
U = ρ, m, E, B , V = ρ, v, p, B .
The maps U (V ) and its inverse are provided by the functions PrimToCons() and ConsToPrim().
The primitive form of the equations is
∂ρ
+ v · ∇ρ + ρ∇ · v = 0
∂t
∂v 1 1
+ v · ∇v + B × (∇ × B) + ∇p = −∇Φ + g
∂t ρ ρ
(6.7)
∂B
+ B(∇ · v) − (B · ∇)v + (v · ∇)B = v (∇ · B)
∂t
∂p
+ v · ∇p + ρc2s ∇ · v = 0,
∂t
where the (∇·B) on the right hand side of the third equation is kept for reasons of convenience, although
zero at the continuous level.
1A
√
factor of 1/ 4π has been absorbed in the definition of magnetic field.
CHAPTER 6. BASIC PHYSICS MODULES 59
Note: In 2D, only the third component of A (that is us[AX3]) should be used. Likewise, the third
component of the magnetic field (Bz ) cannot be assigned through the vector potential and must be
prescribed in the standard way, see the third example in Table 6.1.
Table 6.1 shows some examples of magnetic field initializations with and without using the vector
potential.
Table 6.1: Examples of how the magnetic field may be initialized. Direct initialization (standard) is possible when
ASSIGN VECTOR POTENTIAL is set to NO. Otherwise, the components of the vector potential are used (third column).
CHAPTER 6. BASIC PHYSICS MODULES 60
Contributions to ∇ · B are taken direction by direction. Note that the 8-wave method keeps ∇ · B = 0
only at the truncation level and NOT to machine accuracy. More accurate treatments of the solenoidal
condition can be achieved using the other two formulations. The 8-wave algorithm should be used in
conjunction any Riemann solver with the exception of hlld.
∂B ∂ψ c2
+ ∇ · (vB − Bv) + ∇ψ = 0 , + c2h ∇ · B = − h2 ψ , (6.8)
∂t ∂t cp
p
where ch = CFL × ∆lmin /∆tn is maximum speed compatible with the step size, cp = ∆lmin ch /α and
∆lmin is the minimum cell length. The free parameter α controls the rate at which monopole are damped
[MT10] and its value is set by the user-defined constant GLM ALPHA (default value 0.1). A number of
tests suggests that the optimal range can be found for 0.05 . α . 0.3. In the mixed formulation,
divergence errors are transported to the domain boundaries with the maximal admissible speed and are
damped at the same time. By default, ψ is set to zero in the initial and boundary conditions but the
user is free to change it at a user-defined boundary by prescribing d→Vc[PSI GLM][k][j][i] (inside
UserDefBoundary()) which has the usual cell-centered representation. The scalar multiplier is not
written to disk except for the double format, §11, needed for restart.
The advantage of this formulation (GLM-MHD) is that the equations retain a conservative form (no
source terms are introduced), all variables (including magnetic fields) retain a cell-centered representa-
tion and standard 7-wave Riemann solvers (with a single value of the normal component of magnetic
field) may be used.
A slightly different version, called the extended GLM formulation, that breaks momentum and en-
ergy conservation, has been found to be more robust in problems involving strongly magnetized media
(see, for example, configuration # 11 in Test Problems/MHD/Blast). The extended form of the equations
[DKK+ 02, MT10] can be enabled by adding the user-defined constant GLM EXTENDED to definitions.h and
setting its value to YES from the Python script. For a complete description of the GLM- and Extended
GLM-MHD formulation and its implementation in PLUTO refer to [MT10, MTB10].
CHAPTER 6. BASIC PHYSICS MODULES 61
see Fig. 6.1. In Cartesian coordinates, for instance, bx is located at X-faces whereas by lives at Y-faces, etc.,
see the boxes and triangles in Fig. 5.1. This feature must be used only in conjunction with an unsplit integrator.
With CT, the solenoidal condition is maintained at machine accuracy as long as field initialization is done
using the vector potential, §6.2.2.
The staggered magnetic field is treated as an area-weighted average on the zone face and Stoke’s
theorem is used to update it:
Z I
∂b dbxd 1
+ ∇ × E · dS d = 0 =⇒ + E · dl = 0 (6.9)
∂t dt Sd
Please note that the staggered components are initialized and integrated also on the boundary interfaces
in the corresponding staggered direction. In other words, the interior values are
IBEG − 1 ≤ i ≤ IEND
bx1 ,i+ 12 ,j,k : JBEG ≤ j ≤ JEND
KBEG ≤ k ≤ KEND
IBEG ≤ i ≤ IEND
bx2 ,i,j+ 21 ,k : JBEG − 1 ≤ j ≤ JEND
KBEG ≤ k ≤ KEND
IBEG ≤ i ≤ IEND
bx3 ,i,j,k+ 21 : JBEG ≤ j ≤ JEND
KBEG − 1 ≤ k ≤ KEND
Thus bx1 ,i+ 21 ,j,k is NOT a boundary value for i = IBEG − 1, JBEG ≤ j ≤ JEND, KBEG ≤ k ≤ KEND but
it is considered part of the solution !! Similar considerations hold for bx2 and bx3 components at the x2
and x3 boundaries, respectively.
The electromotive force (EMF) E is computed at zone edges, see Fig. 6.1 by a proper averaging/re-
construction scheme (set by CT EMF AVERAGE inside your definitions.h). Options are:
• CT EMF AVERAGE = ARITHMETIC yields a simple arithmetic averaging [BS99] of the fluxes com-
puted during the upwind steps. In this case, one has available
0 Ex3 −Ex2
−Ex3 , 0 , Ex1
Ex2 i+ 1 ,j,k
−Ex1 i,j+ 1 ,k 0 i,j,k+ 1
2 2 2
1
Ex1 ,i,j+ 21 ,k+ 12 = Ex1 ,j,k+ 12 + Ex1 ,i,j+1,k+ 12 + Ex1 ,i,j+ 12 ,k + Ex1 ,i,j+ 12 ,k+1
4
CHAPTER 6. BASIC PHYSICS MODULES 62
y
Ω11
−0+
00
11
00
00
11
00
11
x z
11
00
Ω0−+ 00
11
00
11 b0
1
00+ 11
00
00 x
11
00
11 1
0 00
11
00
11 00
11
z z Ω
0++
Ω 00
11
−+
00
11 1
0
0
1
Ω ++
000
111 000
111
00
11
00
11 0
1 000
111 111
000
000
111
00
11 000
111
000
111 000
111
y y
000
111
b 0+ Ω+0+ 00 z
11
11
00
Ω
00
11
00 −+0
11
y
p11
000
00
b 0+0
00
11 00
11
00
11
00
11
z x
p00 , B00 x z 00
11 b +00 11
00 z
00
11 00
11 1
0 00
11
11
00
00
11 b 00
11 Ω 00
11
+−011
00 0
1 00
11Ω
00 ++0
11
00
11 +0
00
11 z
11
00
00 x
11
y 00
11
00
11
Ω 0+−
y
z 11
00
00
11
x 00
11 x
111
000Ω
000 +−
111
00
11
y11
00
000
111
000
111 Ω+0−
Figure 6.1: Collocation points in 2.x D (left) and in 3D (right). Cell-centered quantities are given as green circles, face-centered
as red squares and edge-centered as blue diamonds.
1
Ex2 ,i+ 21 ,j,k+ 21 = Ex2 ,i+ 12 ,j,k + Ex2 ,i+ 12 ,j,k+1 + Ex2 ,i,j,k+ 12 + Ex2 ,i+1,j,k+ 12
4
1
Ex3 ,i+ 12 ,j+ 21 ,k = Ex3 ,i+ 12 ,j,k + Ex3 ,i+ 12 ,j+1,k + Ex3 ,i,j+ 12 ,k + Ex3 ,i+1,j+ 12 ,k
4
Although being the simplest one, this average procedure may suffer from insufficient dissipation
in some circumstances ([GS05, Ld04]) and does not reduce to its one dimensional equivalent algo-
rithm for plane parallel grid aligned flows.
• CT EMF AVERAGE = UCT HLL uses a two dimensional Riemann solver based on a four-state HLL
flux function, see [DBL03, Ld04]. If the fully unsplit HANCOCK or CHARACTRISTIC TRACING
scheme is used, the Courant number must be CF L . 0.7 (in 2D) and CF L . 0.35 (in 3D).
• CT EMF AVERAGE = UCT0 or CT EMF AVERAGE = UCT CONTACT employs the face-to-edge inte-
gration procedures proposed by [GS05], where electromotive force derivatives are averaged from
neighbor zones (UCT0) or selected according to the sign of the contact mode (UCT CONTACT). The
former has reduced dissipation and is preferably used with linear interpolants and RK integrators,
while the latter shows better dissipation properties.
All algorithms, with the exception of the arithmetic averaging, reduce to the corresponding one dimen-
sional scheme for grid aligned flows. However, in our experience, UCT HLL and UCT CONTACT show the
best dissipation and stability properties. The CT formulation works with any of the Riemann solvers.
Assigning Boundary Conditions. Within the CT framework, user-defined boundary conditions (b.c.)
must be assigned on the staggered components as well. This is done in your UserDefBoundary()
function using the d→Vs[nv][k][j][i] array, where nv gives the staggered component: BX1s, BX2s
or BX3s.
Note: In PLUTO we follow the convention that the cell “center” owns its right interface, e.g., ‘i’
means i + 12 . Thus:
Beware that the three staggered components have different spatial locations and the BOX LOOP()
macro introduced in §5.2 automatically implements the correct loop over the boundary ghost zones.
Thus, at the x1 boundary, for instance, one needs to assign
at
)
bx2 ,i,j+ 12 ,k x1,i , x2,j+ 12 , x3,k
for i = 0, · · · , IBEG-1
bx3 ,i,j,k+ 21 at x1,i , x2,j , x3,k+ 12
The component normal to the interface (bx1 in this case) should NOT be assigned since it is automatically
computed by PLUTO from the ∇ · B = 0 condition after the tangential components have been set.
Example:
The following example prescribes user-defined boundary conditions at the lower x2 boundary for a
MHD jet problem in cylindrical coordinates (x1 ≡ R, x2 ≡ z). Inflow conditions are given as (ρ, vR , vz , p, Br , Bz ) =
(1, 0, 10, 1/Γ, 0, 3) for R ≤ 1 while a symmetric counter-jet is assumed for R > 1:
if (side == X2_BEG){
Here STAGGERED MHD is defined only in the MHD constrained transport and the boundary conditions
are assigned on bx1 ≡ bR only (i.e. the orthogonal component).
∂B 0
= 0, ∇ · B0 = 0 , ∇ × B0 = 0 .
∂t
In this case one can show [Pow94] that the MHD equations reduce to:
∂ρ
+ ∇ · (ρv) = 0
∂t
∂m
+ ∇ · mv − B 1 B − B 0 B 1 + ∇pt = ρ(−∇Φ + g)
∂t
∂(E1 + ρΦ) h i
+ ∇ · (E1 + pt + ρΦ)v − (v · B 1 )B = m·g
∂t
∂B 1
− ∇ × (v × B) = 0
∂t
CHAPTER 6. BASIC PHYSICS MODULES 64
where
B 21 p 1
ρv 2 + B 21
pt = p + + B1 · B0 , E1 = +
2 Γ−1 2
Thus the energy depends only on B 1 , a feature that turns out to be useful when dealing with low-beta
plasma. The sets of conservative and primitive variables are the same as the original ones, with B → B 1 ,
E → E1 .
In order to enable this feature, the macro BACKGROUND FIELD must be turned to YES in your
definitions.h. The initial and boundary conditions must be imposed on B 1 alone while the function
BackgroundField() can be added to your init.c to assign B 0 :
void BackgroundField (double x1, double x2, double x3, double *B0)
Note that when writing output datafiles to disk, only the deviation B 1 is written.
Examples can be found in the 4th configuration of Test Problems/MHD/Rotor/ and in the 4th or 5th
configurations of Test Problems/MHD/Blast/.
Note: Background field splitting works, at present, with the CT and GLM divergence cleaning
techniques, with most Riemann solvers but only with RK-type integrators.
CHAPTER 6. BASIC PHYSICS MODULES 65
6.3.1 Equations
The special relativistic module evolves the conservative set U of state variables
T
U = D, m1 , m2 , m3 , E
where D is the laboratory density, mx1,x2,x3 are the momentum components, E is the total energy (in-
cluding contribution from the rest mass). The evolutionary conservative equations are
T
D Dv
∂
m + ∇ · mv + pI = 0
∂t
E m
where v is the velocity, p is the thermal pressure. Primitive variables V always include the rest-mass
density ρ, three-velocity v = (vx1 , vx2 , vx3 ) and pressure p. The relation between U and V is more
complicated and is expressed by
where h is the specific enthalpy (see Chapter 7 for available equation of states).
In order to express the equations in primitive (quasi-linear) form, one assumes δp = c2s δe, where cs
is the adiabatic speed of sound:
∂ρ 1 1 ∂p
+ v · ∇ρ − 2 v · ∇p =
∂t cs h c2s h ∂t
∂v 1 v ∂p
+ v · ∇v + ∇p = − +a (6.10)
∂t ρhγ 2 ρhγ 2 ∂t
∂p 1 h
2 2
i
+ cs ρh∇ · v + (1 − cs )v · ∇p = 0.
∂t 1 − v 2 c2s
For more detailed expressions and the characteristic decomposition, see [MPB05].
Spatial reconstruction may be performed on the four-velocity rather than on the three-velocity by
enabling the macro RECONSTRUCT 4VEL to YES manually in your definitions.h (see also Appendix B.3).
Using the four-velocity in place
√ of the three-velocity offers (in some circumstances) the advantage that
the total velocity |v| = |u|/ 1 + u2 is always less than 1 by construction, for any 0 ≤ |u| < ∞. This is
not always the case when the three-velocity is used and precautionary measures are used to ensure that
|v| < 1.
CHAPTER 6. BASIC PHYSICS MODULES 66
6.4.1 Equations
The RMHD module solves the following system of conservation laws:
T
D Dv
wt γ 2 vv − bb + Ipt
∂ m
+∇· =0 (6.11)
∂t E
m
B vB − Bv
where D is the laboratory density, m is the momentum density, E is the total energy (including contri-
bution from the rest mass):
b0 = γv · B
D= γρ
b = B/γ + γ(v · B)v
2 0
m = wt γ v − b b , wt = ρh + B 2 /γ 2 + (v · B)2
2 0 0
E = wt γ − b b − pt
B 2 /γ 2 + (v · B)2
pt = p +
2
Notice that the components of the momentum tensor may also be written as:
bi B j
i
ij i j i j i j i j B
M = wt u u − b b = m v − =mv − + v v · B Bj
i
γ γ2
Primitive variables are similar to the RHD module but they also contain the magnetic field, V =
(ρ, v, p, B). The quasi-linear form of the RMHD is not available yet and algorithms using the char-
acteristic decomposition of the equations or the quasi-linear form are not available. Therefore, the
CHARACTERISTIC TRACING step cannot be used and the HANCOCK scheme works by default using
the conservative predictor step rather than the primitive one. On the other hand, Runge-Kutta type
integrators works well for the RMHD module.
The available equations of state are IDEAL and TAUB already introduced for the RHD module (see
[MM07] for the extension of this EOS to the RMHD equations).
The RMHD sub-menu offers some of the switches already discussed in the MHD module (§6.2) or in
the RHD (§6.3) module. Divergence control is achieved using the same algorithms introduced for MHD,
namely: 8-wave (§6.2.3.1), divergence cleaning (§6.2.3.2) and the constrained transport (§6.2.3.3).
Computation of the fast characteristic speeds can be perfomed by replacing the numerical solution
of a quartic equation (see [MM07]) with the analytical solution of an approximate quadratic equtions
thus making computation faster. This is achieved by setting RMHD FAST EIGENVALUES to YES (as in
[DZBL07]), see the Appendix B.3.
7. Equation of State
In the current implementation, PLUTO describes a thermally ideal gas obeying the thermal Equation of
State (EOS)
ρ
p = nkB T = kB T (7.1)
mu µ
where p is the pressure, n is the total particle number density, kB is the Boltzmann constant, T is the tem-
perature, ρ is the density, mu is the atomic mass unit and µ is the mean molecular weight. The thermal
EOS describes the thermodynamic state of a plasma in terms of its pressure p, density ρ, temperature
T and chemical composition µ. Eq. (7.1) is written in CGS physical units. Using code units for p and ρ
while leaving temperature in Kelvin, the thermal EOS is conveniently re-expressed as
ρT p
p= ⇐⇒ T = Kµ (7.2)
Kµ ρ
where K is the KELVIN macro which depends explictly on the value of UNIT VELOCITY.
Another fundamental quantity is the (specific) internal energy e whose rate of change under a phys-
ical process is regulated by the first law of thermodynamics:
1
de = dQ − pd . (7.3)
ρ
where Q represents the heat absorbed or released. The internal energy is a state function of the system
and can also be related to temperature and density via the caloric equation of state [Tor97]
e = e(T, ρ) . (7.4)
The thermal and caloric equations of state given by Eq. (7.2) and (7.4) constitutes the basis for the
consideration discussed in the next sections.
p = ρc2iso (7.5)
where ciso (the isothermal sound speed) can be either a constant value or a spatially-varying quantity.
This EOS is available only in the HD and MHD modules. No energy equation is present and the labels
ENG and PRS are undefined.
The value of ciso can be set using the global variable g isoSoundSpeed in your init.c, e.g.
g_isoSoundSpeed = 2.0; /* sets the sound speed to be 2 */
If not set, the default value is ciso = 1.
In order to have a space-dependent isothermal speed of sound, one has to copy the source file Sr-
c/HD/eos.c to your local working directory and make the appropriate modification.
67
CHAPTER 7. EQUATION OF STATE 68
The value of Γ is stored in the global variable g gamma and can be modified in your Init() function
(default value 5/3).
For a relativistic flow, the constant-Γ EOS is more conveniently expressed through the specific en-
thalpy:
Γ
ρh = ρ + p. (7.7)
Γ−1
The ideal EOS is compatible with all physics modules, algorithms and Riemann solvers in the code.
p
needed to evaluate the sound speed, cs = Γ1 p/ρ. Note that Γ1 has the upper bound of 5/3 and
may not be straightforward to compute. Fortunately, its value is only needed to estimate the wave
propagation speed during the Riemann solver and an approximate value should suffice.
Two different implementations are provided with the current distribution: pvte law H+.c is suitable
for a partially hydrogen gas in LTE (described in the next section) while pvte law dAngelo.c can be used
for molecular and atomic hydrogen cooling as in D’Angelo, G. et al ApJ (2013) 778. More technical
details can be found under the Src/EOS/PVTE folder in the API reference guide or following this link.
Note: The PVTE LAW EOS is not compatible with algorithms requiring characteristic decomposi-
tion and cannot be used with the ENTROPY SWITCH. We suggest to use RK time-stepping and the
tvdlf, hll or hllc Riemann solvers. This EOS is, at present, available for the HD and MHD
modules only.
where µ = 1/(1+x) is the mean molecular weight, x = np /(np +n0 ) is the degree of ionization computed
from Saha equation:
x2 (2πme kB T )3/2 −χ/(kB T )
= e , (7.10)
1−x h3 (np + n0 )
where χ = 13.6 eV and np + n0 = ρ/mp .
The (specific) internal energy includes two contributions:
3 kB T χ 3p χ
e= + x= + x (7.11)
2 µmp mp 2 ρ mp
where the first one represents the standard kinetic energy while the second one corresponds to the
ionization energy (neutral atoms have a potential energy that is lower than that of ions). Note that the
latter introduces a temperature, or equivalently, a velocity scale in the problem so that computations are
no longer scale-invariant but depend on the value of UNIT VELOCITY (used to obtain the temperature
in Kelvin) and UNIT DENSITY (used in Saha equation) that must be defined in your Init() function,
see §5.1.1. Fig. 7.1 shows the classical Sod shock tube solution at t = 0.2 obtained with the IDEAL
equation of state and the PVTE LAW with UNIT DENSITY= 105 mp and UNIT VELOCITY= 10 Km/s.
The equivalent Γ, defined as
p
Γeq = + 1, (7.12)
ρe
is no longer a constant but a function of the temperature, see Fig. 7.2.
The implementation of this particular EOS can be found in Src/EOS/PVTE/pvte law H+.c (simply copy
it to your working directory as pvte law.c). Eq. (7.11) is implemented by the InternalEnergyFunc()
function while the mean molecular weights µ is defined by the GetMu() function.
CHAPTER 7. EQUATION OF STATE 70
tell PLUTO to replace the thermal EOS with a temperature table T = T (pi , ρj ) while still using the
CHAPTER 7. EQUATION OF STATE 71
analytical approach (i.e. direct function evaluation or root finder) for the caloric EOS.
The tables T (pi , ρj ) and ρe(Ti , ρj ) are initialized at runtime and used throughout the integration. The
number of points needed to construct such tables is fixed by the constants {PV TEMPERATURE TABLE NX,
PV TEMPERATURE TABLE NY} for the first table and {TV ENERGY TABLE NX, TV ENERGY TABLE NY}
for the second one. To avoid the occurrence of spurious waves in the solution of the Riemann problem,
a monotone cubic spline is always used in the temperature grid, see Appendix C of [VMBM15].
In this chapter we give an overview of the code capabilities for treating dissipative (or diffusion) terms
which, at present, include
• Viscosity (HD, MHD), described in §8.1;
8.1 Viscosity
The viscous stresses enter the HD and MHD equations with two parabolic diffusion terms in the mo-
mentum and the energy conservation. Adding the viscous stress tensor to the original conservation law,
Eq. (1.1), we obtain a mixed hyperbolic/parabolic system which, in compact form, may be expressed by
the following:
∂U
+∇·T=∇·Π+S (8.1)
∂t
where Π represents the viscous stress tensor, whose components are given by
ν1 vi;j + vj;j 2
(Π)ij = 2 + ν2 − ν1 ∇ · vδij . (8.2)
hi hj 2 3
Coefficients ν1 and ν2 are the first (shear) and second (bulk) parameter of viscosity respectively, vi;j and
vj;i denote the covariant derivatives whereas hi , hj are the geometrical elements of the respective direc-
tion. The expression above holds for an isotropic viscous stress and the resulting tensor is symmetric,
with (Π)ij = (Π)ji .
The actual diffusion terms will then be given by ∇ · Π and ∇ · (v · Π) on the right hand side of the mo-
mentum and the energy equation respectively. These fluxes are added to the hyperbolic momentum and
energy fluxes computed with a Riemann solver in a fully conservative and unsplit fashion (if EXPLICIT
is chosen). In curvilinear geometries, additional geometrical source terms coming from the tensor’s di-
vergence are added to the right hand side of the equations. On the other hand, if VISCOSITY is set to
STS, advection and diffusion terms are treated separately using operator splitting. The implementation
of the previous expressions together with the equation module can be found under the directory Src/Vis-
cosity. Derivative terms are discretized at cell interfaces using second-order accurate finite differences
and assuming a uniform grid spacing. Note that when using FARGO-MHD, this module can operate
only with STS.
The viscous transport coefficients ν1 (shear) and ν2 (bulk) are defined in the function Visc nu() in
the source file PLUTO/Src/Viscosity/visc nu.c. This file should be copied from its original folder to the
actual working directory before doing any modification.
72
CHAPTER 8. DISSIPATIVE EFFECTS 73
Arguments:
8.2 Resistivity
The resistive module is enabled by setting RESISTIVITY to either EXPLICIT (for time-explicit com-
putations) or to SUPER TIME STEPPING (to accelerate explicit computations) from the Python menu.
Magnetic field dissipation is modeled by introducing the resistivity tensor η so that the electric field be-
comes E = −v × B + η · J , where J ≡ ∇ × B is the current density. The induction and energy equations
gain extra terms on the right hand sides:
∂B
+ ∇ × (−v × B) = −∇ × (η · J )
∂t
(8.3)
∂E
+ ∇ · [(E + pt )v − B (v · B)] = −∇ · [(η · J ) × B] .
∂t
Similarly, the internal energy equation modifies to
∂p
+ v · ∇p + ρc2s ∇ · v = (Γ − 1) (η · J ) · J . (8.4)
∂t
The resistive tensor η is assumed to be diagonal with components
The module is implemented in the Src/MHD/Resistivity directory and the functional form of η can be
specified by editing your local copy of PLUTO/Src/MHD/Resistivity/res eta.c which includes the function
Resistive eta():
Syntax:
void Resistive_eta(double *v, double x1, double x2, double x3,
double *J, double *eta)
Arguments:
Note: The resistive module is only partially compatible with the entropy switch (§2.2.4).
CHAPTER 8. DISSIPATIVE EFFECTS 75
where the subscripts k and ⊥ denote, respectively, the parallel and normal components to the magnetic
field, T is the temperature, κk and κ⊥ are the thermal conduction coefficients along and across the field.
In the purely hydrodynamical limit (no magnetic field), Eq. (8.8) reduces to F c = κk ∇T .
Saturated effects are accounted for by making the flux independent of ∇T for very large tempera-
ture gradients [Spi62, CM77]. In this limit, the flux magnitude approaches Fsat = 5φρc3iso where is the
isothermal speed of sound and φ < 1 is a free parameter. Note, however, that it is possible to suppress
saturation effects by turning the macro TC SATURATED FLUX to NO, see also Appendix B.3: in this case
F c = F class .
The coefficients appearing in Eq. (8.8), (8.7) and in the definition of the saturated flux may be spec-
ified using the function TC kappa() in (your local copy of) PLUTO/Src/Thermal Conduction/tc kappa.c
and by noting the equivalence κk → ∗kpar, κ⊥ → ∗knor and φ → ∗phi. The variable ∗knor can be
ignored in the HD case, where κ = κk . Proper setting of units and dimensions is briefly discussed in
§8.3.1.
The thermal conduction module is implemented inside Src/Thermal Conduction and works in 1, 2
and 3 dimensions in all systems of coordinates. Derivative terms are discretized at cell interfaces using
second-order accurate finite differences and assuming a uniform grid spacing. Integration may proceed
via standard explicit time stepping or Super-Time-Stepping, see §8.4.
Note: Thermal conduction behave like a purely parabolic (diffusion) operator in the classical limit
(φ → ∞) and like a hyperbolic operator in the saturated limit (|∇T | → ∞). Thus in the general
case a mixed treatment is required, where the parabolic term is discretized using standard central
differences and the saturated term follows an upwind rule, [BTH08, MZT+ 12].
In this case and when Super-Time-Stepping integration is used to evolve the equations, sev-
eral numerical tests have shown that problem involving strong discontinuities may require
a reduction of the parabolic Courant number Cp (see §8.4) and a more tight coupling be-
tween the hydrodynamical and thermal conduction scale. The latter condition may be accom-
plished by lowering the rmax par parameter (§4.3) which controls the ratio between the cur-
rent time step and the diffusion time scale, see also §8.4. An example problem can be found in
Test Problems/MHD/Thermal conduction/Blast.
8.3.1 Dimensions
Equations (8.6)-(8.8) are solved in dimensionless form by expressing energy and time in units of ρ0 v02 and
L0 /v0 (respectively) and by writing temperature as T = (p/ρ)Kµ, where p and ρ are in code units and µ is
CHAPTER 8. DISSIPATIVE EFFECTS 76
the mean molecular weight. Here ρ0 , v0 , L0 are the unit density, velocity, length while K is the KELVIN
macro, see §5.1.1. The thermal conduction coefficients must be properly defined by re-absorbing the
correct normalization constants in the TC kappa() function as follows
µmu
κ → κcgs (8.9)
ρ0 v0 L0 kB
√
where, for instance, one may use κcgs,k = 5.6 · 10−7 T 5/2 and κcgs,⊥ = 3.3 · 10−16 n2H /( T B 2cgs ), both
in units of erg s−1 K−1 cm−1 , while B 2cgs = 4πρ0 v02 B 2 . An example of such dimensionalization can be
found in Test Problems/MHD/Thermal Conduction/Blast.
CHAPTER 8. DISSIPATIVE EFFECTS 77
Here ∆tpar is the explicit parabolic time step computed in terms of the diffusion coefficient D and phys-
ical grid size ∆l. The previous equation is solved to find N for given values of ∆tn , ∆tpar and ν. For
ν → 0, STS is asymptotically N times faster that the standard explicit scheme. However, very low val-
ues of ν may result in an unstable integration whereas values close to 1 can decrease STS’s efficiency. By
default ν = 0.01, a value which in many cases retains stability whereas giving substantial gain, see Fig
8.1. To change the default value of ν = STS NU, redefine it in the user-defined symbolic constant section
of definitions.h, see §2.3.
Stability analysis for the constant coefficient diffusion equation, [Bec92], indicates that the value of
Cp (parabolic Courant number) should be ≤ 1/Ndim (Ndim is the number of spatial dimensions) and it
may be used to adjust the size of the spectral radius for strongly nonlinear problems. A reduction of Cp
CHAPTER 8. DISSIPATIVE EFFECTS 78
will results in increased stability at the cost of more substeps N . The default value is Cp = 0.8/Ndim but
it may be changed in your pluto.ini through CFL par, see §4.3.
Since STS treats parabolic equations in an operator-split formalism, it may be advisable (for highly
nonlinear problems involving strong discontinuities) to limit the scale disparity between advection and
diffusion time scales by restricting the time step ∆tn to be at most rmax ∆tpar , with ∆tpar defined by Eq.
(8.11) and rmax a free parameter, see §4.3. In this cases, rmax may be lowered by lowering rmax par in
pluto.ini from its default value (100) to 40 or even less.
Note that although this method is in many cases considerably more efficient than the explicit one,
it is found to be slightly less accurate due to operator splitting. The method is by definition first order
accurate in time, although different values of the ν parameter are found to affect the accuracy. On
the other hand, STS bypasses the severe time constraint posed by second derivative operators in high
resolution simulations.
During the STS step, momentum, magnetic field or total energy are evolved in time even if the
ENTROPY SWITCH has been enabled.
9. Optically Thin Cooling
PLUTO can include time-dependent optically thin radiative losses in a fractional step formalism in
which the hydrodynamical evolution and the source step are solved separately using operator splitting.
This preserves 2nd order accuracy in time if both the advection and source steps are at least 2nd order
accurate. During the cooling source step, specifically, PLUTO solves the internal energy and chemical
reaction network equations
∂(ρe)
= −Λ(n, T, X)
∂t
(9.1)
∂X
= S(X, T )
∂t
where Λ is a cooling (or heating) term, X is an array of fractional abundances (typically ion or molecule
number fractions) and S is a reaction source term. The right-hand side of Equations (9.1) is implemented
in the function Src/Cooling/<COOLING>/radiat.c of each corresponding cooling module, except for the
POWER LAW cooling where integration is performed analytically. The user can select one among several
different cooling module by setting the COOLING flag during the python script:
• POWER LAW : power-law cooling, see §9.1;
• TABULATED: only the equation for the internal energy with a tabulated cooling function Λ(T ) is
provided. No chemical network, see §9.2;
• SNEq: cooling function for atomic hydrogen, X = {XHI }, including ionization, recombination
and collisionally excited emission lines, §9.3;
• H2 COOL: cooling function for atomic and molecular and atomic hydrogen, X = {XH2 , XHI , XHII },
including ionization, recombination and collisionally excited emission lines, §9.4;
• MINEq: cooling function for atomic and molecular and atomic hydrogen treating the time-dependent
ionization state of the plasma, X = {XH , XHe , XC , XN , XN e, XO , XS }, see §9.5.
Cooling modules are implemented inside the Src/Cooling directory and require three dimensional
constants to be correctly initialized. Dimensional constants are essential to scale data values to cgs
physical units as explained in §5.1.1.
Other variables are introduced to control crucial parameters such as the maximum allowed cooling
rate in each time step, or the cutoff temperature:
• g maxCoolingRate: limit the time step so that the maximum fractional thermal losses cannot
exceed g maxCoolingRate. In general 0 <g maxCoolingRate< 1; the default is 0.1.
• g minCoolingTemp: sets the cut-off temperature below which cooling is artificially set to 0.
79
CHAPTER 9. OPTICALLY THIN COOLING 80
Γ−1 ρ0 L0
C = abr
(kB µmH )3/2 v02
where ρ0 , v0 and L0 are the reference density, velocity and length defined in §5.1.1 and abr = 2 · 10−27
in expressed in c.g.s. units. The implementation of this cooling step, with α = 1/2, can be found under
Src/Cooling/Power Law/cooling.c.
CHAPTER 9. OPTICALLY THIN COOLING 81
when the cooling/heating function Λ̃(T ) is not known analytically but rather is available as a table
sampled at discrete (not necessarily equidistant) points, i.e., Λ̃j ≡ Λ̃(Tj ). In order to use this module,
the user must provide a two-column ascii files in the working directory named cooltable.dat of the form
. .
. .
. .
T(j) Lambda(j)
. .
. .
. .
3
with the temperature expressed in Kelvin and the cooling/heating function Λ̃ in ergs·cm /s. An
example of such file1 can be found in Src/Cooling/Tab/cooltable.dat. As usual, the dimensionalization is
done automatically by the cooling module, once UNIT DENSITY, UNIT LENGTH and UNIT VELOCITY
have been defined in Init().
Alternatively, the TABULATED cooling module can be used to provide a user-defined cooling func-
tion,
Λ = Λ(V ) , (9.6)
where V is a vector primitive variables. The explicit dependence of Λ can be given by i) copying Src/-
Cooling/Tab/radiat.c into your local working directory and ii) make the appropriate changes.
1 Generated with Cloudy 90.01 for an optically thin plasma and solar abundances, thanks to T. Plewa.
CHAPTER 9. OPTICALLY THIN COOLING 82
in your Init() function. The fraction of neutrals is treated as a passive scalar during the hydro step
while it is governed by the following ODE during the cooling step:
∂xHI h i
= S = ne − (cr + ci ) fn + cr (9.8)
∂t
together with the energy equation
k=16
!
∂(ρe) X
= −Λ = −ne nH jk + wi/r (9.9)
∂t
k=1
where the summation over k accounts for 16 different line emissions coming from some of the most
common elements, k = Ly α, H α, HeI (584+623), CI (9850 + 9823), CII (156µ), CII (2325Å), NI (5200 Å),
NII (6584 + 6548 Å), OI (63µ), OI (6300 + 6363 Å), OII (3727), MgII (2800), SiII (35µ), SII (6717 + 6727),
FeII (25µ), FeII (1.6µ).
The coefficient jk in (9.9) has dimensions of erg/sec cm3 and is computed from
√
~2 2π hνk
jk = √ fk q12
kB me me 1 + n e (q21 /A21 )
where k is the index of a particular transition, fk = nk /nH is the abundance for that particular species.
Here
8.6 · 10−6 Ω12 8.6 · 10−6 Ω21
hνk
q12 = √ exp − , q21 = √
T g1 kB T T g2
where Ω12 = Ω21 is the collision strength and is tabulated.
In Eq. (9.9) wi/r represents the thermal energy lost by ionization and recombination:
T
wi/r = ci × 13.6 × 1.6 · 10−12 fn + cr × 0.67 × 1.6 · 10−12 (1 − fn )
11590
where cr and ci are the hydrogen ionization and recombination rate coefficients:
√
2.6 · 10−11 1.08 · 10−8 T
157890.0
cr = √ ; ci = exp − √ .
T (13.6)2 T
CHAPTER 9. OPTICALLY THIN COOLING 83
Table 9.1: Summary of the chemistry reaction set. T is the temperature in Kelvin, TeV is the temperature
in electron-volts and T2 = T/100
No. Reaction Rate Coefficient (cm3 s−1 ) Reference a
− + − −11 0.5
1. H + e → H + 2e k1 = 5.84 × 10 T exp(−157, 809.0/T ) 1
2. H+ + e− → H + hν k2 = 2.6 × 10−11 T −0.5 1
− − −10 0.35
3. H2 + e → 2H + e k3 = 4.4 × 10 T exp(−102, 000.0/T ) 2
4. H2 + H → 3H k4 = 1.067 × 10−10 TeV
2.012
in your Init() function. Note, the value of v[X H2] should be between 0.0 and 0.5, while the remain-
ing two hydrogen fractions can have values ranging from 0.0 to 1.0, such that their sum is conserved.
The chemical evolution of molecular, atomic and ionized hydrogen is governed by equations listed
in Table 9.1. The number density of various hydrogen forms are determined by solving the chemical
rate equations, which have a general form as,
dni X X
= kj,k nj nk − ni ki,j nj , (9.10)
dt j
j,k
where, n is the number density, kj,k is the rate of formation of ith specie from all j and k species and ki,j is
the rate of destruction of ith specie due to all j species.
The code integrates the three hydrogen fractions defined above using the advection equation of the
form:
∂Xi
= −v · ∇Xi + Si , (9.11)
∂t
where the first term on the rhs is treated during the hydro step while only the second is integrated during
the cooling step. The source terms Si is essentially the difference between formation and destruction rate
of a particular specie (see eq.9.10). Additionally, the internal energy losses take into accounts various
hydrogen cooling processes,
where, ΛCI and ΛRR are losses due to collisional ionization and radiative recombination respectively.
The remaining terms, Λrotvib , ΛH2diss and Λgrain are associated with molecular hydrogen and represent
CHAPTER 9. OPTICALLY THIN COOLING 84
losses due to rotational-vibrational cooling, dissociation and gas-grain processes. Their variation with
temperature for a particular set ofm hydrogen fractions is shown in fig.9.1. Depending on the require-
ment, the user can add more components to the cooling function, for e.g., cooling due to fixed fractions
of standard molecules like CO, OH, H2 O etc or contributions from collisional excitation of lines as indi-
cated in the SNEq module.
CHAPTER 9. OPTICALLY THIN COOLING 85
where N and T are the plasma number density and temperature respectively and *v is a vector of
primitive variables. The function will return the electron density as output, and *v will contain the
computed ionization fractions (the other variables are not affected). The routine solves the system of
equations for abundances in equilibrium.
Note: The number of ions for C, N, O, Ne and S may be reduced from 5 to a lower number (>
1) by editing Src/Cooling/MINEq/cooling.h. This may reduce computational time if the expected
temperatures are not large enough to produce high ionization stages (e.g. IV or V if T < 105 K).
The current default value is 3.
The elements abundances are set in radiat.c from the Src/Cooling/MINEq/ folder. When using the
MINEq module, the cooling coefficients tables are generated at the beginning of the simulation by the
routines in Src/Cooling/MINEq/make tables.c. Update or customization of the atomic data can be done by
editing this file.
The ion fractions are integrated through advection equations of the form:
∂Xi
+ v · ∇Xi = Si , (9.13)
∂t
where the source term Si is computed taking into account collisional ionization, radiative and dielec-
tronic recombination, as well as charge-transfer with H and He processes, see [TMM08]. Similarly, the
energy loss term is
h i X
Λ = nat nel Λ1 (T, X) + LFF + LI−R , Λ1 (T, X) = Xk Lk (nel , T )Bk , (9.14)
k
is the total cooling for one ion specie, that is computed and saved to external files by the tables generation
program, then loaded at runtime.
In Eq. (9.14), LFF and LI−R represent the energy losses in bremsstrahlung and ionization/recombi-
nation processes respectively, nat and nel are the total atom and electron number densities respectively.
MINEq uses a dynamically switching integration algorithm for the ion species and energy designed
to maximize the accuracy while keeping the computational cost as low as possible.
10. Additional Modules
+w
y z
The shearingbox provides a local model of a differentially rotating system obtained by expanding
the tidal forces in a reference frame co-rotating with the disk at some fiducial radius R0 . The validity
of the approximation (and of the module itself) is restricted to a Cartesian box (considered small with
respect to the global flow) with a steady flow consisting of a linear shear velocity,
d log Ω(R)
vy = −qΩ0 x , with q = − (10.1)
d log R R=R0
where Ω0 is the local constant angular velocity and q is a local measure of the differential rotation (q =
3/2 for a Keplerian profile). The module solves the HD or MHD equations in a non-inertial frame so
that the momentum and energy equations become
∂(ρv)
+ ∇ · (ρvv − BB) + ∇pt = ρg s − 2Ω0 ẑ × ρv
∂t
(10.2)
∂E
+ ∇ · [(E + pt ) v − (v · B) B] = ρv · g s ,
∂t
where g s = Ω20 (2qxx̂ − zẑ) is the tidal expansion of the effective gravity while the second term in Eq.
(10.2) represents the Coriolis force. The continuity and induction equations retain the same form as the
original system.
While the computational box should be periodic in the azimuthal (y) direction, radial (x) boundary
conditions are determined by ”image” boxes sliding with relative velocity w = |qΩ0 Lx | relative to the
computational domain, Fig 10.1. In other words, the boundary conditions at the left/right x-boundaries
are (
q(x, y, z, t) = q (x ± Lx , y ∓ wt, z, t)
(10.3)
vy (x, y, z, t) = vy (x ± Lx , y ∓ wt, z, t) ± w ,
where q is any other flow quantities except vy .
The ShearingBox module is implemented inside Src/MHD/ShearingBox and works, at present, with
the HD equations or with CONSTRAINED TRANSPORT MHD. Parallelization can be performed in all
three spatial dimensions.
86
CHAPTER 10. ADDITIONAL MODULES 87
The numerical value of q and Ω0 is prescribed (starting with PLUTO 4.2) using the macros SB Q and
SB OMEGA which, by default, take the value of 3/2 and 1, respectively. Should you change the default
value, add them as user-defined constants as explained in §2.3.
Only gravitational forces must be given through the BodyForceVector() function since Coriolis
term are separately included by PLUTO . An example containing several configurations can be found
in the Test Problems/MHD/Shearing Box/ directory.
Boundary conditions must be prescribed as shearingbox at the X1 BEG and X1 END boundaries,
periodic in the azimuthal (y) direction but can be freely assigned in the vertical direction z.
Compatibility with the FARGO module. The shearingbox module is fully compatible with the FARGO
algorithm and a significant gain may be obtained for boxes with large aspect ratio (Lx Lz ). To enable
both modules, you must invoke the python script with the --with-sb and the --with-fargo options.
In this case the macro FARGO AVERAGE VELOCITY (§10.2.1) is automatically turned to NO so that the
background orbital velocity is prescribed analytically with the FARGO SetVelocity() function.
With FARGO, however, the source terms in the momentum and energy equations are slightly different
[MFS+ 12, SG10]: h i h i h i
S m = 2Ω0 ρvy0 î + (q − 2)Ω0 ρvx ĵ + − ρΩ20 z k̂
With a large number of processors (& 2048), the resulting auto-decomposition mode may result in
sub-domains that violate this condition and an error message is issued. To avoid this problem you can
specify the parallel decomposition manually using the -dec n1 [n2] [n3] command line argument
(§1.4.1) and ensure that not too many processors are used along the φ direction. As an example, suppose
you wish to use 4096 processors but only 8 along the orbital direction (x2 ). You may specify the domain
decomposition by giving, say, 32, 8 and 16 in the three directions with
In this Chapter we describe the data formats supported by the static grid version of PLUTO and how
they can be read and visualized with some popular visualization packages.
*.vtk: VTK (legacy) file format using structured or rectilinear grids (serial/parallel);
*.tab: tabulated multi-column ascii format (serial only);
*.ppm: portable pixmap color images of 2D data slices (serial/parallel);
Output files are named as base.nnnn.ext, where base is either ”data” (when all variables are written
to a single file) or the name of the corresponding variable (when each variable is written to a different
file, see Table 11.1), nnnn is a four-digit zero-padded integer counting the output number and ext is the
corresponding file extension listed above. By default, data files are written in the local working directory
unless a different location has been specified using output dir in your pluto.ini, see §4.6. There’s no
distinction between serial or parallel mode.
Table 11.1: Base prefix for multiple data set. The size is in units of 4 (for the flt format) or 8 (for the dbl format) bytes.
1 Bitmap image format that employs lossless data compression
92
CHAPTER 11. OUTPUT AND VISUALIZATION 93
For each format, it is possible to dump all or just some of the variables. Additional user-defined
variables may be written as well, §11.2.0.1. The default setting is described separately for each output in
the next subsections and may be changed if necessary, see §11.2.1.
Each format has an independent output frequency and an associated log file (i.e. dbl.out, flt.out, vtk.out
and so forth) keeping track of the dump history. Two additional files, grid.out and sysconf.out, contain
grid and system-related information, respectively.
Important: some visualization packages need the information stored in *.out files. We thus strongly
recommend to backup these files together with the actual datafiles.
Note: Restart is possible only using the .dbl or .dbl.h5 data formats.
where nout, t, dt and nstep are, respectively, the file number, time, time step and integration step at
the time of writing. The next column (single file/multiple files) tells whether a single-file or
multiple-files are expected. The following one (little/big) gives the endianity of the architecture,
whereas the remaining columns list the variable names and their order in this particular format.
Default: The default is to write ALL fields in dbl format, whereas to exclude staggered magnetic field
components (if any) from the flt format.
• VTK TIME INFO: when set to YES, time information will be added to the header section of the
.vtk file. Beware that standard VTK files do not have a specific construct for adding time informa-
tion and, by doing so, this information will be available only to the VisIt visualisation software
(see §11.3.5) which implements a convention where CYCLE and TIME values can be specified as
FieldData in the file. If you’re using Paraview or other visualisation software different from VisIt,
enabling this option will most likely result in a software crash.
• VTK VECTOR DUMP: by default, all flow quantities (e.g. density, or the x1 component of velocity)
are written with “scalar” attribute as they are. However, by setting VTK VECTOR DUMP to YES,
vector fields (such as velocity and magnetic field) can be saved with the “vector” attribute and
their components are automatically transformed to Cartesian.
where the index j changes faster and a blank records separates blocks with different i index.
Default: By default, all variables except staggered magnetic field components (if any) are written.
• slice coord: a real number specifying the coordinate orthogonal to slice plane.
• max,min: the maximum and minimum values to which the image is scaled to. If max=min au-
toscaling is used;
CHAPTER 11. OUTPUT AND VISUALIZATION 95
The rest of the file is made up of 3 sections, one for each dimension, giving the (interior) number of
point followed by a tabulated multi-column list containing (from left to right) the point number, left and
right cell interfaces:
nx1
. . .
. . .
. . .
<point number> <cell left edge> <cell right edge>
. . .
. . .
. . .
T = GetUserVar("T");
vortz = GetUserVar("vortz");
dx = grid[IDIR].dx; /* shortcut to dx */
dy = grid[JDIR].dx; /* shortcut to dy */
DOM_LOOP(k,j,i){
T[k][j][i] = p[k][j][i]/rho[k][j][i];
vortz[k][j][i] = 0.5*(vy[k][j][i+1] - vy[k][j][i-1])/dx[i]
- 0.5*(vx[k][j+1][i] - vx[k][j-1][i])/dy[j];
}
}
PLUTO automatically allocates static memory area for the new variables T and vortz when calling the
GetUserVar() function. The DOM LOOP macro performs a loop on the whole computational domain
(boundary excluded) in order to compute T[k][j][i] and vortz[k][j][i]. Once PLUTO runs,
these two variables will automatically be written in all selected formats (except for the ppm and png
formats), by default.
Beware that if the number of uservar is reset to zero but the previous function is still executed, a
segmentation fault error will occur since user-defined variables (such as T and vortz in the example
above) have not been allocated into memory.
In order to change the default attributes, follow the example in the next subsection.
VTK OUTPUT, DBL H5 OUTPUT, FLT H5 OUTPUT, TAB OUTPUT, PPM OUTPUT, PNG OUTPUT. This is a
sketch of how this function may be used:
void ChangeDumpVar ()
{
Image *image; /* a pointer to an image structure */
In this example, the variable “bx1” is excluded from the flt output, “prs” and “vortz” (defined in the
previous example) are added to the ppm and png outputs, respectively. Furthermore, the default image
attributes of “rho” (included by default) are changed to represent a cut (in log scale, red colormap) in
the xz plane at the point coordinate y = 1.1 in the y−direction.
Note that the default for .dbl of .dbl.h5 datasets should never be changed since restarting from a given
file requires ALL variables being evolved in time.
CHAPTER 11. OUTPUT AND VISUALIZATION 98
Table 11.2: Output data formats and supported graphic visualization packages.
File Format gnuplot IDL Mathematica Paraview PyPluto Visit
√ √ √ √ √ √
.dbl
√ √ √ √ √ √
.flt
√ √ √ √
.vtk - -
√ √ √
.dbl.h5 - - -
√ √ √
.flt.h5 - - -
√ √ √ √
.hdf5 - -
√
.tab - - - - -
11.3 Visualization
PLUTO data files can be read with a variety of commercial and open source packages. In what follows
we describe how PLUTO data files can be read and visualized with IDL2 , VisIt3 , ParaView4 , pyPLUTO
(§11.3.3), Mathematica5 and Gnuplot6 . Table 11.2 show some of the visualization softwares supporting
different output formats.
We recall that reading of .dbl or .flt files must be complemented by grid information which is stored
in a separate file (grid.out). On the other hand, VTK and HDF5 files (.xmf / .h5 , .vtk or .hdf5) are “stand-
alones” in the sense that they embed grid information and can be opened alone.
In the following we give a short summary of the available options while a more detailed documen-
tation can be found in Doc/gnuplot.html.
Ascii Data Files. If you enabled the .tab output format in pluto.ini, you can plot 1D data from, e.g., the
first output file by typing
gnuplot> plot "data.0001.tab" u 1:3 title "Density"
gnuplot> replot "data.0001.tab" u 1:5 title "Pressure" # overplot
Here the first column corresponds to the x coordinate, the second column to the y coordinate and flow
data values start from the third column. Fig. 11.1 shows the density and pressure profiles for the Sod
shock tube problem (conf. #03 in Test Problems/HD/Sod) using the previous commands.
Two-dimensional ascii datafiles can also be visualized using the splot command. Fig. 11.2 shows
a simple contour drawing of the final solution of the Mach reflection test problem (remember to enable
.tab output) using
gnuplot> set contour
gnuplot> set cntrparam level incremental 0.1,0.2,20 # Uniform levels from 0.1 to 20
gnuplot> set view map
gnuplot> unset surface
gnuplot> unset key
gnuplot> splot "data.0001.tab" u 1:2:3 w lines
2 http://www.exelisvis.com/
3 https://wci.llnl.gov/codes/visit/home.html
4 http://www.paraview.org/
5 http://www.wolfram.com
6 http://www.gnuplot.info
7 Version 4.2 or higher is recommended.
CHAPTER 11. OUTPUT AND VISUALIZATION 99
Binary Data Files. Starting with Gnuplot 4.2, raw binary files are also supported. In this case, grid
information (being stored in separate files) must be supplied explicitly through appropriate keywords
making the syntax a little awkward.
To ease up this task, one can take advantage of the scripts provided with the code distribution in
Tools/Gnuplot. For this, we recommend to define the GNUPLOT LIB environment variable (in your shell)
which will be appended to the loadpath of Gnuplot:
> export GNUPLOT_LIB=$PLUTO_DIR/Tools/Gnuplot # use setenv for tcsh users
The first line invokes the grid.gp script which is used to read grid information, the second script sets the
data file size (8 or 4 for double or single precision) while the last one initializes a default environment
for viewing binary data files using the pm3d style of Gnuplot.
For additional documentation and examples please refer to Doc/gnuplot.html.
CHAPTER 11. OUTPUT AND VISUALIZATION 100
The PLOAD Procedure The PLOAD procedure can be considered the main driver for reading data
stored in one of the following formats: .dbl, .flt, .vtk, .dbl.h5, .flt.h5 or .hdf5. PLOAD requires the infor-
mation stored in the corresponding data log file (e.g. grid.out, dbl.out, flt.out, etc...) to initialize common
block variables and grid information shared by other functions and procedures in the Tools/IDL/ subdi-
rectory. Because of this reason, it should always be called at the very beginning of an IDL session. For
example:
IDL> ; Read all variables from the the third output in double precision
IDL> ; and store it into memory {rho, vx1, vx2, prs, ...}
IDL> PLOAD,3
IDL> ; Read only pressure from the fifth output in single precision
IDL> ; and store it into memory
IDL> PLOAD,5,/FLOAT, VAR="prs"
By default, PLOAD tries to read binary data in double precision if dbl.out is present. To select a different
format, a corresponding keyword must be supplied (e.g. /FLOAT, /H5 or /HDF5 or a combination of
them, see Doc/idl tools.html).
When PLOAD is called for the first time, it initializes the following four common blocks:
• PLUTO GRID: contains grid information such as the number of points (nx1,nx2,nx3), coordi-
nates (x1,x2,x3) and mesh spacing (dx1, dx2, dx3);
• PLUTO VAR: the number (NVAR) and the names of variables being written for the chosen format.
Variable names follow the same convention adopted in PLUTO , e.g., rho, vx1, vx2, ...,
bx1, bx2, prs, .. and so on;
• PLUTO RUN: time stepping information such as output time (t), time step (dt) and total number
of files (nlast).
PLOAD can be used inside a normal IDL script, after it has been invoked at least once (or compiled with
.r pload).
The DISPLAY Procedure DISPLAY is a general-purpose visualization routine and the source code can
be found in Tools/IDL/display.pro The DISPLAY procedure can be used to display the intensity map of a
2D variable to a graphic window, e.g.,
IDL> PLOAD,3 ; load the third data set in double precision
IDL> DISPLAY,x1=x1,x2=x2,alog10(rho), title=’Density’,/vbar
IDL> DISPLAY,x1=x1,x2=x2,vx1,title=’X-Velocity’,nwin=1
The second line displays the density logarithm and the third line displays the x1 component of velocity
in a new window.
Another example, shown in Fig. 11.3, shows how to visualize magnetic pressure and density in two
different windows and overplot the velocity field. For more details, consult Doc/idl tools.html.
CHAPTER 11. OUTPUT AND VISUALIZATION 101
Figure 11.3:
An exam-
ple of
visualiza-
tion in IDL
using the
display.pro
routine.
CHAPTER 11. OUTPUT AND VISUALIZATION 102
Binary data files (.dbl, .flt) and VTK files (.vtk) can be visualized using the pyPLUTO code. This
tool is included in the current code distribution in the directory Tools/pyPLUTO/ and provides python
modules (Python version > 2.7 is recommended) to load, visualize and analyse data. Additionally,
for the purpose of a quick check, Graphic User Interface (GUI) is provided (requires Python Tkinter).
Details of the Installation and Getting Started can be found in the Doc/pyPLUTO.html.
On successful installation, the user can load data in the following manner:
> ipython --pylab
In [1]: import pyPLUTO as pp
# for loading data.0010.dbl
In [2]: D = pp.pload(10,w_dir=<path to data dir>)
# for loading data.0010.flt
In [3]: D = pp.pload(10,w_dir=<path to data dir>, datatype=’float’)
Here, D is a pload object that has all the information regarding the variable names and their values
which are stored as arrays. It also has the respective grid and time information. For example, D.x1 is the
numpy x-array, D.rho - is the numpy density array, D.vx1 - is the numpy vx1 array and so on. These
numpy arrays can be easily visualized using matplotlib, python’s plotting library. The pyPLUTO’s also
provides two classes - Image and Tools. They have some frequently used functions for analysis and data
plotting. Details about these classes along with their usage can be found in HTML document referred
above.
In order to use the GUI version for visualizing the data, append $PATH variable to the bin folder
where the executable GUI pyPLUTO.py exists after the installation of source code (see installation notes
in Doc/pyPLUTO.html) and then apply the following commands in the data directory -
> GUI_pyPLUTO.py # default is for .dbl files
> GUI_pyPLUTO.py --float # for .flt files
> GUI_pyPLUTO.py --vtk # for .vtk files
Along with the code, an example folder with some sample .py files are provided for certain test prob-
lems. The source codes from these files along with their outputs are listed in the HTML documentation.
It is required to first run the respective test problem and generate the data files, after which the user
can run the sample .py files as follows from the Tools/pyPLUTO/examples folder:
> python samplefile.py
Table 11.3: List of sample .py files provided in the Tools/pyPLUTO/examples folder
samplefile.py Test Problem
sod.py HD/Sod
Rayleigh taylor.py HD/Rayleigh Taylor
stellar wind.py HD/Stellar Wind
jet.py MHD/Jet
orszag tang.py MHD/Orszag Tang
Sph disk.py MHD/FARGO/Spherical Disk
flow past cyc.py HD/Viscosity/Flow Past Cylinder
CHAPTER 11. OUTPUT AND VISUALIZATION 104
PLUTO data files can be displayed with Mathematica8 using a notebook interface to create an in-
teractive document. A simple reader interface is provided by Tools/Mathematica/pload.m and it can be
launched to load and display binary datafiles written in single or double precision (.flt and .dbl). Data
is stored into lists and can be handled using a variety of built-in functions in Mathematica. Grid and
time information are also read from the .out log files and stored into the variables nx and ny (number of
points), t (current time level), nvar (number of variables), dt (current time step).
A typical interactive session once you open an empty book is
AppendTo[$Path, ToFileName[{"/home/mignone/PLUTO/Tools/Mathematica"}]]
SetDirectory["/home/mignone/PLUTO/Test_Problems/MHD/Shock_Cloud"]
<< pload.m
Please remember to type Shif t + Enter after each line to make the Wolfram Language process your
input. The first line simply adds the Tools/Mathematica directory to the path, the second line changes
directory to the working location and the third invokes the reader. Once executed, pload.m reader
prompts for the output number, single or double precision and then the variable to display. The out-
put of this session is shown in Fig. 11.5 for the MHD Shock-Cloud interaction test (conf. #01 in
Test Problems/MHD/Shock Cloud).
The function ArrayPlot[] is used to display 2D datasets and is directly included in the interface
reader. For instance, to change colormap and visualize pressure in log scale, use
ArrayPlot[Log[data[[8]]], DataReversed -> True, ColorFunction -> "RoseColors",
DataRange -> {{xmin, xmax}, {ymin, ymax}}]
The current directory can be displayed by typing Directory[] while the home directory can shown
by typing $HomeDirectory
8 http://www.wolfram.com
CHAPTER 11. OUTPUT AND VISUALIZATION 105
Figure 11.6: An example of visualization of an .xmf (.h5) data file using VisIt (left) or ParaView (right).
Visualization of HDF5 files. Both VisiIt and Paraview interpret the cell-centered grid and data con-
tained in the Pixie files as node-centered: as a consequence, the first and the last half cells in every
direction are clipped from the images (e.g. a small sector around φ = 0 is chopped from a periodic polar
plot covering the 2π angle).
Therefore, for every .h5 file, PLUTO writes also a .xmf text file in XDMF format that describes the
content of the corresponding HDF5 file. The .xmf files can be directly opened by VisIt and ParaView, so
as to provide the correct data centering and avoid the image clipping. Besides, we noticed that the Pixie
reader crashes (e.g. using ParaView 3.14 - 3.98) or incorrectly reads the .h5 files (e.g. using VisIt versions
after 2.6), while all versions of both VisIt and Paraview properly open the .xmf files. All the variables are
read as scalar quantities.
Visualization of VTK files. PLUTO writes .vtk files using a cell-centered attribute rather than point-
centered (as in previous versions). Although this has not been found to be a problem for VisIt, many
filters in ParaView (such as streamlines) may require to apply a Cell Data to Point Data filter.
12. Adaptive Mesh Refinement (AMR)
PLUTO provides adaptive mesh refinement (AMR) functionality in 1, 2 and 3 dimesions through the
Chombo library1 . Chombo provides a distributed infrastructure for parallel calculations over block-
structured, adaptively refined grids. PLUTO-Chombo is compatible with any of the available physics
modules (i.e. HD, MHD, RHD, RMHD) and grid refinement is supported in all coordinate systems. Moreover,
grid zones are no longer constrained to be equilateral but sides can have different lengths. Magnetic
fields are evolved using cell-centered schemes i.e., either Powell’s EIGHT WAVES or DIV CLEANING.
Constrained transport is not yet available. I/O is provided by the Hierarchical Data Format (HDF5)
library2 , designed to store and organize large amounts of numerical data. A detailed presentation of the
implementation method together with an extensive numerical test suite may be found in [MZT+ 12].
For compatibility reasons, not all the algorithms available with the static grid version of PLUTO have
been extended to the AMR version. The AMR implementation of PLUTO is not compatible, at present,
with:
• constrained-transport MHD;
• finite difference schemes;
12.1 Installation
In order to properly install PLUTO-Chombo , you will need (check also Table 1.1):
• C, C++ and Fortran compilers;
• the MPI library (for parallel runs).
• GNU make
• the Chombo library1 (version 3.2 is recommended);
• the HDF5 library2 (version < 1.8.14 is recommended);
• the chombo-3.2-patch.tar.gz provided with the PLUTO distribution, which replaces some of the
library source files.
The following sections give a quick headstart on how these libraries can be built for being used by
PLUTO . Please consult the libraries’ respective documentation for additional information.
1 https://commons.lbl.gov/display/chombo/
2 http://www.hdfgroup.org/HDF5/
106
CHAPTER 12. ADAPTIVE MESH REFINEMENT (AMR) 107
Note: Both PLUTO (static) and PLUTO-Chombo (AMR) have been succesffuly tested for serial
and parallel computation using with HDF5 v. < 1.8.14 while parallel I/O problems were found on
Ubuntu systems using newer versions.
Different builds are necessary for serial or parallel execution and, since in both cases library names
are the same (by default), it is advisable to store them in separate locations. On a single-processor
machine, serial libraries can be built, for example, using
> ./configure --prefix=/usr/local/lib/HDF5-serial
> make
> make check # optional
> make install
This will install the libraries under /usr/local/lib/HDF5-serial/lib. If you do not have root
privileges, choose a different location in your home directory (e.g. $PLUTO DIR/Lib/HDF5-serial).
Note: The I/O of Chombo 3.2 has been updated to use the HDF5 1.8 API. Howerer, if HDF5
1.6.x is installed on your system, the support for the 1.6 API is still provided by adding the
-DH5 USE 16 API flag to the HDFINCFLAGS variable inside your Make.defs.local, see §12.1.2. Nev-
ertheless, it is not guaranteed that the HDF5 1.6 API will be supported in future Chombo releases.
On multiple-processor architectures, parallel libraries can be built by specifying the name of the
mpicc compiler in the CC variable and invoking configure with the --enable parallel switch,
e.g.,
> CC=mpicc ./configure --prefix=/usr/local/lib/HDF5-parallel --enable-parallel # bash user
> make
> make check # optional
> make install
This will install both shared (dynamic, *.so) and static (*.a) libraries. If you build shared libraries, the
environment variable LD LIBRARY PATH should contain the full path name to your HDF5 library (e.g.
/usr/local/lib/HDF5-serial/lib in the example above). Please make sure to add, for example,
> setenv LD_LIBRARY_PATH /usr/local/lib/HDF5-serial/lib:$LD_LIBRARY_PATH
if you’re using bash. If you do not want shared libraries, then add --disable-shared to the configure
command.
In order to use Chombo, you may have to build different libraries depending on the chosen compiler,
serial/parallel build, number of dimensions, optimizations, etc... If you intend to run PLUTO-Chombo
for serial or parallel computations in one, two or three dimensions, we suggest to compile all possible
configurations (that is 1, 2 and 3D serial or 1, 2 and 3D parallel). Libraries are automatically named by
Chombo after the chosen configuration.
The default configuration can be set by editing manually Chombo-3.2/lib/mk/Make.defs.local where,
depending on your local system and configuration, you need to set make variables. To this end:
> cd Chombo-3.2/lib
> make setup # create Make.defs.local from template
> cd mk/
The command ’make setup’ will create this file from a template that contains instructions for set-
ting make variables that Chombo uses. These variables specify the default configuration to build, what
compiler to use (together with its flags), where the HDF library can be found and so on.
At this point you should edit Make.defs.local. The normal procedure is to define a default configura-
tion, e.g., 2D serial:
## Configuration variables
DIM = 2
DEBUG = FALSE
OPT = TRUE
PRECISION = DOUBLE
PROFILE = FALSE
CXX = g++
FC = gfortran
MPI = FALSE
## Note: don’t set the MPICXX variable if you don’t have MPI installed
MPICXX = mpic++
#OBJMODEL =
#XTRACONFIG =
## Optional features
#USE_64 =
#USE_COMPLEX =
#USE_EB =
#USE_CCSE =
USE_HDF = TRUE
HDFINCFLAGS = -I/usr/local/lib/HDF5-serial/include
HDFLIBFLAGS = -L/usr/local/lib/HDF5-serial/lib -lhdf5 -lz
## Note: don’t set the HDFMPI* variables if you don’t have parallel HDF installed
HDFMPIINCFLAGS= -I/usr/local/lib/HDF5-parallel/include
HDFMPILIBFLAGS= -L/usr/local/lib/HDF5-parallel/lib -lhdf5 -lz
Defaults are used for the remaining field beginning with a ’#’.
Libraries can now be built under Chombo-3.2/lib, with
> make lib
Do not try make all since it won’t work after the Chombo patch file has been unpacked.
Alternative configurations can be made from the default one by specifying the configuration vari-
ables explicitly on the make command line. For example:
> make DIM=3 MPI=TRUE lib
will build the parallel version of the 3D library. Additional information may be found in the Chom-
bo/README file and by consulting the library documentation.
CHAPTER 12. ADAPTIVE MESH REFINEMENT (AMR) 109
This will use the default library configuration (2D serial in the example above).
To use a configuration different from the default one, enter the make configuration variables em-
ployed when building the library, e.g.:
˜/work> python $PLUTO_DIR/setup.py --with-chombo: MPI=TRUE
(do not use spaces in MPI=TRUE). Note that the number of dimensions (DIM) is specified during the
Python script and should NOT be given as a command line argument.
The setup proceeds normally as in the static grid case by choosing Setup problem from the Python
script to change/configure your test problem. The makefile is then automatically created by the Python
script by dumping Chombo makefile variables into the file make.vars, part of your local working direc-
tory. Although system dependencies have already been created during the Chombo compilation stage,
the Change makefile option from the Python menu is still used to specify the name and flags of the C
compiler used to compile PLUTO source files. This step is achieved as usual, by selecting a suitable .defs
file from the Config/ directory, see Chapter 3. Beware that, during this step, additional variables such
as PARALLEL, USE HDF5, etc...(normally used in the static grid version) have no effect since Chombo
has its own independent parallelization strategy and I/O. Fortran and C++ compilers are the same ones
used to build the library.
Initial and boundary conditions are coded in the usual way but definitions.h and pluto.ini may contain
some AMR-specific directives.
where the supported command line options are given in Table 1.3 in §1.4. Note that -restart must be
followed by the restart (checkpoint) file number. An error will occur otherwise.
Parallel runs proceeds in the usual way, e.g.,
˜/MyWorkDir> mpirun -np 8 ./pluto [flags]
Note that when running in parallel, each processor redirects the output on a separate file pout.n (instead
of pluto.log) where n=0...Np-1 and Np is the total number of processors. However, pout.0 also contains
additional information regarding the chosen configuration.
Pre-configured examples can be found in the Test Problems/ folder, e.g.,
• Configuration #04 of Test Problems/HD/Mach Reflection;
where U ∈ U is a conserved variable, ∆d,± 21 U are the undivided forward and backward differences in
the direction d, e.g., ∆x,± 12 U = ±(Ui±1 − Ui ) (see also section 4.1 in [MZT+ 12]). The last term appearing
in the denominator, Ud,ref , prevents regions of small ripples from being refined and it is defined by
The procedure HDF5LOAD (located in /Tools/IDL/hdf5load.pro) can read a HDF5 data file and store its
content on the usual set of variables used during a typical IDL session. HDF5LOAD is directly called
from PLOAD (§11.3.2) when the latter is invoked with the /HDF5 keyword. For instance, in order to read
data.0001.hdf5 at the equivalent resolution provided by the 4th refinement level, you need
IDL> pload, /hdf5,2,level=4 # will load data.0002.hdf5, ref level = 4
Note that IDL re-interpolates the required dataset to a uniform mesh with resolution given by the spec-
ified refinement level.
As an example, we show how to visualize the density map for the relativistic Kelvin-Helmholtz test
problem as in Fig. 12.1 corresponding to the output of configuration # 03 of Test Problems/RMHD/KH.
Figure 12.1: Density maps of the relativistic Kelvin-Helmholtz test problem, at t = 5. Refinement levels are displayed, using
the oplotbox routine.
The figure has been produced with the following IDL commands:
IDL> PLOAD, /HDF5, dir="DATA_03",5,lev=4, x2range=[0.5,1.5]
IDL> LOADCT,6
IDL> DISPLAY,x1=x1,x2=x2,/vbar,rho,imax=1.1,imin=0.65,title="Density map"
IDL> OPLOTBOX,ctab=3
The last command (OPLOTBOX) overplots the levels of refinement, utilizing the color table 3. If you are
plotting a 2D map in curvilinear coordinates (polar or spherical) using the DISPLAY procedure setting
the /POLAR keyword, you can use the same /POLAR keyword for the OPLOTBOX procedure to correctly
overplot the levels of refinement.
Reading Large Datasets. It may occur that the dataset one wishes to load exceeds the available mem-
ory. In that case, it is useful to load only a portion of it. This can be accomplished by specifying sub-
domain through the keywords x1range, x2range and x3range. For instance:
IDL> PLOAD, /hdf5, 5,lev=6, x1range=[0.25,0.75], x2range=[0.75,1.25]
# will load data.0005.2d.hdf5, ref level = 6
# but only inside the region x in [0.25,0.75], y in [0.75,1.25]
IDL> DISPLAY, x1=x1,x2=x2, rho, nwin=1, imax=1.1,imin=0.65
IDL> OPLOTBOX, ctab=3
CHAPTER 12. ADAPTIVE MESH REFINEMENT (AMR) 112
As an example we show, in Fig. 12.2, a close-up of the final solution obtained with configuration #08
of the Test Problems/HD/Disk Planet/ problem.
Figure 12.2: Density distribution with overplotted AMR levels for the disk-planet interaction.
12.4.3 Visualization with pyPLUTO
The simulation data obtained from PLUTO-Chombo is written as a HDF5 file, which can now be visu-
alised and analysed using pyPLUTO (§11.3.3). The reader for HDF5 files with AMR data in pyPLUTO
has been developed by Dr. Antoine Strugarek (Departement of Physics, University of Montreal) and
has same capablities as that of IDL’s HDF5LOAD. In order to use this reader it is required to install, h5py
package, the Pythonic interface to HDF5 data.
The syntax you need is similar to that used for static grids. For example, in order to read data.0001.hdf5
at the equivalent resolution provided by the 4th refinement level,
> ipython --pylab
In [1]: import pyPLUTO as pp
In [2]: D = pp.pload(1,datatype=’hdf5’,level=4)
Now, the pyPLUTO pload object, D has all information regarding the data. To visualize (say) the
density ρ, one can use the pyPLUTO.Image class as follows.
In [3]: I = pp.Image()
In [4]: I.pldisplay(D, D.rho, x1 = D.x1, x2 = D.x2, cbar=(True,
’vertical’))
# To plot 2D R-Phi data obtained from a POLAR AMR Grid.
In [5]: I.pldisplay(D, D.rho, x1 = D.x1, x2 = D.x2, cbar=(True,
’vertical’), polar=[True, True])
# To plot 2D R-Theta Slice from 3D POLAR AMR Data.
In [6]: I.pldisplay(D, D.rho[:,:,D.n3/2], x1 = D.x1, x2 = D.x2, cbar=(True,
’vertical’), polar=[True, False])
Further, AMR levels in form of boxes can be overplotted using the oplotbox routine. Here, we plot
the boxes for all 4 refine levels in addition to the base coarse grid.
In [7]: I.oplotbox(D.AMRLevel, lrange=[0,4],cval=[’r’,’g’,’k’,’c’,’m’],geom=D.geometry)
The figure 12.3 shows the total magnetic pressure obtained for the MHD Rotor problem in 2D at
the equivalent resolution provided by the 4th refinement level, also, overplotted are the AMR levels in
different colored lines for all of these 4 levels.
Note: : The HDF5 reader is not yet integrated into the pyPLUTO’s graphical user interface
113
A. Equations in Different Geometries
In this section we give the explicit form of the MHD and RMHD equations written in different systems of
coordinates. Non-ideal terms such as viscosity, resistivity and thermal conduction are not included here.
The discretizations used in the Src/MHD/rhs.c and Src/RMHD/rhs.c strictly follow these form. Equations
for the non-magnetized version (HD and RHD) are obtained by setting the magnetic field vector B = 0.
∂ρ
+ ∇ · (ρv) = 0
∂t
∂mx ∂pt ∂Φ
+ ∇ · (mx v − Bx B) + = ρ gx −
∂t ∂x ∂x
∂my ∂pt ∂Φ
+ ∇ · (my v − By B) + = ρ gy −
∂t ∂y ∂y
∂mz ∂pt ∂Φ
+ ∇ · (mz v − Bz B) + = ρ gz −
∂t ∂z ∂z (A.1)
∂ h i
(E + ρΦ) + ∇ · (E + pt + ρΦ)v − B (v · B) = ρv · g
∂t
∂Bx ∂Ez ∂Ey
+ − = 0
∂t ∂y ∂z
∂By ∂Ex ∂Ez
+ − = 0
∂t ∂z ∂x
∂Bz ∂Ey ∂Ex
+ − = 0
∂t ∂x ∂y
where v = (vx , vy , vz ) and B = (Bx , By , Bz ) are the velocity and magnetic field vectors, (Ex , Ey , Ez )
are the components of the electromotive force E = −v × B, g is the body force vector and Φ is the
gravitational potential.
114
A.1.2 Polar Coordinates
In polar cylindrical coordinates (R, φ, z), the conservative ideal MHD Equations (6.4) are discretized
using the following divergence form
∂ρ
+ ∇ · (ρv) = 0
∂t
ρvφ2 − Bφ2
∂mR ∂pt ∂Φ
+ ∇ · (mR v − BR B) + = ρ gR − +
∂t ∂R ∂R R
∂mφ 1 ∂pt 1 ∂Φ
+ ∇R · (mφ v − Bφ B) + = ρ gφ −
∂t R ∂φ R ∂φ
∂mz ∂pt ∂Φ
+ ∇ · (mz v − Bz B) + = ρ gz −
∂t ∂z ∂z (A.2)
∂ h i
(E + ρΦ) + ∇ · (E + pt + ρΦ)v − B (v · B) = ρv · g
∂t
∂BR 1 ∂Ez ∂Eφ
+ − = 0
∂t R ∂φ ∂z
∂Bφ ∂ER ∂Ez
+ − = 0
∂t ∂z ∂R
∂Bz 1 ∂(REφ ) 1 ∂ER
+ − = 0,
∂t R ∂R R ∂φ
Note that curvature terms are present in the radial component while the azimuthal component is dis-
cretized in angular momentum conserving form. The corresponding divergence operators are
In the previous equations v = (vR , vφ , vz ) and B = (BR , Bφ , Bz ) are the velocity and magnetic field
vectors, (ER , Eφ , Ez ) are the components of the electromotive force E = −v ×B, g is the body force vector
and Φ is the gravitational potential.
115
A.1.3 Spherical Coordinates
In spherical coordinates (r, θ, φ) the ideal MHD equations (6.4) are discretized using the following di-
vergence form
∂ρ
+ ∇ · (ρv) = 0
∂t
ρv 2 − Bθ2 ρvφ2 − Bφ2
∂mr ∂pt ∂Φ
+ ∇ · (mr v − Br B) + = ρ gr − + θ +
∂t ∂r ∂r r r
ρvφ2 − Bφ2
∂mθ 1 ∂pt 1 ∂Φ ρvθ vr − Bθ Br
+ ∇ · (mθ v − Bθ B) + = ρ gθ − − + cot θ
∂t r ∂θ r ∂θ r r
∂mφ 1 ∂pt 1 ∂Φ
+ ∇r · (mφ v − Bφ B) + = ρ gφ −
∂t r sin θ ∂φ r sin θ ∂φ
∂ h i
(E + ρΦ) + ∇ · (E + pt + ρΦ)v − B (v · B) = ρv · g
∂t
∂Br 1 ∂(sin θEφ ) 1 ∂Eθ
+ − = 0
∂t r sin θ ∂θ r sin θ ∂φ
∂Bθ 1 ∂Er 1 ∂(rEφ )
+ − = 0
∂t r sin θ ∂φ r ∂r
∂Bφ 1 ∂(rEθ ) 1 ∂Er
+ − = 0
∂t r ∂r r ∂θ
(A.4)
Note that curvature terms are present in the radial and meridional components while the azimuthal
component is discretized in angular momentum conserving form. The corresponding divergence oper-
ators are
1 ∂(r2 Fr ) 1 ∂(sin θFθ ) 1 ∂Fφ
∇·F = 2
+ +
r ∂r r sin θ ∂θ r sin θ ∂φ
2
(A.5)
3
r 1 ∂(r Fr ) 1 ∂(sin θFθ ) 1 ∂Fφ
∇ ·F = + +
r3 ∂r r sin2 θ ∂θ r sin θ ∂φ
In the previous equations v = (vr , vθ , vφ ) and B = (Br , Bθ , Bφ ) are the velocity and magnetic field
vectors, (Er , Eθ , Eφ ) are the components of the electromotive force E = −v × B, g is the body force vector
and Φ is the gravitational potential.
116
A.2 (Special) Relativistic MHD Equations
A.2.1 Cartesian Coordinates
In Cartesian coordinates (x, y, z), the relativistic MHD equations (6.11) take the form
∂D
+ ∇ · (Dv) = 0
∂t
∂mx ∂pt
+ ∇ · (w + b2 )vx v − bx b +
= ρgx
∂t ∂x
∂my 2
∂pt
+ ∇ · (w + b )vy v − by b + = ρgy
∂t ∂y
∂mz ∂pt
+ ∇ · (w + b2 )vz v − bz b +
= ρgz
∂t ∂z
(A.6)
∂E
+ ∇ · (m − Dv) = Dv · g
∂t
∂Bx ∂Ez ∂Ey
+ − = 0
∂t ∂y ∂z
∂By ∂Ex ∂Ez
+ − = 0
∂t ∂z ∂x
∂Bz ∂Ey ∂Ex
+ − = 0
∂t ∂x ∂y
where D = γρ is the lab density, m = (w + b2 )v − γ(v · B)b is the momentum density, w is the gas
enthalpy, b2 = B 2 /γ 2 + (v · B)2 , v = (vx , vy , vz ) is the velocity, B = (Bx , By , Bz ) is the magnetic field
in the lab frame, b = B/γ + γ(v · B)v is the covariant field, (Ex , Ey , Ez ) are the components of the
electromotive force E = −v × B and g is the body force vector.
117
Note that curvature terms are present in the radial component while the azimuthal component is dis-
cretized in angular momentum conserving form. The corresponding divergence operators are
In the previous equations v = (vR , vφ , vz ) and B = (BR , Bφ , Bz ) are the velocity and magnetic field
vectors, (ER , Eφ , Ez ) are the components of the electromotive force E = −v ×B, g is the body force vector
and Φ is the gravitational potential.
∂D
+ ∇ · (Dv) = 0
∂t
∂mr ∂pt mθ vθ + mφ vφ
+ ∇ · (w + b2 )vr v − br b +
= ρgr + +
∂t ∂r r
Bθ Bθ Bφ Bφ
− 2
+ (v · B)vθ − 2
+ (v · B)vφ
γ r γ r
∂mθ 1 ∂pt mθ vr − cot θmφ vφ
+ ∇ · (w + b2 )vθ v − bθ b +
= ρgθ −
∂t r ∂θ r
Bθ Br Bφ Bφ
+ 2
+ (v · B)vθ − cot θ 2
+ (v · B)vφ
γ r γ r
∂mφ 1 ∂pt
+ ∇r · (w + b2 )vφ v − bφ b +
= ρgφ
∂t r sin θ ∂φ
∂E
+ ∇ · (m − Dv) = Dv · g
∂t
∂Br 1 ∂(sin θEφ ) 1 ∂Eθ
+ − = 0
∂t r sin θ ∂θ r sin θ ∂φ
∂Bθ 1 ∂Er 1 ∂(rEφ )
+ − = 0
∂t r sin θ ∂φ r ∂r
∂Bφ 1 ∂(rEθ ) 1 ∂Er
+ − = 0
∂t r ∂r r ∂θ
(A.9)
Note that curvature terms are present in the radial and meridional components while the azimuthal
component is discretized in angular momentum conserving form. The corresponding divergence oper-
ators are
1 ∂(r2 Fr ) 1 ∂(sin θFθ ) 1 ∂Fφ
∇·F = + +
r2 ∂r r sin θ ∂θ r sin θ ∂φ
(A.10)
r 1 ∂(r3 Fr ) 1 ∂(sin2 θFθ ) 1 ∂Fφ
∇ ·F = + +
r3 ∂r r sin2 θ ∂θ r sin θ ∂φ
118
B. Predefined Constants and Macros
119
B.3 Advanced Options
PLUTO allows a number of switches to be fine-tuned directly from your definitions.h in the user-defined
constant section, see §2.3. These advanced options are described in Table B.1.
120
Table B.1 – Continued from previous page
Name Value Description
Set the reference state used during the characteristic tracing
step (see Src/States/char tracing.c), as explained in section 3.3
of [MZT+ 12]. The allowed values are 1, 2 or 3:
ref
1: use the cell-centered value: wi,± = wi,0 . This choice is
slightly more diffusive but has found to work well for
flows containing strong discontinuities;
2: No reference state is introduced and the interpolated
ref
states at the base time level are used: wi,± = wi,± . This
CHTR REF STATE (1/2/3)
is found to be a good choice in presence of smooth flow
and equlibrium configurations.
3: reference states are constructed as in the original PPM al-
gorithm [CW84, Col90] to minimize the size of the term
susceptible to characteristic limiting (see Eq. [29] and [30]
of [MZT+ 12]).
The default value is 3 except for PARABOLIC/WENO reconstruc-
tion in characteristic variable for which 2 is used.
Sets the maximum shock strength above which fluid variables
inside a given computational zone can be safely updated us-
ing the entropy equation (see §2.2.4 and the source file Sr-
EPS PSHOCK ENTROPY (real)
c/flag shock.c). It has effect only when ENTROPY SWITCH has
been enabled. A lower value will trigger the flattening proce-
dure in more zones. Default is 0.05.
Sets the minimum shock strength above which the MULTID
shock flattening algorithm flags a zone to be inside a shock (see
EPS PSHOCK FLATTEN (real) Src/flag shock.c). It has effect only when SHOCK FLATTENING
is set to MULTID. A lower value will trigger the flattening pro-
cedure in more zones. Default is 5.0.
Set this to YES if the FARGO orbital velocity w should be
computed by averaging the azimuthal velocity every fixed
FARGO AVERAGE VELOCITY (YES/NO) number of steps. When set to NO, w is computed from the
FARGO SetVelocity() function. Default is NO, or YES if
FARGO is used with the shearing box module.
Sets how often the orbital velocity should be recomputed in the
FARGO NSTEP AVERAGE (int)
FARGO transport step. Default is 10.
Sets the spatial order of the reconstruction used during the lin-
ear transport step of the FARGO algorithm. The allowed values
FARGO ORDER (int)
are 3 (third-order, PPM-like reconstruction) or 2 (second-order
MUSCL-HANCOCK scheme). Default is 3.
Sets the value of the constant α used monopole damping in the
GLM ALPHA (real)
GLM formalism, see §6.2.3.2. The default value is 0.1.
Enable the (E)xtented GLM form of the MHD equations, see
GLM EXTENDED (YES/NO)
§6.2.3.2. Default value is NO.
Hydrogen mass fraction, X = mu nH AH /ρ. Used to compute
H MASS FRAC (double) FRAC He and FRAC Z in the definition of the mean molecular
weight, see §5.1.2. Default value is X = 0.7110.
Helium mass fraction, Y = mu nHe AHe /ρ. Used to compute
FRAC He and FRAC Z in the definition of the mean molecular
He MASS FRAC (double)
weight, see §5.1.2. Note that the fraction of metals is always
computed as Z = 1 − X − Y . The default value is Y = 0.2741.
Continued on next page
121
Table B.1 – Continued from previous page
Name Value Description
Sets the order of reconstruction when using PARABOLIC recon-
struction. Allowed values are 3 (uses three-point stencil, third-
PPM ORDER (3/4/5) order accurate), 4 (fourth order) and 5 (fifth order). For more
information see [Mig14]. The default value is 4 (as in the origi-
nal PPM method).
Used for the PVTE LAW EOS in ionization equilibrium, §7.3.2.
When set to YES replaces function evaluations of the thermal
PV TEMPERATURE TABLE (YES/NO) EOS (p = nkB T ) and its inverse with lookup table and bilinear
interpolation. This results in a considerably faster execution.
Default is YES.
Sets the number of x-points used to construct the temperature
PV TEMPERATURE TABLE NX (int) table for the PVTE LAW EOS. The default value is set in Sr-
c/EOS/PVTE/thermal eos.c.
Sets the number of y-points used to construct the temperature
PV TEMPERATURE TABLE NY (int) table for the PVTE LAW EOS. The default value is set in Sr-
c/EOS/PVTE/thermal eos.c.
Use the four-velocity u = γv instead of the three velocity
when reconstructing left and right states in the RHD and RMHD
RECONSTRUCT 4VEL (YES/NO)
modules. Not compatible with conservative form of MUSCL-
Hancock scheme. Default is NO.
If set to YES, use approximate (and faster) expressions when
computing the fast magnetosonic speed of the RMHD equa-
RMHD FAST EIGENVALUES (YES/NO) tions, see Sect. 3.3 of [DZBL07]. Solutions of quartic equa-
tion is avoided and replaced with upper bounds provided by
quadratic equation. Default is NO.
Used in the RMHD module (§6.4) to evolve the total energy
minus the mass density contribution (see [MM07]). This is
RMHD REDUCED ENERGY (YES/NO) more advisable in order to avoid numerical errors in the non-
relativistic limit and catastrophic cancellation problems. De-
fault is YES.
[Shearing box module only, §10.1]. The value of the orbital fre-
SB OMEGA (real)
quency parameter Ω0 , see §10.1. The default value is 1.0.
[Shearing box module only, §10.1]. The value of the differential
SB Q (real) shear parameter q, see §10.1. The default value is 1.5 proper
for a Keplerian profile.
[Shearing box module only, §10.1]. Symmetrize the hydrody-
namical fluxes at the left and right x-boundaries in order to en-
SB SYMMERIZE HYDRO (YES/NO)
force conservation of hydrodynamic variables like density, mo-
mentum and energy (no magnetic field). Default is YES.
[Shearing box module only, §10.1]. Symmetrize the y-
component of the electric field at the left and right x-boundaries
SB SYMMERIZE EY (YES/NO)
to enforce conservation of magnetic field (only in 3D, see Sr-
c/MHD/Shearing Box/sb fluxes.c). Default value if YES.
[Shearing box module only, §10.1]. Symmetrize the z-
SB SYMMERIZE EZ (YES/NO) component of electric field at the left and right x-boundaries
to enforce conservation of magnetic field. Default is YES.
Print, during the integration log, the three time steps (hyper-
SHOW TIME STEPS (YES/NO) bolic, parabolic and radiative) from which the CFL condition is
estimated.
Sets the value of the ν parameter used to control the effi-
ciency of Super-Time-Stepping integration for parabolic (diffu-
STS NU (real)
sion) terms, see Chapter 8 and §8.4.2. If not set, the default value
is 0.01.
Continued on next page
122
Table B.1 – Continued from previous page
Name Value Description
Include saturation effects when computing the thermal conduc-
TC SATURATED FLUX (YES/NO)
tion flux. Default value is YES.
Sets the cut-off temperature (in K) used in the PVTE LAW equa-
tion of state (§7.3). Zones with temperature below T CUT RHOE
T CUT RHOE (real)
will be reset to this value and the internal energy will be rede-
fined accordingly. Default value is 10 K.
Used for the PVTE LAW EOS in ionization equilibrium, §7.3.2.
When set to YES replaces function evaluations of the caloric
TV ENERGY TABLE (YES/NO) EOS (internal energy) and its inverse (e(T, ρ) and T (e, ρ)) with
lookup table and bilinear interpolation. This results in a consid-
erably faster execution. Default is YES.
Sets the number of x-points used to construct the tempera-
TV ENERGY TABLE NX (int) ture table for the PVTE LAW EOS. Default value is set in Sr-
c/EOS/PVTE/internal energy.c.
Sets the number of y-points used to construct the tempera-
TV ENERGY TABLE NY (int) ture table for the PVTE LAW EOS. Default value is set in Sr-
c/EOS/PVTE/internal energy.c.
Sets the unit density in gr/cm3 . Default value is the proton
UNIT DENSITY (real)
mass per cm3 .
UNIT LENGTH (real) Sets the unit length in cm. Default value is 1 astronomical unit.
UNIT VELOCITY (real) Sets the unit velocity in cm/sec. Default value is 1 Km/sec.
123
Bibliography
[AAG96] Vasilios Alexiades, Geneviève Amiez, and Pierre-Alain Gremaud, Super-time-stepping acceleration of
explicit schemes for parabolic problems, Communications in Numerical Methods in Engineering 12 (1996),
no. 1, 31–42.
[AAZN97] T. Abel, P. Anninos, Y. Zhang, and M. L. Norman, Modeling primordial gas in numerical cosmology, New
Astronomy2 (1997), 181–207.
[Bal86] S. A. Balbus, Magnetized thermal conduction fronts, ApJ304 (1986), 787–798.
[BCCD08] R. Borges, M. Carmona, B. Costa, and W. S. Don, An improved weighted essentially non-oscillatory scheme
for hyperbolic conservation laws, Journal of Computational Physics 227 (2008), 3191–3211.
[Bec92] J. M. Beckers, Analytical linear numerical stability conditions for an anisotropic three-dimensional advection-
diffusion equation, SIAM Journal on Numerical Analysis 29 (1992), no. 3, 701–713.
[BS99] D. S. Balsara and D. S. Spicer, A Staggered Mesh Algorithm Using High Order Godunov Fluxes to Ensure
Solenoidal Magnetic Fields in Magnetohydrodynamic Simulations, Journal of Computational Physics 149
(1999), 270–292.
[BS03] T. J. M. Boyd and J. J. Sanderson, The Physics of Plasmas, January 2003.
[BTH08] D. S. Balsara, D. A. Tilley, and J. C. Howk, Simulating anisotropic thermal conduction in supernova remnants
- I. Numerical methods, MNRAS386 (2008), 627–641.
[CM77] L. L. Cowie and C. F. McKee, The evaporation of spherical clouds in a hot gas. I - Classical and saturated mass
loss rates, ApJ211 (1977), 135–146.
[Col85] Phillip Colella, A direct eulerian muscl scheme for gas dynamics, SIAM Journal on Scientific and Statistical
Computing 6 (1985), no. 1, 104–117.
[Col90] P. Colella, Multidimensional upwind methods for hyperbolic conservation laws, Journal of Computational
Physics 87 (1990), 171–200.
[ČT09] M. Čada and M. Torrilhon, Compact third-order limiter functions for finite volume methods, Journal of
Computational Physics 228 (2009), 4118–4145.
[CW84] P. Colella and P. R. Woodward, The Piecewise Parabolic Method (PPM) for Gas-Dynamical Simulations,
Journal of Computational Physics 54 (1984), 174–201.
[DBL03] L. Del Zanna, N. Bucciantini, and P. Londrillo, An efficient shock-capturing central-type scheme for multi-
dimensional relativistic flows. II. Magnetohydrodynamics, A&A400 (2003), 397–413.
[DKK+ 02] A. Dedner, F. Kemm, D. Kröner, C.-D. Munz, T. Schnitzer, and M. Wesenberg, Hyperbolic Divergence
Cleaning for the MHD Equations, Journal of Computational Physics 175 (2002), 645–673.
[DZBL07] L. Del Zanna, O. Zanotti, N. Bucciantini, and P. Londrillo, ECHO: a Eulerian conservative high-order
scheme for general relativistic magnetohydrodynamics and magnetodynamics, A&A473 (2007), 11–30.
[GP98] D. Galli and F. Palla, The chemistry of the early Universe, A&A335 (1998), 403–420.
[GS05] T. A. Gardiner and J. M. Stone, An unsplit Godunov method for ideal MHD via constrained transport, Journal
of Computational Physics 205 (2005), 509–539.
[HEOC87] A. Harten, B. Engquist, S. Osher, and S. R. Chakravarthy, Uniformly high order accurate essentially non-
oscillatory schemes, III, Journal of Computational Physics 71 (1987), 231–303.
[HM79] D. Hollenbach and C. F. McKee, Molecule formation and infrared emission in fast interstellar shocks. I Phys-
ical processes, ApJS41 (1979), 555–592.
[JS96] G.-S. Jiang and C.-W. Shu, Efficient Implementation of Weighted ENO Schemes, Journal of Computational
Physics 126 (1996), 202–228.
124
[Kle98] W. Kley, On the treatment of the Coriolis force in computational astrophysics, A&A338 (1998), L37–L41.
[Ld04] P. Londrillo and L. del Zanna, On the divergence-free condition in Godunov-type schemes for ideal magne-
tohydrodynamics: the upwind constrained transport method, Journal of Computational Physics 195 (2004),
17–48.
[Lio96] M.-S. Liou, A Sequel to AUSM: AUSM + , Journal of Computational Physics 129 (1996), 364–382.
[LL87] L. D. Landau and E. M. Lifshitz, Fluid mechanics, 2 ed., Pergamon Press, Oxford, 1987.
[LOC94] X.-D. Liu, S. Osher, and T. Chan, Weighted Essentially Non-oscillatory Schemes, Journal of Computational
Physics 115 (1994), 200–212.
[Loh87] R. Lohner, An adaptive finite element scheme for transient problems in CFD, Computer Methods in Applied
Mechanics and Engineering 61 (1987), 323–338.
[MB05] A. Mignone and G. Bodo, An HLLC Riemann solver for relativistic flows - I. Hydrodynamics, MNRAS364
(2005), 126–136.
[MBM+ 07] A. Mignone, G. Bodo, S. Massaglia, T. Matsakos, O. Tesileanu, C. Zanni, and A. Ferrari, PLUTO: A
Numerical Code for Computational Astrophysics, ApJS170 (2007), 228–242.
[MFS+ 12] A. Mignone, M. Flock, M. Stute, S. M. Kolb, and G. Muscianisi, A conservative orbital advection scheme
for simulations of magnetized shear flows with the PLUTO code, A&A545 (2012), A152.
[Mig07] A. Mignone, A simple and accurate Riemann solver for isothermal MHD, Journal of Computational Physics
225 (2007), 1427–1441.
[Mig14] , High-order conservative reconstruction schemes for finite volume methods in cylindrical and spherical
coordinates, Journal of Computational Physics 270 (2014), 784–814.
[MK05] T. Miyoshi and K. Kusano, A multi-state HLL approximate Riemann solver for ideal magnetohydrodynamics,
Journal of Computational Physics 208 (2005), 315–344.
[MM96] J. M. . Martı́ and E. Müller, Extension of the Piecewise Parabolic Method to One-Dimensional Relativistic
Hydrodynamics, Journal of Computational Physics 123 (1996), 1–14.
[MM07] A. Mignone and J. C. McKinney, Equation of state in relativistic magnetohydrodynamics: variable versus
constant adiabatic index, MNRAS378 (2007), 1118–1130.
[MPB05] A. Mignone, T. Plewa, and G. Bodo, The Piecewise Parabolic Method for Multidimensional Relativistic Fluid
Dynamics, ApJS160 (2005), 199–219.
[MT10] A. Mignone and P. Tzeferacos, A second-order unsplit Godunov scheme for cell-centered MHD: The CTU-
GLM scheme, Journal of Computational Physics 229 (2010), 2117–2138.
[MTB10] A. Mignone, P. Tzeferacos, and G. Bodo, High-order conservative finite difference GLM-MHD schemes for
cell-centered MHD, Journal of Computational Physics 229 (2010), 5896–5920.
[MUB09] A. Mignone, M. Ugliano, and G. Bodo, A five-wave Harten-Lax-van Leer Riemann solver for relativistic
magnetohydrodynamics, MNRAS393 (2009), 1141–1156.
[MZT+ 12] A. Mignone, C. Zanni, P. Tzeferacos, B. van Straalen, P. Colella, and G. Bodo, The PLUTO Code for
Adaptive Mesh Computations in Astrophysical Fluid Dynamics, ApJS198 (2012), 7.
[OBR+ 08] S. Orlando, F. Bocchino, F. Reale, G. Peres, and P. Pagano, The Importance of Magnetic-Field-Oriented
Thermal Conduction in the Interaction of SNR Shocks with Interstellar Clouds, ApJ678 (2008), 274–286.
[Pow94] K. G. Powell, Approximate Riemann solver for magnetohydrodynamics (that works in more than one dimen-
sion), Tech. report, March 1994.
[PRL+ 99] K. G. Powell, P. L. Roe, T. J. Linde, T. I. Gombosi, and D. L. De Zeeuw, A Solution-Adaptive Upwind
Scheme for Ideal Magnetohydrodynamics, Journal of Computational Physics 154 (1999), 284–309.
[RBMF97] P. Rossi, G. Bodo, S. Massaglia, and A. Ferrari, Evolution of Kelvin-Helmholtz instabilities in radiative jets.
II. Shock structure and entrainment properties., A&A321 (1997), 672–684.
[Roe81] P. L. Roe, Approximate Riemann Solvers, Parameter Vectors, and Difference Schemes, Journal of Computa-
tional Physics 43 (1981), 357–372.
[Sal94] J. Saltzman, An Unsplit 3D Upwind Method for Hyperbolic Conservation Laws, Journal of Computational
Physics 115 (1994), 153–168.
[SG10] J. M. Stone and T. A. Gardiner, Implementation of the Shearing Box Approximation in Athena, ApJS189
(2010), 142–155.
[SH97] A. Suresh and H. T. Huynh, Accurate Monotonicity-Preserving Schemes with Runge Kutta Time Stepping,
Journal of Computational Physics 136 (1997), 83–99.
125
[SO89] C.-W. Shu and S. Osher, Efficient Implementation of Essentially Non-oscillatory Shock-Capturing Schemes,
II, Journal of Computational Physics 83 (1989), 32–78.
[Spi62] L. Spitzer, Physics of Fully Ionized Gases, 1962.
[Str68] G. Strang, On the Construction and Comparison of Difference Schemes, SIAM Journal on Numerical Anal-
ysis 5 (1968), 506–517.
[Syn57] John Lighton Synge, The relativistic gas, North-Holland Publishing Company ; Interscience Publishers,
Amsterdam; New York, 1957.
[TMM08] O. Teşileanu, A. Mignone, and S. Massaglia, Simulating radiative astrophysical flows with the PLUTO code:
a non-equilibrium, multi-species cooling function, A&A488 (2008), 429–440.
[Tor97] Eleuterio F. Toro, Riemann solvers and numerical methods for fluid dynamics, 2 ed., Springer-Verlag Berlin
Heidelberg, 1997.
[van79] B. van Leer, Towards the ultimate conservative difference scheme. V - A second-order sequel to Godunov’s
method, Journal of Computational Physics 32 (1979), 101–136.
[VMBM15] B. Vaidya, A. Mignone, G. Bodo, and S. Massaglia, Astrophysical fluid simulations of thermally ideal gases
with non-constant adiabatic index: numerical implementation, A&A580 (2015), A110.
[WAMM07] J. Woodall, M. Agúndez, A. J. Markwick-Kemper, and T. J. Millar, The UMIST database for astrochemistry
2006, A&A466 (2007), 1197–1204.
[YC09] N. K. Yamaleev and M. H. Carpenter, A systematic methodology for constructing high-order energy stable
WENO schemes, Journal of Computational Physics 228 (2009), 4248–4272.
126