Muscat.IO.RstReader module

rst based Ansys mesh and result reader.

This module provides the RstReader class and the ReadRst() helper function to read meshes and solution fields (nodal, elemental and elemental-nodal) from an Ansys .rst result file. The reading relies on the ansys-dpf-core and ansys-dpf-post packages and returns a Muscat Mesh instance.

CheckIntegrity(GUI: bool = False) str[source]

Check the integrity of the RstReader module.

Parameters:

GUI (bool, optional) – Whether to run the check in GUI mode, by default False.

Returns:

"ok" if the check succeeds, or a "skip: ..." message when the Ansys dependencies are not available.

Return type:

str

ReadRst(fileName: str, time: float64 | None = None, timeIndex: int64 | None = None, fromElementalNodalToNodal: bool = True, dimensionality: int | List[int] | None = None) Mesh[source]

Read the mesh and solution fields (nodal, elemental and elemental-nodal) from a rst file.

Parameters:
  • fileName (str) – Name of the file to be read.

  • time (MuscatFloat, optional) – Time at which the fields are read, by default None.

  • timeIndex (MuscatIndex, optional) – Time index at which the fields are read, by default None.

  • fromElementalNodalToNodal (bool, optional) – If True, elemental-nodal fields are averaged at the nodes, by default True.

Returns:

Output Mesh object containing the results.

Return type:

Mesh

class Results(name: str, operator_name: str, native_location: str, n_components: int)[source]

Bases: object

Lightweight description of an available result of an rst file.

name

Name of the result.

Type:

str

operator_name

Name of the DPF operator producing the result.

Type:

str

native_location

Native location of the result ("Nodal", "Elemental" or "ElementalNodal").

Type:

str

n_components

Number of components of the result.

Type:

int

n_components
name
native_location
operator_name
class RstReader[source]

Bases: ReaderBase

Reader for Ansys .rst result files.

This class reads the mesh and the available solution fields stored in an Ansys .rst file, supporting nodal, elemental and elemental-nodal fields as well as temporal and modal simulations.

GetAvailablePostResults() List[str][source]

Return the available post-processing results of the simulation.

Returns:

Names of the callable post-processing results exposed by the ansys-dpf-post simulation object.

Return type:

list

Raises:

ModuleNotFoundError – If ansys-dpf-post is not installed.

GetAvailableResultsAndOperators() List[Results][source]

Return the available results together with their operator name.

Returns:

List of Results objects exposing the name, operator_name, native_location and n_components attributes.

Return type:

list of Results

GetAvailableTimes() ndarray[source]

Return the available times at which data can be read.

Returns:

Available times at which data can be read.

Return type:

np.ndarray

GetModel() Model[source]

Recover the dpf Model associated with the rst file.

Returns:

The dpf model associated with the file.

Return type:

Model

Raises:
  • RuntimeError – If the fileName has not been set yet.

  • ModuleNotFoundError – If ansys-dpf-core and ansys-dpf-post are not installed.

GetPostResults(post_names: List[str] | None = None, locations: List[str] | None = None) None[source]

Read post-processing results and store them in the output mesh.

Parameters:
  • post_names (list of str, optional) – Names of the post-processing results to read, by default None.

  • locations (list of str, optional) – Location ("nodal" or "elemental") associated with each requested result, by default None.

Raises:

ModuleNotFoundError – If ansys-dpf-post is not installed.

MeshRead() Mesh[source]

Read the mesh stored in the rst file.

Returns:

Mesh containing the reading result.

Return type:

Mesh

Read(time: float64 | None = None, timeIndex: int64 | None = None, fromElementalNodalToNodal: bool = True, dimensionality: int | List[int] | None = None) Mesh[source]

Read the mesh and the fields stored in the rst file.

Parameters:
  • time (MuscatFloat, optional) – Time at which the fields are read, by default None.

  • timeIndex (MuscatIndex, optional) – Time index at which the fields are read, by default None.

  • fromElementalNodalToNodal (bool, optional) – If True, elemental-nodal fields are averaged at the nodes; otherwise they are stored as discontinuous finite element fields, by default True.

  • dimensionality (int or list of int, optional) – Dimensionality (or list of dimensionalities) of the elements on which the elemental-nodal fields (e.g. stress, strain) are read. When None (default), the fields are read on every geometry present in the mesh, whatever its dimensionality. This is important when several geometries of different dimensions (e.g. a solid and a shell) coexist in the same rst file and both carry results.

Returns:

Output Mesh object containing the results.

Return type:

Mesh

Raises:

ModuleNotFoundError – If ansys-dpf-core and ansys-dpf-post are not installed.

ReadField(fieldname: str, time: float64 | None = None, timeIndex: int64 | None = None, fromElementalNodalToNodal: bool = True, dimensionality: int | List[int] | None = None) ndarray | List[FEField] | None[source]

Read a single field from the rst file.

Parameters:
  • fieldname (str) – Name of the field to be read.

  • time (MuscatFloat, optional) – Time at which the field is read, by default None.

  • timeIndex (MuscatIndex, optional) – Time index at which the field is read, by default None.

  • fromElementalNodalToNodal (bool, optional) – For elemental-nodal fields, whether to average the field at the nodes, by default True.

  • dimensionality (int or list of int, optional) – For elemental-nodal fields, the dimensionality (or list of dimensionalities) of the elements on which the field is read. When None (default), the field is read on every geometry present in the mesh, whatever its dimensionality. This is required when several geometries of different dimensions coexist in the same rst file and more than one carries elemental-nodal results.

Returns:

For a nodal or elemental field, a numpy array of the field values. For an elemental-nodal field:

  • if fromElementalNodalToNodal is True (default), a numpy array of the averaged value at the nodes;

  • if fromElementalNodalToNodal is False, a list of discontinuous finite element fields (one for each component of the field).

None is returned if the field could not be broadcast to the mesh.

Return type:

np.ndarray or list of FEField

Raises:
  • ModuleNotFoundError – If ansys-dpf-core and ansys-dpf-post are not installed.

  • KeyError – If the requested field cannot be found.

ReadMetaData() Dict[source]

Read the metadata of an rst file.

The metadata includes the number of points, the number of elements, the time steps and the available fields. The result is cached in self.meshMetadata and returned on subsequent calls.

Returns:

Dictionary containing the mesh metadata.

Return type:

dict

Reset() None[source]

Reset the reader to its initial state.

SetFileName(fileName: str) None[source]

Set the file to read.

Parameters:

fileName (str) – Path to the simulation file.

SetTimeToRead(time: float64 | None = None, timeIndex: int64 | None = None) int64[source]

Set the time at which the data is read.

Parameters:
  • time (MuscatFloat, optional) – Time at which the data is read, by default None.

  • timeIndex (MuscatIndex, optional) – Time index at which the data is read, by default None.

Returns:

Time index at which the data is read.

Return type:

MuscatIndex

Raises:

ValueError – If both time and timeIndex are specified.