def test_log_file_name(self): model = FMUModelME1Extended("bouncingBall.fmu", path_to_fmus_me1) assert os.path.exists("bouncingBall_log.txt") model = FMUModelME1Extended("bouncingBall.fmu", path_to_fmus_me1, log_file_name="Test_log.txt") assert os.path.exists("Test_log.txt")
def test_multiple_loadings_and_simulations(self): model = FMUModelME1Extended("bouncingBall.fmu", path_to_fmus_me1, enable_logging=False) res = model.simulate(final_time=1.0) h_res = res.final('h') for i in range(40): model = FMUModelME1Extended("bouncingBall.fmu", path_to_fmus_me1, enable_logging=False) res = model.simulate(final_time=1.0) assert N.abs(h_res - res.final('h')) < 1e-4
def test_filter(self): model = FMUModelME1Extended(Test_FMUModelME1Extended.rlc_circuit) opts = model.simulate_options() opts["filter"] = "resistor.*" res = model.simulate(final_time=0.1) nose.tools.assert_raises( Exception, res.result_data.get_variable_data("capacitor.v")) data = res["resistor.v"] model.reset() opts = model.simulate_options() opts["filter"] = "resistor.*" opts["result_handling"] = "memory" res = model.simulate(final_time=0.1) nose.tools.assert_raises( Exception, res.result_data.get_variable_data("capacitor.v")) data = res["resistor.v"] model.reset() opts = model.simulate_options() opts["filter"] = ["resistor.*", "capacitor.v"] res = model.simulate(final_time=0.1) data = res["capacitor.v"] data = res["resistor.v"]
def test_result_name_file(self): rlc = FMUModelME1Extended(Test_FMUModelME1Extended.rlc_circuit) res = rlc.simulate(options={"result_handling": "file"}) #Default name assert res.result_file == "RLC_Circuit_result.txt" assert os.path.exists(res.result_file) rlc = FMUModelME1Extended("RLC_Circuit.fmu") res = rlc.simulate( options={"result_file_name": "RLC_Circuit_result_test.txt"}) #User defined name assert res.result_file == "RLC_Circuit_result_test.txt" assert os.path.exists(res.result_file)
def test_simulation_cs(self): model = FMUModelME1Extended( "Modelica_Mechanics_Rotational_Examples_CoupledClutches_ME.fmu", path_to_fmus_me1) res = model.simulate(final_time=1.5) assert (res.final("J1.w") - 3.245091100366517) < 1e-4
def test_version(self): rlc = FMUModelME1Extended(Test_FMUModelME1Extended.rlc_circuit) # use get_version and not _get_version since it is an internal property # just for accessing version (which is also deprecated) rlc_version = rlc.get_version() expected = '1.0' assert rlc_version == expected, "EXPECTED: {}\nACTUAL:{}".format( expected, rlc_version)
def test_default_experiment(self): model = FMUModelME1Extended( "Modelica_Mechanics_Rotational_Examples_CoupledClutches_ME.fmu", path_to_fmus_me1) assert N.abs(model.get_default_experiment_start_time()) < 1e-4 assert N.abs(model.get_default_experiment_stop_time() - 1.5) < 1e-4 assert N.abs(model.get_default_experiment_tolerance() - 0.0001) < 1e-4
def test_simulation_with_reset_cs_2(self): rlc = FMUModelME1Extended(Test_FMUModelME1Extended.rlc_circuit) res1 = rlc.simulate(final_time=30) resistor_v = res1['resistor.v'] assert N.abs(resistor_v[-1] - 0.159255008028) < 1e-3 rlc.reset() res2 = rlc.simulate(final_time=30) resistor_v = res2['resistor.v'] assert N.abs(resistor_v[-1] - 0.159255008028) < 1e-3
def test_simulation_with_reset_cs(self): model = FMUModelME1Extended( "Modelica_Mechanics_Rotational_Examples_CoupledClutches_ME.fmu", path_to_fmus_me1) res1 = model.simulate(final_time=1.5) assert (res1["J1.w"][-1] - 3.245091100366517) < 1e-4 model.reset() res2 = model.simulate(final_time=1.5) assert (res2["J1.w"][-1] - 3.245091100366517) < 1e-4
def test_zero_step_size(self): model = FMUModelME1Extended( Test_FMUModelME1Extended.input_discontinuity) model.initialize() model.do_step(0, 1) model.set("u", 1.0) nose.tools.assert_almost_equal(model.get("x"), 0.0) model.do_step(1, 0) nose.tools.assert_almost_equal(model.get("x"), 1.0)
def test_input_derivatives3(self): model = FMUModelME1Extended(Test_FMUModelME1Extended.simple_input) model.initialize() model.set_input_derivatives("u", 1.0, 1) model.set_input_derivatives("u", -1.0, 2) model.do_step(0, 1) nose.tools.assert_almost_equal(model.get("u"), 0.5) model.do_step(1, 1) nose.tools.assert_almost_equal(model.get("u"), 0.5)
def test_simulation_with_reset_cs_3(self): rlc_square = FMUModelME1Extended( Test_FMUModelME1Extended.rlc_circuit_square) res1 = rlc_square.simulate() resistor_v = res1['resistor.v'] print resistor_v[-1] assert N.abs(resistor_v[-1] + 0.233534539103) < 1e-3 rlc_square.reset() res2 = rlc_square.simulate() resistor_v = res2['resistor.v'] assert N.abs(resistor_v[-1] + 0.233534539103) < 1e-3
def setUp(self): """ Sets up the test case. """ self.rlc = FMUModelME1Extended('RLC_Circuit.fmu') self.rlc_square = FMUModelME1Extended('RLC_Circuit_Square.fmu') self.no_state3 = FMUModelME1Extended("NoState_Example3.fmu") self.simple_input = FMUModelME1Extended("Inputs_SimpleInput.fmu") self.simple_input2 = FMUModelME1Extended("Inputs_SimpleInput2.fmu") self.input_discontinuity = FMUModelME1Extended( "Inputs_InputDiscontinuity.fmu")
def test_input_derivatives2(self): model = FMUModelME1Extended(Test_FMUModelME1Extended.simple_input2) model.initialize() model.set_input_derivatives("u1", 2.0, 1) model.do_step(0, 1) nose.tools.assert_almost_equal(model.get("u1"), 2.0) nose.tools.assert_almost_equal(model.get("u2"), 0.0) model.set_input_derivatives("u2", 2.0, 1) model.do_step(1, 1) nose.tools.assert_almost_equal(model.get("u2"), 2.0) nose.tools.assert_almost_equal(model.get("u1"), 2.0) model.set_input_derivatives(["u1", "u2"], [1.0, 1.0], [1, 1]) model.do_step(2, 1) nose.tools.assert_almost_equal(model.get("u2"), 3.0) nose.tools.assert_almost_equal(model.get("u1"), 3.0)
def test_custom_result_handler(self): model = FMUModelME1Extended(Test_FMUModelME1Extended.rlc_circuit) 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)
def test_valid_platforms(self): rlc = FMUModelME1Extended(Test_FMUModelME1Extended.rlc_circuit) rlc_platform = rlc.types_platform expected = 'standard32' assert rlc_platform == expected, "EXPECTED: {}\nACTUAL: {}".format( expected, rlc_platform)
def test_simulation_no_state(self): model = FMUModelME1Extended(Test_FMUModelME1Extended.no_state3) res = model.simulate(final_time=1.0) nose.tools.assert_almost_equal(res.final("x"), 1.0)
def test_default_simulation_stop_time(self): model = FMUModelME1Extended( "Modelica_Mechanics_Rotational_Examples_CoupledClutches_ME.fmu", path_to_fmus_me1) res = model.simulate() assert N.abs(1.5 - res.final('time')) < 1e-4
def test_exception_output_derivatives(self): model = FMUModelME1Extended( "Modelica_Mechanics_Rotational_Examples_CoupledClutches_ME.fmu", path_to_fmus_me1) nose.tools.assert_raises(FMUException, model.get_output_derivatives, "u", 1)
def test_types_platform(self): model = FMUModelME1Extended( "Modelica_Mechanics_Rotational_Examples_CoupledClutches_ME.fmu", path_to_fmus_me1) assert model.types_platform == "standard32"
def test_version(self): rlc = FMUModelME1Extended(Test_FMUModelME1Extended.rlc_circuit) assert rlc._get_version() == '1.0'
def test_valid_platforms(self): rlc = FMUModelME1Extended(Test_FMUModelME1Extended.rlc_circuit) assert rlc._get_types_platform() == 'standard32'