예제 #1
0
    def test_unicode_description(self):
        full_path = os.path.join(file_path, "files", "FMUs", "XML", "ME1.0",
                                 "Description.fmu")
        model = FMUModelME1(full_path, _connect_dll=False)

        desc = model.get_variable_description("x")

        assert desc == "Test symbols '' ‘’"
예제 #2
0
    def test_ode_get_sizes(self):
        bounce = FMUModelME1("bouncingBall.fmu",
                             os.path.join(file_path, "files", "FMUs", "XML",
                                          "ME1.0"),
                             _connect_dll=False)
        dq = FMUModelME1("dq.fmu",
                         os.path.join(file_path, "files", "FMUs", "XML",
                                      "ME1.0"),
                         _connect_dll=False)

        [nCont, nEvent] = bounce.get_ode_sizes()
        assert nCont == 2
        assert nEvent == 1

        [nCont, nEvent] = dq.get_ode_sizes()
        assert nCont == 1
        assert nEvent == 0
예제 #3
0
 def test_get_time_varying_variables(self):
     model = FMUModelME1("RLC_Circuit.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
     
     [r,i,b] = model.get_model_time_varying_value_references()
     [r_f, i_f, b_f] = model.get_model_time_varying_value_references(filter="*")
     
     assert len(r) == len(r_f)
     assert len(i) == len(i_f)
     assert len(b) == len(b_f)
예제 #4
0
파일: test_util.py 프로젝트: stheid/PyFMI
    def __init__(self, states_vref, *args, **kwargs):
        FMUModelME1.__init__(self, *args, **kwargs)

        self.continuous_states = np.zeros(self.get_ode_sizes()[0])
        self.nominal_continuous_states = np.ones(self.get_ode_sizes()[0])
        self.variables = self.get_model_variables(include_alias=False)
        self.states_vref = states_vref

        self.values = {}
        for var in self.variables:
            try:
                start = self.get_variable_start(var)
            except FMUException:
                start = 0.0
            self.values[self.variables[var].value_reference] = start

        for i, vref in enumerate(self.states_vref):
            self.continuous_states[i] = self.values[vref]
예제 #5
0
    def test_default_experiment(self):
        model = FMUModelME1("CoupledClutches.fmu",
                            os.path.join(file_path, "files", "FMUs", "XML",
                                         "ME1.0"),
                            _connect_dll=False)

        assert np.abs(model.get_default_experiment_start_time()) < 1e-4
        assert np.abs(model.get_default_experiment_stop_time() - 1.5) < 1e-4
        assert np.abs(model.get_default_experiment_tolerance() - 0.0001) < 1e-4
예제 #6
0
    def test_get_time_varying_variables_with_alias(self):
        model = FMUModelME1("Alias1.fmu",
                            os.path.join(file_path, "files", "FMUs", "XML",
                                         "ME1.0"),
                            _connect_dll=False)

        [r, i, b] = model.get_model_time_varying_value_references(filter="y*")

        assert len(r) == 1
        assert r[0] == model.get_variable_valueref("y")
예제 #7
0
    def test_get_variable_by_valueref(self):
        bounce = FMUModelME1("bouncingBall.fmu",
                             os.path.join(file_path, "files", "FMUs", "XML",
                                          "ME1.0"),
                             _connect_dll=False)
        assert "der(v)" == bounce.get_variable_by_valueref(3)
        assert "v" == bounce.get_variable_by_valueref(2)

        nose.tools.assert_raises(FMUException, bounce.get_variable_by_valueref,
                                 7)
예제 #8
0
 def test_get_fmi_options(self):
     """
     Test that simulate_options on an FMU returns the correct options
     class instance.
     """
     bounce = FMUModelME1("bouncingBall.fmu",
                          os.path.join(file_path, "files", "FMUs", "XML",
                                       "ME1.0"),
                          _connect_dll=False)
     assert isinstance(bounce.simulate_options(),
                       fmi_algorithm_drivers.AssimuloFMIAlgOptions)
예제 #9
0
    def test_get_scalar_variable(self):
        negated_alias = FMUModelME1("NegatedAlias.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)

        sc_x = negated_alias.get_scalar_variable("x")
        
        assert sc_x.name == "x"
        assert sc_x.value_reference >= 0
        assert sc_x.type == fmi.FMI_REAL
        assert sc_x.variability == fmi.FMI_CONTINUOUS
        assert sc_x.causality == fmi.FMI_INTERNAL
        assert sc_x.alias == fmi.FMI_NO_ALIAS

        nose.tools.assert_raises(FMUException, negated_alias.get_scalar_variable, "not_existing")
예제 #10
0
def run_demo(with_plots=True):
    
    # Choose starting point (initial estimation)
    x0 = N.array([0.012,0.002])

    # Choose lower and upper bounds (optional)
    lb = N.zeros(2)
    ub = x0 + 1e-2

    x_opt,f_opt,nbr_iters,nbr_fevals,solve_time = dfo.nelme_modified(furuta_dfo_cost,xstart=x0*1e3,
                                                            lb=lb,ub=ub*1e3,
                                                            x_tol=1e-3,f_tol=1e-2,debug=False)
    [armFrictionCoefficient_opt,pendulumFrictionCoefficient_opt] = x_opt/1e3
    
    # Load model
    model = FMUModelME1(os.path.join(curr_dir, 'files', 'FMUs', 'Furuta.fmu'), enable_logging=False)
    
    # Set optimal parameter values into the model
    model.set('armFriction', armFrictionCoefficient_opt)
    model.set('pendulumFriction', pendulumFrictionCoefficient_opt)
    
    opts = model.simulate_options()
    opts['filter'] = ['armJoint.phi', 'pendulumJoint.phi']
    
    # Simulate model response with optimal parameter values
    res = model.simulate(start_time=0., final_time=40)
    
    # Load optimal simulation result
    phi_opt = res['armJoint.phi']
    theta_opt = res['pendulumJoint.phi']
    t_opt  = res['time']
    
    assert N.abs(res.final('armJoint.phi') + 0.309)      < 3e-2
    assert N.abs(res.final('pendulumJoint.phi') - 3.130) < 3e-2
    assert N.abs(res.final('time') - 40.0)               < 1e-3
    
    if with_plots:
        plt.figure(1)
        plt.subplot(2,1,1)
        plt.plot(t_opt, theta_opt, linewidth=1, label='Simulation optimal parameters')
        plt.plot(t_meas, theta_meas, linewidth=1, label='Physical data')
        plt.legend()
        plt.subplot(2,1,2)
        plt.plot(t_opt, phi_opt, linewidth=1, label='Simulation optimal parameters')
        plt.plot(t_meas, phi_meas, linewidth=1, label='Physical data')
        plt.legend()
        plt.show()
예제 #11
0
 def test_loading_xml_me1(self):
     
     model = FMUModelME1("CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
     
     assert model.get_name() == "CoupledClutches", model.get_name()
예제 #12
0
 def test_get_variable_nominal_valueref(self):
     bounce = FMUModelME1("bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
     assert bounce.get_variable_nominal("v") == bounce.get_variable_nominal(valueref=2)
예제 #13
0
 def setUp(self):
     """
     Sets up the test class.
     """
     self.fmu_name = compile_fmu(self._cpath, self._fpath)
     self.model = FMUModelME1(self.fmu_name)
예제 #14
0
 def test_log_file_name(self):
     model = FMUModelME1("bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
     assert os.path.exists("bouncingBall_log.txt")
     model = FMUModelME1("bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False, log_file_name="Test_log.txt")
     assert os.path.exists("Test_log.txt")
예제 #15
0
 def test_get_name(self):
     bounce = FMUModelME1("bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
     dq = FMUModelME1("dq.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
     
     assert bounce.get_name() == 'bouncingBall'
     assert dq.get_name() == 'dq'
예제 #16
0
 def test_get_erronous_nominals(self):
     model = FMUModelME1("NominalTest4.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
     
     nose.tools.assert_almost_equal(model.get_variable_nominal("x"), 2.0)
     nose.tools.assert_almost_equal(model.get_variable_nominal("y"), 1.0)
예제 #17
0
 def setUp(self):
     """
     Sets up the test class.
     """
     self.fmu_name = compile_fmu(self._cpath, self._fpath,compiler_options={'compliance_as_warning':True, 'generate_runtime_option_parameters':False})
     self.model = FMUModelME1(self.fmu_name)
예제 #18
0
 def test_get_variable_description(self):
     model = FMUModelME1("CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
     assert model.get_variable_description("J1.phi") == "Absolute rotation angle of component"