예제 #1
0
    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)
예제 #2
0
 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 
예제 #3
0
파일: test_io.py 프로젝트: stheid/PyFMI
 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])
예제 #4
0
    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 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.
        
        Parameters::
        
            name -- 
                Name of the variable/parameter/constant.
예제 #6
0
파일: test_io.py 프로젝트: stheid/PyFMI
 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)