Browse Source

upgraded modelica models to most recent version due to problem in exporting and the trivial scenario successfully loads FMUs from modelica. Still more problems to solve.

Cláudio Gomes 4 years ago
parent
commit
1896532358
86 changed files with 19003 additions and 9 deletions
  1. 11 0
      ModelicaModels/Echo.mo
  2. 2 2
      ModelicaModels/Obstacle.mo
  3. 2 2
      ModelicaModels/PW_PowerSystem.mo
  4. 2 2
      ModelicaModels/PW_PowerSystem_Test.mo
  5. 2 2
      ModelicaModels/PW_Window.mo
  6. 26 0
      SemanticAdaptationForFMI/Experiments/hierarchical_fmu/fmu20/.project
  7. BIN
      SemanticAdaptationForFMI/Experiments/hierarchical_fmu/fmu20/fmu/cs/mass_spring_damper.fmu
  8. BIN
      SemanticAdaptationForFMI/Experiments/hierarchical_fmu/fmu20/fmu/cs/mass_spring_damper_hierarchical.fmu
  9. 1 1
      SemanticAdaptationForFMI/Experiments/hierarchical_fmu/fmu20/src/co_simulation/main.c
  10. 14 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/README.txt
  11. 57 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/bin/License.txt
  12. 9 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/build_all.bat
  13. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/Echo.fmu
  14. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/Obstacle.fmu
  15. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/PW_PowerSystem.fmu
  16. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/PW_Window.fmu
  17. 63 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/build_all.bat
  18. 43 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/co_simulation/power_window_plain_cosim.c
  19. 75 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/fmi2.h
  20. 243 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/include/fmi2FunctionTypes.h
  21. 333 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/include/fmi2Functions.h
  22. 115 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/include/fmi2TypesPlatform.h
  23. 654 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlElement.cpp
  24. 160 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlElement.h
  25. 314 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlParser.cpp
  26. 126 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlParser.h
  27. 242 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlParserCApi.cpp
  28. 203 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlParserCApi.h
  29. 50 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlParserException.h
  30. 96 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/DOCBparser.h
  31. 306 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/HTMLparser.h
  32. 147 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/HTMLtree.h
  33. 173 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/SAX.h
  34. 178 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/SAX2.h
  35. 126 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/c14n.h
  36. 182 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/catalog.h
  37. 230 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/chvalid.h
  38. 217 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/debugXML.h
  39. 86 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/dict.h
  40. 240 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/encoding.h
  41. 151 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/entities.h
  42. 509 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/globals.h
  43. 233 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/hash.h
  44. 137 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/list.h
  45. 163 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/nanoftp.h
  46. 81 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/nanohttp.h
  47. 1241 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/parser.h
  48. 644 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/parserInternals.h
  49. 100 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/pattern.h
  50. 217 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/relaxng.h
  51. 958 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/schemasInternals.h
  52. 142 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/schematron.h
  53. 84 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/threads.h
  54. 1311 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/tree.h
  55. 94 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/uri.h
  56. 458 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/valid.h
  57. 129 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xinclude.h
  58. 189 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xlink.h
  59. 366 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlIO.h
  60. 146 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlautomata.h
  61. 945 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlerror.h
  62. 162 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlexports.h
  63. 224 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlmemory.h
  64. 57 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlmodule.h
  65. 428 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlreader.h
  66. 222 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlregexp.h
  67. 88 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlsave.h
  68. 246 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlschemas.h
  69. 151 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlschemastypes.h
  70. 140 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlstring.h
  71. 202 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlunicode.h
  72. 489 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlversion.h
  73. 488 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xmlwriter.h
  74. 557 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xpath.h
  75. 632 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xpathInternals.h
  76. 114 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml/xpointer.h
  77. 21 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/libxml_license.txt
  78. 649 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/sim_support.c
  79. 40 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/sim_support.h
  80. 82 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/xmlVersionParser.c
  81. 28 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/xmlVersionParser.h
  82. 39 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmusim.bat
  83. 8 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/get_modelica_fmus.bat
  84. 885 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/log.txt
  85. 22 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/run_all.bat
  86. 3 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/run_all_log.bat

+ 11 - 0
ModelicaModels/Echo.mo

@@ -0,0 +1,11 @@
+model Echo
+  Modelica.Blocks.Interfaces.RealInput u annotation(
+    Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-80, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+  Modelica.Blocks.Interfaces.RealOutput y annotation(
+    Placement(visible = true, transformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+equation
+  connect(u, y) annotation(
+    Line(points = {{-100, 0}, {104, 0}, {104, 0}, {110, 0}}, color = {0, 0, 127}));
+  annotation(
+    uses(Modelica(version = "3.2.2")));
+end Echo;

+ 2 - 2
ModelicaModels/Obstacle.mo

@@ -16,5 +16,5 @@ equation
   connect(add1.y, greaterEqualThreshold1.u) annotation(Line(points = {{-38, 40}, {-36, 40}, {-36, -8}, {-30, -8}}, color = {0, 0, 127}));
   connect(in_height, add1.u2) annotation(Line(points = {{-100, 34}, {-62, 34}}, color = {0, 0, 127}));
   connect(realExpression1.y, add1.u1) annotation(Line(points = {{-74, 70}, {-68, 70}, {-68, 46}, {-62, 46}, {-62, 46}}, color = {0, 0, 127}));
-  annotation(uses(Modelica(version = "3.2.1")));
-end Obstacle;
+  annotation(uses(Modelica(version = "3.2.2")));
+end Obstacle;

+ 2 - 2
ModelicaModels/PW_PowerSystem.mo

@@ -38,5 +38,5 @@ equation
   connect(motor.pin_en, voltage_ground.p) annotation(Line(points = {{-18, -34}, {-60, -34}}, color = {0, 0, 255}));
   connect(up_voltage.n, up_ground.p) annotation(Line(points = {{-62, 38}, {-62, 24}, {-80, 24}}, color = {0, 0, 255}));
   connect(dc_motor_power.n, voltage_ground.p) annotation(Line(points = {{-48, -18}, {-48, -18}, {-48, -34}, {-60, -34}, {-60, -34}}, color = {0, 0, 255}));
-  annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), experiment(StartTime = 0, StopTime = 8, Tolerance = 0.0001, Interval = 0.004), uses(Modelica(version = "3.2.1")));
-end PW_PowerSystem;
+  annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), experiment(StartTime = 0, StopTime = 8, Tolerance = 0.0001, Interval = 0.004), uses(Modelica(version = "3.2.2")));
+end PW_PowerSystem;

+ 2 - 2
ModelicaModels/PW_PowerSystem_Test.mo

@@ -13,5 +13,5 @@ equation
   connect(window.window_torque_out, add1.u1) annotation(Line(points = {{21, -5}, {28, -5}, {28, -16}, {-8, -16}}, color = {0, 0, 127}));
   connect(power.speed, window.speed_motor) annotation(Line(points = {{-12, 0}, {2, 0}}, color = {0, 0, 127}));
   connect(add1.y, power.input_torque) annotation(Line(points = {{-32, -22}, {-38, -22}, {-38, 0}, {-26, 0}, {-26, 0}}, color = {0, 0, 127}));
-  annotation(uses(Modelica(version = "3.2.1")), experiment(StartTime = 0, StopTime = 5, Tolerance = 0.0001, Interval = 0.0025));
-end PW_PowerSystem_Test;
+  annotation(uses(Modelica(version = "3.2.2")), experiment(StartTime = 0, StopTime = 5, Tolerance = 0.0001, Interval = 0.0025));
+end PW_PowerSystem_Test;

+ 2 - 2
ModelicaModels/PW_Window.mo

@@ -21,5 +21,5 @@ equation
   connect(window_angle.phi, window_height.u) annotation(Line(points = {{54, -18}, {58, -18}, {58, -40}, {62, -40}, {62, -40}}, color = {0, 0, 127}));
   connect(window_height.y, window_height_out) annotation(Line(points = {{85, -40}, {100, -40}}, color = {0, 0, 127}));
   connect(window_speed.y, window_speed_out) annotation(Line(points = {{85, 10}, {100, 10}}, color = {0, 0, 127}));
-  annotation(uses(Modelica(version = "3.2.1")));
-end PW_Window;
+  annotation(uses(Modelica(version = "3.2.2")));
+end PW_Window;

+ 26 - 0
SemanticAdaptationForFMI/Experiments/hierarchical_fmu/fmu20/.project

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>fmu20</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+			<triggers>clean,full,incremental,</triggers>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+			<triggers>full,incremental,</triggers>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.cdt.core.cnature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+	</natures>
+</projectDescription>

BIN
SemanticAdaptationForFMI/Experiments/hierarchical_fmu/fmu20/fmu/cs/mass_spring_damper.fmu


BIN
SemanticAdaptationForFMI/Experiments/hierarchical_fmu/fmu20/fmu/cs/mass_spring_damper_hierarchical.fmu


+ 1 - 1
SemanticAdaptationForFMI/Experiments/hierarchical_fmu/fmu20/src/co_simulation/main.c

@@ -45,7 +45,7 @@ static int simulate(FMU* fmu, double tEnd, double h, fmi2Boolean loggingOn, char
     fmi2Status fmi2Flag;                    // return code of the fmu functions
     char *fmuResourceLocation = getTempResourcesLocation(); // path to the fmu resources as URL, "file://C:\QTronic\sales"
     fmi2Boolean visible = fmi2False;        // no simulator user interface
-
+	
     fmi2CallbackFunctions callbacks = {fmuLogger, calloc, free, NULL, fmu};  // called by the model during simulation
     ModelDescription* md;                      // handle to the parsed XML file
     fmi2Boolean toleranceDefined = fmi2False;  // true if model description define tolerance

+ 14 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/README.txt

@@ -0,0 +1,14 @@
+Author of these instructions: Claudio Gomes (claudio.gomes@uantwerp.be)
+
+Before following the installation instructions in the doc folder, you need to install Visual Studio 2015 Community.
+I've ported the libxml and the .bat files to work with that compiler.
+
+Then you just have to run build_all.bat
+
+Then run_all.bat
+
+
+
+Some problems that you may encounter:
+	- Incapable of loading a specific dll.
+		I had a similar issue due to the way OpenModelica exports the FMUs. I had to copy the missing dlls from the OpenModelica installation. I copied them to the bin directory.

+ 57 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/bin/License.txt

@@ -0,0 +1,57 @@
+  7-Zip
+  ~~~~~
+  License for use and distribution
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+  7-Zip Copyright (C) 1999-2007 Igor Pavlov.
+
+  Licenses for files are:
+
+    1) 7z.dll: GNU LGPL + unRAR restriction
+    2) All other files:  GNU LGPL
+
+  The GNU LGPL + unRAR restriction means that you must follow both 
+  GNU LGPL rules and unRAR restriction rules.
+
+
+  Note: 
+    You can use 7-Zip on any computer, including a computer in a commercial 
+    organization. You don't need to register or pay for 7-Zip.
+
+
+  GNU LGPL information
+  --------------------
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+  unRAR restriction
+  -----------------
+
+    The decompression engine for RAR archives was developed using source 
+    code of unRAR program.
+    All copyrights to original unRAR code are owned by Alexander Roshal.
+
+    The license for original unRAR code has the following restriction:
+
+      The unRAR sources cannot be used to re-create the RAR compression algorithm, 
+      which is proprietary. Distribution of modified unRAR sources in separate form 
+      or as a part of other software is permitted, provided that it is clearly
+      stated in the documentation and source comments that the code may
+      not be used to develop a RAR (WinRAR) compatible archiver.
+
+
+  --
+  Igor Pavlov

+ 9 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/build_all.bat

@@ -0,0 +1,9 @@
+@echo off 
+
+echo -----------------------------------------------------------
+echo Making the simulators and models for FMI 2.0 ...
+pushd fmu20\src
+call build_all
+popd
+echo Making the simulators and models for FMI 2.0 ... DONE!
+echo -----------------------------------------------------------

BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/Echo.fmu


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/Obstacle.fmu


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/PW_PowerSystem.fmu


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/PW_Window.fmu


+ 63 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/build_all.bat

@@ -0,0 +1,63 @@
+@echo off 
+
+setlocal
+
+echo -----------------------------------------------------------
+echo building fmu20sim_cs.exe - FMI for Co-Simulation 2.0
+echo -----------------------------------------------------------
+
+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 "%1"=="-win64" (set x64=x64\) else set x64=
+
+rem setup the compiler
+if defined x64 (
+if not exist ..\..\bin\x64 mkdir ..\..\bin\x64
+if defined VS140COMNTOOLS (call "%VS140COMNTOOLS%\..\..\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 VS100COMNTOOLS (call "%VS100COMNTOOLS%\vsvars32.bat") else ^
+if defined VS90COMNTOOLS (call "%VS90COMNTOOLS%\vsvars32.bat") else ^
+if defined VS80COMNTOOLS (call "%VS80COMNTOOLS%\vsvars32.bat") else ^
+goto noCompiler
+)
+
+set SRC=power_window_plain_cosim.c ..\shared\sim_support.c ..\shared\xmlVersionParser.c ..\shared\parser\XmlParser.cpp ..\shared\parser\XmlElement.cpp ..\shared\parser\XmlParserCApi.cpp
+set INC=/I..\shared\include /I..\shared /I..\shared\parser
+set OPTIONS=/DFMI_COSIMULATION /nologo /EHsc /DSTANDALONE_XML_PARSER /DLIBXML_STATIC
+
+rem create fmu20sim_cs.exe in co_simulation dir
+pushd co_simulation
+cl %SRC% %INC% %OPTIONS% /Fefmu20sim_cs.exe /link /LIBPATH:..\shared\parser\%x64% /NODEFAULTLIB:libcmtd.lib
+
+del *.obj
+popd
+if not exist co_simulation\fmu20sim_cs.exe goto compileError
+move /Y co_simulation\fmu20sim_cs.exe ..\..\bin\%x64%
+goto done
+
+:noCompiler
+echo No Microsoft Visual C compiler found
+
+:compileError
+echo build of fmu20sim_cs.exe failed
+
+:done
+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
+
+pause

+ 43 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/co_simulation/power_window_plain_cosim.c

@@ -0,0 +1,43 @@
+/* -------------------------------------------------------------------------
+ * Author: Claudio Gomes (claudio.gomes@uantwerp.be)
+ * -------------------------------------------------------------------------*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "fmi2.h"
+#include "sim_support.h"
+
+// The paths to the FMUs to be simulated.
+#define OBSTACLE_FMU_PATH "fmu20\\fmu\\cs\\Obstacle.fmu"
+#define POWERSYSTEM_FMU_PATH "fmu20\\fmu\\cs\\PW_PowerSystem.fmu"
+#define WINDOW_FMU_PATH "fmu20\\fmu\\cs\\PW_Window.fmu"
+
+int main(int argc, char *argv[]) {
+    int i;
+	
+	// The fmus to be loaded and simulated.
+	FMU Obstacle; 
+	FMU PW_PowerSystem; 
+	FMU PW_Window; 
+	
+    // parse command line arguments and load the FMU
+    // default arguments value
+    double tEnd = 1.0;
+    double h=0.1;
+    int loggingOn = 1;
+    char csv_separator = ',';
+    char **categories = NULL;
+    int nCategories = 0;
+	
+	printf("Loading FMUs...\n");
+	
+	// TODO: The fmus need to be loaded onto separate directories.
+    loadFMU(OBSTACLE_FMU_PATH, &Obstacle);
+	loadFMU(POWERSYSTEM_FMU_PATH, &PW_PowerSystem);
+	loadFMU(WINDOW_FMU_PATH, &PW_Window);
+	
+	printf("FMUs loaded.\n");
+	
+    return EXIT_SUCCESS;
+}

+ 75 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/fmi2.h

@@ -0,0 +1,75 @@
+/* ------------------------------------------------------------------------- 
+ * fmi.h
+ * Struct with the corresponding function pointers for FMI 2.0.
+ * Copyright QTronic GmbH. All rights reserved.
+ * -------------------------------------------------------------------------*/
+
+#ifndef FMI_H
+#define FMI_H
+
+#include <windows.h>
+#include "fmi2Functions.h"
+
+#include "XmlParserCApi.h"
+
+typedef struct {
+    ModelDescription* modelDescription;
+
+    HMODULE dllHandle; // fmu.dll handle
+    /***************************************************
+    Common Functions
+    ****************************************************/
+    fmi2GetTypesPlatformTYPE         *getTypesPlatform;
+    fmi2GetVersionTYPE               *getVersion;
+    fmi2SetDebugLoggingTYPE          *setDebugLogging;
+    fmi2InstantiateTYPE              *instantiate;
+    fmi2FreeInstanceTYPE             *freeInstance;
+    fmi2SetupExperimentTYPE          *setupExperiment;
+    fmi2EnterInitializationModeTYPE  *enterInitializationMode;
+    fmi2ExitInitializationModeTYPE   *exitInitializationMode;
+    fmi2TerminateTYPE                *terminate;
+    fmi2ResetTYPE                    *reset;
+    fmi2GetRealTYPE                  *getReal;
+    fmi2GetIntegerTYPE               *getInteger;
+    fmi2GetBooleanTYPE               *getBoolean;
+    fmi2GetStringTYPE                *getString;
+    fmi2SetRealTYPE                  *setReal;
+    fmi2SetIntegerTYPE               *setInteger;
+    fmi2SetBooleanTYPE               *setBoolean;
+    fmi2SetStringTYPE                *setString;
+    fmi2GetFMUstateTYPE              *getFMUstate;
+    fmi2SetFMUstateTYPE              *setFMUstate;
+    fmi2FreeFMUstateTYPE             *freeFMUstate;
+    fmi2SerializedFMUstateSizeTYPE   *serializedFMUstateSize;
+    fmi2SerializeFMUstateTYPE        *serializeFMUstate;
+    fmi2DeSerializeFMUstateTYPE      *deSerializeFMUstate;
+    fmi2GetDirectionalDerivativeTYPE *getDirectionalDerivative;
+    /***************************************************
+    Functions for FMI2 for Co-Simulation
+    ****************************************************/
+    fmi2SetRealInputDerivativesTYPE  *setRealInputDerivatives;
+    fmi2GetRealOutputDerivativesTYPE *getRealOutputDerivatives;
+    fmi2DoStepTYPE                   *doStep;
+    fmi2CancelStepTYPE               *cancelStep;
+    fmi2GetStatusTYPE                *getStatus;
+    fmi2GetRealStatusTYPE            *getRealStatus;
+    fmi2GetIntegerStatusTYPE         *getIntegerStatus;
+    fmi2GetBooleanStatusTYPE         *getBooleanStatus;
+    fmi2GetStringStatusTYPE          *getStringStatus;
+    /***************************************************
+    Functions for FMI2 for Model Exchange
+    ****************************************************/
+    fmi2EnterEventModeTYPE                *enterEventMode;
+    fmi2NewDiscreteStatesTYPE             *newDiscreteStates;
+    fmi2EnterContinuousTimeModeTYPE       *enterContinuousTimeMode;
+    fmi2CompletedIntegratorStepTYPE       *completedIntegratorStep;
+    fmi2SetTimeTYPE                       *setTime;
+    fmi2SetContinuousStatesTYPE           *setContinuousStates;
+    fmi2GetDerivativesTYPE                *getDerivatives;
+    fmi2GetEventIndicatorsTYPE            *getEventIndicators;
+    fmi2GetContinuousStatesTYPE           *getContinuousStates;
+    fmi2GetNominalsOfContinuousStatesTYPE *getNominalsOfContinuousStates;
+} FMU;
+
+#endif // FMI_H
+

+ 243 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/include/fmi2FunctionTypes.h

@@ -0,0 +1,243 @@
+#ifndef fmi2FunctionTypes_h
+#define fmi2FunctionTypes_h
+
+#include "fmi2TypesPlatform.h"
+
+/* This header file must be utilized when compiling an FMU or an FMI master.
+   It declares data and function types for FMI 2.0
+
+   Revisions:
+   - Apr.  9, 2014: all prefixes "fmi" renamed to "fmi2" (decision from April 8)
+   - Apr.  3, 2014: Added #include <stddef.h> for size_t definition
+   - Mar. 27, 2014: Added #include "fmiTypesPlatform.h" (#179)
+   - Mar. 26, 2014: Introduced function argument "void" for the functions (#171)
+                      fmiGetTypesPlatformTYPE and fmiGetVersionTYPE
+   - Oct. 11, 2013: Functions of ModelExchange and CoSimulation merged:
+                      fmiInstantiateModelTYPE , fmiInstantiateSlaveTYPE  -> fmiInstantiateTYPE
+                      fmiFreeModelInstanceTYPE, fmiFreeSlaveInstanceTYPE -> fmiFreeInstanceTYPE
+                      fmiEnterModelInitializationModeTYPE, fmiEnterSlaveInitializationModeTYPE -> fmiEnterInitializationModeTYPE
+                      fmiExitModelInitializationModeTYPE , fmiExitSlaveInitializationModeTYPE  -> fmiExitInitializationModeTYPE
+                      fmiTerminateModelTYPE , fmiTerminateSlaveTYPE  -> fmiTerminate
+                      fmiResetSlave -> fmiReset (now also for ModelExchange and not only for CoSimulation)
+                    Functions renamed
+                      fmiUpdateDiscreteStatesTYPE -> fmiNewDiscreteStatesTYPE
+                    Renamed elements of the enumeration fmiEventInfo
+                      upcomingTimeEvent             -> nextEventTimeDefined // due to generic naming scheme: varDefined + var
+                      newUpdateDiscreteStatesNeeded -> newDiscreteStatesNeeded;
+   - June 13, 2013: Changed type fmiEventInfo
+                    Functions removed:
+                       fmiInitializeModelTYPE
+                       fmiEventUpdateTYPE
+                       fmiCompletedEventIterationTYPE
+                       fmiInitializeSlaveTYPE
+                    Functions added:
+                       fmiEnterModelInitializationModeTYPE
+                       fmiExitModelInitializationModeTYPE
+                       fmiEnterEventModeTYPE
+                       fmiUpdateDiscreteStatesTYPE
+                       fmiEnterContinuousTimeModeTYPE
+                       fmiEnterSlaveInitializationModeTYPE;
+                       fmiExitSlaveInitializationModeTYPE;
+   - Feb. 17, 2013: Added third argument to fmiCompletedIntegratorStepTYPE
+                    Changed function name "fmiTerminateType" to "fmiTerminateModelType" (due to #113)
+                    Changed function name "fmiGetNominalContinuousStateTYPE" to
+                                          "fmiGetNominalsOfContinuousStatesTYPE"
+                    Removed fmiGetStateValueReferencesTYPE.
+   - Nov. 14, 2011: First public Version
+
+
+   Copyright © 2011 MODELISAR consortium,
+               2012-2013 Modelica Association Project "FMI"
+               All rights reserved.
+   This file is licensed by the copyright holders under the BSD 2-Clause License
+   (http://www.opensource.org/licenses/bsd-license.html):
+
+   ----------------------------------------------------------------------------
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   - Redistributions of source code must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+   - Redistributions in binary form must reproduce the above copyright notice,
+     this list of conditions and the following disclaimer in the documentation
+     and/or other materials provided with the distribution.
+   - Neither the name of the copyright holders nor the names of its
+     contributors may be used to endorse or promote products derived
+     from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+   TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+   OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+   ----------------------------------------------------------------------------
+
+   with the extension:
+
+   You may distribute or publicly perform any modification only under the
+   terms of this license.
+   (Note, this means that if you distribute a modified file,
+    the modified file must also be provided under this license).
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* make sure all compiler use the same alignment policies for structures */
+#if defined _MSC_VER || defined __GNUC__
+#pragma pack(push,8)
+#endif
+
+/* Include stddef.h, in order that size_t etc. is defined */
+#include <stddef.h>
+
+
+/* Type definitions */
+typedef enum {
+    fmi2OK,
+    fmi2Warning,
+    fmi2Discard,
+    fmi2Error,
+    fmi2Fatal,
+    fmi2Pending
+} fmi2Status;
+
+typedef enum {
+    fmi2ModelExchange,
+    fmi2CoSimulation
+} fmi2Type;
+
+typedef enum {
+    fmi2DoStepStatus,
+    fmi2PendingStatus,
+    fmi2LastSuccessfulTime,
+    fmi2Terminated
+} fmi2StatusKind;
+
+typedef void      (*fmi2CallbackLogger)        (fmi2ComponentEnvironment, fmi2String, fmi2Status, fmi2String, fmi2String, ...);
+typedef void*     (*fmi2CallbackAllocateMemory)(size_t, size_t);
+typedef void      (*fmi2CallbackFreeMemory)    (void*);
+typedef void      (*fmi2StepFinished)          (fmi2ComponentEnvironment, fmi2Status);
+
+typedef struct {
+   const fmi2CallbackLogger         logger;
+   const fmi2CallbackAllocateMemory allocateMemory;
+   const fmi2CallbackFreeMemory     freeMemory;
+   const fmi2StepFinished           stepFinished;
+   const fmi2ComponentEnvironment   componentEnvironment;
+} fmi2CallbackFunctions;
+
+typedef struct {
+	 fmi2Boolean newDiscreteStatesNeeded;
+   fmi2Boolean terminateSimulation;
+   fmi2Boolean nominalsOfContinuousStatesChanged;
+   fmi2Boolean valuesOfContinuousStatesChanged;
+   fmi2Boolean nextEventTimeDefined;
+   fmi2Real    nextEventTime;
+} fmi2EventInfo;
+
+
+/* reset alignment policy to the one set before reading this file */
+#if defined _MSC_VER || defined __GNUC__
+#pragma pack(pop)
+#endif
+
+
+/* Define fmi2 function pointer types to simplify dynamic loading */
+
+/***************************************************
+Types for Common Functions
+****************************************************/
+
+/* Inquire version numbers of header files and setting logging status */
+   typedef const char* fmi2GetTypesPlatformTYPE(void);
+   typedef const char* fmi2GetVersionTYPE(void);
+   typedef fmi2Status  fmi2SetDebugLoggingTYPE(fmi2Component, fmi2Boolean, size_t, const fmi2String[]);
+
+/* Creation and destruction of FMU instances and setting debug status */
+   typedef fmi2Component fmi2InstantiateTYPE (fmi2String, fmi2Type, fmi2String, fmi2String, const fmi2CallbackFunctions*, fmi2Boolean, fmi2Boolean);
+   typedef void          fmi2FreeInstanceTYPE(fmi2Component);
+
+/* Enter and exit initialization mode, terminate and reset */
+   typedef fmi2Status fmi2SetupExperimentTYPE        (fmi2Component, fmi2Boolean, fmi2Real, fmi2Real, fmi2Boolean, fmi2Real);
+   typedef fmi2Status fmi2EnterInitializationModeTYPE(fmi2Component);
+   typedef fmi2Status fmi2ExitInitializationModeTYPE (fmi2Component);
+   typedef fmi2Status fmi2TerminateTYPE              (fmi2Component);
+   typedef fmi2Status fmi2ResetTYPE                  (fmi2Component);
+
+/* Getting and setting variable values */
+   typedef fmi2Status fmi2GetRealTYPE   (fmi2Component, const fmi2ValueReference[], size_t, fmi2Real   []);
+   typedef fmi2Status fmi2GetIntegerTYPE(fmi2Component, const fmi2ValueReference[], size_t, fmi2Integer[]);
+   typedef fmi2Status fmi2GetBooleanTYPE(fmi2Component, const fmi2ValueReference[], size_t, fmi2Boolean[]);
+   typedef fmi2Status fmi2GetStringTYPE (fmi2Component, const fmi2ValueReference[], size_t, fmi2String []);
+
+   typedef fmi2Status fmi2SetRealTYPE   (fmi2Component, const fmi2ValueReference[], size_t, const fmi2Real   []);
+   typedef fmi2Status fmi2SetIntegerTYPE(fmi2Component, const fmi2ValueReference[], size_t, const fmi2Integer[]);
+   typedef fmi2Status fmi2SetBooleanTYPE(fmi2Component, const fmi2ValueReference[], size_t, const fmi2Boolean[]);
+   typedef fmi2Status fmi2SetStringTYPE (fmi2Component, const fmi2ValueReference[], size_t, const fmi2String []);
+
+/* Getting and setting the internal FMU state */
+   typedef fmi2Status fmi2GetFMUstateTYPE           (fmi2Component, fmi2FMUstate*);
+   typedef fmi2Status fmi2SetFMUstateTYPE           (fmi2Component, fmi2FMUstate);
+   typedef fmi2Status fmi2FreeFMUstateTYPE          (fmi2Component, fmi2FMUstate*);
+   typedef fmi2Status fmi2SerializedFMUstateSizeTYPE(fmi2Component, fmi2FMUstate, size_t*);
+   typedef fmi2Status fmi2SerializeFMUstateTYPE     (fmi2Component, fmi2FMUstate, fmi2Byte[], size_t);
+   typedef fmi2Status fmi2DeSerializeFMUstateTYPE   (fmi2Component, const fmi2Byte[], size_t, fmi2FMUstate*);
+
+/* Getting partial derivatives */
+   typedef fmi2Status fmi2GetDirectionalDerivativeTYPE(fmi2Component, const fmi2ValueReference[], size_t,
+                                                                   const fmi2ValueReference[], size_t,
+                                                                   const fmi2Real[], fmi2Real[]);
+
+/***************************************************
+Types for Functions for FMI2 for Model Exchange
+****************************************************/
+
+/* Enter and exit the different modes */
+   typedef fmi2Status fmi2EnterEventModeTYPE         (fmi2Component);
+   typedef fmi2Status fmi2NewDiscreteStatesTYPE      (fmi2Component, fmi2EventInfo*);
+   typedef fmi2Status fmi2EnterContinuousTimeModeTYPE(fmi2Component);
+   typedef fmi2Status fmi2CompletedIntegratorStepTYPE(fmi2Component, fmi2Boolean, fmi2Boolean*, fmi2Boolean*);
+
+/* Providing independent variables and re-initialization of caching */
+   typedef fmi2Status fmi2SetTimeTYPE            (fmi2Component, fmi2Real);
+   typedef fmi2Status fmi2SetContinuousStatesTYPE(fmi2Component, const fmi2Real[], size_t);
+
+/* Evaluation of the model equations */
+   typedef fmi2Status fmi2GetDerivativesTYPE               (fmi2Component, fmi2Real[], size_t);
+   typedef fmi2Status fmi2GetEventIndicatorsTYPE           (fmi2Component, fmi2Real[], size_t);
+   typedef fmi2Status fmi2GetContinuousStatesTYPE          (fmi2Component, fmi2Real[], size_t);
+   typedef fmi2Status fmi2GetNominalsOfContinuousStatesTYPE(fmi2Component, fmi2Real[], size_t);
+
+
+/***************************************************
+Types for Functions for FMI2 for Co-Simulation
+****************************************************/
+
+/* Simulating the slave */
+   typedef fmi2Status fmi2SetRealInputDerivativesTYPE (fmi2Component, const fmi2ValueReference [], size_t, const fmi2Integer [], const fmi2Real []);
+   typedef fmi2Status fmi2GetRealOutputDerivativesTYPE(fmi2Component, const fmi2ValueReference [], size_t, const fmi2Integer [], fmi2Real []);
+
+   typedef fmi2Status fmi2DoStepTYPE     (fmi2Component, fmi2Real, fmi2Real, fmi2Boolean);
+   typedef fmi2Status fmi2CancelStepTYPE (fmi2Component);
+
+/* Inquire slave status */
+   typedef fmi2Status fmi2GetStatusTYPE       (fmi2Component, const fmi2StatusKind, fmi2Status* );
+   typedef fmi2Status fmi2GetRealStatusTYPE   (fmi2Component, const fmi2StatusKind, fmi2Real*   );
+   typedef fmi2Status fmi2GetIntegerStatusTYPE(fmi2Component, const fmi2StatusKind, fmi2Integer*);
+   typedef fmi2Status fmi2GetBooleanStatusTYPE(fmi2Component, const fmi2StatusKind, fmi2Boolean*);
+   typedef fmi2Status fmi2GetStringStatusTYPE (fmi2Component, const fmi2StatusKind, fmi2String* );
+
+
+#ifdef __cplusplus
+}  /* end of extern "C" { */
+#endif
+
+#endif /* fmi2FunctionTypes_h */

+ 333 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/include/fmi2Functions.h

@@ -0,0 +1,333 @@
+#ifndef fmi2Functions_h
+#define fmi2Functions_h
+
+/* This header file must be utilized when compiling a FMU.
+   It defines all functions of the
+         FMI 2.0 Model Exchange and Co-Simulation Interface.
+
+   In order to have unique function names even if several FMUs
+   are compiled together (e.g. for embedded systems), every "real" function name
+   is constructed by prepending the function name by "FMI2_FUNCTION_PREFIX".
+   Therefore, the typical usage is:
+
+      #define FMI2_FUNCTION_PREFIX MyModel_
+      #include "fmi2Functions.h"
+
+   As a result, a function that is defined as "fmi2GetDerivatives" in this header file,
+   is actually getting the name "MyModel_fmi2GetDerivatives".
+
+   This only holds if the FMU is shipped in C source code, or is compiled in a
+   static link library. For FMUs compiled in a DLL/sharedObject, the "actual" function
+   names are used and "FMI2_FUNCTION_PREFIX" must not be defined.
+
+   Revisions:
+   - Apr.  9, 2014: all prefixes "fmi" renamed to "fmi2" (decision from April 8)
+   - Mar. 26, 2014: FMI_Export set to empty value if FMI_Export and FMI_FUNCTION_PREFIX
+                    are not defined (#173)
+   - Oct. 11, 2013: Functions of ModelExchange and CoSimulation merged:
+                      fmiInstantiateModel , fmiInstantiateSlave  -> fmiInstantiate
+                      fmiFreeModelInstance, fmiFreeSlaveInstance -> fmiFreeInstance
+                      fmiEnterModelInitializationMode, fmiEnterSlaveInitializationMode -> fmiEnterInitializationMode
+                      fmiExitModelInitializationMode , fmiExitSlaveInitializationMode  -> fmiExitInitializationMode
+                      fmiTerminateModel, fmiTerminateSlave  -> fmiTerminate
+                      fmiResetSlave -> fmiReset (now also for ModelExchange and not only for CoSimulation)
+                    Functions renamed:
+                      fmiUpdateDiscreteStates -> fmiNewDiscreteStates
+   - June 13, 2013: Functions removed:
+                       fmiInitializeModel
+                       fmiEventUpdate
+                       fmiCompletedEventIteration
+                       fmiInitializeSlave
+                    Functions added:
+                       fmiEnterModelInitializationMode
+                       fmiExitModelInitializationMode
+                       fmiEnterEventMode
+                       fmiUpdateDiscreteStates
+                       fmiEnterContinuousTimeMode
+                       fmiEnterSlaveInitializationMode;
+                       fmiExitSlaveInitializationMode;
+   - Feb. 17, 2013: Portability improvements:
+                       o DllExport changed to FMI_Export
+                       o FUNCTION_PREFIX changed to FMI_FUNCTION_PREFIX
+                       o Allow undefined FMI_FUNCTION_PREFIX (meaning no prefix is used)
+                    Changed function name "fmiTerminate" to "fmiTerminateModel" (due to #113)
+                    Changed function name "fmiGetNominalContinuousState" to
+                                          "fmiGetNominalsOfContinuousStates"
+                    Removed fmiGetStateValueReferences.
+   - Nov. 14, 2011: Adapted to FMI 2.0:
+                       o Split into two files (fmiFunctions.h, fmiTypes.h) in order
+                         that code that dynamically loads an FMU can directly
+                         utilize the header files).
+                       o Added C++ encapsulation of C-part, in order that the header
+                         file can be directly utilized in C++ code.
+                       o fmiCallbackFunctions is passed as pointer to fmiInstantiateXXX
+                       o stepFinished within fmiCallbackFunctions has as first
+                         argument "fmiComponentEnvironment" and not "fmiComponent".
+                       o New functions to get and set the complete FMU state
+                         and to compute partial derivatives.
+   - Nov.  4, 2010: Adapted to specification text:
+                       o fmiGetModelTypesPlatform renamed to fmiGetTypesPlatform
+                       o fmiInstantiateSlave: Argument GUID     replaced by fmuGUID
+                                              Argument mimetype replaced by mimeType
+                       o tabs replaced by spaces
+   - Oct. 16, 2010: Functions for FMI for Co-simulation added
+   - Jan. 20, 2010: stateValueReferencesChanged added to struct fmiEventInfo (ticket #27)
+                    (by M. Otter, DLR)
+                    Added WIN32 pragma to define the struct layout (ticket #34)
+                    (by J. Mauss, QTronic)
+   - Jan.  4, 2010: Removed argument intermediateResults from fmiInitialize
+                    Renamed macro fmiGetModelFunctionsVersion to fmiGetVersion
+                    Renamed macro fmiModelFunctionsVersion to fmiVersion
+                    Replaced fmiModel by fmiComponent in decl of fmiInstantiateModel
+                    (by J. Mauss, QTronic)
+   - Dec. 17, 2009: Changed extension "me" to "fmi" (by Martin Otter, DLR).
+   - Dez. 14, 2009: Added eventInfo to meInitialize and added
+                    meGetNominalContinuousStates (by Martin Otter, DLR)
+   - Sept. 9, 2009: Added DllExport (according to Peter Nilsson's suggestion)
+                    (by A. Junghanns, QTronic)
+   - Sept. 9, 2009: Changes according to FMI-meeting on July 21:
+                    meInquireModelTypesVersion     -> meGetModelTypesPlatform
+                    meInquireModelFunctionsVersion -> meGetModelFunctionsVersion
+                    meSetStates                    -> meSetContinuousStates
+                    meGetStates                    -> meGetContinuousStates
+                    removal of meInitializeModelClass
+                    removal of meGetTime
+                    change of arguments of meInstantiateModel
+                    change of arguments of meCompletedIntegratorStep
+                    (by Martin Otter, DLR):
+   - July 19, 2009: Added "me" as prefix to file names (by Martin Otter, DLR).
+   - March 2, 2009: Changed function definitions according to the last design
+                    meeting with additional improvements (by Martin Otter, DLR).
+   - Dec. 3 , 2008: First version by Martin Otter (DLR) and Hans Olsson (Dynasim).
+
+   Copyright © 2008-2011 MODELISAR consortium,
+               2012-2013 Modelica Association Project "FMI"
+               All rights reserved.
+   This file is licensed by the copyright holders under the BSD 2-Clause License
+   (http://www.opensource.org/licenses/bsd-license.html):
+
+   ----------------------------------------------------------------------------
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   - Redistributions of source code must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+   - Redistributions in binary form must reproduce the above copyright notice,
+     this list of conditions and the following disclaimer in the documentation
+     and/or other materials provided with the distribution.
+   - Neither the name of the copyright holders nor the names of its
+     contributors may be used to endorse or promote products derived
+     from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+   TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+   OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+   ----------------------------------------------------------------------------
+
+   with the extension:
+
+   You may distribute or publicly perform any modification only under the
+   terms of this license.
+   (Note, this means that if you distribute a modified file,
+    the modified file must also be provided under this license).
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "fmi2TypesPlatform.h"
+#include "fmi2FunctionTypes.h"
+#include <stdlib.h>
+
+
+/*
+  Export FMI2 API functions on Windows and under GCC.
+  If custom linking is desired then the FMI2_Export must be
+  defined before including this file. For instance,
+  it may be set to __declspec(dllimport).
+*/
+#if !defined(FMI2_Export)
+  #if !defined(FMI2_FUNCTION_PREFIX)
+    #if defined _WIN32 || defined __CYGWIN__
+     /* Note: both gcc & MSVC on Windows support this syntax. */
+        #define FMI2_Export __declspec(dllexport)
+    #else
+      #if __GNUC__ >= 4
+        #define FMI2_Export __attribute__ ((visibility ("default")))
+      #else
+        #define FMI2_Export
+      #endif
+    #endif
+  #else
+    #define FMI2_Export
+  #endif
+#endif
+
+/* Macros to construct the real function name
+   (prepend function name by FMI2_FUNCTION_PREFIX) */
+#if defined(FMI2_FUNCTION_PREFIX)
+  #define fmi2Paste(a,b)     a ## b
+  #define fmi2PasteB(a,b)    fmi2Paste(a,b)
+  #define fmi2FullName(name) fmi2PasteB(FMI2_FUNCTION_PREFIX, name)
+#else
+  #define fmi2FullName(name) name
+#endif
+
+/***************************************************
+Common Functions
+****************************************************/
+#define fmi2GetTypesPlatform         fmi2FullName(fmi2GetTypesPlatform)
+#define fmi2GetVersion               fmi2FullName(fmi2GetVersion)
+#define fmi2SetDebugLogging          fmi2FullName(fmi2SetDebugLogging)
+#define fmi2Instantiate              fmi2FullName(fmi2Instantiate)
+#define fmi2FreeInstance             fmi2FullName(fmi2FreeInstance)
+#define fmi2SetupExperiment          fmi2FullName(fmi2SetupExperiment)
+#define fmi2EnterInitializationMode  fmi2FullName(fmi2EnterInitializationMode)
+#define fmi2ExitInitializationMode   fmi2FullName(fmi2ExitInitializationMode)
+#define fmi2Terminate                fmi2FullName(fmi2Terminate)
+#define fmi2Reset                    fmi2FullName(fmi2Reset)
+#define fmi2GetReal                  fmi2FullName(fmi2GetReal)
+#define fmi2GetInteger               fmi2FullName(fmi2GetInteger)
+#define fmi2GetBoolean               fmi2FullName(fmi2GetBoolean)
+#define fmi2GetString                fmi2FullName(fmi2GetString)
+#define fmi2SetReal                  fmi2FullName(fmi2SetReal)
+#define fmi2SetInteger               fmi2FullName(fmi2SetInteger)
+#define fmi2SetBoolean               fmi2FullName(fmi2SetBoolean)
+#define fmi2SetString                fmi2FullName(fmi2SetString)
+#define fmi2GetFMUstate              fmi2FullName(fmi2GetFMUstate)
+#define fmi2SetFMUstate              fmi2FullName(fmi2SetFMUstate)
+#define fmi2FreeFMUstate             fmi2FullName(fmi2FreeFMUstate)
+#define fmi2SerializedFMUstateSize   fmi2FullName(fmi2SerializedFMUstateSize)
+#define fmi2SerializeFMUstate        fmi2FullName(fmi2SerializeFMUstate)
+#define fmi2DeSerializeFMUstate      fmi2FullName(fmi2DeSerializeFMUstate)
+#define fmi2GetDirectionalDerivative fmi2FullName(fmi2GetDirectionalDerivative)
+
+
+/***************************************************
+Functions for FMI2 for Model Exchange
+****************************************************/
+#define fmi2EnterEventMode                fmi2FullName(fmi2EnterEventMode)
+#define fmi2NewDiscreteStates             fmi2FullName(fmi2NewDiscreteStates)
+#define fmi2EnterContinuousTimeMode       fmi2FullName(fmi2EnterContinuousTimeMode)
+#define fmi2CompletedIntegratorStep       fmi2FullName(fmi2CompletedIntegratorStep)
+#define fmi2SetTime                       fmi2FullName(fmi2SetTime)
+#define fmi2SetContinuousStates           fmi2FullName(fmi2SetContinuousStates)
+#define fmi2GetDerivatives                fmi2FullName(fmi2GetDerivatives)
+#define fmi2GetEventIndicators            fmi2FullName(fmi2GetEventIndicators)
+#define fmi2GetContinuousStates           fmi2FullName(fmi2GetContinuousStates)
+#define fmi2GetNominalsOfContinuousStates fmi2FullName(fmi2GetNominalsOfContinuousStates)
+
+
+/***************************************************
+Functions for FMI2 for Co-Simulation
+****************************************************/
+#define fmi2SetRealInputDerivatives      fmi2FullName(fmi2SetRealInputDerivatives)
+#define fmi2GetRealOutputDerivatives     fmi2FullName(fmi2GetRealOutputDerivatives)
+#define fmi2DoStep                       fmi2FullName(fmi2DoStep)
+#define fmi2CancelStep                   fmi2FullName(fmi2CancelStep)
+#define fmi2GetStatus                    fmi2FullName(fmi2GetStatus)
+#define fmi2GetRealStatus                fmi2FullName(fmi2GetRealStatus)
+#define fmi2GetIntegerStatus             fmi2FullName(fmi2GetIntegerStatus)
+#define fmi2GetBooleanStatus             fmi2FullName(fmi2GetBooleanStatus)
+#define fmi2GetStringStatus              fmi2FullName(fmi2GetStringStatus)
+
+/* Version number */
+#define fmi2Version "2.0"
+
+
+/***************************************************
+Common Functions
+****************************************************/
+
+/* Inquire version numbers of header files */
+   FMI2_Export fmi2GetTypesPlatformTYPE fmi2GetTypesPlatform;
+   FMI2_Export fmi2GetVersionTYPE       fmi2GetVersion;
+   FMI2_Export fmi2SetDebugLoggingTYPE  fmi2SetDebugLogging;
+
+/* Creation and destruction of FMU instances */
+   FMI2_Export fmi2InstantiateTYPE  fmi2Instantiate;
+   FMI2_Export fmi2FreeInstanceTYPE fmi2FreeInstance;
+
+/* Enter and exit initialization mode, terminate and reset */
+   FMI2_Export fmi2SetupExperimentTYPE         fmi2SetupExperiment;
+   FMI2_Export fmi2EnterInitializationModeTYPE fmi2EnterInitializationMode;
+   FMI2_Export fmi2ExitInitializationModeTYPE  fmi2ExitInitializationMode;
+   FMI2_Export fmi2TerminateTYPE               fmi2Terminate;
+   FMI2_Export fmi2ResetTYPE                   fmi2Reset;
+
+/* Getting and setting variables values */
+   FMI2_Export fmi2GetRealTYPE    fmi2GetReal;
+   FMI2_Export fmi2GetIntegerTYPE fmi2GetInteger;
+   FMI2_Export fmi2GetBooleanTYPE fmi2GetBoolean;
+   FMI2_Export fmi2GetStringTYPE  fmi2GetString;
+
+   FMI2_Export fmi2SetRealTYPE    fmi2SetReal;
+   FMI2_Export fmi2SetIntegerTYPE fmi2SetInteger;
+   FMI2_Export fmi2SetBooleanTYPE fmi2SetBoolean;
+   FMI2_Export fmi2SetStringTYPE  fmi2SetString;
+
+/* Getting and setting the internal FMU state */
+   FMI2_Export fmi2GetFMUstateTYPE            fmi2GetFMUstate;
+   FMI2_Export fmi2SetFMUstateTYPE            fmi2SetFMUstate;
+   FMI2_Export fmi2FreeFMUstateTYPE           fmi2FreeFMUstate;
+   FMI2_Export fmi2SerializedFMUstateSizeTYPE fmi2SerializedFMUstateSize;
+   FMI2_Export fmi2SerializeFMUstateTYPE      fmi2SerializeFMUstate;
+   FMI2_Export fmi2DeSerializeFMUstateTYPE    fmi2DeSerializeFMUstate;
+
+/* Getting partial derivatives */
+   FMI2_Export fmi2GetDirectionalDerivativeTYPE fmi2GetDirectionalDerivative;
+
+
+/***************************************************
+Functions for FMI2 for Model Exchange
+****************************************************/
+
+/* Enter and exit the different modes */
+   FMI2_Export fmi2EnterEventModeTYPE               fmi2EnterEventMode;
+   FMI2_Export fmi2NewDiscreteStatesTYPE            fmi2NewDiscreteStates;
+   FMI2_Export fmi2EnterContinuousTimeModeTYPE      fmi2EnterContinuousTimeMode;
+   FMI2_Export fmi2CompletedIntegratorStepTYPE      fmi2CompletedIntegratorStep;
+
+/* Providing independent variables and re-initialization of caching */
+   FMI2_Export fmi2SetTimeTYPE             fmi2SetTime;
+   FMI2_Export fmi2SetContinuousStatesTYPE fmi2SetContinuousStates;
+
+/* Evaluation of the model equations */
+   FMI2_Export fmi2GetDerivativesTYPE                fmi2GetDerivatives;
+   FMI2_Export fmi2GetEventIndicatorsTYPE            fmi2GetEventIndicators;
+   FMI2_Export fmi2GetContinuousStatesTYPE           fmi2GetContinuousStates;
+   FMI2_Export fmi2GetNominalsOfContinuousStatesTYPE fmi2GetNominalsOfContinuousStates;
+
+
+/***************************************************
+Functions for FMI2 for Co-Simulation
+****************************************************/
+
+/* Simulating the slave */
+   FMI2_Export fmi2SetRealInputDerivativesTYPE  fmi2SetRealInputDerivatives;
+   FMI2_Export fmi2GetRealOutputDerivativesTYPE fmi2GetRealOutputDerivatives;
+
+   FMI2_Export fmi2DoStepTYPE     fmi2DoStep;
+   FMI2_Export fmi2CancelStepTYPE fmi2CancelStep;
+
+/* Inquire slave status */
+   FMI2_Export fmi2GetStatusTYPE        fmi2GetStatus;
+   FMI2_Export fmi2GetRealStatusTYPE    fmi2GetRealStatus;
+   FMI2_Export fmi2GetIntegerStatusTYPE fmi2GetIntegerStatus;
+   FMI2_Export fmi2GetBooleanStatusTYPE fmi2GetBooleanStatus;
+   FMI2_Export fmi2GetStringStatusTYPE  fmi2GetStringStatus;
+
+#ifdef __cplusplus
+}  /* end of extern "C" { */
+#endif
+
+#endif /* fmi2Functions_h */

+ 115 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/include/fmi2TypesPlatform.h

@@ -0,0 +1,115 @@
+#ifndef fmi2TypesPlatform_h
+#define fmi2TypesPlatform_h
+
+/* Standard header file to define the argument types of the
+   functions of the Functional Mock-up Interface 2.0.
+   This header file must be utilized both by the model and
+   by the simulation engine.
+
+   Revisions:
+   - Apr.  9, 2014: all prefixes "fmi" renamed to "fmi2" (decision from April 8)
+   - Mar   31, 2014: New datatype fmiChar introduced.
+   - Feb.  17, 2013: Changed fmiTypesPlatform from "standard32" to "default".
+                     Removed fmiUndefinedValueReference since no longer needed
+                     (because every state is defined in ScalarVariables).
+   - March 20, 2012: Renamed from fmiPlatformTypes.h to fmiTypesPlatform.h
+   - Nov.  14, 2011: Use the header file "fmiPlatformTypes.h" for FMI 2.0
+                     both for "FMI for model exchange" and for "FMI for co-simulation"
+                     New types "fmiComponentEnvironment", "fmiState", and "fmiByte".
+                     The implementation of "fmiBoolean" is change from "char" to "int".
+                     The #define "fmiPlatform" changed to "fmiTypesPlatform"
+                     (in order that #define and function call are consistent)
+   - Oct.   4, 2010: Renamed header file from "fmiModelTypes.h" to fmiPlatformTypes.h"
+                     for the co-simulation interface
+   - Jan.   4, 2010: Renamed meModelTypes_h to fmiModelTypes_h (by Mauss, QTronic)
+   - Dec.  21, 2009: Changed "me" to "fmi" and "meModel" to "fmiComponent"
+                     according to meeting on Dec. 18 (by Martin Otter, DLR)
+   - Dec.   6, 2009: Added meUndefinedValueReference (by Martin Otter, DLR)
+   - Sept.  9, 2009: Changes according to FMI-meeting on July 21:
+                     Changed "version" to "platform", "standard" to "standard32",
+                     Added a precise definition of "standard32" as comment
+                     (by Martin Otter, DLR)
+   - July  19, 2009: Added "me" as prefix to file names, added meTrue/meFalse,
+                     and changed meValueReferenced from int to unsigned int
+                     (by Martin Otter, DLR).
+   - March  2, 2009: Moved enums and function pointer definitions to
+                     ModelFunctions.h (by Martin Otter, DLR).
+   - Dec.  3, 2008 : First version by Martin Otter (DLR) and
+                     Hans Olsson (Dynasim).
+
+
+   Copyright © 2008-2011 MODELISAR consortium,
+               2012-2013 Modelica Association Project "FMI"
+               All rights reserved.
+   This file is licensed by the copyright holders under the BSD 2-Clause License
+   (http://www.opensource.org/licenses/bsd-license.html):
+
+   ----------------------------------------------------------------------------
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   - Redistributions of source code must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+   - Redistributions in binary form must reproduce the above copyright notice,
+     this list of conditions and the following disclaimer in the documentation
+     and/or other materials provided with the distribution.
+   - Neither the name of the copyright holders nor the names of its
+     contributors may be used to endorse or promote products derived
+     from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+   TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+   OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+   ----------------------------------------------------------------------------
+
+   with the extension:
+
+   You may distribute or publicly perform any modification only under the
+   terms of this license.
+   (Note, this means that if you distribute a modified file,
+    the modified file must also be provided under this license).
+*/
+
+/* Platform (unique identification of this header file) */
+#define fmi2TypesPlatform "default"
+
+/* Type definitions of variables passed as arguments
+   Version "default" means:
+
+   fmi2Component           : an opaque object pointer
+   fmi2ComponentEnvironment: an opaque object pointer
+   fmi2FMUstate            : an opaque object pointer
+   fmi2ValueReference      : handle to the value of a variable
+   fmi2Real                : double precision floating-point data type
+   fmi2Integer             : basic signed integer data type
+   fmi2Boolean             : basic signed integer data type
+   fmi2Char                : character data type
+   fmi2String              : a pointer to a vector of fmi2Char characters
+                             ('\0' terminated, UTF8 encoded)
+   fmi2Byte                : smallest addressable unit of the machine, typically one byte.
+*/
+   typedef void*           fmi2Component;               /* Pointer to FMU instance       */
+   typedef void*           fmi2ComponentEnvironment;    /* Pointer to FMU environment    */
+   typedef void*           fmi2FMUstate;                /* Pointer to internal FMU state */
+   typedef unsigned int    fmi2ValueReference;
+   typedef double          fmi2Real   ;
+   typedef int             fmi2Integer;
+   typedef int             fmi2Boolean;
+   typedef char            fmi2Char;
+   typedef const fmi2Char* fmi2String;
+   typedef char            fmi2Byte;
+
+/* Values for fmi2Boolean  */
+#define fmi2True  1
+#define fmi2False 0
+
+
+#endif /* fmi2TypesPlatform_h */

+ 654 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlElement.cpp

@@ -0,0 +1,654 @@
+/*
+ * Copyright QTronic GmbH. All rights reserved.
+ */
+
+/* ---------------------------------------------------------------------------*
+ * XmlElement.cpp
+ * Elements implementation that describe content of model description of a
+ * FMI 2.0 model. All elements have Element as parent class. Elements have
+ * attributes and other specific content.
+ *
+ * Author: Adrian Tirea
+ * ---------------------------------------------------------------------------*/
+
+#include "XmlElement.h"
+#include <assert.h>
+#include <map>
+#include <string>
+#include <vector>
+#include "XmlParserException.h"
+
+#ifdef STANDALONE_XML_PARSER
+#define logThis(n, ...) printf(__VA_ARGS__); printf("\n")
+#else
+#include "GlobalIncludes.h"
+#include "logging.h"  // logThis
+#endif  // STANDALONE_XML_PARSER
+
+Element::~Element() {
+    for (std::map<XmlParser::Att, char *>::const_iterator it = attributes.begin(); it != attributes.end(); ++it) {
+        free(it->second);
+    }
+    attributes.clear();
+}
+template <typename T> void Element::deleteListOfElements(const std::vector<T *> &list) {
+    typename std::vector<T*>::const_iterator it;
+    for (it = list.begin(); it != list.end(); ++it) {
+        delete *it;
+    }
+}
+void Element::handleElement(XmlParser *parser, const char *childName, int isEmptyElement) {
+    throw XmlParserException("Elements are not expected inside '%s'. Found instead '%s'",
+        XmlParser::elmNames[type],
+        childName);
+}
+void Element::printElement(int indent) {
+    std::string indentS(indent, ' ');
+    logThis(ERROR_INFO, "%s%s", indentS.c_str(), XmlParser::elmNames[type]);
+    for (std::map<XmlParser::Att, char *>::const_iterator it = attributes.begin(); it != attributes.end(); ++it) {
+        logThis(ERROR_INFO, "%s%s=%s", indentS.c_str(), XmlParser::attNames[it->first], it->second);
+    }
+}
+template <typename T> void Element::printListOfElements(int indent, const std::vector<T *> &list) {
+    typename std::vector<T*>::const_iterator it;
+    for (it = list.begin(); it != list.end(); ++it) {
+        (*it)->printElement(indent);
+    }
+}
+
+const char *Element::getAttributeValue(XmlParser::Att att) {
+    std::map<XmlParser::Att, char *>::const_iterator it = attributes.find(att);
+    if (it != attributes.end()) {
+        return it->second;
+    }
+    return NULL;
+}
+int Element::getAttributeInt(XmlParser::Att att, XmlParser::ValueStatus *vs) {
+    int n = 0;
+    const char *value = getAttributeValue(att);
+    if (!value) { *vs = XmlParser::valueMissing; return n; }
+    *vs = (1 == sscanf(value, "%d", &n)) ? XmlParser::valueDefined : XmlParser::valueIllegal;
+    return n;
+}
+unsigned int Element::getAttributeUInt(XmlParser::Att att, XmlParser::ValueStatus *vs) {
+    unsigned int u = -1;
+    const char* value = getAttributeValue(att);
+    if (!value) { *vs = XmlParser::valueMissing; return u; }
+    *vs = (1 == sscanf(value, "%u", &u)) ? XmlParser::valueDefined : XmlParser::valueIllegal;
+    return u;
+}
+double Element::getAttributeDouble(XmlParser::Att att, XmlParser::ValueStatus *vs) {
+    double d = 0;
+    const char* value = getAttributeValue(att);
+    if (!value) { *vs = XmlParser::valueMissing; return d; }
+    *vs = (1 == sscanf(value, "%lf", &d)) ? XmlParser::valueDefined : XmlParser::valueIllegal;
+    return d;
+}
+bool Element::getAttributeBool(XmlParser::Att att, XmlParser::ValueStatus *vs) {
+    const char* value = getAttributeValue(att);
+    if (!value) {*vs = XmlParser::valueMissing; return false;}
+    *vs = XmlParser::valueDefined;
+    if (!strcmp(value, "true")) return true;
+    if (!strcmp(value, "false")) return false;
+    *vs = XmlParser::valueIllegal;
+    return false;
+}
+
+ListElement::~ListElement() {
+    deleteListOfElements(list);
+}
+void ListElement::handleElement(XmlParser *parser, const char *childName, int isEmptyElement) {
+    XmlParser::Elm childType = parser->checkElement(childName);
+    if (childType == XmlParser::elm_Item) {
+        Element *item = new Element;
+        item->type = childType;
+        parser->parseElementAttributes(item);
+        if (!isEmptyElement) {
+            parser->parseEndElement();
+        }
+        list.push_back(item);
+    } else {
+        throw XmlParserException("Expected '%s' element inside '%s'. Found instead: '%s'.",
+                XmlParser::elmNames[XmlParser::elm_Item],
+                XmlParser::elmNames[XmlParser::elm_Enumeration],
+                childName);
+    }
+}
+void ListElement::printElement(int indent) {
+    Element::printElement(indent);
+    int childIndent = indent + 1;
+    printListOfElements(childIndent, list);
+}
+
+
+Unit::Unit() {
+    baseUnit = NULL;
+}
+Unit::~Unit() {
+    if (baseUnit) delete baseUnit;
+    deleteListOfElements(displayUnits);
+}
+void Unit::handleElement(XmlParser *parser, const char *childName, int isEmptyElement) {
+    XmlParser::Elm childType = parser->checkElement(childName);
+    if (childType == XmlParser::elm_BaseUnit) {
+        baseUnit = new Element;
+        baseUnit->type = childType;
+        parser->parseElementAttributes(baseUnit);
+        if (!isEmptyElement) {
+            parser->parseEndElement();
+        }
+    } else if (childType == XmlParser::elm_DisplayUnit) {
+        Element *displayUnit = new Element;
+        displayUnit->type = childType;
+        parser->parseElementAttributes(displayUnit);
+        displayUnits.push_back(displayUnit);
+        if (!isEmptyElement) {
+            parser->parseEndElement();
+        }
+    } else {
+        throw XmlParserException("Expected '%s' | '%s' element inside '%s'. Found instead: '%s'.",
+            XmlParser::elmNames[XmlParser::elm_BaseUnit],
+            XmlParser::elmNames[XmlParser::elm_DisplayUnit],
+            XmlParser::elmNames[XmlParser::elm_SourceFiles],
+            childName);
+    }
+}
+void Unit::printElement(int indent) {
+    Element::printElement(indent);
+    int childIndent = indent + 1;
+    if (baseUnit) baseUnit->printElement(childIndent);
+    printListOfElements(childIndent, displayUnits);
+}
+
+
+SimpleType::SimpleType() {
+    typeSpec = NULL;
+}
+SimpleType::~SimpleType() {
+    if (typeSpec) delete typeSpec;
+}
+void SimpleType::handleElement(XmlParser *parser, const char *childName, int isEmptyElement) {
+    XmlParser::Elm childType = parser->checkElement(childName);
+    switch (childType) {
+        case XmlParser::elm_Real:
+        case XmlParser::elm_Integer:
+        case XmlParser::elm_Boolean:
+        case XmlParser::elm_String: {
+            typeSpec = new Element;
+            typeSpec->type = childType;
+            parser->parseElementAttributes(typeSpec);
+            if (!isEmptyElement) {
+                parser->parseEndElement();
+            }
+            break;
+        }
+        case XmlParser::elm_Enumeration: {
+            typeSpec = new ListElement;
+            typeSpec->type = childType;
+            parser->parseElementAttributes(typeSpec);
+            if (!isEmptyElement) {
+                parser->parseChildElements(typeSpec);
+            }
+            break;
+        }
+        default: {
+            throw XmlParserException(
+                "Expected '%s' | '%s' | '%s' | '%s' | '%s' element inside '%s'. Found instead: '%s'.",
+                XmlParser::elmNames[XmlParser::elm_Real],
+                XmlParser::elmNames[XmlParser::elm_Integer],
+                XmlParser::elmNames[XmlParser::elm_Boolean],
+                XmlParser::elmNames[XmlParser::elm_String],
+                XmlParser::elmNames[XmlParser::elm_Enumeration],
+                XmlParser::elmNames[type],
+                childName);
+        }
+    }
+}
+void SimpleType::printElement(int indent) {
+    Element::printElement(indent);
+    int childIndent = indent + 1;
+    if (typeSpec) typeSpec->printElement(childIndent);
+}
+
+
+Component::~Component() {
+    deleteListOfElements(files);
+}
+void Component::handleElement(XmlParser *parser, const char *childName, int isEmptyElement) {
+    XmlParser::Elm childType = parser->checkElement(childName);
+    if (childType == XmlParser::elm_SourceFiles) {
+        if (!isEmptyElement) {
+            parser->parseChildElements(this);
+        }
+    } else if (childType == XmlParser::elm_File) {
+        Element *sourceFile = new Element;
+        sourceFile->type = childType;
+        parser->parseElementAttributes(sourceFile);
+        if (!isEmptyElement) {
+            parser->parseEndElement();
+        }
+        files.push_back(sourceFile);
+    } else {
+        throw XmlParserException("Expected '%s' | '%s' element inside '%s'. Found instead: '%s'.",
+            XmlParser::elmNames[XmlParser::elm_File],
+            XmlParser::elmNames[XmlParser::elm_SourceFiles],
+            XmlParser::elmNames[type],
+            childName);
+    }
+}
+void Component::printElement(int indent) {
+    Element::printElement(indent);
+    int childIndent = indent + 1;
+    printListOfElements(childIndent, files);
+}
+
+
+ScalarVariable::ScalarVariable() {
+    typeSpec = NULL;
+}
+ScalarVariable::~ScalarVariable() {
+    delete typeSpec;
+    deleteListOfElements(annotations);
+}
+void ScalarVariable::handleElement(XmlParser *parser, const char *childName, int isEmptyElement) {
+    XmlParser::Elm childType = parser->checkElement(childName);
+    switch (childType) {
+        case XmlParser::elm_Real:
+        case XmlParser::elm_Integer:
+        case XmlParser::elm_Boolean:
+        case XmlParser::elm_String:
+        case XmlParser::elm_Enumeration: {
+            typeSpec = new Element;
+            typeSpec->type = childType;
+            parser->parseElementAttributes(typeSpec);
+            if (!isEmptyElement) {
+                parser->parseEndElement();
+            }
+            break;
+        }
+        case XmlParser::elm_Annotations: {
+            // no attributes expected; this class handles also the Tool
+            if (!isEmptyElement) parser->parseChildElements(this);
+            break;
+        }
+        case XmlParser::elm_Tool: {
+            Element *tool = new Element;
+            tool->type = childType;
+            parser->parseElementAttributes(tool, false);
+            if (!isEmptyElement) {
+                parser->parseSkipChildElement();
+            }
+            annotations.push_back(tool);
+            break;
+        }
+        default: {
+            throw XmlParserException(
+                "Expected '%s' | '%s' | '%s' | '%s' | '%s' | '%s' | '%s' element inside '%s'. Found instead: '%s'.",
+                XmlParser::elmNames[XmlParser::elm_Real],
+                XmlParser::elmNames[XmlParser::elm_Integer],
+                XmlParser::elmNames[XmlParser::elm_Boolean],
+                XmlParser::elmNames[XmlParser::elm_String],
+                XmlParser::elmNames[XmlParser::elm_Enumeration],
+                XmlParser::elmNames[XmlParser::elm_Annotations],
+                XmlParser::elmNames[XmlParser::elm_Tool],
+                XmlParser::elmNames[type],
+                childName);
+        }
+    }
+}
+fmi2ValueReference ScalarVariable::getValueReference() {
+    XmlParser::ValueStatus vs;
+    fmi2ValueReference ref = getAttributeUInt(XmlParser::att_valueReference, &vs);
+    assert(vs == XmlParser::valueDefined);  // this is a required attribute
+    return ref;
+}
+XmlParser::Enu ScalarVariable::getVariability() {
+    const char *value = getAttributeValue(XmlParser::att_variability);
+    if (!value) {
+        return XmlParser::enu_continuous;  // default
+    }
+    try {
+        return XmlParser::checkEnumValue(value);
+    } catch (XmlParserException& ) {
+        return XmlParser::enu_BAD_DEFINED;
+    }
+}
+XmlParser::Enu ScalarVariable::getCausality() {
+    const char *value = getAttributeValue(XmlParser::att_causality);
+    if (!value) {
+        return XmlParser::enu_local;  // default
+    }
+    try {
+        return XmlParser::checkEnumValue(value);
+    } catch (XmlParserException& ) {
+        return XmlParser::enu_BAD_DEFINED;
+    }
+}
+void ScalarVariable::printElement(int indent) {
+    Element::printElement(indent);
+    int childIndent = indent + 1;
+    typeSpec->printElement(childIndent);
+    printListOfElements(childIndent, annotations);
+}
+
+ModelStructure::ModelStructure() {
+    unknownParentType = XmlParser::elm_BAD_DEFINED;
+}
+
+ModelStructure::~ModelStructure() {
+    deleteListOfElements(outputs);
+    deleteListOfElements(derivatives);
+    deleteListOfElements(discreteStates);
+    deleteListOfElements(initialUnknowns);
+}
+void ModelStructure::handleElement(XmlParser *parser, const char *childName, int isEmptyElement) {
+    XmlParser::Elm childType = parser->checkElement(childName);
+    switch (childType) {
+    case XmlParser::elm_Outputs:
+    case XmlParser::elm_Derivatives:
+    case XmlParser::elm_DiscreteStates:
+    case XmlParser::elm_InitialUnknowns:
+        {
+            // no attributes expected; this class handles also the Unknown
+            if (!isEmptyElement) {
+                unknownParentType = childType;
+                parser->parseChildElements(this);
+            }
+            break;
+        }
+    case XmlParser::elm_Unknown:
+        {
+            Element *unknown = new Element;
+            unknown->type = childType;
+            parser->parseElementAttributes(unknown);
+            if (!isEmptyElement) {
+                parser->parseEndElement();
+            }
+            switch (unknownParentType) {
+                case XmlParser::elm_Outputs:
+                    outputs.push_back(unknown);
+                    break;
+                case XmlParser::elm_Derivatives:
+                    derivatives.push_back(unknown);
+                    break;
+                case XmlParser::elm_DiscreteStates:
+                    discreteStates.push_back(unknown);
+                    break;
+                case XmlParser::elm_InitialUnknowns:
+                    initialUnknowns.push_back(unknown);
+                    break;
+                default: {
+                    throw XmlParserException(
+                    "Element '%s' must be inside of '%s' | '%s' | '%s' | '%s'.",
+                    XmlParser::elmNames[XmlParser::elm_Unknown],
+                    XmlParser::elmNames[XmlParser::elm_Outputs],
+                    XmlParser::elmNames[XmlParser::elm_Derivatives],
+                    XmlParser::elmNames[XmlParser::elm_DiscreteStates],
+                    XmlParser::elmNames[XmlParser::elm_InitialUnknowns]);
+}
+            }
+            break;
+        }
+    default:
+        {
+            throw XmlParserException(
+                "Expected '%s' | '%s' | '%s' | '%s' | '%s' element inside '%s'. Found instead: '%s'.",
+                XmlParser::elmNames[XmlParser::elm_Outputs],
+                XmlParser::elmNames[XmlParser::elm_Derivatives],
+                XmlParser::elmNames[XmlParser::elm_DiscreteStates],
+                XmlParser::elmNames[XmlParser::elm_InitialUnknowns],
+                XmlParser::elmNames[XmlParser::elm_Unknown],
+                XmlParser::elmNames[type],
+                childName);
+        }
+    }
+}
+void ModelStructure::printElement(int indent) {
+    Element::printElement(indent);
+    int childIndent = indent + 1;
+    printListOfElements(childIndent, outputs);
+    printListOfElements(childIndent, derivatives);
+    printListOfElements(childIndent, discreteStates);
+    printListOfElements(childIndent, initialUnknowns);
+}
+
+
+ModelDescription::ModelDescription() {
+    modelExchange = NULL;
+    coSimulation = NULL;
+    defaultExperiment = NULL;
+    modelStructure = NULL;
+}
+ModelDescription::~ModelDescription() {
+    deleteListOfElements(unitDefinitions);
+    deleteListOfElements(typeDefinitions);
+    if (coSimulation) delete coSimulation;
+    if (modelExchange) delete modelExchange;
+    deleteListOfElements(logCategories);
+    if (defaultExperiment) delete defaultExperiment;
+    deleteListOfElements(vendorAnnotations);
+    deleteListOfElements(modelVariables);
+    if (modelStructure) delete modelStructure;
+}
+void ModelDescription::handleElement(XmlParser *parser, const char *childName, int isEmptyElement) {
+    XmlParser::Elm childType = parser->checkElement(childName);
+    switch (childType) {
+    case XmlParser::elm_CoSimulation:
+        {
+            coSimulation = new Component;
+            coSimulation->type = childType;
+            parser->parseElementAttributes(coSimulation);
+            if (!isEmptyElement) {
+                parser->parseChildElements(coSimulation);
+            }
+            break;
+        }
+    case XmlParser::elm_ModelExchange:
+        {
+            modelExchange = new Component;
+            modelExchange->type = childType;
+            parser->parseElementAttributes(modelExchange);
+            if (!isEmptyElement) {
+                parser->parseChildElements(modelExchange);
+            }
+            break;
+        }
+    case XmlParser::elm_UnitDefinitions:
+        {
+            // no attributes expected; this class handles the Category
+            if (!isEmptyElement) parser->parseChildElements(this);
+            break;
+        }
+    case XmlParser::elm_Unit:
+        {
+            Unit *unit = new Unit;
+            unit->type = childType;
+            parser->parseElementAttributes(unit);
+            if (!isEmptyElement) {
+                parser->parseChildElements(unit);
+            }
+            unitDefinitions.push_back(unit);
+            break;
+        }
+    case XmlParser::elm_TypeDefinitions:
+        {
+            // no attributes expected; this class handles also the SimpleType
+            if (!isEmptyElement) parser->parseChildElements(this);
+            break;
+        }
+    case XmlParser::elm_SimpleType:
+        {
+            SimpleType *type = new SimpleType;
+            type->type = childType;
+            parser->parseElementAttributes(type);
+            if (!isEmptyElement) {
+                parser->parseChildElements(type);
+            }
+            typeDefinitions.push_back(type);
+            break;
+        }
+    case XmlParser::elm_DefaultExperiment:
+        {
+            defaultExperiment = new Element;
+            defaultExperiment->type = childType;
+            parser->parseElementAttributes(defaultExperiment);
+            if (!isEmptyElement) {
+                parser->parseEndElement();
+            }
+            break;
+        }
+    case XmlParser::elm_LogCategories:
+        {
+            // no attributes expected; this class handles also the Category
+            if (!isEmptyElement) parser->parseChildElements(this);
+            break;
+        }
+    case XmlParser::elm_Category:
+        {
+            Element *category = new Element;
+            category->type = childType;
+            parser->parseElementAttributes(category);
+            if (!isEmptyElement) {
+                parser->parseEndElement();
+            }
+            logCategories.push_back(category);
+            break;
+        }
+    case XmlParser::elm_VendorAnnotations:
+        {
+            // no attributes expected; this class handles also the Tool
+            if (!isEmptyElement) parser->parseChildElements(this);
+            break;
+        }
+    case XmlParser::elm_Tool:
+        {
+            Element *tool = new Element;
+            tool->type = childType;
+            parser->parseElementAttributes(tool, false);
+            if (!isEmptyElement) {
+                parser->parseSkipChildElement();
+            }
+            vendorAnnotations.push_back(tool);
+            break;
+        }
+    case XmlParser::elm_ModelVariables:
+        {
+            // no attributes expected; this class handles also the ScalarVariable
+            if (!isEmptyElement) parser->parseChildElements(this);
+            break;
+        }
+    case XmlParser::elm_ScalarVariable:
+        {
+            ScalarVariable *variable = new ScalarVariable;
+            variable->type = childType;
+            parser->parseElementAttributes(variable);
+            if (!isEmptyElement) {
+                parser->parseChildElements(variable);
+            }
+            modelVariables.push_back(variable);
+            break;
+        }
+    case XmlParser::elm_ModelStructure:
+        {
+            modelStructure = new ModelStructure;
+            modelStructure->type = childType;
+            parser->parseElementAttributes(modelStructure);
+            if (!isEmptyElement) {
+                parser->parseChildElements(modelStructure);
+            }
+            break;
+        }
+    default:
+        throw XmlParserException("Element '%s' is not expected inside of '%s' | '%s' | '%s' | '%s'.",
+            childName,
+            XmlParser::elmNames[type]);
+    }
+}
+
+void ModelDescription::printElement(int indent) {
+    Element::printElement(indent);
+    int childIndent = indent + 1;
+
+    if (coSimulation) coSimulation->printElement(childIndent);
+    if (modelExchange) modelExchange->printElement(childIndent);
+    for (std::vector<Unit *>::const_iterator it = unitDefinitions.begin(); it != unitDefinitions.end(); ++it) {
+        (*it)->printElement(childIndent);
+    }
+    for (std::vector<SimpleType *>::const_iterator it = typeDefinitions.begin(); it != typeDefinitions.end(); ++it) {
+        (*it)->printElement(childIndent);
+    }
+    for (std::vector<Element *>::const_iterator it = logCategories.begin(); it != logCategories.end(); ++it) {
+        (*it)->printElement(childIndent);
+    }
+    if (defaultExperiment) defaultExperiment->printElement(childIndent);
+    for (std::vector<Element *>::const_iterator it = vendorAnnotations.begin(); it != vendorAnnotations.end(); ++it) {
+        (*it)->printElement(childIndent);
+    }
+    for (std::vector<ScalarVariable *>::const_iterator it = modelVariables.begin(); it != modelVariables.end(); ++it) {
+        (*it)->printElement(childIndent);
+    }
+    if (modelStructure) modelStructure->printElement(childIndent);
+}
+
+SimpleType *ModelDescription::getSimpleType(const char *name) {
+    for (std::vector<SimpleType *>::const_iterator it = typeDefinitions.begin(); it != typeDefinitions.end(); ++it) {
+        const char *typeName = (*it)->getAttributeValue(XmlParser::att_name);
+        if (typeName && 0 == strcmp(typeName, name)) {
+            return (*it);
+        }
+    }
+    return NULL;
+}
+
+ScalarVariable *ModelDescription::getVariable(const char *name) {
+    if (!name) return NULL;
+    for (std::vector<ScalarVariable *>::const_iterator it = modelVariables.begin(); it != modelVariables.end(); ++it) {
+        const char *varName = (*it)->getAttributeValue(XmlParser::att_name);
+        if (varName && 0 == strcmp(name, varName)) {
+            return (*it);
+        }
+    }
+    return NULL;
+}
+
+// Enumeration and Integer have the same base type while
+// Real, String, Boolean define own base types.
+static int sameBaseType(XmlParser::Elm  t1, XmlParser::Elm  t2){
+    return t1 == t2 ||
+           t1 == XmlParser::elm_Enumeration && t2 == XmlParser::elm_Integer ||
+           t2 == XmlParser::elm_Enumeration && t1 == XmlParser::elm_Integer;
+}
+
+ScalarVariable *ModelDescription::getVariable(fmi2ValueReference vr, XmlParser::Elm type) {
+    for (std::vector<ScalarVariable *>::const_iterator it = modelVariables.begin(); it != modelVariables.end(); ++it) {
+        if (vr == (*it)->getValueReference() && sameBaseType(type, (*it)->typeSpec->type)) {
+            return (*it);
+        }
+    }
+    return NULL;
+}
+
+const char *ModelDescription::getDescriptionForVariable(ScalarVariable *sv) {
+    const char *desc = sv->getAttributeValue(XmlParser::att_description);
+    // found description
+    if (desc) return desc;
+    // look for description of declared type:
+    const char *typeName = sv->typeSpec->getAttributeValue(XmlParser::att_declaredType);
+    if (typeName) {
+        SimpleType *type = getSimpleType(typeName);
+        if (type) return type->getAttributeValue(XmlParser::att_description);
+    }
+    return NULL;
+}
+
+const char *ModelDescription::getAttributeFromTypeOrDeclaredType(ScalarVariable *sv, XmlParser::Att a) {
+    const char *stringValue = sv->typeSpec->getAttributeValue(a);
+    if (stringValue) return stringValue;
+    // look for stringValue inside declared type:
+    const char *typeName = sv->typeSpec->getAttributeValue(XmlParser::att_declaredType);
+    if (typeName) {
+        SimpleType *type = getSimpleType(typeName);
+        if (type) return type->getAttributeValue(a);
+    }
+    return NULL;
+}

+ 160 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlElement.h

@@ -0,0 +1,160 @@
+/*
+ * Copyright QTronic GmbH. All rights reserved.
+ */
+
+/* ---------------------------------------------------------------------------*
+ * XmlElement.h
+ * Contains elements classes that describe content of model description of a
+ * FMI 2.0 model. All elements have Element as parent class. Elements have
+ * attributes and other specific content.
+ *
+ * Author: Adrian Tirea
+ * ---------------------------------------------------------------------------*/
+
+#ifndef XML_ELEMENT_H
+#define XML_ELEMENT_H
+
+#include <map>
+#include <vector>
+#include "XmlParser.h"
+
+class Element {
+ public:
+    XmlParser::Elm type;  // element type
+    std::map<XmlParser::Att, char*> attributes;  // map with key one of XmlParser::Att
+
+ public:
+    virtual ~Element();
+    virtual void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
+    virtual void printElement(int indent);
+    const char *getAttributeValue(XmlParser::Att att);  // value or NULL if not present
+    int getAttributeInt(XmlParser::Att att, XmlParser::ValueStatus *vs);
+    unsigned int getAttributeUInt(XmlParser::Att att, XmlParser::ValueStatus *vs);
+    double getAttributeDouble(XmlParser::Att att, XmlParser::ValueStatus *vs);
+    bool getAttributeBool(XmlParser::Att att, XmlParser::ValueStatus *vs);
+
+    template <typename T> void printListOfElements(int indent, const std::vector<T *> &list);
+    template <typename T> void deleteListOfElements(const std::vector<T *> &list);
+};
+
+
+class ListElement : public Element {
+ public:
+    std::vector<Element*> list;  // list of Element
+
+ public:
+    ~ListElement();
+    void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
+    void printElement(int indent);
+};
+
+
+class Unit : public Element {
+ public:
+    std::vector<Element *> displayUnits;  // list of DisplayUnit
+    Element *baseUnit;                    // null or BaseUnit
+
+ public:
+    Unit();
+    ~Unit();
+    void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
+    void printElement(int indent);
+};
+
+
+class SimpleType : public Element {
+ public:
+    Element *typeSpec;  // one of RealType, IntegerType etc.
+
+ public:
+    SimpleType();
+    ~SimpleType();
+    void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
+    void printElement(int indent);
+};
+
+
+class Component : public Element {
+ public:
+    std::vector<Element *> files;  // list of File. Only meaningful for source code FMUs (not .dll).
+
+ public:
+    ~Component();
+    void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
+    void printElement(int indent);
+};
+
+
+class ScalarVariable : public Element {
+ public :
+    Element *typeSpec;                   // one of Real, Integer, etc
+    std::vector<Element *> annotations;  // list of Annotations
+    // int modelIdx;                     // only used in fmu10
+
+ public:
+    ScalarVariable();
+    ~ScalarVariable();
+    void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
+    void printElement(int indent);
+    // get the valueReference of current variable. This attribute is mandatory for a variable.
+    fmi2ValueReference getValueReference();
+    // returns one of constant, fixed, tunable, discrete, continuous.
+    // If value is missing, the default continuous is returned.
+    // If unknown value, return enu_BAD_DEFINED.
+    XmlParser::Enu getVariability();
+    // returns one of parameter, calculatedParameter, input, output, local, independent.
+    // If value is missing, the default local is returned.
+    // If unknown value, return enu_BAD_DEFINED.
+    XmlParser::Enu getCausality();
+};
+
+
+class ModelStructure : public Element {
+ private:
+    XmlParser::Elm unknownParentType;  // used in handleElement to know in which list next Unknown belongs.
+
+ public:
+    std::vector<Element *> outputs;            // list of Unknown
+    std::vector<Element *> derivatives;        // list of Unknown
+    std::vector<Element *> discreteStates;     // list of Unknown
+    std::vector<Element *> initialUnknowns;    // list of Unknown
+
+ public:
+    ModelStructure();
+    ~ModelStructure();
+    void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
+    void printElement(int indent);
+};
+
+class ModelDescription : public Element {
+ public:
+    std::vector<Unit *> unitDefinitions;        // list of Units
+    std::vector<SimpleType *> typeDefinitions;  // list of Types
+    Component *modelExchange;                   // NULL or ModelExchange
+    Component *coSimulation;                    // NULL or CoSimulation
+                                                // At least one of CoSimulation, ModelExchange must be present.
+    std::vector<Element *> logCategories;       // list of Category
+    Element *defaultExperiment;                 // NULL or DefaultExperiment
+    std::vector<Element *> vendorAnnotations;   // list of Tools
+    std::vector<ScalarVariable *> modelVariables;  // list of ScalarVariable
+    ModelStructure *modelStructure;             // not NULL ModelStructure
+
+ public:
+    ModelDescription();
+    ~ModelDescription();
+    void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
+    void printElement(int indent);
+    // get the SimpleType definition by name, if any. NULL if not found.
+    SimpleType *getSimpleType(const char *name);
+    // get the ScalarVariable by name, if any. NULL if not found.
+    ScalarVariable *getVariable(const char *name);
+    // get the ScalarVariable by vr and type. NULL if not found.
+    ScalarVariable *getVariable(fmi2ValueReference vr, XmlParser::Elm type);
+    // get description from variable, if not present look for type definition description.
+    const char *getDescriptionForVariable(ScalarVariable *sv);
+    // get attribute from type, if not present look for it inside declared type.
+    // Attributes example: 'min', 'max', 'quantity'.
+    const char *getAttributeFromTypeOrDeclaredType(ScalarVariable *sv, XmlParser::Att a);
+};
+
+#endif  // XML_ELEMENT_H

+ 314 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlParser.cpp

@@ -0,0 +1,314 @@
+/*
+ * Copyright QTronic GmbH. All rights reserved.
+ */
+
+/* ---------------------------------------------------------------------------*
+ * XmlParser.cpp
+ * Parser implementation for xml model description file of a FMI 2.0 model.
+ * The result of parsing is a ModelDescription object that can be queried to
+ * get necessary information. The parsing is based on libxml2.lib.
+ *
+ * Author: Adrian Tirea
+ * ---------------------------------------------------------------------------*/
+
+#include "XmlParser.h"
+#include <utility>
+#include <vector>
+#include "XmlElement.h"
+#include "XmlParserException.h"
+
+
+#ifdef STANDALONE_XML_PARSER
+#define logThis(n, ...) printf(__VA_ARGS__); printf("\n")
+#define checkStrdup(str) strdup(str)
+#else
+#include "GlobalIncludes.h"
+#include "logging.h"  // logThis
+#include "minutil.h"  // checkStrdup
+#endif  // STANDALONE_XML_PARSER
+
+/* Helper functions to check validity of xml. */
+static int checkAttribute(const char* att);
+
+const char *XmlParser::elmNames[SIZEOF_ELM] = {
+    "fmiModelDescription", "ModelExchange", "CoSimulation", "SourceFiles", "File",
+    "UnitDefinitions", "Unit", "BaseUnit", "DisplayUnit", "TypeDefinitions",
+    "SimpleType", "Real", "Integer", "Boolean", "String",
+    "Enumeration", "Item", "LogCategories", "Category", "DefaultExperiment",
+    "VendorAnnotations", "Tool", "ModelVariables", "ScalarVariable", "Annotations",
+    "ModelStructure", "Outputs", "Derivatives", "DiscreteStates", "InitialUnknowns",
+    "Unknown"
+};
+
+const char *XmlParser::attNames[SIZEOF_ATT] = {
+    "fmiVersion", "modelName", "guid", "description", "author",
+    "version", "copyright", "license", "generationTool", "generationDateAndTime",
+    "variableNamingConvention", "numberOfEventIndicators", "name", "kg", "m",
+    "s", "A", "K", "mol", "cd",
+    "rad", "factor", "offset", "quantity", "unit",
+    "displayUnit", "relativeQuantity", "min", "max", "nominal",
+    "unbounded", "value", "startTime", "stopTime", "tolerance",
+    "stepSize", "valueReference", "causality", "variability", "initial",
+    "previous", "canHandleMultipleSetPerTimeInstant", "declaredType", "start", "derivative",
+    "reinit", "index", "dependencies", "dependenciesKind", "modelIdentifier",
+    "needsExecutionTool", "completedIntegratorStepNotNeeded", "canBeInstantiatedOnlyOncePerProcess",
+        "canNotUseMemoryManagementFunctions", "canGetAndSetFMUstate",
+    "canSerializeFMUstate", "providesDirectionalDerivative", "canHandleVariableCommunicationStepSize",
+        "canInterpolateInputs", "maxOutputDerivativeOrder",
+    "canRunAsynchronuously",
+
+    // not conform with the FMI 2.0 doc.  // TODO : remove when used models become mature.
+    "xmlns:xsi",                       // Dymola examples from 2014 FD01
+    "providesDirectionalDerivatives",  // Dymola examples from 2014 FD01
+    "canHandleEvents"                  // Dymola examples from 2014 FD01
+};
+
+const char *XmlParser::enuNames[SIZEOF_ENU] = {
+    "flat", "structured", "dependent", "constant", "fixed",
+    "tunable", "discrete", "parameter", "calculatedParameter", "input",
+    "output", "local", "independent", "continuous", "exact",
+    "approx", "calculated"
+};
+
+XmlParser::XmlParser(char *xmlPath) {
+    this->xmlPath = (char *)checkStrdup(xmlPath);
+    xmlReader = NULL;
+}
+
+XmlParser::~XmlParser() {
+    free(xmlPath);
+    xmlCleanupParser();
+}
+
+ModelDescription *XmlParser::parse() {
+    xmlReader = xmlReaderForFile(xmlPath, NULL, 0);
+    ModelDescription *md = NULL;
+    if (xmlReader != NULL) {
+        try {
+            if (readNextInXml()) {
+                // I expect that first element is fmiModelDescription.
+                if (0 != strcmp((char *)xmlTextReaderConstLocalName(xmlReader), elmNames[elm_fmiModelDescription])) {
+                    throw XmlParserException("Expected '%s' element. Found instead: '%s'.",
+                        elmNames[elm_fmiModelDescription],
+                        xmlTextReaderConstLocalName(xmlReader));
+                }
+
+                md = new ModelDescription;
+                md->type = elm_fmiModelDescription;
+                parseElementAttributes((Element *)md);
+                parseChildElements(md);
+            } else {
+                throw XmlParserException("Syntax error parsing xml file '%s'", xmlPath);
+            }
+        } catch (XmlParserException& e) {
+            logThis(ERROR_ERROR, e.what());
+            md = NULL;
+        } catch (std::bad_alloc& ) {
+            logThis(ERROR_FATAL, "Out of memory");
+            md = NULL;
+        }
+        xmlFreeTextReader(xmlReader);
+    } else {
+        logThis(ERROR_ERROR, "Unable to open '%s'", xmlPath);
+    }
+
+    return validate(md);
+}
+
+void XmlParser::parseElementAttributes(Element *element, bool ignoreUnknownAttributes) {
+    while (xmlTextReaderMoveToNextAttribute(xmlReader)) {
+        xmlChar *name = xmlTextReaderName(xmlReader);
+        xmlChar *value = xmlTextReaderValue(xmlReader);
+        try {
+            XmlParser::Att key = checkAttribute((char *)name);
+            char *theValue = value ? (char *)checkStrdup((char *)value) : NULL;
+            element->attributes.insert(std::pair<XmlParser::Att, char *>(key, theValue));
+        } catch (XmlParserException &ex) {
+            if (ignoreUnknownAttributes) {
+                xmlFree(name);
+                xmlFree(value);
+                throw;
+            }
+        }
+        xmlFree(name);
+        xmlFree(value);
+    }
+}
+
+void XmlParser::parseElementAttributes(Element *element) {
+    parseElementAttributes(element, true);
+}
+
+void XmlParser::parseChildElements(Element *el) {
+    int elementIsEmpty = xmlTextReaderIsEmptyElement(xmlReader);
+    if (elementIsEmpty == -1) {
+        throw XmlParserException("Error parsing xml file '%s'", xmlPath);
+    } else if (elementIsEmpty == 1) {
+        return;
+    }
+
+    bool ret = readNextInXml();
+    while (ret  && xmlTextReaderNodeType(xmlReader) != XML_READER_TYPE_END_ELEMENT) {
+        if (xmlTextReaderNodeType(xmlReader) == XML_READER_TYPE_ELEMENT) {
+            const char *localName = (char *)xmlTextReaderConstLocalName(xmlReader);
+            int depthBefore = xmlTextReaderDepth(xmlReader);
+            int isEmptyElement = xmlTextReaderIsEmptyElement(xmlReader);
+            el->handleElement(this, localName, isEmptyElement);
+            if (!isEmptyElement) {
+                int depthAfter = xmlTextReaderDepth(xmlReader);
+                if (depthBefore != depthAfter) {
+                    throw XmlParserException("Parser error. Depth wrong after parsing sub-tree for %s.", localName);
+                }
+            }
+        }
+        ret = readNextInXml();
+    }
+    if (!ret) {
+        throw XmlParserException("Error parsing xml file '%s'", xmlPath);
+    }
+}
+
+void XmlParser::parseEndElement() {
+    bool ret = readNextInXml();
+    while (ret  && xmlTextReaderNodeType(xmlReader) != XML_READER_TYPE_END_ELEMENT) {
+        ret = readNextInXml();
+    }
+    if (!ret) {
+        throw XmlParserException("Error parsing xml file '%s'", xmlPath);
+    }
+}
+
+void XmlParser::parseSkipChildElement() {
+    int ret = xmlTextReaderNext(xmlReader);
+    if (ret == -1) {
+        throw XmlParserException("Error parsing xml file '%s'", xmlPath);
+    }
+}
+
+bool XmlParser::readNextInXml() {
+    int ret;
+    do {
+        ret = xmlTextReaderRead(xmlReader);
+    } while (ret == 1 && xmlTextReaderNodeType(xmlReader) == XML_READER_TYPE_COMMENT);
+
+    if (ret != 1) {
+        return false;
+    }
+    return true;
+}
+
+/* -------------------------------------------------------------------------* 
+ * Helper functions to check validity of xml.
+ * -------------------------------------------------------------------------*/
+
+// Returns the index of name in the array.
+// Throw exception if name not found (invalid).
+static int checkName(const char *name, const char *kind, const char *array[], int n) {
+    for (int i = 0; i < n; i++) {
+        if (!strcmp(name, array[i])) {
+            return i;
+        }
+    }
+    throw XmlParserException("Illegal %s %s", kind, name);
+}
+
+XmlParser::Att XmlParser::checkAttribute(const char *att) {
+    return (XmlParser::Att)checkName(att, "attribute", XmlParser::attNames, XmlParser::SIZEOF_ATT);
+}
+
+XmlParser::Elm XmlParser::checkElement(const char *elm) {
+    return (XmlParser::Elm)checkName(elm, "element", XmlParser::elmNames, XmlParser::SIZEOF_ELM);
+}
+
+XmlParser::Enu XmlParser::checkEnumValue(const char *enu) {
+    return (XmlParser::Enu)checkName(enu, "enum value", XmlParser::enuNames, XmlParser::SIZEOF_ENU);
+}
+
+ModelDescription *XmlParser::validate(ModelDescription *md) {
+    if (md == NULL) return NULL;
+    int errors = 0;
+    // check modelDescription required attributes
+    if (!(md->getAttributeValue(XmlParser::att_fmiVersion)
+        && md->getAttributeValue(XmlParser::att_modelName)
+        && md->getAttributeValue(XmlParser::att_guid))) {
+            logThis(ERROR_ERROR, "Model description miss required attributes in file %s", xmlPath);
+            return NULL;
+    }
+
+    if (!(md->coSimulation || md->modelExchange)) {
+        logThis(ERROR_ERROR, "Model description must have a co-simulation or model exchange component in file %s",
+            xmlPath);
+            return NULL;
+    }
+
+    // check model variables
+    for (std::vector<ScalarVariable *>::const_iterator it = md->modelVariables.begin(); it != md->modelVariables.end();
+            ++it) {
+        const char *varName = (*it)->getAttributeValue(XmlParser::att_name);
+        if (!varName) {
+            logThis(ERROR_ERROR, "Scalar variable miss required %s attribute in modelDescription.xml",
+                XmlParser::attNames[XmlParser::att_name]);
+            errors++;
+            continue;
+        }
+        XmlParser::ValueStatus vs;
+        (*it)->getAttributeUInt(XmlParser::att_valueReference, &vs);
+        if (vs == XmlParser::valueMissing) {
+            logThis(ERROR_ERROR, "Scalar variable %s miss required %s attribute in modelDescription.xml",
+                varName, XmlParser::attNames[XmlParser::att_valueReference]);
+            errors++;
+            continue;
+        }
+        if (vs == XmlParser::valueIllegal) {
+            logThis(ERROR_ERROR, "Scalar variable %s has illegal format for %s attribute in modelDescription.xml",
+                varName, XmlParser::attNames[XmlParser::att_valueReference]);
+            errors++;
+            continue;
+        }
+
+        if (!(*it)->typeSpec) {
+            logThis(ERROR_ERROR, "Scalar variable %s miss type specification in modelDescription.xml",
+                varName);
+            errors++;
+            continue;
+        }
+        if ((*it)->typeSpec->type == XmlParser::elm_Enumeration) {
+            const char *typeName = (*it)->typeSpec->getAttributeValue(XmlParser::att_declaredType);
+            if (!typeName) {
+                logThis(ERROR_ERROR, "Scalar variable %s with enum type specification miss required %s attribute in "
+                        "modelDescription.xml", varName, XmlParser::attNames[XmlParser::att_declaredType]);
+                errors++;
+                continue;
+            }
+            if (!md->getSimpleType(typeName)) {
+                logThis(ERROR_ERROR, "Declared type %s of variable %s not found in modelDescription.xml",
+                     typeName, varName);
+                errors++;
+                continue;
+            }
+        }
+    }
+
+    if (errors > 0) {
+        logThis(ERROR_ERROR, "Found %d error in file %s", errors, xmlPath);
+        return NULL;
+    }
+    return md;
+}
+
+// #define TEST
+#ifdef TEST
+int main() {
+    // { char c='c'; while(c!='g') scanf("%c", &c); } // to debug: wait for the g key
+
+    XmlParser *parser =
+        new XmlParser("c:\\_data\\fmi-fmu\\fmi-fmuVS\\fmi-fmuVS\\modelDescriptionDymola - ManuallyModifiedCopy.xml");
+    ModelDescription *md = parser->parse();
+    if (md) md->printElement(0);
+    delete parser;
+    if (md) delete md;
+
+    dumpMemoryLeaks();
+    return 0;
+}
+#endif  // TEST

+ 126 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlParser.h

@@ -0,0 +1,126 @@
+/*
+ * Copyright QTronic GmbH. All rights reserved.
+ */
+
+/* ---------------------------------------------------------------------------*
+ * XmlParser.h
+ * Parser for xml model description file of a FMI 2.0 model.
+ * The result of parsing is a ModelDescription object that can be queried to
+ * get necessary information. The parsing is based on libxml2.lib.
+ *
+ * Author: Adrian Tirea
+ * ---------------------------------------------------------------------------*/
+
+#ifndef XML_PARSER_H
+#define XML_PARSER_H
+
+#include <libxml/xmlreader.h>
+
+#pragma comment(lib, "libxml2.lib")
+#pragma comment(lib, "wsock32.lib")
+
+#ifndef fmi2TypesPlatform_h
+// same as in FMI 2.0 specification
+typedef unsigned int fmi2ValueReference;
+#endif
+
+class Element;
+class ModelDescription;
+
+class XmlParser {
+ public:
+    // Elements
+    static const int SIZEOF_ELM = 31;
+    static const char *elmNames[SIZEOF_ELM];
+    enum Elm {
+        elm_BAD_DEFINED = -1,
+        elm_fmiModelDescription, elm_ModelExchange, elm_CoSimulation, elm_SourceFiles, elm_File,
+        elm_UnitDefinitions, elm_Unit, elm_BaseUnit, elm_DisplayUnit, elm_TypeDefinitions,
+        elm_SimpleType, elm_Real, elm_Integer, elm_Boolean, elm_String,
+        elm_Enumeration, elm_Item, elm_LogCategories, elm_Category, elm_DefaultExperiment,
+        elm_VendorAnnotations, elm_Tool, elm_ModelVariables, elm_ScalarVariable, elm_Annotations,
+        elm_ModelStructure, elm_Outputs, elm_Derivatives, elm_DiscreteStates, elm_InitialUnknowns,
+        elm_Unknown
+    };
+
+    // Attributes
+    static const int SIZEOF_ATT = 64;  // 61;
+    static const char *attNames[SIZEOF_ATT];
+    enum Att {
+        att_BAD_DEFINED = -1,
+        att_fmiVersion, att_modelName, att_guid, att_description, att_author,
+        att_version, att_copyright, att_license, att_generationTool, att_generationDateAndTime,
+        att_variableNamingConvention, att_numberOfEventIndicators, att_name, att_kg, att_m,
+        att_s, att_A, att_K, att_mol, att_cd,
+        att_rad, att_factor, att_offset, att_quantity, att_unit,
+        att_displayUnit, att_relativeQuantity, att_min, att_max, att_nominal,
+        att_unbounded, att_value, att_startTime, att_stopTime, att_tolerance,
+        att_stepSize, att_valueReference, att_causality, att_variability, att_initial,
+        att_previous, att_canHandleMultipleSetPerTimeInstant, att_declaredType, att_start, att_derivative,
+        att_reinit, att_index, att_dependencies, att_dependenciesKind, att_modelIdentifier,
+        att_needsExecutionTool, att_completedIntegratorStepNotNeeded, att_canBeInstantiatedOnlyOncePerProcess,
+            att_canNotUseMemoryManagementFunctions, att_canGetAndSetFMUstate,
+        att_canSerializeFMUstate, att_providesDirectionalDerivative, att_canHandleVariableCommunicationStepSize,
+            att_canInterpolateInputs, att_maxOutputDerivativeOrder,
+        att_canRunAsynchronuously,
+
+        att_xmlnsXsi, att_providesDirectionalDerivatives, att_canHandleEvents
+    };
+
+    // Enumeration values
+    static const int SIZEOF_ENU = 17;
+    static const char *enuNames[SIZEOF_ENU];
+    enum Enu {
+        enu_BAD_DEFINED = -1,
+        enu_flat, enu_structured, enu_dependent, enu_constant, enu_fixed,
+        enu_tunable, enu_discrete, enu_parameter, enu_calculatedParameter, enu_input,
+        enu_output, enu_local, enu_independent, enu_continuous, enu_exact,
+        enu_approx, enu_calculated
+    };
+
+    // Possible results when retrieving an attribute value from an element
+    enum ValueStatus {
+        valueMissing,
+        valueDefined,
+        valueIllegal
+    };
+
+ private:
+    char *xmlPath;
+    xmlTextReaderPtr xmlReader;
+
+ public:
+    // return the type of this element. Int value match the index in elmNames.
+    // throw XmlParserException if element is invalid.
+    static XmlParser::Elm checkElement(const char* elm);
+    // return the type of this attribute. Int value match the index in attNames.
+    // throw XmlParserException if attribute is invalid.
+    static XmlParser::Att checkAttribute(const char* att);
+    // return the type of this enum value. Int value match the index in enuNames.
+    // throw XmlParserException if enu is invalid.
+    static XmlParser::Enu checkEnumValue(const char* enu);
+
+    // Obs. the destructor calls xmlCleanupParser(). This is a single call for all parsers instantiated.
+    // Be carefully how you link XmlParser (i.e. multithreading, more parsers started at once).
+    explicit XmlParser(char *xmlPath);
+    ~XmlParser();
+    // return NULL on errors. Caller must free the result if not NULL.
+    ModelDescription *parse();
+
+    // throw XmlParserException if attribute invalid.
+    void parseElementAttributes(Element *element);
+    void parseElementAttributes(Element *element, bool ignoreUnknownAttributes);
+    void parseChildElements(Element *el);
+    void parseEndElement();
+    void parseSkipChildElement();
+
+ private:
+    // advance reading in xml and skip comments if present.
+    bool readNextInXml();
+
+    // check some properties of model description (i.e. each variable has valueReference, ...)
+    // if valid return the input model description, else return NULL.
+    ModelDescription *validate(ModelDescription *md);
+};
+
+#endif  // XML_PARSER_H

+ 242 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlParserCApi.cpp

@@ -0,0 +1,242 @@
+/* ---------------------------------------------------------------------------*
+ * XmlParserCApi.cpp
+ * Expose functionality of XmlParser.cpp as a c API.
+ * Call functions of this file to parse and get information from xml
+ * model description file of a FMI 2.0 model.
+ *
+ * Author: Adrian Tirea
+ * Copyright QTronic GmbH. All rights reserved.
+ * ---------------------------------------------------------------------------*/
+
+#include "XmlParserCApi.h"
+#include "XmlParser.h"
+#include "XmlElement.h"
+
+#ifdef STANDALONE_XML_PARSER
+#define logThis(n, ...) printf(__VA_ARGS__); printf("\n")
+#define checkStrdup(str) strdup(str)
+#else
+#include "logging.h"  // logThis
+#endif  // STANDALONE_XML_PARSER
+
+ModelDescription* parse(char* xmlPath) {
+    XmlParser parser(xmlPath);
+    return parser.parse();
+}
+void freeModelDescription(ModelDescription *md) {
+    if (md) delete md;
+}
+
+/* ModelDescription fields access*/
+int getUnitDefinitionsSize(ModelDescription *md) {
+    return md->unitDefinitions.size();
+}
+
+Unit *getUnitDefinition(ModelDescription *md, int index) {
+    return md->unitDefinitions.at(index);
+}
+
+int getTypeDefinitionsSize(ModelDescription *md) {
+    return md->typeDefinitions.size();
+}
+
+SimpleType *getTypeDefinition(ModelDescription *md, int index) {
+    return md->typeDefinitions.at(index);
+}
+
+Component *getModelExchange(ModelDescription *md) {
+    return md->modelExchange;
+}
+
+Component *getCoSimulation(ModelDescription *md) {
+    return md->coSimulation;
+}
+
+int getLogCategoriesSize(ModelDescription *md) {
+    return md->logCategories.size();
+}
+
+Element *getLogCategory(ModelDescription *md, int index) {
+    return md->logCategories.at(index);
+}
+
+Element *getDefaultExperiment(ModelDescription *md) {
+    return md->defaultExperiment;
+}
+
+int getVendorAnnotationsSize(ModelDescription *md) {
+    return md->vendorAnnotations.size();
+}
+
+Element *getVendorAnnotation(ModelDescription *md, int index) {
+    return md->vendorAnnotations.at(index);
+}
+
+int getScalarVariableSize(ModelDescription *md) {
+    return md->modelVariables.size();
+}
+
+ScalarVariable *getScalarVariable(ModelDescription *md, int index) {
+    return md->modelVariables.at(index);
+}
+
+ModelStructure  *getModelStructure (ModelDescription *md) {
+    return md->modelStructure;
+}
+
+SimpleType *getSimpleType(ModelDescription *md, const char *name) {
+    return md->getSimpleType(name);
+}
+
+ScalarVariable *getVariable(ModelDescription *md, const char *name) {
+    return md->getVariable(name);
+}
+
+const char *getDescriptionForVariable(ModelDescription *md, ScalarVariable *sv) {
+    return md->getDescriptionForVariable(sv);
+}
+
+/* ModelStructure fields access */
+int getOutputs(ModelStructure *ms) {
+    return ms->outputs.size();
+}
+
+Element *getOutput(ModelStructure *ms, int index) {
+    return ms->outputs.at(index);
+}
+
+int getDerivativesSize(ModelStructure *ms) {
+    return ms->derivatives.size();
+}
+
+Element *getDerivative(ModelStructure *ms, int index) {
+    return ms->derivatives.at(index);
+}
+
+int getDiscreteStates(ModelStructure *ms) {
+    return ms->discreteStates.size();
+}
+
+Element *getDiscreteState(ModelStructure *ms, int index) {
+    return ms->discreteStates.at(index);
+}
+
+int getInitialUnknowns(ModelStructure *ms) {
+    return ms->initialUnknowns.size();
+}
+
+Element *getInitialUnknown(ModelStructure *ms, int index) {
+    return ms->initialUnknowns.at(index);
+}
+
+/* ScalarVariable field access */
+Element *getTypeSpec(ScalarVariable *sv) {
+    return sv->typeSpec;
+}
+
+int getAnnotationsSize(ScalarVariable *sv) {
+    return sv->annotations.size();
+}
+
+Element *getAnnotation(ScalarVariable *sv, int index) {
+    return sv->annotations.at(index);
+}
+
+fmi2ValueReference getValueReference(ScalarVariable *sv) {
+    return sv->getValueReference();
+}
+// returns one of constant, fixed, tunable, discrete, continuous.
+// If value is missing, the default continuous is returned.
+// If unknown value, return enu_BAD_DEFINED.
+Enu getVariability(ScalarVariable *sv) {
+    return (Enu)sv->getVariability();
+}
+// returns one of parameter, calculatedParameter, input, output, local, independent.
+// If value is missing, the default local is returned.
+// If unknown value, return enu_BAD_DEFINED.
+Enu getCausality(ScalarVariable *sv) {
+    return (Enu)sv->getCausality();
+}
+
+/* Component field access */
+int getFilesSize(Component *c) {
+    return c->files.size();
+}
+
+Element *getFile(Component *c, int index) {
+    return c->files.at(index);
+}
+
+/* SimpleType field access */
+Element *getTypeSpecDef(SimpleType *st) {
+    return st->typeSpec;
+}
+
+/* Unit field access */
+Element *getBaseUnit(Unit *u) {
+    return u->baseUnit;
+}
+
+int getDisplayUnitsSize(Unit *u) {
+    return u->displayUnits.size();
+}
+
+Element *getDisplayUnit(Unit *u, int index) {
+    return u->displayUnits.at(index);
+}
+
+/* ListElement field access */
+int getListSize(ListElement *le) {
+    return le->list.size();
+}
+
+Element *getElementFromList(ListElement *le, int index) {
+    return le->list.at(index);
+}
+
+/* Element functions */
+Elm getElementType(Element *el) {
+    return (Elm)el->type;
+}
+
+const char *getElementTypeName(Element *el) {
+    return XmlParser::elmNames[el->type];
+}
+
+const char **getAttributesAsArray(Element *el, int *n) {
+    *n = el->attributes.size();
+    const char **result = (const char **)calloc(2 * (*n), sizeof(char *));
+    if (!result) {
+        logThis(ERROR_FATAL, "Out of memory");
+        n = 0;
+        return NULL;
+    }
+    int i = 0;
+    for (std::map<XmlParser::Att, char *>::iterator it = el->attributes.begin(); it != el->attributes.end(); ++it ) {
+        result[i] = (const char*)XmlParser::attNames[it->first];
+        result[i + 1] = it->second;
+        i = i + 2;
+    }
+    return result;
+}
+
+const char *getAttributeValue(Element *el, Att att) {
+    return el->getAttributeValue((XmlParser::Att)att);
+}
+
+int getAttributeInt(Element *el, Att att, ValueStatus *vs) {
+    return el->getAttributeInt((XmlParser::Att)att, (XmlParser::ValueStatus *)vs);
+}
+
+unsigned int getAttributeUInt(Element *el, Att att, ValueStatus *vs) {
+    return el->getAttributeUInt((XmlParser::Att)att, (XmlParser::ValueStatus *)vs);
+}
+
+double getAttributeDouble(Element *el, Att att, ValueStatus *vs) {
+    return el->getAttributeDouble((XmlParser::Att)att, (XmlParser::ValueStatus *)vs);
+}
+
+int getAttributeBool(Element *el, Att att, ValueStatus *vs) {
+    if (el->getAttributeBool((XmlParser::Att)att, (XmlParser::ValueStatus *)vs)) return 1;
+    return 0;
+}

+ 203 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/shared/parser/XmlParserCApi.h

@@ -0,0 +1,203 @@
+/* ---------------------------------------------------------------------------*
+ * XmlParserCApi.cpp
+ * Expose functionality of XmlParser.cpp as a c API.
+ * Call functions of this file to parse and get information from xml
+ * model description file of a FMI 2.0 model.
+ *
+ * Author: Adrian Tirea
+ * Copyright QTronic GmbH. All rights reserved.
+ * ---------------------------------------------------------------------------*/
+
+#ifndef XML_PARSER_C_API_H
+#define XML_PARSER_C_API_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef fmi2TypesPlatform_h
+// same as in FMI 2.0 specification
+typedef unsigned int fmi2ValueReference;
+#endif
+
+// elements from ModelDescription
+typedef struct ModelDescription ModelDescription;
+typedef struct ModelStructure ModelStructure;
+typedef struct ScalarVariable ScalarVariable;
+typedef struct Component Component;
+typedef struct SimpleType SimpleType;
+typedef struct Unit Unit;
+typedef struct ListElement ListElement;
+typedef struct Element Element;
+
+// Elements names used in ModelDescription.xml
+typedef enum {
+    elm_BAD_DEFINED = -1,
+    elm_fmiModelDescription, elm_ModelExchange, elm_CoSimulation, elm_SourceFiles, elm_File,
+    elm_UnitDefinitions, elm_Unit, elm_BaseUnit, elm_DisplayUnit, elm_TypeDefinitions,
+    elm_SimpleType, elm_Real, elm_Integer, elm_Boolean, elm_String,
+    elm_Enumeration, elm_Item, elm_LogCategories, elm_Category, elm_DefaultExperiment,
+    elm_VendorAnnotations, elm_Tool, elm_ModelVariables, elm_ScalarVariable, elm_Annotations,
+    elm_ModelStructure, elm_Outputs, elm_Derivatives, elm_DiscreteStates, elm_InitialUnknowns,
+    elm_Unknown
+} Elm;
+
+// Attributes names used in ModelDescription.xml
+typedef enum {
+    att_BAD_DEFINED = -1,
+    att_fmiVersion, att_modelName, att_guid, att_description, att_author,
+    att_version, att_copyright, att_license, att_generationTool, att_generationDateAndTime,
+    att_variableNamingConvention, att_numberOfEventIndicators, att_name, att_kg, att_m,
+    att_s, att_A, att_K, att_mol, att_cd,
+    att_rad, att_factor, att_offset, att_quantity, att_unit,
+    att_displayUnit, att_relativeQuantity, att_min, att_max, att_nominal,
+    att_unbounded, att_value, att_startTime, att_stopTime, att_tolerance,
+    att_stepSize, att_valueReference, att_causality, att_variability, att_initial,
+    att_previous, att_canHandleMultipleSetPerTimeInstant, att_declaredType, att_start, att_derivative,
+    att_reinit, att_index, att_dependencies, att_dependenciesKind, att_modelIdentifier,
+    att_needsExecutionTool, att_completedIntegratorStepNotNeeded, att_canBeInstantiatedOnlyOncePerProcess, att_canNotUseMemoryManagementFunctions, att_canGetAndSetFMUstate,
+    att_canSerializeFMUstate, att_providesDirectionalDerivative, att_canHandleVariableCommunicationStepSize, att_canInterpolateInputs, att_maxOutputDerivativeOrder,
+    att_canRunAsynchronuously
+} Att;
+
+// Enumerated values names used in ModelDescription.xml
+typedef enum {
+    enu_BAD_DEFINED = -1,
+    enu_flat, enu_structured, enu_dependent, enu_constant, enu_fixed,
+    enu_tunable, enu_discrete, enu_parameter, enu_calculatedParameter, enu_input,
+    enu_output, enu_local, enu_independent, enu_continuous, enu_exact,
+    enu_approx, enu_calculated
+} Enu;
+
+typedef enum {
+    valueMissing,
+    valueDefined,
+    valueIllegal
+} ValueStatus;
+
+// Returns NULL to indicate failure
+// Otherwise, return the root node md of the AST. From the result of this
+// function user can access all other elements from ModelDescription.xml.
+// The receiver must call freeModelDescription(md) to release AST memory.
+ModelDescription* parse(char* xmlPath);
+void freeModelDescription(ModelDescription *md);
+
+
+/* ModelDescription functions */
+// get number of unit definitions
+int getUnitDefinitionsSize(ModelDescription *md);
+// get unit definition at index
+Unit *getUnitDefinition(ModelDescription *md, int index);
+// get number of type definitions
+int getTypeDefinitionsSize(ModelDescription *md);
+// get type definition at index
+SimpleType *getTypeDefinition(ModelDescription *md, int index);
+// Null or component for ModelExchange
+Component *getModelExchange(ModelDescription *md);
+// Null or component for CoSimulation
+Component *getCoSimulation(ModelDescription *md);
+// get number of log categories
+int getLogCategoriesSize(ModelDescription *md);
+// get log category at index
+Element *getLogCategory(ModelDescription *md, int index);
+// Null or DefaultExperiment
+Element *getDefaultExperiment(ModelDescription *md);
+// get number of vendor annotations
+int getVendorAnnotationsSize(ModelDescription *md);
+// get vendor annotation at index
+Element *getVendorAnnotation(ModelDescription *md, int index);
+// get number of scalar variables
+int getScalarVariableSize(ModelDescription *md);
+// get scalar variable at index
+ScalarVariable *getScalarVariable(ModelDescription *md, int index);
+// Null or ModelStructure
+ModelStructure  *getModelStructure (ModelDescription *md);
+
+// get the SimpleType definition by name, if any. NULL if not found.
+SimpleType *getSimpleType(ModelDescription *md, const char *name);
+// get the ScalarVariable by name, if any. NULL if not found.
+ScalarVariable *getVariable(ModelDescription *md, const char *name);
+// get description from variable, if not present look for type definition description.
+const char *getDescriptionForVariable(ModelDescription *md, ScalarVariable *sv);
+
+/* ModelStructure functions */
+// get number of outputs
+int getOutputsSize(ModelStructure *ms);
+// get output at index
+Element *getOutput(ModelStructure *ms, int index);
+// get number of derivatives
+int getDerivativesSize(ModelStructure *ms);
+// get derivative at index
+Element *getDerivative(ModelStructure *ms, int index);
+// get number of discrete states
+int getDiscreteStatesSize(ModelStructure *ms);
+// get discrete state at index
+Element *getDiscreteState(ModelStructure *ms, int index);
+// get number of initial unknowns
+int getInitialUnknownsSize(ModelStructure *ms);
+// get initial unknown at index
+Element *getInitialUnknown(ModelStructure *ms, int index);
+
+/* ScalarVariable functions */
+// one of Real, Integer, etc.
+Element *getTypeSpec(ScalarVariable *sv);
+// get number of annotations
+int getAnnotationsSize(ScalarVariable *sv);
+// get annotation at index
+Element *getAnnotation(ScalarVariable *sv, int index);
+
+// get the valueReference of current variable. This attribute is mandatory for a variable.
+fmi2ValueReference getValueReference(ScalarVariable *sv);
+// returns one of constant, fixed, tunable, discrete, continuous.
+// If value is missing, the default continuous is returned.
+// If unknown value, return enu_BAD_DEFINED.
+Enu getVariability(ScalarVariable *sv);
+// returns one of parameter, calculatedParameter, input, output, local, independent.
+// If value is missing, the default local is returned.
+// If unknown value, return enu_BAD_DEFINED.
+Enu getCausality(ScalarVariable *sv);
+
+/* Component functions */
+// get number of files
+int getFilesSize(Component *c);
+// get file at index
+Element *getFile(Component *c, int index);
+
+/* SimpleType functions */
+// one of RealType, IntegerType etc.