Commit 69622a9b authored by Louis Beauloye's avatar Louis Beauloye
Browse files

change if else for MbsPart in assign

parent 7dfcfc7e
......@@ -1030,8 +1030,8 @@ class MbsData(object):
else:
print(fun + " is not an existing symbolic function")
else:
print('The "functions" parameter must be a list and not a ' + str(type(functions)))
else:
print('The "functions" parameter must be a list and not a ' + str(type(functions)))
def __unassign_user_fct_2__(self, functions):
......@@ -1101,14 +1101,12 @@ class MbsData(object):
if fun == "cons_hJ":
# cons_hJ
if mbs_module is not None:
if mbs_module.name == "MbsDirdyn" or mbs_module.name == "MbsEquil":
self.ptrs_to_user_fcts["user_cons_hJ"] = user_cons_hJ_wrap(lambda h, Jac, mbs, tsim: self.user_cons_hJ(mbs_module._huserc, mbs_module._Juserc, self, tsim))
self.mbs_data_ptr.contents.user_cons_hJ = self.ptrs_to_user_fcts["user_cons_hJ"]
elif mbs_module.name == "MbsPart":
if isinstance(mbs_module, MbsPart):
self.ptrs_to_user_fcts["user_cons_hJ"] = user_cons_hJ_wrap(lambda h, Jac, mbs, tsim: self.__callback_user_cons_hJ_part(self.user_cons_hJ, h, Jac, tsim))
self.mbs_data_ptr.contents.user_cons_hJ = self.ptrs_to_user_fcts["user_cons_hJ"]
else:
print(mbs_module.name + ' is not a valid module name')
self.ptrs_to_user_fcts["user_cons_hJ"] = user_cons_hJ_wrap(lambda h, Jac, mbs, tsim: self.user_cons_hJ(mbs_module._huserc, mbs_module._Juserc, self, tsim))
self.mbs_data_ptr.contents.user_cons_hJ = self.ptrs_to_user_fcts["user_cons_hJ"]
else:
print(' A module needs to be passed as mbs_module argument')
elif fun == "cons_jdqd":
......@@ -1203,24 +1201,19 @@ class MbsData(object):
elif fun == "cons_hJ":
# mbs_cons_hJ
if mbs_module is not None:
if mbs_module.name == "MbsDirdyn":
self.ptrs_to_symb_fcts["mbs_cons_hJ"] = mbs_cons_hJ_wrap(lambda h, Jac, mbs, tsim: self.mbs_cons_hJ(mbs_module._h, mbs_module._Jac, self))
self.mbs_data_ptr.contents.mbs_cons_hJ = self.ptrs_to_symb_fcts["mbs_cons_hJ"]
elif mbs_module.name == "MbsPart":
if isinstance(mbs_module, MbsPart):
self.ptrs_to_symb_fcts["mbs_cons_hJ"] = mbs_cons_hJ_wrap(lambda h, Jac, mbs, tsim: self.__callback_mbs_cons_hJ_part(self.mbs_cons_hJ, h, Jac))
self.mbs_data_ptr.contents.mbs_cons_hJ = self.ptrs_to_symb_fcts["mbs_cons_hJ"]
else:
print(mbs_module.name + ' is not a valid module name')
self.ptrs_to_symb_fcts["mbs_cons_hJ"] = mbs_cons_hJ_wrap(lambda h, Jac, mbs, tsim: self.mbs_cons_hJ(mbs_module._h, mbs_module._Jac, self))
self.mbs_data_ptr.contents.mbs_cons_hJ = self.ptrs_to_symb_fcts["mbs_cons_hJ"]
else:
print(' A module needs to be passed as mbs_module argument')
elif fun == "cons_jdqd":
# mbs_cons_jdqd
if mbs_module is not None:
if mbs_module.name == "MbsDirdyn":
self.ptrs_to_symb_fcts["mbs_cons_jdqd"] = mbs_cons_jdqd_wrap(lambda jdqd, mbs, tsim: self.mbs_cons_jdqd(mbs_module._jdqd, self))
self.mbs_data_ptr.contents.mbs_cons_jdqd = self.ptrs_to_symb_fcts["mbs_cons_jdqd"]
else:
print(mbs_module.name + ' is not a valid module name')
self.ptrs_to_symb_fcts["mbs_cons_jdqd"] = mbs_cons_jdqd_wrap(lambda jdqd, mbs, tsim: self.mbs_cons_jdqd(mbs_module._jdqd, self))
self.mbs_data_ptr.contents.mbs_cons_jdqd = self.ptrs_to_symb_fcts["mbs_cons_jdqd"]
else:
print(' A module needs to be passed as mbs_module argument')
elif fun == "extforces":
......@@ -1296,19 +1289,16 @@ class MbsData(object):
SWr = fun(__PxF, __RxF, __VxF, __OMxF, __AxF, __OMPxF, self, tsim, ixF)
self.SWr[ixF, 1:7] = SWr[1:7]
def __callback_mbs_sensor(self, fun, sens, isens):
"""Do the callback for gensensor, forcesensor and sensor."""
self.__sens.__reassign_memory__(sens)
fun(self.__sens, self, isens)
def __callback_user_cons_hJ_part(self, fun, h, Jac, tsim):
__h = np.ctypeslib.as_array(h, (self.Nuserc + 1,))
__Jac = np.ctypeslib.as_array(Jac[0], (self.Nuserc + 1, self.njoint + 1))
fun(__h, __Jac, self, tsim)
def __callback_mbs_cons_hJ_part(self, fun, h, Jac):
if __DEBUG__:
print("DEBUG>> callback_mbs_cons_hJ")
......
......@@ -32,16 +32,16 @@ from .._mbsysc_loader.loadlibs import libmodules
from ..mbs_utilities import callback_undefined
# importing function handler
from .._mbs_function_handler import assign_user_fct_to_None
from .._mbs_function_handler import assign_symb_fct_to_None
from .._mbs_function_handler import __unassign_user_fct_2__
from .._mbs_function_handler import __unassign_symb_fct_2__
from .._mbs_function_handler import __assign_user_to_undefined__
from .._mbs_function_handler import __assign_symb_to_undefined__
from .._mbs_function_handler import __load_symbolic_fct_2__
from .._mbs_function_handler import __load_user_fct_2__
from .._mbs_function_handler import __assign_symb_fct_2__
from .._mbs_function_handler import __assign_user_fct_2__
# from .._mbs_function_handler import assign_user_fct_to_None
# from .._mbs_function_handler import assign_symb_fct_to_None
# from .._mbs_function_handler import __unassign_user_fct_2__
# from .._mbs_function_handler import __unassign_symb_fct_2__
# from .._mbs_function_handler import __assign_user_to_undefined__
# from .._mbs_function_handler import __assign_symb_to_undefined__
# from .._mbs_function_handler import __load_symbolic_fct_2__
# from .._mbs_function_handler import __load_user_fct_2__
# from .._mbs_function_handler import __assign_symb_fct_2__
# from .._mbs_function_handler import __assign_user_fct_2__
# importing wrapping function
from .._mbsysc_loader.callback import user_cons_hJ_wrap
......@@ -167,12 +167,12 @@ class MbsDirdyn(object):
'LinkForces', 'Link3DForces', 'dirdyn_init', 'dirdyn_loop', 'dirdyn_finish']
self.symb_fun_list = ['accelred', 'cons_hJ', 'cons_jdqd', 'invdyna', 'dirdyna', 'extforces', 'gensensor',
'link', 'link3D', 'sensor']
assign_user_fct_to_None(self.mbs, self.user_fun_list)
self.mbs.assign_user_fct_to_None(self.user_fun_list)
if self.mbs.opt_load_c < 2:
__assign_user_to_undefined__(self.mbs, self.user_fun_list)
assign_symb_fct_to_None(self.mbs, self.symb_fun_list)
self.mbs.__assign_user_to_undefined__(self.user_fun_list)
self.mbs.assign_symb_fct_to_None(self.symb_fun_list)
if self.mbs.opt_load_c < 1:
__assign_symb_to_undefined__(self.mbs, self.symb_fun_list)
self.mbs.__assign_symb_to_undefined__(self.symb_fun_list)
# self.user_cons_hJ = None
# self.user_cons_jdqd = None
# self.user_dirdyn_init = None
......@@ -212,13 +212,15 @@ class MbsDirdyn(object):
if __DEBUG__:
print("DEBUG>> Loading user functions")
self.__load_user_fct__(self.user_path)
# Loading symbolic function
if self.mbs.opt_load_c < 1:
if __DEBUG__:
print("DEBUG>> Loading symbolic functions")
# self.__load_user_fct__(self.user_path)
self.mbs.__load_user_fct_2__(__MODULE_DIR__, self.user_fun_list, self.user_path)
if self.mbs.opt_load_c < 1:
# Loading symbolic function
if __DEBUG__:
print("DEBUG>> Loading symbolic functions")
self.__load_symbolic_fct__(self.symbolic_path)
# self.__load_symbolic_fct__(self.symbolic_path)
self.mbs.__load_symbolic_fct_2__(__MODULE_DIR__, self.symb_fun_list, self.symbolic_path)
def __str__(self):
"""Return str(self)."""
......@@ -248,7 +250,7 @@ class MbsDirdyn(object):
user_path: str
The path to the folder containing the user functions.
"""
__load_user_fct_2__(self.mbs, __MODULE_DIR__, self.user_fun_list, user_path)
self.mbs.__load_user_fct_2__(__MODULE_DIR__, self.user_fun_list, user_path)
# template_path = os.path.join(__MODULE_DIR__, '../templates/user')
# # cons_hJ
......@@ -309,7 +311,7 @@ class MbsDirdyn(object):
symbolic_path: str
The path to the folder containing the symbolic functions.
"""
__load_symbolic_fct_2__(self.mbs, __MODULE_DIR__, self.symb_fun_list, symbolic_path)
self.mbs.__load_symbolic_fct_2__(__MODULE_DIR__, self.symb_fun_list, symbolic_path)
# mbs_name = self.mbs.mbs_name
# template_path = os.path.join(__MODULE_DIR__, '../templates/symbolic')
......@@ -359,7 +361,7 @@ class MbsDirdyn(object):
module. Store the functions in the MbsData instance and assign the
pointer of functions in the C structure.
"""
__assign_user_fct_2__(self.mbs, self.user_fun_list, self)
self.mbs.__assign_user_fct_2__(self.user_fun_list, self)
# # cons_hJ
# self.ptrs_to_user_fcts["user_cons_hJ"] = user_cons_hJ_wrap(lambda h, Jac, mbs, tsim: self.user_cons_hJ(self._huserc, self._Juserc, self.mbs, tsim))
# self.mbs.user_cons_hJ = self.user_cons_hJ
......@@ -391,7 +393,7 @@ class MbsDirdyn(object):
on MbsDirdyn module. Store the functions in the MbsData instance
and assign the pointer of functions in the C structure
"""
__assign_symb_fct_2__(self.mbs, self.symb_fun_list, self)
self.mbs.__assign_symb_fct_2__(self.symb_fun_list, self)
# # mbs_cons_hJ
# self.ptrs_to_symb_fcts["mbs_cons_hJ"] = mbs_cons_hJ_wrap(lambda h, Jac, mbs, tsim: self.mbs_cons_hJ(self._h, self._Jac, self.mbs))
# self.mbs.mbs_cons_hJ = self.mbs_cons_hJ
......@@ -422,7 +424,7 @@ class MbsDirdyn(object):
"""Unassign user function where some args depend on MbsDirdyn module."""
# self.ptrs_to_user_fcts.clear()
__unassign_user_fct_2__(self.mbs, self.user_fun_list)
self.mbs.__unassign_user_fct_2__(self.user_fun_list)
# self.mbs.user_cons_hJ = None
# self.mbs.mbs_data_ptr.contents.user_cons_hJ = user_cons_hJ_wrap(lambda h, Jac, mbs, tsim: callback_undefined("user_cons_hJ"))
# self.mbs.user_cons_jdqd = None
......@@ -438,7 +440,7 @@ class MbsDirdyn(object):
"""Unassign symbolic function where some args depend on MbsDirdyn module."""
# self.ptrs_to_symb_fcts.clear()
__unassign_symb_fct_2__(self.mbs, self.symb_fun_list)
self.mbs.__unassign_symb_fct_2__(self.symb_fun_list)
# self.mbs.mbs_cons_hJ = None
# self.mbs.mbs_data_ptr.contents.mbs_cons_hJ = mbs_cons_hJ_wrap(lambda h, Jac, mbs, tsim: callback_undefined("mbs_cons_hJ"))
# self.mbs.mbs_cons_jdqd = None
......@@ -469,13 +471,11 @@ class MbsDirdyn(object):
"""
# Assing required user functions
if self.mbs.opt_load_c < 2:
self.__assign_user_fct__()
#self.mbs.__assign_user_fct__()
self.mbs.__assign_user_fct_2__(self.user_fun_list, self)
# Assing required symbolic functions
if self.mbs.opt_load_c < 1:
self.__assign_symbolic_fct__()
#self.mbs.__assign_symb_fct__()
self.mbs.__assign_symb_fct_2__(self.symb_fun_list, self)
if not self.store_results:
libmodules.mbs_run_dirdyn(self.mbs_dirdyn_ptr, self.mbs.mbs_data_ptr)
......@@ -538,13 +538,11 @@ class MbsDirdyn(object):
# Anassign user functions
if self.mbs.opt_load_c < 2:
self.__unassign_user_fct__()
#self.mbs.__unassign_user_fct__()
self.mbs.__unassign_user_fct_2__(self.user_fun_list)
# Anassing required symbolic functions
if self.mbs.opt_load_c < 1:
self.__unassign_symbolic_fct__()
#self.mbs.__unassign_symb_fct__()
self.mbs.__unassign_symb_fct_2__(self.symb_fun_list)
return self.results
......
Markdown is supported
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