Skip to content

Commit

Permalink
Initial cut at port to fmusdk1.0.2 from http://www.qtronic.de/doc/fmu…
Browse files Browse the repository at this point in the history
  • Loading branch information
cxbrooks committed Feb 20, 2012
1 parent 559c37f commit 61478a5
Show file tree
Hide file tree
Showing 98 changed files with 5,822 additions and 4,393 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
all:
(cd src; $(MAKE))

clean:
(cd src; $(MAKE) clean)

distclean: clean
rm -f bin/fmusim_cs* bin/fmusim_me*
rm -rf fmu
find . -name "*~" -exec rm {} \;
find . -name "#*~" -exec rm {} \;
Binary file added binaries/win32/MIMO_0dymola.dll
Binary file not shown.
Binary file added binaries/win32/MIMO_0dymola.lib
Binary file not shown.
104 changes: 75 additions & 29 deletions doc/FmuSdk_reference.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
<html>
<head>
<title>Documentation for FMU SDK 1.0</title>
<title>Documentation for FMU SDK 1.0.2</title>
<style type="text/css">
html { font-family: Verdana, Arial, Helvetica, sans-serif; }
h1,h2,h3 { color: #000066; }
</style>
</head>
<body>
<h1>FMU SDK 1.0</h1>
<h1>FMU SDK 1.0.2</h1>
The FMU SDK is a free software development kit provided by
<a href="http://www.qtronic.de" target="_blank">QTronic</a>.
The FMU SDK demonstrates basic use of Functional Mockup Units (FMUs)
as defined by the
<a href="http://www.functional-mockup-interface.org/fmi.html"
target="_blank">FMI Specification 1.0</a>.
as defined by the following specifications
<ul>
<li>Functional Mock-up Interface for <a href=
"http://www.functional-mockup-interface.org/specifications/FMI_for_ModelExchange_v1.0.pdf"
target="_blank">Model Exchange 1.0</a> (January 26, 2010)</li>
<li>Functional Mock-up Interface for <a href=
"http://www.functional-mockup-interface.org/specifications/FMI_for_CoSimulation_v1.0.pdf"
target="_blank">Co-Simulation 1.0</a> (October 12, 2010)</li>
</ul>
The FMI specifications are available from
<a href="http://www.functional-mockup-interface.org/fmi.html" target="_blank">here</a>.
A short overview on FMUs and the FMI specification can be found
<a href="http://www.qtronic.de/doc/fmi_overview.pdf" taget="_blank">here</a>.
The FMU SDK can also serve as starting point for developing applications
that create or process FMUs.
<p>
The FMU SDK contains the C sources for various discrete and continuous
FMU models, a batch file for compiling and zip'ing these models,
an XML parser for parsing the model description of an FMU and a simple
simulation program that runs a given FMU and outputs the result as CSV file.
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.
<p>
The FMU SDK can be downloaded from
<a href="http://www.qtronic.de/doc/fmusdk.zip">
Expand All @@ -45,28 +53,29 @@ <h2>Table of Contents</h2>

<hr />
<h2><a name="installation">Building and Installing the FMU SDK</a></h2>
Downwload the FMU SDK from <a href="http://www.qtronic.de/products/fmusdk.zip">here</a>,
Downwload the FMU SDK from <a href="http://www.qtronic.de/doc/fmusdk.zip">here</a>,
and unzip 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 an the simulator, not the executables,
The FMU SDK contains only the C sources of the FMUs and the simulator, not the executables,
and should compile on all Windows platforms.
<p/>
To build the FMUs and the simulator, double click on FMUSDK_HOME\source\build_all.bat.
This should create files FMUSDK_HOME\fmu\*.fmu and the simulator FMUSDK_HOME\bin\fmusim.exe.
To build the FMUs and the simulator, double click on FMUSDK_HOME\src\build_all.bat.
This should create fmu files in FMUSDK_HOME\fmu\me and FMUSDK_HOME\fmu\cs, as well as two
simulators fmusim_me.exe and fmusim_cs.exe in FMUSDK_HOME\bin.
Compilation using build_all.bat requires that you have installed
Microsoft Visual Studio 2005 (VS8) or 2008 (VS9), for example the free Express Edition.
To compile with another compiler, adapt file build_all.bat.
<hr />
<h2><a name="simulation">Simulating an FMU</a></h2>
To run one of the FMUs in FMUSDK_HOME\fmu, open a command shell in directory
FMUSDK_HOME and run the command fmusim
To run a given FMU, open a command shell in directory FMUSDK_HOME and run the command fmusim
<pre>
fmusim model.fmu tEnd h loggingOn csvSeparator
fmusim fmi model.fmu tEnd h loggingOn csvSeparator
fmi ........... cs for co-simulation or me 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 .. column separator char in csv file, optional, defaults to ';'
csvSeparator .. c for comma, s for semicolon, optional, defaults to c
</pre>
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
Expand All @@ -76,11 +85,11 @@ <h2><a name="simulation">Simulating an FMU</a></h2>
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 simulator logs every step and every event that is detected.
fmusim simulators logs every step and every event that is detected.
<p/>
Example command:
<pre>
&gt; fmusim fmu/bouncingBall.fmu 5 0.1 0 ;
&gt; fmusim me fmu/me/bouncingBall.fmu 5 0.1 0 s
FMU Simulator: run 'fmu/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
Expand All @@ -94,37 +103,74 @@ <h2><a name="simulation">Simulating an FMU</a></h2>
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, which does not attempt to locate the
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.
To improve this, either reduce the step size or add your own procedure for state-event location to fmusim_me.
<p/>
<img src="bouncingBallCalc.png">

<hr />
<h2><a name="creating_fmus">Creating your own FMUs</a></h2>
The FMU SDK contains a few sample FMUs
<ul>
<li><a href="../source/dq/_main.html">dq</a> the Dahlquist test function x = -k der(x)</li>
<li><a href="../source/inc/_main.html">inc</a> increments an integer counter every second</li>
<li><a href="../source/values/_main.html">values</a> demonstrates the use of all scalar FMU data types</li>
<li><a href="../source/bouncingBall/_main.html">bouncingBall</a> a bouncing ball that defines state events</li>
<li><a href="../src/models/dq/_main.html">dq</a> the Dahlquist test function x = -k der(x)</li>
<li><a href="../src/models/inc/_main.html">inc</a> increments an integer counter every second</li>
<li><a href="../src/models/values/_main.html">values</a> demonstrates the use of all scalar FMU data types</li>
<li><a href="../src/models/vanDerPol/_main.html">vanDerPol</a> ODE with 2 continuous states</li>
<li><a href="../src/models/bouncingBall/_main.html">bouncingBall</a> a bouncing ball that defines state events</li>
</ul>
To implement your own FMU using the FMU SDK, create a directory - say xy - in FMUSDK_HOME\source, and create
files modelDescription.xml and xy.c there.
To implement your own FMU using the FMU SDK, create a directory - say xy - in FMUSDK_HOME\src\models, and create
files modelDescription.xml and xy.c there.
The names of the new directory and 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.
When done with editing the xml file and xy.c, open a command shell in FMUSDK_HOME\source
and run the command <code>build_fmu xy</code>.
This should create the FMU file xy.fmu in directory FMUSDK_HOME\fmu.
The XML file must not contain the <code>&lt;implementation&gt;</code>
element and the closing <code>&lt/fmiModelDescription&gt;</code> tag, because this is added automatically during build.
When done with editing the xml file and xy.c, open a command shell in FMUSDK_HOME\src\model and run the
command <code>build_fmu me xy</code> to build an FMU for model exchange, or <code>build_fmu cs xy</code> to build an FMU for co-simulation.
This should create the FMU file xy.fmu in directory FMUSDK_HOME\fmu\me or FMUSDK_HOME\fmu\cs.
<p>
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. Notation: UML class diagram.
<img src="fmu10-xml-schema.png">

<hr />

<h2>FMU SDK Revision history</h2>
<ul>
<li>07.02.2010, Version 1.0
<ul>
<li>First release</li>
<li>demo FMI for Model Exchange 1.0</li>
</ul>
</li>
<li>05.03.2010, Version 1.0.1
<ul>
<li>demo FMI for Model Exchange 1.0</li>
<li>bug-fix in fmuTemplate.c: fmiSetString now copies the passed
string argument and fmiFreeModelInstance frees all string copies
</li>
<li>fmusim/main.c: removed strerror(GetLastError()) from error messages
</li>
</ul>
</li>
<li>22.08.2011, Version 1.0.2
<ul>
<li>demo FMI for Model Exchange 1.0 and FMI for Co-Simulation 1.0</li>
<li>added support for FMI for Co-Simulation 1.0 (standalone, no tool coupling)</li>
<li>bug-fix in fmusim/main.c: added missing calls to fmiTerminate and fmiFreeModelInstance</li>
</ul>
</li>
</ul>

<h2><a name="license">License conditions</a></h2>
The FMU SDK is provided by QTronic under the
<a href="http://www.opensource.org/licenses/bsd-license.html">BSD License</a>.
<hr/>
<pre>
FMU SDK license

Copyright © 2008-2010, QTronic GmbH. All rights reserved.
Copyright © 2008-2011, QTronic GmbH. All rights reserved.
The FmuSdk is licensed by the copyright holder under the BSD License
(http://www.opensource.org/licenses/bsd-license.html):
Redistribution and use in source and binary forms, with or without
Expand Down
Binary file added doc/fmu10-xml-schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/fmusdk_license.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

FMU SDK license

Copyright � 2008-2010, QTronic GmbH. All rights reserved.
Copyright � 2008-2011, QTronic GmbH. All rights reserved.
The FmuSdk is licensed by the copyright holder under the BSD License
(http://www.opensource.org/licenses/bsd-license.html):
Redistribution and use in source and binary forms, with or without
Expand Down
35 changes: 35 additions & 0 deletions fmusim
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
# Run a co-simulation or model exchange fmu file
# Usage: fmusim cs|me model.fmu

if [ $# -ne 6 ]; then
cat <<EoF
Usage: $0 fmi model.fmu tEnd h loggingOn csvSeparator
fmi ........... cs for co-simulation or me 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
Try:
$0 me fmu/me/bouncingBall.fmu 5 0.1 0 s
EoF
exit 2
fi

csOrMe=$1
fmuFile=$2

# Error checking
if [ "$csOrMe" != "me" -a "$csOrMe" != "cs" ]; then
echo "$0: first argument must be either 'me' or 'cs', not $csOrMe"
exit 3
fi

if [ ! -f $fmuFile ]; then
echo "$0: file '$fmuFile' does not exist?"
exit 4
fi

set -x
bin/fmusim_${csOrMe} $2 $3 $4 $5 $6
7 changes: 3 additions & 4 deletions fmusim.bat
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
@echo off
rem ------------------------------------------------------------
rem To run a simulation, start this batch in this directory.
rem Example: fmusim fmu/dq.fmu 0.3 0.1 1
rem To build bin\fmusim.exe
rem and the demo FMUs, run source\build_all.bat
rem Example: fmusim me fmu/me/dq.fmu 0.3 0.1 1 c
rem To build simulators bin\*.exe and FMUs, run src\build_all.bat
rem ------------------------------------------------------------

set FMUSDK_HOME=.
bin\fmusim.exe %1 %2 %3 %4
if %1==me (bin\fmusim_me.exe %2 %3 %4 %5 %6) else bin\fmusim_cs.exe %2 %3 %4 %5 %6
50 changes: 50 additions & 0 deletions run_all.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@echo off

rem ------------------------------------------------------------
rem This batch simulates all FMUs of the FmuSDK and stores
rem simulation results in CSV files, one per simulation run.
rem (c) 2011 QTronic GmbH
rem ------------------------------------------------------------

echo -----------------------------------------------------------
echo Runnig all FMUs of the FmuSDK ...

echo -----------------------------------------------------------
call fmusim me fmu\me\bouncingBall.fmu 4 0.01 0 c
move /Y result.csv result_me_bouncingBall.csv

echo -----------------------------------------------------------
call fmusim cs fmu\cs\bouncingBall.fmu 4 0.01 0 c
move /Y result.csv result_cs_bouncingBall.csv

echo -----------------------------------------------------------
call fmusim me fmu\me\vanDerPol.fmu 5 0.1 0 c
move /Y result.csv result_me_vanDerPol.csv

echo -----------------------------------------------------------
call fmusim cs fmu\cs\vanDerPol.fmu 5 0.1 0 c
move /Y result.csv result_cs_vanDerPol.csv

echo -----------------------------------------------------------
call fmusim me fmu\me\dq.fmu 1 0.1 0 c
move /Y result.csv result_me_dq.csv

echo -----------------------------------------------------------
call fmusim cs fmu\cs\dq.fmu 1 0.1 0 c
move /Y result.csv result_cs_dq.csv

echo -----------------------------------------------------------
call fmusim me fmu\me\inc.fmu 15 15 0 c
move /Y result.csv result_me_inc.csv

echo -----------------------------------------------------------
call fmusim cs fmu\cs\inc.fmu 15 0.5 0 c
move /Y result.csv result_cs_inc.csv

echo -----------------------------------------------------------
call fmusim me fmu\me\values.fmu 12 12 0 c
move /Y result.csv result_me_values.csv

echo -----------------------------------------------------------
call fmusim cs fmu\cs\values.fmu 12 0.3 0 c
move /Y result.csv result_cs_values.csv
39 changes: 0 additions & 39 deletions source/Makefile

This file was deleted.

50 changes: 0 additions & 50 deletions source/Makefile.macosx

This file was deleted.

3 changes: 0 additions & 3 deletions source/bouncingBall/Makefile

This file was deleted.

Loading

0 comments on commit 61478a5

Please sign in to comment.