pylbo.visualisation.modes.vtk_export

Classes

VTKDataExporter

Main class to prepare data for export to VTK files.

VTKCartesianData

Main class to prepare data for export to VTK files.

VTKCylindricalData

Main class to prepare data for export to VTK files.

Module Contents

class pylbo.visualisation.modes.vtk_export.VTKDataExporter(data: pylbo.visualisation.modes.mode_data.ModeVisualisationData, u1: numpy.ndarray, u2: numpy.ndarray, u3: numpy.ndarray)[source]

Main class to prepare data for export to VTK files.

Parameters:
  • data (ModeVisualisationData) – The data for the visualisation

  • u1 (np.ndarray) – The 1D \(u_1\) coordinate array.

  • u2 (np.ndarray) – The 1D \(u_2\) coordinate array.

  • u3 (np.ndarray) – The 1D \(u_3\) coordinate array.

_u1

The 1D \(u_1\) coordinates.

Type:

ndarray

_u2

The 1D \(u_2\) coordinates.

Type:

ndarray

_u3

The 1D \(u_3\) coordinates.

Type:

ndarray

u1_data

The 3D \(u_1\) coordinate data.

Type:

ndarray

u2_data

The 3D \(u_2\) coordinate data.

Type:

ndarray

u3_data

The 3D \(u_3\) coordinate data.

Type:

ndarray

dims[source]

The grid dimensions.

Type:

tuple

_vtk_dtype[source]

The VTK data type, defaults to “float”.

Type:

str

_vtk_byte_order[source]

The VTK byte order, defaults to “>” (big endian).

Type:

str

_vtk_fmt[source]

The VTK data format, defaults to “>f”.

Type:

str

data[source]
_vtk_dtype = None[source]
_vtk_byte_order = '>'[source]
_vtk_fmt = None[source]
_pbar = None[source]
dims = None[source]
_set_coordinate_data(u1: numpy.ndarray, u2: numpy.ndarray, u3: numpy.ndarray)[source]

Sets the coordinate data.

Parameters:
  • u1 (np.ndarray) – The 1D \(u_1\) coordinate array.

  • u2 (np.ndarray) – The 1D \(u_2\) coordinate array.

  • u3 (np.ndarray) – The 1D \(u_3\) coordinate array.

abstract get_coordinate_data() tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Returns the coordinate data. This should always return the data in a Cartesian reference frame (u1, u2, u3), so coordinate transformations should be implemented in subclassed if necessary.

Returns:

  • u1_data (ndarray) – The 3D \(u_1\) coordinate data.

  • u2_data (ndarray) – The 3D \(u_2\) coordinate data.

  • u3_data (ndarray) – The 3D \(u_3\) coordinate data.

broadcast_to_3d(array: numpy.ndarray) numpy.ndarray[source]

Broadcasts a 1D array to a 3D array with the same shape as the coordinate data.

Parameters:

array (np.ndarray) – The 1D array to broadcast.

Returns:

The broadcasted array.

Return type:

np.ndarray

get_solution(name: str, time: float) numpy.ndarray[source]

Returns the eigenmode solution for a given time.

Parameters:
  • name (str) – The name of the eigenfunction.

  • time (float) – The time at which to get the solution.

Returns:

The eigenmode solution.

Return type:

np.ndarray

_log_info(msg: str) None[source]

Logs an info message only if the progress bar is inactive.

_validate_and_set_dtype(dtype: str) None[source]

Validates and sets the VTK data type.

Parameters:

dtype (str) – The VTK data type. Valid values are “float32” and “float64”.

Raises:

ValueError – If the VTK data type is not valid.

_write_vtk_header(vtkfile)[source]

Writes the VTK file header. This includes the VTK file version, the data type, the grid dimensions and the number of points.

Parameters:

vtkfile (str) – The name of the VTK file to write to.

_write_vtk_coordinate_data(vtkfile)[source]

Writes the VTK grid coordinates.

Parameters:

vtkfile (str) – The name of the VTK file to write to.

_write_vtk_point_data_start(vtkfile)[source]

Writes the VTK point data start marker, i.e. the ‘POINT_DATA’ statement and the number of points.

Parameters:

vtkfile (str) – The name of the VTK file to write to.

_write_vtk_scalar_field(vtkfile, fieldname, fielddata)[source]

Writes a 3D VTK scalar field with a given fieldname. If fielddata is smaller than 1e-12 everywhere the field is not written to the VTK file.

Parameters:
  • vtkfile (str) – The name of the VTK file to write to.

  • fieldname (str) – The name of the field.

  • fielddata (ndarray) – The field data.

_write_vtk_auxiliary_coordinates(vtkfile)[source]

Writes auxiliary coordinate data to the VTK file, for example the theta values in cylindrical geometry. These are needed for appropriate transformations to draw vector fields in e.g. ParaView.

Parameters:

vtkfile (str) – The name of the VTK file to write to.

export_to_vtk(filename: str, time: float | numpy.ndarray, names: str | list[str] = None, bg_names: str | list[str] = None, dtype: str = 'float32', starting_index: int = 0) None[source]

Exports the mode solution to a VTK file.

Parameters:
  • filename (str) – The name of the VTK file to write to.

  • time (Union[float, np.ndarray]) – The time(s) at which to export the mode solution.

  • names (Union[str, list[str]], optional) – The name(s) of the mode(s) to export.

  • bg_names (Union[str, list[str]], optional) – The name(s) of the equilibrium background(s) to export.

  • dtype (str, optional) – The VTK data type, defaults to “float32” (32 bit floating point). Can be set to “float64” (64 bit floating point) but uses more memory.

  • starting_index (int, optional) – The starting index for filenames, defaults to 0.

class pylbo.visualisation.modes.vtk_export.VTKCartesianData(data: pylbo.visualisation.modes.mode_data.ModeVisualisationData, u2: numpy.ndarray, u3: numpy.ndarray)[source]

Bases: VTKDataExporter

Main class to prepare data for export to VTK files.

Parameters:
  • data (ModeVisualisationData) – The data for the visualisation

  • u1 (np.ndarray) – The 1D \(u_1\) coordinate array.

  • u2 (np.ndarray) – The 1D \(u_2\) coordinate array.

  • u3 (np.ndarray) – The 1D \(u_3\) coordinate array.

_u1

The 1D \(u_1\) coordinates.

Type:

ndarray

_u2

The 1D \(u_2\) coordinates.

Type:

ndarray

_u3

The 1D \(u_3\) coordinates.

Type:

ndarray

u1_data

The 3D \(u_1\) coordinate data.

Type:

ndarray

u2_data

The 3D \(u_2\) coordinate data.

Type:

ndarray

u3_data

The 3D \(u_3\) coordinate data.

Type:

ndarray

dims[source]

The grid dimensions.

Type:

tuple

_vtk_dtype[source]

The VTK data type, defaults to “float”.

Type:

str

_vtk_byte_order[source]

The VTK byte order, defaults to “>” (big endian).

Type:

str

_vtk_fmt[source]

The VTK data format, defaults to “>f”.

Type:

str

get_coordinate_data() tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Returns the coordinate data. This should always return the data in a Cartesian reference frame (u1, u2, u3), so coordinate transformations should be implemented in subclassed if necessary.

Returns:

  • u1_data (ndarray) – The 3D \(u_1\) coordinate data.

  • u2_data (ndarray) – The 3D \(u_2\) coordinate data.

  • u3_data (ndarray) – The 3D \(u_3\) coordinate data.

class pylbo.visualisation.modes.vtk_export.VTKCylindricalData(data: pylbo.visualisation.modes.mode_data.ModeVisualisationData, u2: numpy.ndarray, u3: numpy.ndarray)[source]

Bases: VTKDataExporter

Main class to prepare data for export to VTK files.

Parameters:
  • data (ModeVisualisationData) – The data for the visualisation

  • u1 (np.ndarray) – The 1D \(u_1\) coordinate array.

  • u2 (np.ndarray) – The 1D \(u_2\) coordinate array.

  • u3 (np.ndarray) – The 1D \(u_3\) coordinate array.

_u1

The 1D \(u_1\) coordinates.

Type:

ndarray

_u2

The 1D \(u_2\) coordinates.

Type:

ndarray

_u3

The 1D \(u_3\) coordinates.

Type:

ndarray

u1_data

The 3D \(u_1\) coordinate data.

Type:

ndarray

u2_data

The 3D \(u_2\) coordinate data.

Type:

ndarray

u3_data

The 3D \(u_3\) coordinate data.

Type:

ndarray

dims[source]

The grid dimensions.

Type:

tuple

_vtk_dtype[source]

The VTK data type, defaults to “float”.

Type:

str

_vtk_byte_order[source]

The VTK byte order, defaults to “>” (big endian).

Type:

str

_vtk_fmt[source]

The VTK data format, defaults to “>f”.

Type:

str

get_coordinate_data() tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Returns the coordinate data. This should always return the data in a Cartesian reference frame (u1, u2, u3), so coordinate transformations should be implemented in subclassed if necessary.

Returns:

  • u1_data (ndarray) – The 3D \(u_1\) coordinate data.

  • u2_data (ndarray) – The 3D \(u_2\) coordinate data.

  • u3_data (ndarray) – The 3D \(u_3\) coordinate data.

_write_vtk_auxiliary_coordinates(vtkfile)[source]

Writes auxiliary coordinate data to the VTK file, for example the theta values in cylindrical geometry. These are needed for appropriate transformations to draw vector fields in e.g. ParaView.

Parameters:

vtkfile (str) – The name of the VTK file to write to.