def test_SampleSystemSubSystemDictionaryInline(self): filename = self.ssp_dev_path( 'SystemStructureDescription', 'examples', 'SampleSystemSubSystemDictionaryInline.ssp') ssd = read_ssd(filename) self.assertEqual( ssd.name, 'Simple System with SubSystem and Dictionary all inline') # inline parameter bindings parameter_binding = ssd.system.parameterBindings[0] self.assertEqual('SubSystem.', parameter_binding.prefix) self.assertEqual('application/x-ssp-parameter-set', parameter_binding.type) p1, p2, p3 = parameter_binding.parameterValues[0].parameters self.assertEqual(('FirstFMUInstance1.Gain_Gain', 'Real', '8.0'), (p1.name, p1.type, p1.value)) self.assertEqual(('FirstFMUInstance2.Gain_Gain', 'Real', '3.0'), (p2.name, p2.type, p2.value)) self.assertEqual(('FirstFMUInstance2.Gain1_Gain', 'Real', '18.0'), (p3.name, p3.type, p3.value)) # inline signal dictionary signal_dictionary = ssd.system.signalDictionaries[0] self.assertEqual('MyDictionary', signal_dictionary.name) self.assertEqual('application/x-ssp-signal-dictionary', signal_dictionary.type) sd_entry1, sd_entry2 = signal_dictionary.entries self.assertEqual(('Var2', 'Real', 'km/h'), (sd_entry1.name, sd_entry1.type, sd_entry1.unit)) self.assertEqual(('Var4', 'Real', 'km/h'), (sd_entry2.name, sd_entry2.type, sd_entry2.unit))
def test_read_ssd_with_inlined_signal_dictionary(self): filename = self.ssp_dev_path( 'SystemStructureDescription', 'examples', 'SampleSystemSubSystemDictionaryInline.ssp') ssd = read_ssd(filename) self.assertEqual( ssd.name, 'Simple System with SubSystem and Dictionary all inline')
def test_read_ssd_with_referenced_signal_dictionary(self): filename = self.ssp_example_path('SampleSystemSubSystemDictionary.ssp') ssd = read_ssd(filename) self.assertEqual(ssd.name, 'Simple System with SubSystem and Dictionary') self.assertEqual( 1, len(ssd.system.elements[2].elements[0].parameterBindings))
def test_SampleSystem(self): filename = self.ssp_example_path('SampleSystem.ssp') ssd = read_ssd(filename) self.assertEqual('Simple Sample System', ssd.name) # System self.assertEqual('SampleSystem', ssd.system.name) self.assertEqual('Very simple Sample System', ssd.system.description)
def test_SampleSystemSubSystemParamConnectors(self): filename = self.ssp_example_path( 'SampleSystemSubSystemParamConnectors.ssp') ssd = read_ssd(filename) self.assertEqual( ssd.name, 'Simple System with SubSystem and Dictionary all inline, and parameter connectors' )
def test_SampleSystem(self): filename = self.ssp_dev_path('SystemStructureDescription', 'examples', 'SampleSystem.ssp') ssd = read_ssd(filename) self.assertEqual('Simple Sample System', ssd.name) # System self.assertEqual('SampleSystem', ssd.system.name) self.assertEqual('Very simple Sample System', ssd.system.description)
def test_SampleSystemSubSystemDictionary(self): filename = self.ssp_dev_path('SystemStructureDescription', 'examples', 'SampleSystemSubSystemDictionary.ssp') ssd = read_ssd(filename) self.assertEqual(ssd.name, 'Simple System with SubSystem and Dictionary') # parameter bindings from .ssv file parameter_binding = ssd.system.parameterBindings[0] self.assertEqual('SubSystem.', parameter_binding.prefix) self.assertEqual('application/x-ssp-parameter-set', parameter_binding.type) p1, p2, p3 = parameter_binding.parameterValues[0].parameters self.assertEqual(('FirstFMUInstance1.Gain_Gain', 'Real', '8.0'), (p1.name, p1.type, p1.value)) self.assertEqual(('FirstFMUInstance2.Gain_Gain', 'Real', '3.0'), (p2.name, p2.type, p2.value)) self.assertEqual(('FirstFMUInstance2.Gain1_Gain', 'Real', '18.0'), (p3.name, p3.type, p3.value)) # signal dictionary from .ssb file signal_dictionary = ssd.system.signalDictionaries[0] self.assertEqual('MyDictionary', signal_dictionary.name) self.assertEqual('resources/SampleSignalDictionary.ssb', signal_dictionary.source) self.assertEqual('application/x-ssp-signal-dictionary', signal_dictionary.type) sd_entry1, sd_entry2 = signal_dictionary.entries self.assertEqual(('Var2', 'Real', 'km/h'), (sd_entry1.name, sd_entry1.type, sd_entry1.unit)) self.assertEqual(('Var4', 'Real', 'km/h'), (sd_entry2.name, sd_entry2.type, sd_entry2.unit)) # units u1, u2 = ssd.units self.assertEqual(('km/h', 1, -1, 0.2777777777777778), (u1.name, u1.m, u1.s, u1.factor)) self.assertEqual(('m/s', 1, -1), (u2.name, u2.m, u1.s))
def test_read_ssd_dictionary(self): filename = self.ssp_example_path('SampleSystemSubSystemDictionary.ssp') ssd = read_ssd(filename) self.assertEqual(ssd.name, 'Simple System with SubSystem and Dictionary')
def simulate_ssp(ssp_filename, start_time=0.0, stop_time=None, step_size=None, parameter_set=None, input={}): """ Simulate a system of FMUs """ if stop_time is None: stop_time = 1.0 if step_size is None: step_size = stop_time * 1e-2 ssd = read_ssd(ssp_filename) add_path(ssd.system) components = find_components(ssd.system) connectors = find_connectors(ssd.system) connections = get_connections(ssd.system) # resolve connections connections_reversed = {} for a, b in connections: connections_reversed[b] = a new_connections = [] # trace connections back to the actual start connector for a, b in connections: while isinstance(a.parent, System) and a.parent.parent is not None: a = connections_reversed[a] new_connections.append((a, b)) connections = new_connections # extract the SSP ssp_unzipdir = extract(ssp_filename) # initialize the connectors for connector in connectors: connector.value = 0.0 # instantiate the FMUs for component in components: instantiate_fmu(component, ssp_unzipdir, start_time, parameter_set) time = start_time rows = [] # list to record the results # simulation loop while time < stop_time: # apply input for connector in ssd.system.connectors: if connector.kind == 'input' and connector.name in input: connector.value = input[connector.name](time) # perform one step for component in components: do_step(component, time, step_size) # apply connections for start_connector, end_connector in connections: end_connector.value = start_connector.value # get the results row = [time] for connector in connectors: row.append(connector.value) # append the results rows.append(tuple(row)) # advance the time time += step_size # free the FMUs for component in components: free_fmu(component) # clean up shutil.rmtree(ssp_unzipdir) dtype = [('time', np.float64)] for connector, value in zip(connectors, rows[0][1:]): if type(value) == bool: dtype.append((connector.path, np.bool_)) elif type(value) == int: dtype.append((connector.path, np.int32)) else: dtype.append((connector.path, np.float64)) # convert the results to a structured NumPy array return np.array(rows, dtype=np.dtype(dtype))
def test_SampleSystemSubSystem(self): filename = self.ssp_dev_path('SystemStructureDescription', 'examples', 'SampleSystemSubSystem.ssp') ssd = read_ssd(filename) self.assertEqual(ssd.name, 'Simple System with SubSystem')
def test_SubSystem(self): filename = self.ssp_dev_path('SystemStructureDescription', 'examples', 'SubSystem.ssp') ssd = read_ssd(filename) self.assertEqual(ssd.name, 'Subsystem for External Reuse')
def test_SampleSystemSubSystemReuseNested(self): filename = self.ssp_dev_path('SystemStructureDescription', 'examples', 'SampleSystemSubSystemReuseNested.ssp') ssd = read_ssd(filename) self.assertEqual(ssd.name, 'Simple System with SubSystem and External Reuse')
def test_SampleSystemSubSystem(self): filename = self.ssp_example_path('SampleSystemSubSystem.ssp') ssd = read_ssd(filename) self.assertEqual(ssd.name, 'Simple System with SubSystem')
def test_SubSystem(self): filename = self.ssp_example_path('SubSystem.ssp') ssd = read_ssd(filename) self.assertEqual(ssd.name, 'Subsystem for External Reuse')
def test_SampleSystemVariants(self): filename = self.ssp_example_path('SampleSystemVariants.ssp') ssd = read_ssd(filename) self.assertEqual(ssd.name, 'Simple Sample System')
def test_SampleSystemSubSystemReuseNested(self): filename = self.ssp_example_path( 'SampleSystemSubSystemReuseNested.ssp') ssd = read_ssd(filename) self.assertEqual(ssd.name, 'Simple System with SubSystem and External Reuse')