Commit 4f5f0274 authored by Olivier Lantsoght's avatar Olivier Lantsoght
Browse files

[MBsysPy][Invdyn][Solvekin] loading results working even not in buffer.

parent a64132db
......@@ -208,13 +208,20 @@ class MbsInvdyn(object):
if (error >= 0):
error = libmodules.mbs_invdyn_loop(self.mbs_invdyn_ptr, self.mbs.mbs_data_ptr)
results_loaded = False
# Results(buffer) memory is kept BUT FILES WILL BE WRITTEN LATER
if error >= 0 and self.get_options("save2file"):
self._load_results()
results_loaded = self._load_results()
# finish function is required to close the module and write the results to disk.
error2 = libmodules.mbs_invdyn_finish(self.mbs_invdyn_ptr, self.mbs.mbs_data_ptr)
if error2 >= 0 and error >= 0 and not results_loaded:
mbs_msg("The beginning of the integration is not available in the buffer.\n"
"The complete results are loaded from files.\n")
filename = bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.buffers[0].contents.filename))
self.results.load_results_from_file(filename, module=6)
# Unassign user functions
if self.mbs.opt_load_c < 2:
self.mbs.__unassign_user_fct__(self.user_fun_list)
......@@ -250,7 +257,13 @@ class MbsInvdyn(object):
Load the results from the buffers.
If the beginning of the integration is not available in the buffers,
the complete results are loaded from files
the complete results are loaded from files.
Returns
-------
bool
True if the results have been fully loaded from memory.
False if the results must be loaded from files.
"""
# c_mbs_invdyn_write_buffers(self.mbs_invdyn_ptr)
size1 = self.mbs_invdyn_ptr.contents.buffers[0].contents.index
......@@ -263,9 +276,10 @@ class MbsInvdyn(object):
# get time array from the q buffer
self.results.t = self.results.q[:, 0]
if not self.results.t[0] == self.get_options("t0"):
mbs_msg("The beginning of the integration is not available in the buffer.\n The complete results have to be loaded from files.")
filename = bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.buffers[0].contents.filename))
self.results.load_results_from_file(filename, module=6)
self.results.q = []
self.results.t = []
return False
# get qd and qdd buffer
self.results.qd = np.copy(np.ctypeslib.as_array(self.mbs_invdyn_ptr.contents.buffers[1].contents.tx, (size1, size2)))
self.results.qdd = np.copy(np.ctypeslib.as_array(self.mbs_invdyn_ptr.contents.buffers[2].contents.tx, (size1, size2)))
......@@ -299,6 +313,8 @@ class MbsInvdyn(object):
name = bytes_to_str(self.mbs_invdyn_ptr.contents.user_buffer.contents.names[i])
self.results.outputs[name] = user_out[i, :]
return True
def 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.
......
......@@ -174,11 +174,18 @@ class MbsSolvekin(MbsInvdyn):
error_1 = libmodules.mbs_solvekin_loop(self.mbs_solvekin_ptr, self.mbs.mbs_data_ptr)
# Results (buffer) memory is kept BUT FILES WILL BE WRITTEN LATER
results_loaded = False
if error_1 >= 0 and self.get_options("save2file"):
self._load_results()
results_loaded = self._load_results()
error_2 = libmodules.mbs_solvekin_finish(self.mbs_solvekin_ptr, self.mbs.mbs_data_ptr)
if error_2 >= 0 and error_1 >= 0 and not results_loaded:
mbs_msg("The beginning of the integration is not available in the buffer.\n"
"The complete results are loaded from files.\n")
filename = bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.buffers[0].contents.filename))
self.results.load_results_from_file(filename, module=5)
# Unassign user functions
if self.mbs.opt_load_c < 2:
self.mbs.__unassign_user_fct__(self.user_fun_list)
......@@ -216,6 +223,12 @@ class MbsSolvekin(MbsInvdyn):
If the beginning of the integration is not available in the buffers,
the complete results are loaded from files. If the option 'motion' is
set to 'oneshot', the results are loaded from MbsData
Returns
-------
bool
True if the results have been fully loaded from memory.
False if the results must be loaded from files.
"""
if self.get_options("motion") == "oneshot":
self.results.q = np.array(self.mbs.q)
......@@ -233,9 +246,10 @@ class MbsSolvekin(MbsInvdyn):
self.results.t = self.results.q[:, 0]
if not self.results.t[0] == self.get_options("t0"):
mbs_msg("The beginning of the integration is not available in the buffer.\n The complete results have to be loaded from files.")
filename = bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.buffers[0].contents.filename))
self.results.load_results_from_file(filename, module=5)
self.results.q = []
self.results.t = []
return False
# get qd and qdd buffer
self.results.qd = np.copy(np.ctypeslib.as_array(self.mbs_solvekin_ptr.contents.buffers[1].contents.tx, (size1, size2)))
self.results.qdd = np.copy(np.ctypeslib.as_array(self.mbs_solvekin_ptr.contents.buffers[2].contents.tx, (size1, size2)))
......@@ -246,6 +260,7 @@ class MbsSolvekin(MbsInvdyn):
for i in range(nbOutput):
name = bytes_to_str(self.mbs_solvekin_ptr.contents.user_buffer.contents.names[i])
self.results.outputs[name] = user_out[i, :]
return True
def set_user_fct_from_file(self, function_name, user_path, user_file):
"""
......
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