Giter Club home page Giter Club logo

fmusdk's Introduction


This repository has been archived. Development is continued on modelica/Reference-FMUs.


Travis CI AppVeyor

FMU SDK

The FMU SDK is a free software development kit provided by Synopsys. It demonstrates basic use of Functional Mockup Units (FMUs) as defined by the following Functional Mock-up Interface specifications for

The FMI specifications are available from here. A short overview on FMUs and the FMI specification can be found here. The FMU SDK can also serve as starting point for developing applications that create or process FMUs.

For each of the supported FMI versions (currently 1.0 and 2.0), the FMU SDK contains the C sources for various discrete and continuous FMU models, a batch file for compiling and zipping these models, an XML parser for parsing the model description of an FMU and two simple simulation programs that run a given FMU and output the result as CSV file.

For bug reports, questions or contributions regarding the FMU SDK, please follow the contribution guide.

FMUs

Installing the FMU SDK

The FMU SDK runs on all 32 bit and 64 bit Windows platforms, Linux and Mac OS X platforms. Download the FMU SDK from here, and unzip the file in a directory where you have write access. That directory is called FMUSDK_HOME below and may contain white space, such as in C:/Program Files/fmusdk. The FMU SDK contains only the C sources of the FMUs and the simulators, not the executables, and should compile on all Windows, Linux and Mac OS X platforms.

To build Windows 32 bit versions of all FMUs and simulators of the FMU SDK, double click on FMUSDK_HOME/install.bat. This should create fmus in FMUSDK_HOME/fmu10/fmu and FMUSDK_HOME/fmu20/fmu, as well as four simulators in FMUSDK_HOME/fmu10/bin/win32 and FMUSDK_HOME/fmu20/bin/win32.

To build Windows 64 bit versions of all FMUs and simulators, open a command shell and run install -win64. This creates additional fmus in the win64 subdirectories in FMUSDK_HOME/fmu10/fmu and FMUSDK_HOME/fmu20/fmu, as well as additional simulators in FMUSDK_HOME/fmu10/bin/win64 and FMUSDK_HOME/fmu20/bin/win64. Building these 64 bit versions works also on 32 bit Windows platforms. Execution of the 64 bit simulators and fmus requires however a 64 bit version of Windows.

Compilation using install.bat requires that you have installed one of Microsoft Visual Studio 2005 (VS8), 2008 (VS9), 2010 (VS10), 2012 (VS11), 2013 (VS12) or 2015 (VS14), for example the free Express Edition. To compile with another compiler, adapt the batch files.

To build Linux or Mac OS X binaries of all FMUs and simulators, open command shell and run make. The build requires that you have installed the C and C++ compilers, libexpat and libxml2 libraries. To install these dependencies on Linux you can use a package manager like sudo apt install g++, sudo apt install libexpat1-dev, sudo apt install libxml2-dev.

Building the FMUs with CMake

Install CMake 3.2 or later, open a command line and change into the folder where you've cloned or extracted the FMU SDK.

On Mac and Linux enter

mkdir build
cd build
cmake -G "Unix Makefiles" ..
make

on Windows enter

mkdir build
cd build
cmake -G "Visual Studio 14 2015 Win64" ..
msbuild FMUSDK.sln

which builds all FMUs into the dist folder. To get a list of the available generators enter

cmake --help

Alternatively you can use CMake's graphical user interface to generate the build pipeline.

Simulating an FMU

On Windows, to run a given FMU with one of the FMU simulators, open a command shell in directory FMUSDK_HOME and run the command fmusim

fmusim simulator model.fmu [tEnd [h [loggingOn [csvSeparator]]]] [-win64]
  simulator ..... cs10 or cs20 for co-simulation, me10 or me20 for model exchange, required
  model.fmu ..... path to FMU, relative to current dir or absolute, required
  tEnd .......... end  time of simulation, optional, defaults to 1.0 sec
  h ............. step size of simulation, optional, defaults to 0.1 sec
  loggingOn ..... 1 to activate logging,   optional, defaults to 0
  csvSeparator .. c for comma, s for semicolon, optional, defaults to c
  -win64 ........ to use a 64 bit simulator. By default, the 32 bit version is

This unzips the given FMU, parses the contained modelDescription.xml file, simulates the FMU from t=0 to t=tEnd, and writes the solution to file result.csv. The file is written in CSV format (comma-separated values), using ; to separate columns and using , instead of . as decimal dot to print floating-point numbers. To change the result file format, use the CSV separator option. The logging option activates logging of the simulated FMU. The FMI specification does not specify, what exactly to log in this case. However, when logging is switched on, the sample FMUs of the FMU SDK log every single FMU function call. Moreover, the fmusim simulators log every step and every event that is detected.

Example command:

fmusim me10 fmu10/fmu/me/win32/bouncingBall.fmu 5 0.1 0 s

parse C:\Users\tirea\AppData\Local\Temp\fmu\modelDescription.xml
fmiModelDescription
  fmiVersion=1.0
  modelName=bouncingBall
  modelIdentifier=bouncingBall
  guid={8c4e810f-3df3-4a00-8276-176fa3c9f003}
  numberOfContinuousStates=2
  numberOfEventIndicators=1
FMU Simulator: run 'fmu10/fmu/me/win32/bouncingBall.fmu' from t=0..5 with step size h=0.1, loggingOn=0, csv separator=';'
Simulation from 0 to 5 terminated successful
  steps ............ 51
  fixed step size .. 0.1
  time events ...... 0
  state events ..... 10
  step events ...... 0
CSV file 'result.csv' written

On Linux and Mac OS X get inspired by run_all target inside FMUSDK_HOME/makefile.

To plot the result file, open it e.g. in a spread-sheet program, such as Miscrosoft Excel or OpenOffice Calc. The figure below shows the result of the above simulation when plotted using OpenOffice Calc 3.0. Note that the height h of the bouncing ball as computed by fmusim becomes negative at the contact points, while the true solution of the FMU does actually not contain negative height values. This is not a limitation of the FMU, but of fmusim_me, which does not attempt to locate the exact time of state events. To improve this, either reduce the step size or add your own procedure for state-event location to fmusim_me.

FMUs

Creating your own FMUs

The FMU SDK contains a few sample FMUs

  • dq the Dahlquist test function x = -k der(x)
  • inc increments an integer counter every second
  • values demonstrates the use of all scalar FMU data types
  • vanDerPol ODE with 2 continuous states
  • bouncingBall a bouncing ball that defines state events

To implement your own FMU using the FMU SDK, create a directory - say xy - in FMUSDK_HOME/fmu10/src/models, or FMUSDK_HOME/fmu20/src/models, and create files xy.c there. The name of the new directory and of the .c file must be the same. The content of the .c file should follow the existing FMU examples, see the comments in the example code. Add file modelDescription_cs.xml used for co-simulation and modelDescription_me.xml used for model-exchange. When done with editing xy.c and the xml files, open a command shell in FMUSDK_HOME/fmu10/src/models or in FMUSDK_HOME/fmu20/src/models to run the build command.

On Windows, run command build_fmu me xy to build an FMU for model-exchange, or build_fmu cs xy to build an FMU for co-simulation. This should create a 32 bit FMU file xy.fmu in the corresponding subdirectory of FMUSDK_HOME/fmu10 or FMUSDK_HOME/fmu20. To build a 64-bit FMU, append option -win64 to the build command. For Linux and Mac OS X get inspired by all target inside FMUSDK_HOME/fmu10/src/models/makefile and FMUSDK_HOME/fmu20/src/models/makefile.

The figure below might help to create or process the XML file modelDescription.xml. It shows all XML elements (without attributes) used in the schema files (XSD) for model exchange and co-simulation 1.0. Notation: UML class diagram.

FMI 1.0 XML schema

For the case of FMU 2.0, see the corresponding overview figure in the FMI specification 2.0.

Release notes

07.02.2010, Version 1.0

  • First release
  • demo FMI for Model Exchange 1.0

05.03.2010, Version 1.0.1

  • demo FMI for Model Exchange 1.0
  • bug-fix in fmuTemplate.c: fmiSetString now copies the passed string argument and fmiFreeModelInstance frees all string copies
  • fmusim/main.c: removed strerror(GetLastError()) from error messages

22.08.2011, Version 1.0.2

  • demo FMI for Model Exchange 1.0 and FMI for Co-Simulation 1.0
  • added support for FMI for Co-Simulation 1.0 (standalone, no tool coupling)
  • bug-fix in fmusim/main.c: added missing calls to fmiTerminate and fmiFreeModelInstance

07.03.2014, Version 2.0.0

  • demo FMI for versions 1.0 and 2.0 RC1
  • added support for FMI 2.0 RC1
  • added 64 bit support
  • more compilers recognized by the installer

16.04.2014, Version 2.0.1

  • bug-fix in modelDescription.xml files: remove alias parameter, add derivative attribute to suitable variables
  • bug-fix in fmu20/fmuTemplate.c: allow modules to request termination of simulation, better time event handling, initialize() moved from fmiEnterInitialization to fmiExitInitialization, correct logging message format in fmiDoStep
  • bug-fix in Co-Simulation and Model Exchange simulators: set fmu location for 1.0 and fmu resources location for 2.0 at instantiation of model

02.07.2014, Version 2.0.2

  • added support for FMI 2.0 RC2
  • remove support for exporting FMI 2.0 RC1. Co-Simulation and Model Exchange simulators still support FMI 2.0 RC1
  • fmi2setDebugLogging called with 0 categories, set all categories to loggingOn value

27.08.2014, Version 2.0.3

  • track all states of Model-exchange and Co-simulation and check the allowed calling sequences for FMI 2.0
  • added explicit 'isTimeEvent' parameter for eventUpdate function in the user's models
  • lazy computation of computed values
  • bug-fix in modelDescription.xml: set initial attribute to local and output variables, add unknown variables in section

20.10.2015, Version 2.0.4

  • added explicit 'isNewEventIteration' parameter for eventUpdate function in the user's models
  • bouncingBall example improvement: demonstrate tunable parameters, avoid 'fall through effect' due to numerical calculation
  • bug-fix: allow to declare real variables and zero states in a model
  • bug-fix: allow to simulate FMI 2.0 RC1 models
  • bug-fix: remove memory leaks and compilation warnings

8.12.2017, Version 2.0.5

  • added support for Linux and Mac OS X. Thanks to @cxbrooks
  • added support for building with Microsoft VS 2015
  • location of simulators changes to FMUSDK_HOME\fmu10\bin and FMUSDK_HOME\fmu20\bin instead of FMUSDK_HOME\bin
  • fmu20 build define DISABLE_PREFIX to not use prefixed FMI functions
  • fmu20 models declare source files in ModelDescription.xml
  • log error messages regardless of loggingOn flag when functions return fmi2Error
  • bug-fix: allow to declare real variables and zero states

20.07.2018, Version 2.0.6

  • update libxml2.lib to work for windows 7 and Visual Studio 2013 and 2015
  • linux - give exec right to build_fmu.sh before executing it
  • copy .h model files with rsync to avoid missing file error

License

The FMU SDK is provided by Synopsys under the BSD 2-Clause License.

The following additional tools are distributed with the FMU SDK under their respective licenses:

The contribution guide is adapted from normalize.css (MIT License) and chris.beams.io

fmusdk's People

Contributors

adriantirea avatar andreas-junghanns avatar beutlich avatar panswering avatar t-sommer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fmusdk's Issues

unable to make in mac os

here are errors

rsync error: syntax or usage error (code 1) at /System/Volumes/Data/SWE/macOS/BuildRoots/e90674e518/Library/Caches/com.apple.xbs/Sources/rsync/rsync-55/rsync/main.c(1337) [client=2.6.9]
make[4]: *** [bouncingBall.fmu] Error 1
rm bouncingBall.o bouncingBall.dylib
make[3]: *** [all] Error 2
make[2]: *** [all] Error 2
make[1]: *** [all] Error 2
make: *** [all] Error 2

64-bit build does not work for Windows w/MSVS 2017

Not supporting MSVS 2017 for new users seems cruel:


Making the simulators and models for FMI 2.0 of the FmuSDK ...

building fmusim_me.exe - FMI for Model Exchange 2.0

The specified configuration type is missing. The tools for the
configuration might not be installed.
main.c
sim_support.c
xmlVersionParser.c
Generating Code...
Compiling...
XmlParser.cpp
XmlElement.cpp
XmlParserCApi.cpp
Generating Code...
xmlVersionParser.obj : error LNK2019: unresolved external symbol _xmlFreeTextReader referenced in function _streamFile
XmlParser.obj : error LNK2001: unresolved external symbol _xmlFreeTextReader
xmlVersionParser.obj : error LNK2019: unresolved external symbol _xmlTextReaderRead referenced in function _readNextInXml
XmlParser.obj : error LNK2001: unresolved external symbol _xmlTextReaderRead
xmlVersionParser.obj : error LNK2019: unresolved external symbol _xmlTextReaderNodeType referenced in function _readNextInXml
XmlParser.obj : error LNK2001: unresolved external symbol _xmlTextReaderNodeType
xmlVersionParser.obj : error LNK2019: unresolved external symbol _xmlTextReaderConstLocalName referenced in function _streamFile
XmlParser.obj : error LNK2001: unresolved external symbol _xmlTextReaderConstLocalName
xmlVersionParser.obj : error LNK2019: unresolved external symbol _xmlTextReaderGetAttribute referenced in function _extractFmiVersionAttribute
xmlVersionParser.obj : error LNK2019: unresolved external symbol _xmlReaderForFile referenced in function _streamFile
XmlParser.obj : error LNK2001: unresolved external symbol _xmlReaderForFile
xmlVersionParser.obj : error LNK2019: unresolved external symbol _xmlFree referenced in function _extractFmiVersionAttribute
XmlParser.obj : error LNK2001: unresolved external symbol _xmlFree
XmlParser.obj : error LNK2019: unresolved external symbol _xmlTextReaderDepth referenced in function __catch$?parseElementAttributes@XmlParser@@QAEXPAVElement@@_N@Z$0
XmlParser.obj : error LNK2019: unresolved external symbol _xmlTextReaderIsEmptyElement referenced in function __catch$?parseElementAttributes@XmlParser@@QAEXPAVElement@@_N@Z$0
XmlParser.obj : error LNK2019: unresolved external symbol _xmlTextReaderName referenced in function __catch$?parse@XmlParser@@QAEPAVModelDescription@@xz$1
XmlParser.obj : error LNK2019: unresolved external symbol _xmlTextReaderValue referenced in function __catch$?parse@XmlParser@@QAEPAVModelDescription@@xz$1
XmlParser.obj : error LNK2019: unresolved external symbol _xmlTextReaderMoveToNextAttribute referenced in function __catch$?parse@XmlParser@@QAEPAVModelDescription@@xz$1
..\shared\parser\win64\libxml2.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
fmusim_me.exe : fatal error LNK1120: 12 unresolved externals
build of fmusim_me.exe failed
done.

Example Command incorrect for Windows

The command in the example omits a directory level.

The command as given:

fmusim me10 fmu10/fmu/me/bouncingBall.fmu 5 0.1 0 s

For win32 it should be:

fmusim me10 fmu10/fmu/me/win32/bouncingBall.fmu 5 0.1 0 s

Generated FMU 1.0 ME with zero states fails the FMU Checker 2.0.4

If the generated FMU 1.0 ME has zero states (as for example in

#define NUMBER_OF_STATES 0
) it fails the FMU compliance checker 2.0.4 when calling fmiSetContinuousStates/fmiGetStateValueReferences/fmiGetContinuousStates/fmiGetNominalContinuousStates/fmiGetDerivatives with a NULL pointer as state vector.

[VERBOSE][FMICAPI] Calling fmiInitialize
	[FMU][log][FMU status:OK] fmiInitialize: toleranceControlled=0 relativeTolerance=0.0001
	[FMU][error][FMU status:Error] fmiGetContinuousStates: Invalid argument states[] = NULL.
[FATAL][FMUCHK] Failed to initialize FMU for simulation (FMU status: Error)
[FATAL][FMUCHK] Simulation loop terminated at time 0 since FMU returned status: Error
	[FMU][error][FMU status:Error] fmiTerminate: Illegal call sequence.
[ERROR][FMUCHK] fmiTerminate returned status: Error

inc.zip

Not able to run install.bat file with visual studio March 2019 (Version 1.33)

Hello,
Not able to run the install.bat file , Ending up with following error

  1. No Microsoft Visual C compiler found ( Installed in system visual studio March 2019 (Version 1.33))
  2. The system cannot find the path specified.'build_all' is not recognized as an internal or external command,operable program or batch file.
    Kindly let me know any supporting tools required, to run the batch file

Thankyou in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.