Claudio Gomes 7 лет назад
Родитель
Сommit
0fcc7853f5

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


+ 42 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/values/modelDescription_cs.xml

@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<fmiModelDescription
+  fmiVersion="1.0"
+  modelName="values"
+  modelIdentifier="values"
+  guid="{8c4e810f-3df3-4a00-8276-176fa3c9f004}"
+  numberOfContinuousStates="1"
+  numberOfEventIndicators="0">
+<ModelVariables>
+  <ScalarVariable name="x" valueReference="0" description="used as continuous state">
+     <Real start="1" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="der(x)" valueReference="1" description="time derivative of x">
+     <Real/>
+  </ScalarVariable> 
+  <ScalarVariable name="int_in" valueReference="0" description="integer input" causality = "input">
+     <Integer start="2"/>
+  </ScalarVariable>
+  <ScalarVariable name="int_out" valueReference="1" description="index in string array 'month'" causality = "output">
+     <Integer start="0" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="bool_in" valueReference="0" description="boolean input" causality = "input">
+     <Boolean start="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="bool_out" valueReference="1" description="boolean output" causality = "output">
+     <Boolean/>
+  </ScalarVariable>
+  <ScalarVariable name="string_in" valueReference="0" description="string input" causality = "input">
+     <String start="QTronic"/>
+  </ScalarVariable>
+  <ScalarVariable name="string_out" valueReference="1" description="the string month[int_out]" causality = "output">
+     <String/>
+  </ScalarVariable>
+</ModelVariables>
+<Implementation>
+  <CoSimulation_StandAlone>
+    <Capabilities
+      canHandleVariableCommunicationStepSize="true"
+      canHandleEvents="true"/>
+  </CoSimulation_StandAlone>
+</Implementation>
+</fmiModelDescription>

+ 35 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/values/modelDescription_me.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<fmiModelDescription
+  fmiVersion="1.0"
+  modelName="values"
+  modelIdentifier="values"
+  guid="{8c4e810f-3df3-4a00-8276-176fa3c9f004}"
+  numberOfContinuousStates="1"
+  numberOfEventIndicators="0">
+<ModelVariables>
+  <ScalarVariable name="x" valueReference="0" description="used as continuous state">
+     <Real start="1" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="der(x)" valueReference="1" description="time derivative of x">
+     <Real/>
+  </ScalarVariable> 
+  <ScalarVariable name="int_in" valueReference="0" description="integer input" causality = "input">
+     <Integer start="2"/>
+  </ScalarVariable>
+  <ScalarVariable name="int_out" valueReference="1" description="index in string array 'month'" causality = "output">
+     <Integer start="0" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="bool_in" valueReference="0" description="boolean input" causality = "input">
+     <Boolean start="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="bool_out" valueReference="1" description="boolean output" causality = "output">
+     <Boolean/>
+  </ScalarVariable>
+  <ScalarVariable name="string_in" valueReference="0" description="string input" causality = "input">
+     <String start="QTronic"/>
+  </ScalarVariable>
+  <ScalarVariable name="string_out" valueReference="1" description="the string month[int_out]" causality = "output">
+     <String/>
+  </ScalarVariable>
+</ModelVariables>
+</fmiModelDescription>

BIN
examples/mass_spring_damper/fmusdk/fmu10/src/models/values/values.PNG


+ 84 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/values/values.c

@@ -0,0 +1,84 @@
+/* ---------------------------------------------------------------------------*
+ * Sample implementation of an FMU.
+ * This demonstrates the use of all FMU variable types.
+ * Copyright QTronic GmbH. All rights reserved.
+ * ---------------------------------------------------------------------------*/
+
+// define class name and unique id
+#define MODEL_IDENTIFIER values
+#define MODEL_GUID "{8c4e810f-3df3-4a00-8276-176fa3c9f004}"
+
+// define model size
+#define NUMBER_OF_REALS 2
+#define NUMBER_OF_INTEGERS 2
+#define NUMBER_OF_BOOLEANS 2
+#define NUMBER_OF_STRINGS 2
+#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 int_in_     0
+#define int_out_    1
+#define bool_in_    0
+#define bool_out_   1
+#define string_in_  0
+#define string_out_ 1
+
+// define state vector as vector of value references
+#define STATES { x_ }
+
+const char* month[] = {
+    "jan","feb","march","april","may","june","july",
+    "august","sept","october","november","december"
+};
+
+// 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;
+    i(int_in_) = 2;
+    i(int_out_) = 0;
+    b(bool_in_) = fmiTrue;
+    b(bool_out_) = fmiFalse;
+    copy(string_in_, "QTronic");
+    copy(string_out_, month[0]);
+}
+
+// called by fmiInitialize() after setting eventInfo to defaults
+// Used to set the first time event, if any.
+void initialize(ModelInstance* comp, fmiEventInfo* eventInfo) {
+    eventInfo->upcomingTimeEvent   = fmiTrue;
+    eventInfo->nextEventTime       = 1 + comp->time;
+}
+
+// called by fmiGetReal, fmiGetContinuousStates and fmiGetDerivatives
+fmiReal getReal(ModelInstance* comp, fmiValueReference vr){
+    switch (vr) {
+        case x_     : return   r(x_);
+        case der_x_ : return - r(x_);
+        default: return 0;
+    }
+}
+
+// called by fmiEventUpdate() after setting eventInfo to defaults
+void eventUpdate(ModelInstance* comp, fmiEventInfo* eventInfo) {
+    eventInfo->upcomingTimeEvent   = fmiTrue;
+    eventInfo->nextEventTime       = 1 + comp->time;
+    i(int_out_) += 1;
+    b(bool_out_) = !b(bool_out_);
+    if (i(int_out_)<12) copy(string_out_, month[i(int_out_)]);
+    else eventInfo->terminateSimulation = fmiTrue;
+}
+
+// include code that implements the FMI based on the above definitions
+#include "fmuTemplate.c"

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

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

+ 27 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/vanDerPol/index.html

@@ -0,0 +1,27 @@
+<html>
+<head>
+<title>Documentation for vanDerPol.fmu</title>
+<style type="text/css">
+  html { font-family: Verdana, Arial, Helvetica, sans-serif; }
+  h1   { color: #000066; }
+</style>
+</head>
+<body>
+<h1>vanDerPol.fmu</h1>
+This FMU implements the famous
+<a href="http://en.wikipedia.org/wiki/Van_der_Pol_oscillator" target="_blank">Van der Pol oscillator</a>.
+<ul>
+<li> der(x0) = x1 </li>
+<li> der(x1) = mu * ((1 - x0 * x0) * x1) - x0</li>
+</ul>
+<img src="plot_states.png">
+<br/>
+The figure shows the solution computed with Silver 
+for start values x0 = 2, x1 = 0, mu = 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/vanDerPol/model.png


+ 33 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/vanDerPol/modelDescription_cs.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<fmiModelDescription
+  fmiVersion="1.0"
+  modelName="van der Pol oscillator"
+  modelIdentifier="vanDerPol"
+  guid="{8c4e810f-3da3-4a00-8276-176fa3c9f000}"
+  numberOfContinuousStates="2"
+  numberOfEventIndicators="0">
+<ModelVariables>
+  <ScalarVariable name="x0" valueReference="0" description="the first state">
+     <Real start="2" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="der(x0)" valueReference="1">
+     <Real/>
+  </ScalarVariable> 
+  <ScalarVariable name="x1" valueReference="2" description="the second state">
+     <Real start="0" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="der(x1)" valueReference="3">
+     <Real/>
+  </ScalarVariable> 
+  <ScalarVariable name="mu" valueReference="4" variability="parameter">
+     <Real start="1" fixed="true"/>
+  </ScalarVariable>
+</ModelVariables>
+<Implementation>
+  <CoSimulation_StandAlone>
+    <Capabilities
+      canHandleVariableCommunicationStepSize="true"
+      canHandleEvents="true"/>
+  </CoSimulation_StandAlone>
+</Implementation>
+</fmiModelDescription>

+ 26 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/vanDerPol/modelDescription_me.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<fmiModelDescription
+  fmiVersion="1.0"
+  modelName="van der Pol oscillator"
+  modelIdentifier="vanDerPol"
+  guid="{8c4e810f-3da3-4a00-8276-176fa3c9f000}"
+  numberOfContinuousStates="2"
+  numberOfEventIndicators="0">
+<ModelVariables>
+  <ScalarVariable name="x0" valueReference="0" description="the first state">
+     <Real start="2" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="der(x0)" valueReference="1">
+     <Real/>
+  </ScalarVariable> 
+  <ScalarVariable name="x1" valueReference="2" description="the second state">
+     <Real start="0" fixed="true"/>
+  </ScalarVariable>
+  <ScalarVariable name="der(x1)" valueReference="3">
+     <Real/>
+  </ScalarVariable> 
+  <ScalarVariable name="mu" valueReference="4" variability="parameter">
+     <Real start="1" fixed="true"/>
+  </ScalarVariable>
+</ModelVariables>
+</fmiModelDescription>

BIN
examples/mass_spring_damper/fmusdk/fmu10/src/models/vanDerPol/plot_states.png


+ 74 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/models/vanDerPol/vanDerPol.c

@@ -0,0 +1,74 @@
+/* ---------------------------------------------------------------------------*
+ * Copyright QTronic GmbH. All rights reserved.
+ * Sample implementation of an FMU - the Van der Pol oscillator.
+ * See http://en.wikipedia.org/wiki/Van_der_Pol_oscillator
+ *  
+ *   der(x0) = x1
+ *   der(x1) = mu * ((1 - x0 ^ 2) * x1) - x0;
+ *
+ *   start values: x0=2, x1=0, mue=1
+ * ---------------------------------------------------------------------------*/
+
+// define class name and unique id
+#define MODEL_IDENTIFIER vanDerPol
+#define MODEL_GUID "{8c4e810f-3da3-4a00-8276-176fa3c9f000}"
+
+// define model size
+#define NUMBER_OF_REALS 5
+#define NUMBER_OF_INTEGERS 0
+#define NUMBER_OF_BOOLEANS 0
+#define NUMBER_OF_STRINGS 0
+#define NUMBER_OF_STATES 2
+#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 x0_     0
+#define der_x0_ 1
+#define x1_     2
+#define der_x1_ 3
+#define mu_     4
+
+// define state vector as vector of value references
+#define STATES { x0_, x1_ }
+
+// 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(x0_) = 2;
+    r(x1_) = 0;
+    r(mu_) = 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 x0_     : return r(x0_);
+        case x1_     : return r(x1_);
+        case der_x0_ : return r(x1_);
+        case der_x1_ : return r(mu_) * ((1.0-r(x0_)*r(x0_))*r(x1_)) - r(x0_);
+        case mu_     : return r(mu_);
+        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"
+
+

+ 24 - 0
examples/mass_spring_damper/fmusdk/fmu10/src/shared/COPYING.txt

@@ -0,0 +1,24 @@
+Files expat.h, expat_external.h and libexpatMT.lib
+
+Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
+                               and Clark Cooper
+Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Expat maintainers.
+
+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.