def test_correct_file_after_simulation_failure(self): simple_alias = Dummy_FMUModelME2([("x", "y")], "NegatedAlias.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME2.0"), _connect_dll=False) def f(*args, **kwargs): if simple_alias.time > 0.5: raise Exception return -simple_alias.continuous_states simple_alias.get_derivatives = f opts = simple_alias.simulate_options() opts["result_handling"] = "binary" opts["solver"] = "ExplicitEuler" successful_simulation = False try: res = simple_alias.simulate(options=opts) successful_simulation = True #The above simulation should fail... except: pass if successful_simulation: raise Exception result = ResultDymolaBinary("NegatedAlias_result.mat") x = result.get_variable_data("x").x y = result.get_variable_data("y").x assert len(x) > 2 for i in range(len(x)): nose.tools.assert_equal(x[i], -y[i])
def test_work_flow_me2(self): model = Dummy_FMUModelME2([], "bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME2.0"), _connect_dll=False) model.setup_experiment() model.initialize() bouncingBall = ResultHandlerBinaryFile(model) bouncingBall.set_options(model.simulate_options()) bouncingBall.simulation_start() bouncingBall.initialize_complete() bouncingBall.integration_point() bouncingBall.simulation_end() res = ResultDymolaBinary('bouncingBall_result.mat') h = res.get_variable_data('h') derh = res.get_variable_data('der(h)') g = res.get_variable_data('g') nose.tools.assert_almost_equal(h.x, 1.000000, 5) nose.tools.assert_almost_equal(derh.x, 0.000000, 5)
def test_result_only_variable_data_bin(self): """ Test that it is possible to get time data from a binary result file with only variable data. """ res_file = os.path.join(path_to_results, 'onlyVars.mat') res = ResultDymolaBinary(res_file) time_traj = res.get_variable_data('time') assert N.abs(time_traj.t[-1] - 1.0) < 1e-6 time_traj_dym = res.get_variable_data('Time') assert N.abs(time_traj_dym.t[-1] - 1.0) < 1e-6
def test_get_description(self): model = Dummy_FMUModelME1([], "CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False) model.initialize() result_writer = ResultHandlerBinaryFile(model) result_writer.set_options(model.simulate_options()) result_writer.simulation_start() result_writer.initialize_complete() result_writer.integration_point() result_writer.simulation_end() res = ResultDymolaBinary('CoupledClutches_result.mat') assert res.description[res.get_variable_index("J1.phi")] == "Absolute rotation angle of component"
def test_description_not_stored(self): model = Dummy_FMUModelME1([], "CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False) model.initialize() opts = model.simulate_options() opts["result_store_variable_description"] = False result_writer = ResultHandlerBinaryFile(model) result_writer.set_options(opts) result_writer.simulation_start() result_writer.initialize_complete() result_writer.integration_point() result_writer.simulation_end() res = ResultDymolaBinary('CoupledClutches_result.mat') assert res.description[res.get_variable_index("J1.phi")] == "", "Description is not empty, " + res.description[res.get_variable_index("J1.phi")]
def test_get_description_unicode(self): model = Dummy_FMUModelME1([], "Description.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False) model.initialize() result_writer = ResultHandlerBinaryFile(model) result_writer.set_options(model.simulate_options()) result_writer.simulation_start() result_writer.initialize_complete() result_writer.integration_point() result_writer.simulation_end() res = ResultDymolaBinary('Description_result.mat') desc = res.description[res.get_variable_index("x")] #This handling should in the future be nativly handled by the IO module desc = desc.encode("latin_1", "replace").decode("utf-8", "replace") assert desc == u"Test symbols '' ‘’"
def test_filter_no_variables(self): model = Dummy_FMUModelME2([], "bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME2.0"), _connect_dll=False) model.setup_experiment() model.initialize() model.time = 1.0 opts = model.simulate_options() opts["filter"] = "NoMatchingVariables" bouncingBall = ResultHandlerBinaryFile(model) bouncingBall.set_options(opts) bouncingBall.simulation_start() bouncingBall.initialize_complete() bouncingBall.integration_point() bouncingBall.simulation_end() res = ResultDymolaBinary('bouncingBall_result.mat') t = res.get_variable_data('time') nose.tools.assert_almost_equal(t.x[-1], 1.000000, 5)
from pyfmi.common.io import ResultDymolaBinary import pandas as pd import sys import numpy as np from plotly.offline import plot from plotly.graph_objs import * # get the data from the values dictionary mat = ResultDymolaBinary(TestValues.mat) mat_name = mat.name Node = [mat_name] for y in Node: data_1 = [data for data in y if ".k" not in data] data_2 = [data for data in data_1 if ".y" not in data] Data1 = [data for data in data_2 if "_" not in data] Data = [data for data in Data1 if "Time" not in data] Str = [] for DATA in Data: Str.append(DATA) len_data = len(Data) for i in Data: time = mat.get_variable_data(i).t Value = [] for i in Data: value = mat.get_variable_data(i).x Value.append(value) def is_negated(self, name): """ Returns True if the given name corresponds to a negated result vector.
def test_read_all_variables(self): res = ResultDymolaBinary(os.path.join(file_path, "files", "Results", "DoublePendulum.mat")) for var in res.name: res.get_variable_data(var)