def test_simulate_sub_system(self): ssp_filename = self.ssp_example_path('SampleSystemSubSystem.ssp') sine = lambda t: np.sin(t * 2 * np.pi) result = simulate_ssp(ssp_filename, stop_time=1.0, step_size=0.01, input={'In1': sine}) # check if the input has been applied correctly self.assertTrue( np.all(np.abs(result['In1'] - sine(result['time'])) < 0.01))
def test_simulate_sample_system_with_parameters(self): ssv_filename = self.ssp_example_path('SampleSystemParameterValues.ssv') parameters = read_ssv(ssv_filename) filename = self.ssp_example_path('SampleSystem.ssp') sine = lambda t: np.sin(t * 2 * np.pi) result = simulate_ssp(filename, stop_time=1.0, step_size=0.01, parameters=parameters, input={'In1': sine}) # check if the input has been applied correctly self.assertTrue( np.all(np.abs(result['In1'] - sine(result['time'])) < 0.01))
def test_ControlledTemperature(self): ssp_filename = r'ControlledTemperature.ssp' if not os.path.isfile(ssp_filename): return def Tenv(t): return 20.0 def Tref(t): return 20.0 + np.floor(t) * 3 result = simulate_ssp(ssp_filename, stop_time=10, step_size=1e-2, input={ 'Tenv': Tenv, 'Tref': Tref })
def simulate_controlled_drivetrain(show_plot=True): """ Download and simulate ControlledDrivetrain.ssp Parameters: show_plot plot the results """ ssp_filename = r'ControlledDrivetrain.ssp' download_file('https://github.com/CATIA-Systems/FMPy/releases/download/v0.1.1/' + ssp_filename, checksum='45e667ed') print("Simulating %s..." % ssp_filename) result = simulate_ssp(ssp_filename, stop_time=4, step_size=1e-3) if show_plot: print("Plotting results...") plot_result(result, names=['reference.y', 'drivetrain.w', 'controller.y'], window_title=ssp_filename) print('Done.') return result
def test_ControlledDrivetrain(self): ssp_filename = self.ssp_dev_path('Examples', 'ControlledDrivetrain', 'ControlledDrivetrain.ssp') result = simulate_ssp(ssp_filename, step_size=1e-2, stop_time=4.0)
except Exception as download_error: print(f"ERROR: Cannot download {ssp_uri}: {download_error}") def set_simulation_env(envs): for var_name, endpoint in envs.items(): host_var_name = var_name + "_HOST" environ[host_var_name] = endpoint["host"] port_var_name = var_name + "_PORT" environ[port_var_name] = str(endpoint["port"]) while True: print("Waiting for work") message = json.loads(provider.get_message()) step_size = message['step-size'] stop_time = message['stop-time'] ssp_file = download_ssp_zip(message['ssp_uri']) set_simulation_env(message['fmu-environment']) print(f"Start co-simulation of {message['id']}") try: simulate_ssp(ssp_file, step_size=step_size, stop_time=stop_time) except Exception as simulation_error: print( f"ERROR: Cannot co-simulate {message['id']} : {simulation_error}") print(f"Co-simulation of {message['id']} done!") if (oneshot_worker): print("One shot! -> exiting") break