Esempio n. 1
0
        def test_no_result(self):
            model = Dummy_FMUModelME1([], "NegatedAlias.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)

            opts = model.simulate_options()
            opts["result_handling"] = "none"
            res = model.simulate(options=opts)

            nose.tools.assert_raises(Exception,res._get_result_data)
            
            model = Dummy_FMUModelME1([], "NegatedAlias.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)

            opts = model.simulate_options()
            opts["return_result"] = False
            res = model.simulate(options=opts)

            nose.tools.assert_raises(Exception,res._get_result_data)
Esempio n. 2
0
        def test_variable_alias_custom_handler(self):

            simple_alias = Dummy_FMUModelME1([40],
                                             "NegatedAlias.fmu",
                                             os.path.join(
                                                 file_path, "files", "FMUs",
                                                 "XML", "ME1.0"),
                                             _connect_dll=False)

            opts = simple_alias.simulate_options()
            opts["result_handling"] = "custom"
            opts["result_handler"] = ResultHandlerCSV(simple_alias)

            res = simple_alias.simulate(options=opts)

            # test that res['y'] returns a vector of the same length as the time
            # vector
            nose.tools.assert_equal(len(res['y']), len(res['time']),
                                    "Wrong size of result vector.")

            x = res["x"]
            y = res["y"]

            for i in range(len(x)):
                nose.tools.assert_equal(x[i], -y[i])
Esempio n. 3
0
 def test_csv_options_me1(self):
     simple_alias = Dummy_FMUModelME1([40],
                                      "NegatedAlias.fmu",
                                      os.path.join(
                                          file_path, "files", "FMUs",
                                          "XML", "ME1.0"),
                                      _connect_dll=False)
     _run_negated_alias(simple_alias, "csv")
Esempio n. 4
0
        def test_simulate_with_debug_option_no_state(self):
            model = Dummy_FMUModelME1([], "NoState.Example1.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)

            opts=model.simulate_options()
            opts["logging"] = True
            
            #Verify that a simulation is successful
            res=model.simulate(options=opts)
            
            from pyfmi.debug import CVodeDebugInformation
            debug = CVodeDebugInformation("NoState_Example1_debug.txt")
Esempio n. 5
0
    def test_simulation_without_initialization(self):
        model = Dummy_FMUModelME1([], "bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
        opts = model.simulate_options()
        opts["initialize"] = False

        nose.tools.assert_raises(FMUException, model.simulate, options=opts)
        
        model = Dummy_FMUModelCS1([], "bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "CS1.0"), _connect_dll=False)
        opts = model.simulate_options()
        opts["initialize"] = False

        nose.tools.assert_raises(FMUException, model.simulate, options=opts)
Esempio n. 6
0
 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"
Esempio n. 7
0
    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 = ResultHandlerFile(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 = ResultDymolaTextual('Description_result.txt')
        desc = res.description[res.get_variable_index("x")] 

        assert desc == u"Test symbols '' ‘’"
Esempio n. 8
0
 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")]
Esempio n. 9
0
        def test_custom_result_handler(self):
            model = Dummy_FMUModelME1([], "NegatedAlias.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)

            class A:
                pass
            class B(ResultHandler):
                def get_result(self):
                    return None

            opts = model.simulate_options()
            opts["result_handling"] = "hejhej"
            nose.tools.assert_raises(Exception, model.simulate, options=opts)
            opts["result_handling"] = "custom"
            nose.tools.assert_raises(Exception, model.simulate, options=opts)
            opts["result_handler"] = A()
            nose.tools.assert_raises(Exception, model.simulate, options=opts)
            opts["result_handler"] = B()
            res = model.simulate(options=opts)
Esempio n. 10
0
 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 '' ‘’"
Esempio n. 11
0
    def test_work_flow_me1(self):
        model = Dummy_FMUModelME1([], "bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
        model.initialize()
        
        bouncingBall = ResultHandlerCSV(model)
        
        bouncingBall.set_options(model.simulate_options())
        bouncingBall.simulation_start()
        bouncingBall.initialize_complete()
        bouncingBall.integration_point()
        bouncingBall.simulation_end()
        
        res = ResultCSVTextual('bouncingBall_result.csv')
        
        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)