Commit 7628f38b authored by Louis Beauloye's avatar Louis Beauloye
Browse files

[Ctypes] update struct

parent fdd21d6a
......@@ -60,9 +60,12 @@ mbs_new_user_IO_wrap = ctypes.CFUNCTYPE(ctypes.POINTER(UserIO_c), ctypes.POINTER
mbs_new_user_model_wrap = ctypes.CFUNCTYPE(ctypes.POINTER(UserModel_c))
mbs_delete_user_model_wrap = ctypes.CFUNCTYPE(None, ctypes.POINTER(UserModel_c))
mbs_delete_user_IO_wrap = ctypes.CFUNCTYPE(None, ctypes.POINTER(UserIO_c))
mbs_get_user_IO_size_wrap = ctypes.CFUNCTYPE(None, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
mbs_load_user_model_xml_wrap= ctypes.CFUNCTYPE(None, ctypes.POINTER(MbsInfos_c), ctypes.POINTER(UserModel_c))
mbs_bind_user_model_wrap = ctypes.CFUNCTYPE(None, ctypes.POINTER(MbsInfos_c), ctypes.POINTER(UserModel_c))
mbs_print_user_model_wrap = ctypes.CFUNCTYPE(None, ctypes.POINTER(UserModel_c))
mbs_get_user_model_size_wrap = ctypes.CFUNCTYPE(None, ctypes.POINTER(ctypes.c_int))
mbs_get_user_model_list_wrap = ctypes.CFUNCTYPE(None, ctypes.POINTER(ctypes.c_int))
# Symbolic
mbs_link_wrap = ctypes.CFUNCTYPE(None, ctypes.POINTER(ctypes.POINTER(ctypes.c_double)), ctypes.POINTER(ctypes.POINTER(ctypes.c_double)), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(MbsData_c), ctypes.c_double)
......
......@@ -14,11 +14,11 @@ While generating the libraries:
- SENSORKIN MUST BE UNDEFINED
- REALTIME MUST BE UNDEFINED
- ACCELRED MUST BE UNDEFINED
- INVDYNARED MUST BE UNDEFINED
- MBS_SIMULINK MUST BE UNDEFINED
- PRJ_FCT_PTR MUST BE DEFINED
- DIRDYNARED MUST BE DEFINED
- INVDYNARED MUST BE DEFINED
Declaration of MBsysC structure related to mbs_aux.h file in MBsysC.
......@@ -51,6 +51,7 @@ MbsAux_c._fields_ = [
("Juserc", ctypes.POINTER(ctypes.POINTER(ctypes.c_double))),
("mJv", ctypes.POINTER(ctypes.POINTER(ctypes.c_double))),
("ind_mJv", ctypes.POINTER(ctypes.c_int)),
("Qc", ctypes.POINTER(ctypes.c_double)),
("mJv_h", ctypes.POINTER(ctypes.c_double)),
......@@ -71,6 +72,8 @@ MbsAux_c._fields_ = [
("bp", ctypes.POINTER(ctypes.c_double)),
("psens", ctypes.POINTER(MbsSensor_c)),
("q_save", ctypes.POINTER(ctypes.c_double)),
("close_anim", ctypes.c_int),
("c", ctypes.POINTER(ctypes.c_double)),
("M", ctypes.POINTER(ctypes.POINTER(ctypes.c_double))),
......@@ -89,9 +92,12 @@ MbsAux_c._fields_ = [
("Fr", ctypes.POINTER(ctypes.c_double)),
("p_Mr", ctypes.POINTER(ctypes.c_double)),
("Qc", ctypes.POINTER(ctypes.c_double)),
("compute_Qc_vec", ctypes.POINTER(ctypes.c_int)),
("Qact", ctypes.POINTER(ctypes.c_double)),
("A", ctypes.POINTER(ctypes.POINTER(ctypes.c_double))),
("ind_A", ctypes.POINTER(ctypes.c_int)),
("phi", ctypes.POINTER(ctypes.c_double)),
("R", ctypes.POINTER(ctypes.c_double)),
......
......@@ -54,9 +54,12 @@ from .callback import mbs_new_user_IO_wrap
from .callback import mbs_new_user_model_wrap
from .callback import mbs_delete_user_model_wrap
from .callback import mbs_delete_user_IO_wrap
from .callback import mbs_get_user_IO_size_wrap
from .callback import mbs_load_user_model_xml_wrap
from .callback import mbs_bind_user_model_wrap
from .callback import mbs_print_user_model_wrap
from .callback import mbs_get_user_model_size_wrap
from .callback import mbs_get_user_model_list_wrap
from .callback import mbs_link_wrap
from .callback import mbs_link3D_wrap
......@@ -99,9 +102,13 @@ user_c._fields_ =[# REAL_TIME cannot be defined
("mbs_new_user_model", mbs_new_user_model_wrap),
("mbs_delete_user_model", mbs_delete_user_model_wrap),
("mbs_delete_user_IO", mbs_delete_user_IO_wrap),
("mbs_get_user_IO_size", mbs_get_user_IO_size_wrap),
("mbs_load_user_model_xml", mbs_load_user_model_xml_wrap),
("mbs_bind_user_model", mbs_bind_user_model_wrap),
("mbs_print_user_model", mbs_print_user_model_wrap)]
("mbs_print_user_model", mbs_print_user_model_wrap),
("mbs_get_user_model_size", mbs_get_user_model_size_wrap),
("mbs_get_user_model_list", mbs_get_user_model_list_wrap)
]
#==============================================================================
......
......@@ -57,6 +57,7 @@ MbsDirdynOptions_c._fields_ = [
("realtime", ctypes.c_int),
("accelred", ctypes.c_int),
("flag_compute_Qc", ctypes.c_int),
("compute_all_uxd", ctypes.c_int),
("compute_Qc", ctypes.POINTER(ctypes.c_int)),
("integrator", ctypes.c_int),
("verbose", ctypes.c_int),
......@@ -70,7 +71,8 @@ MbsDirdynOptions_c._fields_ = [
("rtoler", ctypes.c_double),
("atoler", ctypes.c_double),
("dt_max", ctypes.c_double),
("n_freeze", ctypes.c_int)
("n_freeze", ctypes.c_int),
("show_failed_closure", ctypes.c_int),
]
......
......@@ -68,7 +68,7 @@ class MbsDirdyn(object):
dt : double
Current integration step size.
results : MbsResult
Instance of MbsResult containing the results of the direct dynamics analysi.s
Instance of MbsResult containing the results of the direct dynamics analysis
"""
def __init__(self, mbs, user_path=None, symbolic_path=None):
if __DEBUG__ : print( "DEBUG>> Creating MbsDirdyn struct for "+mbs.mbs_name+"' MBS.")
......@@ -253,16 +253,6 @@ class MbsDirdyn(object):
module = imp.load_source(symb_file[:-3], path)
self.mbs_cons_jdqd = module.cons_jdqd
# invdyna
symb_file = "mbs_invdyna_"+mbs_name+".py"
path = os.path.abspath(os.path.join(symbolic_path, symb_file))
if not os.path.isfile(path):
if __DEBUG__ : print( "DEBUG>> file '"+symb_file+"' not found in folder '"+os.path.dirname(path))
symb_file = "mbs_invdyna_PRJ.py"
path = os.path.abspath(os.path.join(template_path, symb_file))
module = imp.load_source(symb_file[:-3], path)
self.mbs_invdyna = module.invdyna
# dirdyna
symb_file = "mbs_dirdyna_"+mbs_name+".py"
path = os.path.abspath(os.path.join(symbolic_path, symb_file))
......@@ -320,11 +310,6 @@ class MbsDirdyn(object):
self.mbs.mbs_cons_jdqd = self.mbs_cons_jdqd
self.mbs.mbs_data_ptr.contents.mbs_cons_jdqd = self.ptrs_to_symb_fcts["mbs_cons_jdqd"]
# invdyna
self.ptrs_to_symb_fcts["mbs_invdyna"] = mbs_invdyna_wrap(lambda Q,mbs,tsim : self.mbs_invdyna(self.mbs, tsim, None))
self.mbs.mbs_invdyna = self.mbs_invdyna
self.mbs.mbs_data_ptr.contents.mbs_invdyna = self.ptrs_to_symb_fcts["mbs_invdyna"]
# dirdyna
self.ptrs_to_symb_fcts["mbs_dirdyna"] = mbs_dirdyna_wrap(lambda M,c,mbs,tsim : self.mbs_dirdyna(self._M, self._c, self.mbs, tsim))
self.mbs.mbs_dirdyna = self.mbs_dirdyna
......@@ -370,8 +355,6 @@ class MbsDirdyn(object):
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_invdyna = None
self.mbs.mbs_data_ptr.contents.mbs_invdyna = mbs_invdyna_wrap(lambda Q,mbs,tsim : callback_undefined("mbs_invdyna"))
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"))
......@@ -531,6 +514,10 @@ class MbsDirdyn(object):
For dirdyn only
==1 by default
this allows to go faster
compute_all_uxd : int
choose to compute (or not) the user derivative during dirdyn time integration.
For dirdyn only.
default = 1
compute_Qc : numpy.ndarray
If options->flag_compute_Qc is set to 0, the vector allows to compute only the needed Qc
For dirdyn only.
......@@ -581,6 +568,9 @@ class MbsDirdyn(object):
n_freeze : int
number of time step when the jacobian is freezed (computed once at the start of the n_freeze time steps)
default = 0
show_failed_closure : int
1 to generate animation of the failed Newton-Raphson procedure
default = 0.
store_results : boolean
1 to save a copy of the results from the buffers
default = 1
......@@ -620,6 +610,8 @@ class MbsDirdyn(object):
self.mbs_dirdyn_ptr.contents.options.contents.accelred = value
elif key == "flag_compute_Qc":
self.mbs_dirdyn_ptr.contents.options.contents.flag_compute_Qc = value
elif key == "compute_all_uxd":
self.mbs_dirdyn_ptr.contents.options.contents.compute_all_uxd = value
elif key == "compute_Qc":
if (type(value) is np.ndarray) or (type(value) is list):
if np.size(value) == self.mbs.mbs_data_ptr.contents.njoint + 1:
......@@ -679,6 +671,8 @@ class MbsDirdyn(object):
self.mbs_dirdyn_ptr.contents.options.contents.dt_max = value
elif key == "n_freeze":
self.mbs_dirdyn_ptr.contents.options.contents.n_freeze = value
elif key == "show_failed_closure":
self.mbs_dirdyn_ptr.contents.options.contents.show_failed_closure = value
elif key == "store_results":
self.store_results = value
else:
......@@ -735,6 +729,8 @@ class MbsDirdyn(object):
options.append(self.mbs_dirdyn_ptr.contents.options.contents.accelred)
elif key == "flag_compute_Qc":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.flag_compute_Qc)
elif key == "compute_all_uxd":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.compute_all_uxd)
elif key == "compute_Qc":
compute_Qc_py = np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.options.contents.compute_Qc, (self.mbs.mbs_data_ptr.contents.njoint+1,))
options.append(compute_Qc_py)
......@@ -781,6 +777,8 @@ class MbsDirdyn(object):
options.append(self.mbs_dirdyn_ptr.contents.options.contents.dt_max)
elif key == "n_freeze":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.n_freeze)
elif key == "show_failed_closure":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.show_failed_closure)
elif key == "store_results":
options.append(self.store_results)
else:
......
......@@ -46,7 +46,7 @@ from ..mbsysc_loader.callback import mbs_invdyna_wrap
#==============================================================================
# Global parameter of the current module
#==============================================================================
__DEBUG__ = False
__DEBUG__ = True
__MODULE_DIR__ = os.path.dirname(os.path.abspath(__file__))
......@@ -65,8 +65,6 @@ class MbsEquil(object):
#Test
if __DEBUG__ :
print( "DEBUG>> MbsEquil created.")
print( " >> options->tf (5.0): ", self.mbs_equil_ptr.contents.options.contents.tf)
print( " >> options->dt_max (1e-3): ", self.mbs_equil_ptr.contents.options.contents.dt_max)
print( " >> aux->NRerr (-): ", self.mbs_equil_ptr.contents.aux.contents.NRerr)
print( " >> aux->nquc (-): ", self.mbs_equil_ptr.contents.aux.contents.nquc)
print( " >> aux->M[1:3][1:3]: ",
......@@ -133,6 +131,7 @@ class MbsEquil(object):
self._F = np.ctypeslib.as_array(self.mbs_equil_ptr.contents.aux.contents.F, (self.mbs.njoint+1,))
self._phi = np.ctypeslib.as_array(self.mbs_equil_ptr.contents.aux.contents.phi, (self.mbs.njoint+1,))
# Loading user function
if __DEBUG__ : print( "DEBUG>> Loading user functions")
self.__load_user_fct__(self.user_path)
......@@ -369,8 +368,8 @@ class MbsEquil(object):
self.mbs.__unassign_user_fct__()
# Anassing required symbolic functions
#self.__unassign_symbolic_fct__()
#self.mbs.__unassign_symb_fct__()
self.__unassign_symbolic_fct__()
self.mbs.__unassign_symb_fct__()
## WIP
def set_options(self, **kwargs):
......
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