mhd module

Module for MHD specific plotting.

sapphireppplot.mhd.load_solution(plot_properties, path_prefix='', results_folder='', base_file_name='', animation_time=None)

Load solution for MHD module.

This function performs the following steps:

  1. Retrieves the folder containing simulation results.

  2. Loads the parameter file.

  3. Loads the solution data from the files in the results folder.

  4. Adds time step information if necessary.

  5. Updates the animation scene to the specified animation time.

Parameters:
  • plot_properties (PlotPropertiesMHD) – Properties of the solution to load.

  • path_prefix (str) – Prefix for relative path.

  • results_folder (str) – The path to the results folder.

  • base_file_name (str) – Overwrite base name of the solutions files.

  • animation_time (Optional[float]) – Set the time at which the animation scene is displayed. Defaults to the last time step.

Return type:

tuple[str, Dict[str, Any], SourceProxy, Proxy]

Returns:

  • results_folder (str) – The path to the results folder.

  • prm (ParamDict) – Dictionary of the parameters.

  • solution (SourceProxy) – A ParaView reader object with selected point arrays enabled.

  • animation_scene (Proxy) – The ParaView AnimationScene.

Raises:

ValueError – If no matching files are found.

See also

sapphireppplot.pvload

Module to load ParaView files.

sapphireppplot.utils.get_results_folder

Prompt for results folder.

sapphireppplot.plot_properties.PlotProperties.series_names

Series names list to load.

sapphireppplot.mhd.save_to_dat(solution, animation_scene, results_folder, filename, plot_properties, quantities=None, time_steps=None)

Convert to cell-centred data and save as .dat files with history file .hst.

Parameters:
  • solution (SourceProxy) – ParaView solution data.

  • animation_scene (Proxy) – The ParaView AnimationScene.

  • results_folder (str) – Path to the folder where results will be saved.

  • filename (str) – The base name for the saved data file (without extension).

  • plot_properties (PlotPropertiesMHD) – Properties of the solution.

  • quantities (Optional[Sequence[str]]) – List of physical quantity to save. Defaults to only the conserved variables.

  • time_steps (Optional[Iterable[float]]) – List of time steps to extract the data. Defaults to using all time steps.

Return type:

None

sapphireppplot.mhd.compute_kinetic_energy(solution, plot_properties_in)

Compute kinetic energy E_kin for the solution.

\[\mathcal{E}_{\rm kin} = \frac{p^2}{2 \rho}\]
Parameters:
  • solution (SourceProxy) – The the source data.

  • plot_properties_in (PlotPropertiesMHD) – Properties of the source.

Return type:

tuple[SourceProxy, PlotPropertiesMHD]

Returns:

  • calculator (SourceProxy) – Solution with kinetic energy.

  • plot_properties (PlotPropertiesMHD) – Solution properties for the including the kinetic energy.

See also

sapphireppplot.transform.calculator

Create Calculator.

sapphireppplot.mhd.compute_sound_speed(solution, plot_properties_in, gamma=1.6666666666666667)

Compute sound speed a_s for the solution.

\[a_{\mathrm{s}} = \sqrt{\frac{\gamma P}{\rho}}\]
Parameters:
  • solution (SourceProxy) – The the source data.

  • plot_properties_in (PlotPropertiesMHD) – Properties of the source.

  • gamma (float) – The adiabatic index.

Return type:

tuple[SourceProxy, PlotPropertiesMHD]

Returns:

  • calculator (SourceProxy) – Solution with sound speed.

  • plot_properties (PlotPropertiesMHD) – Solution properties for the including the sound speed.

See also

sapphireppplot.transform.calculator

Create Calculator.

sapphireppplot.mhd.compute_alfven_speed(solution, plot_properties_in)

Compute Alfvén speed c_A for the solution.

\[c_{\mathrm{A}} = \sqrt{\frac{b^2}{\rho}}\]
Parameters:
  • solution (SourceProxy) – The the source data.

  • plot_properties_in (PlotPropertiesMHD) – Properties of the source.

Return type:

tuple[SourceProxy, PlotPropertiesMHD]

Returns:

  • calculator (SourceProxy) – Solution with Alfvén speed.

  • plot_properties (PlotPropertiesMHD) – Solution properties for the including the Alfvén speed.

See also

sapphireppplot.transform.calculator

Create Calculator.

sapphireppplot.mhd.compute_mach_number(solution, plot_properties_in, gamma=1.6666666666666667)

Compute Mach number M for the solution.

\[M = \frac{\|u\|}{a_{\mathrm{s}}}\]

with \(a_{\mathrm{s}}\) the sound speed.

Parameters:
  • solution (SourceProxy) – The the source data.

  • plot_properties_in (PlotPropertiesMHD) – Properties of the source.

  • gamma (float) – The adiabatic index.

Return type:

tuple[SourceProxy, PlotPropertiesMHD]

Returns:

  • calculator (SourceProxy) – Solution with Mach number.

  • plot_properties (PlotPropertiesMHD) – Solution properties for the including the Mach number.

See also

sapphireppplot.transform.calculator

Create Calculator.

sapphireppplot.mhd.compute_alfven_mach_number(solution, plot_properties_in)

Compute Alfvén Mach number M_A for the solution.

\[M_{\mathrm{A}} = \frac{\|u\|}{c_{\mathrm{A}}}\]

with \(c_{\mathrm{A}}\) the Alfvén speed.

Parameters:
  • solution (SourceProxy) – The the source data.

  • plot_properties_in (PlotPropertiesMHD) – Properties of the source.

Return type:

tuple[SourceProxy, PlotPropertiesMHD]

Returns:

  • calculator (SourceProxy) – Solution with Alfvén Mach number.

  • plot_properties (PlotPropertiesMHD) – Solution properties for the including the Alfvén Mach number.

See also

sapphireppplot.transform.calculator

Create Calculator.

sapphireppplot.mhd.compute_magnetic_pressure(solution, plot_properties_in, gamma=1.6666666666666667)

Compute magnetic pressure P_B for the solution.

\[P_B = (\gamma -1) b^2\]
Parameters:
  • solution (SourceProxy) – The the source data.

  • plot_properties_in (PlotPropertiesMHD) – Properties of the source.

  • gamma (float) – The adiabatic index.

Return type:

tuple[SourceProxy, PlotPropertiesMHD]

Returns:

  • calculator (SourceProxy) – Solution with magnetic pressure.

  • plot_properties (PlotPropertiesMHD) – Solution properties for the including the magnetic pressure.

See also

sapphireppplot.transform.calculator

Create Calculator.

sapphireppplot.mhd.compute_normalized_magnetic_divergence(solution, plot_properties_in, divergence_type='total', delta_x=None)

Compute normalized_magnetic_divergence for the solution.

It is calculated using the following formula: \(\frac{|\nabla \cdot \mathbf{b}|}{\|\mathbf{b}\|} \Delta x\).

Parameters:
  • solution (SourceProxy) – The the source data.

  • plot_properties_in (PlotPropertiesMHD) – Properties of the source.

  • divergence_type (Literal['total', 'cells', 'faces']) – “total”, “cells” or “faces” divergence.

  • delta_x (Optional[float]) – Cell size. If none is given assume square grid with square cells.

Return type:

tuple[SourceProxy, PlotPropertiesMHD]

Returns:

  • calculator (SourceProxy) – Solution with normalized magnetic divergence.

  • plot_properties (PlotPropertiesMHD) – Solution properties for the including the log magnetic divergence.

See also

sapphireppplot.transform.calculator

Create Calculator.

sapphireppplot.mhd.plot_quantities_1d(solution, results_folder, quantities, name, plot_properties, x_label='$x$', x_range=None, value_range=None, log_x_scale=False, log_y_scale=False, show_time=False, save_animation=False, layout=None)

Plot and save a visualization of a specified physical quantity in 1D.

Parameters:
  • solution (SourceProxy) – The simulation or computation result containing the data to plot.

  • results_folder (str) – Path to the folder where results (images/animations) will be saved.

  • quantities (Sequence[str]) – List of physical quantity to plot.

  • name (str) – Name of the layout and image/animation files.

  • plot_properties (PlotPropertiesMHD) – Properties for plotting.

  • x_label (str) – Label for the bottom axis of the chart.

  • x_range (Optional[tuple[float, float]]) – Minimal (x_range[0]) and maximal (x_range[1]) value for the x-axes.

  • value_range (Optional[tuple[float, float]]) – Minimal (value_range[0]) and maximal (value_range[1]) value for the y-axes.

  • log_x_scale (bool) – Use a logarithmic x-scale?

  • log_y_scale (bool) – Use a logarithmic y-scale?

  • show_time (bool) – Display the simulation time in the line chart view view.

  • save_animation (bool) – Save an animation of the plot.

  • layout (Optional[ViewLayoutProxy]) – The layout object where the plot should be added as new view. Will create a new one if none if provided.

Return type:

tuple[ViewLayoutProxy, Proxy]

Returns:

  • layout (ViewLayoutProxy) – The layout object used for the plot.

  • line_chart_view (XYChartViewProxy) – The configured XY chart view.

See also

sapphireppplot.pvplot.plot_line_chart_view

Plot LineChartView.

sapphireppplot.mhd.plot_split_view_1d(solution, results_folder, quantities, name, plot_properties_in, labels=None, x_range=None, value_range=None, log_x_scale=False, log_y_scale=False, save_animation=False)

Create split plot of with one quantity per line chart plot.

Parameters:
  • solution (SourceProxy) – The simulation or computation result containing the data to plot.

  • results_folder (str) – Path to the folder where results (images/animations) will be saved.

  • quantities (Sequence[str]) – List of physical quantity to plot.

  • name (str) – Name of the layout and image/animation files.

  • plot_properties – Properties for plotting.

  • labels (Optional[Sequence[str]]) – Labels for the numeric and projected/interpolated solution.

  • x_range (Optional[tuple[float, float]]) – Minimal (x_range[0]) and maximal (x_range[1]) value for the x-axes.

  • value_range (Optional[tuple[float, float]]) – Minimal (value_range[0]) and maximal (value_range[1]) value for the y-axes.

  • log_x_scale (bool) – Use a logarithmic x-scale?

  • log_y_scale (bool) – Use a logarithmic y-scale?

  • save_animation (bool) – Save an animation of the plot.

Return type:

ViewLayoutProxy

Returns:

layout (ViewLayoutProxy) – The layout object used for the plot.

See also

sapphireppplot.pvplot.plot_line_chart_view

Plot LineChartView.

sapphireppplot.mhd.plot_quantity_2d(solution, results_folder, quantity, name, plot_properties, prefix='', value_range=None, log_scale=False, camera_direction=None, show_time=False, save_animation=False, layout=None)

Plot and save visualization of specified physical quantity in 2D.

Parameters:
  • solution (SourceProxy) – The simulation or computation result containing the data to plot.

  • results_folder (str) – Path to the folder where results (images/animations) will be saved.

  • quantity (str) – The physical quantity to plot.

  • plot_properties (PlotPropertiesMHD) – Properties for plotting.

  • name (str) – Name of the layout and image/animation files.

  • prefix (str) – Prefix for quantity name.

  • value_range (Optional[tuple[float, float]]) – Minimal (value_range[0]) and maximal (value_range[1]) value for the y-axes.

  • log_scale (bool) – Use a logarithmic color scale?

  • camera_direction (Optional[list[float]]) – Direction of the camera.

  • show_time (bool) – Display the simulation time in the render view.

  • save_animation (bool) – Save an animation of the plot.

  • layout (Optional[ViewLayoutProxy]) – The layout object where the plot should be added as new view. Will create a new one if none if provided.

Return type:

tuple[ViewLayoutProxy, Proxy]

Returns:

  • layout (ViewLayoutProxy) – The layout object used for the plot.

  • render_view (RenderViewProxy) – The configured 2D render view.

sapphireppplot.mhd.plot_quantity_3d(solution, results_folder, quantity, name, plot_properties, prefix='', value_range=None, log_scale=False, camera_direction=None, show_time=False, save_animation=False, layout=None)

Plot and save visualization of specified physical quantity in 3D.

Parameters:
  • solution (SourceProxy) – The simulation or computation result containing the data to plot.

  • results_folder (str) – Path to the folder where results (images/animations) will be saved.

  • quantity (str) – The physical quantity to plot.

  • plot_properties (PlotPropertiesMHD) – Properties for plotting.

  • name (str) – Name of the layout and image/animation files.

  • prefix (str) – Prefix for quantity name.

  • value_range (Optional[tuple[float, float]]) – Minimal (value_range[0]) and maximal (value_range[1]) value for the y-axes.

  • log_scale (bool) – Use a logarithmic color scale?

  • camera_direction (Optional[list[float]]) – Direction of the camera.

  • show_time (bool) – Display the simulation time in the render view.

  • save_animation (bool) – Save an animation of the plot.

  • layout (Optional[ViewLayoutProxy]) – The layout object where the plot should be added as new view. Will create a new one if none if provided.

Return type:

tuple[ViewLayoutProxy, Proxy]

Returns:

  • layout (ViewLayoutProxy) – The layout object used for the plot.

  • render_view (RenderViewProxy) – The configured 3D render view.

sapphireppplot.mhd.plot_quantities_over_x(solution, results_folder, quantities, name, plot_properties, direction='x', offset=None, x_axes_scale=None, x_label=None, x_range=None, value_range=None, log_x_scale=False, log_y_scale=False, show_time=False, save_animation=False, layout=None)

Take and plot slice along a spatial dimension of the solution.

Parameters:
  • solution (SourceProxy) – The simulation or computation result containing the data to plot.

  • results_folder (str) – Path to the folder where results (images/animations) will be saved.

  • quantities (Sequence[str]) – List of physical quantity to plot.

  • name (str) – Name of the layout and image/animation files.

  • plot_properties (PlotPropertiesMHD) – Properties for plotting.

  • direction (Union[Literal['x', 'y', 'z', 'd'], tuple[tuple[float, float, float], tuple[float, float, float]]]) – Direction of the line.

  • offset (Optional[tuple[float, float, float]]) – Offset of the line.

  • x_axes_scale (Optional[float]) – Divide the x-axes coordinate by this scale.

  • x_label (Optional[str]) – Label for the bottom axis of the chart.

  • x_range (Optional[tuple[float, float]]) – Minimal (x_range[0]) and maximal (x_range[1]) value for the x-axes.

  • value_range (Optional[tuple[float, float]]) – Minimal (value_range[0]) and maximal (value_range[1]) value for the y-axes.

  • log_x_scale (bool) – Use a logarithmic x-scale?

  • log_y_scale (bool) – Use a logarithmic y-scale?

  • show_time (bool) – Display the simulation time in the line chart view view.

  • save_animation (bool) – Save an animation of the plot.

  • layout (Optional[ViewLayoutProxy]) – The layout object where the plot should be added as new view. Will create a new one if none if provided.

Return type:

tuple[SourceProxy, ViewLayoutProxy, Proxy]

Returns:

  • plot_over_line_x (SourceProxy) – The PlotOverLine source.

  • layout (ViewLayoutProxy) – The layout object used for the plot.

  • line_chart_view (XYChartViewProxy) – The configured XY chart view.

sapphireppplot.mhd.plot_integrated_quantities_over_time(solution, results_folder, quantities, name, plot_properties_in, t_axes_scale=None, t_label='$t$', t_range=None, value_range=None, log_x_scale=False, log_y_scale=False, layout=None)

Integrate quantities over the grid and plot over time.

The integrated quantities are divided by the grid volume/area.

Parameters:
  • solution (SourceProxy) – The simulation or computation result containing the data to plot.

  • results_folder (str) – Path to the folder where results (images/animations) will be saved.

  • quantities (Sequence[str]) – List of physical quantity to plot.

  • name (str) – Name of the layout and image/animation files.

  • plot_properties – Properties for plotting.

  • t_axes_scale (Optional[float]) – Divide the time-axes by this scale. The scaled axes will be stored in a variable scaled_t_axes.

  • t_label (str) – Label for the bottom axis of the chart.

  • t_range (Optional[tuple[float, float]]) – Minimal (t_range[0]) and maximal (t_range[1]) value for the t-axes.

  • value_range (Optional[tuple[float, float]]) – Minimal (value_range[0]) and maximal (value_range[1]) value for the y-axes.

  • log_t_scale – Use a logarithmic t-scale?

  • log_y_scale (bool) – Use a logarithmic y-scale?

  • layout (Optional[ViewLayoutProxy]) – The layout object where the plot should be added as new view. Will create a new one if none if provided.

Return type:

tuple[SourceProxy, ViewLayoutProxy, Proxy, PlotPropertiesMHD]

Returns:

  • solution_integrated (SourceProxy) – The PlotOverTime source.of the integrated variables.

  • layout (ViewLayoutProxy) – The layout object used for the plot.

  • line_chart_view (XYChartViewProxy) – The configured XY chart view.

  • plot_properties (PlotPropertiesMHD) – The PlotProperties for PlotOverTime.

sapphireppplot.mhd.extract_slices_from_3d(solution, animation_scene, results_folder, plot_properties, origin=(0.0, 0.0, 0.0), subfolder='extracts', frame_window=None)

Create and save slices of x-y, x-z and y-z planes from a 3D solution.

Note, this function is expensive as it iterates over all time steps. Note, sets the animation time to the last time step.

Parameters:
  • solution (SourceProxy) – The data source.

  • animation_scene (Proxy) – The ParaView AnimationScene.

  • results_folder (str) – The parent directory path where the extracts will be saved.

  • plot_properties (PlotPropertiesMHD) – Properties of the solution.

  • origin (tuple[float, float, float]) – Origin of the planes.

  • subfolder (str) – The subfolder to save the extracts.

  • frame_window (Optional[tuple[int, int]]) – The range of timesteps to extract.

Return type:

tuple[SourceProxy, SourceProxy, SourceProxy]

Returns:

  • slice_plane_xy (SourceProxy) – The 2D slice of x-y plane.

  • slice_plane_xz (SourceProxy) – The 2D slice of x-z plane.

  • slice_plane_yz (SourceProxy) – The 2D slice of y-z plane.

See also

sapphireppplot.transform.slice_plane

Slice 2D planes form 3D solution.

sapphireppplot.transform.create_extractor

Create extractor for slice.

sapphireppplot.transform.save_extracts

Save extracts.