Commit c264048e authored by Olivier Lantsoght's avatar Olivier Lantsoght
Browse files

[MBsysPy][Equil][Doc] Some fix related to #253

parent 440d58ed
......@@ -300,9 +300,8 @@ class MbsEquil(object):
"""
self.mbs.__set_user_fct_from_ptr__(function_name, user_fct_ptr)
def add_exchange(self, ptr, index, replaced_var_id, ptr_name="??"):
"""
Add a new equilibrium variable that replaces the specified one.
def 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()
......@@ -314,31 +313,40 @@ class MbsEquil(object):
Parameters
----------
ptr: ndarray
Array containing the variable to be exchanged
Array containing the new equilibrium variable to be used.
index: int
Index in ptr of the variable to be exchanged
replaced_var_id: int
Index of the default variable that will be replaced
ptr_name: str
(optionnal) Name of the variable to be exchanged
Index in 'ptr' of the new equilibrium variable to be used.
exchange_var_id: int
Index of the default equilibrium variable that will be replaced by
'ptr[index]'.
ptr_name: str, optionnal
Name of the variable to be exchanged.
If not set a generic name will be assigned.
"""
if self.get_options("nquch"):
mbs_msg("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()")
mbs_msg("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()")
if index > np.size(ptr) - 1:
mbs_msg(">>EQUIL>> variable exchange: Index out of bound")
return
address = ptr.ctypes.data + ctypes.sizeof(ctypes.c_double) * index
if ptr.ctypes.data == self.mbs.q.ctypes.data:
mbs_msg(">>EQUIL>> variable exchange: Warning ! Generalized coordinates have to be used with caution as exchange variables")
mbs_msg(">>EQUIL>> variable exchange: Warning ! Generalized coordinates "
"have to be used with caution as exchange variables")
if not ptr_name:
ptr_name = "exchange_{:d}".format(len(self.exchange_list) + 1)
if len(self.exchange_list) == 0:
self.exchange_list = [[address, replaced_var_id, ptr_name]]
if not ptr_name:
self.exchange_list = [[address, exchange_var_id, ptr_name]]
else:
for element in self.exchange_list:
if element[0] == address:
mbs_msg(">>EQUIL>> variable exchange: Exchange variable is already an equilibrium variable")
else:
self.exchange_list.append([address, replaced_var_id, ptr_name])
self.exchange_list.append([address, exchange_var_id, ptr_name])
return
def add_extra_variable(self, ptr, index, ptr_name=None):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment