FmuSdk_reference.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <html>
  2. <head>
  3. <title>Documentation for FMU SDK 2.0.4</title>
  4. <style type="text/css">
  5. html { font-family: Verdana, Arial, Helvetica, sans-serif; }
  6. h1,h2,h3 { color: #000066; }
  7. </style>
  8. </head>
  9. <body>
  10. <h1>FMU SDK 2.0.4</h1>
  11. The FMU SDK is a free software development kit provided by
  12. <a href="http://www.qtronic.de" target="_blank">QTronic</a>.
  13. The FMU SDK demonstrates basic use of Functional Mockup Units (FMUs)
  14. as defined by the following specifications
  15. <ul>
  16. <li>Functional Mock-up Interface for <a href=
  17. "https://svn.modelica.org/fmi/branches/public/specifications/v2.0/FMI_for_ModelExchange_and_CoSimulation_v2.0.pdf"
  18. target="_blank">Model Exchange and Co-Simulation 2.0</a> (July 25, 2014)</li>
  19. <li>Functional Mock-up Interface for <a href=
  20. "https://svn.modelica.org/fmi/branches/public/specifications/v1.0/FMI_for_ModelExchange_v1.0.pdf"
  21. target="_blank">Model Exchange 1.0</a> (January 26, 2010)</li>
  22. <li>Functional Mock-up Interface for <a href=
  23. "https://svn.modelica.org/fmi/branches/public/specifications/v1.0/FMI_for_CoSimulation_v1.0.pdf"
  24. target="_blank">Co-Simulation 1.0</a> (October 12, 2010)</li>
  25. </ul>
  26. The FMI specifications are available from
  27. <a href="https://fmi-standard.org/downloads" target="_blank">here</a>.
  28. A short overview on FMUs and the FMI specification can be found
  29. <a href="http://www.qtronic.de/doc/fmi_overview.pdf" target="_blank">here</a>.
  30. The FMU SDK can also serve as starting point for developing applications
  31. that create or process FMUs.
  32. <p>
  33. For each of the supported FMI versions (currently 1.0 and 2.0),
  34. the FMU SDK contains the C sources for various discrete and continuous
  35. FMU models, a batch file for compiling and zip'ing these models,
  36. an XML parser for parsing the model description of an FMU and two simple
  37. simulation programs that run a given FMU and output the result as CSV file.
  38. <p>
  39. The FMU SDK 2.0.4 can be downloaded from
  40. <a href="http://www.qtronic.de/doc/fmusdk.zip">
  41. http://www.qtronic.de/doc/fmusdk.zip</a>.
  42. For bug reports, questions or comments regarding the FMU SDK, please
  43. mail to <a href="mailto:fmu@qtronic.de">fmu@qtronic.de</a>.
  44. Questions or comments regarding the FMU specification should be sent to
  45. <a href="mailto:info@functional-mockup-interface.org">info@functional-mockup-interface.org</a>.
  46. <img src="fmus.jpg">
  47. <hr />
  48. <h2>Table of Contents</h2>
  49. <ul>
  50. <li><a href="#installation">Building and Installing the FMU SDK</a></li>
  51. <li><a href="#simulation">Simulating an FMU</a></li>
  52. <li><a href="#creating_fmus">Creating your own FMUs</a></li>
  53. <li><a href="#revisions">FMU SDK Revision history</a></li>
  54. <li><a href="#license">License conditions</a></li>
  55. </ul>
  56. <hr />
  57. <h2><a name="installation">Installing the FMU SDK</a></h2>
  58. The FMU SDK runs on all 32 bit and 64 bit Windows platforms, starting from Windows XP.
  59. Downwload the FMU SDK from <a href="http://www.qtronic.de/doc/fmusdk.zip">here</a>,
  60. and unzip the file in a directory where you have write access.
  61. That directory is called FMUSDK_HOME below and may contain white space, such as in "C:\Program Files\fmusdk".
  62. The FMU SDK contains only the C sources of the FMUs and the simulators, not the executables,
  63. and should compile on all Windows platforms.
  64. <p/>
  65. To build 32 bit versions of all FMUs and simulators of the FMU SDK,
  66. double click on FMUSDK_HOME\install.bat.
  67. This should create fmus in FMUSDK_HOME\fmu10\fmu and FMUSDK_HOME\fmu20\fmu, as well as four
  68. simulators in FMUSDK_HOME\bin.
  69. <p/>
  70. To build 64 bit versions of all FMUs and simulators, open a command shell an run "install -win64".
  71. This creates additional fmus in the x64 subdirectories in FMUSDK_HOME\fmu10\fmu and FMUSDK_HOME\fmu20\fmu, as well
  72. as additional simulators in FMUSDK_HOME\bin\x64. Building these 64 bit versions works also on 32 bit
  73. Windows platforms. Execution of the 64 bit simulators and fmus requires however a 64 bit version of Windows.
  74. <p/>
  75. Compilation using install.bat requires that you have installed one of
  76. Microsoft Visual Studio 2005 (VS8), 2008 (VS9), 2010 (VS10), or 2012 (VS11),
  77. for example the free Express Edition.
  78. To compile with another compiler, adapt the batch files.
  79. <hr />
  80. <h2><a name="simulation">Simulating an FMU</a></h2>
  81. To run a given FMU with one of the FMU simulators, open a command shell in
  82. directory FMUSDK_HOME and run the command fmusim
  83. <pre>
  84. fmusim simulator model.fmu [tEnd [h [loggingOn [csvSeparator]]]] [-win64]
  85. simulator ..... cs10 or cs20 for co-simulation, me10 or me20 for model exchange, required
  86. model.fmu ..... path to FMU, relative to current dir or absolute, required
  87. tEnd .......... end time of simulation, optional, defaults to 1.0 sec
  88. h ............. step size of simulation, optional, defaults to 0.1 sec
  89. loggingOn ..... 1 to activate logging, optional, defaults to 0
  90. csvSeparator .. c for comma, s for semicolon, optional, defaults to c
  91. -win64 ........ to use a 64 bit simulator. By default, the 32 bit version is used
  92. </pre>
  93. This unzips the given FMU, parses the contained modelDescription.xml file, simulates
  94. the FMU from t=0 to t=tEnd, and writes the solution to file 'result.csv'. The file
  95. is written in CSV format (comma-separated values), using ';' to separate columns and
  96. using ',' instead of '.' as decimal dot to print floating-point numbers.
  97. To change the result file format, use the 'csv separator' option.
  98. The logging option activates logging of the simulated FMU. The FMI specification does
  99. not specify, what exactly to log in this case. However, when logging is switched on,
  100. the sample FMUs of the FMU SDK log every single FMU function call. Moreover, the
  101. fmusim simulators log every step and every event that is detected.
  102. <p/>
  103. Example command:
  104. <pre>
  105. &gt; fmusim me10 fmu10/fmu/me/bouncingBall.fmu 5 0.1 0 s
  106. FMU Simulator: run 'fmu/bouncingBall.fmu' from t=0..5 with step size h=0.1, loggingOn=0, csv separator=';'
  107. Simulation from 0 to 5 terminated successful
  108. steps ............ 51
  109. fixed step size .. 0.1
  110. time events ...... 0
  111. state events ..... 14
  112. step events ...... 0
  113. CSV file 'result.csv' written
  114. </pre>
  115. To plot the result file, open it e.g. in a spread-sheet program, such as Miscrosoft Excel or OpenOffice Calc.
  116. The figure below shows the result of the above simulation when plotted using OpenOffice Calc 3.0.
  117. Note that the height h of the bouncing ball as computed by fmusim becomes negative at the contact points,
  118. while the true solution of the FMU does actually not contain negative height values.
  119. This is not a limitation of the FMU, but of fmusim_me, which does not attempt to locate the
  120. exact time of state events.
  121. To improve this, either reduce the step size or add your own procedure for state-event location to fmusim_me.
  122. <p/>
  123. <img src="bouncingBallCalc.png">
  124. <hr />
  125. <h2><a name="creating_fmus">Creating your own FMUs</a></h2>
  126. The FMU SDK contains a few sample FMUs
  127. <ul>
  128. <li><a href="../fmu20/src/models/dq/_main.html">dq</a> the Dahlquist test function x = -k der(x)</li>
  129. <li><a href="../fmu20/src/models/inc/_main.html">inc</a> increments an integer counter every second</li>
  130. <li><a href="../fmu20/src/models/values/_main.html">values</a> demonstrates the use of all scalar FMU data types</li>
  131. <li><a href="../fmu20/src/models/vanDerPol/_main.html">vanDerPol</a> ODE with 2 continuous states</li>
  132. <li><a href="../fmu20/src/models/bouncingBall/_main.html">bouncingBall</a> a bouncing ball that defines state events</li>
  133. </ul>
  134. To implement your own FMU using the FMU SDK, create a directory - say xy - in FMUSDK_HOME\fmu10\src\models,
  135. or FMUSDK_HOME\fmu20\src\models, and create files xy.c there.
  136. The name of the new directory and of the .c file must be the same.
  137. The content of the .c file should follow the existing FMU examples, see the comments in the example code.
  138. For FMI 1.0, add also file modelDescription.xml.
  139. The XML file must not contain the <code>&lt;implementation&gt;</code>
  140. element and the closing <code>&lt;fmiModelDescription&gt;</code> tag, because this is added automatically during build.
  141. For FMI 2.0, add file modelDescription_cs.xml and modelDescription_cs.xml.
  142. When done with editing xy.c and the xml file (or files), open a command shell in FMUSDK_HOME\fmu10\src\models
  143. or in FMUSDK_HOME\fmu20\src\models and run the
  144. command <code>build_fmu me xy</code> to build an FMU for model-exchange, or
  145. <code>build_fmu cs xy</code> to build an FMU for co-simulation.
  146. This should create a 32 bit FMU file xy.fmu in the corresponding subdirectory of FMUSDK_HOME\fmu10 or FMUSDK_HOME\fmu20
  147. To build a 64-bit FMU, append option -win64 to the build command.
  148. <p/>
  149. The figure below might help to create or process the XML file modelDescription.xml.
  150. It shows all XML elements (without attributes) used in the schema files (XSD) for
  151. model exchange and co-simulation 1.0. Notation: UML class diagram.
  152. <img src="fmu10-xml-schema.png">
  153. <br/>
  154. For the case of FMU 2.0, see the corresponding overview figure in the
  155. <a href="https://svn.modelica.org/fmi/branches/public/specifications/v2.0/FMI_for_ModelExchange_and_CoSimulation_v2.0.pdf"
  156. target="_blank">FMI specification 2.0</a>.
  157. <hr />
  158. <h2><a name="revisions">FMU SDK Revision history</a></h2>
  159. <ul>
  160. <li>07.02.2010, Version 1.0
  161. <ul>
  162. <li>First release</li>
  163. <li>demo FMI for Model Exchange 1.0</li>
  164. </ul>
  165. </li>
  166. <li>05.03.2010, Version 1.0.1
  167. <ul>
  168. <li>demo FMI for Model Exchange 1.0</li>
  169. <li>bug-fix in fmuTemplate.c: fmiSetString now copies the passed
  170. string argument and fmiFreeModelInstance frees all string copies
  171. </li>
  172. <li>fmusim/main.c: removed strerror(GetLastError()) from error messages
  173. </li>
  174. </ul>
  175. </li>
  176. <li>22.08.2011, Version 1.0.2
  177. <ul>
  178. <li>demo FMI for Model Exchange 1.0 and FMI for Co-Simulation 1.0</li>
  179. <li>added support for FMI for Co-Simulation 1.0 (standalone, no tool coupling)</li>
  180. <li>bug-fix in fmusim/main.c: added missing calls to fmiTerminate and fmiFreeModelInstance</li>
  181. </ul>
  182. </li>
  183. <li>07.03.2014, Version 2.0.0
  184. <ul>
  185. <li>demo FMI for versions 1.0 and 2.0 RC1</li>
  186. <li>added support for FMI 2.0 RC1</li>
  187. <li>added 64 bit support</li>
  188. <li>more compilers recognized by the installer</li>
  189. </ul>
  190. </li>
  191. <li>16.04.2014, Version 2.0.1
  192. <ul>
  193. <li>bug-fix in modelDescription.xml files: remove alias parameter, add derivative attribute to suitable variables</li>
  194. <li>bug-fix in fmu20/fmuTemplate.c: allow modules to request termination of simulation, better time event
  195. handling, initialize() moved from fmiEnterInitialization to fmiExitInitialization, correct logging message
  196. format in fmiDoStep</li>
  197. <li>bug-fix in Co-Simulation and Model Exchange simulators: set fmu location for 1.0 and fmu resources location
  198. for 2.0 at instantiation of model</li>
  199. </ul>
  200. </li>
  201. <li>02.07.2014, Version 2.0.2
  202. <ul>
  203. <li>added support for FMI 2.0 RC2</li>
  204. <li>remove support for exporting FMI 2.0 RC1. Co-Simulation and Model Exchange simulators still support FMI 2.0 RC1</li>
  205. <li>fmi2setDebugLogging called with 0 categories, set all categories to loggingOn value</li>
  206. </ul>
  207. </li>
  208. <li>27.08.2014, Version 2.0.3
  209. <ul>
  210. <li>track all states of Model-exchange and Co-simulation and check the allowed calling sequences for FMI 2.0</li>
  211. <li>added explicit 'isTimeEvent' parameter for eventUpdate function in the user's models</li>
  212. <li>lazy computation of computed values</li>
  213. <li>bug-fix in modelDescription.xml: set initial attribute to local and output variables,
  214. add unknown variables in &lt;ModelStructure&gt;&lt;InitialUnknowns&gt; section</li>
  215. </ul>
  216. </li>
  217. <li>20.10.2015, Version 2.0.4
  218. <ul>
  219. <li>added explicit 'isNewEventIteration' parameter for eventUpdate function in the user's models</li>
  220. <li>bouncingBall example improvement: demonstrate tunable parameters, avoid 'fall through effect' due to numerical calculation</li>
  221. <li>bug-fix: allow to declare real variables and zero states in a model</li>
  222. <li>bug-fix: allow to simulate FMI 2.0 RC1 models</li>
  223. <li>bug-fix: remove memory leaks and compilation warnings</li>
  224. </ul>
  225. </li>
  226. </ul>
  227. <h2><a name="license">License conditions</a></h2>
  228. The FMU SDK is provided by QTronic under the
  229. <a href="http://www.opensource.org/licenses/bsd-license.html">BSD License</a>.
  230. <hr/>
  231. <pre>
  232. FMU SDK license
  233. Copyright © 2008-2014, QTronic GmbH. All rights reserved.
  234. The FmuSdk is licensed by the copyright holder under the BSD License
  235. (http://www.opensource.org/licenses/bsd-license.html):
  236. Redistribution and use in source and binary forms, with or without
  237. modification, are permitted provided that the following conditions are met:
  238. - Redistributions of source code must retain the above copyright notice,
  239. this list of conditions and the following disclaimer.
  240. - Redistributions in binary form must reproduce the above copyright notice,
  241. this list of conditions and the following disclaimer in the documentation
  242. and/or other materials provided with the distribution.
  243. THIS SOFTWARE IS PROVIDED BY QTRONIC GMBH "AS IS" AND ANY EXPRESS OR
  244. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  245. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  246. IN NO EVENT SHALL QTRONIC GMBH BE LIABLE FOR ANY DIRECT, INDIRECT,
  247. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  248. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  249. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  250. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  251. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  252. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  253. </pre>
  254. <hr/>
  255. The following additional tools are distributed with the FMU SDK under their
  256. respective licenses
  257. <ul>
  258. <li><a href="http://www.7-zip.org" target="_blank">7z 4.57</a>
  259. by Igor Pavlov. Used here to zip and unzip FMUs,
  260. license is <a href="../bin/license.txt">here</a>.</li>
  261. <li><a href="http://sourceforge.net/projects/expat/" target="_blank">eXpat 2.0.1</a>
  262. by James Clark. Used here to parse the modelDescription.xml file of an FMU 1.0,
  263. license is <a href="../fmu10/src/shared/COPYING.txt">here</a>.</li>
  264. <li><a href="http://xmlsoft.org" target="_blank">libxml</a>,
  265. the XML C parser and toolkit of Gnome.
  266. Used here to parse the modelDescription.xml file of an FMU 2.0,
  267. license is <a href="../fmu20/src/shared/parser/libxml_license.txt">here</a>.</li>
  268. </ul>
  269. <hr />
  270. </body>
  271. </html>