How to use the fmpy.util.download_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_c_code.py View on Github external
""" Create a CMake project """

        from subprocess import check_call
        import shutil
        from fmpy.util import visual_c_versions

        try:
            # check if CMake is installed
            check_call(['cmake'])
            cmake_available = True
        except:
            cmake_available = False

        for fmu in self.fmus:

            download_file(self.url + fmu)

            filename = os.path.basename(fmu)

            model_name, _ = os.path.splitext(filename)

            # clean up
            if os.path.isdir(model_name):
                shutil.rmtree(model_name)

            # create the CMake project
            create_cmake_project(filename, model_name)

            if not cmake_available:
                continue  # skip compilation

            # generate the build system
github CATIA-Systems / FMPy / tests / test_c_code.py View on Github external
def test_compile(self):
        """ Compile the platform binary """

        for fmu in self.fmus:
            download_file(self.url + fmu)

            filename = os.path.basename(fmu)

            compile_platform_binary(filename)

            result = simulate_fmu(filename=filename)
            self.assertIsNotNone(result)
github CATIA-Systems / FMPy / tests / test_type_definitions.py View on Github external
def test_type_definitions(self):
        """ Read the Type Definitions from the modelDescription.xml """

        for fmi_version in ['1.0', '2.0']:

            download_file('https://github.com/modelica/fmi-cross-check/raw/master/fmus/'
                          + fmi_version + '/cs/win64/Dymola/2017/DFFREG/DFFREG.fmu')

            model_description = read_model_description('DFFREG.fmu')

            real = model_description.typeDefinitions[0]

            self.assertEqual('Real', real.type)
            self.assertEqual('Modelica.SIunits.Time', real.name)
            self.assertEqual('Time', real.quantity)
            self.assertEqual('s', real.unit)

            logic = model_description.typeDefinitions[1]

            self.assertEqual('Enumeration', logic.type)
            self.assertEqual('Modelica.Electrical.Digital.Interfaces.Logic', logic.name)
            self.assertEqual(9, len(logic.items))
github CATIA-Systems / FMPy / tests / test_validation.py View on Github external
def setUp(self):
        download_file(url='https://github.com/modelica/fmi-cross-check/raw/master/fmus/2.0/me/win64/MapleSim/2015.1/CoupledClutches/CoupledClutches.fmu',
                      checksum='af8f8ca4d7073b2d6207d8eea4a3257e3a23a69089f03181236ee3ecf13ff77f')
github CATIA-Systems / FMPy / fmpy / ssp / examples / controlled_drivetrain.py View on Github external
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
github CATIA-Systems / FMPy / fmpy / examples / efficient_loops.py View on Github external
def run_efficient_loop():

    # download the FMU
    url = 'https://github.com/modelica/fmi-cross-check/raw/master/fmus/2.0/cs/win64/Test-FMUs/0.0.2/VanDerPol/VanDerPol.fmu'
    sha = 'a870f5f7f712e8152bfd60a1c2fd1c0bc10d4ca8124bd3031e321e8dd1e71bb0'
    download_file(url, sha)

    # extract the FMU to a temporary directory
    unzipdir = extract('VanDerPol.fmu')

    # read the model description
    model_description = read_model_description(unzipdir)

    # instantiate the FMU
    fmu_instance = instantiate_fmu(unzipdir, model_description, 'ModelExchange')

    # perform the iteration
    for i in range(100):

        # reset the FMU instance instead of creating a new one
        fmu_instance.reset()
github CATIA-Systems / FMPy / remoting / build_remoting.py View on Github external
import os
import tarfile
import shutil
from subprocess import check_call
from fmpy.util import download_file


url = 'https://github.com/rpclib/rpclib/archive/v2.2.1.tar.gz'
checksum = 'ceef2c521a1712035bc64d1bd5e3b2c7de16a1d856cbbeadd000ae318c96463f'

# build configuration
config = 'Release'

download_file(url, checksum)

filename = os.path.basename(url)

basedir = os.path.dirname(__file__)

source_dir = 'rpclib-2.2.1'

rpclib_dir = os.path.join(basedir, source_dir).replace('\\', '/')

shutil.rmtree(source_dir, ignore_errors=True)

print("Extracting %s" % filename)
with tarfile.open(filename, 'r:gz') as tar:
    tar.extractall()

path = os.path.dirname(__file__)