Commit a781f2ed authored by Louis Beauloye's avatar Louis Beauloye
Browse files

[Ctypes] fix function to load result

parent a59be7c8
......@@ -414,7 +414,8 @@ class MbsDirdyn(object):
self.results.t = self.results.q[:,0]
if not self.results.t[0] == self.get_options("t0"):
print("The beginning of the integration is not available in the buffer.\n The complete results have to be loaded from files.")
self.results.load_results_from_file()
filename = ctypes.string_at(self.mbs_dirdyn_ptr.contents.buffers[0].contents.filename).decode('utf-8')
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)))
......@@ -875,7 +876,7 @@ class MbsResult(object):
self.Z=[]
self.Zd=[]
self.Qq=[]
self.qa=[]
self.Qa=[]
self.t=[]
self.ux=[]
self.uxd=[]
......@@ -883,19 +884,23 @@ class MbsResult(object):
self.outputs={}
self.mbs=mbs
def load_results_from_file(self, baseFileName="dirdyn", result_path="resultsR"):
def load_results_from_file(self, filename, result_path="resultsR", module=0):
"""
Load results from files into a MbsResult instance
:param baseFileName The path and resfilename containing the state to load.
The suffix _q, _qd, _ux, ... .res will be added.
default = "dirdyn" if not specified
:param filename The path and resfilename containing the state to load..
:param result_path The relative path of the result folder from the project folder
default = "resultsR" if not specified
:param module The module in which this function is called
In some modules, some results files don't exist
default = 0, all files are loaded
"""
project_path = self.mbs.project_path
baseFileName = os.path.basename(filename)
baseFileName = baseFileName[:-6]
result_path = os.path.join(project_path, result_path)
# Error handeling
if not os.path.isdir(result_path):
......@@ -905,8 +910,11 @@ class MbsResult(object):
CurFile = baseFileName+'_q.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path) ):
self.results.q = np.loadtxt(path)
self.results.t = self.results.q[:,0]
self.q = np.loadtxt(path)
if np.array(self.q).ndim > 1:
self.t = self.q[:,0]
else:
self.t = self.q[0]
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
......@@ -914,7 +922,7 @@ class MbsResult(object):
CurFile = baseFileName+'_qd.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path)):
self.results.qd = np.loadtxt(path)
self.qd = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
......@@ -922,66 +930,74 @@ class MbsResult(object):
CurFile = baseFileName+'_qdd.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path)):
self.results.qdd = np.loadtxt(path)
self.qdd = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
CurFile = baseFileName+'_Qq.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path)):
self.results.Qq = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
if module != 5:
CurFile = baseFileName+'_Qq.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path)):
self.Qq = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
# Generalized user state
if self.mbs.Nux:
if self.mbs.Nux and (module != 5 and module != 6):
CurFile = baseFileName+'_ux.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path) ):
self.results.ux = np.loadtxt(path)
self.ux = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
CurFile = baseFileName+'_uxd.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path)):
self.results.uxd = np.loadtxt(path)
self.uxd = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
# Link
if self.mbs.Nlink:
if self.mbs.Nlink and module != 5:
CurFile = baseFileName+'_linkF.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path) ):
self.results.Fl = np.loadtxt(path)
self.Fl = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
CurFile = baseFileName+'_linkZ.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path)):
self.results.Z = np.loadtxt(path)
self.Z = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
CurFile = baseFileName+'_linkZd.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path)):
self.results.Zd = np.loadtxt(path)
self.Zd = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
# Qc
if self.mbs.nqc:
if self.mbs.nqc and module != 5:
CurFile = baseFileName+'_Qc.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path) ):
self.results.Qc = np.loadtxt(path)
self.Qc = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
# Qa
if self.mbs.nqa and (module != 5 and module != 3):
CurFile = baseFileName+'_Qa.res'
path = os.path.abspath(os.path.join(result_path, CurFile))
if (os.path.isfile(path) ):
self.Qa = np.loadtxt(path)
else:
if __DEBUG__ : print( "DEBUG>> file '"+CurFile+"' not found in folder '"+os.path.dirname(path))
......@@ -385,7 +385,8 @@ class MbsInvdyn(object):
self.results.t = self.results.q[:,0]
if not self.results.t[0] == self.get_options("t0"):
print("The beginning of the integration is not available in the buffer.\n The complete results have to be loaded from files.")
self.results.load_results_from_file()
filename = ctypes.string_at(self.mbs_invdyn_ptr.contents.buffers[0].contents.filename).decode('utf-8')
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_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)))
......@@ -393,7 +394,7 @@ class MbsInvdyn(object):
self.results.Qq = np.copy(np.ctypeslib.as_array(self.mbs_invdyn_ptr.contents.buffers[3].contents.tx ,(size1, size2)))
if self.module_name == "MbsInvdyn":
size2 = self.mbs_invdyn_ptr.contents.buffers[4].contents.nx+1
self.results.qa = np.copy(np.ctypeslib.as_array(self.mbs_invdyn_ptr.contents.buffers[4].contents.tx ,(size1, size2)))
self.results.Qa = np.copy(np.ctypeslib.as_array(self.mbs_invdyn_ptr.contents.buffers[4].contents.tx ,(size1, size2)))
buffer_id = 5
else:
buffer_id = 4
......@@ -593,11 +594,21 @@ class MbsInvdyn(object):
elif key == "save2file":
options.append(self.mbs_invdyn_ptr.contents.options.contents.save2file)
elif key == "resfilename":
options.append(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.resfilename).decode("utf-8"))
if self.mbs_invdyn_ptr.contents.options.contents.resfilename is None:
print(">>" +self.module_name + ">> The option "+key+ " is not assigned")
else:
options.append(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.resfilename).decode("utf-8"))
elif key == "respath":
options.append(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.respath).decode("utf-8"))
if self.mbs_invdyn_ptr.contents.options.contents.respath is None:
print(">>" +self.module_name + ">> The option "+key+ " is not assigned")
else:
options.append(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.respath).decode("utf-8"))
elif key == "animpath":
options.append(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.animpath).decode("utf-8"))
if self.mbs_invdyn_ptr.contents.options.contents.animpath is None:
print(">>" +self.module_name + ">> The option "+key+ " is not assigned")
else:
options.append(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.animpath).decode("utf-8"))
elif key == "save_anim":
options.append(self.mbs_invdyn_ptr.contents.options.contents.save_anim)
elif key == "framerate":
......
......@@ -185,7 +185,8 @@ class MbsSolvekin(MbsInvdyn):
print(self.results.t[0])
if not self.results.t[0] == self.get_options("t0"):
print("The beginning of the integration is not available in the buffer.\n The complete results have to be loaded from files.")
self.results.load_results_from_file()
filename = ctypes.string_at(self.mbs_solvekin_ptr.contents.buffers[0].contents.filename).decode('utf-8')
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_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)))
......
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