Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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_coupled_clutches_example(self):
if platform.startswith('win'):
fmi_versions = ['2.0'] # ['1.0', '2.0'] quick fix until 1.0 is available again
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:
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
def test_coupled_clutches_example(self):
if platform.startswith('win'):
fmi_versions = ['2.0'] # ['1.0', '2.0'] quick fix until 1.0 is available again
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,
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')
command = 'call "' + installation_path + r'\VC\Auxiliary\Build\vcvarsall.bat"'
if platform == 'win64':
command += ' x86_amd64'
else:
command += ' x86'
command += ' && cl /LD /I. /I"%s"' % include_dir
for definition in preprocessor_definitions:
command += ' /D' + definition
command += ' /Fe' + build_configuration.modelIdentifier + ' shlwapi.lib ' + ' '.join(source_files)
elif compiler == 'gcc':
command = ''
if platform.startswith('win'):
command += r'set PATH=C:\MinGW\bin;%%PATH%% && '
command += 'gcc -c -I. -I%s' % include_dir
if platform in ['linux32', 'linux64']:
command += ' -fPIC'
for definition in preprocessor_definitions:
command += ' -D' + definition
command += ' ' + ' '.join(source_files)
command += ' && gcc'
if platform != 'darwin64':
command += ' -static-libgcc'
command += ' -shared -o%s *.o' % target
else:
raise Exception("Unsupported compiler: '%s'" % compiler)
cur_dir = os.getcwd()
def compile_dll(model_description, sources_dir, compiler=None):
""" Compile the shared library
Parameters:
sources_dir: directory that contains the FMU's source code
compiler: compiler to use (None: use Visual C on Windows, GCC otherwise)
"""
from . import platform, sharedLibraryExtension
if model_description.fmiVersion == '1.0':
raise Exception("FMI 1.0 source FMUs are currently not supported")
if compiler is None:
if platform.startswith('win'):
compiler = 'vc'
else:
compiler = 'gcc'
include_dir = os.path.join(os.path.dirname(__file__), 'c-code')
preprocessor_definitions = []
source_files = []
if len(model_description.buildConfigurations) == 0:
raise Exception("No build configuration found.")
build_configuration = model_description.buildConfigurations[0]
if len(build_configuration.sourceFileSets) > 1:
raise Exception("More than one SourceFileSet is not supported.")