MBsysPy.mbsyspy.mbs_results module

Module to handle results from MBS analysis.

Summary

Define the class MbsResults dedicated to load the MbsBuffer C structure. Such structures contains the result of the multibody analysis, except for modal analysis.

The module internal class ‘_buffer_ids’ must be updated to be coherent with the enumeration in the file “mbs_buffer.h”. Currently only the value of ‘BUFFER_Q’ is used.

class MBsysPy.mbsyspy.mbs_results.MbsResult(mbs=None, prj_path=None)

Bases: object

Class containing results of multibody analysis (except for modal analysis).

Each attribute are accessible via the properties. This allows to raise a warning instead of an exception if trying to access an unloaded field.

The user-defined outputs (vector or floats) are stored in a dictionary winch is the attribute ‘outputs’.

The class is overloaded by equilibrium analysis to add it specific informations that are not given by the buffers and files.

Variables
  • _q (numpy.ndarray) – Array containing the history of the generalized coordinates.

  • _qd (numpy.ndarray) – Array containing the history of the generalized velocities.

  • _qdd (numpy.ndarray) – Array containing the history of the generalized accelerations.

  • _Lambda (numpy.ndarray) – Array containing the history of the lagrange multipliers related to the constraints.

  • prj_path (str) – Path of the project folder. This is required if the results must be loaded from files instead of loading from the buffers.

  • _Fl (numpy.ndarray) – Array containing the history of the forces in each links.

  • outputs (dict) – Dict containing the names (as key) and the history (as value) of the user outputs. Each history is a numpy.ndarray with first column being the time.

  • _Qa (numpy.ndarray) – Array containing the history of the actuation force (or torque) in each articulations, the value for non-articulated joints is always 0. This field is only relevant for inverse dynamic.

  • _Qc (numpy.ndarray) – Array containing the history of the force introduced in driven joints to respect the user-specified trajectory (position, velocity, acceleration). The values for non-driven joints is always 0.

  • _Qq (numpy.ndarray) – Array containing the history of the joint forces.

  • _t (numpy.ndarray) – Array containing the time vector.

  • _ux (numpy.ndarray) – Array containing the history of the user variables.

  • _uxd (numpy.ndarray) – Array containing the history of the time derivative of the user variables.

  • _Z (numpy.ndarray) – Array containing the history of the lenght of each link.

  • _Zd (numpy.ndarray) – Array containing the history of the speed (spreading) of each link.

  • _x (numpy.ndarray) – Array containing the equil. module history of the equilibrium variables.

  • _F (numpy.ndarray) – Array containing the equil. module history of the residual force on each equilibrium variable.

  • _R (numpy.ndarray) – Array containing the equil. module history of residual force.

Notes

The module internal class ‘_buffer_ids’ must be updated to be coherent with the enumeration in the file “mbs_buffer.h”

Parameters
  • prj_path (str, optional) – The path to the project directory. It can be omitted if mbs is provided. The default is None.

  • mbs (MBsysPy.MbsData, optional) – The multibody system related to the results to be loaded. Only the project path will be read from this instance. If it is not provided, prj_path must be provided. The default is None.

Raises

ValueError : – Exception raided if both mbs and prj_path are None.

Attributes
F

Array containing the history of the residual force on equilibrium variables (read only).

Fl

Array containing the history of the forces in each links (read-only).

Lambda

Array containing the history of the lagrange multipliers related to the constraints (read-only).

Qa

Array containing the history of the actuation force (or torque) in each articulations (read only).

Qc

Array containing the history of the force introduced in driven joints (read only).

Qq

Array containing the history of the user joint forces (read-only).

R

Array containing the history of the equilibrium residual (read only).

Z

Array containing the history of the lenght of each link (read only).

Zd

Array containing the history of the speed (spreading) of each link (read only).

q

Array containing the history of the generalized coordinates (read-only).

qd

Array containing the history of the generalized velocities (read-only).

qdd

Array containing the history of the generalized accelerations (read-only).

t

Array containing the time vector (read-only).

ux

Array containing the history of the user variables (read only).

uxd

Array containing the history of the time derivative of the user variables (read only).

x

Array containing the history of the equilibrium variables (read only).

Methods

clear(self)

Reset all data fields to None.

load_results_from_buffer(self, c_ptr[, t0, …])

Load the results from the buffer if completely available.

load_results_from_file(self, filename[, …])

Load the results from the files.

set_buffer(self, buf_id, buf_array[, name])

Set the buffer array in the field corresponding the the buffer id.

set_time_from_array(self, array)

If the time array is not yet defined, fill it from the provided.

property F

Array containing the history of the residual force on equilibrium variables (read only).

This results is specific to equilibrium analysis.

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property Fl

Array containing the history of the forces in each links (read-only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property Lambda

Array containing the history of the lagrange multipliers related to the constraints (read-only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property Qa

Array containing the history of the actuation force (or torque) in each articulations (read only).

The value for non-articulated joints is always 0.

This field is only relevant for inverse dynamic.

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property Qc

Array containing the history of the force introduced in driven joints (read only).

The force introduced is required to respect the user-specified trajectory (position, velocity, acceleration). The values for non-driven joints is always 0.

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property Qq

Array containing the history of the user joint forces (read-only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property R

Array containing the history of the equilibrium residual (read only).

This results is specific to equilibrium analysis.

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property Z

Array containing the history of the lenght of each link (read only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property Zd

Array containing the history of the speed (spreading) of each link (read only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

__init__(self, mbs=None, prj_path=None)

Initialize the fields to None.

clear(self)

Reset all data fields to None.

load_results_from_buffer(self, c_ptr, t0=None, resfilename='')

Load the results from the buffer if completely available.

Parameters
  • c_ptr (ctypes.POINTER to either MbsDirdyn_c or MbsSolvekin_c or MbsInvdyn_c) – Pointer to the c-structure of the current module. The module must contain the fields ‘buffers’ (MbsBuffer**), ‘bufferNb’ (int) and ‘user_buffer’ (MbsGrowingBuffer*).

  • t0 (float, optional) – Initial time (if relevant) of the analysis. If the initial time in the buffer does not match the provided value, the buffer are not loaded. If the value is None, then the buffers are loaded whatever the available timesteps. The default is None.

  • resfilename (str, optional) – The option of ‘resfilename’ of the module, this variable is only used to create the user output vectors name from the user filename. The default is ‘’ (empty str).

Returns

True if the whole analysis was loaded from the buffers. False if nothing was loaded from the buffers in case of incomplete or invalid buffers.

Return type

bool

Notes

Usually the first buffer is dedicated to generalized coordinates. At the exception of equilibrium analysis, where it is the fourth buffer. Even if equilibrium analysis is not (yet) handled by this function the loading iterates on the buffers until finding the one dedicated to generalized coordinates.

The buffer of the generalized coordinates is used to check if the full simulation is available in the buffer.

load_results_from_file(self, filename, result_path='resultsR', module=0, user_output=None, user_vector=None)

Load the results from the files.

This function is called if the buffers do not contain the full simulation.

Parameters
  • filename (str) – The filename of the results to load. It is either the base filename (without the suffix and extension) or the name of a file containing basic buffers (ie: q, qd, qdd…) to be loaded. In the second case the suffix and extension will be stripped to retrieve the basefilename. It can contain the full path to files, but it will be ignored.

  • result_path (str, optional) – The relative path of the result folder from the project folder. The default is “resultsR”.

  • user_output (list) – List containing the user output files to be loaded if not None. default is None.

  • user_vector (list) – List containing the user vector output files to be loaded if not None. default is None.

Returns

False if the result path was not located.

Return type

bool

property q

Array containing the history of the generalized coordinates (read-only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property qd

Array containing the history of the generalized velocities (read-only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property qdd

Array containing the history of the generalized accelerations (read-only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

set_buffer(self, buf_id, buf_array, name=None)

Set the buffer array in the field corresponding the the buffer id.

Parameters
  • buf_id (int) – Value of the buffer id to be set. Buffer id are defined in the _buffer_ids class.

  • buf_array (numpy.ndarray) – Array with the history of the variable stored in the specified buffer.

  • name (str, optionnal) – Name of the user buffer to be set, ignored for other buffer.

Returns

True if success, False otherwise.

Return type

bool

set_time_from_array(self, array)

If the time array is not yet defined, fill it from the provided.

Parameters

array (np.ndarray) – Any array of results whose first col is the time array.

Returns

Return type

None.

property t

Array containing the time vector (read-only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property ux

Array containing the history of the user variables (read only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property uxd

Array containing the history of the time derivative of the user variables (read only).

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.

property x

Array containing the history of the equilibrium variables (read only).

This results is specific to equilibrium analysis.

Return an empty array if no results are set in memory.

Raises

UserWarning – Exception raised when no results has been loaded.