Plotting

This page documents Ulula’s plotting capabilities.

Overview

Ulula comes with two plotting routines for 1D and 2D data, plot1d() and plot2d(). Both plot multiple panels for multiple fluid quantities that are given as a list of strings. Valid identifiers are listed fields dictionary. A simulation object must be passed to the plotting functions.

fields

List of fields that can be plotted.

getPlotQuantities(sim, q_plot)

Compile an array of fluid properties

plot1d(sim[, q_plot, plot_type, idir_func, …])

Plot fluid state along a 1D line

plot2d(sim[, q_plot, vminmax_func, …])

Plot fluid state in 2D

Plottable quantities

All plotting functions take a q_plot parameter that contains a list of the fluid variables to be plotted. Possible values include the primitive and conserved variables that the simulation keeps track of (see Simulation framework), as well as some derived quantities:

Abbreviation

Quantity

DN

Density

PR

Pressure

ET

Total energy (thermal + kinetic + potentials)

VX

X-velocity

VY

Y-velocity

VT

Total velocity

MX

X-momentum

MY

Y-momentum

The full list is contained in the following dictionary:

ulula.plots.fields = {'DN': {'cmap': 'viridis', 'name': 'Density'}, 'ET': {'cmap': 'viridis', 'name': 'Energy'}, 'MX': {'cmap': 'RdBu_r', 'name': 'X-momentum'}, 'MY': {'cmap': 'RdBu_r', 'name': 'Y-momentum'}, 'PR': {'cmap': 'viridis', 'name': 'Pressure'}, 'VT': {'cmap': 'viridis', 'name': 'Total velocity'}, 'VX': {'cmap': 'RdBu_r', 'name': 'X-velocity'}, 'VY': {'cmap': 'RdBu_r', 'name': 'Y-velocity'}}

List of fields that can be plotted. Most fields occur in the primitive or conserved variable arrays, but some fields are derived (e.g., total velocity).

ulula.plots.getPlotQuantities(sim, q_plot)

Compile an array of fluid properties

Fluid properties are stored in separate arrays as primitive and conserved variables, or even in other arrays. Some quantities, such as total velocity, need to be calculated after the simulation has finished. This function takes care of all related operations and returns a single array that has the same dimensions as the domain.

Parameters
sim: Simulation

Object of type Simulation

q_plot: array_like

List of quantities to plot. Quantities are identified via the short strings given in the fields dictionary.

Returns
q_array: array_like

Array of fluid properties

Plotting functions

ulula.plots.plot1d(sim, q_plot=['DN', 'VX', 'VY', 'PR'], plot_type='line', idir_func=None, true_solution_func=None, vminmax_func=None, radial_bins_per_cell=4.0)

Plot fluid state along a 1D line

Create a multi-panel plot of the fluid variables along a line through the domain. This plotting routine is intended for pseudo-1D simulations, where the fluid state is uniform in the second dimension. The line is taken at the center of the domain in that dimension. The plot is created but not shown or saved to a file; these operations can be completed using the current matplotlib figure.

Parameters
q_plot: array_like

List of quantities to plot. Quantities are identified via the short strings given in the fields dictionary.

plot_type: str

The type of cut through the domain that is plotted. Can be line (in which case the idir parameter specifies the dimension along which the plot is made), or radius (which creates a radially averaged plot from the center).

idir_func: function

If plot_type == line, this function must be given and return the direction along which to plot (0 = x, 1 = y)

true_solution_func: function

If not None, the given function must return a 2D array with the true solution for the default fluid quantities and for a given input array of coordinates. This function is typically implemented within the problem setup (see Hydro problem setups).

vminmax_func: function

A function that returns two lists of minimum and maximum plot extents for the nq fluid variables. If None, the limits are chosen automatically.

radial_bins_per_cell: float

If plot_type == radius, this parameter chooses how many radial bins per cell are plotted. The bins are averaged onto the radial annuli, so this number can be greater than one.

ulula.plots.plot2d(sim, q_plot=['DN', 'VX', 'VY', 'PR'], vminmax_func=None, cmap_func=None, panel_size=3.0, plot_ghost_cells=False)

Plot fluid state in 2D

Create a multi-panel plot of the fluid variables along a line through the domain. This plotting routine is intended for pseudo-1D simulations, where the fluid state is uniform in the second dimension. The line is taken at the center of the domain in that dimension. The plot is created but not shown or saved to a file; these operations can be completed using the current matplotlib figure.

Parameters
q_plot: array_like

List of quantities to plot. Quantities are identified via the short strings given in the fields dictionary.

vminmax_func: function

A function that returns two lists of minimum and maximum plot extents for the nq fluid variables. If None, the limits are chosen automatically.

cmap_func: function

A function that returns a list of size nq with colormap objects to be used when plotting the fluid variables. If None, the default colormap is used for all fluid variables.

panel_size: float

Size of each plotted panel in inches

plot_ghost_cells: bool

If True, ghost cells are plotted and separated from the physical domain by a gray frame. This option is useful for debugging.