How to use the fmpy.util.download_test_file function in FMPy

To help you get started, we’ve selected a few FMPy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CATIA-Systems / FMPy / tests / test_command_line.py View on Github external
def setUpClass(cls):
        # download the FMU and input file
        download_test_file('2.0', 'ModelExchange', 'MapleSim', '2016.2', 'CoupledClutches', 'CoupledClutches.fmu')
        download_test_file('2.0', 'ModelExchange', 'MapleSim', '2016.2', 'CoupledClutches', 'CoupledClutches_in.csv')
        download_file('https://github.com/modelica/fmi-cross-check/raw/master/fmus/2.0/me/win64/Dymola/2019FD01/Rectifier/Rectifier.fmu')
github CATIA-Systems / FMPy / tests / test_extracted_fmu.py View on Github external
def test_extracted_fmu(self):
        """ Simulate an extracted FMU """

        download_test_file('2.0', 'CoSimulation', 'MapleSim', '2017', 'CoupledClutches', 'CoupledClutches.fmu')

        # extract the FMU
        tempdir = extract('CoupledClutches.fmu')

        # load the model description before the simulation
        model_description = read_model_description(tempdir)

        result = simulate_fmu(tempdir, model_description=model_description)

        self.assertIsNotNone(result)

        # clean up
        shutil.rmtree(tempdir)
github CATIA-Systems / FMPy / tests / test_command_line.py View on Github external
def setUpClass(cls):
        # download the FMU and input file
        download_test_file('2.0', 'ModelExchange', 'MapleSim', '2016.2', 'CoupledClutches', 'CoupledClutches.fmu')
        download_test_file('2.0', 'ModelExchange', 'MapleSim', '2016.2', 'CoupledClutches', 'CoupledClutches_in.csv')
        download_file('https://github.com/modelica/fmi-cross-check/raw/master/fmus/2.0/me/win64/Dymola/2019FD01/Rectifier/Rectifier.fmu')
github CATIA-Systems / FMPy / tests / test_common_functions.py View on Github external
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, 'cs', '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
github CATIA-Systems / FMPy / tests / test_get_start_values.py View on Github external
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')
github CATIA-Systems / FMPy / tests / test_serialize_fmu_state.py View on Github external
def test_serialize_fmu_state(self):

        fmu_filename = 'Rectifier.fmu'

        # download the FMU
        download_test_file('2.0', 'cs', 'MapleSim', '2016.2', 'Rectifier', fmu_filename)

        # read the model description
        model_description = read_model_description(fmu_filename)

        # extract the FMU
        unzipdir = extract(fmu_filename)

        # instantiate the FMU
        fmu = FMU2Slave(guid=model_description.guid,
                        unzipDirectory=unzipdir,
                        modelIdentifier=model_description.coSimulation.modelIdentifier)

        # initialize
        fmu.instantiate()
        fmu.setupExperiment()
        fmu.enterInitializationMode()
github CATIA-Systems / FMPy / fmpy / examples / coupled_clutches.py View on Github external
def simulate_coupled_clutches(fmi_version='2.0',
                              fmi_type='ModelExchange',
                              output=['outputs[1]', 'outputs[2]', 'outputs[3]', 'outputs[4]'],
                              solver='CVode',
                              fmi_logging=False,
                              show_plot=True):

    # download the FMU and input file
    for filename in ['CoupledClutches.fmu', 'CoupledClutches_in.csv']:
        download_test_file(fmi_version, fmi_type, 'MapleSim', '2017', 'CoupledClutches', filename)

    print("Loading input...")
    input = np.genfromtxt('CoupledClutches_in.csv', delimiter=',', names=True)

    print("Simulating CoupledClutches.fmu (FMI %s, %s, %s)..." % (fmi_version, fmi_type, solver))
    result = simulate_fmu(
        filename='CoupledClutches.fmu',
        start_time=0,
        stop_time=1.5,
        solver=solver,
        step_size=1e-2,
        output_interval=2e-2,
        start_values={'CoupledClutches1_freqHz': 0.4},
        input=input,
        output=output,
        validate=False,
github CATIA-Systems / FMPy / fmpy / examples / custom_input.py View on Github external
def simulate_custom_input(show_plot=True):

    # define the model name and simulation parameters
    fmu_filename = 'CoupledClutches.fmu'
    start_time = 0.0
    threshold = 2.0
    stop_time = 2.0
    step_size = 1e-3

    # download the FMU
    download_test_file('2.0', 'CoSimulation', 'MapleSim', '2016.2', 'CoupledClutches', fmu_filename)

    # read the model description
    model_description = read_model_description(fmu_filename)

    # collect the value references
    vrs = {}
    for variable in model_description.modelVariables:
        vrs[variable.name] = variable.valueReference

    # get the value references for the variables we want to get/set
    vr_inputs   = vrs['inputs']      # normalized force on the 3rd clutch
    vr_outputs4 = vrs['outputs[4]']  # angular velocity of the 4th inertia

    # extract the FMU
    unzipdir = extract(fmu_filename)
github CATIA-Systems / FMPy / fmpy / examples / parameter_variation.py View on Github external
def run_experiment(show_plot=True):

    if platform not in ['win32', 'win64']:
        raise Exception("Rectifier.fmu is only available for Windows")

    print("Parameter variation on %s:" % fmu_filename)
    print("  VAC", v_ac)
    print("  IDC", i_dc)

    if sync:
        dask.config.set(scheduler='synchronous')  # synchronized scheduler

    # download the FMU
    download_test_file('2.0', 'CoSimulation', 'Dymola', '2017', 'Rectifier', fmu_filename)

    # read the model description
    model_description = read_model_description(fmu_filename)

    # collect the value references for the variables to read / write
    vrs = {}
    for variable in model_description.modelVariables:
        vrs[variable.name] = variable.valueReference

    # extract the FMU
    unzipdir = fmpy.extract(fmu_filename)

    fmu_args = {'guid': model_description.guid,
                'modelIdentifier': model_description.coSimulation.modelIdentifier,
                'unzipDirectory': unzipdir}