Commit 5a5ff5c1 authored by Louis Beauloye's avatar Louis Beauloye
Browse files

unassign function ok

parent a1057647
......@@ -26,6 +26,17 @@ from ._mbsysc_loader.callback import user_equil_loop_wrap
from ._mbsysc_loader.callback import user_equil_finish_wrap
from ._mbsysc_loader.callback import user_equil_fxe_wrap
from ._mbsysc_loader.callback import mbs_accelred_wrap
from ._mbsysc_loader.callback import mbs_extforces_wrap
from ._mbsysc_loader.callback import mbs_gensensor_wrap
from ._mbsysc_loader.callback import mbs_link_wrap
from ._mbsysc_loader.callback import mbs_link3D_wrap
from ._mbsysc_loader.callback import mbs_sensor_wrap
from ._mbsysc_loader.callback import mbs_cons_hJ_wrap
from ._mbsysc_loader.callback import mbs_cons_jdqd_wrap
from ._mbsysc_loader.callback import mbs_invdyna_wrap
from ._mbsysc_loader.callback import mbs_dirdyna_wrap
def assign_user_fct_to_None(module, functions=None):
"""
......@@ -88,8 +99,7 @@ def assign_user_fct_to_None(module, functions=None):
module.user_dirdyn_finish = None
def iassign_symb_fct_to_None(module, functions=None):
def assign_symb_fct_to_None(module, functions=None):
"""
Parameters
......@@ -138,6 +148,7 @@ def iassign_symb_fct_to_None(module, functions=None):
module.mbs_link3D = None
module.mbs_sensor = None
def __unassign_user_fct_2__(module, functions=None):
"""
Unassign all user function if all args are in MbsData instance.
......@@ -148,11 +159,13 @@ def __unassign_user_fct_2__(module, functions=None):
print("unassign 2")
# Not necessary but if not present, dictionary must be filled in the
# load function and not the assign function.
module.ptrs_to_user_fcts.clear()
# module.ptrs_to_user_fcts.clear()
__assign_user_to_undefined__(module, functions)
assign_user_fct_to_None(module)
# if from data, to not suppress it
if functions is not None:
assign_user_fct_to_None(module, functions)
def __assign_user_to_undefined__(module, functions=None):
......@@ -160,9 +173,9 @@ def __assign_user_to_undefined__(module, functions=None):
if functions is not None:
for fun in functions:
if fun == "cons_hJ":
module.mbs.mbs_data_ptr.contents.user_cons_hJ = user_cons_hJ_wrap(lambda h, Jac, mbs, tsim: callback_undefined("user_cons_hJ"))
module.mbs_data_ptr.contents.user_cons_hJ = user_cons_hJ_wrap(lambda h, Jac, mbs, tsim: callback_undefined("user_cons_hJ"))
elif fun == "cons_jdqd":
module.mbs.mbs_data_ptr.contents.user_cons_jdqd = user_cons_jdqd_wrap(lambda h, Jac, mbs, tsim: callback_undefined("user_cons_jdqd"))
module.mbs_data_ptr.contents.user_cons_jdqd = user_cons_jdqd_wrap(lambda h, Jac, mbs, tsim: callback_undefined("user_cons_jdqd"))
elif fun == "derivative":
module.mbs_data_ptr.contents.user_Derivative = user_Derivative_wrap(lambda mbs: callback_undefined("user_Derivative"))
elif fun == "DrivenJoints":
......@@ -176,19 +189,19 @@ def __assign_user_to_undefined__(module, functions=None):
elif fun == "Link3DForces":
module.mbs_data_ptr.contents.user_Link3DForces = user_Link3DForces_wrap(lambda PxF, RxF, VxF, OMxF, AxF, OMPxF, mbs, tsim, ixF: callback_undefined("user_Link3DForces"))
elif fun == "dirdyn_init":
module.mbs.mbs_data_ptr.contents.user_dirdyn_init = user_dirdyn_init_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_init"))
module.mbs_data_ptr.contents.user_dirdyn_init = user_dirdyn_init_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_init"))
elif fun == "dirdyn_loop":
module.mbs.mbs_data_ptr.contents.user_dirdyn_loop = user_dirdyn_loop_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_loop"))
module.mbs_data_ptr.contents.user_dirdyn_loop = user_dirdyn_loop_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_loop"))
elif fun == "dirdyn_finish":
module.mbs.mbs_data_ptr.contents.user_dirdyn_finish = user_dirdyn_finish_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_finish"))
module.mbs_data_ptr.contents.user_dirdyn_finish = user_dirdyn_finish_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_finish"))
elif fun == "equil_init":
module.mbs.mbs_data_ptr.contents.user_equil_init = user_equil_init_wrap(lambda mbs, eq: callback_undefined("user_equil_init"))
module.mbs_data_ptr.contents.user_equil_init = user_equil_init_wrap(lambda mbs, eq: callback_undefined("user_equil_init"))
elif fun == "equil_loop":
module.mbs.mbs_data_ptr.contents.user_equil_loop = user_equil_loop_wrap(lambda mbs, eq: callback_undefined("user_equil_loop"))
module.mbs_data_ptr.contents.user_equil_loop = user_equil_loop_wrap(lambda mbs, eq: callback_undefined("user_equil_loop"))
elif fun == "equil_finish":
module.mbs.mbs_data_ptr.contents.user_equil_finish = user_equil_finish_wrap(lambda mbs, eq: callback_undefined("user_equil_finish"))
module.mbs_data_ptr.contents.user_equil_finish = user_equil_finish_wrap(lambda mbs, eq: callback_undefined("user_equil_finish"))
elif fun == "equil_fxe":
module.mbs.mbs_data_ptr.contents.user_equil_fxe = user_equil_fxe_wrap(lambda mbs, f: callback_undefined("user_equil_fxe"))
module.mbs_data_ptr.contents.user_equil_fxe = user_equil_fxe_wrap(lambda mbs, f: callback_undefined("user_equil_fxe"))
else:
print(fun + " is not an existing user function")
else:
......@@ -198,3 +211,57 @@ def __assign_user_to_undefined__(module, functions=None):
module.mbs_data_ptr.contents.user_JointForces = user_JointForces_wrap(lambda mbs, t: callback_undefined("user_JointForces"))
module.mbs_data_ptr.contents.user_LinkForces = user_LinkForces_wrap(lambda Z, Zd, mbs, tsim, ilnk: callback_undefined("user_LinkForces"))
module.mbs_data_ptr.contents.user_Link3DForces = user_Link3DForces_wrap(lambda PxF, RxF, VxF, OMxF, AxF, OMPxF, mbs, tsim, ixF: callback_undefined("user_Link3DForces"))
def __unassign_symb_fct_2__(module, functions=None):
"""
Unassign all user function if all args are in MbsData instance.
Only unassign the user functions in which the arguments are not
dependent of another module instance (ie. MbsPart, MbsDirdyn...).
"""
print("unassign 2")
# Not necessary but if not present, dictionary must be filled in the
# load function and not the assign function.
# module.ptrs_to_user_fcts.clear()
__assign_symb_to_undefined__(module, functions)
# if from data, to not suppress it
if functions is not None:
assign_symb_fct_to_None(module, functions)
def __assign_symb_to_undefined__(module, functions=None):
if functions is not None:
for fun in functions:
if fun == "accelred":
module.mbs_data_ptr.contents.mbs_accelred = mbs_accelred_wrap(lambda mbs, tsim: callback_undefined("mbs_accelred"))
elif fun == "cons_hJ":
module.mbs_data_ptr.contents.mbs_cons_hJ = mbs_cons_hJ_wrap(lambda h, Jac, mbs, tsim: callback_undefined("mbs_cons_hJ"))
elif fun == "cons_jdqd":
module.mbs_data_ptr.contents.mbs_cons_jdqd = mbs_cons_jdqd_wrap(lambda jdqd, mbs, tsim: callback_undefined("mbs_cons_jdqd"))
elif fun == "dirdyna":
module.mbs_data_ptr.contents.mbs_dirdyna = mbs_dirdyna_wrap(lambda M, c, mbs, tsim: callback_undefined("mbs_dirdyna"))
elif fun == "extforces":
module.mbs_data_ptr.contents.mbs_extforces = mbs_extforces_wrap(lambda frc, trq, mbs, tsim: callback_undefined("mbs_extforces"))
elif fun == "gensensor":
module.mbs_data_ptr.contents.mbs_gensensor = mbs_gensensor_wrap(lambda sens, mbs, isens: callback_undefined("mbs_gensensor"))
elif fun == "invdyna":
module.mbs_data_ptr.contents.mbs_invdyna = mbs_invdyna_wrap(lambda Q, mbs, tsim: callback_undefined("mbs_invdyna"))
elif fun == "link":
module.mbs_data_ptr.contents.mbs_link = mbs_link_wrap(lambda frc, trq, Flnk, Z, Zd, mbs, tsim: callback_undefined("mbs_link"))
elif fun == "link3D":
module.mbs_data_ptr.contents.mbs_link3D = mbs_link3D_wrap(lambda frc, trq, mbs, tsim: callback_undefined("mbs_link3D"))
elif fun == "sensor":
module.mbs_data_ptr.contents.mbs_sensor = mbs_sensor_wrap(lambda sens, mbs, isens: callback_undefined("mbs_sensor"))
else:
print(fun + " is not an existing symbolic function")
else:
module.mbs_data_ptr.contents.mbs_accelred = mbs_accelred_wrap(lambda mbs, tsim: callback_undefined("mbs_accelred"))
module.mbs_data_ptr.contents.mbs_extforces = mbs_extforces_wrap(lambda frc, trq, mbs, tsim: callback_undefined("mbs_extforces"))
module.mbs_data_ptr.contents.mbs_gensensor = mbs_gensensor_wrap(lambda sens, mbs, isens: callback_undefined("mbs_gensensor"))
module.mbs_data_ptr.contents.mbs_link = mbs_link_wrap(lambda frc, trq, Flnk, Z, Zd, mbs, tsim: callback_undefined("mbs_link"))
module.mbs_data_ptr.contents.mbs_link3D = mbs_link3D_wrap(lambda frc, trq, mbs, tsim: callback_undefined("mbs_link3D"))
module.mbs_data_ptr.contents.mbs_sensor = mbs_sensor_wrap(lambda sens, mbs, isens: callback_undefined("mbs_sensor"))
......@@ -44,9 +44,14 @@ from .._mbsysc_loader.loadlibs import libloadXML
from ..mbs_utilities import callback_undefined
# importing function handler
from .._mbs_function_handler import init_user_fct
from .._mbs_function_handler import init_symb_fct
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__
# importing wrapping function
from .._mbsysc_loader.callback import user_Derivative_wrap
......@@ -405,7 +410,8 @@ class MbsData(object):
# self.user_JointForces = None
# self.user_LinkForces = None
# self.user_Link3DForces = None
init_user_fct(self)
assign_user_fct_to_None(self)
__assign_user_to_undefined__(self)
# User function also related to dirdyn, equil...
# self.user_dirdyn_init = None
# self.user_dirdyn_loop = None
......@@ -422,7 +428,8 @@ class MbsData(object):
# self.mbs_link = None
# self.mbs_link3D = None
# self.mbs_sensor = None
init_symb_fct(self)
assign_symb_fct_to_None(self)
__assign_symb_to_undefined__(self)
# pointers dict to avoid garbage collecting
self.ptrs_to_user_fcts = dict()
......@@ -869,10 +876,11 @@ class MbsData(object):
Only unassign the user functions in which the arguments are not
dependent of another module instance (ie. MbsPart, MbsDirdyn...).
"""
__unassign_user_fct_2__(self)
# # Not necessary but if not present, dictionary must be filled in the
# # load function and not the assign function.
# self.ptrs_to_user_fcts = {}
self.ptrs_to_user_fcts.clear()
__unassign_user_fct_2__(self)
# self.mbs_data_ptr.contents.user_Derivative = user_Derivative_wrap(lambda mbs: callback_undefined("user_Derivative"))
# self.mbs_data_ptr.contents.user_DrivenJoints = user_DrivenJoints_wrap(lambda mbs, t: callback_undefined("user_DrivenJoints"))
......@@ -892,12 +900,14 @@ class MbsData(object):
# load function and not the assign function.
self.ptrs_to_symb_fcts = {}
self.mbs_data_ptr.contents.mbs_accelred = mbs_accelred_wrap(lambda mbs, tsim: callback_undefined("mbs_accelred"))
self.mbs_data_ptr.contents.mbs_extforces = mbs_extforces_wrap(lambda frc, trq, mbs, tsim: callback_undefined("mbs_extforces"))
self.mbs_data_ptr.contents.mbs_gensensor = mbs_gensensor_wrap(lambda sens, mbs, isens: callback_undefined("mbs_gensensor"))
self.mbs_data_ptr.contents.mbs_link = mbs_link_wrap(lambda frc, trq, Flnk, Z, Zd, mbs, tsim: callback_undefined("mbs_link"))
self.mbs_data_ptr.contents.mbs_link3D = mbs_link3D_wrap(lambda frc, trq, mbs, tsim: callback_undefined("mbs_link3D"))
self.mbs_data_ptr.contents.mbs_sensor = mbs_sensor_wrap(lambda sens, mbs, isens: callback_undefined("mbs_sensor"))
__unassign_symb_fct_2__(self)
# self.mbs_data_ptr.contents.mbs_accelred = mbs_accelred_wrap(lambda mbs, tsim: callback_undefined("mbs_accelred"))
# self.mbs_data_ptr.contents.mbs_extforces = mbs_extforces_wrap(lambda frc, trq, mbs, tsim: callback_undefined("mbs_extforces"))
# self.mbs_data_ptr.contents.mbs_gensensor = mbs_gensensor_wrap(lambda sens, mbs, isens: callback_undefined("mbs_gensensor"))
# self.mbs_data_ptr.contents.mbs_link = mbs_link_wrap(lambda frc, trq, Flnk, Z, Zd, mbs, tsim: callback_undefined("mbs_link"))
# self.mbs_data_ptr.contents.mbs_link3D = mbs_link3D_wrap(lambda frc, trq, mbs, tsim: callback_undefined("mbs_link3D"))
# self.mbs_data_ptr.contents.mbs_sensor = mbs_sensor_wrap(lambda sens, mbs, isens: callback_undefined("mbs_sensor"))
def __generate_id__(self):
"""
......
......@@ -31,6 +31,14 @@ from .._mbsysc_loader.loadlibs import libmodules
# importing utilities function
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__
# importing wrapping function
from .._mbsysc_loader.callback import user_cons_hJ_wrap
from .._mbsysc_loader.callback import user_cons_jdqd_wrap
......@@ -149,15 +157,21 @@ class MbsDirdyn(object):
self.ptrs_to_symb_fcts = dict()
# Storing project function pointer
self.user_cons_hJ = None
self.user_cons_jdqd = None
self.user_dirdyn_init = None
self.user_dirdyn_loop = None
self.user_dirdyn_finish = None
self.mbs_cons_hJ = None
self.mbs_cons_jdqd = None
self.mbs_invdyna = None
self.mbs_dirdyna = None
self.user_fun_list = ['cons_hJ', 'cons_jdqd', 'dirdyn_init', 'dirdyn_loop', 'dirdyn_finish']
self.symb_fun_list = ['cons_hJ', 'cons_jdqd', 'invdyna', 'dirdyna']
assign_user_fct_to_None(self, self.user_fun_list)
__assign_user_to_undefined__(self.mbs, self.user_fun_list)
assign_symb_fct_to_None(self, self.symb_fun_list)
__assign_symb_to_undefined__(self.mbs, self.symb_fun_list)
# self.user_cons_hJ = None
# self.user_cons_jdqd = None
# self.user_dirdyn_init = None
# self.user_dirdyn_loop = None
# self.user_dirdyn_finish = None
# self.mbs_cons_hJ = None
# self.mbs_cons_jdqd = None
# self.mbs_invdyna = None
# self.mbs_dirdyna = None
# Storing Results
self.results = MbsResult(self.mbs)
......@@ -392,27 +406,29 @@ class MbsDirdyn(object):
"""Unassign user function where some args depend on MbsDirdyn module."""
self.ptrs_to_user_fcts.clear()
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
self.mbs.mbs_data_ptr.contents.user_cons_jdqd = user_cons_jdqd_wrap(lambda h, Jac, mbs, tsim: callback_undefined("user_cons_jdqd"))
self.mbs.user_dirdyn_init = None
self.mbs.mbs_data_ptr.contents.user_dirdyn_init = user_dirdyn_init_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_init"))
self.mbs.user_dirdyn_loop = None
self.mbs.mbs_data_ptr.contents.user_dirdyn_loop = user_dirdyn_loop_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_loop"))
self.mbs.user_dirdyn_finish = None
self.mbs.mbs_data_ptr.contents.user_dirdyn_finish = user_dirdyn_finish_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_finish"))
__unassign_user_fct_2__(self.mbs, 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
# self.mbs.mbs_data_ptr.contents.user_cons_jdqd = user_cons_jdqd_wrap(lambda h, Jac, mbs, tsim: callback_undefined("user_cons_jdqd"))
# self.mbs.user_dirdyn_init = None
# self.mbs.mbs_data_ptr.contents.user_dirdyn_init = user_dirdyn_init_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_init"))
# self.mbs.user_dirdyn_loop = None
# self.mbs.mbs_data_ptr.contents.user_dirdyn_loop = user_dirdyn_loop_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_loop"))
# self.mbs.user_dirdyn_finish = None
# self.mbs.mbs_data_ptr.contents.user_dirdyn_finish = user_dirdyn_finish_wrap(lambda mbs, dd: callback_undefined("user_dirdyn_finish"))
def __unassign_symbolic_fct__(self):
"""Unassign symbolic function where some args depend on MbsDirdyn module."""
self.ptrs_to_symb_fcts.clear()
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
self.mbs.mbs_data_ptr.contents.mbs_cons_jdqd = mbs_cons_jdqd_wrap(lambda jdqd, mbs, tsim: callback_undefined("mbs_cons_jdqd"))
self.mbs.mbs_dirdyna = None
self.mbs.mbs_data_ptr.contents.mbs_dirdyna = mbs_dirdyna_wrap(lambda M, c, mbs, tsim: callback_undefined("mbs_dirdyna"))
__unassign_symb_fct_2__(self.mbs, 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
# self.mbs.mbs_data_ptr.contents.mbs_cons_jdqd = mbs_cons_jdqd_wrap(lambda jdqd, mbs, tsim: callback_undefined("mbs_cons_jdqd"))
# self.mbs.mbs_dirdyna = None
# self.mbs.mbs_data_ptr.contents.mbs_dirdyna = mbs_dirdyna_wrap(lambda M, c, mbs, tsim: callback_undefined("mbs_dirdyna"))
def __del__(self):
"""Delete the object by freeing the C-related memory."""
......
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