-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
16,199 additions
and
752 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import shutil | ||
|
||
from fmpy import platform, sharedLibraryExtension | ||
import os | ||
from subprocess import check_call | ||
|
||
|
||
if os.name == 'nt': | ||
generators = [ | ||
('win32', 'Visual Studio 15 2017'), | ||
('win64', 'Visual Studio 15 2017 Win64') | ||
] | ||
else: | ||
generators = [(platform, 'Unix Makefiles')] | ||
|
||
for p, generator in generators: | ||
|
||
build_dir = 'fmpy/fmucontainer/%s' % p | ||
|
||
shutil.rmtree(build_dir, ignore_errors=True) | ||
os.mkdir(build_dir) | ||
|
||
check_call([ | ||
'cmake', | ||
'-G', generator, | ||
'-S', 'fmpy/fmucontainer', | ||
'-B', build_dir | ||
]) | ||
|
||
check_call(['cmake', '--build', build_dir, '--config', 'Release']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# build artifacts | ||
darwin64/ | ||
linux64/ | ||
win32/ | ||
win64/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
cmake_minimum_required (VERSION 3.2) | ||
|
||
project (FMUContainer) | ||
|
||
if (WIN32) | ||
set(FMI_PLATFORM win) | ||
elseif (APPLE) | ||
set(FMI_PLATFORM darwin) | ||
else () | ||
set(FMI_PLATFORM linux) | ||
endif () | ||
|
||
if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") | ||
set (FMI_PLATFORM ${FMI_PLATFORM}64) | ||
else () | ||
set (FMI_PLATFORM ${FMI_PLATFORM}32) | ||
endif () | ||
|
||
if (MSVC) | ||
# link statically against the the Visual C runtime | ||
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") | ||
string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") | ||
|
||
# disable compiler warnings | ||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE) | ||
endif () | ||
|
||
add_library(FMUContainer SHARED | ||
../c-code/fmi2Functions.h | ||
../c-code/fmi2FunctionTypes.h | ||
../c-code/fmi2TypesPlatform.h | ||
sources/FMUContainer.c | ||
sources/mpack.h | ||
sources/mpack.c | ||
) | ||
|
||
SET_TARGET_PROPERTIES(FMUContainer PROPERTIES PREFIX "") | ||
|
||
target_include_directories(FMUContainer PUBLIC | ||
sources | ||
../c-code | ||
) | ||
|
||
target_link_libraries(FMUContainer | ||
${CMAKE_DL_LIBS} | ||
) | ||
|
||
add_custom_command(TARGET FMUContainer POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy | ||
"$<TARGET_FILE:FMUContainer>" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/binaries/${FMI_PLATFORM}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
from tempfile import mkdtemp | ||
|
||
|
||
def create_fmu_container(configuration, output_filename): | ||
""" Create an FMU from nested FMUs (experimental) | ||
see tests/test_fmu_container.py for an example | ||
""" | ||
|
||
import os | ||
import shutil | ||
import fmpy | ||
from fmpy import read_model_description, extract | ||
import msgpack | ||
from datetime import datetime | ||
import pytz | ||
|
||
base_filename, _ = os.path.splitext(output_filename) | ||
model_name = os.path.basename(base_filename) | ||
|
||
unzipdir = mkdtemp() | ||
|
||
basedir = os.path.dirname(__file__) | ||
|
||
for directory in ['binaries', 'documentation', 'sources']: | ||
shutil.copytree(os.path.join(basedir, directory), os.path.join(unzipdir, directory)) | ||
|
||
os.mkdir(os.path.join(unzipdir, 'resources')) | ||
|
||
data = { | ||
'components': [], | ||
'variables': [], | ||
'connections': [] | ||
} | ||
|
||
l = [] | ||
|
||
component_map = {} | ||
vi = 0 # variable index | ||
|
||
l.append('<?xml version="1.0" encoding="UTF-8"?>') | ||
l.append('<fmiModelDescription') | ||
l.append(' fmiVersion="2.0"') | ||
l.append(' modelName="%s"' % model_name) | ||
l.append(' guid=""') | ||
if 'description' in configuration: | ||
l.append(' description="%s"' % configuration['description']) | ||
l.append(' generationTool="FMPy %s FMU Container"' % fmpy.__version__) | ||
l.append(' generationDateAndTime="%s">' % datetime.now(pytz.utc).isoformat()) | ||
l.append('') | ||
l.append(' <CoSimulation modelIdentifier="FMUContainer">') | ||
l.append(' <SourceFiles>') | ||
l.append(' <File name="FMUContainer.c"/>') | ||
l.append(' <File name="mpack.c"/>') | ||
l.append(' </SourceFiles>') | ||
l.append(' </CoSimulation>') | ||
l.append('') | ||
l.append(' <ModelVariables>') | ||
for i, component in enumerate(configuration['components']): | ||
model_description = read_model_description(component['filename']) | ||
model_identifier = model_description.coSimulation.modelIdentifier | ||
extract(component['filename'], os.path.join(unzipdir, 'resources', model_identifier)) | ||
variables = dict((v.name, v) for v in model_description.modelVariables) | ||
component_map[component['name']] = (i, variables) | ||
data['components'].append({ | ||
'name': component['name'], | ||
'guid': model_description.guid, | ||
'modelIdentifier': model_identifier, | ||
}) | ||
for name in component['variables']: | ||
v = variables[name] | ||
data['variables'].append({'component': i, 'valueReference': v.valueReference}) | ||
name = component['name'] + '.' + v.name | ||
description = v.description | ||
if name in configuration['variables']: | ||
mapping = configuration['variables'][name] | ||
if 'name' in mapping: | ||
name = mapping['name'] | ||
if 'description' in mapping: | ||
description = mapping['description'] | ||
description = ' description="%s"' % description if description else '' | ||
l.append(' <ScalarVariable name="%s" valueReference="%d" causality="%s" variability="%s"%s>' % (name, vi, v.causality, v.variability, description)) | ||
l.append(' <%s%s/>' % (v.type, ' start="%s"' % v.start if v.start else '')) | ||
l.append(' </ScalarVariable>') | ||
vi += 1 | ||
l.append(' </ModelVariables>') | ||
l.append('') | ||
l.append(' <ModelStructure/>') | ||
l.append('') | ||
l.append('</fmiModelDescription>') | ||
|
||
for sc, sv, ec, ev in configuration['connections']: | ||
data['connections'].append({ | ||
'type': component_map[sc][1][sv].type, | ||
'startComponent': component_map[sc][0], | ||
'endComponent': component_map[ec][0], | ||
'startValueReference': component_map[sc][1][sv].valueReference, | ||
'endValueReference': component_map[ec][1][ev].valueReference, | ||
}) | ||
|
||
with open(os.path.join(unzipdir, 'modelDescription.xml'), 'w') as f: | ||
f.write('\n'.join(l) + '\n') | ||
|
||
with open(os.path.join(unzipdir, 'resources', 'config.mp'), 'wb') as f: | ||
packed = msgpack.packb(data) | ||
f.write(packed) | ||
|
||
shutil.make_archive(base_filename, 'zip', unzipdir) | ||
|
||
if os.path.isfile(output_filename): | ||
os.remove(output_filename) | ||
|
||
os.rename(base_filename + '.zip', output_filename) | ||
|
||
shutil.rmtree(unzipdir, ignore_errors=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.dylib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
This FMU is part of FMPy and is released under the 2-Clause BSD license. | ||
Any contained FMUs and resources are subject to their respective licenses. | ||
|
||
Copyright (c) 2017-2020 Dassault Systemes. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
This FMU contains a copy of MPack (https://github.com/ludocode/mpack) in | ||
both binary and source form. It is license under the | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015-2018 Nicholas Fraser | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.