MBsysPy.mbsyspy.mbs_equil module

Module to handle equilibrium analysis on Multibody systems.

Summary

Define the class MbsEquil based on the MbsEquil structure of MBsysC.This class has the functions required to manipulate the equilibrium module. This includes setting the options, running an(or multiple) analysis and freeing the memory.

class MBsysPy.mbsyspy.mbs_equil.MbsEquil(mbs, user_path=None, symbolic_path=None)

Bases: object

Class of the Equilibrium(static or quasi - static) module.

Variables

results (MbsResult) – Instance of MbsResult(dedicated to equilibrium module) containing the results of the numerical analysis.

Examples

>>> mbs_data = MBsysPy.MbsData("../dataR/ExampleProject.mbs")
>>> mbs_equil = MBsysPy.MbsEquil(mbs_data)
>>> mbs_equil.set_options(equitol = 1e - 4)
>>> mbs_equil.get_options(equitol)
    0.0001
>>> results = mbs_equil.run()
Attributes
mbs_filename

Access to self.mbs.mbs_filename (read-only).

mbs_name

Access to self.mbs.mbs_name (read-only).

nx

Access to nx attribute (read-only).

project_path

Access to self.mbs.project_path (read-only).

success

Access to success attribute (read-only).

Methods

add_exchange(self, ptr, index, exchange_var_id)

Add a new equilibrium variable that will replace the specified one.

add_exchange_um(self, user_model, param, …)

Add a user model as a new equilibrium variable that replaces the specified one.

add_extra_variable(self, ptr, index[, ptr_name])

Add a new equilibrium variable.

add_extra_variable_um(self, user_model, param)

Add a user model as new equilibrium variable.

add_to_results(self)

Add specific field for equilibrium analysis o the results.

get_options(self, *args)

Get the specified options for Equil module.

print_equil(self)

mbs_msg the results of the equilibrium analysis from C library.

replace_exchange(self, ptr, index, id_exchanged)

Replace an existing exchanged variable with another one.

replace_exchange_um(self, user_model, param, …)

Replace an existing exchanged variable with a user model.

replace_extra_variable(self, ptr, index, …)

Replace an existing extra variable with another one.

replace_extra_variable_um(self, user_model, …)

Replace an existing extra variable with a user model.

run(self, **kwargs)

Run a equilibrium analysis.

set_options(self, **kwargs)

Set the specified options for Equil module.

set_user_fct_from_file(self, function_name, …)

Load a user function from a file chosen by the user instead of the default one in the userfctR folder.

set_user_fct_from_ptr(self, function_name, …)

Load a user function chosen by the user instead of the default one in the userfctR folder.

add_exchange(self, ptr, index, exchange_var_id, ptr_name=None)

Add a new equilibrium variable that will replace the specified one.

Exchanged variables are stored and will be set in the memory of the external library when ‘MbsEquil::run()’ is called. Between two run() the equilibrium can be modified thanks to replace(). However as the number of equilibrium variables is locked in the external memory after the first call of run(), this function can not be called between two run().

Parameters
  • ptr (ndarray) – Array containing the new equilibrium variable to be used.

  • index (int) – Index in ‘ptr’ of the new equilibrium variable to be used.

  • exchange_var_id (int) – Index of the joint (in MbsData.q) that will be replaced by ‘ptr[index]’.

  • ptr_name (str, optional) – Name of the variable to be exchanged. If not set a generic name will be assigned.

add_exchange_um(self, user_model, param, replaced_var_id)

Add a user model as a new equilibrium variable that replaces the specified one.

Exchanged variables are stored and will be set in the memory of the external library when ‘MbsEquil::run()’ is called. Between two run() the equilibrium can be modified thanks to replace(). However as the number of equilibrium variables is locked in the external memory after the first call of run(), this function can not be called between two run().

Parameters
  • user_model (str) – Name of the user model to be exchanged

  • param (str) – Parameter of the user model to be exchanged

  • replaced_var_id (int) – Index of the default variable that will be replaced

add_extra_variable(self, ptr, index, ptr_name=None)

Add a new equilibrium variable.

Extra variables are stored and will be set in the memory of the external library when ‘MbsEquil::run()’ is called. Between two run() the equilibrium can be modified thanks to replace(). However as the number of equilibrium variables is locked in the external memory after the first call of run(), this function can not be called between two run().

Parameters
  • ptr (ndarray) – Array containing the extra variable to add to the equilibrium variables

  • index (int) – Index in ptr of the extra variable to add to the equilibrium variables

  • ptr_name (str) – Name of the extra variable, if not set a default name will be given.

add_extra_variable_um(self, user_model, param)

Add a user model as new equilibrium variable.

Extra variables are stored and will be set in the memory of the external library when ‘MbsEquil::run()’ is called. Between two run() the equilibrium can be modified thanks to replace(). However as the number of equilibrium variables is locked in the external memory after the first call of run(), this function can not be called between two run().

Parameters
  • user_model (str) – Name of the user model to add to the equilibrium variables

  • param (str) – Parameter of the user model to add to the equilibrium variables

add_to_results(self)

Add specific field for equilibrium analysis o the results.

The fields below are added.

typestr

The type of equilibrium executed.

nquchint

The number of changed independant variables.

nxeint

The number of extra equilibrium variables.

nxint

The number of variables for the equilibrium.

x_namelist of str

List of the name given to each equilibrium variable. When not specified independant generalized coordinates are denoted with “q#” and if computed user derivative with “ux#”.

sucessstr

Indicates if the equilibrium procedure success or not.

get_options(self, *args)

Get the specified options for Equil module.

Parameters

The different options specified in the documentation of set_options

Returns

Return type

The value of the different options specified in the documentation of set_options

property mbs_filename

Access to self.mbs.mbs_filename (read-only).

property mbs_name

Access to self.mbs.mbs_name (read-only).

property nx

Access to nx attribute (read-only).

print_equil(self)

mbs_msg the results of the equilibrium analysis from C library.

property project_path

Access to self.mbs.project_path (read-only).

replace_exchange(self, ptr, index, id_exchanged, ptr_name=None)

Replace an existing exchanged variable with another one.

This function can be called between two ‘MbsEquil::run()’ as it does not change the number of equilibrium variables.

Parameters
  • ptr (ndarray) – Array containing the variable to be exchanged.

  • index (int) – Index in ‘ptr’ of the variable to be exchanged.

  • id_exchanged (int) – Index in the list of exchanged variable of the variable to be replaced.

  • ptr_name (str, optional) – Name of the variable to be exchanged. If set to None the existing name is kept. The default is None.

replace_exchange_um(self, user_model, param, id_exchanged)

Replace an existing exchanged variable with a user model.

This function can be called between two ‘MbsEquil::run()’ as it does not change the number of equilibrium variables.

The name of the exchanged equilibrium variable is replaced by ‘user_model.param’.

Parameters
  • user_model (str) – Name of the user model containing the parameter to be exchanged.

  • param (str) – Parameter of the user model to be exchanged.

  • id_exchanged (int) – Index in the list of exchanged variable of the variable to be replaced.

replace_extra_variable(self, ptr, index, id_extra, ptr_name=None)

Replace an existing extra variable with another one.

This function can be called between two ‘MbsEquil::run()’ as it does not change the number of equilibrium variables.

Parameters
  • ptr (ndarray) – Array containing the extra variable to be exchanged.

  • index (int) – Index in ‘ptr’ of the extra variable to be exchanged.

  • id_extra (int) – Index in the list of extra variable of the variable to be replaced.

  • ptr_name (str, optional) – Name of the variable to be exchanged. If set to None the existing name is kept. The default is None.

replace_extra_variable_um(self, user_model, param, id_extra)

Replace an existing extra variable with a user model.

This function can be called between two ‘MbsEquil::run()’ as it does not change the number of equilibrium variables.

The name of the extra equilibrium variable is replaced by ‘user_model.param’.

Parameters
  • user_model (str) – Name of the user model containing the parameter to be exchanged.

  • param (str) – Parameter of the user model to be exchanged.

  • id_extra (int) – Index in the list of extra variable of the variable to be replaced.

run(self, **kwargs)

Run a equilibrium analysis.

Options can be set with the function ‘set_options()’ before calling this function. Options can be retrieved with the function ‘get_options()’.

Returns

self.results – The MbsResults containing the results of the analysis.

Return type

MbsResult

set_options(self, **kwargs)

Set the specified options for Equil module.

Parameters
  • method (int) – fsolvepk = 1 / optim = 2 default = 1

  • equitol (float) – equilibrium acceptation tolerance default = 1e - 6

  • verbose (int) – no = 0, yes = 1 default = 1

  • save2file (int) – 1: results saved, 0: not saved default = 1

  • compute_uxd (int) – no = 0, yes = 1 flag to compute the extra constitutive differential equations as equil equations default = 1

  • grad_lpk (int) – options to compute the gradient through the lpk parabolic fitting method. If not activated, the gradient is computed by small deviation with options devJac default = 0

  • lpk_itermax (int) – options for the lpk gradient default = 10

  • lpk_relincr (float) – options for the lpk gradient default = 1e - 2

  • lpk_absincr (float) – options for the lpk gradient default = 1e - 3

  • lpk_absincr_max (float) – options for the lpk gradient default = 1e - 3

  • lpk_equitol (float) – options for the lpk gradient default = 1e - 6

  • lpk_lintol (float) – options for the lpk gradient default = 1e - 3

  • resfilename (char) – The keyword used for determining the name of result files default: equil

  • respath (char) – Path in which result file are saved. default: resultsR folder

  • animpath (char) – Path in which animation file are saved. default: animationR folder

  • buffer_format (str) – The format for saving the data (double) to file. For example set “%.3e” to use scientific notation with 3 decimal. defaut: ‘%e’.

  • mode (int) – 1=static / 2=quasistatic / 3=dynamic default = 0

  • relax (int) – relaxation in pk algorithm no = 0, yes = 1 default = 0

  • relaxcoeff (float) – relaxation coefficient default = 0.9

  • relaxIterMax (float) – maximum number of relaxation iterations default = 10

  • soft (int) – softing in pk algorithm no = 0, yes = 1 default = 0

  • senstol (float) – tolerance for testing a variable non - sensitivity default = 1e - 6

  • devjac (float) – deviate state for Gradient calculation default = 1e - 6

  • itermax (int) – maximum number of iteration for solvepk default = 30

  • visualize (int) – no = 0, yes = 1 default = 0

  • clearmbsglobal (int) – inout = 1, out = 2, none = 3, all = 4 default = 1

  • saveperiod (int) – The number of iteration between two buffer records default = 1(every iteration are recorded)

  • save_anim (int) – 1 to save the anim file 0 otherwise(only valid if ‘save2file’ is set to 1)

  • framerate (int) – number of frame per second for the .anim file

  • buffersize (int) – The number of time step that can be recorded in the buffer default = - 1

  • max_save_user (int) – The maximal number of user variables saved default = 12

  • store_results (int) – If set to 1, a copy of the results is done. default is 1

set_user_fct_from_file(self, function_name, user_path, user_file)

Load a user function from a file chosen by the user instead of the default one in the userfctR folder.

The function is then unassigned by the module at the end of the run().

Parameters
  • function_name (str) – name of the user function to replace.

  • user_path (str) – path to the new user function file.

  • user_file (str) – name of the new user function file.

set_user_fct_from_ptr(self, function_name, user_fct_ptr)

Load a user function chosen by the user instead of the default one in the userfctR folder.

The function is then unassigned by the module at the end of the run().

Parameters
  • function_name (str) – name of the user function to replace.

  • user_fct_ptr (ptr) – new user function pointer.

property success

Access to success attribute (read-only).