Claudio Gomes пре 6 година
родитељ
комит
764c7e858b

+ 31 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/bouncingBall/modelDescription_me.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<fmiModelDescription
+  fmiVersion="1.0"
+  modelName="bouncingBall"
+  modelIdentifier="bouncingBall"
+  guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}"
+  numberOfContinuousStates="2"
+  numberOfEventIndicators="1">
+<ModelVariables>
+  <ScalarVariable name="h" valueReference="0" description="height, used as state">
+     <Real start="1" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="der(h)" valueReference="1" description="velocity of ball">
+     <Real/>
+  </ScalarVariable> 
+  <ScalarVariable name="v" valueReference="2" description="velocity of ball, used as state">
+     <Real/>
+  </ScalarVariable>
+  <ScalarVariable name="der(v)" valueReference="3" description="acceleration of ball">
+     <Real/>
+  </ScalarVariable>
+  <ScalarVariable name="g" valueReference="4" description="acceleration of gravity"
+                  variability="parameter">
+     <Real start="9.81" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="e" valueReference="5" description="dimensionless parameter"
+                  variability="parameter">
+     <Real start="0.7" fixed="true"/>
+  </ScalarVariable>
+</ModelVariables>
+</fmiModelDescription>

BIN
examples/mass_spring_damper/fmusdk/fmu10/src/models/bouncingBall/plot_h.PNG


+ 59 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/build_fmu

@@ -0,0 +1,59 @@
+#!/bin/sh
+# Build a model exchange or co-simulation fmu
+# Usage: build_fmu cs|me directory
+
+if [ $# -ne 2 ]; then
+   echo "Usage: $0 cs|me directory"
+   exit 2
+fi
+
+csOrMe=$1
+directory=$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 [ ! -d $directory ]; then
+   echo "$0: directory $directory does not exist"
+   exit 4
+fi
+
+if [ "$csOrMe" = "cs" ]; then
+   csOrMeInclude="-DFMI_COSIMULATION -I../../co_simulation/include"
+else
+   csOrMeInclude=-I../../model_exchange/include
+fi
+
+case "`uname -s`" in
+     CYGWIN*) arch=win
+     	      sharedLibrarySuffix=dll;;
+     Darwin)  arch=darwin
+     	      sharedLibrarySuffix=dylib;;
+     Linux)   arch=linux
+     	      pic=-fPIC
+     	      sharedLibrarySuffix=so;;
+esac     
+
+# Number of bits, default to 64
+bits=64
+case "`uname -m`" in
+     *64)      bits=64;;
+     *32)      bits=32;;
+     *i[3-6]86) bits=32;;
+esac
+
+# Uncomment the next line to force building 32-bit
+#bits=32
+# See also ../Makefile
+
+if [ $arch = linux -a $bits = 32 ]; then
+    CBITSFLAGS=-m32
+fi
+
+set -x
+(cd $directory; \
+    make dirclean; \
+    make ARCH=${arch}${bits} CBITSFLAGS=${CBITSFLAGS} CSORME=${csOrMe} CSORME_INCLUDE="${csOrMeInclude}" PIC=${pic} SHARED_LIBRARY_SUFFIX=${sharedLibrarySuffix} $directory.fmu)

+ 94 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/build_fmu.bat

@@ -0,0 +1,94 @@
+@echo off 
+rem ------------------------------------------------------------
+rem This batch builds an FMU of the FMU SDK
+rem Usage: build_fmu (me|cs) <fmu_dir_name> 
+rem Copyright QTronic GmbH. All rights reserved
+rem ------------------------------------------------------------
+
+setlocal
+
+echo -----------------------------------------------------------
+if %1==cs (^
+echo building FMU %2 - FMI for Co-Simulation 1.0) else ^
+echo building FMU %2 - FMI for Model Exchange 1.0
+
+rem save env variable settings
+set PREV_PATH=%PATH%
+if defined INCLUDE set PREV_INCLUDE=%INLUDE%
+if defined LIB     set PREV_LIB=%LIB%
+if defined LIBPATH set PREV_LIBPATH=%LIBPATH%
+
+if "%3"=="-win64" (set FMI_PLATFORM=win64) else (set FMI_PLATFORM=win32)
+
+rem setup the compiler
+if %FMI_PLATFORM%==win64 (
+if defined VS140COMNTOOLS (call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64) else ^
+if defined VS120COMNTOOLS (call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64) else ^
+if defined VS110COMNTOOLS (call "%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64) else ^
+if defined VS100COMNTOOLS (call "%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64) else ^
+if defined VS90COMNTOOLS (call "%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64) else ^
+if defined VS80COMNTOOLS (call "%VS80COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64) else ^
+goto noCompiler
+) else (
+if defined VS140COMNTOOLS (call "%VS140COMNTOOLS%\vsvars32.bat") else ^
+if defined VS120COMNTOOLS (call "%VS120COMNTOOLS%\vsvars32.bat") else ^
+if defined VS110COMNTOOLS (call "%VS110COMNTOOLS%\vsvars32.bat") else ^
+if defined VS100COMNTOOLS (call "%VS100COMNTOOLS%\vsvars32.bat") else ^
+if defined VS90COMNTOOLS (call "%VS90COMNTOOLS%\vsvars32.bat") else ^
+if defined VS80COMNTOOLS (call "%VS80COMNTOOLS%\vsvars32.bat") else ^
+goto noCompiler
+)
+
+rem create the %2.dll in the temp dir
+if not exist temp mkdir temp 
+pushd temp
+if exist *.dll del /Q *.dll
+
+if %1==cs (set DEF=/DFMI_COSIMULATION) else set DEF=
+cl /LD /nologo %DEF% ..\%2\%2.c /I ..\. /I ..\..\shared\include
+if not exist %2.dll goto compileError
+
+rem create FMU dir structure with root 'fmu'
+set BIN_DIR=fmu\binaries\%FMI_PLATFORM%
+set SRC_DIR=fmu\sources
+set DOC_DIR=fmu\documentation
+if not exist %BIN_DIR% mkdir %BIN_DIR%
+if not exist %SRC_DIR% mkdir %SRC_DIR%
+if not exist %DOC_DIR% mkdir %DOC_DIR%
+move /Y %2.dll %BIN_DIR%
+if exist ..\%2\*~ del /Q ..\%2\*~
+copy ..\%2\%2.c %SRC_DIR%
+copy ..\%2\modelDescription_%1.xml fmu\modelDescription.xml
+copy ..\%2\model.png fmu
+copy ..\fmuTemplate.c %SRC_DIR%
+copy ..\fmuTemplate.h %SRC_DIR%
+copy ..\%2\*.html %DOC_DIR%
+copy ..\%2\*.png  %DOC_DIR%
+del %DOC_DIR%\model.png
+
+rem zip the directory tree and move to fmu directory 
+cd fmu
+set FMU_FILE=..\..\..\..\fmu\%1\%FMI_PLATFORM%\%2.fmu
+if exist %FMU_FILE% del %FMU_FILE%
+..\..\..\..\bin\7z.exe a -tzip %FMU_FILE% ^
+  modelDescription.xml model.png binaries sources documentation
+goto cleanup
+
+:noCompiler
+echo No Microsoft Visual C compiler found
+
+:compileError
+echo build of %2 failed
+
+:cleanup
+popd
+if exist temp rmdir /S /Q temp
+
+rem undo variable settings performed by vsvars32.bat
+set PATH=%PREV_PATH%
+if defined PREV_INCLUDE set INCLUDE=%PREV_INLUDE%
+if defined PREV_LIB     set LIB=%PREV_LIB%
+if defined PREV_LIBPATH set LIBPATH=%PREV_LIBPATH%
+echo done.
+
+endlocal

+ 3 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/dq/Makefile

@@ -0,0 +1,3 @@
+CFLAGS = -I..
+
+include ../Makefile

+ 64 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/dq/dq.c

@@ -0,0 +1,64 @@
+/* ---------------------------------------------------------------------------*
+ * Sample implementation of an FMU - the Dahlquist test equation.
+ *
+ *   der(x) = - k * x and x(0) = 1. 
+ *   Analytical solution: x(t) = exp(-k*t).
+ * Copyright QTronic GmbH. All rights reserved.
+ * ---------------------------------------------------------------------------*/
+
+// define class name and unique id
+#define MODEL_IDENTIFIER dq
+#define MODEL_GUID "{8c4e810f-3df3-4a00-8276-176fa3c9f000}"
+
+// define model size
+#define NUMBER_OF_REALS 3
+#define NUMBER_OF_INTEGERS 0
+#define NUMBER_OF_BOOLEANS 0
+#define NUMBER_OF_STRINGS 0
+#define NUMBER_OF_STATES 1
+#define NUMBER_OF_EVENT_INDICATORS 0
+
+// include fmu header files, typedefs and macros
+#include "fmuTemplate.h"
+
+// define all model variables and their value references
+// conventions used here:
+// - if x is a variable, then macro x_ is its variable reference
+// - the vr of a variable is its index in array  r, i, b or s
+// - if k is the vr of a real state, then k+1 is the vr of its derivative
+#define x_     0
+#define der_x_ 1
+#define k_     2
+
+// define state vector as vector of value references
+#define STATES { x_ }
+
+// called by fmiInstantiateModel
+// Set values for all variables that define a start value
+// Settings used unless changed by fmiSetX before fmiInitialize
+void setStartValues(ModelInstance *comp) {
+    r(x_) = 1;
+    r(k_) = 1;
+}
+
+// called by fmiInitialize() after setting eventInfo to defaults
+// Used to set the first time event, if any.
+void initialize(ModelInstance* comp, fmiEventInfo* eventInfo) {
+}
+
+// called by fmiGetReal, fmiGetContinuousStates and fmiGetDerivatives
+fmiReal getReal(ModelInstance* comp, fmiValueReference vr){
+    switch (vr) {
+        case x_     : return r(x_);
+        case der_x_ : return - r(k_) * r(x_);
+        case k_     : return r(k_);
+        default: return 0;
+    }
+}
+
+// Used to set the next time event, if any.
+void eventUpdate(fmiComponent comp, fmiEventInfo* eventInfo) {
+} 
+
+// include code that implements the FMI based on the above definitions
+#include "fmuTemplate.c"

+ 33 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/dq/index.html

@@ -0,0 +1,33 @@
+<html>
+<head>
+<title>Documentation for dq.fmu</title>
+<style type="text/css">
+  html { font-family: Verdana, Arial, Helvetica, sans-serif; }
+  h1   { color: #000066; }
+</style>
+</head>
+<body>
+<h1>dq.fmu</h1>
+This FMU implements the equation 
+<ul>
+<li> der(x) = -k * x </li>
+</ul>
+The analytical solution of this system is 
+<ul>
+<li> x(t) = exp(-k*t) </li>
+</ul>
+The above equation is also known as 
+<a href="http://en.wikipedia.org/wiki/Germund_Dahlquist" target="_blank">Dahlquist</a> 
+test equation.
+<br/>
+<img src="plot_x.png">
+<br/>
+The figure shows the solution for x computed with Silver 
+for start values k = 1 and x = 1.
+
+<h2><a name="license">License conditions</a></h2>
+The FMU is provided by QTronic under the
+<a href="http://www.opensource.org/licenses/bsd-license.html">BSD License</a>.
+</body>
+</html>
+

BIN
examples/mass_spring_damper/fmusdk/fmu10/src/models/dq/model.png


+ 27 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/dq/modelDescription_cs.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<fmiModelDescription
+  fmiVersion="1.0"
+  modelName="dq"
+  modelIdentifier="dq"
+  guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}"
+  numberOfContinuousStates="1"
+  numberOfEventIndicators="0">
+<ModelVariables>
+  <ScalarVariable name="x" valueReference="0" description="the only state">
+     <Real start="1" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="der(x)" valueReference="1">
+     <Real/>
+  </ScalarVariable> 
+  <ScalarVariable name="k" valueReference="2" variability="parameter">
+     <Real start="1" fixed="true"/>
+  </ScalarVariable>
+</ModelVariables>
+<Implementation>
+  <CoSimulation_StandAlone>
+    <Capabilities
+      canHandleVariableCommunicationStepSize="true"
+      canHandleEvents="true"/>
+  </CoSimulation_StandAlone>
+</Implementation>
+</fmiModelDescription>