def __init__(self, mat_file='', filter=None): """ Loads in mat-file, extracts given variables in filter (time always included) and converts lists of values into numpy arrays. These are stored in result as: {{name1: array([values1])}, ..., {nameN: array([valuesN])}} """ self.result = {} fileName, fileExtension = os.path.splitext(mat_file) if fileExtension.lower() == '.mat': # MatLab result format Dymola or OpenModelica mat_converter = MatFile2Dict(mat_file, filter, False) result_lists = mat_converter.get_results() # convert lists into numpy arrays for item in result_lists.iteritems(): self.result.update({item[0]: np.array(item[1])}) elif fileExtension.lower() == '.txt': # Text result format JModelica # TODO: this is a temporary solution #set PYTHONPATH=C:\JModelica.org-1.12\install\Python #set JMODELICA_HOME=C:\JModelica.org-1.12\install #set IPOPT_HOME=C:\JModelica.org-1.12\Ipopt-MUMPS #set MINGW_HOME=C:\JModelica.org-1.12\MinGW #set CPPAD_HOME=%JMODELICA_HOME%\ThirdParty\CppAD #set JAVA_HOME=C:\JModelica.org-1.12\Java\jre7 #set SEPARATE_PROCESS_JVM=C:\JModelica.org-1.12\Java\jre7 #set JPYPE_JVM=C:\JModelica.org-1.12\Java\jre7-i586\bin\client\jvm.dll #set SUNDIALS_HOME=C:\JModelica.org-1.12\install\ThirdParty\Sundials #set PATH=%PATH%;C:\JModelica.org-1.12\MinGW\bin;C:\JModelica.org-1.12\Java\jre7\bin os.environ['JMODELICA_HOME'] = r'C:\JModelica.org-1.12\install' os.environ['MINGW_HOME'] = r'C:\JModelica.org-1.12\MinGW' os.environ['JPYPE_JVM'] = r'C:\JModelica.org-1.12\Java\jre7-i586\bin\client\jvm.dll' sys.path.append(r'C:\JModelica.org-1.12\install\Python') sys.path.append(r'C:\Python27\Lib\site-packages') import pyjmi.jmi print mat_file res = pyjmi.jmi.ResultDymolaTextual(mat_file) for name in res.name: #print name self.result.update({str(name): res.get_variable_data(name).x}) self.time = self.result['time']
def __init__(self, mat_file='', variable_filter=None): """ Loads in mat-file, extracts given variables in variable_filter (time always included) and converts lists of values into numpy arrays. These are stored in result as: {{name1: array([values1])}, ..., {nameN: array([valuesN])}} """ mat_converter = MatFile2Dict(mat_file, variable_filter, False) result_lists = mat_converter.get_results() # convert lists into numpy arrays self.result = {} for item in result_lists.iteritems(): self.result.update({item[0]: np.array(item[1])}) self.time = self.result['time']
def run_simulation(self, variable_filter=None, gather_desc=False): """ Simulates the model and returns with the two dictionaries; first one with parameters(constants) and second one with variables . Filter should be a list of strings with names of variables/parameters to include. If None all are returned. """ if self.tool.simulate_model(): result_file = self.tool.result_mat mat_converter = MatFile2Dict(result_file, variable_filter, gather_desc) result = mat_converter.get_results() desc = None if gather_desc: desc = mat_converter.get_descriptions() return result, desc else: return None, None