Beispiel #1
0
    def test_basic_algebraic_loop(self):
        model_sub1 = FMUModelCS2("LinearStability.SubSystem1.fmu",
                                 cs2_xml_path,
                                 _connect_dll=False)
        model_sub2 = FMUModelCS2("LinearStability.SubSystem2.fmu",
                                 cs2_xml_path,
                                 _connect_dll=False)

        models = [model_sub1, model_sub2]
        connections = [(model_sub1, "y1", model_sub2, "u2"),
                       (model_sub2, "y2", model_sub1, "u1")]

        sim = Master(models, connections)
        assert sim.algebraic_loops

        model_sub1 = FMUModelCS2("LinearStability_LinearSubSystemNoFeed1.fmu",
                                 cs2_xml_path,
                                 _connect_dll=False)
        model_sub2 = FMUModelCS2("LinearStability_LinearSubSystemNoFeed2.fmu",
                                 cs2_xml_path,
                                 _connect_dll=False)

        models = [model_sub1, model_sub2]
        connections = [(model_sub1, "y1", model_sub2, "u2"),
                       (model_sub2, "y2", model_sub1, "u1")]

        sim = Master(models, connections)
        assert not sim.algebraic_loops
Beispiel #2
0
def get_linear_model_matrices(model: fmi.FMUModelCS2):
    x_num = int(model.get('n'))
    u_num = int(model.get('m'))
    y_num = int(model.get('p'))

    A = _read_model_matrix(model, 'A', (x_num, x_num))
    B = _read_model_matrix(model, 'B', (x_num, u_num))
    C = _read_model_matrix(model, 'C', (y_num, x_num))
    D = _read_model_matrix(model, 'D', (y_num, u_num))
    return A, B, C, D
Beispiel #3
0
    def test_loading_models(self):
        model_sub1 = FMUModelCS2("LinearStability.SubSystem1.fmu",
                                 cs2_xml_path,
                                 _connect_dll=False)
        model_sub2 = FMUModelCS2("LinearStability.SubSystem2.fmu",
                                 cs2_xml_path,
                                 _connect_dll=False)

        models = [model_sub1, model_sub2]
        connections = [(model_sub1, "y1", model_sub2, "u2"),
                       (model_sub2, "y2", model_sub1, "u1")]

        #Assert that loading is successful
        sim = Master(models, connections)
Beispiel #4
0
def _read_model_matrix(model: fmi.FMUModelCS2, matrix_name: str,
                       shape: t.Tuple[int, int]):
    M = np.zeros(shape)
    for i in range(1, shape[0] + 1):
        for j in range(1, shape[1] + 1):
            M[i - 1, j - 1] = model.get(f'{matrix_name}[{i},{j}]')
    return M
Beispiel #5
0
    def test_log_file_name(self):
        full_path = os.path.join(file_path, "files", "FMUs", "XML", "CS2.0",
                                 "CoupledClutches.fmu")
        model = FMUModelCS2(full_path, _connect_dll=False)

        path, file_name = os.path.split(full_path)
        assert model.get_log_file_name() == file_name.replace(
            ".", "_")[:-4] + "_log.txt"
Beispiel #6
0
    def test_loading_xml_cs2(self):

        model = FMUModelCS2("CoupledClutches.fmu",
                            os.path.join(file_path, "files", "FMUs", "XML",
                                         "CS2.0"),
                            _connect_dll=False)

        assert model.get_name() == "CoupledClutches", model.get_name()
Beispiel #7
0
    def test_connection_variables(self):
        model_sub1 = FMUModelCS2("LinearStability.SubSystem1.fmu",
                                 cs2_xml_path,
                                 _connect_dll=False)
        model_sub2 = FMUModelCS2("LinearStability.SubSystem2.fmu",
                                 cs2_xml_path,
                                 _connect_dll=False)

        models = [model_sub1, model_sub2]

        #Test all connections are inputs or outputs
        connections = [(model_sub1, "y1", model_sub2, "x2"),
                       (model_sub2, "y2", model_sub1, "u1")]

        nose.tools.assert_raises(FMUException, Master, models, connections)

        #Test wrong input / output order
        connections = [(model_sub2, "u2", model_sub1, "y1"),
                       (model_sub2, "y2", model_sub1, "u1")]

        nose.tools.assert_raises(FMUException, Master, models, connections)
Beispiel #8
0
 def __init__(self, negated_aliases, *args,**kwargs):
     FMUModelCS2.__init__(self, *args, **kwargs)
 
     
     self.continuous_states = np.zeros(self.get_ode_sizes()[0])
     self.variables = self.get_model_variables(include_alias=False)
     self.negated_aliases = negated_aliases
     
     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 alias in self.negated_aliases:
         self.values[self.variables[alias[1]].value_reference] = -self.values[self.variables[alias[0]].value_reference]
     
     states = self.get_states_list()
     for i,state in enumerate(states):
         self.continuous_states[i] = self.values[states[state].value_reference]
Beispiel #9
0
    def test_loading_wrong_model(self):
        model_sub1 = FMUModelCS2("LinearStability.SubSystem1.fmu",
                                 cs2_xml_path,
                                 _connect_dll=False)
        model_sub2 = FMUModelME2("LinearStability.SubSystem2.fmu",
                                 me2_xml_path,
                                 _connect_dll=False)

        models = [model_sub1, model_sub2]
        connections = [(model_sub1, "y1", model_sub2, "u2"),
                       (model_sub2, "y2", model_sub1, "u1")]

        nose.tools.assert_raises(FMUException, Master, models, connections)