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

[MBsysPy][MbsDirdyn] Change the results loading path.

Variables name changed for simplifications.
parent 626d0ce6
......@@ -232,71 +232,98 @@ class MbsDirdyn(object):
if (error >= 0 and self.get_options("save2file")):
# Results(buffer) memory is kept BUT FILES WILL BE WRITTEN LATER
size1 = self.mbs_dirdyn_ptr.contents.buffers[0].contents.index
if size1 == 0:
size1 = self.mbs_dirdyn_ptr.contents.buffers[0].contents.size
size2 = self.mbs_dirdyn_ptr.contents.buffers[0].contents.nx + 1
# array are initialized to the time pointer so as to start index of joints at 1(we have to ensure contiguity between t and x in buffers ! ! !)
self.results.q = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[0].contents.tx, (size1, size2)))
# Arrays are initialized to the time pointer so as to start index of joints at 1.
nb_joint = self.mbs_dirdyn_ptr.contents.buffers[0].contents.nx + 1
nb_steps = self.mbs_dirdyn_ptr.contents.buffers[0].contents.index
if nb_steps == 0:
# nb_steps is the number of steps not (yet) save to disk.
# If the value is 0 it means that all has been saved to disk.
# But all is also still in memory.
nb_steps = self.mbs_dirdyn_ptr.contents.buffers[0].contents.size
# Load the joint coordinates to test if the whole integration is in memory
self.results.q = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[0].contents.tx, (nb_steps, nb_joint)))
# 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_dirdyn_ptr.contents.buffers[0].contents.filename))
self.results.load_results_from_file(filename, module=6)
# get qd and qdd buffer
self.results.qd = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[1].contents.tx, (size1, size2)))
self.results.qdd = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[2].contents.tx, (size1, size2)))
size2 = self.mbs_dirdyn_ptr.contents.buffers[3].contents.nx + 1
self.results.Qq = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[3].contents.tx, (size1, size2)))
buffer_id = 4
if self.mbs.Nux:
size2 = self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.nx + 1
self.results.ux = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.tx, (size1, size2)))
self.results.uxd = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id + 1].contents.tx, (size1, size2)))
buffer_id = buffer_id + 2
if self.mbs.Nlink:
size2 = self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.nx + 1
self.results.Z = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.tx, (size1, size2)))
self.results.Zd = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id + 1].contents.tx, (size1, size2)))
self.results.Fl = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id + 2].contents.tx, (size1, size2)))
buffer_id = buffer_id + 3
if self.mbs.nqc:
size2 = self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.nx + 1
self.results.Qc = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.tx, (size1, size2)))
buffer_id = buffer_id + 1
if self.mbs.nhu:
size2 = self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.nx + 1
self.results.Lambda = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.tx, (size1, size2)))
buffer_id = buffer_id + 1
nb_user_output_vector = libutilities.get_output_vector_nb()
for i in range(nb_user_output_vector):
size2 = self.mbs_dirdyn_ptr.contents.buffers[buffer_id + i].contents.nx + 1
user_out = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id + i].contents.tx, (size1, size2)))
# Name of the output vector should be recoverable with function
# 'libutilities.get_output_vector_label(i)' returning char*.
# However on MacOs (see comments of merge request !383) this
# does not work (pointer seems to be random).
name = bytes_to_str(os.path.basename(self.mbs_dirdyn_ptr.contents.buffers[buffer_id + i].contents.filename)[:-4])
len_prefix = len(self.get_options("resfilename"))
name = name[len_prefix + 1:]
self.results.outputs[name] = user_out
if self.mbs_dirdyn_ptr.contents.user_buffer.contents.nx:
size = self.mbs_dirdyn_ptr.contents.user_buffer.contents.index
if self.results.t[0] != self.get_options("t0"):
results_loaded = False
# Results have to be loaded from file, extract files names.
results_filename = bytes_to_str(ctypes.string_at(self.mbs_dirdyn_ptr.contents.buffers[0].contents.filename))
# Check if user vector output have been defined
user_output_vector_filenames = []
nb_user_output_vector = libutilities.get_output_vector_nb()
first_buffer_id = self.buffer_nb - nb_user_output_vector
for i in range(nb_user_output_vector):
vector_name = bytes_to_str(self.mbs_dirdyn_ptr.contents.buffers[first_buffer_id + i].contents.filename)
user_output_vector_filenames.append(os.path.basename(vector_name))
# Check if user auto output have been used
user_output_filenames = []
nbOutput = self.mbs_dirdyn_ptr.contents.user_buffer.contents.nx
for i in range(nbOutput):
user_out = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.user_buffer.contents.X[i], (1, size)))
name = bytes_to_str(self.mbs_dirdyn_ptr.contents.user_buffer.contents.names[i])
self.results.outputs[name] = user_out[0]
user_output_filenames.append(self.get_options("resfilename") + '_' + name + '.res')
else:
results_loaded = True
# The whole integration is in the memory, load all results.
self.results.qd = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[1].contents.tx, (nb_steps, nb_joint)))
self.results.qdd = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[2].contents.tx, (nb_steps, nb_joint)))
self.results.Qq = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[3].contents.tx, (nb_steps, nb_joint)))
buffer_id = 4
if self.mbs.Nux and self.get_options("compute_all_uxd"):
size2 = self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.nx + 1
self.results.ux = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.tx, (nb_steps, size2)))
self.results.uxd = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id + 1].contents.tx, (nb_steps, size2)))
buffer_id = buffer_id + 2
if self.mbs.Nlink:
size2 = self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.nx + 1
self.results.Z = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.tx, (nb_steps, size2)))
self.results.Zd = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id + 1].contents.tx, (nb_steps, size2)))
self.results.Fl = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id + 2].contents.tx, (nb_steps, size2)))
buffer_id = buffer_id + 3
if self.mbs.nqc:
self.results.Qc = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.tx, (nb_steps, nb_joint)))
buffer_id = buffer_id + 1
if self.mbs.nhu:
self.results.Lambda = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id].contents.tx, (nb_steps, nb_joint)))
buffer_id = buffer_id + 1
nb_user_output_vector = libutilities.get_output_vector_nb()
for i in range(nb_user_output_vector):
vector_size = self.mbs_dirdyn_ptr.contents.buffers[buffer_id + i].contents.nx + 1
user_out = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.buffers[buffer_id + i].contents.tx, (nb_steps, vector_size)))
# Name of the output vector should be recoverable with function
# 'libutilities.get_output_vector_label(i)' returning char*.
# However on MacOs (see comments of merge request !383) this
# does not work (pointer seems to be random).
name = bytes_to_str(os.path.basename(self.mbs_dirdyn_ptr.contents.buffers[buffer_id + i].contents.filename)[:-4])
len_prefix = len(self.get_options("resfilename"))
name = name[len_prefix + 1:]
self.results.outputs[name] = user_out
if self.mbs_dirdyn_ptr.contents.user_buffer.contents.nx:
size = self.mbs_dirdyn_ptr.contents.user_buffer.contents.index
if not size:
size = self.mbs_dirdyn_ptr.contents.user_buffer.contents.size
nbOutput = self.mbs_dirdyn_ptr.contents.user_buffer.contents.nx
for i in range(nbOutput):
user_out = np.copy(np.ctypeslib.as_array(self.mbs_dirdyn_ptr.contents.user_buffer.contents.X[i], (1, size)))
name = bytes_to_str(self.mbs_dirdyn_ptr.contents.user_buffer.contents.names[i])
self.results.outputs[name] = user_out[0]
if (error >= 0):
libmodules.mbs_dirdyn_finish(self.mbs_dirdyn_ptr, self.mbs.mbs_data_ptr)
if 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")
self.results.load_results_from_file(results_filename, module=6,
user_output=user_output_filenames,
user_vector=user_output_vector_filenames)
# Unassign user functions
if self.mbs.opt_load_c < 2:
self.mbs.__unassign_user_fct__(self.user_fun_list)
......
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