def test_coupled_clutches_example(self): if platform.startswith('win'): fmi_versions = ['1.0', '2.0'] elif platform.startswith(('darwin', 'linux')): fmi_versions = ['2.0'] else: self.fail('Platform not supported') for fmi_version in fmi_versions: for fmi_type in ['CoSimulation', 'ModelExchange']: solvers = ['Euler'] if fmi_type == 'ModelExchange': solvers.append('CVode') for solver in solvers: result = simulate_coupled_clutches(fmi_version=fmi_version, fmi_type=fmi_type, solver=solver, show_plot=False, output=['inputs', 'CoupledClutches1_freqHz']) if result is not None: # sometimes the download fails... freqHz = result['CoupledClutches1_freqHz'] self.assertTrue(np.all(freqHz == 0.4), "Start value has not been applied") inputs = result['inputs'] self.assertAlmostEqual(inputs[0], 0, "Input has not been applied") self.assertAlmostEqual(inputs[-1], 1, "Input has not been applied") self.assertEqual(0.0, result['time'][0], msg="Result must start at start_time (= 0.0)")
def test_coupled_clutches_example(self): print("Python:") print(sys.version) if platform.startswith('win'): fmi_versions = ['1.0', '2.0'] elif platform.startswith(('darwin', 'linux')): fmi_versions = ['2.0'] else: self.fail('Platform not supported') for fmi_version in fmi_versions: for fmi_type in ['CoSimulation', 'ModelExchange']: result = simulate_coupled_clutches( fmi_version=fmi_version, fmi_type=fmi_type, show_plot=False, output=['inputs', 'CoupledClutches1_freqHz']) if result is not None: # sometimes the download fails... # check if the start value has been set freqHz = result['CoupledClutches1_freqHz'] self.assertTrue(np.all(freqHz == 0.4)) # check if the input has been set inputs = result['inputs'] self.assertAlmostEqual(inputs[0], 0) self.assertAlmostEqual(inputs[-1], 1)
def test_get_start_values(self): if platform.startswith('win'): fmi_versions = ['2.0'] # quick fix until FMUs are available elif platform.startswith(('darwin', 'linux')): fmi_versions = ['2.0'] else: self.fail('Platform not supported') for fmi_version in fmi_versions: for fmi_type in ['CoSimulation', 'ModelExchange']: download_test_file(fmi_version, fmi_type, 'MapleSim', '2016.2', 'CoupledClutches', 'CoupledClutches.fmu') start_values = get_start_values('CoupledClutches.fmu') self.assertEqual(start_values['CoupledClutches1_freqHz'], '0.2')
def test_common_functions(self): if platform.startswith('win'): fmi_versions = ['1.0', '2.0'] else: return for fmi_version in fmi_versions: model_name = 'BooleanNetwork1' filename = model_name + '.fmu' download_test_file(fmi_version, 'CoSimulation', 'Dymola', '2017', model_name, filename) model_description = read_model_description(filename) unzipdir = extract(filename) guid = model_description.guid variables = {} for v in model_description.modelVariables: variables[v.name] = v args = { 'guid': guid, 'modelIdentifier': model_description.coSimulation.modelIdentifier, 'unzipDirectory': unzipdir, 'instanceName': None } if fmi_version == '1.0': fmu = FMU1Slave(**args) fmu.instantiate("instance1") fmu.initialize() else: fmu = FMU2Slave(**args) fmu.instantiate(loggingOn=False) fmu.setupExperiment(tolerance=None) fmu.enterInitializationMode() fmu.exitInitializationMode() # get types platform types_platform = fmu.getTypesPlatform() if fmi_version == '1.0': self.assertEqual('standard32', types_platform) else: self.assertEqual('default', types_platform) # get FMI version version = fmu.getVersion() self.assertEqual(fmi_version, version) # set debug logging if fmi_version == '1.0': fmu.setDebugLogging(True) else: fmu.setDebugLogging(True, ['logAll']) # set and get Real vr = [variables['booleanPulse1.width'].valueReference] value = [30.0] fmu.setReal(vr, value) result = fmu.getReal(vr) self.assertTrue(result[0] == value[0]) # set and get Integer vr = [variables['integerConstant.k'].valueReference] value = [-4] fmu.setInteger(vr, value) result = fmu.getInteger(vr) self.assertTrue(result[0] == value[0]) # set and get Boolean vr = [variables['rSFlipFlop.Qini'].valueReference] value = [True] fmu.setBoolean(vr, value) result = fmu.getBoolean(vr) self.assertTrue(result[0] == value[0]) # TODO: set and get String # clean up fmu.terminate() fmu.freeInstance() shutil.rmtree(unzipdir)