Browse Source

case study

Joachim Denil 7 years ago
parent
commit
0676e1d2ab
100 changed files with 14184 additions and 229 deletions
  1. 113 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/.cproject
  2. 1 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/.gitignore
  3. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/Obstacle.zip
  4. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/PW_PowerSystem.fmu
  5. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/Window.zip
  6. 72 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/fmi2/fmi2.h
  7. 247 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/fmi2/fmi2FunctionTypes.h
  8. 339 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/fmi2/fmi2Functions.h
  9. 115 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/fmi2/fmi2TypesPlatform.h
  10. 1001 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/result_Control_sa.csv
  11. 1001 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/result_ENV.csv
  12. 1001 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/result_power_sa.csv
  13. 228 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/src/pw_case.c
  14. 594 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/src/sim_support.c
  15. 44 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/case/src/sim_support.h
  16. 124 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/.cproject
  17. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/Debug/FMI_Environment.o
  18. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/Debug/libFMI_Environment.dll
  19. 536 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/FMI_Environment.c
  20. 51 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/FMI_Environment.h
  21. 247 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/fmi2/fmi2FunctionTypes.h
  22. 339 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/fmi2/fmi2Functions.h
  23. 115 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/fmi2/fmi2TypesPlatform.h
  24. 124 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_SEL/.cproject
  25. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_SEL/Debug/FMI_SEL.o
  26. 124 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_TD/.cproject
  27. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_TD/Debug/FMI_SEL.o
  28. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_TD/Debug/FMI_TD.o
  29. 134 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/.cproject
  30. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/FMI_CM.o
  31. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/FMI_GM.o
  32. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/FMI_SEL.o
  33. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/FMI_Window_sa.o
  34. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/FMI_power_sa.o
  35. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/libFMI_Window_sa.dll
  36. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/sim_support.o
  37. 398 221
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/FMI_Window_sa.c
  38. 17 6
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/FMI_Window_sa.h
  39. 3 2
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/sim_support.c
  40. 125 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_control_master/.cproject
  41. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_control_master/Debug/FMI_CM.o
  42. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_control_master/Debug/FMI_SEL.o
  43. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_control_master/Debug/sim_support.o
  44. 134 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/.cproject
  45. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/Debug/FMI_CM.o
  46. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/Debug/FMI_GM.o
  47. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/Debug/FMI_SEL.o
  48. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/Debug/libFMI_controller_sa.dll
  49. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/Debug/sim_support.o
  50. 719 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/FMI_GM.c
  51. 69 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/FMI_GM.h
  52. 72 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/fmi2/fmi2.h
  53. 247 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/fmi2/fmi2FunctionTypes.h
  54. 339 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/fmi2/fmi2Functions.h
  55. 115 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/fmi2/fmi2TypesPlatform.h
  56. 594 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/sim_support.c
  57. 44 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/sim_support.h
  58. 125 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/.cproject
  59. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/FMI_CM.o
  60. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/FMI_GM.o
  61. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/FMI_SEL.o
  62. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/libFMI_SEL.dll
  63. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/libFMI_control_master.dll
  64. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/sim_support.o
  65. 134 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/.cproject
  66. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/Debug/FMI_CM.o
  67. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/Debug/FMI_GM.o
  68. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/Debug/FMI_SEL.o
  69. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/Debug/FMI_power_sa.o
  70. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/Debug/sim_support.o
  71. 637 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/FMI_loop_sa.c
  72. 58 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/FMI_loop_sa.h
  73. 72 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/fmi2/fmi2.h
  74. 247 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/fmi2/fmi2FunctionTypes.h
  75. 339 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/fmi2/fmi2Functions.h
  76. 115 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/fmi2/fmi2TypesPlatform.h
  77. 594 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/sim_support.c
  78. 44 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/sim_support.h
  79. 134 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/.cproject
  80. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/FMI_CM.o
  81. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/FMI_GM.o
  82. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/FMI_SEL.o
  83. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/FMI_power_sa.o
  84. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/libFMI_power_sa.dll
  85. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/sim_support.o
  86. 652 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/FMI_power_sa.c
  87. 62 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/FMI_power_sa.h
  88. 72 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/fmi2/fmi2.h
  89. 247 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/fmi2/fmi2FunctionTypes.h
  90. 339 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/fmi2/fmi2Functions.h
  91. 115 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/fmi2/fmi2TypesPlatform.h
  92. 594 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/sim_support.c
  93. 44 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/sim_support.h
  94. 134 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/.cproject
  95. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/FMI_CM.o
  96. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/FMI_GM.o
  97. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/FMI_SEL.o
  98. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/FMI_power_sa.o
  99. BIN
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/libFMI_power_sa.dll
  100. 0 0
      SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/sim_support.o

+ 113 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/.cproject

@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+	<storageModule moduleId="org.eclipse.cdt.core.settings">
+		<cconfiguration id="cdt.managedbuild.config.gnu.mingw.exe.debug.1589967115">
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.mingw.exe.debug.1589967115" moduleId="org.eclipse.cdt.core.settings" name="Debug">
+				<externalSettings/>
+				<extensions>
+					<extension id="org.eclipse.cdt.core.PE" point="org.eclipse.cdt.core.BinaryParser"/>
+					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+				</extensions>
+			</storageModule>
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+				<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.mingw.exe.debug.1589967115" name="Debug" parent="cdt.managedbuild.config.gnu.mingw.exe.debug">
+					<folderInfo id="cdt.managedbuild.config.gnu.mingw.exe.debug.1589967115." name="/" resourcePath="">
+						<toolChain id="cdt.managedbuild.toolchain.gnu.mingw.exe.debug.2065198422" name="MinGW GCC" superClass="cdt.managedbuild.toolchain.gnu.mingw.exe.debug">
+							<targetPlatform id="cdt.managedbuild.target.gnu.platform.mingw.exe.debug.710302017" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.mingw.exe.debug"/>
+							<builder buildPath="${workspace_loc:/pw_case}/Debug" id="cdt.managedbuild.tool.gnu.builder.mingw.base.692255892" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base"/>
+							<tool id="cdt.managedbuild.tool.gnu.assembler.mingw.exe.debug.1564201794" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.exe.debug">
+								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.822854060" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.491915181" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/>
+							<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.debug.1422720996" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.debug">
+								<option id="gnu.cpp.compiler.mingw.exe.debug.option.optimization.level.255528101" name="Optimization Level" superClass="gnu.cpp.compiler.mingw.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
+								<option id="gnu.cpp.compiler.mingw.exe.debug.option.debugging.level.441545821" name="Debug Level" superClass="gnu.cpp.compiler.mingw.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug.338201069" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug">
+								<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.mingw.exe.debug.option.optimization.level.1911017642" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.debug.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
+								<option id="gnu.c.compiler.mingw.exe.debug.option.debugging.level.652346632" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
+								<option id="gnu.c.compiler.option.include.paths.1252884278" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/fmi2}&quot;"/>
+								</option>
+								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.161528920" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug.793124615" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug">
+								<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.337727223" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
+									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
+									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
+								</inputType>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.debug.1466756633" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.debug"/>
+						</toolChain>
+					</folderInfo>
+					<sourceEntries>
+						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
+					</sourceEntries>
+				</configuration>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+		</cconfiguration>
+		<cconfiguration id="cdt.managedbuild.config.gnu.mingw.exe.release.1502470385">
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.mingw.exe.release.1502470385" moduleId="org.eclipse.cdt.core.settings" name="Release">
+				<externalSettings/>
+				<extensions>
+					<extension id="org.eclipse.cdt.core.PE" point="org.eclipse.cdt.core.BinaryParser"/>
+					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+				</extensions>
+			</storageModule>
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+				<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.mingw.exe.release.1502470385" name="Release" parent="cdt.managedbuild.config.gnu.mingw.exe.release">
+					<folderInfo id="cdt.managedbuild.config.gnu.mingw.exe.release.1502470385." name="/" resourcePath="">
+						<toolChain id="cdt.managedbuild.toolchain.gnu.mingw.exe.release.842114339" name="MinGW GCC" superClass="cdt.managedbuild.toolchain.gnu.mingw.exe.release">
+							<targetPlatform id="cdt.managedbuild.target.gnu.platform.mingw.exe.release.21663748" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.mingw.exe.release"/>
+							<builder buildPath="${workspace_loc:/pw_case}/Release" id="cdt.managedbuild.tool.gnu.builder.mingw.base.93633296" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base"/>
+							<tool id="cdt.managedbuild.tool.gnu.assembler.mingw.exe.release.2081075908" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.exe.release">
+								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.699941151" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.1708225123" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/>
+							<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.release.2070140754" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.release">
+								<option id="gnu.cpp.compiler.mingw.exe.release.option.optimization.level.1917586500" name="Optimization Level" superClass="gnu.cpp.compiler.mingw.exe.release.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
+								<option id="gnu.cpp.compiler.mingw.exe.release.option.debugging.level.1081975185" name="Debug Level" superClass="gnu.cpp.compiler.mingw.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release.1857559091" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release">
+								<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.mingw.exe.release.option.optimization.level.272324535" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.release.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
+								<option id="gnu.c.compiler.mingw.exe.release.option.debugging.level.344004096" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
+								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1530750796" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.release.265163382" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.release">
+								<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1794226632" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
+									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
+									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
+								</inputType>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.release.2002347536" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.release"/>
+						</toolChain>
+					</folderInfo>
+					<sourceEntries>
+						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
+					</sourceEntries>
+				</configuration>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+		</cconfiguration>
+	</storageModule>
+	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+		<project id="pw_case.cdt.managedbuild.target.gnu.mingw.exe.2039998570" name="Executable" projectType="cdt.managedbuild.target.gnu.mingw.exe"/>
+	</storageModule>
+	<storageModule moduleId="scannerConfiguration">
+		<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.mingw.exe.debug.1589967115;cdt.managedbuild.config.gnu.mingw.exe.debug.1589967115.;cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug.338201069;cdt.managedbuild.tool.gnu.c.compiler.input.161528920">
+			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+		</scannerConfigBuildInfo>
+		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.mingw.exe.release.1502470385;cdt.managedbuild.config.gnu.mingw.exe.release.1502470385.;cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release.1857559091;cdt.managedbuild.tool.gnu.c.compiler.input.1530750796">
+			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+		</scannerConfigBuildInfo>
+	</storageModule>
+	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+	<storageModule moduleId="refreshScope"/>
+	<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
+</cproject>

+ 1 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/.gitignore

@@ -0,0 +1 @@
+/Debug/

BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/Obstacle.zip


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


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/Window.zip


+ 72 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/fmi2/fmi2.h

@@ -0,0 +1,72 @@
+/* -------------------------------------------------------------------------
+ * 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 "fmi2Functions.h"
+
+typedef struct {
+//    ModelDescription* modelDescription;
+
+    void  *dllHandle; // fmu.so 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
+

+ 247 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/fmi2/fmi2FunctionTypes.h

@@ -0,0 +1,247 @@
+#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 (C) 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);
+#ifdef FMU_EXPERIMENTAL
+   typedef fmi2Status fmi2GetSpecificDerivativesTYPE       (fmi2Component, fmi2Real[], const fmi2ValueReference [], size_t);
+#endif
+
+   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 */

+ 339 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/fmi2/fmi2Functions.h

@@ -0,0 +1,339 @@
+#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 (C) 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)
+#ifdef FMU_EXPERIMENTAL
+#define fmi2GetSpecificDerivatives        fmi2FullName(fmi2GetSpecificDerivatives)
+#endif
+#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;
+#ifdef FMU_EXPERIMENTAL
+   FMI2_Export fmi2GetSpecificDerivativesTYPE        fmi2GetSpecificDerivatives;
+#endif
+   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/case/fmi2/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 (C) 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 */

File diff suppressed because it is too large
+ 1001 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/result_Control_sa.csv


File diff suppressed because it is too large
+ 1001 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/result_ENV.csv


File diff suppressed because it is too large
+ 1001 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/result_power_sa.csv


+ 228 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/src/pw_case.c

@@ -0,0 +1,228 @@
+/*
+ ============================================================================
+ Name        : pw_case.c
+ Author      : Joachim Denil
+ Version     :
+ Copyright   : Your copyright notice
+ Description : Hello World in C, Ansi-style
+ ============================================================================
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "sim_support.h"
+#include "fmi2.h"
+
+#define START_TIME 0.0
+#define STOP_TIME 10.0
+#define STEP_SIZE 0.01
+
+FMU fmu_env, fmu_control_sa, fmu_power_sa, fmu_window_sa;
+
+int main(void) {
+
+	FILE *fp_fmu_env;
+	fp_fmu_env = fopen("result_ENV.csv", "w");
+	FILE *fp_fmu_control_sa;
+	fp_fmu_control_sa = fopen("result_Control_sa.csv", "w");
+	FILE *fp_fmu_power_sa;
+	fp_fmu_power_sa = fopen("result_power_sa.csv","w");
+
+	puts("Loading Dlls\n"); /* prints Hello World */
+	/* loading */
+    loadDll("libFMI_Environment.dll", &fmu_env, "PW_ENV");
+    loadDll("libFMI_controller_sa.dll", &fmu_control_sa, "PW_CONTROLLER_SA");
+    loadDll("libFMI_power_sa.dll", &fmu_power_sa, "POWER_SA");
+    loadDll("libFMI_Window_sa.dll", &fmu_window_sa, "WINDOW_SA");
+
+    puts("instantiating fmus\n");
+    fmi2Component c_env, c_control_sa, c_power_sa, c_window_sa;
+
+    char *fmuResourceLocation_env = "libFMI_Environment.dll";
+    char *fmuResourceLocation_control_sa = "libFMI_controller_sa.dll";
+    char *fmuResourceLocation_power_sa = "libFMI_power_sa.dll";
+    char *fmuResourceLocation_window_sa = "libFMI_Wower_sa.dll";
+
+    fmi2CallbackFunctions callbacks_env= {fmuLogger, calloc, free, NULL, &fmu_env};
+    fmi2CallbackFunctions callbacks_control_sa = {fmuLogger, calloc, free, NULL, &fmu_control_sa};
+    fmi2CallbackFunctions callbacks_power_sa = {fmuLogger, calloc, free, NULL, &fmu_power_sa};
+    fmi2CallbackFunctions callbacks_window_sa = {fmuLogger, calloc, free, NULL, &fmu_window_sa};
+
+    c_env = fmu_env.instantiate("env", fmi2CoSimulation, "1", fmuResourceLocation_env, &callbacks_env, fmi2False, fmi2False);
+    c_control_sa = fmu_control_sa.instantiate("control_sa", fmi2CoSimulation, "1", fmuResourceLocation_control_sa, &callbacks_control_sa, fmi2False, fmi2False);
+    c_power_sa = fmu_power_sa.instantiate("power_sa", fmi2CoSimulation, "1", fmuResourceLocation_power_sa, &callbacks_power_sa, fmi2False, fmi2False);
+    c_window_sa = fmu_window_sa.instantiate("window_sa",fmi2CoSimulation, "1", fmuResourceLocation_window_sa, &callbacks_window_sa, fmi2False, fmi2False );
+
+    fmi2Boolean toleranceDefined = fmi2False;  // true if model description define tolerance
+    fmi2Real tolerance = 0;                    // used in setting up the experiment
+
+    puts("FMU components instantiated, setting up experiments\n");
+    fmi2Status fmi2Flag[4];
+    fmi2Flag[0] = fmu_env.setupExperiment(c_env, toleranceDefined, tolerance, START_TIME, fmi2True, STOP_TIME);
+    if (fmi2Flag[0] == fmi2Error){
+    	return -1;
+    }
+    fmi2Flag[1] = fmu_control_sa.setupExperiment(c_control_sa, toleranceDefined, tolerance, START_TIME, fmi2True, STOP_TIME);
+    if (fmi2Flag[1] == fmi2Error){
+    	return -1;
+    }
+    fmi2Flag[2] = fmu_power_sa.setupExperiment(c_power_sa, toleranceDefined, tolerance, START_TIME, fmi2True, STOP_TIME);
+    if (fmi2Flag[2] == fmi2Error){
+    	return -1;
+    }
+    fmi2Flag[3] = fmu_window_sa.setupExperiment(c_window_sa, toleranceDefined, tolerance, START_TIME, fmi2True, STOP_TIME);
+    if (fmi2Flag[3] == fmi2Error){
+    	return -1;
+    }
+
+    puts("Experiment setup, entering init mode\n");
+    fmi2Flag[0] = fmu_env.enterInitializationMode(c_env);
+    if (fmi2Flag[0] == fmi2Error){
+    	return -1;
+    }
+    fmi2Flag[1] = fmu_control_sa.enterInitializationMode(c_control_sa);
+    if (fmi2Flag[1] == fmi2Error){
+    	return -1;
+    }
+    fmi2Flag[2] = fmu_power_sa.enterInitializationMode(c_power_sa);
+    if (fmi2Flag[2] == fmi2Error){
+    	return -1;
+    }
+    fmi2Flag[3] = fmu_window_sa.enterInitializationMode(c_window_sa);
+    if (fmi2Flag[3] == fmi2Error){
+    	return -1;
+    }
+
+    puts("Experiment setup, exiting init mode\n");
+    fmi2Flag[0] = fmu_env.exitInitializationMode(c_env);
+    if (fmi2Flag[0] == fmi2Error){
+    	return -1;
+    }
+    fmi2Flag[1] = fmu_control_sa.exitInitializationMode(c_control_sa);
+    if (fmi2Flag[1] == fmi2Error){
+    	return -1;
+    }
+    fmi2Flag[2] = fmu_power_sa.exitInitializationMode(c_power_sa);
+    if (fmi2Flag[2] == fmi2Error){
+    	return -1;
+    }
+    fmi2Flag[3] = fmu_window_sa.exitInitializationMode(c_window_sa);
+    if (fmi2Flag[3] == fmi2Error){
+    	return -1;
+    }
+
+    fmi2ValueReference vr_out_env[9]={0,1,2,3,4,5,6,7,8};
+    fmi2Boolean b_out_env[9];
+    fmi2ValueReference vr_out_window[1]={0};
+    fmi2Real r_out_window[1]={0};
+    fmi2ValueReference vr_in_control_sa_from_env[8]={0,1,2,3,4,5,6,7};
+    fmi2ValueReference vr_in_control_sa_from_window[1] = {0};
+    fmi2ValueReference vr_out_control_sa[2]={9,10};
+    fmi2ValueReference vr_out_power_i[1] = {0};
+    fmi2ValueReference vr_in_power_sa_u_d_tau[3] = {3,4,5};
+    fmi2Real r_in_power[3];
+    fmi2ValueReference vr_out_power_sa[3] = {0,1,2};
+    fmi2Real r_out_power[3];
+
+    fmi2Boolean b_out_control_sa[2];
+    double currentTime = START_TIME;
+    const fmi2StatusKind lst = fmi2LastSuccessfulTime;
+
+    while(currentTime <= STOP_TIME){
+    	printf("\n----master new loop, ct:%f, h:%f\n",currentTime,STEP_SIZE);
+    	double next_step_size = STEP_SIZE;
+    	fmi2Component ctemp_env, ctemp_control_sa;
+    	/* Make backup*/
+    	fmu_env.getFMUstate(c_env,&ctemp_env);
+    	fmu_control_sa.getFMUstate(c_control_sa, &ctemp_control_sa);
+    	/* do step*/
+    	fmi2Flag[0] = fmu_env.doStep(c_env, currentTime, STEP_SIZE, fmi2True);
+    	if (fmu_env.getBoolean(c_env, vr_out_env, 9, &b_out_env[0]) != fmi2OK){
+    	            return 1;
+    	}
+    	if (fmu_power_sa.getBoolean(c_power_sa, vr_out_power_i, 1, &r_out_window[0]) != fmi2OK){
+    	    	            return 1;
+    	    	}
+
+    	fprintf(fp_fmu_env,"%f,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
+    			currentTime,
+				b_out_env[0],
+				b_out_env[1],
+				b_out_env[2],
+				b_out_env[3],
+				b_out_env[4],
+				b_out_env[5],
+				b_out_env[6],
+				b_out_env[7],
+				b_out_env[8]);
+    	if (b_out_env[8]){
+    		r_out_window[0] = 5;
+    	}else{
+    		r_out_window[0]= 0;
+    	}
+    	fmi2Flag[1] = fmu_control_sa.setBoolean(c_control_sa,vr_in_control_sa_from_env,8,&b_out_env[0]);
+    	if(fmi2Flag[1] != fmi2OK){
+    		return 1;
+    	}
+    	fmi2Flag[1] = fmu_control_sa.setReal(c_control_sa,vr_in_control_sa_from_window,1, &r_out_window[0]);
+    	if(fmi2Flag[1] != fmi2OK){
+    	    		return 1;
+    	}
+
+    	fmi2Flag[1] = fmu_control_sa.doStep(c_control_sa, currentTime, STEP_SIZE, fmi2True);
+
+    	if (fmu_control_sa.getBoolean(c_control_sa, vr_out_control_sa, 2, &b_out_control_sa[0]) != fmi2OK){
+    	    	            return 1;
+    	    	}
+    	fprintf(fp_fmu_control_sa,"%f,%d,%d\n",
+    			currentTime,
+				b_out_control_sa[0],
+				b_out_control_sa[1]);
+
+    	r_in_power[0] = b_out_control_sa[1];
+    	r_in_power[1] = 0;
+    	r_in_power[2] = b_out_control_sa[2];
+
+    	fmi2Flag[2] = fmu_power_sa.setReal(c_power_sa,vr_in_power_sa_u_d_tau,3, &r_in_power[0]);
+    	if(fmi2Flag[1] != fmi2OK){
+    		return 1;
+    	}
+
+    	fmi2Flag[2] = fmu_power_sa.doStep(c_power_sa, currentTime, STEP_SIZE, fmi2True);
+
+    	if (fmu_env.setReal(c_power_sa, vr_out_power_sa, 3, &r_out_power[0]) != fmi2OK){
+    	    	            return 1;
+    	    	}
+
+    	fprintf(fp_fmu_power_sa,"%f,%f,%f,%f\n",
+    	    			currentTime,
+    					r_out_window[0],
+    					r_out_window[1],
+						r_out_window[2]);
+
+    	int redoStep  = 0;
+    	for(int i=0; i<2; i++)
+    	if (fmi2Flag[i] == fmi2Discard){
+    		redoStep = 1;
+    		fmi2Real newtime;
+
+    		fmu_control_sa.getRealStatus(c_control_sa, lst, &newtime);
+    		fmi2Real the_FMU_new_step = newtime - currentTime;
+    		if(the_FMU_new_step < next_step_size){
+    			next_step_size = the_FMU_new_step;
+    		}
+    	}
+
+    	if(redoStep){ // should be a while loop!
+    		// Recover all FMUs and do step again
+    		printf("recover not yet implemented\n");
+    	}else{
+    		currentTime += STEP_SIZE;
+    	}
+
+    }
+    fclose(fp_fmu_env);
+    fclose(fp_fmu_power_sa);
+    fclose(fp_fmu_control_sa);
+	return EXIT_SUCCESS;
+}

+ 594 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/src/sim_support.c

@@ -0,0 +1,594 @@
+/* -------------------------------------------------------------------------
+ * sim_support.c
+ * Functions used by both FMU simulators fmu20sim_me and fmu20sim_cs
+ * to parse command-line arguments, to unzip and load an fmu,
+ * to write CSV file, and more.
+ *
+ * Revision history
+ *  07.03.2014 initial version released in FMU SDK 2.0.0
+ *  10.04.2014 use FMI 2.0 headers that prefix function and type names with 'fmi2'.
+ *             When 'fmi2' functions are not found in loaded DLL, look also for
+ *             FMI 2.0 RC1 function names.
+ *
+ * Author: Adrian Tirea
+ * Copyright QTronic GmbH. All rights reserved.
+ * -------------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <stdarg.h>
+#include <dlfcn.h>
+#include "fmi2.h"
+#include "sim_support.h"
+
+#define FMI_COSIMULATION
+extern FMU fmu;
+
+
+//int unzip(const char *zipPath, const char *outPath) {
+//    int code;
+//    char cwd[BUFSIZE];
+//    char binPath[BUFSIZE];
+//    int n = strlen(UNZIP_CMD) + strlen(outPath) + 3 +  strlen(zipPath) + 9;
+//    char* cmd = (char*)calloc(sizeof(char), n);
+//
+//    // remember current directory
+//    if (!GetCurrentDirectory(BUFSIZE, cwd)) {
+//        printf ("error: Could not get current directory\n");
+//        return 0; // error
+//    }
+//
+//    // change to %FMUSDK_HOME%\bin to find 7z.dll and 7z.exe
+//    if (!GetEnvironmentVariable("FMUSDK_HOME", binPath, BUFSIZE)) {
+//        if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
+//            printf ("error: Environment variable FMUSDK_HOME not defined\n");
+//        }
+//        else {
+//            printf ("error: Could not get value of FMUSDK_HOME\n");
+//        }
+//        return 0; // error
+//    }
+//    strcat(binPath, "\\bin");
+//    if (!SetCurrentDirectory(binPath)) {
+//        printf ("error: could not change to directory '%s'\n", binPath);
+//        return 0; // error
+//    }
+//
+//    // run the unzip command
+//    // remove "> NUL" to see the unzip protocol
+//    sprintf(cmd, "%s\"%s\" \"%s\" > NUL", UNZIP_CMD, outPath, zipPath);
+//    // printf("cmd='%s'\n", cmd);
+//    code = system(cmd);
+//    free(cmd);
+//    if (code != SEVEN_ZIP_NO_ERROR) {
+//        printf("7z: ");
+//        switch (code) {
+//            case SEVEN_ZIP_WARNING:            printf("warning\n"); break;
+//            case SEVEN_ZIP_ERROR:              printf("error\n"); break;
+//            case SEVEN_ZIP_COMMAND_LINE_ERROR: printf("command line error\n"); break;
+//            case SEVEN_ZIP_OUT_OF_MEMORY:      printf("out of memory\n"); break;
+//            case SEVEN_ZIP_STOPPED_BY_USER:    printf("stopped by user\n"); break;
+//            default: printf("unknown problem\n");
+//        }
+//    }
+//
+//    // restore current directory
+//    SetCurrentDirectory(cwd);
+//    return (code == SEVEN_ZIP_NO_ERROR || code == SEVEN_ZIP_WARNING) ? 1 : 0;
+//}
+//
+//// fileName is an absolute path, e.g. C:\test\a.fmu
+//// or relative to the current dir, e.g. ..\test\a.fmu
+//// Does not check for existence of the file
+//static char* getFmuPath(const char* fileName){
+//    char pathName[MAX_PATH];
+//    int n = GetFullPathName(fileName, MAX_PATH, pathName, NULL);
+//    return n ? strdup(pathName) : NULL;
+//}
+//
+//static char* getTmpPath() {
+//    char tmpPath[BUFSIZE];
+//    if(! GetTempPath(BUFSIZE, tmpPath)) {
+//        printf ("error: Could not find temporary disk space\n");
+//        return NULL;
+//    }
+//    strcat(tmpPath, "fmu\\");
+//    return strdup(tmpPath);
+//}
+//
+//char *getTempResourcesLocation() {
+//    char *tempPath = getTmpPath();
+//    char *resourcesLocation = (char *)calloc(sizeof(char), 9 + strlen(RESOURCES_DIR) + strlen(tempPath));
+//    strcpy(resourcesLocation, "file:///");
+//    strcat(resourcesLocation, tempPath);
+//    strcat(resourcesLocation, RESOURCES_DIR);
+//    free(tempPath);
+//    return resourcesLocation;
+//}
+
+static void *getAdr(int *success, void *dllHandle, const char *functionName, const char* preamble) {
+
+    int length = strlen(preamble) + strlen(functionName) + 1;
+    char* new_name = malloc(length);  // allocate memory
+    strcpy(new_name, preamble);  // copy first string
+    strcat(new_name, functionName);
+    void* fp = dlsym(dllHandle, new_name);
+    if (!fp) {
+        printf("warning: Function %s not found in dll\n", new_name);
+        *success = 0;
+    }
+    free(new_name);
+    return fp;
+}
+
+// Load the given dll and set function pointers in fmu
+// Return 0 to indicate failure
+int loadDll(const char* dllPath, FMU *fmu, const char* preamble) {
+    int x = 1, s = 1;
+    //HMODULE h = LoadLibrary(dllPath);
+    void *h = dlopen(dllPath, RTLD_LAZY);
+    printf("%s", dlerror());
+    if (!h) {
+        printf("error: Could not load %s\n", dllPath);
+        return 0; // failure
+    }
+    fmu->dllHandle = h;
+    fmu->getTypesPlatform          = (fmi2GetTypesPlatformTYPE *)      getAdr(&s, h, "fmi2GetTypesPlatform", preamble);
+    fmu->getVersion                = (fmi2GetVersionTYPE *)            getAdr(&s, h, "fmi2GetVersion", preamble);
+    fmu->setDebugLogging           = (fmi2SetDebugLoggingTYPE *)       getAdr(&s, h, "fmi2SetDebugLogging",preamble);
+    fmu->instantiate               = (fmi2InstantiateTYPE *)           getAdr(&s, h, "fmi2Instantiate", preamble);
+    fmu->freeInstance              = (fmi2FreeInstanceTYPE *)          getAdr(&s, h, "fmi2FreeInstance", preamble);
+    fmu->setupExperiment           = (fmi2SetupExperimentTYPE *)       getAdr(&s, h, "fmi2SetupExperiment", preamble);
+    fmu->enterInitializationMode   = (fmi2EnterInitializationModeTYPE *) getAdr(&s, h, "fmi2EnterInitializationMode", preamble);
+    fmu->exitInitializationMode    = (fmi2ExitInitializationModeTYPE *) getAdr(&s, h, "fmi2ExitInitializationMode", preamble);
+    fmu->terminate                 = (fmi2TerminateTYPE *)             getAdr(&s, h, "fmi2Terminate", preamble);
+    fmu->reset                     = (fmi2ResetTYPE *)                 getAdr(&s, h, "fmi2Reset", preamble);
+    fmu->getReal                   = (fmi2GetRealTYPE *)               getAdr(&s, h, "fmi2GetReal", preamble);
+    fmu->getInteger                = (fmi2GetIntegerTYPE *)            getAdr(&s, h, "fmi2GetInteger", preamble);
+    fmu->getBoolean                = (fmi2GetBooleanTYPE *)            getAdr(&s, h, "fmi2GetBoolean", preamble);
+    fmu->getString                 = (fmi2GetStringTYPE *)             getAdr(&s, h, "fmi2GetString", preamble);
+    fmu->setReal                   = (fmi2SetRealTYPE *)               getAdr(&s, h, "fmi2SetReal", preamble);
+    fmu->setInteger                = (fmi2SetIntegerTYPE *)            getAdr(&s, h, "fmi2SetInteger", preamble);
+    fmu->setBoolean                = (fmi2SetBooleanTYPE *)            getAdr(&s, h, "fmi2SetBoolean", preamble);
+    fmu->setString                 = (fmi2SetStringTYPE *)             getAdr(&s, h, "fmi2SetString", preamble);
+    fmu->getFMUstate               = (fmi2GetFMUstateTYPE *)           getAdr(&s, h, "fmi2GetFMUstate", preamble);
+    fmu->setFMUstate               = (fmi2SetFMUstateTYPE *)           getAdr(&s, h, "fmi2SetFMUstate", preamble);
+    fmu->freeFMUstate              = (fmi2FreeFMUstateTYPE *)          getAdr(&s, h, "fmi2FreeFMUstate", preamble);
+    fmu->serializedFMUstateSize    = (fmi2SerializedFMUstateSizeTYPE *) getAdr(&s, h, "fmi2SerializedFMUstateSize", preamble);
+    fmu->serializeFMUstate         = (fmi2SerializeFMUstateTYPE *)     getAdr(&s, h, "fmi2SerializeFMUstate", preamble);
+    fmu->deSerializeFMUstate       = (fmi2DeSerializeFMUstateTYPE *)   getAdr(&s, h, "fmi2DeSerializeFMUstate", preamble);
+    fmu->getDirectionalDerivative  = (fmi2GetDirectionalDerivativeTYPE *) getAdr(&s, h, "fmi2GetDirectionalDerivative", preamble);
+#ifdef FMI_COSIMULATION
+    fmu->setRealInputDerivatives   = (fmi2SetRealInputDerivativesTYPE *) getAdr(&s, h, "fmi2SetRealInputDerivatives", preamble);
+    fmu->getRealOutputDerivatives  = (fmi2GetRealOutputDerivativesTYPE *) getAdr(&s, h, "fmi2GetRealOutputDerivatives", preamble);
+    fmu->doStep                    = (fmi2DoStepTYPE *)                getAdr(&s, h, "fmi2DoStep", preamble);
+    fmu->cancelStep                = (fmi2CancelStepTYPE *)            getAdr(&s, h, "fmi2CancelStep", preamble);
+    fmu->getStatus                 = (fmi2GetStatusTYPE *)             getAdr(&s, h, "fmi2GetStatus", preamble);
+    fmu->getRealStatus             = (fmi2GetRealStatusTYPE *)         getAdr(&s, h, "fmi2GetRealStatus", preamble);
+    fmu->getIntegerStatus          = (fmi2GetIntegerStatusTYPE *)      getAdr(&s, h, "fmi2GetIntegerStatus", preamble);
+    fmu->getBooleanStatus          = (fmi2GetBooleanStatusTYPE *)      getAdr(&s, h, "fmi2GetBooleanStatus", preamble);
+    fmu->getStringStatus           = (fmi2GetStringStatusTYPE *)       getAdr(&s, h, "fmi2GetStringStatus", preamble);
+#else // FMI2 for Model Exchange
+    fmu->enterEventMode            = (fmi2EnterEventModeTYPE *)        getAdr(&s, h, "fmi2EnterEventMode", preamble);
+    fmu->newDiscreteStates         = (fmi2NewDiscreteStatesTYPE *)     getAdr(&s, h, "fmi2NewDiscreteStates", preamble);
+    fmu->enterContinuousTimeMode   = (fmi2EnterContinuousTimeModeTYPE *) getAdr(&s, h, "fmi2EnterContinuousTimeMode", preamble);
+    fmu->completedIntegratorStep   = (fmi2CompletedIntegratorStepTYPE *) getAdr(&s, h, "fmi2CompletedIntegratorStep", preamble);
+    fmu->setTime                   = (fmi2SetTimeTYPE *)               getAdr(&s, h, "fmi2SetTime", preamble);
+    fmu->setContinuousStates       = (fmi2SetContinuousStatesTYPE *)   getAdr(&s, h, "fmi2SetContinuousStates", preamble);
+    fmu->getDerivatives            = (fmi2GetDerivativesTYPE *)        getAdr(&s, h, "fmi2GetDerivatives", preamble);
+    fmu->getEventIndicators        = (fmi2GetEventIndicatorsTYPE *)    getAdr(&s, h, "fmi2GetEventIndicators", preamble);
+    fmu->getContinuousStates       = (fmi2GetContinuousStatesTYPE *)   getAdr(&s, h, "fmi2GetContinuousStates", preamble);
+    fmu->getNominalsOfContinuousStates = (fmi2GetNominalsOfContinuousStatesTYPE *) getAdr(&s, h, "fmi2GetNominalsOfContinuousStates", preamble);
+#endif
+
+    if (fmu->getVersion == NULL && fmu->instantiate == NULL) {
+        printf("warning: Functions from FMI 2.0 could not be found in %s\n", dllPath);
+        printf("warning: Simulator will look for FMI 2.0 RC1 functions names...\n");
+        fmu->getTypesPlatform          = (fmi2GetTypesPlatformTYPE *)      getAdr(&s, h, "fmiGetTypesPlatform", preamble);
+        fmu->getVersion                = (fmi2GetVersionTYPE *)            getAdr(&s, h, "fmiGetVersion", preamble);
+        fmu->setDebugLogging           = (fmi2SetDebugLoggingTYPE *)       getAdr(&s, h, "fmiSetDebugLogging", preamble);
+        fmu->instantiate               = (fmi2InstantiateTYPE *)           getAdr(&s, h, "fmiInstantiate", preamble);
+        fmu->freeInstance              = (fmi2FreeInstanceTYPE *)          getAdr(&s, h, "fmiFreeInstance", preamble);
+        fmu->setupExperiment           = (fmi2SetupExperimentTYPE *)       getAdr(&s, h, "fmiSetupExperiment", preamble);
+        fmu->enterInitializationMode   = (fmi2EnterInitializationModeTYPE *) getAdr(&s, h, "fmiEnterInitializationMode", preamble);
+        fmu->exitInitializationMode    = (fmi2ExitInitializationModeTYPE *) getAdr(&s, h, "fmiExitInitializationMode", preamble);
+        fmu->terminate                 = (fmi2TerminateTYPE *)             getAdr(&s, h, "fmiTerminate", preamble);
+        fmu->reset                     = (fmi2ResetTYPE *)                 getAdr(&s, h, "fmiReset", preamble);
+        fmu->getReal                   = (fmi2GetRealTYPE *)               getAdr(&s, h, "fmiGetReal", preamble);
+        fmu->getInteger                = (fmi2GetIntegerTYPE *)            getAdr(&s, h, "fmiGetInteger", preamble);
+        fmu->getBoolean                = (fmi2GetBooleanTYPE *)            getAdr(&s, h, "fmiGetBoolean", preamble);
+        fmu->getString                 = (fmi2GetStringTYPE *)             getAdr(&s, h, "fmiGetString", preamble);
+        fmu->setReal                   = (fmi2SetRealTYPE *)               getAdr(&s, h, "fmiSetReal", preamble);
+        fmu->setInteger                = (fmi2SetIntegerTYPE *)            getAdr(&s, h, "fmiSetInteger", preamble);
+        fmu->setBoolean                = (fmi2SetBooleanTYPE *)            getAdr(&s, h, "fmiSetBoolean", preamble);
+        fmu->setString                 = (fmi2SetStringTYPE *)             getAdr(&s, h, "fmiSetString", preamble);
+        fmu->getFMUstate               = (fmi2GetFMUstateTYPE *)           getAdr(&s, h, "fmiGetFMUstate", preamble);
+        fmu->setFMUstate               = (fmi2SetFMUstateTYPE *)           getAdr(&s, h, "fmiSetFMUstate", preamble);
+        fmu->freeFMUstate              = (fmi2FreeFMUstateTYPE *)          getAdr(&s, h, "fmiFreeFMUstate", preamble);
+        fmu->serializedFMUstateSize    = (fmi2SerializedFMUstateSizeTYPE *) getAdr(&s, h, "fmiSerializedFMUstateSize", preamble);
+        fmu->serializeFMUstate         = (fmi2SerializeFMUstateTYPE *)     getAdr(&s, h, "fmiSerializeFMUstate", preamble);
+        fmu->deSerializeFMUstate       = (fmi2DeSerializeFMUstateTYPE *)   getAdr(&s, h, "fmiDeSerializeFMUstate", preamble);
+        fmu->getDirectionalDerivative  = (fmi2GetDirectionalDerivativeTYPE *) getAdr(&s, h, "fmiGetDirectionalDerivative", preamble);
+    #ifdef FMI_COSIMULATION
+        fmu->setRealInputDerivatives   = (fmi2SetRealInputDerivativesTYPE *) getAdr(&s, h, "fmiSetRealInputDerivatives", preamble);
+        fmu->getRealOutputDerivatives  = (fmi2GetRealOutputDerivativesTYPE *) getAdr(&s, h, "fmiGetRealOutputDerivatives", preamble);
+        fmu->doStep                    = (fmi2DoStepTYPE *)                getAdr(&s, h, "fmiDoStep", preamble);
+        fmu->cancelStep                = (fmi2CancelStepTYPE *)            getAdr(&s, h, "fmiCancelStep", preamble);
+        fmu->getStatus                 = (fmi2GetStatusTYPE *)             getAdr(&s, h, "fmiGetStatus", preamble);
+        fmu->getRealStatus             = (fmi2GetRealStatusTYPE *)         getAdr(&s, h, "fmiGetRealStatus", preamble);
+        fmu->getIntegerStatus          = (fmi2GetIntegerStatusTYPE *)      getAdr(&s, h, "fmiGetIntegerStatus", preamble);
+        fmu->getBooleanStatus          = (fmi2GetBooleanStatusTYPE *)      getAdr(&s, h, "fmiGetBooleanStatus", preamble);
+        fmu->getStringStatus           = (fmi2GetStringStatusTYPE *)       getAdr(&s, h, "fmiGetStringStatus", preamble);
+    #else // FMI2 for Model Exchange
+        fmu->enterEventMode            = (fmi2EnterEventModeTYPE *)        getAdr(&s, h, "fmiEnterEventMode", preamble);
+        fmu->newDiscreteStates         = (fmi2NewDiscreteStatesTYPE *)     getAdr(&s, h, "fmiNewDiscreteStates", preamble);
+        fmu->enterContinuousTimeMode   = (fmi2EnterContinuousTimeModeTYPE *) getAdr(&s, h, "fmiEnterContinuousTimeMode", preamble);
+        fmu->completedIntegratorStep   = (fmi2CompletedIntegratorStepTYPE *) getAdr(&s, h, "fmiCompletedIntegratorStep", preamble);
+        fmu->setTime                   = (fmi2SetTimeTYPE *)               getAdr(&s, h, "fmiSetTime", preamble);
+        fmu->setContinuousStates       = (fmi2SetContinuousStatesTYPE *)   getAdr(&s, h, "fmiSetContinuousStates", preamble);
+        fmu->getDerivatives            = (fmi2GetDerivativesTYPE *)        getAdr(&s, h, "fmiGetDerivatives", preamble);
+        fmu->getEventIndicators        = (fmi2GetEventIndicatorsTYPE *)    getAdr(&s, h, "fmiGetEventIndicators", preamble);
+        fmu->getContinuousStates       = (fmi2GetContinuousStatesTYPE *)   getAdr(&s, h, "fmiGetContinuousStates", preamble);
+        fmu->getNominalsOfContinuousStates = (fmi2GetNominalsOfContinuousStatesTYPE *) getAdr(&s, h, "fmiGetNominalsOfContinuousStates", preamble);
+    #endif
+    }
+    return s;
+}
+
+//static void printModelDescription(ModelDescription* md){
+//    Element* e = (Element*)md;
+//    int i;
+//    int n; // number of attributes
+//    const char **attributes = getAttributesAsArray(e, &n);
+//    Component *component;
+//
+//    if (!attributes) {
+//        printf("ModelDescription printing aborted.");
+//        return;
+//    }
+//    printf("%s\n", getElementTypeName(e));
+//    for (i = 0; i < n; i += 2) {
+//        printf("  %s=%s\n", attributes[i], attributes[i+1]);
+//    }
+//    free((void *)attributes);
+//
+//#ifdef FMI_COSIMULATION
+//    component = getCoSimulation(md);
+//    if (!component) {
+//        printf("error: No CoSimulation element found in model description. This FMU is not for Co-Simulation.\n");
+//        exit(EXIT_FAILURE);
+//    }
+//#else // FMI_MODEL_EXCHANGE
+//    component = getModelExchange(md);
+//    if (!component) {
+//        printf("error: No ModelExchange element found in model description. This FMU is not for Model Exchange.\n");
+//        exit(EXIT_FAILURE);
+//    }
+//#endif
+//    printf("%s\n", getElementTypeName((Element *)component));
+//    attributes = getAttributesAsArray((Element *)component, &n);
+//    if (!attributes) {
+//        printf("ModelDescription printing aborted.");
+//        return;
+//    }
+//    for (i = 0; i < n; i += 2) {
+//        printf("  %s=%s\n", attributes[i], attributes[i+1]);
+//    }
+//
+//    free((void *)attributes);
+//}
+//
+//void loadFMU(const char* fmuFileName) {
+//    char* fmuPath;
+//    char* tmpPath;
+//    char* xmlPath;
+//    char* dllPath;
+//    const char *modelId;
+//
+//    // get absolute path to FMU, NULL if not found
+//    fmuPath = getFmuPath(fmuFileName);
+//    if (!fmuPath) exit(EXIT_FAILURE);
+//
+//    // unzip the FMU to the tmpPath directory
+//    tmpPath = getTmpPath();
+//    if (!unzip(fmuPath, tmpPath)) exit(EXIT_FAILURE);
+//
+//    // parse tmpPath\modelDescription.xml
+//    xmlPath = calloc(sizeof(char), strlen(tmpPath) + strlen(XML_FILE) + 1);
+//    sprintf(xmlPath, "%s%s", tmpPath, XML_FILE);
+//    fmu.modelDescription = parse(xmlPath);
+//    free(xmlPath);
+//    if (!fmu.modelDescription) exit(EXIT_FAILURE);
+//    printModelDescription(fmu.modelDescription);
+//#ifdef FMI_COSIMULATION
+//    modelId = getAttributeValue((Element *)getCoSimulation(fmu.modelDescription), att_modelIdentifier);
+//#else // FMI_MODEL_EXCHANGE
+//    modelId = getAttributeValue((Element *)getModelExchange(fmu.modelDescription), att_modelIdentifier);
+//#endif
+//    // load the FMU dll
+//    dllPath = calloc(sizeof(char), strlen(tmpPath) + strlen(DLL_DIR)
+//        + strlen(modelId) +  strlen(".dll") + 1);
+//    sprintf(dllPath, "%s%s%s.dll", tmpPath, DLL_DIR, modelId);
+//    if (!loadDll(dllPath, &fmu)) {
+//        exit(EXIT_FAILURE);
+//    }
+//    free(dllPath);
+//    free(fmuPath);
+//    free(tmpPath);
+//}
+//
+//void deleteUnzippedFiles() {
+//    const char *fmuTempPath = getTmpPath();
+//    char *cmd = (char *)calloc(15 + strlen(fmuTempPath), sizeof(char));
+//    sprintf(cmd, "rmdir /S /Q %s", fmuTempPath);
+//    system(cmd);
+//    free(cmd);
+//}
+//
+//static void doubleToCommaString(char* buffer, double r){
+//    char* comma;
+//    sprintf(buffer, "%.16g", r);
+//    comma = strchr(buffer, '.');
+//    if (comma) *comma = ',';
+//}
+//
+//// output time and all variables in CSV format
+//// if separator is ',', columns are separated by ',' and '.' is used for floating-point numbers.
+//// otherwise, the given separator (e.g. ';' or '\t') is to separate columns, and ',' is used
+//// as decimal dot in floating-point numbers.
+//void outputRow(FMU *fmu, fmi2Component c, double time, FILE* file, char separator, fmi2Boolean header) {
+//    int k;
+//    fmi2Real r;
+//    fmi2Integer i;
+//    fmi2Boolean b;
+//    fmi2String s;
+//    fmi2ValueReference vr;
+//    int n = getScalarVariableSize(fmu->modelDescription);
+//    char buffer[32];
+//
+//    // print first column
+//    if (header) {
+//        fprintf(file, "time");
+//    } else {
+//        if (separator==',')
+//            fprintf(file, "%.16g", time);
+//        else {
+//            // separator is e.g. ';' or '\t'
+//            doubleToCommaString(buffer, time);
+//            fprintf(file, "%s", buffer);
+//        }
+//    }
+//
+//    // print all other columns
+//    for (k = 0; k < n; k++) {
+//        ScalarVariable *sv = getScalarVariable(fmu->modelDescription, k);
+//        if (header) {
+//            // output names only
+//            if (separator == ',') {
+//                // treat array element, e.g. print a[1, 2] as a[1.2]
+//                const char *s = getAttributeValue((Element *)sv, att_name);
+//                fprintf(file, "%c", separator);
+//                while (*s) {
+//                    if (*s != ' ') {
+//                        fprintf(file, "%c", *s == ',' ? '.' : *s);
+//                    }
+//                    s++;
+//                }
+//            } else {
+//                fprintf(file, "%c%s", separator, getAttributeValue((Element *)sv, att_name));
+//            }
+//        } else {
+//            // output values
+//            vr = getValueReference(sv);
+//            switch (getElementType(getTypeSpec(sv))) {
+//                case elm_Real:
+//                    fmu->getReal(c, &vr, 1, &r);
+//                    if (separator == ',') {
+//                        fprintf(file, ",%.16g", r);
+//                    } else {
+//                        // separator is e.g. ';' or '\t'
+//                        doubleToCommaString(buffer, r);
+//                        fprintf(file, "%c%s", separator, buffer);
+//                    }
+//                    break;
+//                case elm_Integer:
+//                case elm_Enumeration:
+//                    fmu->getInteger(c, &vr, 1, &i);
+//                    fprintf(file, "%c%d", separator, i);
+//                    break;
+//                case elm_Boolean:
+//                    fmu->getBoolean(c, &vr, 1, &b);
+//                    fprintf(file, "%c%d", separator, b);
+//                    break;
+//                case elm_String:
+//                    fmu->getString(c, &vr, 1, &s);
+//                    fprintf(file, "%c%s", separator, s);
+//                    break;
+//                default:
+//                    fprintf(file, "%cNoValueForType=%d", separator, getElementType(getTypeSpec(sv)));
+//            }
+//        }
+//    } // for
+//
+//    // terminate this row
+//    fprintf(file, "\n");
+//}
+//
+static const char* fmi2StatusToString(fmi2Status status){
+    switch (status){
+        case fmi2OK:      return "ok";
+        case fmi2Warning: return "warning";
+        case fmi2Discard: return "discard";
+        case fmi2Error:   return "error";
+        case fmi2Fatal:   return "fatal";
+    #ifdef FMI_COSIMULATION
+        case fmi2Pending: return "fmi2Pending";
+    #endif
+        default:         return "?";
+    }
+}
+
+// search a fmu for the given variable, matching the type specified.
+// return NULL if not found
+//static ScalarVariable* getSV(FMU* fmu, char type, fmi2ValueReference vr) {
+//    return NULL;
+//    int i;
+//    int n = getScalarVariableSize(fmu->modelDescription);
+//    Elm tp;
+//
+//    switch (type) {
+//        case 'r': tp = elm_Real;    break;
+//        case 'i': tp = elm_Integer; break;
+//        case 'b': tp = elm_Boolean; break;
+//        case 's': tp = elm_String;  break;
+//        default : tp = elm_BAD_DEFINED;
+//    }
+//    for (i = 0; i < n; i++) {
+//        ScalarVariable* sv = getScalarVariable(fmu->modelDescription ,i);
+//        if (vr == getValueReference(sv) && tp == getElementType(getTypeSpec(sv))) {
+//            return sv;
+//        }
+//    }
+//    return NULL;
+//}
+
+// replace e.g. #r1365# by variable name and ## by # in message
+// copies the result to buffer
+static void replaceRefsInMessage(const char* msg, char* buffer, int nBuffer, FMU* fmu){
+    int i = 0; // position in msg
+    int k = 0; // position in buffer
+    int n;
+    char c = msg[i];
+    while (c != '\0' && k < nBuffer) {
+        if (c != '#') {
+            buffer[k++] = c;
+            i++;
+            c = msg[i];
+        } else {
+
+            char* end = strchr(msg + i + 1, '#');
+            if (!end) {
+                printf("unmatched '#' in '%s'\n", msg);
+                buffer[k++] = '#';
+                break;
+            }
+            n = end - (msg + i);
+            if (n == 1) {
+                // ## detected, output #
+                buffer[k++] = '#';
+                i += 2;
+                c = msg[i];
+
+            } else {
+                char type = msg[i + 1]; // one of ribs
+                fmi2ValueReference vr;
+                int nvr = sscanf(msg + i + 2, "%u", &vr);
+                if (nvr == 1) {
+                    // vr of type detected, e.g. #r12#
+                    //ScalarVariable* sv = getSV(fmu, type, vr);
+                    //const char* name = sv ? getAttributeValue((Element *)sv, att_name) : "?";
+                    //sprintf(buffer + k, "%s", name);
+                    //k += strlen(name);
+                    //i += (n+1);
+                    //c = msg[i];
+
+                } else {
+                    // could not parse the number
+                    printf("illegal value reference at position %d in '%s'\n", i + 2, msg);
+                    buffer[k++] = '#';
+                    break;
+                }
+            }
+        }
+    } // while
+    buffer[k] = '\0';
+}
+
+#define MAX_MSG_SIZE 1000
+void fmuLogger(void *componentEnvironment, fmi2String instanceName, fmi2Status status,
+               fmi2String category, fmi2String message, ...) {
+    char msg[MAX_MSG_SIZE];
+    char* copy;
+    va_list argp;
+
+    // replace C format strings
+    va_start(argp, message);
+    vsprintf(msg, message, argp);
+    va_end(argp);
+
+    // replace e.g. ## and #r12#
+    copy = strdup(msg);
+//    replaceRefsInMessage(copy, msg, MAX_MSG_SIZE, NULL);
+    free(copy);
+
+    // print the final message
+    if (!instanceName) instanceName = "?";
+    if (!category) category = "?";
+    printf("%s %s (%s): %s\n", fmi2StatusToString(status), instanceName, category, msg);
+}
+
+int error(const char* message){
+    printf("%s\n", message);
+    return 0;
+}
+//
+//void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tEnd, double *h,
+//                    int *loggingOn, char *csv_separator, int *nCategories, char **logCategories[]) {
+//    // parse command line arguments
+//    if (argc > 1) {
+//        *fmuFileName = argv[1];
+//    } else {
+//        printf("error: no fmu file\n");
+//        printHelp(argv[0]);
+//        exit(EXIT_FAILURE);
+//    }
+//    if (argc > 2) {
+//        if (sscanf(argv[2],"%lf", tEnd) != 1) {
+//            printf("error: The given end time (%s) is not a number\n", argv[2]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 3) {
+//        if (sscanf(argv[3],"%lf", h) != 1) {
+//            printf("error: The given stepsize (%s) is not a number\n", argv[3]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 4) {
+//        if (sscanf(argv[4],"%d", loggingOn) != 1 || *loggingOn < 0 || *loggingOn > 1) {
+//            printf("error: The given logging flag (%s) is not boolean\n", argv[4]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 5) {
+//        if (strlen(argv[5]) != 1) {
+//            printf("error: The given CSV separator char (%s) is not valid\n", argv[5]);
+//            exit(EXIT_FAILURE);
+//        }
+//        switch (argv[5][0]) {
+//            case 'c': *csv_separator = ','; break; // comma
+//            case 's': *csv_separator = ';'; break; // semicolon
+//            default:  *csv_separator = argv[5][0]; break; // any other char
+//        }
+//    }
+//    if (argc > 6) {
+//        int i;
+//        *nCategories = argc - 6;
+//        *logCategories = (char **)calloc(sizeof(char *), *nCategories);
+//        for (i = 0; i < *nCategories; i++) {
+//            (*logCategories)[i] = argv[i + 6];
+//        }
+//    }
+//}
+//
+//void printHelp(const char *fmusim) {
+//    printf("command syntax: %s <model.fmu> <tEnd> <h> <loggingOn> <csv separator>\n", fmusim);
+//    printf("   <model.fmu> .... path to FMU, relative to current dir or absolute, required\n");
+//    printf("   <tEnd> ......... end  time of simulation,   optional, defaults to 1.0 sec\n");
+//    printf("   <h> ............ step size of simulation,   optional, defaults to 0.1 sec\n");
+//    printf("   <loggingOn> .... 1 to activate logging,     optional, defaults to 0\n");
+//    printf("   <csv separator>. separator in csv file,     optional, c for ',', s for';', defaults to c\n");
+//    printf("   <logCategories>. list of active categories, optional, see modelDescription.xml for possible values\n");
+//}

+ 44 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/case/src/sim_support.h

@@ -0,0 +1,44 @@
+/* ------------------------------------------------------------------------- 
+ * sim_support.h
+ * Functions used by the FMU simulations fmusim_me and fmusim_cs.
+ * Copyright QTronic GmbH. All rights reserved.
+ * -------------------------------------------------------------------------*/
+#ifndef __SIM_SUPPORT_H
+#define __SIM_SUPPORT_H
+#include "fmi2.h"
+// Used 7z options, version 4.57:
+// -x   Extracts files from an archive with their full paths in the current dir, or in an output dir if specified
+// -aoa Overwrite All existing files without prompt
+// -o   Specifies a destination directory where files are to be extracted
+#define UNZIP_CMD "7z x -aoa -o"
+#define XML_FILE  "modelDescription.xml"
+#define RESULT_FILE "result.csv"
+#define BUFSIZE 4096
+#ifdef _WIN64
+#define DLL_DIR   "binaries\\win64\\"
+#else
+#define DLL_DIR   "binaries\\win32\\"
+#endif
+#define RESOURCES_DIR "resources\\"
+
+// return codes of the 7z command line tool
+#define SEVEN_ZIP_NO_ERROR 0 // success
+#define SEVEN_ZIP_WARNING 1  // e.g., one or more files were locked during zip
+#define SEVEN_ZIP_ERROR 2
+#define SEVEN_ZIP_COMMAND_LINE_ERROR 7
+#define SEVEN_ZIP_OUT_OF_MEMORY 8
+#define SEVEN_ZIP_STOPPED_BY_USER 255
+
+void fmuLogger(fmi2Component c, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message, ...);
+int unzip(const char *zipPath, const char *outPath);
+void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tEnd, double *h,
+                    int *loggingOn, char *csv_separator, int *nCategories, char **logCategories[]);
+void loadFMU(const char *fmuFileName);
+int loadDll(const char* dllPath, FMU *fmu, const char* preamble);
+void deleteUnzippedFiles();
+void outputRow(FMU *fmu, fmi2Component c, double time, FILE* file, char separator, fmi2Boolean header);
+int error(const char *message);
+void printHelp(const char *fmusim);
+char *getTempResourcesLocation(); // caller has to free the result
+
+#endif

File diff suppressed because it is too large
+ 124 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/.cproject


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/Debug/FMI_Environment.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/Debug/libFMI_Environment.dll


+ 536 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/FMI_Environment.c

@@ -0,0 +1,536 @@
+/* ---------------------------------------------------------------------------*
+ * Sample implementation of an FMU - a power window controller
+ * The code is generated from a Yakindu SC
+ * ---------------------------------------------------------------------------*/
+/*
+Template for a sc FMU
+*/
+
+#define MODEL_IDENTIFIER SEL
+#define MODEL_GUID "{41f87101-edf2-4eef-90f3-42db56d4565f}"
+#define FMI2_FUNCTION_PREFIX PW_ENV
+
+
+#include <stdio.h>
+#include "string.h"
+#include "fmi2Functions.h"
+#include <float.h>
+#include "FMI_Environment.h"
+#include <math.h>
+
+
+#define NUMBER_OF_REALS 0
+#define NUMBER_OF_STRINGS 0
+#define NUMBER_OF_BOOLEANS 9
+#define NUMBER_OF_INTEGERS 0
+
+
+#define _out_driver_up 0
+#define _out_driver_up_stop 1
+#define _out_driver_down 2
+#define _out_driver_down_stop 3
+#define _out_passenger_up 4
+#define _out_passenger_up_stop 5
+#define _out_passenger_down 6
+#define _out_passenger_down_stop 7
+#define _out_object 8
+
+
+/*
+ * Helper function for relative error
+ */
+ double relativeError(double a, double b){
+	return fabs((a - b) / a);
+}
+
+/*
+ * Helper function for absolute error
+ */
+ double absoluteError(double a, double b){
+	return fabs(a - b);
+}
+
+/*
+ * is_close function for double comparison
+ */
+ int is_close(double a, double b, double REL_TOL, double ABS_TOL){
+	return ((absoluteError(a,b)<ABS_TOL) && (relativeError(a,b)<REL_TOL));
+}
+
+
+fmi2Status fmi2SetDebugLogging(fmi2Component fc, fmi2Boolean loggingOn, size_t nCategories, const fmi2String categories[])
+{
+    return fmi2OK;
+}
+
+fmi2Status fmi2SetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2String value[])
+{
+    return fmi2Error;
+}
+
+fmi2Status fmi2GetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2String value[])
+{
+    return fmi2Error;
+}
+
+fmi2Status fmi2SetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Real value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+		int i;
+	    for (i = 0; i < nvr; i++)
+		{
+	    	if(vr[i]>=5){
+	    		printf("Value reference: %d, cannot be set, it is a store element\n", vr[i]);
+	    	}else{
+	    		 printf("Value reference: %d\n", vr[i]);
+	    		 comp->r[vr[i]] = value[i];
+	    	}
+
+	        //setExposedReal(vr[i], value[i]);
+	        //comp->r[vr[i]] = value[i];
+	    }
+	    return fmi2OK;
+}
+
+fmi2Status fmi2GetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Real value[])
+{
+
+    FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+    for (i = 0; i < nvr; i++)
+	{
+        value[i] = comp->r[(vr[i])];
+    }
+    return fmi2OK;
+}
+
+fmi2Status fmi2SetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Boolean value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		comp->b[vr[i]] = value[i];
+	}
+    return fmi2OK;
+}
+
+fmi2Status fmi2GetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Boolean value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		value[i] = comp->b[vr[i]];
+	}
+    return fmi2OK;
+}
+
+fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2String fmuGUID, fmi2String fmuLocation, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+
+	//Declare data structure for fmu instance
+    FMUInstance* fi;
+	printf("%s in fmiInstantiate\n",instanceName);
+
+    //Perform checks on passed callback functions
+    if (loggingOn) {
+
+        if (!functions->logger);
+        //return NULL;
+	}
+    //Check for instanceName
+    if (!instanceName || strlen(instanceName)==0) {
+
+        // print (and/or log) instanceName is missing
+        //return NULL;
+    }
+    //Check passed GUID to defined model GUID
+    if (strcmp(fmuGUID, MODEL_GUID))
+	{
+        // print (and/or log) GUID doesn't match
+        //return NULL;
+    }
+
+    //Allocate fmu instance Memory
+    // TODO check if "canNotUseMemoryManagementFunctions == true/false". If false memory allocation not possible
+    fi = (FMUInstance *)functions->allocateMemory(1, sizeof(FMUInstance));
+    fi->functions = functions;
+    if (fi) {
+        // Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
+        fi->r = functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
+        fi->i = functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
+        fi->b = functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
+        fi->s = functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
+    } // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
+
+
+    fi->instanceName = functions->allocateMemory(1 + strlen(instanceName), sizeof(char));
+    fi->GUID = functions->allocateMemory(1 + strlen(fmuGUID), sizeof(char));
+
+    strcpy((char*)fi->instanceName, instanceName);
+    strcpy((char*)fi->GUID, fmuGUID);
+    fi->functions = functions;
+    fi->loggingOn = loggingOn;
+    fi->isVisible = visible;
+    fi->state = fmuInstantiated;
+    return fi;
+}
+
+fmi2Status fmi2SetupExperiment(fmi2Component fc, fmi2Boolean toleranceDefined, fmi2Real tolerance,
+                            fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) {
+
+
+    FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiSetupExperiment\n",fi->instanceName);
+	if (fi->state != fmuInstantiated)
+	{
+		printf("fmu: %s was not instatiated before calling fmiSetupExperiment\n", fi->instanceName);
+		return fmi2Error;
+	}
+	fi->currentTime = startTime;
+	fi->stopTimeDefined = stopTimeDefined;
+	fi->toleranceDefined = toleranceDefined;
+	if (stopTimeDefined)
+	{
+		fi->stopTime = stopTime;
+	}
+
+	if (toleranceDefined)
+	{
+		fi->tolerance = tolerance;
+	}
+	//TODO
+	//fi->stepSize = getStepSize();
+	fi->state = fmuExperimentSettedUp;
+    return fmi2OK;
+}
+
+fmi2Status fmi2EnterInitializationMode(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiEnterInitializationMode\n",fi->instanceName);
+	if (fi->state != fmuExperimentSettedUp)
+	{
+		printf("fmu: %s experiment was not set-up before calling fmiEnterInitializationMode\n", fi->instanceName);
+		return fmi2Error;
+	}
+
+    fi->state = fmuInitMode;
+    return fmi2OK;
+}
+
+fmi2Status fmi2ExitInitializationMode(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance*) fc;
+	fmi2Status initStatus = fmi2OK;
+	printf("%s in fmiExitInitializationMode\n",fi->instanceName);
+	if (fi->state != fmuInitMode)
+	{
+		printf("fmu: %s did not enter Initialization Mode before calling fmiExitInitializationMode\n", fi->instanceName);
+		return fmi2Error;
+	}
+	// TODO
+	//initStatus = calculateInitialUnknownValues();
+	//initialize();
+    fi->state = fmuInitialized;
+    return initStatus;
+}
+
+fmi2Status fmi2DoStep(fmi2Component fc , fmi2Real currentCommPoint, fmi2Real commStepSize, fmi2Boolean noPrevFMUState)
+{
+	FMUInstance* fi = (FMUInstance *)fc;
+	fmi2Status simStatus = fmi2OK;
+    printf("%s in fmiDoStep()\n",fi->instanceName);
+
+    if(currentCommPoint < 0.5){
+    	fi->b[_out_driver_up] = 0;
+    	fi->b[_out_driver_up_stop] = 0;
+		fi->b[_out_driver_down] = 0;
+		fi->b[_out_driver_down_stop] = 0;
+		fi->b[_out_passenger_up] = 0;
+		fi->b[_out_passenger_up_stop] = 0;
+		fi->b[_out_passenger_down] = 0;
+		fi->b[_out_passenger_down_stop] = 0;
+		fi->b[_out_object] = 0;
+    }else if(currentCommPoint < 1){
+    	fi->b[_out_driver_up] = 1;
+    	fi->b[_out_driver_up_stop] = 0;
+		fi->b[_out_driver_down] = 0;
+		fi->b[_out_driver_down_stop] = 0;
+		fi->b[_out_passenger_up] = 0;
+		fi->b[_out_passenger_up_stop] = 0;
+		fi->b[_out_passenger_down] = 0;
+		fi->b[_out_passenger_down_stop] = 0;
+		fi->b[_out_object] = 0;
+    }else if(currentCommPoint < 1.5){
+    	fi->b[_out_driver_up] = 1;
+    	fi->b[_out_driver_up_stop] = 0;
+		fi->b[_out_driver_down] = 0;
+		fi->b[_out_driver_down_stop] = 0;
+		fi->b[_out_passenger_up] = 0;
+		fi->b[_out_passenger_up_stop] = 0;
+		fi->b[_out_passenger_down] = 0;
+		fi->b[_out_passenger_down_stop] = 0;
+		fi->b[_out_object] = 1;
+    }else if(currentCommPoint < 1.7){
+    	fi->b[_out_driver_up] = 0;
+    	fi->b[_out_driver_up_stop] = 0;
+		fi->b[_out_driver_down] = 0;
+		fi->b[_out_driver_down_stop] = 0;
+		fi->b[_out_passenger_up] = 0;
+		fi->b[_out_passenger_up_stop] = 0;
+		fi->b[_out_passenger_down] = 0;
+		fi->b[_out_passenger_down_stop] = 0;
+		fi->b[_out_object] = 0;
+    }else if(currentCommPoint < 2.7){
+    	fi->b[_out_driver_up] = 0;
+    	fi->b[_out_driver_up_stop] = 0;
+		fi->b[_out_driver_down] = 0;
+		fi->b[_out_driver_down_stop] = 0;
+		fi->b[_out_passenger_up] = 0;
+		fi->b[_out_passenger_up_stop] = 0;
+		fi->b[_out_passenger_down] = 0;
+		fi->b[_out_passenger_down_stop] = 0;
+		fi->b[_out_object] = 0;
+    }else if(currentCommPoint < 3.1){
+    	fi->b[_out_driver_up] = 1;
+    	fi->b[_out_driver_up_stop] = 0;
+		fi->b[_out_driver_down] = 0;
+		fi->b[_out_driver_down_stop] = 0;
+		fi->b[_out_passenger_up] = 0;
+		fi->b[_out_passenger_up_stop] = 0;
+		fi->b[_out_passenger_down] = 1;
+		fi->b[_out_passenger_down_stop] = 0;
+		fi->b[_out_object] = 0;
+    }else if(currentCommPoint < 3.5){
+    	fi->b[_out_driver_up] = 0;
+    	fi->b[_out_driver_up_stop] = 1;
+		fi->b[_out_driver_down] = 0;
+		fi->b[_out_driver_down_stop] = 0;
+		fi->b[_out_passenger_up] = 0;
+		fi->b[_out_passenger_up_stop] = 0;
+		fi->b[_out_passenger_down] = 0;
+		fi->b[_out_passenger_down_stop] = 1;
+		fi->b[_out_object] = 0;
+    }
+
+	return simStatus;
+}
+
+fmi2Status fmi2Terminate(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance *)fc;
+	printf("%s in fmiTerminate\n",fi->instanceName);
+	// do check if fi may be terminated
+	fi->state = fmuTerminated;
+    return fmi2OK;
+}
+
+
+void fmi2FreeInstance(fmi2Component fc)
+{
+
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiFreeInstance\n",fi->instanceName);
+
+    if (fi) {
+
+        fi->functions->freeMemory(fi->r);
+        fi->functions->freeMemory(fi->i);
+        fi->functions->freeMemory(fi->b);
+        fi->functions->freeMemory(fi->s);// TODO has to be done with loop
+		fi->functions->freeMemory((void*)fi->instanceName);
+		fi->functions->freeMemory((void*)fi->GUID);
+		fi->functions->freeMemory((void*)fi);
+
+    }
+}
+
+//To be implemented
+
+const char* fmi2GetVersion() {
+	printf("Function fmiGetVersion not supported\n");
+    return NULL;
+}
+
+const char* fmi2GetTypesPlatform() {
+	printf("Function fmiGetTypesPlatform not supported\n");
+    return NULL;
+}
+
+fmi2Status fmi2Reset(fmi2Component fc)
+{
+	printf("Function fmiReset not supported\n");
+    return fmi2Error;
+}
+
+fmi2Status fmi2SetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Integer value[])
+{
+    printf("Function fmiSetInteger not supported\n");
+    return fmi2Error;
+}
+
+fmi2Status fmi2GetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[])
+{
+    printf("Function fmiGetInteger not supported\n");
+    return fmi2Error;
+}
+
+
+/*******OWN IMPLEMENTATION OF Get/Set FMU state*******/
+fmi2Status fmi2GetFMUstate (fmi2Component c, fmi2FMUstate* FMUstate) {
+    FMUInstance* orig = (FMUInstance*)c;
+    FMUInstance* fi = (FMUInstance *)FMUstate;
+    fi = orig->functions->allocateMemory(1, sizeof(FMUInstance));
+    *FMUstate = fi;
+    if (fi) {
+        // Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
+        fi->r = orig->functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
+        fi->i = orig->functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
+        fi->b = orig->functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
+        fi->s = orig->functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
+
+    } // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
+    fi->instanceName = orig->functions->allocateMemory(1 + strlen(orig->instanceName), sizeof(char));
+    fi->GUID = orig->functions->allocateMemory(1 + strlen(orig->GUID), sizeof(char));
+
+    strcpy((char *)fi->instanceName, (char *)orig->instanceName);
+    strcpy((char *)fi->GUID, (char *)orig->GUID);
+    fi->functions = orig->functions;
+    fi->loggingOn = orig->loggingOn;
+    fi->isVisible = orig->isVisible;
+    fi->state = orig->state;
+    fi->stepSize = orig->stepSize;
+    fi->startTime = orig->startTime;
+    fi->stopTime = orig->stopTime;
+	fi->currentTime = orig->currentTime;
+	//copy r
+	int i=0;
+	for (i=0; i< NUMBER_OF_REALS;i++){
+	    printf("Setting real: %i %f\n", i, orig->r[i]);
+        fi->r[i] = orig->r[i];
+        printf("Setted real: %i %f\n", i, fi->r[i]);
+	}
+	//copy s
+	for (i=0; i< NUMBER_OF_STRINGS;i++){
+        fi->s[i] = orig->s[i];
+	}
+	//copy i
+    for (i=0; i< NUMBER_OF_INTEGERS;i++){
+        fi->i[i] = orig->i[i];
+	}
+	//copy b
+	for (i=0; i< NUMBER_OF_BOOLEANS;i++){
+        fi->b[i] = orig->b[i];
+	}
+    return fmi2OK;
+}
+
+
+fmi2Status fmi2SetFMUstate (fmi2Component c, fmi2FMUstate FMUstate) {
+    FMUInstance* orig = (FMUInstance*)FMUstate;
+    FMUInstance* fi = (FMUInstance*)c;
+    //set time etc correct, name and GUID should still be ok ;-)
+    printf("setting time values from %f to %f\n", fi->currentTime, orig->currentTime);
+    fi->state = orig->state;
+    fi->stepSize = orig->stepSize;
+    fi->startTime = orig->startTime;
+    fi->stopTime = orig->stopTime;
+	fi->currentTime = orig->currentTime;
+	printf("setting real values\n");
+	//copy r
+	int i=0;
+	for (i=0; i< NUMBER_OF_REALS;i++){
+        fi->r[i] = orig->r[i];
+	}
+	printf("setting string values\n");
+	//copy s
+	for (i=0; i< NUMBER_OF_STRINGS;i++){
+
+        fi->s[i] = orig->s[i];
+	}
+	//copy i
+    for (i=0; i< NUMBER_OF_INTEGERS;i++){
+        fi->i[i] = orig->i[i];
+	}
+	//copy b
+	for (i=0; i< NUMBER_OF_BOOLEANS;i++){
+        fi->b[i] = orig->b[i];
+	}
+    return fmi2OK;
+
+
+}
+/****************************************************/
+
+fmi2Status fmi2FreeFMUstate(fmi2Component c, fmi2FMUstate* FMUstate) {
+    printf("Function fmiFreeFMUstate not supported\n");
+    return fmi2Error;
+}
+fmi2Status fmi2SerializedFMUstateSize(fmi2Component c, fmi2FMUstate FMUstate, size_t *size) {
+    printf("Function fmiSerializedFMUstateSize not supported\n");
+    return fmi2Error;
+}
+fmi2Status fmi2SerializeFMUstate (fmi2Component c, fmi2FMUstate FMUstate, fmi2Byte serializedState[], size_t size) {
+    printf("Function fmiSerializeFMUstate not supported\n");
+    return fmi2Error;
+}
+fmi2Status fmi2DeSerializeFMUstate (fmi2Component c, const fmi2Byte serializedState[], size_t size, fmi2FMUstate* FMUstate) {
+    printf("Function fmiDeSerializeFMUstate not supported\n");
+    return fmi2Error;
+}
+
+fmi2Status fmi2GetDirectionalDerivative(fmi2Component c, const fmi2ValueReference vUnknown_ref[], size_t nUnknown,
+                const fmi2ValueReference vKnown_ref[] , size_t nKnown, const fmi2Real dvKnown[], fmi2Real dvUnknown[]) {
+    printf("Function fmiGetDirectionalDerivative not supported\n");
+    return fmi2Error;
+}
+
+
+fmi2Status fmi2SetRealInputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
+                                     const fmi2Integer order[], const fmi2Real value[]) {
+    printf("Function fmiGetDirectionalDerivative not supported\n");
+    return fmi2Error;
+}
+
+fmi2Status fmi2GetRealOutputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
+                                      const fmi2Integer order[], fmi2Real value[]) {
+    printf("Function fmiGetDirectionalDerivative not supported\n");
+    return fmi2Error;
+}
+
+fmi2Status fmi2CancelStep(fmi2Component c) {
+    printf("Function fmiGetDirectionalDerivative not supported\n");
+    return fmi2Error;
+}
+
+fmi2Status fmi2GetStatus(fmi2Component c, const fmi2StatusKind s, fmi2Status *value) {
+    printf("Function fmiGetStatus not supported\n");
+    return fmi2Error;
+}
+
+fmi2Status fmi2GetRealStatus(fmi2Component c, const fmi2StatusKind s, fmi2Real *value) {
+    if(s == fmi2LastSuccessfulTime){
+        FMUInstance* comp = (FMUInstance*) c;
+        *value = comp->currentTime;
+        return fmi2OK;
+    }
+    printf("Function fmiGetRealStatus not supported\n");
+    return fmi2Error;
+}
+
+fmi2Status fmi2GetIntegerStatus(fmi2Component c, const fmi2StatusKind s, fmi2Integer *value) {
+    printf("Function fmiGetIntegerStatus not supported\n");
+    return fmi2Error;
+}
+
+fmi2Status fmi2GetBooleanStatus(fmi2Component c, const fmi2StatusKind s, fmi2Boolean *value) {
+    printf("Function fmiGetBooleanStatus not supported\n");
+    return fmi2Error;
+}
+
+fmi2Status fmi2GetStringStatus(fmi2Component c, const fmi2StatusKind s, fmi2String *value) {
+    printf("Function fmiGetStringStatus not supported\n");
+    return fmi2Error;
+}

+ 51 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/FMI_Environment.h

@@ -0,0 +1,51 @@
+/*
+ * PW_Controller.h
+ *
+ *  Created on: Jan 25, 2017
+ *      Author: Joachim
+ */
+
+#ifndef FMI_ENVIRONMENT_H_
+#define FMI_ENVIRONMENT_H_
+
+
+ double relativeError(double a, double b);
+ double absoluteError(double a, double b);
+ int is_close(double a, double b, double REL_TOL, double ABS_TOL);
+
+
+typedef enum {
+    fmuInstantiated = 0,
+    fmuInitMode  = 1,
+	fmuInitialized = 2,
+    fmuTerminated   = 3,
+    fmuError        = 4,
+    fmuExperimentSettedUp = 5
+} FMUState;
+
+
+
+typedef struct {
+	fmi2Real    *r;
+    fmi2Integer *i;
+    fmi2Boolean *b;
+    fmi2String  *s;
+    fmi2Boolean isVisible;
+    fmi2String instanceName;
+    fmi2String GUID;
+    const fmi2CallbackFunctions* functions;
+    fmi2Boolean loggingOn;
+    FMUState state;
+	fmi2Real stepSize;
+    fmi2Real startTime;
+    fmi2Real stopTime;
+	fmi2Real currentTime;
+    fmi2Boolean stopTimeDefined;
+    fmi2Real tolerance;
+    fmi2Boolean toleranceDefined;
+} FMUInstance; // At the moment, most of the variables not really used since multiple instances of an FMU are not supported at the moment (performance issues)
+
+
+
+
+#endif /* FMI_ENVIRONMENT_H_ */

+ 247 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/fmi2/fmi2FunctionTypes.h

@@ -0,0 +1,247 @@
+#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 (C) 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);
+#ifdef FMU_EXPERIMENTAL
+   typedef fmi2Status fmi2GetSpecificDerivativesTYPE       (fmi2Component, fmi2Real[], const fmi2ValueReference [], size_t);
+#endif
+
+   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 */

+ 339 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Environment/fmi2/fmi2Functions.h

@@ -0,0 +1,339 @@
+#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 (C) 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)
+#ifdef FMU_EXPERIMENTAL
+#define fmi2GetSpecificDerivatives        fmi2FullName(fmi2GetSpecificDerivatives)
+#endif
+#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;
+#ifdef FMU_EXPERIMENTAL
+   FMI2_Export fmi2GetSpecificDerivativesTYPE        fmi2GetSpecificDerivatives;
+#endif
+   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/fmu/cs/FMI_Environment/fmi2/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 (C) 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 */

File diff suppressed because it is too large
+ 124 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_SEL/.cproject


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_SEL/Debug/FMI_SEL.o


File diff suppressed because it is too large
+ 124 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_TD/.cproject


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_TD/Debug/FMI_SEL.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_TD/Debug/FMI_TD.o


File diff suppressed because it is too large
+ 134 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/.cproject


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/FMI_CM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/FMI_GM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/FMI_SEL.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/FMI_Window_sa.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/FMI_power_sa.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/libFMI_Window_sa.dll


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/Debug/sim_support.o


+ 398 - 221
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/FMI_Window_sa.c

@@ -1,13 +1,13 @@
 /* ---------------------------------------------------------------------------*
- * Sample implementation of an control support master FMU -
+ * Sample implementation of an generic master FMU -
  * ---------------------------------------------------------------------------*/
 /*
-Template for a sc FMU
-*/
+Template for a  FMU
+ */
 
-#define MODEL_IDENTIFIER CM
+#define MODEL_IDENTIFIER GM
 #define MODEL_GUID "{41f87101-edf2-4eef-90f3-42db56d4565f}"
-#define FMI2_FUNCTION_PREFIX FMI_WINDOW_SA
+#define FMI2_FUNCTION_PREFIX WINDOW_SA
 
 
 #include <stdio.h>
@@ -20,80 +20,126 @@ Template for a sc FMU
 #include "sim_support.h"
 
 
-#define NUMBER_OF_REALS 4
+#define MAX 100000
+
+#define NUMBER_OF_REALS 5
 #define NUMBER_OF_STRINGS 0
 #define NUMBER_OF_BOOLEANS 0
 #define NUMBER_OF_INTEGERS 0
+/*
+ * The input
+ */
 
+#define _out_tau 0
+#define _out_height 1
 
-#define _in_speed_motor 0
-#define _out_window_height 1
-#define _out_window_speed 2
-#define _out_window_torque 3
-
+#define _in_reaction_force 2
+#define _in_displacement 3
+#define _in_speed 4
 
- double relativeError(double a, double b){
+double relativeError(double a, double b){
 	return fabs((a - b) / a);
 }
 
 /*
  * Helper function for absolute error
  */
- double absoluteError(double a, double b){
+double absoluteError(double a, double b){
 	return fabs(a - b);
 }
 
 /*
  * is_close function for double comparison
  */
- int is_close(double a, double b, double REL_TOL, double ABS_TOL){
+int is_close(double a, double b, double REL_TOL, double ABS_TOL){
 	return ((absoluteError(a,b)<ABS_TOL) && (relativeError(a,b)<REL_TOL));
 }
 
 fmi2Status fmi2SetDebugLogging(fmi2Component fc, fmi2Boolean loggingOn, size_t nCategories, const fmi2String categories[])
 {
-    return fmi2OK;
+	return fmi2OK;
 }
 
 fmi2Status fmi2SetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2String value[])
 {
-    return fmi2Error;
+	FMUInstance*  comp = (FMUInstance *)fc;
+
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2Error;
 }
 
 fmi2Status fmi2GetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2String value[])
 {
-    return fmi2Error;
+	return fmi2Error;
 }
 
 fmi2Status fmi2SetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Real value[])
 {
 	FMUInstance* comp = (FMUInstance *)fc;
-		int i;
-	    for (i = 0; i < nvr; i++)
-		{
-	    	if(vr[i]>=5){
-	    		printf("Value reference: %d, cannot be set, it is a store element\n", vr[i]);
-	    	}else{
-	    		 printf("Value reference: %d\n", vr[i]);
-	    		 comp->r[vr[i]] = value[i];
-	    	}
-
-	        //setExposedReal(vr[i], value[i]);
-	        //comp->r[vr[i]] = value[i];
-	    }
-	    return fmi2OK;
+	int i;
+	int isset[NUMBER_OF_REALS];
+	memset(isset, 0, sizeof(int)*NUMBER_OF_REALS);
+
+	for (i = 0; i < nvr; i++)
+	{
+		comp->r[vr[i]] = value[i];
+		isset[i] = 1;
+	}
+	/*Generated: */
+	fmi2Boolean in_condition[_NR_OF_IN_CONDITIONS];
+	/*Condition checking:*/
+	// true
+	in_condition[0] = 1;
+
+	if(in_condition[0]){
+		if(isset[_in_reaction_force]){
+			comp->stored_windowsa_reaction_force = comp->r[_in_reaction_force];
+		}
+		if(isset[_in_speed]){
+			comp->stored_windowsa_speed = comp->r[_in_speed];
+		}
+		if(isset[_in_displacement]){
+			comp->stored_windowsa_displacement = comp->r[_in_displacement];
+		}
+		/* If mealy do update_in and recursive call */
+	}
+	//out_condition_executed := empty map
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2OK;
 }
 
 fmi2Status fmi2GetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Real value[])
 {
 
-    FMUInstance* comp = (FMUInstance *)fc;
-	int i;
-    for (i = 0; i < nvr; i++)
+	FMUInstance* comp = (FMUInstance *)fc;
+
+	int isEmpty = 1;
+	for (int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		if(comp->out_conditions_executed[i] !=0){
+			isEmpty = 0;
+			break;
+		}
+	}
+
+	/*Eval conditions:*/
+	if(1){
+		comp->out_conditions_executed[0] = 1;
+	}
+
+	if (isEmpty){
+		for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+			if(comp->out_conditions_executed[i]){
+				comp->r[_out_tau] = - comp->stored_window_reaction_torque;
+				comp->r[_out_height] = comp->stored_window_height * 100;
+			}
+		}
+	}
+	for (int i = 0; i < nvr; i++)
 	{
-        value[i] = comp->r[(vr[i])];
-    }
-    return fmi2OK;
+		value[i] = comp->r[(vr[i])];
+	}
+
+	return fmi2OK;
 }
 
 fmi2Status fmi2SetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Boolean value[])
@@ -104,7 +150,20 @@ fmi2Status fmi2SetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_
 	{
 		comp->b[vr[i]] = value[i];
 	}
-    return fmi2OK;
+	/*Generated: */
+		fmi2Boolean in_condition[_NR_OF_IN_CONDITIONS];
+		/*Condition checking:*/
+		// true
+		in_condition[0] = 1;
+
+		if(in_condition[0]){
+			/* If mealy do update_in and recursive call */
+		}
+		return fmi2OK;
+
+	//out_condition_executed := empty map
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2OK;
 }
 
 fmi2Status fmi2GetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Boolean value[])
@@ -115,69 +174,76 @@ fmi2Status fmi2GetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_
 	{
 		value[i] = comp->b[vr[i]];
 	}
-    return fmi2OK;
+	return fmi2OK;
 }
 
 fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2String fmuGUID, fmi2String fmuLocation, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
 {
 
 	//Declare data structure for fmu instance
-    FMUInstance* fi;
+	FMUInstance* fi;
 	printf("%s in fmiInstantiate\n",instanceName);
 
-    //Perform checks on passed callback functions
-    if (loggingOn) {
+	//Perform checks on passed callback functions
+	if (loggingOn) {
 
-        if (!functions->logger);
-        //return NULL;
+		if (!functions->logger);
+		//return NULL;
 	}
-    //Check for instanceName
-    if (!instanceName || strlen(instanceName)==0) {
+	//Check for instanceName
+	if (!instanceName || strlen(instanceName)==0) {
 
-        // print (and/or log) instanceName is missing
-        //return NULL;
-    }
-    //Check passed GUID to defined model GUID
-    if (strcmp(fmuGUID, MODEL_GUID))
+		// print (and/or log) instanceName is missing
+		//return NULL;
+	}
+	//Check passed GUID to defined model GUID
+	if (strcmp(fmuGUID, MODEL_GUID))
 	{
-        // print (and/or log) GUID doesn't match
-        //return NULL;
-    }
-
-    //Allocate fmu instance Memory
-    // TODO check if "canNotUseMemoryManagementFunctions == true/false". If false memory allocation not possible
-    fi = (FMUInstance *)functions->allocateMemory(1, sizeof(FMUInstance));
-    if (fi) {
-        // Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
-        fi->r = functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
-        fi->i = functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
-        fi->b = functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
-        fi->s = functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
-    } // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
-
-
-    fi->instanceName = functions->allocateMemory(1 + strlen(instanceName), sizeof(char));
-    fi->GUID = functions->allocateMemory(1 + strlen(fmuGUID), sizeof(char));
-
-    strcpy((char*)fi->instanceName, instanceName);
-    strcpy((char*)fi->GUID, fmuGUID);
-    fi->functions = functions;
-    fi->loggingOn = loggingOn;
-    fi->isVisible = visible;
-    fi->state = fmuInstantiated;
-    /* Load the inner FMUs:*/
-    loadDll("PW_Window.dll", &(fi->inner), "PW_Window_");
-    fi->fmuResourceLocation_inner = "PW_Window_";
-    /*Instantiate inner components*/
-    fi->c_inner = fi->inner.instantiate("inner", fmi2CoSimulation, "1", fi->fmuResourceLocation_inner, fi->functions, visible, 0);
-    return fi;
+		// print (and/or log) GUID doesn't match
+		//return NULL;
+	}
+
+	//Allocate fmu instance Memory
+	// TODO check if "canNotUseMemoryManagementFunctions == true/false". If false memory allocation not possible
+	fi = (FMUInstance *)functions->allocateMemory(1, sizeof(FMUInstance));
+	if (fi) {
+		// Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
+		fi->r = functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
+		fi->i = functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
+		fi->b = functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
+		fi->s = functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
+	} // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
+
+
+	fi->instanceName = functions->allocateMemory(1 + strlen(instanceName), sizeof(char));
+	fi->GUID = functions->allocateMemory(1 + strlen(fmuGUID), sizeof(char));
+
+	strcpy((char*)fi->instanceName, instanceName);
+	strcpy((char*)fi->GUID, fmuGUID);
+	fi->functions = functions;
+	fi->loggingOn = loggingOn;
+	fi->isVisible = visible;
+	fi->state = fmuInstantiated;
+	/* Load the inner FMUs:*/
+
+	loadDll("Window.dll", &(fi->fmu[0]), "");
+	fi->fmuResourceLocation[0] = "Window";
+
+	/*Instantiate inner components*/
+	for (int i=0; i<1; i++){
+		fi->c_fmu[i] = fi->fmu[i].instantiate("Window", fmi2CoSimulation, "{bead1740-5500-42db-88d5-eb3872b63305}", fi->fmuResourceLocation[i] , fi->functions, visible, 0);
+	}
+
+
+
+	return fi;
 }
 
 fmi2Status fmi2SetupExperiment(fmi2Component fc, fmi2Boolean toleranceDefined, fmi2Real tolerance,
-                            fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) {
+		fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) {
 
 
-    FMUInstance* fi = (FMUInstance*) fc;
+	FMUInstance* fi = (FMUInstance*) fc;
 	printf("%s in fmiSetupExperiment\n",fi->instanceName);
 	if (fi->state != fmuInstantiated)
 	{
@@ -191,21 +257,25 @@ fmi2Status fmi2SetupExperiment(fmi2Component fc, fmi2Boolean toleranceDefined, f
 	{
 		fi->stopTime = stopTime;
 	}
-	if (toleranceDefined)
-	{
-		fi->tolerance = tolerance;
-	}
-
 	/*
 	 * setup inner
 	 */
 	fmi2Status fmi2Flag = fmi2OK;
 	fi->state = fmuExperimentSettedUp;
-	fmi2Flag = fi->inner.setupExperiment(fi->c_inner, toleranceDefined, tolerance, startTime, fmi2True, stopTime);
-	    if (fmi2Flag == fmi2Error){
-	    	fi->state = fmuError;
-	    }
-    return fmi2Flag;
+	for(int i=0; i<1; i++){
+		fmi2Flag = fi->fmu[i].setupExperiment(fi->c_fmu[i], toleranceDefined, tolerance, startTime, fmi2True, stopTime);
+		if (fmi2Flag == fmi2Error){
+			fi->state = fmuError;
+		}
+	}
+
+	 fi->stored_windowsa_reaction_force=0;
+	 fi->stored_windowsa_displacement=0;
+	 fi->stored_windowsa_speed=0;
+	 fi->stored_window_reaction_torque=0;
+	 fi->stored_window_height=0;
+
+	return fmi2Flag;
 }
 
 fmi2Status fmi2EnterInitializationMode(fmi2Component fc)
@@ -217,13 +287,15 @@ fmi2Status fmi2EnterInitializationMode(fmi2Component fc)
 		printf("fmu: %s experiment was not set-up before calling fmiEnterInitializationMode\n", fi->instanceName);
 		return fmi2Error;
 	}
-    fi->state = fmuInitMode;
-    fmi2Status fmi2Flag = fmi2OK;
-    fmi2Flag = fi->inner.enterInitializationMode(fi->c_inner);
-    if (fmi2Flag == fmi2Error){
-        return fi->state = fmuError;
-    }
-    return fmi2Flag;
+	fi->state = fmuInitMode;
+	fmi2Status fmi2Flag = fmi2OK;
+	for(int i=0; i<1; i++){
+		fmi2Flag = fi->fmu[i].enterInitializationMode(fi->c_fmu[i]);
+		if (fmi2Flag == fmi2Error){
+			return fi->state = fmuError;
+		}
+	}
+	return fmi2Flag;
 }
 
 fmi2Status fmi2ExitInitializationMode(fmi2Component fc)
@@ -238,28 +310,68 @@ fmi2Status fmi2ExitInitializationMode(fmi2Component fc)
 	// TODO
 	//initStatus = calculateInitialUnknownValues();
 	//initialize();
-    fi->state = fmuInitialized;
-    fmi2Status fmi2Flag = fmi2OK;
-    fmi2Flag = fi->inner.exitInitializationMode(fi->c_inner);
-    if (fmi2Flag == fmi2Error){
-           return fi->state = fmuError;
-    }
-    return fmi2Flag;
+	fi->state = fmuInitialized;
+	fmi2Status fmi2Flag = fmi2OK;
+	for(int i=0; i<1;i++){
+		fmi2Flag = fi->fmu[i].exitInitializationMode(fi->c_fmu[i]);
+		if (fmi2Flag == fmi2Error){
+			return fi->state = fmuError;
+		}
+	}
+	return fmi2Flag;
+}
+
+static fmi2Status DoInnerStep(fmi2Component fc, int index, fmi2Real currentCommPoint, fmi2Real commStepSize){
+	fmi2Status status = fmi2OK;
+	FMUInstance* fi = (FMUInstance *)fc;
+
+	fmi2Real dt =   currentCommPoint - fi->time_last_fmu[index];
+	fmi2Real h = commStepSize + dt;
+	if (1){
+		fmi2ValueReference vr_toWindow[3] = {1,2,4};
+		fmi2Real values[3];
+		values[0] = fi->stored_windowsa_reaction_force;
+		values[1] = fi->stored_windowsa_speed;
+		values[2] = fi->stored_windowsa_displacement;
+		fi->fmu[index].setReal(fi->c_fmu[index],vr_toWindow, 3, &values[0]);
+	}
+
+	status = fi->fmu[index].doStep(fi->c_fmu[index],fi->time_last_fmu[index],h,fmi2True);
+
+	if (1){
+		fmi2ValueReference vr_fromWindow[2] = {3,6};
+		fmi2Real out_values[2];
+		fi->fmu[index].getReal(fi->c_fmu[index],vr_fromWindow, 3, &out_values[0]);
+		fi->stored_window_reaction_torque = out_values[0];
+		fi->stored_window_height = out_values[1];
+
+	}
+	return status;
 }
 
 fmi2Status fmi2DoStep(fmi2Component fc , fmi2Real currentCommPoint, fmi2Real commStepSize, fmi2Boolean noPrevFMUState)
 {
-
 	FMUInstance* fi = (FMUInstance *)fc;
 	fmi2Status simStatus = fmi2OK;
-    printf("%s in fmiDoStep()\n",fi->instanceName);
-    fmi2ValueReference to_inner[1]={5};
-    fmi2ValueReference from_inner[3] = {7,9,10};
-    fi->inner.setReal(fi->c_inner,to_inner,1,&(fi->r[_in_speed_motor]));
-    fi->inner.doStep(fi->c_inner, currentCommPoint, commStepSize, noPrevFMUState);
-    fi->inner.getReal(fi->c_inner, from_inner, 3, &(fi->r[_out_window_height]));
-    /* SA */
-    fi->r[_out_window_torque] = -(fi->r[_out_window_torque]);
+	printf("%s in fmiDoStep(), ct:%f, h:%f\n",fi->instanceName,currentCommPoint,commStepSize);
+	memset(fi->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+
+
+	/*
+	Calculate the elapsed time since the last transition
+	*/
+	fmi2Real e = MAX;
+	fmi2Real elapsed_fmu[_NR_OF_FMUS];
+	for (int i=0; i<_NR_OF_FMUS; i++){
+		elapsed_fmu[i] = currentCommPoint - fi->time_last_fmu[i];
+		e = (elapsed_fmu[i]<e)? elapsed_fmu[i]:e;
+	}
+
+	if(1){
+		simStatus= DoInnerStep(fc,0,currentCommPoint,commStepSize);
+	}
+
+	memset(fi->in_condition_executed, 0, sizeof(fmi2Boolean)*_NR_OF_IN_CONDITIONS);
 	return simStatus;
 }
 
@@ -268,9 +380,12 @@ fmi2Status fmi2Terminate(fmi2Component fc)
 	FMUInstance* fi = (FMUInstance *)fc;
 	printf("%s in fmiTerminate\n",fi->instanceName);
 	// do check if fi may be terminated
-	fi->inner.terminate(fi->c_inner);
+	for (int i=0;i<1;i++){
+		fi->fmu[i].terminate(fi->c_fmu[i]);
+	}
+
 	fi->state = fmuTerminated;
-    return fmi2OK;
+	return fmi2OK;
 }
 
 
@@ -279,212 +394,274 @@ void fmi2FreeInstance(fmi2Component fc)
 
 	FMUInstance* fi = (FMUInstance*) fc;
 	printf("%s in fmiFreeInstance\n",fi->instanceName);
+	for(int i=0;i<1;i++){
+		fi->fmu[i].freeInstance(fi->c_fmu[i]);
+	}
 
-    if (fi) {
-        fi->functions->freeMemory(fi->r);
-        fi->functions->freeMemory(fi->i);
-        fi->functions->freeMemory(fi->b);
-        fi->functions->freeMemory(fi->s);// TODO has to be done with loop
+	if (fi) {
+		fi->functions->freeMemory(fi->r);
+		fi->functions->freeMemory(fi->i);
+		fi->functions->freeMemory(fi->b);
+		fi->functions->freeMemory(fi->s);// TODO has to be done with loop
 		fi->functions->freeMemory((void*)fi->instanceName);
 		fi->functions->freeMemory((void*)fi->GUID);
 		fi->functions->freeMemory((void*)fi);
 
-    }
+	}
 }
 
 //To be implemented
 
 const char* fmi2GetVersion() {
 	printf("Function fmiGetVersion not supported\n");
-    return NULL;
+	return NULL;
 }
 
 const char* fmi2GetTypesPlatform() {
 	printf("Function fmiGetTypesPlatform not supported\n");
-    return NULL;
+	return NULL;
 }
 
 fmi2Status fmi2Reset(fmi2Component fc)
 {
 	printf("Function fmiReset not supported\n");
-    return fmi2Error;
+	return fmi2Error;
 }
 
 fmi2Status fmi2SetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Integer value[])
 {
-    printf("Function fmiSetInteger not supported\n");
-    return fmi2Error;
+	FMUInstance * comp = (FMUInstance*) fc;
+	printf("Function fmiSetInteger not supported\n");
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2Error;
 }
 
 fmi2Status fmi2GetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[])
 {
-    printf("Function fmiGetInteger not supported\n");
-    return fmi2Error;
+	printf("Function fmiGetInteger not supported\n");
+	return fmi2Error;
 }
 
 
 /*******OWN IMPLEMENTATION OF Get/Set FMU state*******/
 fmi2Status fmi2GetFMUstate (fmi2Component c, fmi2FMUstate* FMUstate) {
-    FMUInstance* orig = (FMUInstance*)c;
-    FMUInstance* fi = (FMUInstance *)FMUstate;
-    fi = orig->functions->allocateMemory(1, sizeof(FMUInstance));
-    *FMUstate = fi;
-    if (fi) {
-        // Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
-        fi->r = orig->functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
-        fi->i = orig->functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
-        fi->b = orig->functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
-        fi->s = orig->functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
-
-    } // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
-    fi->instanceName = orig->functions->allocateMemory(1 + strlen(orig->instanceName), sizeof(char));
-    fi->GUID = orig->functions->allocateMemory(1 + strlen(orig->GUID), sizeof(char));
-
-    strcpy((char *)fi->instanceName, (char *)orig->instanceName);
-    strcpy((char *)fi->GUID, (char *)orig->GUID);
-    fi->functions = orig->functions;
-    fi->loggingOn = orig->loggingOn;
-    fi->isVisible = orig->isVisible;
-    fi->state = orig->state;
-    fi->stepSize = orig->stepSize;
-    fi->startTime = orig->startTime;
-    fi->stopTime = orig->stopTime;
+	FMUInstance* orig = (FMUInstance*)c;
+	FMUInstance* fi = (FMUInstance *)FMUstate;
+	*FMUstate = fi;
+	fi = orig->functions->allocateMemory(1, sizeof(FMUInstance));
+	*FMUstate = fi;
+	fi->functions = orig->functions;
+
+	if (fi) {
+		// Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
+		fi->r = fi->functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
+		fi->i = fi->functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
+		fi->b = fi->functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
+		fi->s = fi->functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
+
+	} // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
+	fi->instanceName = orig->functions->allocateMemory(1 + strlen(orig->instanceName), sizeof(char));
+	fi->GUID = orig->functions->allocateMemory(1 + strlen(orig->GUID), sizeof(char));
+
+	strcpy((char *)fi->instanceName, (char *)orig->instanceName);
+	strcpy((char *)fi->GUID, (char *)orig->GUID);
+	fi->functions = orig->functions;
+	fi->loggingOn = orig->loggingOn;
+	fi->isVisible = orig->isVisible;
+	fi->state = orig->state;
+	fi->startTime = orig->startTime;
+	fi->stopTime = orig->stopTime;
 	fi->currentTime = orig->currentTime;
-	fi->inner = orig->inner;
-	orig->inner.getFMUstate(orig->c_inner,fi->c_inner);
-	fi->fmuResourceLocation_inner = fi->functions->allocateMemory(1+strlen(orig->fmuResourceLocation_inner), sizeof(char));
-	strcpy((char *)fi->fmuResourceLocation_inner,(char *)orig->fmuResourceLocation_inner);
+	/* TODO: Store all the rest here.*/
+	fi->fmu[0] = orig->fmu[0];
+	fi->c_fmu[0] = orig->c_fmu[0];
+	for(int i=0; i<_NR_OF_IN_CONDITIONS;i++){
+		fi->in_condition_executed[i] = orig->in_condition_executed[i];
+	}
+	for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		fi->out_conditions_executed[i] = orig->out_conditions_executed[i];
+	}
+	for(int i=0;i<_NR_OF_FMUS;i++){
+		fi->time_last_fmu[i] = orig->time_last_fmu[i];
+	}
+
+	/* Generated */
+	fi->stored_windowsa_reaction_force=orig->stored_windowsa_reaction_force;
+	fi->stored_windowsa_displacement=orig->stored_windowsa_displacement;
+	fi->stored_windowsa_speed=orig->stored_windowsa_speed;
+	fi->stored_window_reaction_torque=orig->stored_window_reaction_torque;
+	fi->stored_window_height=orig->stored_window_height;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+	/*
+	 * This is a hierarchical call. First let the lower FMUs do their state saving
+	 * We will store the saved fmu state in the fi->c_order[i]
+	 */
+	for(int i=0;i<1;i++){
+		fi->fmu[i]=orig->fmu[i];
+		orig->fmu[i].getFMUstate(orig->c_fmu[i],fi->c_fmu[i]);
+		fi->fmuResourceLocation[i] = fi->functions->allocateMemory(1+strlen(orig->fmuResourceLocation[i]), sizeof(char));
+		strcpy((char *)fi->fmuResourceLocation[i],(char *)orig->fmuResourceLocation[i]);
+		/*make shallow copies of the stored fmus*/
+	}
 	//copy r
 	int i=0;
 	for (i=0; i< NUMBER_OF_REALS;i++){
-	    printf("Setting real: %i %f\n", i, orig->r[i]);
-        fi->r[i] = orig->r[i];
-        printf("Setted real: %i %f\n", i, fi->r[i]);
+		printf("Setting real: %i %f\n", i, orig->r[i]);
+		fi->r[i] = orig->r[i];
+		printf("Setted real: %i %f\n", i, fi->r[i]);
 	}
 	//copy s
 	for (i=0; i< NUMBER_OF_STRINGS;i++){
-        fi->s[i] = orig->s[i];
+		//fi->s[i] = orig->s[i]; // why are this not deep copies?
+		fi->s[i] = fi->functions->allocateMemory(1+strlen(orig->s[i]),sizeof(char));
+		strcpy((char *)fi->s[i],(char *)orig->s[i]);
 	}
 	//copy i
-    for (i=0; i< NUMBER_OF_INTEGERS;i++){
-        fi->i[i] = orig->i[i];
+	for (i=0; i< NUMBER_OF_INTEGERS;i++){
+		fi->i[i] = orig->i[i];
 	}
 	//copy b
 	for (i=0; i< NUMBER_OF_BOOLEANS;i++){
-        fi->b[i] = orig->b[i];
+		fi->b[i] = orig->b[i];
 	}
-    return fmi2OK;
+	return fmi2OK;
 }
 
-
 fmi2Status fmi2SetFMUstate (fmi2Component c, fmi2FMUstate FMUstate) {
-    FMUInstance* orig = (FMUInstance*)FMUstate;
-    FMUInstance* fi = (FMUInstance*)c;
-
-    fi->inner.setFMUstate(fi->c_inner,orig->c_inner);
-    fi->fmuResourceLocation_inner = orig->functions->allocateMemory(1+strlen(orig->fmuResourceLocation_inner), sizeof(char));
-    strcpy((char *)fi->fmuResourceLocation_inner,(char *)orig->fmuResourceLocation_inner);
-    //set time etc correct, name and GUID should still be ok ;-)
-    printf("setting time values from %f to %f\n", fi->currentTime, orig->currentTime);
-    fi->state = orig->state;
-    fi->stepSize = orig->stepSize;
-    fi->startTime = orig->startTime;
-    fi->stopTime = orig->stopTime;
+	FMUInstance* orig = (FMUInstance*)FMUstate;
+	FMUInstance* fi = (FMUInstance*)c;
+	/*
+	 * First restore the hierarchical fmus.
+	 */
+	for(int i=0;i<1;i++){
+		fi->fmu[i].setFMUstate(fi->c_fmu[i],orig->c_fmu[i]);
+		fi->fmuResourceLocation[i] = orig->functions->allocateMemory(1+strlen(orig->fmuResourceLocation[i]), sizeof(char));
+		strcpy((char *)fi->fmuResourceLocation[i],(char *)orig->fmuResourceLocation[i]);
+	}
+
+	//set time etc correct, name and GUID should still be ok ;-)
+	printf("setting time values from %f to %f\n", fi->currentTime, orig->currentTime);
+	fi->state = orig->state;
+	fi->startTime = orig->startTime;
+	fi->stopTime = orig->stopTime;
 	fi->currentTime = orig->currentTime;
 
+	fi->fmu[0] = orig->fmu[0];
+	fi->c_fmu[0] = orig->c_fmu[0];
+	for(int i=0; i<_NR_OF_IN_CONDITIONS;i++){
+		fi->in_condition_executed[i] = orig->in_condition_executed[i];
+	}
+	for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		fi->out_conditions_executed[i] = orig->out_conditions_executed[i];
+	}
+	for(int i=0;i<_NR_OF_FMUS;i++){
+		fi->time_last_fmu[i] = orig->time_last_fmu[i];
+	}
+
+	/* Generated */
+	fi->stored_windowsa_reaction_force=orig->stored_windowsa_reaction_force;
+	fi->stored_windowsa_displacement=orig->stored_windowsa_displacement;
+	fi->stored_windowsa_speed=orig->stored_windowsa_speed;
+	fi->stored_window_reaction_torque=orig->stored_window_reaction_torque;
+	fi->stored_window_height=orig->stored_window_height;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+
+	fi->toleranceDefined = orig->toleranceDefined;
 	printf("setting real values\n");
 	//copy r
 	int i=0;
 	for (i=0; i< NUMBER_OF_REALS;i++){
-        fi->r[i] = orig->r[i];
+		fi->r[i] = orig->r[i];
 	}
 	printf("setting string values\n");
 	//copy s
 	for (i=0; i< NUMBER_OF_STRINGS;i++){
 
-        fi->s[i] = orig->s[i];
+		fi->s[i] = orig->s[i];
 	}
 	//copy i
-    for (i=0; i< NUMBER_OF_INTEGERS;i++){
-        fi->i[i] = orig->i[i];
+	for (i=0; i< NUMBER_OF_INTEGERS;i++){
+		fi->i[i] = orig->i[i];
 	}
 	//copy b
 	for (i=0; i< NUMBER_OF_BOOLEANS;i++){
-        fi->b[i] = orig->b[i];
+		fi->b[i] = orig->b[i];
 	}
-    return fmi2OK;
+	return fmi2OK;
 
 
 }
 /****************************************************/
 
 fmi2Status fmi2FreeFMUstate(fmi2Component c, fmi2FMUstate* FMUstate) {
-    printf("Function fmiFreeFMUstate not supported\n");
-    return fmi2Error;
+	printf("Function fmiFreeFMUstate not supported\n");
+	return fmi2Error;
 }
 fmi2Status fmi2SerializedFMUstateSize(fmi2Component c, fmi2FMUstate FMUstate, size_t *size) {
-    printf("Function fmiSerializedFMUstateSize not supported\n");
-    return fmi2Error;
+	printf("Function fmiSerializedFMUstateSize not supported\n");
+	return fmi2Error;
 }
 fmi2Status fmi2SerializeFMUstate (fmi2Component c, fmi2FMUstate FMUstate, fmi2Byte serializedState[], size_t size) {
-    printf("Function fmiSerializeFMUstate not supported\n");
-    return fmi2Error;
+	printf("Function fmiSerializeFMUstate not supported\n");
+	return fmi2Error;
 }
 fmi2Status fmi2DeSerializeFMUstate (fmi2Component c, const fmi2Byte serializedState[], size_t size, fmi2FMUstate* FMUstate) {
-    printf("Function fmiDeSerializeFMUstate not supported\n");
-    return fmi2Error;
+	printf("Function fmiDeSerializeFMUstate not supported\n");
+	return fmi2Error;
 }
 
 fmi2Status fmi2GetDirectionalDerivative(fmi2Component c, const fmi2ValueReference vUnknown_ref[], size_t nUnknown,
-                const fmi2ValueReference vKnown_ref[] , size_t nKnown, const fmi2Real dvKnown[], fmi2Real dvUnknown[]) {
-    printf("Function fmiGetDirectionalDerivative not supported\n");
-    return fmi2Error;
+		const fmi2ValueReference vKnown_ref[] , size_t nKnown, const fmi2Real dvKnown[], fmi2Real dvUnknown[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
 }
 
 
 fmi2Status fmi2SetRealInputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
-                                     const fmi2Integer order[], const fmi2Real value[]) {
-    printf("Function fmiGetDirectionalDerivative not supported\n");
-    return fmi2Error;
+		const fmi2Integer order[], const fmi2Real value[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
 }
 
 fmi2Status fmi2GetRealOutputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
-                                      const fmi2Integer order[], fmi2Real value[]) {
-    printf("Function fmiGetDirectionalDerivative not supported\n");
-    return fmi2Error;
+		const fmi2Integer order[], fmi2Real value[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
 }
 
 fmi2Status fmi2CancelStep(fmi2Component c) {
-    printf("Function fmiGetDirectionalDerivative not supported\n");
-    return fmi2Error;
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
 }
 
 fmi2Status fmi2GetStatus(fmi2Component c, const fmi2StatusKind s, fmi2Status *value) {
-    printf("Function fmiGetStatus not supported\n");
-    return fmi2Error;
+	printf("Function fmiGetStatus not supported\n");
+	return fmi2Error;
 }
 
 fmi2Status fmi2GetRealStatus(fmi2Component c, const fmi2StatusKind s, fmi2Real *value) {
-    if(s == fmi2LastSuccessfulTime){
-        FMUInstance* comp = (FMUInstance*) c;
-        *value = comp->currentTime;
-        return fmi2OK;
-    }
-    printf("Function fmiGetRealStatus not supported\n");
-    return fmi2Error;
+	if(s == fmi2LastSuccessfulTime){
+		FMUInstance* comp = (FMUInstance*) c;
+		*value = comp->currentTime;
+		return fmi2OK;
+	}
+	printf("Function fmiGetRealStatus not supported\n");
+	return fmi2Error;
 }
 
 fmi2Status fmi2GetIntegerStatus(fmi2Component c, const fmi2StatusKind s, fmi2Integer *value) {
-    printf("Function fmiGetIntegerStatus not supported\n");
-    return fmi2Error;
+	printf("Function fmiGetIntegerStatus not supported\n");
+	return fmi2Error;
 }
 
 fmi2Status fmi2GetBooleanStatus(fmi2Component c, const fmi2StatusKind s, fmi2Boolean *value) {
-    printf("Function fmiGetBooleanStatus not supported\n");
-    return fmi2Error;
+	printf("Function fmiGetBooleanStatus not supported\n");
+	return fmi2Error;
 }
 
 fmi2Status fmi2GetStringStatus(fmi2Component c, const fmi2StatusKind s, fmi2String *value) {
-    printf("Function fmiGetStringStatus not supported\n");
-    return fmi2Error;
+	printf("Function fmiGetStringStatus not supported\n");
+	return fmi2Error;
 }

+ 17 - 6
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/FMI_Window_sa.h

@@ -19,7 +19,9 @@ typedef enum {
     fmuExperimentSettedUp = 5
 } FMUState;
 
-
+#define _NR_OF_FMUS 1
+#define _NR_OF_IN_CONDITIONS 1
+#define _NR_OF_OUT_CONDITIONS 1
 
 typedef struct {
 	fmi2Real    *r;
@@ -32,16 +34,25 @@ typedef struct {
     const fmi2CallbackFunctions* functions;
     fmi2Boolean loggingOn;
     FMUState state;
-	fmi2Real stepSize;
     fmi2Real startTime;
     fmi2Real stopTime;
 	fmi2Real currentTime;
     fmi2Boolean stopTimeDefined;
-    fmi2Real tolerance;
     fmi2Boolean toleranceDefined;
-    FMU inner;
-    char *fmuResourceLocation_inner;
-    fmi2Component c_inner;
+    /* for generic algo*/
+    FMU fmu[_NR_OF_FMUS];
+    char *fmuResourceLocation[_NR_OF_FMUS];
+    fmi2Component c_fmu[_NR_OF_FMUS];
+    fmi2Boolean in_condition_executed[_NR_OF_IN_CONDITIONS];
+    fmi2Boolean out_conditions_executed[_NR_OF_OUT_CONDITIONS];
+    fmi2Real time_last_fmu[_NR_OF_FMUS];
+    /* Generated */
+    fmi2Real stored_windowsa_reaction_force;
+    fmi2Real stored_windowsa_displacement;
+    fmi2Real stored_windowsa_speed;
+    fmi2Real stored_window_reaction_torque;
+    fmi2Real stored_window_height;
+
 } FMUInstance; // At the moment, most of the variables not really used since multiple instances of an FMU are not supported at the moment (performance issues)
 
 

+ 3 - 2
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_Window_sa/sim_support.c

@@ -24,6 +24,7 @@
 #include "sim_support.h"
 
 #define FMI_COSIMULATION
+extern FMU fmu;
 
 
 //int unzip(const char *zipPath, const char *outPath) {
@@ -125,7 +126,7 @@ static void *getAdr(int *success, void *dllHandle, const char *functionName, con
 // Load the given dll and set function pointers in fmu
 // Return 0 to indicate failure
 int loadDll(const char* dllPath, FMU *fmu, const char* preamble) {
-    int s = 1;
+    int x = 1, s = 1;
     //HMODULE h = LoadLibrary(dllPath);
     void *h = dlopen(dllPath, RTLD_LAZY);
     printf("%s", dlerror());
@@ -481,7 +482,7 @@ static void replaceRefsInMessage(const char* msg, char* buffer, int nBuffer, FMU
                 c = msg[i];
 
             } else {
-                //char type = msg[i + 1]; // one of ribs
+                char type = msg[i + 1]; // one of ribs
                 fmi2ValueReference vr;
                 int nvr = sscanf(msg + i + 2, "%u", &vr);
                 if (nvr == 1) {

File diff suppressed because it is too large
+ 125 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_control_master/.cproject


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_control_master/Debug/FMI_CM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_control_master/Debug/FMI_SEL.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_control_master/Debug/sim_support.o


File diff suppressed because it is too large
+ 134 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/.cproject


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/Debug/FMI_CM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/Debug/FMI_GM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/Debug/FMI_SEL.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/Debug/libFMI_controller_sa.dll


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/Debug/sim_support.o


+ 719 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/FMI_GM.c

@@ -0,0 +1,719 @@
+/* ---------------------------------------------------------------------------*
+ * Sample implementation of an generic master FMU -
+ * ---------------------------------------------------------------------------*/
+/*
+Template for a  FMU
+ */
+
+#define MODEL_IDENTIFIER GM
+#define MODEL_GUID "{41f87101-edf2-4eef-90f3-42db56d4565f}"
+#define FMI2_FUNCTION_PREFIX PW_CONTROLLER_SA
+
+#define MAX 10000
+
+#include <stdio.h>
+#include "string.h"
+#include "fmi2Functions.h"
+#include <float.h>
+#include "FMI_GM.h"
+#include <math.h>
+#include "fmi2.h"
+#include "sim_support.h"
+
+
+
+#define NUMBER_OF_REALS 1
+#define NUMBER_OF_STRINGS 0
+#define NUMBER_OF_BOOLEANS 11
+#define NUMBER_OF_INTEGERS 0
+/*
+ * The input
+ */
+
+#define _in_armature_current 0
+
+
+#define _in_driver_up 0
+#define _in_driver_up_stop 1
+#define _in_driver_down 2
+#define _in_driver_down_stop 3
+#define _in_passenger_up 4
+#define _in_passenger_up_stop 5
+#define _in_passenger_down 6
+#define _in_passenger_down_stop 7
+
+
+/*
+ * The output:
+ */
+
+#define _out_u 9
+#define _out_d 10
+
+
+double relativeError(double a, double b){
+	return fabs((a - b) / a);
+}
+
+/*
+ * Helper function for absolute error
+ */
+double absoluteError(double a, double b){
+	return fabs(a - b);
+}
+
+/*
+ * is_close function for double comparison
+ */
+int is_close(double a, double b, double REL_TOL, double ABS_TOL){
+	return ((absoluteError(a,b)<ABS_TOL) && (relativeError(a,b)<REL_TOL));
+}
+
+fmi2Status fmi2SetDebugLogging(fmi2Component fc, fmi2Boolean loggingOn, size_t nCategories, const fmi2String categories[])
+{
+	return fmi2OK;
+}
+
+fmi2Status fmi2SetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2String value[])
+{
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2String value[])
+{
+	return fmi2Error;
+}
+
+fmi2Status fmi2SetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Real value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		if(vr[i]>=2){
+			printf("Value reference: %d, cannot be set, it is a store element\n", vr[i]);
+		}else{
+			printf("Value reference: %d\n", vr[i]);
+			comp->r[vr[i]] = value[i];
+		}
+	}
+
+	/*Generated: */
+	fmi2Boolean in_condition[_NR_OF_IN_CONDITIONS];
+	/*Condition checking:*/
+	// get_next_step ->
+	in_condition[0] = comp->get_next_step;
+	//true
+	in_condition[1] = 1;
+
+	if(in_condition[0]){
+		fmi2Component fmu0_temp;
+		comp->fmu[0].getFMUstate(comp->c_fmu[0],&fmu0_temp);
+		fmi2Status status;
+		status = comp->fmu[0].doStep(comp->c_fmu[0],comp->time_last_fmu[0], MAX, fmi2False);
+		if(status == fmi2Discard){
+			fmi2Real nextTime;
+			comp->fmu[0].getRealStatus(comp->c_fmu[0],fmi2LastSuccessfulTime, &nextTime);
+			comp->next_time_step = nextTime;
+		}else{
+			comp->next_time_step = -1;
+		}
+		comp->fmu[0].setFMUstate(comp->c_fmu[0],fmu0_temp);
+		comp->fmu[0].freeInstance(fmu0_temp);
+	}
+	if(in_condition[1]){
+		comp->stored_arm_current = comp->r[_in_armature_current];
+		/* If mealy do update_in and recursive call */
+	}
+
+	//out_condition_executed := empty map
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2OK;
+}
+
+fmi2Status fmi2GetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Real value[])
+{
+
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		value[i] = comp->r[(vr[i])];
+	}
+	return fmi2OK;
+}
+
+fmi2Status fmi2SetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Boolean value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		comp->b[vr[i]] = value[i];
+	}
+	return fmi2OK;
+}
+
+fmi2Status fmi2GetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Boolean value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+
+	int isEmpty = 1;
+	for (int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		if(comp->out_conditions_executed[i] !=0){
+			isEmpty = 0;
+			break;
+		}
+	}
+
+	/*Eval conditions:*/
+		if(1){
+			comp->out_conditions_executed[0] = 1;
+		}
+	/*Set correct values */
+	if (isEmpty){
+		for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+			if(comp->out_conditions_executed[i]){
+				comp->b[_out_u] = comp->stored_up;
+				comp->b[_out_d] = comp->stored_down;
+			}
+		}
+	}
+
+	/*
+	 Copy to given array */
+	for (i = 0; i < nvr; i++)
+	{
+		value[i] = comp->b[vr[i]];
+	}
+	return fmi2OK;
+}
+
+fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2String fmuGUID, fmi2String fmuLocation, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+
+	//Declare data structure for fmu instance
+	FMUInstance* fi;
+	printf("%s in fmiInstantiate\n",instanceName);
+
+	//Perform checks on passed callback functions
+	if (loggingOn) {
+
+		if (!functions->logger);
+		//return NULL;
+	}
+	//Check for instanceName
+	if (!instanceName || strlen(instanceName)==0) {
+
+		// print (and/or log) instanceName is missing
+		//return NULL;
+	}
+	//Check passed GUID to defined model GUID
+	if (strcmp(fmuGUID, MODEL_GUID))
+	{
+		// print (and/or log) GUID doesn't match
+		//return NULL;
+	}
+
+	//Allocate fmu instance Memory
+	// TODO check if "canNotUseMemoryManagementFunctions == true/false". If false memory allocation not possible
+	fi = (FMUInstance *)functions->allocateMemory(1, sizeof(FMUInstance));
+	if (fi) {
+		// Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
+		fi->r = functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
+		fi->i = functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
+		fi->b = functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
+		fi->s = functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
+	} // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
+
+
+	fi->instanceName = functions->allocateMemory(1 + strlen(instanceName), sizeof(char));
+	fi->GUID = functions->allocateMemory(1 + strlen(fmuGUID), sizeof(char));
+
+	strcpy((char*)fi->instanceName, instanceName);
+	strcpy((char*)fi->GUID, fmuGUID);
+	fi->functions = functions;
+	fi->loggingOn = loggingOn;
+	fi->isVisible = visible;
+	fi->state = fmuInstantiated;
+	/* Load the inner FMUs:*/
+
+	loadDll("libpw_controller.dll", &(fi->fmu[0]), "PW_Controller");
+	fi->fmuResourceLocation[0] = "libpw_controller";
+
+	/*Instantiate inner components*/
+	for (int i=0; i<1; i++){
+		fi->c_fmu[i] = fi->fmu[i].instantiate("inner", fmi2CoSimulation, "1", fi->fmuResourceLocation[i] , fi->functions, visible, 0);
+	}
+	return fi;
+}
+
+fmi2Status fmi2SetupExperiment(fmi2Component fc, fmi2Boolean toleranceDefined, fmi2Real tolerance,
+		fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) {
+
+
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiSetupExperiment\n",fi->instanceName);
+	if (fi->state != fmuInstantiated)
+	{
+		printf("fmu: %s was not instatiated before calling fmiSetupExperiment\n", fi->instanceName);
+		return fmi2Error;
+	}
+	fi->currentTime = startTime;
+	fi->stopTimeDefined = stopTimeDefined;
+	fi->toleranceDefined = toleranceDefined;
+	if (stopTimeDefined)
+	{
+		fi->stopTime = stopTime;
+	}
+	/*
+	 * setup inner
+	 */
+	fmi2Status fmi2Flag = fmi2OK;
+	fi->state = fmuExperimentSettedUp;
+	for(int i=0; i<1; i++){
+		fmi2Flag = fi->fmu[i].setupExperiment(fi->c_fmu[i], toleranceDefined, tolerance, startTime, fmi2True, stopTime);
+		if (fmi2Flag == fmi2Error){
+			fi->state = fmuError;
+		}
+	}
+	return fmi2Flag;
+}
+
+fmi2Status fmi2EnterInitializationMode(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiEnterInitializationMode\n",fi->instanceName);
+	if (fi->state != fmuExperimentSettedUp)
+	{
+		printf("fmu: %s experiment was not set-up before calling fmiEnterInitializationMode\n", fi->instanceName);
+		return fmi2Error;
+	}
+	fi->state = fmuInitMode;
+	fmi2Status fmi2Flag = fmi2OK;
+	for(int i=0; i<1; i++){
+		fmi2Flag = fi->fmu[i].enterInitializationMode(fi->c_fmu[i]);
+		if (fmi2Flag == fmi2Error){
+			return fi->state = fmuError;
+		}
+	}
+
+	fi->ABS_TOLERANCE = 1e-08;
+	fi->REL_TOLERANCE = 0.0001;
+	fi->CROSSING = 5;
+	fi->init_armature_current = fi->CROSSING;
+	fi->init_down = 0;
+	fi->init_up = 0;
+	fi->next_time_step = INFINITY;
+	fi->stored_arm_current = fi->CROSSING;
+	fi->aux_obj_detected = 0;
+	fi->get_next_step = 1;
+	fi->previous_arm_current = fi->CROSSING;
+
+	return fmi2Flag;
+}
+
+fmi2Status fmi2ExitInitializationMode(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiExitInitializationMode\n",fi->instanceName);
+	if (fi->state != fmuInitMode)
+	{
+		printf("fmu: %s did not enter Initialization Mode before calling fmiExitInitializationMode\n", fi->instanceName);
+		return fmi2Error;
+	}
+	// TODO
+	//initStatus = calculateInitialUnknownValues();
+	//initialize();
+	fi->state = fmuInitialized;
+	fmi2Status fmi2Flag = fmi2OK;
+	for(int i=0; i<1;i++){
+		fmi2Flag = fi->fmu[i].exitInitializationMode(fi->c_fmu[i]);
+		if (fmi2Flag == fmi2Error){
+			return fi->state = fmuError;
+		}
+	}
+	return fmi2Flag;
+}
+
+fmi2Status fmi2DoStep(fmi2Component fc , fmi2Real currentCommPoint, fmi2Real commStepSize, fmi2Boolean noPrevFMUState)
+{
+	FMUInstance* fi = (FMUInstance *)fc;
+	fmi2Status simStatus = fmi2OK;
+	memset(fi->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	fmi2Boolean b_temp_out[2];
+
+	printf("%s in fmiDoStep(), ct:%f, h:%f\n",fi->instanceName,currentCommPoint,commStepSize);
+	fi->aux_obj_detected = 0;
+	fi->step_size = commStepSize;
+	if(!(! is_close(fi->previous_arm_current, fi->CROSSING , fi->REL_TOLERANCE, fi->ABS_TOLERANCE) && fi->previous_arm_current < fi->CROSSING)
+			&& (!is_close(fi->stored_arm_current,fi->CROSSING,fi->REL_TOLERANCE,fi->ABS_TOLERANCE) && fi->stored_arm_current > fi->CROSSING)){
+		double negative_value = fi->previous_arm_current - fi->CROSSING;
+		double positive_value = fi->stored_arm_current - fi->CROSSING;
+		fi->step_size = (commStepSize * (-negative_value)) / (positive_value - negative_value);
+		simStatus = fmi2Discard;
+	}else{
+		if(!(! is_close(fi->previous_arm_current,fi->CROSSING,fi->REL_TOLERANCE,fi->ABS_TOLERANCE) && fi->previous_arm_current < fi->CROSSING)
+				&& is_close(fi->stored_arm_current,fi->CROSSING, fi->REL_TOLERANCE, fi->ABS_TOLERANCE)){
+			fi->aux_obj_detected = 1;
+		}
+		fi->step_size = commStepSize;
+	}
+
+	if(fi->aux_obj_detected || (fi->next_time_step != -1 && currentCommPoint > fi->next_time_step ) ||1){ //this is not correct. It also has to work when new values are given to all of the bools
+		fmi2ValueReference vr_in_star[8] = {1,2,3,4,5,6,7,8};
+		fi->fmu[0].setBoolean(fi->c_fmu[0], vr_in_star,8, &(fi->b[0]));
+		fmi2ValueReference vr_aux_obj_detected[1] = {0};
+		fi->fmu[0].setBoolean(fi->c_fmu[0], vr_aux_obj_detected,1, &(fi->aux_obj_detected));
+		simStatus = fi->fmu[0].doStep(fi->c_fmu[0], currentCommPoint, commStepSize, fmi2True);
+		fmi2ValueReference vr_out_star[2]={9,10};
+		fi->fmu[0].getBoolean(fi->c_fmu[0],vr_out_star,2,&b_temp_out[0]);
+		fi->get_next_step = 1;
+	}else{
+		fi->get_next_step = 0;
+	}
+	if(is_close(fi->step_size, commStepSize, fi->REL_TOLERANCE,fi->ABS_TOLERANCE)){
+		fi->previous_arm_current = fi->stored_arm_current;
+	}
+
+	if(simStatus == fmi2Discard){
+		fmi2Real theNextTime = currentCommPoint + fi->step_size;
+		for(int i=0; i<1; i++){
+			fmi2Real theFMUtime;
+			fi->fmu[i].getRealStatus(fi->c_fmu[i], fmi2LastSuccessfulTime, &theFMUtime);
+			if(theFMUtime<theNextTime){
+				theNextTime = theFMUtime;
+			}
+		}
+		fi->currentTime = theNextTime;
+	}else if(simStatus == fmi2OK){
+		fi->currentTime = currentCommPoint + commStepSize;
+		fi->time_last_fmu[0] = currentCommPoint + commStepSize;
+	}else{
+	}
+
+	/* do out functions*/
+	if(b_temp_out[0]){
+		fi->stored_up = 1;
+	}
+	if(!b_temp_out[0]){
+		fi->stored_up = 0;
+	}
+	if(b_temp_out[1]){
+		fi->stored_down = 1;
+	}
+	if(!b_temp_out[1]){
+		fi->stored_down = 0;
+	}
+
+	memset(fi->in_condition_executed, 0, sizeof(fmi2Boolean)*_NR_OF_IN_CONDITIONS);
+	return simStatus;
+}
+
+fmi2Status fmi2Terminate(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance *)fc;
+	printf("%s in fmiTerminate\n",fi->instanceName);
+	// do check if fi may be terminated
+	for (int i=0;i<1;i++){
+		fi->fmu[i].terminate(fi->c_fmu[i]);
+	}
+
+	fi->state = fmuTerminated;
+	return fmi2OK;
+}
+
+
+void fmi2FreeInstance(fmi2Component fc)
+{
+
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiFreeInstance\n",fi->instanceName);
+	for(int i=0;i<1;i++){
+		fi->fmu[i].freeInstance(fi->c_fmu[i]);
+	}
+
+	if (fi) {
+		fi->functions->freeMemory(fi->r);
+		fi->functions->freeMemory(fi->i);
+		fi->functions->freeMemory(fi->b);
+		fi->functions->freeMemory(fi->s);// TODO has to be done with loop
+		fi->functions->freeMemory((void*)fi->instanceName);
+		fi->functions->freeMemory((void*)fi->GUID);
+		fi->functions->freeMemory((void*)fi);
+
+	}
+}
+
+//To be implemented
+
+const char* fmi2GetVersion() {
+	printf("Function fmiGetVersion not supported\n");
+	return NULL;
+}
+
+const char* fmi2GetTypesPlatform() {
+	printf("Function fmiGetTypesPlatform not supported\n");
+	return NULL;
+}
+
+fmi2Status fmi2Reset(fmi2Component fc)
+{
+	printf("Function fmiReset not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2SetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Integer value[])
+{
+	printf("Function fmiSetInteger not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[])
+{
+	printf("Function fmiGetInteger not supported\n");
+	return fmi2Error;
+}
+
+
+/*******OWN IMPLEMENTATION OF Get/Set FMU state*******/
+fmi2Status fmi2GetFMUstate (fmi2Component c, fmi2FMUstate* FMUstate) {
+	FMUInstance* orig = (FMUInstance*)c;
+	FMUInstance* fi = (FMUInstance *)FMUstate;
+	*FMUstate = fi;
+	fi = orig->functions->allocateMemory(1, sizeof(FMUInstance));
+	*FMUstate = fi;
+	fi->functions = orig->functions;
+
+	if (fi) {
+		// Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
+		fi->r = fi->functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
+		fi->i = fi->functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
+		fi->b = fi->functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
+		fi->s = fi->functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
+
+	} // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
+	fi->instanceName = orig->functions->allocateMemory(1 + strlen(orig->instanceName), sizeof(char));
+	fi->GUID = orig->functions->allocateMemory(1 + strlen(orig->GUID), sizeof(char));
+
+	strcpy((char *)fi->instanceName, (char *)orig->instanceName);
+	strcpy((char *)fi->GUID, (char *)orig->GUID);
+	fi->functions = orig->functions;
+	fi->loggingOn = orig->loggingOn;
+	fi->isVisible = orig->isVisible;
+	fi->state = orig->state;
+	fi->startTime = orig->startTime;
+	fi->stopTime = orig->stopTime;
+	fi->currentTime = orig->currentTime;
+	/* TODO: Store all the rest here.*/
+	fi->fmu[0] = orig->fmu[0];
+	fi->c_fmu[0] = orig->c_fmu[0];
+	for(int i=0; i<_NR_OF_IN_CONDITIONS;i++){
+		fi->in_condition_executed[i] = orig->in_condition_executed[i];
+	}
+	for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		fi->out_conditions_executed[i] = orig->out_conditions_executed[i];
+	}
+	for(int i=0;i<_NR_OF_FMUS;i++){
+		fi->time_last_fmu[i] = orig->time_last_fmu[i];
+	}
+
+	/* Generated */
+	fi->REL_TOLERANCE = orig->REL_TOLERANCE;
+	fi->ABS_TOLERANCE = orig->ABS_TOLERANCE;
+	fi->CROSSING = orig->CROSSING;
+	fi->init_up = orig->init_up;
+	fi->init_down = orig->init_down;
+	fi->init_armature_current = orig->init_armature_current;
+	fi->next_time_step = orig->next_time_step;
+	fi->stored_arm_current = orig->stored_arm_current;
+	fi->step_size = orig->step_size;
+	fi->aux_obj_detected = orig->aux_obj_detected;
+	fi->get_next_step = orig->get_next_step;
+	fi->previous_arm_current = orig->previous_arm_current;
+	fi->stored_up = orig->stored_up;
+	fi->stored_down = orig->stored_down;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+	/*
+	 * This is a hierarchical call. First let the lower FMUs do their state saving
+	 * We will store the saved fmu state in the fi->c_order[i]
+	 */
+	for(int i=0;i<1;i++){
+		fi->fmu[i]=orig->fmu[i];
+		orig->fmu[i].getFMUstate(orig->c_fmu[i],fi->c_fmu[i]);
+		fi->fmuResourceLocation[i] = fi->functions->allocateMemory(1+strlen(orig->fmuResourceLocation[i]), sizeof(char));
+		strcpy((char *)fi->fmuResourceLocation[i],(char *)orig->fmuResourceLocation[i]);
+		/*make shallow copies of the stored fmus*/
+	}
+	//copy r
+	int i=0;
+	for (i=0; i< NUMBER_OF_REALS;i++){
+		printf("Setting real: %i %f\n", i, orig->r[i]);
+		fi->r[i] = orig->r[i];
+		printf("Setted real: %i %f\n", i, fi->r[i]);
+	}
+	//copy s
+	for (i=0; i< NUMBER_OF_STRINGS;i++){
+		//fi->s[i] = orig->s[i]; // why are this not deep copies?
+		fi->s[i] = fi->functions->allocateMemory(1+strlen(orig->s[i]),sizeof(char));
+		strcpy((char *)fi->s[i],(char *)orig->s[i]);
+	}
+	//copy i
+	for (i=0; i< NUMBER_OF_INTEGERS;i++){
+		fi->i[i] = orig->i[i];
+	}
+	//copy b
+	for (i=0; i< NUMBER_OF_BOOLEANS;i++){
+		fi->b[i] = orig->b[i];
+	}
+	return fmi2OK;
+}
+
+fmi2Status fmi2SetFMUstate (fmi2Component c, fmi2FMUstate FMUstate) {
+	FMUInstance* orig = (FMUInstance*)FMUstate;
+	FMUInstance* fi = (FMUInstance*)c;
+	/*
+	 * First restore the hierarchical fmus.
+	 */
+	for(int i=0;i<1;i++){
+		fi->fmu[i].setFMUstate(fi->c_fmu[i],orig->c_fmu[i]);
+		fi->fmuResourceLocation[i] = orig->functions->allocateMemory(1+strlen(orig->fmuResourceLocation[i]), sizeof(char));
+		strcpy((char *)fi->fmuResourceLocation[i],(char *)orig->fmuResourceLocation[i]);
+	}
+
+	//set time etc correct, name and GUID should still be ok ;-)
+	printf("setting time values from %f to %f\n", fi->currentTime, orig->currentTime);
+	fi->state = orig->state;
+	fi->startTime = orig->startTime;
+	fi->stopTime = orig->stopTime;
+	fi->currentTime = orig->currentTime;
+
+	fi->fmu[0] = orig->fmu[0];
+	fi->c_fmu[0] = orig->c_fmu[0];
+	for(int i=0; i<_NR_OF_IN_CONDITIONS;i++){
+		fi->in_condition_executed[i] = orig->in_condition_executed[i];
+	}
+	for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		fi->out_conditions_executed[i] = orig->out_conditions_executed[i];
+	}
+	for(int i=0;i<_NR_OF_FMUS;i++){
+		fi->time_last_fmu[i] = orig->time_last_fmu[i];
+	}
+
+	/* Generated */
+	fi->REL_TOLERANCE = orig->REL_TOLERANCE;
+	fi->ABS_TOLERANCE = orig->ABS_TOLERANCE;
+	fi->CROSSING = orig->CROSSING;
+	fi->init_up = orig->init_up;
+	fi->init_down = orig->init_down;
+	fi->init_armature_current = orig->init_armature_current;
+	fi->next_time_step = orig->next_time_step;
+	fi->stored_arm_current = orig->stored_arm_current;
+	fi->step_size = orig->step_size;
+	fi->aux_obj_detected = orig->aux_obj_detected;
+	fi->get_next_step = orig->get_next_step;
+	fi->previous_arm_current = orig->previous_arm_current;
+	fi->stored_up = orig->stored_up;
+	fi->stored_down = orig->stored_down;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+	printf("setting real values\n");
+	//copy r
+	int i=0;
+	for (i=0; i< NUMBER_OF_REALS;i++){
+		fi->r[i] = orig->r[i];
+	}
+	printf("setting string values\n");
+	//copy s
+	for (i=0; i< NUMBER_OF_STRINGS;i++){
+
+		fi->s[i] = orig->s[i];
+	}
+	//copy i
+	for (i=0; i< NUMBER_OF_INTEGERS;i++){
+		fi->i[i] = orig->i[i];
+	}
+	//copy b
+	for (i=0; i< NUMBER_OF_BOOLEANS;i++){
+		fi->b[i] = orig->b[i];
+	}
+	return fmi2OK;
+
+
+}
+/****************************************************/
+
+fmi2Status fmi2FreeFMUstate(fmi2Component c, fmi2FMUstate* FMUstate) {
+	printf("Function fmiFreeFMUstate not supported\n");
+	return fmi2Error;
+}
+fmi2Status fmi2SerializedFMUstateSize(fmi2Component c, fmi2FMUstate FMUstate, size_t *size) {
+	printf("Function fmiSerializedFMUstateSize not supported\n");
+	return fmi2Error;
+}
+fmi2Status fmi2SerializeFMUstate (fmi2Component c, fmi2FMUstate FMUstate, fmi2Byte serializedState[], size_t size) {
+	printf("Function fmiSerializeFMUstate not supported\n");
+	return fmi2Error;
+}
+fmi2Status fmi2DeSerializeFMUstate (fmi2Component c, const fmi2Byte serializedState[], size_t size, fmi2FMUstate* FMUstate) {
+	printf("Function fmiDeSerializeFMUstate not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetDirectionalDerivative(fmi2Component c, const fmi2ValueReference vUnknown_ref[], size_t nUnknown,
+		const fmi2ValueReference vKnown_ref[] , size_t nKnown, const fmi2Real dvKnown[], fmi2Real dvUnknown[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+
+fmi2Status fmi2SetRealInputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
+		const fmi2Integer order[], const fmi2Real value[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetRealOutputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
+		const fmi2Integer order[], fmi2Real value[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2CancelStep(fmi2Component c) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetStatus(fmi2Component c, const fmi2StatusKind s, fmi2Status *value) {
+	printf("Function fmiGetStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetRealStatus(fmi2Component c, const fmi2StatusKind s, fmi2Real *value) {
+	if(s == fmi2LastSuccessfulTime){
+		FMUInstance* comp = (FMUInstance*) c;
+		*value = comp->currentTime;
+		return fmi2OK;
+	}
+	printf("Function fmiGetRealStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetIntegerStatus(fmi2Component c, const fmi2StatusKind s, fmi2Integer *value) {
+	printf("Function fmiGetIntegerStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetBooleanStatus(fmi2Component c, const fmi2StatusKind s, fmi2Boolean *value) {
+	printf("Function fmiGetBooleanStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetStringStatus(fmi2Component c, const fmi2StatusKind s, fmi2String *value) {
+	printf("Function fmiGetStringStatus not supported\n");
+	return fmi2Error;
+}

+ 69 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/FMI_GM.h

@@ -0,0 +1,69 @@
+/*
+ * PW_Controller.h
+ *
+ *  Created on: Jan 25, 2017
+ *      Author: Joachim
+ */
+
+#ifndef FMI_GM_H_
+#define FMI_GM_H_
+
+#include "fmi2.h"
+
+typedef enum {
+    fmuInstantiated = 0,
+    fmuInitMode  = 1,
+	fmuInitialized = 2,
+    fmuTerminated   = 3,
+    fmuError        = 4,
+    fmuExperimentSettedUp = 5
+} FMUState;
+
+#define _NR_OF_FMUS 1
+#define _NR_OF_IN_CONDITIONS 2
+#define _NR_OF_OUT_CONDITIONS 1
+
+typedef struct {
+	fmi2Real    *r;
+    fmi2Integer *i;
+    fmi2Boolean *b;
+    fmi2String  *s;
+    fmi2Boolean isVisible;
+    fmi2String instanceName;
+    fmi2String GUID;
+    const fmi2CallbackFunctions* functions;
+    fmi2Boolean loggingOn;
+    FMUState state;
+    fmi2Real startTime;
+    fmi2Real stopTime;
+	fmi2Real currentTime;
+    fmi2Boolean stopTimeDefined;
+    fmi2Boolean toleranceDefined;
+    /* for generic algo*/
+    FMU fmu[1];
+    char *fmuResourceLocation[_NR_OF_FMUS];
+    fmi2Component c_fmu[_NR_OF_FMUS];
+    fmi2Boolean in_condition_executed[_NR_OF_IN_CONDITIONS];
+    fmi2Boolean out_conditions_executed[_NR_OF_OUT_CONDITIONS];
+    fmi2Real time_last_fmu[_NR_OF_FMUS];
+    /* Generated */
+    fmi2Real REL_TOLERANCE;
+    fmi2Real ABS_TOLERANCE;
+    fmi2Real CROSSING;
+    fmi2Real init_up;
+    fmi2Real init_down;
+    fmi2Real init_armature_current;
+    fmi2Real next_time_step;
+    fmi2Real stored_arm_current;
+    fmi2Real step_size;
+    fmi2Boolean aux_obj_detected;
+    fmi2Boolean get_next_step;
+    fmi2Real previous_arm_current;
+    fmi2Boolean stored_up;
+    fmi2Boolean stored_down;
+} FMUInstance; // At the moment, most of the variables not really used since multiple instances of an FMU are not supported at the moment (performance issues)
+
+
+
+
+#endif /* FMI_GM_H_ */

+ 72 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/fmi2/fmi2.h

@@ -0,0 +1,72 @@
+/* -------------------------------------------------------------------------
+ * 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 "fmi2Functions.h"
+
+typedef struct {
+//    ModelDescription* modelDescription;
+
+    void  *dllHandle; // fmu.so 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
+

+ 247 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/fmi2/fmi2FunctionTypes.h

@@ -0,0 +1,247 @@
+#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 (C) 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);
+#ifdef FMU_EXPERIMENTAL
+   typedef fmi2Status fmi2GetSpecificDerivativesTYPE       (fmi2Component, fmi2Real[], const fmi2ValueReference [], size_t);
+#endif
+
+   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 */

+ 339 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/fmi2/fmi2Functions.h

@@ -0,0 +1,339 @@
+#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 (C) 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)
+#ifdef FMU_EXPERIMENTAL
+#define fmi2GetSpecificDerivatives        fmi2FullName(fmi2GetSpecificDerivatives)
+#endif
+#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;
+#ifdef FMU_EXPERIMENTAL
+   FMI2_Export fmi2GetSpecificDerivativesTYPE        fmi2GetSpecificDerivatives;
+#endif
+   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/fmu/cs/FMI_generic_algorithm/fmi2/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 (C) 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 */

+ 594 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/sim_support.c

@@ -0,0 +1,594 @@
+/* -------------------------------------------------------------------------
+ * sim_support.c
+ * Functions used by both FMU simulators fmu20sim_me and fmu20sim_cs
+ * to parse command-line arguments, to unzip and load an fmu,
+ * to write CSV file, and more.
+ *
+ * Revision history
+ *  07.03.2014 initial version released in FMU SDK 2.0.0
+ *  10.04.2014 use FMI 2.0 headers that prefix function and type names with 'fmi2'.
+ *             When 'fmi2' functions are not found in loaded DLL, look also for
+ *             FMI 2.0 RC1 function names.
+ *
+ * Author: Adrian Tirea
+ * Copyright QTronic GmbH. All rights reserved.
+ * -------------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <stdarg.h>
+#include <dlfcn.h>
+#include "fmi2.h"
+#include "sim_support.h"
+
+#define FMI_COSIMULATION
+extern FMU fmu;
+
+
+//int unzip(const char *zipPath, const char *outPath) {
+//    int code;
+//    char cwd[BUFSIZE];
+//    char binPath[BUFSIZE];
+//    int n = strlen(UNZIP_CMD) + strlen(outPath) + 3 +  strlen(zipPath) + 9;
+//    char* cmd = (char*)calloc(sizeof(char), n);
+//
+//    // remember current directory
+//    if (!GetCurrentDirectory(BUFSIZE, cwd)) {
+//        printf ("error: Could not get current directory\n");
+//        return 0; // error
+//    }
+//
+//    // change to %FMUSDK_HOME%\bin to find 7z.dll and 7z.exe
+//    if (!GetEnvironmentVariable("FMUSDK_HOME", binPath, BUFSIZE)) {
+//        if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
+//            printf ("error: Environment variable FMUSDK_HOME not defined\n");
+//        }
+//        else {
+//            printf ("error: Could not get value of FMUSDK_HOME\n");
+//        }
+//        return 0; // error
+//    }
+//    strcat(binPath, "\\bin");
+//    if (!SetCurrentDirectory(binPath)) {
+//        printf ("error: could not change to directory '%s'\n", binPath);
+//        return 0; // error
+//    }
+//
+//    // run the unzip command
+//    // remove "> NUL" to see the unzip protocol
+//    sprintf(cmd, "%s\"%s\" \"%s\" > NUL", UNZIP_CMD, outPath, zipPath);
+//    // printf("cmd='%s'\n", cmd);
+//    code = system(cmd);
+//    free(cmd);
+//    if (code != SEVEN_ZIP_NO_ERROR) {
+//        printf("7z: ");
+//        switch (code) {
+//            case SEVEN_ZIP_WARNING:            printf("warning\n"); break;
+//            case SEVEN_ZIP_ERROR:              printf("error\n"); break;
+//            case SEVEN_ZIP_COMMAND_LINE_ERROR: printf("command line error\n"); break;
+//            case SEVEN_ZIP_OUT_OF_MEMORY:      printf("out of memory\n"); break;
+//            case SEVEN_ZIP_STOPPED_BY_USER:    printf("stopped by user\n"); break;
+//            default: printf("unknown problem\n");
+//        }
+//    }
+//
+//    // restore current directory
+//    SetCurrentDirectory(cwd);
+//    return (code == SEVEN_ZIP_NO_ERROR || code == SEVEN_ZIP_WARNING) ? 1 : 0;
+//}
+//
+//// fileName is an absolute path, e.g. C:\test\a.fmu
+//// or relative to the current dir, e.g. ..\test\a.fmu
+//// Does not check for existence of the file
+//static char* getFmuPath(const char* fileName){
+//    char pathName[MAX_PATH];
+//    int n = GetFullPathName(fileName, MAX_PATH, pathName, NULL);
+//    return n ? strdup(pathName) : NULL;
+//}
+//
+//static char* getTmpPath() {
+//    char tmpPath[BUFSIZE];
+//    if(! GetTempPath(BUFSIZE, tmpPath)) {
+//        printf ("error: Could not find temporary disk space\n");
+//        return NULL;
+//    }
+//    strcat(tmpPath, "fmu\\");
+//    return strdup(tmpPath);
+//}
+//
+//char *getTempResourcesLocation() {
+//    char *tempPath = getTmpPath();
+//    char *resourcesLocation = (char *)calloc(sizeof(char), 9 + strlen(RESOURCES_DIR) + strlen(tempPath));
+//    strcpy(resourcesLocation, "file:///");
+//    strcat(resourcesLocation, tempPath);
+//    strcat(resourcesLocation, RESOURCES_DIR);
+//    free(tempPath);
+//    return resourcesLocation;
+//}
+
+static void *getAdr(int *success, void *dllHandle, const char *functionName, const char* preamble) {
+
+    int length = strlen(preamble) + strlen(functionName) + 1;
+    char* new_name = malloc(length);  // allocate memory
+    strcpy(new_name, preamble);  // copy first string
+    strcat(new_name, functionName);
+    void* fp = dlsym(dllHandle, new_name);
+    if (!fp) {
+        printf("warning: Function %s not found in dll\n", new_name);
+        *success = 0;
+    }
+    free(new_name);
+    return fp;
+}
+
+// Load the given dll and set function pointers in fmu
+// Return 0 to indicate failure
+int loadDll(const char* dllPath, FMU *fmu, const char* preamble) {
+    int x = 1, s = 1;
+    //HMODULE h = LoadLibrary(dllPath);
+    void *h = dlopen(dllPath, RTLD_LAZY);
+    printf("%s", dlerror());
+    if (!h) {
+        printf("error: Could not load %s\n", dllPath);
+        return 0; // failure
+    }
+    fmu->dllHandle = h;
+    fmu->getTypesPlatform          = (fmi2GetTypesPlatformTYPE *)      getAdr(&s, h, "fmi2GetTypesPlatform", preamble);
+    fmu->getVersion                = (fmi2GetVersionTYPE *)            getAdr(&s, h, "fmi2GetVersion", preamble);
+    fmu->setDebugLogging           = (fmi2SetDebugLoggingTYPE *)       getAdr(&s, h, "fmi2SetDebugLogging",preamble);
+    fmu->instantiate               = (fmi2InstantiateTYPE *)           getAdr(&s, h, "fmi2Instantiate", preamble);
+    fmu->freeInstance              = (fmi2FreeInstanceTYPE *)          getAdr(&s, h, "fmi2FreeInstance", preamble);
+    fmu->setupExperiment           = (fmi2SetupExperimentTYPE *)       getAdr(&s, h, "fmi2SetupExperiment", preamble);
+    fmu->enterInitializationMode   = (fmi2EnterInitializationModeTYPE *) getAdr(&s, h, "fmi2EnterInitializationMode", preamble);
+    fmu->exitInitializationMode    = (fmi2ExitInitializationModeTYPE *) getAdr(&s, h, "fmi2ExitInitializationMode", preamble);
+    fmu->terminate                 = (fmi2TerminateTYPE *)             getAdr(&s, h, "fmi2Terminate", preamble);
+    fmu->reset                     = (fmi2ResetTYPE *)                 getAdr(&s, h, "fmi2Reset", preamble);
+    fmu->getReal                   = (fmi2GetRealTYPE *)               getAdr(&s, h, "fmi2GetReal", preamble);
+    fmu->getInteger                = (fmi2GetIntegerTYPE *)            getAdr(&s, h, "fmi2GetInteger", preamble);
+    fmu->getBoolean                = (fmi2GetBooleanTYPE *)            getAdr(&s, h, "fmi2GetBoolean", preamble);
+    fmu->getString                 = (fmi2GetStringTYPE *)             getAdr(&s, h, "fmi2GetString", preamble);
+    fmu->setReal                   = (fmi2SetRealTYPE *)               getAdr(&s, h, "fmi2SetReal", preamble);
+    fmu->setInteger                = (fmi2SetIntegerTYPE *)            getAdr(&s, h, "fmi2SetInteger", preamble);
+    fmu->setBoolean                = (fmi2SetBooleanTYPE *)            getAdr(&s, h, "fmi2SetBoolean", preamble);
+    fmu->setString                 = (fmi2SetStringTYPE *)             getAdr(&s, h, "fmi2SetString", preamble);
+    fmu->getFMUstate               = (fmi2GetFMUstateTYPE *)           getAdr(&s, h, "fmi2GetFMUstate", preamble);
+    fmu->setFMUstate               = (fmi2SetFMUstateTYPE *)           getAdr(&s, h, "fmi2SetFMUstate", preamble);
+    fmu->freeFMUstate              = (fmi2FreeFMUstateTYPE *)          getAdr(&s, h, "fmi2FreeFMUstate", preamble);
+    fmu->serializedFMUstateSize    = (fmi2SerializedFMUstateSizeTYPE *) getAdr(&s, h, "fmi2SerializedFMUstateSize", preamble);
+    fmu->serializeFMUstate         = (fmi2SerializeFMUstateTYPE *)     getAdr(&s, h, "fmi2SerializeFMUstate", preamble);
+    fmu->deSerializeFMUstate       = (fmi2DeSerializeFMUstateTYPE *)   getAdr(&s, h, "fmi2DeSerializeFMUstate", preamble);
+    fmu->getDirectionalDerivative  = (fmi2GetDirectionalDerivativeTYPE *) getAdr(&s, h, "fmi2GetDirectionalDerivative", preamble);
+#ifdef FMI_COSIMULATION
+    fmu->setRealInputDerivatives   = (fmi2SetRealInputDerivativesTYPE *) getAdr(&s, h, "fmi2SetRealInputDerivatives", preamble);
+    fmu->getRealOutputDerivatives  = (fmi2GetRealOutputDerivativesTYPE *) getAdr(&s, h, "fmi2GetRealOutputDerivatives", preamble);
+    fmu->doStep                    = (fmi2DoStepTYPE *)                getAdr(&s, h, "fmi2DoStep", preamble);
+    fmu->cancelStep                = (fmi2CancelStepTYPE *)            getAdr(&s, h, "fmi2CancelStep", preamble);
+    fmu->getStatus                 = (fmi2GetStatusTYPE *)             getAdr(&s, h, "fmi2GetStatus", preamble);
+    fmu->getRealStatus             = (fmi2GetRealStatusTYPE *)         getAdr(&s, h, "fmi2GetRealStatus", preamble);
+    fmu->getIntegerStatus          = (fmi2GetIntegerStatusTYPE *)      getAdr(&s, h, "fmi2GetIntegerStatus", preamble);
+    fmu->getBooleanStatus          = (fmi2GetBooleanStatusTYPE *)      getAdr(&s, h, "fmi2GetBooleanStatus", preamble);
+    fmu->getStringStatus           = (fmi2GetStringStatusTYPE *)       getAdr(&s, h, "fmi2GetStringStatus", preamble);
+#else // FMI2 for Model Exchange
+    fmu->enterEventMode            = (fmi2EnterEventModeTYPE *)        getAdr(&s, h, "fmi2EnterEventMode", preamble);
+    fmu->newDiscreteStates         = (fmi2NewDiscreteStatesTYPE *)     getAdr(&s, h, "fmi2NewDiscreteStates", preamble);
+    fmu->enterContinuousTimeMode   = (fmi2EnterContinuousTimeModeTYPE *) getAdr(&s, h, "fmi2EnterContinuousTimeMode", preamble);
+    fmu->completedIntegratorStep   = (fmi2CompletedIntegratorStepTYPE *) getAdr(&s, h, "fmi2CompletedIntegratorStep", preamble);
+    fmu->setTime                   = (fmi2SetTimeTYPE *)               getAdr(&s, h, "fmi2SetTime", preamble);
+    fmu->setContinuousStates       = (fmi2SetContinuousStatesTYPE *)   getAdr(&s, h, "fmi2SetContinuousStates", preamble);
+    fmu->getDerivatives            = (fmi2GetDerivativesTYPE *)        getAdr(&s, h, "fmi2GetDerivatives", preamble);
+    fmu->getEventIndicators        = (fmi2GetEventIndicatorsTYPE *)    getAdr(&s, h, "fmi2GetEventIndicators", preamble);
+    fmu->getContinuousStates       = (fmi2GetContinuousStatesTYPE *)   getAdr(&s, h, "fmi2GetContinuousStates", preamble);
+    fmu->getNominalsOfContinuousStates = (fmi2GetNominalsOfContinuousStatesTYPE *) getAdr(&s, h, "fmi2GetNominalsOfContinuousStates", preamble);
+#endif
+
+    if (fmu->getVersion == NULL && fmu->instantiate == NULL) {
+        printf("warning: Functions from FMI 2.0 could not be found in %s\n", dllPath);
+        printf("warning: Simulator will look for FMI 2.0 RC1 functions names...\n");
+        fmu->getTypesPlatform          = (fmi2GetTypesPlatformTYPE *)      getAdr(&s, h, "fmiGetTypesPlatform", preamble);
+        fmu->getVersion                = (fmi2GetVersionTYPE *)            getAdr(&s, h, "fmiGetVersion", preamble);
+        fmu->setDebugLogging           = (fmi2SetDebugLoggingTYPE *)       getAdr(&s, h, "fmiSetDebugLogging", preamble);
+        fmu->instantiate               = (fmi2InstantiateTYPE *)           getAdr(&s, h, "fmiInstantiate", preamble);
+        fmu->freeInstance              = (fmi2FreeInstanceTYPE *)          getAdr(&s, h, "fmiFreeInstance", preamble);
+        fmu->setupExperiment           = (fmi2SetupExperimentTYPE *)       getAdr(&s, h, "fmiSetupExperiment", preamble);
+        fmu->enterInitializationMode   = (fmi2EnterInitializationModeTYPE *) getAdr(&s, h, "fmiEnterInitializationMode", preamble);
+        fmu->exitInitializationMode    = (fmi2ExitInitializationModeTYPE *) getAdr(&s, h, "fmiExitInitializationMode", preamble);
+        fmu->terminate                 = (fmi2TerminateTYPE *)             getAdr(&s, h, "fmiTerminate", preamble);
+        fmu->reset                     = (fmi2ResetTYPE *)                 getAdr(&s, h, "fmiReset", preamble);
+        fmu->getReal                   = (fmi2GetRealTYPE *)               getAdr(&s, h, "fmiGetReal", preamble);
+        fmu->getInteger                = (fmi2GetIntegerTYPE *)            getAdr(&s, h, "fmiGetInteger", preamble);
+        fmu->getBoolean                = (fmi2GetBooleanTYPE *)            getAdr(&s, h, "fmiGetBoolean", preamble);
+        fmu->getString                 = (fmi2GetStringTYPE *)             getAdr(&s, h, "fmiGetString", preamble);
+        fmu->setReal                   = (fmi2SetRealTYPE *)               getAdr(&s, h, "fmiSetReal", preamble);
+        fmu->setInteger                = (fmi2SetIntegerTYPE *)            getAdr(&s, h, "fmiSetInteger", preamble);
+        fmu->setBoolean                = (fmi2SetBooleanTYPE *)            getAdr(&s, h, "fmiSetBoolean", preamble);
+        fmu->setString                 = (fmi2SetStringTYPE *)             getAdr(&s, h, "fmiSetString", preamble);
+        fmu->getFMUstate               = (fmi2GetFMUstateTYPE *)           getAdr(&s, h, "fmiGetFMUstate", preamble);
+        fmu->setFMUstate               = (fmi2SetFMUstateTYPE *)           getAdr(&s, h, "fmiSetFMUstate", preamble);
+        fmu->freeFMUstate              = (fmi2FreeFMUstateTYPE *)          getAdr(&s, h, "fmiFreeFMUstate", preamble);
+        fmu->serializedFMUstateSize    = (fmi2SerializedFMUstateSizeTYPE *) getAdr(&s, h, "fmiSerializedFMUstateSize", preamble);
+        fmu->serializeFMUstate         = (fmi2SerializeFMUstateTYPE *)     getAdr(&s, h, "fmiSerializeFMUstate", preamble);
+        fmu->deSerializeFMUstate       = (fmi2DeSerializeFMUstateTYPE *)   getAdr(&s, h, "fmiDeSerializeFMUstate", preamble);
+        fmu->getDirectionalDerivative  = (fmi2GetDirectionalDerivativeTYPE *) getAdr(&s, h, "fmiGetDirectionalDerivative", preamble);
+    #ifdef FMI_COSIMULATION
+        fmu->setRealInputDerivatives   = (fmi2SetRealInputDerivativesTYPE *) getAdr(&s, h, "fmiSetRealInputDerivatives", preamble);
+        fmu->getRealOutputDerivatives  = (fmi2GetRealOutputDerivativesTYPE *) getAdr(&s, h, "fmiGetRealOutputDerivatives", preamble);
+        fmu->doStep                    = (fmi2DoStepTYPE *)                getAdr(&s, h, "fmiDoStep", preamble);
+        fmu->cancelStep                = (fmi2CancelStepTYPE *)            getAdr(&s, h, "fmiCancelStep", preamble);
+        fmu->getStatus                 = (fmi2GetStatusTYPE *)             getAdr(&s, h, "fmiGetStatus", preamble);
+        fmu->getRealStatus             = (fmi2GetRealStatusTYPE *)         getAdr(&s, h, "fmiGetRealStatus", preamble);
+        fmu->getIntegerStatus          = (fmi2GetIntegerStatusTYPE *)      getAdr(&s, h, "fmiGetIntegerStatus", preamble);
+        fmu->getBooleanStatus          = (fmi2GetBooleanStatusTYPE *)      getAdr(&s, h, "fmiGetBooleanStatus", preamble);
+        fmu->getStringStatus           = (fmi2GetStringStatusTYPE *)       getAdr(&s, h, "fmiGetStringStatus", preamble);
+    #else // FMI2 for Model Exchange
+        fmu->enterEventMode            = (fmi2EnterEventModeTYPE *)        getAdr(&s, h, "fmiEnterEventMode", preamble);
+        fmu->newDiscreteStates         = (fmi2NewDiscreteStatesTYPE *)     getAdr(&s, h, "fmiNewDiscreteStates", preamble);
+        fmu->enterContinuousTimeMode   = (fmi2EnterContinuousTimeModeTYPE *) getAdr(&s, h, "fmiEnterContinuousTimeMode", preamble);
+        fmu->completedIntegratorStep   = (fmi2CompletedIntegratorStepTYPE *) getAdr(&s, h, "fmiCompletedIntegratorStep", preamble);
+        fmu->setTime                   = (fmi2SetTimeTYPE *)               getAdr(&s, h, "fmiSetTime", preamble);
+        fmu->setContinuousStates       = (fmi2SetContinuousStatesTYPE *)   getAdr(&s, h, "fmiSetContinuousStates", preamble);
+        fmu->getDerivatives            = (fmi2GetDerivativesTYPE *)        getAdr(&s, h, "fmiGetDerivatives", preamble);
+        fmu->getEventIndicators        = (fmi2GetEventIndicatorsTYPE *)    getAdr(&s, h, "fmiGetEventIndicators", preamble);
+        fmu->getContinuousStates       = (fmi2GetContinuousStatesTYPE *)   getAdr(&s, h, "fmiGetContinuousStates", preamble);
+        fmu->getNominalsOfContinuousStates = (fmi2GetNominalsOfContinuousStatesTYPE *) getAdr(&s, h, "fmiGetNominalsOfContinuousStates", preamble);
+    #endif
+    }
+    return s;
+}
+
+//static void printModelDescription(ModelDescription* md){
+//    Element* e = (Element*)md;
+//    int i;
+//    int n; // number of attributes
+//    const char **attributes = getAttributesAsArray(e, &n);
+//    Component *component;
+//
+//    if (!attributes) {
+//        printf("ModelDescription printing aborted.");
+//        return;
+//    }
+//    printf("%s\n", getElementTypeName(e));
+//    for (i = 0; i < n; i += 2) {
+//        printf("  %s=%s\n", attributes[i], attributes[i+1]);
+//    }
+//    free((void *)attributes);
+//
+//#ifdef FMI_COSIMULATION
+//    component = getCoSimulation(md);
+//    if (!component) {
+//        printf("error: No CoSimulation element found in model description. This FMU is not for Co-Simulation.\n");
+//        exit(EXIT_FAILURE);
+//    }
+//#else // FMI_MODEL_EXCHANGE
+//    component = getModelExchange(md);
+//    if (!component) {
+//        printf("error: No ModelExchange element found in model description. This FMU is not for Model Exchange.\n");
+//        exit(EXIT_FAILURE);
+//    }
+//#endif
+//    printf("%s\n", getElementTypeName((Element *)component));
+//    attributes = getAttributesAsArray((Element *)component, &n);
+//    if (!attributes) {
+//        printf("ModelDescription printing aborted.");
+//        return;
+//    }
+//    for (i = 0; i < n; i += 2) {
+//        printf("  %s=%s\n", attributes[i], attributes[i+1]);
+//    }
+//
+//    free((void *)attributes);
+//}
+//
+//void loadFMU(const char* fmuFileName) {
+//    char* fmuPath;
+//    char* tmpPath;
+//    char* xmlPath;
+//    char* dllPath;
+//    const char *modelId;
+//
+//    // get absolute path to FMU, NULL if not found
+//    fmuPath = getFmuPath(fmuFileName);
+//    if (!fmuPath) exit(EXIT_FAILURE);
+//
+//    // unzip the FMU to the tmpPath directory
+//    tmpPath = getTmpPath();
+//    if (!unzip(fmuPath, tmpPath)) exit(EXIT_FAILURE);
+//
+//    // parse tmpPath\modelDescription.xml
+//    xmlPath = calloc(sizeof(char), strlen(tmpPath) + strlen(XML_FILE) + 1);
+//    sprintf(xmlPath, "%s%s", tmpPath, XML_FILE);
+//    fmu.modelDescription = parse(xmlPath);
+//    free(xmlPath);
+//    if (!fmu.modelDescription) exit(EXIT_FAILURE);
+//    printModelDescription(fmu.modelDescription);
+//#ifdef FMI_COSIMULATION
+//    modelId = getAttributeValue((Element *)getCoSimulation(fmu.modelDescription), att_modelIdentifier);
+//#else // FMI_MODEL_EXCHANGE
+//    modelId = getAttributeValue((Element *)getModelExchange(fmu.modelDescription), att_modelIdentifier);
+//#endif
+//    // load the FMU dll
+//    dllPath = calloc(sizeof(char), strlen(tmpPath) + strlen(DLL_DIR)
+//        + strlen(modelId) +  strlen(".dll") + 1);
+//    sprintf(dllPath, "%s%s%s.dll", tmpPath, DLL_DIR, modelId);
+//    if (!loadDll(dllPath, &fmu)) {
+//        exit(EXIT_FAILURE);
+//    }
+//    free(dllPath);
+//    free(fmuPath);
+//    free(tmpPath);
+//}
+//
+//void deleteUnzippedFiles() {
+//    const char *fmuTempPath = getTmpPath();
+//    char *cmd = (char *)calloc(15 + strlen(fmuTempPath), sizeof(char));
+//    sprintf(cmd, "rmdir /S /Q %s", fmuTempPath);
+//    system(cmd);
+//    free(cmd);
+//}
+//
+//static void doubleToCommaString(char* buffer, double r){
+//    char* comma;
+//    sprintf(buffer, "%.16g", r);
+//    comma = strchr(buffer, '.');
+//    if (comma) *comma = ',';
+//}
+//
+//// output time and all variables in CSV format
+//// if separator is ',', columns are separated by ',' and '.' is used for floating-point numbers.
+//// otherwise, the given separator (e.g. ';' or '\t') is to separate columns, and ',' is used
+//// as decimal dot in floating-point numbers.
+//void outputRow(FMU *fmu, fmi2Component c, double time, FILE* file, char separator, fmi2Boolean header) {
+//    int k;
+//    fmi2Real r;
+//    fmi2Integer i;
+//    fmi2Boolean b;
+//    fmi2String s;
+//    fmi2ValueReference vr;
+//    int n = getScalarVariableSize(fmu->modelDescription);
+//    char buffer[32];
+//
+//    // print first column
+//    if (header) {
+//        fprintf(file, "time");
+//    } else {
+//        if (separator==',')
+//            fprintf(file, "%.16g", time);
+//        else {
+//            // separator is e.g. ';' or '\t'
+//            doubleToCommaString(buffer, time);
+//            fprintf(file, "%s", buffer);
+//        }
+//    }
+//
+//    // print all other columns
+//    for (k = 0; k < n; k++) {
+//        ScalarVariable *sv = getScalarVariable(fmu->modelDescription, k);
+//        if (header) {
+//            // output names only
+//            if (separator == ',') {
+//                // treat array element, e.g. print a[1, 2] as a[1.2]
+//                const char *s = getAttributeValue((Element *)sv, att_name);
+//                fprintf(file, "%c", separator);
+//                while (*s) {
+//                    if (*s != ' ') {
+//                        fprintf(file, "%c", *s == ',' ? '.' : *s);
+//                    }
+//                    s++;
+//                }
+//            } else {
+//                fprintf(file, "%c%s", separator, getAttributeValue((Element *)sv, att_name));
+//            }
+//        } else {
+//            // output values
+//            vr = getValueReference(sv);
+//            switch (getElementType(getTypeSpec(sv))) {
+//                case elm_Real:
+//                    fmu->getReal(c, &vr, 1, &r);
+//                    if (separator == ',') {
+//                        fprintf(file, ",%.16g", r);
+//                    } else {
+//                        // separator is e.g. ';' or '\t'
+//                        doubleToCommaString(buffer, r);
+//                        fprintf(file, "%c%s", separator, buffer);
+//                    }
+//                    break;
+//                case elm_Integer:
+//                case elm_Enumeration:
+//                    fmu->getInteger(c, &vr, 1, &i);
+//                    fprintf(file, "%c%d", separator, i);
+//                    break;
+//                case elm_Boolean:
+//                    fmu->getBoolean(c, &vr, 1, &b);
+//                    fprintf(file, "%c%d", separator, b);
+//                    break;
+//                case elm_String:
+//                    fmu->getString(c, &vr, 1, &s);
+//                    fprintf(file, "%c%s", separator, s);
+//                    break;
+//                default:
+//                    fprintf(file, "%cNoValueForType=%d", separator, getElementType(getTypeSpec(sv)));
+//            }
+//        }
+//    } // for
+//
+//    // terminate this row
+//    fprintf(file, "\n");
+//}
+//
+static const char* fmi2StatusToString(fmi2Status status){
+    switch (status){
+        case fmi2OK:      return "ok";
+        case fmi2Warning: return "warning";
+        case fmi2Discard: return "discard";
+        case fmi2Error:   return "error";
+        case fmi2Fatal:   return "fatal";
+    #ifdef FMI_COSIMULATION
+        case fmi2Pending: return "fmi2Pending";
+    #endif
+        default:         return "?";
+    }
+}
+
+// search a fmu for the given variable, matching the type specified.
+// return NULL if not found
+//static ScalarVariable* getSV(FMU* fmu, char type, fmi2ValueReference vr) {
+//    return NULL;
+//    int i;
+//    int n = getScalarVariableSize(fmu->modelDescription);
+//    Elm tp;
+//
+//    switch (type) {
+//        case 'r': tp = elm_Real;    break;
+//        case 'i': tp = elm_Integer; break;
+//        case 'b': tp = elm_Boolean; break;
+//        case 's': tp = elm_String;  break;
+//        default : tp = elm_BAD_DEFINED;
+//    }
+//    for (i = 0; i < n; i++) {
+//        ScalarVariable* sv = getScalarVariable(fmu->modelDescription ,i);
+//        if (vr == getValueReference(sv) && tp == getElementType(getTypeSpec(sv))) {
+//            return sv;
+//        }
+//    }
+//    return NULL;
+//}
+
+// replace e.g. #r1365# by variable name and ## by # in message
+// copies the result to buffer
+static void replaceRefsInMessage(const char* msg, char* buffer, int nBuffer, FMU* fmu){
+    int i = 0; // position in msg
+    int k = 0; // position in buffer
+    int n;
+    char c = msg[i];
+    while (c != '\0' && k < nBuffer) {
+        if (c != '#') {
+            buffer[k++] = c;
+            i++;
+            c = msg[i];
+        } else {
+
+            char* end = strchr(msg + i + 1, '#');
+            if (!end) {
+                printf("unmatched '#' in '%s'\n", msg);
+                buffer[k++] = '#';
+                break;
+            }
+            n = end - (msg + i);
+            if (n == 1) {
+                // ## detected, output #
+                buffer[k++] = '#';
+                i += 2;
+                c = msg[i];
+
+            } else {
+                char type = msg[i + 1]; // one of ribs
+                fmi2ValueReference vr;
+                int nvr = sscanf(msg + i + 2, "%u", &vr);
+                if (nvr == 1) {
+                    // vr of type detected, e.g. #r12#
+                    //ScalarVariable* sv = getSV(fmu, type, vr);
+                    //const char* name = sv ? getAttributeValue((Element *)sv, att_name) : "?";
+                    //sprintf(buffer + k, "%s", name);
+                    //k += strlen(name);
+                    //i += (n+1);
+                    //c = msg[i];
+
+                } else {
+                    // could not parse the number
+                    printf("illegal value reference at position %d in '%s'\n", i + 2, msg);
+                    buffer[k++] = '#';
+                    break;
+                }
+            }
+        }
+    } // while
+    buffer[k] = '\0';
+}
+
+#define MAX_MSG_SIZE 1000
+void fmuLogger(void *componentEnvironment, fmi2String instanceName, fmi2Status status,
+               fmi2String category, fmi2String message, ...) {
+    char msg[MAX_MSG_SIZE];
+    char* copy;
+    va_list argp;
+
+    // replace C format strings
+    va_start(argp, message);
+    vsprintf(msg, message, argp);
+    va_end(argp);
+
+    // replace e.g. ## and #r12#
+    copy = strdup(msg);
+//    replaceRefsInMessage(copy, msg, MAX_MSG_SIZE, NULL);
+    free(copy);
+
+    // print the final message
+    if (!instanceName) instanceName = "?";
+    if (!category) category = "?";
+    printf("%s %s (%s): %s\n", fmi2StatusToString(status), instanceName, category, msg);
+}
+
+int error(const char* message){
+    printf("%s\n", message);
+    return 0;
+}
+//
+//void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tEnd, double *h,
+//                    int *loggingOn, char *csv_separator, int *nCategories, char **logCategories[]) {
+//    // parse command line arguments
+//    if (argc > 1) {
+//        *fmuFileName = argv[1];
+//    } else {
+//        printf("error: no fmu file\n");
+//        printHelp(argv[0]);
+//        exit(EXIT_FAILURE);
+//    }
+//    if (argc > 2) {
+//        if (sscanf(argv[2],"%lf", tEnd) != 1) {
+//            printf("error: The given end time (%s) is not a number\n", argv[2]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 3) {
+//        if (sscanf(argv[3],"%lf", h) != 1) {
+//            printf("error: The given stepsize (%s) is not a number\n", argv[3]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 4) {
+//        if (sscanf(argv[4],"%d", loggingOn) != 1 || *loggingOn < 0 || *loggingOn > 1) {
+//            printf("error: The given logging flag (%s) is not boolean\n", argv[4]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 5) {
+//        if (strlen(argv[5]) != 1) {
+//            printf("error: The given CSV separator char (%s) is not valid\n", argv[5]);
+//            exit(EXIT_FAILURE);
+//        }
+//        switch (argv[5][0]) {
+//            case 'c': *csv_separator = ','; break; // comma
+//            case 's': *csv_separator = ';'; break; // semicolon
+//            default:  *csv_separator = argv[5][0]; break; // any other char
+//        }
+//    }
+//    if (argc > 6) {
+//        int i;
+//        *nCategories = argc - 6;
+//        *logCategories = (char **)calloc(sizeof(char *), *nCategories);
+//        for (i = 0; i < *nCategories; i++) {
+//            (*logCategories)[i] = argv[i + 6];
+//        }
+//    }
+//}
+//
+//void printHelp(const char *fmusim) {
+//    printf("command syntax: %s <model.fmu> <tEnd> <h> <loggingOn> <csv separator>\n", fmusim);
+//    printf("   <model.fmu> .... path to FMU, relative to current dir or absolute, required\n");
+//    printf("   <tEnd> ......... end  time of simulation,   optional, defaults to 1.0 sec\n");
+//    printf("   <h> ............ step size of simulation,   optional, defaults to 0.1 sec\n");
+//    printf("   <loggingOn> .... 1 to activate logging,     optional, defaults to 0\n");
+//    printf("   <csv separator>. separator in csv file,     optional, c for ',', s for';', defaults to c\n");
+//    printf("   <logCategories>. list of active categories, optional, see modelDescription.xml for possible values\n");
+//}

+ 44 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_algorithm/sim_support.h

@@ -0,0 +1,44 @@
+/* ------------------------------------------------------------------------- 
+ * sim_support.h
+ * Functions used by the FMU simulations fmusim_me and fmusim_cs.
+ * Copyright QTronic GmbH. All rights reserved.
+ * -------------------------------------------------------------------------*/
+#ifndef __SIM_SUPPORT_H
+#define __SIM_SUPPORT_H
+
+// Used 7z options, version 4.57:
+// -x   Extracts files from an archive with their full paths in the current dir, or in an output dir if specified
+// -aoa Overwrite All existing files without prompt
+// -o   Specifies a destination directory where files are to be extracted
+#define UNZIP_CMD "7z x -aoa -o"
+#define XML_FILE  "modelDescription.xml"
+#define RESULT_FILE "result.csv"
+#define BUFSIZE 4096
+#ifdef _WIN64
+#define DLL_DIR   "binaries\\win64\\"
+#else
+#define DLL_DIR   "binaries\\win32\\"
+#endif
+#define RESOURCES_DIR "resources\\"
+
+// return codes of the 7z command line tool
+#define SEVEN_ZIP_NO_ERROR 0 // success
+#define SEVEN_ZIP_WARNING 1  // e.g., one or more files were locked during zip
+#define SEVEN_ZIP_ERROR 2
+#define SEVEN_ZIP_COMMAND_LINE_ERROR 7
+#define SEVEN_ZIP_OUT_OF_MEMORY 8
+#define SEVEN_ZIP_STOPPED_BY_USER 255
+
+void fmuLogger(fmi2Component c, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message, ...);
+int unzip(const char *zipPath, const char *outPath);
+void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tEnd, double *h,
+                    int *loggingOn, char *csv_separator, int *nCategories, char **logCategories[]);
+void loadFMU(const char *fmuFileName);
+int loadDll(const char* dllPath, FMU *fmu, const char* preamble);
+void deleteUnzippedFiles();
+void outputRow(FMU *fmu, fmi2Component c, double time, FILE* file, char separator, fmi2Boolean header);
+int error(const char *message);
+void printHelp(const char *fmusim);
+char *getTempResourcesLocation(); // caller has to free the result
+
+#endif

File diff suppressed because it is too large
+ 125 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/.cproject


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/FMI_CM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/FMI_GM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/FMI_SEL.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/libFMI_SEL.dll


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/libFMI_control_master.dll


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_generic_master/Debug/sim_support.o


File diff suppressed because it is too large
+ 134 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/.cproject


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/Debug/FMI_CM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/Debug/FMI_GM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/Debug/FMI_SEL.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/Debug/FMI_power_sa.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/Debug/sim_support.o


+ 637 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/FMI_loop_sa.c

@@ -0,0 +1,637 @@
+/* ---------------------------------------------------------------------------*
+ * Sample implementation of an generic master FMU -
+ * ---------------------------------------------------------------------------*/
+/*
+Template for a  FMU
+ */
+
+#define MODEL_IDENTIFIER GM
+#define MODEL_GUID "{41f87101-edf2-4eef-90f3-42db56d4565f}"
+#define FMI2_FUNCTION_PREFIX POWER_SA
+
+
+#include <stdio.h>
+#include "string.h"
+#include "fmi2Functions.h"
+#include <float.h>
+#include "FMI_loop_sa.h"
+#include <math.h>
+#include "fmi2.h"
+#include "sim_support.h"
+
+
+#define MAX 100000
+
+#define NUMBER_OF_REALS 3
+#define NUMBER_OF_STRINGS 0
+#define NUMBER_OF_BOOLEANS 0
+#define NUMBER_OF_INTEGERS 0
+
+#define MAXITER 10
+#define REL_TOL 1e-05
+#define ABS_TOL 1e-05
+
+#define _out_tau 0
+#define _in_speed 1
+#define _in_displacement 2
+
+
+double relativeError(double a, double b){
+	return fabs((a - b) / a);
+}
+
+/*
+ * Helper function for absolute error
+ */
+double absoluteError(double a, double b){
+	return fabs(a - b);
+}
+
+/*
+ * is_close function for double comparison
+ */
+int is_close(double a, double b, double rel_tol, double abs_tol){
+	return ((absoluteError(a,b)<abs_tol) && (relativeError(a,b)<rel_tol));
+}
+
+fmi2Status fmi2SetDebugLogging(fmi2Component fc, fmi2Boolean loggingOn, size_t nCategories, const fmi2String categories[])
+{
+	return fmi2OK;
+}
+
+fmi2Status fmi2SetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2String value[])
+{
+	FMUInstance*  comp = (FMUInstance *)fc;
+
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2String value[])
+{
+	return fmi2Error;
+}
+
+fmi2Status fmi2SetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Real value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		comp->r[vr[i]] = value[i];
+	}
+	//out_condition_executed := empty map
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2OK;
+}
+
+fmi2Status fmi2GetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Real value[])
+{
+
+	FMUInstance* comp = (FMUInstance *)fc;
+
+	int isEmpty = 1;
+	for (int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		if(comp->out_conditions_executed[i] !=0){
+			isEmpty = 0;
+			break;
+		}
+	}
+
+	/*Eval conditions:*/
+	if(1){
+		comp->out_conditions_executed[0] = 1;
+	}
+
+	if (isEmpty){
+		for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+			if(comp->out_conditions_executed[i]){
+
+			}
+		}
+	}
+	for (int i = 0; i < nvr; i++)
+	{
+		value[i] = comp->r[(vr[i])];
+	}
+
+	return fmi2OK;
+}
+
+fmi2Status fmi2SetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Boolean value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		comp->b[vr[i]] = value[i];
+	}
+	/*Generated: */
+		fmi2Boolean in_condition[_NR_OF_IN_CONDITIONS];
+		/*Condition checking:*/
+		// true
+		in_condition[0] = 1;
+
+		if(in_condition[0]){
+			/* If mealy do update_in and recursive call */
+		}
+		return fmi2OK;
+
+	//out_condition_executed := empty map
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2OK;
+}
+
+fmi2Status fmi2GetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Boolean value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		value[i] = comp->b[vr[i]];
+	}
+	return fmi2OK;
+}
+
+fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2String fmuGUID, fmi2String fmuLocation, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+
+	//Declare data structure for fmu instance
+	FMUInstance* fi;
+	printf("%s in fmiInstantiate\n",instanceName);
+
+	//Perform checks on passed callback functions
+	if (loggingOn) {
+
+		if (!functions->logger);
+		//return NULL;
+	}
+	//Check for instanceName
+	if (!instanceName || strlen(instanceName)==0) {
+
+		// print (and/or log) instanceName is missing
+		//return NULL;
+	}
+	//Check passed GUID to defined model GUID
+	if (strcmp(fmuGUID, MODEL_GUID))
+	{
+		// print (and/or log) GUID doesn't match
+		//return NULL;
+	}
+
+	//Allocate fmu instance Memory
+	// TODO check if "canNotUseMemoryManagementFunctions == true/false". If false memory allocation not possible
+	fi = (FMUInstance *)functions->allocateMemory(1, sizeof(FMUInstance));
+	if (fi) {
+		// Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
+		fi->r = functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
+		fi->i = functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
+		fi->b = functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
+		fi->s = functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
+	} // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
+
+
+	fi->instanceName = functions->allocateMemory(1 + strlen(instanceName), sizeof(char));
+	fi->GUID = functions->allocateMemory(1 + strlen(fmuGUID), sizeof(char));
+
+	strcpy((char*)fi->instanceName, instanceName);
+	strcpy((char*)fi->GUID, fmuGUID);
+	fi->functions = functions;
+	fi->loggingOn = loggingOn;
+	fi->isVisible = visible;
+	fi->state = fmuInstantiated;
+	/* Load the inner FMUs:*/
+
+	loadDll("libFMI_Window_sa.dll", &(fi->fmu[0]), "WINDOW_SA");
+	fi->fmuResourceLocation[0] = "libFMI_Window_sa";
+	loadDll("Obstacle.dll", &(fi->fmu[1]),"");
+	fi->fmuResourceLocation[1] = "Obstacle.dll";
+
+	fi->fmu_guid[0]= functions->allocateMemory(1 + strlen("1"), sizeof(char));
+	fi->fmu_guid[1] = functions->allocateMemory(1 + strlen("{c6327117-e5f2-4e48-abcd-318439d1e7c4}"), sizeof(char));
+	strcpy(fi->fmu_guid[0], "1");
+	strcpy(fi->fmu_guid[1], "{c6327117-e5f2-4e48-abcd-318439d1e7c4}");
+
+	/*Instantiate inner components*/
+	for (int i=0; i<1; i++){
+		fi->c_fmu[i] = fi->fmu[i].instantiate("inner", fmi2CoSimulation, fi->fmu_guid[i], fi->fmuResourceLocation[i] , fi->functions, visible, 0);
+	}
+	return fi;
+}
+
+fmi2Status fmi2SetupExperiment(fmi2Component fc, fmi2Boolean toleranceDefined, fmi2Real tolerance,
+		fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) {
+
+
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiSetupExperiment\n",fi->instanceName);
+	if (fi->state != fmuInstantiated)
+	{
+		printf("fmu: %s was not instatiated before calling fmiSetupExperiment\n", fi->instanceName);
+		return fmi2Error;
+	}
+	fi->currentTime = startTime;
+	fi->stopTimeDefined = stopTimeDefined;
+	fi->toleranceDefined = toleranceDefined;
+	if (stopTimeDefined)
+	{
+		fi->stopTime = stopTime;
+	}
+	/*
+	 * setup inner
+	 */
+	fmi2Status fmi2Flag = fmi2OK;
+	fi->state = fmuExperimentSettedUp;
+	for(int i=0; i<1; i++){
+		fmi2Flag = fi->fmu[i].setupExperiment(fi->c_fmu[i], toleranceDefined, tolerance, startTime, fmi2True, stopTime);
+		if (fmi2Flag == fmi2Error){
+			fi->state = fmuError;
+		}
+	}
+
+	fi->prev_disp = 0;
+
+	return fmi2Flag;
+}
+
+fmi2Status fmi2EnterInitializationMode(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiEnterInitializationMode\n",fi->instanceName);
+	if (fi->state != fmuExperimentSettedUp)
+	{
+		printf("fmu: %s experiment was not set-up before calling fmiEnterInitializationMode\n", fi->instanceName);
+		return fmi2Error;
+	}
+	fi->state = fmuInitMode;
+	fmi2Status fmi2Flag = fmi2OK;
+	for(int i=0; i<1; i++){
+		fmi2Flag = fi->fmu[i].enterInitializationMode(fi->c_fmu[i]);
+		if (fmi2Flag == fmi2Error){
+			return fi->state = fmuError;
+		}
+	}
+	return fmi2Flag;
+}
+
+fmi2Status fmi2ExitInitializationMode(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiExitInitializationMode\n",fi->instanceName);
+	if (fi->state != fmuInitMode)
+	{
+		printf("fmu: %s did not enter Initialization Mode before calling fmiExitInitializationMode\n", fi->instanceName);
+		return fmi2Error;
+	}
+	// TODO
+	//initStatus = calculateInitialUnknownValues();
+	//initialize();
+	fi->state = fmuInitialized;
+	fmi2Status fmi2Flag = fmi2OK;
+	for(int i=0; i<1;i++){
+		fmi2Flag = fi->fmu[i].exitInitializationMode(fi->c_fmu[i]);
+		if (fmi2Flag == fmi2Error){
+			return fi->state = fmuError;
+		}
+	}
+	return fmi2Flag;
+}
+
+static fmi2Status DoInnerStep(fmi2Component fc, int index, fmi2Real currentCommPoint, fmi2Real commStepSize){
+	fmi2Status status = fmi2OK;
+	FMUInstance* fi = (FMUInstance *)fc;
+
+	fmi2Real dt =currentCommPoint - fi->time_last_fmu[index];
+	fmi2Real h = commStepSize + dt;
+	int repeat = 0;
+	for (int iter= 0; iter< MAXITER; iter++) {
+		save_state(obstacle);
+		save_state(window_sa);
+		obstacle.disp := prev_disp; do_step(obstacle,t,H); do_step(window_sa,t,H);
+	repeat := is_close(prev_disp, window_sa.disp, REL_TOL, ABS_TOL); prev_disp := window_sa.disp;
+	if (repeat) {
+	break; } else {
+	rollback(obstacle);
+	rollback(window_sa);
+	}
+	return status;
+}
+
+fmi2Status fmi2DoStep(fmi2Component fc , fmi2Real currentCommPoint, fmi2Real commStepSize, fmi2Boolean noPrevFMUState)
+{
+	FMUInstance* fi = (FMUInstance *)fc;
+	fmi2Status simStatus = fmi2OK;
+	printf("%s in fmiDoStep(), ct:%f, h:%f\n",fi->instanceName,currentCommPoint,commStepSize);
+	memset(fi->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+
+
+	/*
+	Calculate the elapsed time since the last transition
+	*/
+	fmi2Real e = MAX;
+	fmi2Real elapsed_fmu[_NR_OF_FMUS];
+	for (int i=0; i<_NR_OF_FMUS; i++){
+		elapsed_fmu[i] = currentCommPoint - fi->time_last_fmu[i];
+		e = (elapsed_fmu[i]<e)? elapsed_fmu[i]:e;
+	}
+
+	if(1){
+		simStatus= DoInnerStep(fc,0,currentCommPoint,commStepSize);
+	}
+
+	memset(fi->in_condition_executed, 0, sizeof(fmi2Boolean)*_NR_OF_IN_CONDITIONS);
+	return simStatus;
+}
+
+fmi2Status fmi2Terminate(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance *)fc;
+	printf("%s in fmiTerminate\n",fi->instanceName);
+	// do check if fi may be terminated
+	for (int i=0;i<1;i++){
+		fi->fmu[i].terminate(fi->c_fmu[i]);
+	}
+
+	fi->state = fmuTerminated;
+	return fmi2OK;
+}
+
+
+void fmi2FreeInstance(fmi2Component fc)
+{
+
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiFreeInstance\n",fi->instanceName);
+	for(int i=0;i<1;i++){
+		fi->fmu[i].freeInstance(fi->c_fmu[i]);
+	}
+
+	if (fi) {
+		fi->functions->freeMemory(fi->r);
+		fi->functions->freeMemory(fi->i);
+		fi->functions->freeMemory(fi->b);
+		fi->functions->freeMemory(fi->s);// TODO has to be done with loop
+		fi->functions->freeMemory((void*)fi->instanceName);
+		fi->functions->freeMemory((void*)fi->GUID);
+		fi->functions->freeMemory((void*)fi);
+
+	}
+}
+
+//To be implemented
+
+const char* fmi2GetVersion() {
+	printf("Function fmiGetVersion not supported\n");
+	return NULL;
+}
+
+const char* fmi2GetTypesPlatform() {
+	printf("Function fmiGetTypesPlatform not supported\n");
+	return NULL;
+}
+
+fmi2Status fmi2Reset(fmi2Component fc)
+{
+	printf("Function fmiReset not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2SetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Integer value[])
+{
+	FMUInstance * comp = (FMUInstance*) fc;
+	printf("Function fmiSetInteger not supported\n");
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[])
+{
+	printf("Function fmiGetInteger not supported\n");
+	return fmi2Error;
+}
+
+
+/*******OWN IMPLEMENTATION OF Get/Set FMU state*******/
+fmi2Status fmi2GetFMUstate (fmi2Component c, fmi2FMUstate* FMUstate) {
+	FMUInstance* orig = (FMUInstance*)c;
+	FMUInstance* fi = (FMUInstance *)FMUstate;
+	*FMUstate = fi;
+	fi = orig->functions->allocateMemory(1, sizeof(FMUInstance));
+	*FMUstate = fi;
+	fi->functions = orig->functions;
+
+	if (fi) {
+		// Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
+		fi->r = fi->functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
+		fi->i = fi->functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
+		fi->b = fi->functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
+		fi->s = fi->functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
+
+	} // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
+	fi->instanceName = orig->functions->allocateMemory(1 + strlen(orig->instanceName), sizeof(char));
+	fi->GUID = orig->functions->allocateMemory(1 + strlen(orig->GUID), sizeof(char));
+
+	strcpy((char *)fi->instanceName, (char *)orig->instanceName);
+	strcpy((char *)fi->GUID, (char *)orig->GUID);
+	fi->functions = orig->functions;
+	fi->loggingOn = orig->loggingOn;
+	fi->isVisible = orig->isVisible;
+	fi->state = orig->state;
+	fi->startTime = orig->startTime;
+	fi->stopTime = orig->stopTime;
+	fi->currentTime = orig->currentTime;
+	/* TODO: Store all the rest here.*/
+	fi->fmu[0] = orig->fmu[0];
+	fi->c_fmu[0] = orig->c_fmu[0];
+	for(int i=0; i<_NR_OF_IN_CONDITIONS;i++){
+		fi->in_condition_executed[i] = orig->in_condition_executed[i];
+	}
+	for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		fi->out_conditions_executed[i] = orig->out_conditions_executed[i];
+	}
+	for(int i=0;i<_NR_OF_FMUS;i++){
+		fi->time_last_fmu[i] = orig->time_last_fmu[i];
+	}
+
+	/* Generated */
+	fi->stored_windowsa_u = orig->stored_windowsa_u;
+	fi->stored_windowsa_d = orig->stored_windowsa_d;
+	fi->stored_tau = orig->stored_tau;
+	fi->stored_armature_current = orig->stored_armature_current;
+	fi->stored_speed = orig->stored_speed;
+	fi->stored_displacement = orig->stored_displacement;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+	/*
+	 * This is a hierarchical call. First let the lower FMUs do their state saving
+	 * We will store the saved fmu state in the fi->c_order[i]
+	 */
+	for(int i=0;i<1;i++){
+		fi->fmu[i]=orig->fmu[i];
+		orig->fmu[i].getFMUstate(orig->c_fmu[i],fi->c_fmu[i]);
+		fi->fmuResourceLocation[i] = fi->functions->allocateMemory(1+strlen(orig->fmuResourceLocation[i]), sizeof(char));
+		strcpy((char *)fi->fmuResourceLocation[i],(char *)orig->fmuResourceLocation[i]);
+		/*make shallow copies of the stored fmus*/
+	}
+	//copy r
+	int i=0;
+	for (i=0; i< NUMBER_OF_REALS;i++){
+		printf("Setting real: %i %f\n", i, orig->r[i]);
+		fi->r[i] = orig->r[i];
+		printf("Setted real: %i %f\n", i, fi->r[i]);
+	}
+	//copy s
+	for (i=0; i< NUMBER_OF_STRINGS;i++){
+		//fi->s[i] = orig->s[i]; // why are this not deep copies?
+		fi->s[i] = fi->functions->allocateMemory(1+strlen(orig->s[i]),sizeof(char));
+		strcpy((char *)fi->s[i],(char *)orig->s[i]);
+	}
+	//copy i
+	for (i=0; i< NUMBER_OF_INTEGERS;i++){
+		fi->i[i] = orig->i[i];
+	}
+	//copy b
+	for (i=0; i< NUMBER_OF_BOOLEANS;i++){
+		fi->b[i] = orig->b[i];
+	}
+	return fmi2OK;
+}
+
+fmi2Status fmi2SetFMUstate (fmi2Component c, fmi2FMUstate FMUstate) {
+	FMUInstance* orig = (FMUInstance*)FMUstate;
+	FMUInstance* fi = (FMUInstance*)c;
+	/*
+	 * First restore the hierarchical fmus.
+	 */
+	for(int i=0;i<1;i++){
+		fi->fmu[i].setFMUstate(fi->c_fmu[i],orig->c_fmu[i]);
+		fi->fmuResourceLocation[i] = orig->functions->allocateMemory(1+strlen(orig->fmuResourceLocation[i]), sizeof(char));
+		strcpy((char *)fi->fmuResourceLocation[i],(char *)orig->fmuResourceLocation[i]);
+	}
+
+	//set time etc correct, name and GUID should still be ok ;-)
+	printf("setting time values from %f to %f\n", fi->currentTime, orig->currentTime);
+	fi->state = orig->state;
+	fi->startTime = orig->startTime;
+	fi->stopTime = orig->stopTime;
+	fi->currentTime = orig->currentTime;
+
+	fi->fmu[0] = orig->fmu[0];
+	fi->c_fmu[0] = orig->c_fmu[0];
+	for(int i=0; i<_NR_OF_IN_CONDITIONS;i++){
+		fi->in_condition_executed[i] = orig->in_condition_executed[i];
+	}
+	for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		fi->out_conditions_executed[i] = orig->out_conditions_executed[i];
+	}
+	for(int i=0;i<_NR_OF_FMUS;i++){
+		fi->time_last_fmu[i] = orig->time_last_fmu[i];
+	}
+
+	/* Generated */
+	fi->stored_windowsa_u = orig->stored_windowsa_u;
+	fi->stored_windowsa_d = orig->stored_windowsa_d;
+	fi->stored_tau = orig->stored_tau;
+	fi->stored_armature_current = orig->stored_armature_current;
+	fi->stored_speed = orig->stored_speed;
+	fi->stored_displacement = orig->stored_displacement;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+	printf("setting real values\n");
+	//copy r
+	int i=0;
+	for (i=0; i< NUMBER_OF_REALS;i++){
+		fi->r[i] = orig->r[i];
+	}
+	printf("setting string values\n");
+	//copy s
+	for (i=0; i< NUMBER_OF_STRINGS;i++){
+
+		fi->s[i] = orig->s[i];
+	}
+	//copy i
+	for (i=0; i< NUMBER_OF_INTEGERS;i++){
+		fi->i[i] = orig->i[i];
+	}
+	//copy b
+	for (i=0; i< NUMBER_OF_BOOLEANS;i++){
+		fi->b[i] = orig->b[i];
+	}
+	return fmi2OK;
+
+
+}
+/****************************************************/
+
+fmi2Status fmi2FreeFMUstate(fmi2Component c, fmi2FMUstate* FMUstate) {
+	printf("Function fmiFreeFMUstate not supported\n");
+	return fmi2Error;
+}
+fmi2Status fmi2SerializedFMUstateSize(fmi2Component c, fmi2FMUstate FMUstate, size_t *size) {
+	printf("Function fmiSerializedFMUstateSize not supported\n");
+	return fmi2Error;
+}
+fmi2Status fmi2SerializeFMUstate (fmi2Component c, fmi2FMUstate FMUstate, fmi2Byte serializedState[], size_t size) {
+	printf("Function fmiSerializeFMUstate not supported\n");
+	return fmi2Error;
+}
+fmi2Status fmi2DeSerializeFMUstate (fmi2Component c, const fmi2Byte serializedState[], size_t size, fmi2FMUstate* FMUstate) {
+	printf("Function fmiDeSerializeFMUstate not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetDirectionalDerivative(fmi2Component c, const fmi2ValueReference vUnknown_ref[], size_t nUnknown,
+		const fmi2ValueReference vKnown_ref[] , size_t nKnown, const fmi2Real dvKnown[], fmi2Real dvUnknown[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+
+fmi2Status fmi2SetRealInputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
+		const fmi2Integer order[], const fmi2Real value[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetRealOutputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
+		const fmi2Integer order[], fmi2Real value[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2CancelStep(fmi2Component c) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetStatus(fmi2Component c, const fmi2StatusKind s, fmi2Status *value) {
+	printf("Function fmiGetStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetRealStatus(fmi2Component c, const fmi2StatusKind s, fmi2Real *value) {
+	if(s == fmi2LastSuccessfulTime){
+		FMUInstance* comp = (FMUInstance*) c;
+		*value = comp->currentTime;
+		return fmi2OK;
+	}
+	printf("Function fmiGetRealStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetIntegerStatus(fmi2Component c, const fmi2StatusKind s, fmi2Integer *value) {
+	printf("Function fmiGetIntegerStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetBooleanStatus(fmi2Component c, const fmi2StatusKind s, fmi2Boolean *value) {
+	printf("Function fmiGetBooleanStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetStringStatus(fmi2Component c, const fmi2StatusKind s, fmi2String *value) {
+	printf("Function fmiGetStringStatus not supported\n");
+	return fmi2Error;
+}

+ 58 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/FMI_loop_sa.h

@@ -0,0 +1,58 @@
+/*
+ * PW_Controller.h
+ *
+ *  Created on: Jan 25, 2017
+ *      Author: Joachim
+ */
+
+#ifndef FMI_LOOP_SA_H_
+#define FMI_LOOP_SA_H_
+
+#include "fmi2.h"
+
+typedef enum {
+    fmuInstantiated = 0,
+    fmuInitMode  = 1,
+	fmuInitialized = 2,
+    fmuTerminated   = 3,
+    fmuError        = 4,
+    fmuExperimentSettedUp = 5
+} FMUState;
+
+#define _NR_OF_FMUS 2
+#define _NR_OF_IN_CONDITIONS 1
+#define _NR_OF_OUT_CONDITIONS 1
+
+typedef struct {
+	fmi2Real    *r;
+    fmi2Integer *i;
+    fmi2Boolean *b;
+    fmi2String  *s;
+    fmi2Boolean isVisible;
+    fmi2String instanceName;
+    fmi2String GUID;
+    const fmi2CallbackFunctions* functions;
+    fmi2Boolean loggingOn;
+    FMUState state;
+    fmi2Real startTime;
+    fmi2Real stopTime;
+	fmi2Real currentTime;
+    fmi2Boolean stopTimeDefined;
+    fmi2Boolean toleranceDefined;
+    /* for generic algo*/
+    FMU fmu[_NR_OF_FMUS];
+    char *fmuResourceLocation[_NR_OF_FMUS];
+    char *fmu_guid[_NR_OF_FMUS];
+    fmi2Component c_fmu[_NR_OF_FMUS];
+    fmi2Boolean in_condition_executed[_NR_OF_IN_CONDITIONS];
+    fmi2Boolean out_conditions_executed[_NR_OF_OUT_CONDITIONS];
+    fmi2Real time_last_fmu[_NR_OF_FMUS];
+    /* Generated */
+	fmi2Real prev_disp;
+
+} FMUInstance; // At the moment, most of the variables not really used since multiple instances of an FMU are not supported at the moment (performance issues)
+
+
+
+
+#endif /* FMI_LOOP_SA_H_ */

+ 72 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/fmi2/fmi2.h

@@ -0,0 +1,72 @@
+/* -------------------------------------------------------------------------
+ * 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 "fmi2Functions.h"
+
+typedef struct {
+//    ModelDescription* modelDescription;
+
+    void  *dllHandle; // fmu.so 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
+

+ 247 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/fmi2/fmi2FunctionTypes.h

@@ -0,0 +1,247 @@
+#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 (C) 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);
+#ifdef FMU_EXPERIMENTAL
+   typedef fmi2Status fmi2GetSpecificDerivativesTYPE       (fmi2Component, fmi2Real[], const fmi2ValueReference [], size_t);
+#endif
+
+   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 */

+ 339 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/fmi2/fmi2Functions.h

@@ -0,0 +1,339 @@
+#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 (C) 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)
+#ifdef FMU_EXPERIMENTAL
+#define fmi2GetSpecificDerivatives        fmi2FullName(fmi2GetSpecificDerivatives)
+#endif
+#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;
+#ifdef FMU_EXPERIMENTAL
+   FMI2_Export fmi2GetSpecificDerivativesTYPE        fmi2GetSpecificDerivatives;
+#endif
+   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/fmu/cs/FMI_loop_sa/fmi2/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 (C) 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 */

+ 594 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/sim_support.c

@@ -0,0 +1,594 @@
+/* -------------------------------------------------------------------------
+ * sim_support.c
+ * Functions used by both FMU simulators fmu20sim_me and fmu20sim_cs
+ * to parse command-line arguments, to unzip and load an fmu,
+ * to write CSV file, and more.
+ *
+ * Revision history
+ *  07.03.2014 initial version released in FMU SDK 2.0.0
+ *  10.04.2014 use FMI 2.0 headers that prefix function and type names with 'fmi2'.
+ *             When 'fmi2' functions are not found in loaded DLL, look also for
+ *             FMI 2.0 RC1 function names.
+ *
+ * Author: Adrian Tirea
+ * Copyright QTronic GmbH. All rights reserved.
+ * -------------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <stdarg.h>
+#include <dlfcn.h>
+#include "fmi2.h"
+#include "sim_support.h"
+
+#define FMI_COSIMULATION
+extern FMU fmu;
+
+
+//int unzip(const char *zipPath, const char *outPath) {
+//    int code;
+//    char cwd[BUFSIZE];
+//    char binPath[BUFSIZE];
+//    int n = strlen(UNZIP_CMD) + strlen(outPath) + 3 +  strlen(zipPath) + 9;
+//    char* cmd = (char*)calloc(sizeof(char), n);
+//
+//    // remember current directory
+//    if (!GetCurrentDirectory(BUFSIZE, cwd)) {
+//        printf ("error: Could not get current directory\n");
+//        return 0; // error
+//    }
+//
+//    // change to %FMUSDK_HOME%\bin to find 7z.dll and 7z.exe
+//    if (!GetEnvironmentVariable("FMUSDK_HOME", binPath, BUFSIZE)) {
+//        if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
+//            printf ("error: Environment variable FMUSDK_HOME not defined\n");
+//        }
+//        else {
+//            printf ("error: Could not get value of FMUSDK_HOME\n");
+//        }
+//        return 0; // error
+//    }
+//    strcat(binPath, "\\bin");
+//    if (!SetCurrentDirectory(binPath)) {
+//        printf ("error: could not change to directory '%s'\n", binPath);
+//        return 0; // error
+//    }
+//
+//    // run the unzip command
+//    // remove "> NUL" to see the unzip protocol
+//    sprintf(cmd, "%s\"%s\" \"%s\" > NUL", UNZIP_CMD, outPath, zipPath);
+//    // printf("cmd='%s'\n", cmd);
+//    code = system(cmd);
+//    free(cmd);
+//    if (code != SEVEN_ZIP_NO_ERROR) {
+//        printf("7z: ");
+//        switch (code) {
+//            case SEVEN_ZIP_WARNING:            printf("warning\n"); break;
+//            case SEVEN_ZIP_ERROR:              printf("error\n"); break;
+//            case SEVEN_ZIP_COMMAND_LINE_ERROR: printf("command line error\n"); break;
+//            case SEVEN_ZIP_OUT_OF_MEMORY:      printf("out of memory\n"); break;
+//            case SEVEN_ZIP_STOPPED_BY_USER:    printf("stopped by user\n"); break;
+//            default: printf("unknown problem\n");
+//        }
+//    }
+//
+//    // restore current directory
+//    SetCurrentDirectory(cwd);
+//    return (code == SEVEN_ZIP_NO_ERROR || code == SEVEN_ZIP_WARNING) ? 1 : 0;
+//}
+//
+//// fileName is an absolute path, e.g. C:\test\a.fmu
+//// or relative to the current dir, e.g. ..\test\a.fmu
+//// Does not check for existence of the file
+//static char* getFmuPath(const char* fileName){
+//    char pathName[MAX_PATH];
+//    int n = GetFullPathName(fileName, MAX_PATH, pathName, NULL);
+//    return n ? strdup(pathName) : NULL;
+//}
+//
+//static char* getTmpPath() {
+//    char tmpPath[BUFSIZE];
+//    if(! GetTempPath(BUFSIZE, tmpPath)) {
+//        printf ("error: Could not find temporary disk space\n");
+//        return NULL;
+//    }
+//    strcat(tmpPath, "fmu\\");
+//    return strdup(tmpPath);
+//}
+//
+//char *getTempResourcesLocation() {
+//    char *tempPath = getTmpPath();
+//    char *resourcesLocation = (char *)calloc(sizeof(char), 9 + strlen(RESOURCES_DIR) + strlen(tempPath));
+//    strcpy(resourcesLocation, "file:///");
+//    strcat(resourcesLocation, tempPath);
+//    strcat(resourcesLocation, RESOURCES_DIR);
+//    free(tempPath);
+//    return resourcesLocation;
+//}
+
+static void *getAdr(int *success, void *dllHandle, const char *functionName, const char* preamble) {
+
+    int length = strlen(preamble) + strlen(functionName) + 1;
+    char* new_name = malloc(length);  // allocate memory
+    strcpy(new_name, preamble);  // copy first string
+    strcat(new_name, functionName);
+    void* fp = dlsym(dllHandle, new_name);
+    if (!fp) {
+        printf("warning: Function %s not found in dll\n", new_name);
+        *success = 0;
+    }
+    free(new_name);
+    return fp;
+}
+
+// Load the given dll and set function pointers in fmu
+// Return 0 to indicate failure
+int loadDll(const char* dllPath, FMU *fmu, const char* preamble) {
+    int x = 1, s = 1;
+    //HMODULE h = LoadLibrary(dllPath);
+    void *h = dlopen(dllPath, RTLD_LAZY);
+    printf("%s", dlerror());
+    if (!h) {
+        printf("error: Could not load %s\n", dllPath);
+        return 0; // failure
+    }
+    fmu->dllHandle = h;
+    fmu->getTypesPlatform          = (fmi2GetTypesPlatformTYPE *)      getAdr(&s, h, "fmi2GetTypesPlatform", preamble);
+    fmu->getVersion                = (fmi2GetVersionTYPE *)            getAdr(&s, h, "fmi2GetVersion", preamble);
+    fmu->setDebugLogging           = (fmi2SetDebugLoggingTYPE *)       getAdr(&s, h, "fmi2SetDebugLogging",preamble);
+    fmu->instantiate               = (fmi2InstantiateTYPE *)           getAdr(&s, h, "fmi2Instantiate", preamble);
+    fmu->freeInstance              = (fmi2FreeInstanceTYPE *)          getAdr(&s, h, "fmi2FreeInstance", preamble);
+    fmu->setupExperiment           = (fmi2SetupExperimentTYPE *)       getAdr(&s, h, "fmi2SetupExperiment", preamble);
+    fmu->enterInitializationMode   = (fmi2EnterInitializationModeTYPE *) getAdr(&s, h, "fmi2EnterInitializationMode", preamble);
+    fmu->exitInitializationMode    = (fmi2ExitInitializationModeTYPE *) getAdr(&s, h, "fmi2ExitInitializationMode", preamble);
+    fmu->terminate                 = (fmi2TerminateTYPE *)             getAdr(&s, h, "fmi2Terminate", preamble);
+    fmu->reset                     = (fmi2ResetTYPE *)                 getAdr(&s, h, "fmi2Reset", preamble);
+    fmu->getReal                   = (fmi2GetRealTYPE *)               getAdr(&s, h, "fmi2GetReal", preamble);
+    fmu->getInteger                = (fmi2GetIntegerTYPE *)            getAdr(&s, h, "fmi2GetInteger", preamble);
+    fmu->getBoolean                = (fmi2GetBooleanTYPE *)            getAdr(&s, h, "fmi2GetBoolean", preamble);
+    fmu->getString                 = (fmi2GetStringTYPE *)             getAdr(&s, h, "fmi2GetString", preamble);
+    fmu->setReal                   = (fmi2SetRealTYPE *)               getAdr(&s, h, "fmi2SetReal", preamble);
+    fmu->setInteger                = (fmi2SetIntegerTYPE *)            getAdr(&s, h, "fmi2SetInteger", preamble);
+    fmu->setBoolean                = (fmi2SetBooleanTYPE *)            getAdr(&s, h, "fmi2SetBoolean", preamble);
+    fmu->setString                 = (fmi2SetStringTYPE *)             getAdr(&s, h, "fmi2SetString", preamble);
+    fmu->getFMUstate               = (fmi2GetFMUstateTYPE *)           getAdr(&s, h, "fmi2GetFMUstate", preamble);
+    fmu->setFMUstate               = (fmi2SetFMUstateTYPE *)           getAdr(&s, h, "fmi2SetFMUstate", preamble);
+    fmu->freeFMUstate              = (fmi2FreeFMUstateTYPE *)          getAdr(&s, h, "fmi2FreeFMUstate", preamble);
+    fmu->serializedFMUstateSize    = (fmi2SerializedFMUstateSizeTYPE *) getAdr(&s, h, "fmi2SerializedFMUstateSize", preamble);
+    fmu->serializeFMUstate         = (fmi2SerializeFMUstateTYPE *)     getAdr(&s, h, "fmi2SerializeFMUstate", preamble);
+    fmu->deSerializeFMUstate       = (fmi2DeSerializeFMUstateTYPE *)   getAdr(&s, h, "fmi2DeSerializeFMUstate", preamble);
+    fmu->getDirectionalDerivative  = (fmi2GetDirectionalDerivativeTYPE *) getAdr(&s, h, "fmi2GetDirectionalDerivative", preamble);
+#ifdef FMI_COSIMULATION
+    fmu->setRealInputDerivatives   = (fmi2SetRealInputDerivativesTYPE *) getAdr(&s, h, "fmi2SetRealInputDerivatives", preamble);
+    fmu->getRealOutputDerivatives  = (fmi2GetRealOutputDerivativesTYPE *) getAdr(&s, h, "fmi2GetRealOutputDerivatives", preamble);
+    fmu->doStep                    = (fmi2DoStepTYPE *)                getAdr(&s, h, "fmi2DoStep", preamble);
+    fmu->cancelStep                = (fmi2CancelStepTYPE *)            getAdr(&s, h, "fmi2CancelStep", preamble);
+    fmu->getStatus                 = (fmi2GetStatusTYPE *)             getAdr(&s, h, "fmi2GetStatus", preamble);
+    fmu->getRealStatus             = (fmi2GetRealStatusTYPE *)         getAdr(&s, h, "fmi2GetRealStatus", preamble);
+    fmu->getIntegerStatus          = (fmi2GetIntegerStatusTYPE *)      getAdr(&s, h, "fmi2GetIntegerStatus", preamble);
+    fmu->getBooleanStatus          = (fmi2GetBooleanStatusTYPE *)      getAdr(&s, h, "fmi2GetBooleanStatus", preamble);
+    fmu->getStringStatus           = (fmi2GetStringStatusTYPE *)       getAdr(&s, h, "fmi2GetStringStatus", preamble);
+#else // FMI2 for Model Exchange
+    fmu->enterEventMode            = (fmi2EnterEventModeTYPE *)        getAdr(&s, h, "fmi2EnterEventMode", preamble);
+    fmu->newDiscreteStates         = (fmi2NewDiscreteStatesTYPE *)     getAdr(&s, h, "fmi2NewDiscreteStates", preamble);
+    fmu->enterContinuousTimeMode   = (fmi2EnterContinuousTimeModeTYPE *) getAdr(&s, h, "fmi2EnterContinuousTimeMode", preamble);
+    fmu->completedIntegratorStep   = (fmi2CompletedIntegratorStepTYPE *) getAdr(&s, h, "fmi2CompletedIntegratorStep", preamble);
+    fmu->setTime                   = (fmi2SetTimeTYPE *)               getAdr(&s, h, "fmi2SetTime", preamble);
+    fmu->setContinuousStates       = (fmi2SetContinuousStatesTYPE *)   getAdr(&s, h, "fmi2SetContinuousStates", preamble);
+    fmu->getDerivatives            = (fmi2GetDerivativesTYPE *)        getAdr(&s, h, "fmi2GetDerivatives", preamble);
+    fmu->getEventIndicators        = (fmi2GetEventIndicatorsTYPE *)    getAdr(&s, h, "fmi2GetEventIndicators", preamble);
+    fmu->getContinuousStates       = (fmi2GetContinuousStatesTYPE *)   getAdr(&s, h, "fmi2GetContinuousStates", preamble);
+    fmu->getNominalsOfContinuousStates = (fmi2GetNominalsOfContinuousStatesTYPE *) getAdr(&s, h, "fmi2GetNominalsOfContinuousStates", preamble);
+#endif
+
+    if (fmu->getVersion == NULL && fmu->instantiate == NULL) {
+        printf("warning: Functions from FMI 2.0 could not be found in %s\n", dllPath);
+        printf("warning: Simulator will look for FMI 2.0 RC1 functions names...\n");
+        fmu->getTypesPlatform          = (fmi2GetTypesPlatformTYPE *)      getAdr(&s, h, "fmiGetTypesPlatform", preamble);
+        fmu->getVersion                = (fmi2GetVersionTYPE *)            getAdr(&s, h, "fmiGetVersion", preamble);
+        fmu->setDebugLogging           = (fmi2SetDebugLoggingTYPE *)       getAdr(&s, h, "fmiSetDebugLogging", preamble);
+        fmu->instantiate               = (fmi2InstantiateTYPE *)           getAdr(&s, h, "fmiInstantiate", preamble);
+        fmu->freeInstance              = (fmi2FreeInstanceTYPE *)          getAdr(&s, h, "fmiFreeInstance", preamble);
+        fmu->setupExperiment           = (fmi2SetupExperimentTYPE *)       getAdr(&s, h, "fmiSetupExperiment", preamble);
+        fmu->enterInitializationMode   = (fmi2EnterInitializationModeTYPE *) getAdr(&s, h, "fmiEnterInitializationMode", preamble);
+        fmu->exitInitializationMode    = (fmi2ExitInitializationModeTYPE *) getAdr(&s, h, "fmiExitInitializationMode", preamble);
+        fmu->terminate                 = (fmi2TerminateTYPE *)             getAdr(&s, h, "fmiTerminate", preamble);
+        fmu->reset                     = (fmi2ResetTYPE *)                 getAdr(&s, h, "fmiReset", preamble);
+        fmu->getReal                   = (fmi2GetRealTYPE *)               getAdr(&s, h, "fmiGetReal", preamble);
+        fmu->getInteger                = (fmi2GetIntegerTYPE *)            getAdr(&s, h, "fmiGetInteger", preamble);
+        fmu->getBoolean                = (fmi2GetBooleanTYPE *)            getAdr(&s, h, "fmiGetBoolean", preamble);
+        fmu->getString                 = (fmi2GetStringTYPE *)             getAdr(&s, h, "fmiGetString", preamble);
+        fmu->setReal                   = (fmi2SetRealTYPE *)               getAdr(&s, h, "fmiSetReal", preamble);
+        fmu->setInteger                = (fmi2SetIntegerTYPE *)            getAdr(&s, h, "fmiSetInteger", preamble);
+        fmu->setBoolean                = (fmi2SetBooleanTYPE *)            getAdr(&s, h, "fmiSetBoolean", preamble);
+        fmu->setString                 = (fmi2SetStringTYPE *)             getAdr(&s, h, "fmiSetString", preamble);
+        fmu->getFMUstate               = (fmi2GetFMUstateTYPE *)           getAdr(&s, h, "fmiGetFMUstate", preamble);
+        fmu->setFMUstate               = (fmi2SetFMUstateTYPE *)           getAdr(&s, h, "fmiSetFMUstate", preamble);
+        fmu->freeFMUstate              = (fmi2FreeFMUstateTYPE *)          getAdr(&s, h, "fmiFreeFMUstate", preamble);
+        fmu->serializedFMUstateSize    = (fmi2SerializedFMUstateSizeTYPE *) getAdr(&s, h, "fmiSerializedFMUstateSize", preamble);
+        fmu->serializeFMUstate         = (fmi2SerializeFMUstateTYPE *)     getAdr(&s, h, "fmiSerializeFMUstate", preamble);
+        fmu->deSerializeFMUstate       = (fmi2DeSerializeFMUstateTYPE *)   getAdr(&s, h, "fmiDeSerializeFMUstate", preamble);
+        fmu->getDirectionalDerivative  = (fmi2GetDirectionalDerivativeTYPE *) getAdr(&s, h, "fmiGetDirectionalDerivative", preamble);
+    #ifdef FMI_COSIMULATION
+        fmu->setRealInputDerivatives   = (fmi2SetRealInputDerivativesTYPE *) getAdr(&s, h, "fmiSetRealInputDerivatives", preamble);
+        fmu->getRealOutputDerivatives  = (fmi2GetRealOutputDerivativesTYPE *) getAdr(&s, h, "fmiGetRealOutputDerivatives", preamble);
+        fmu->doStep                    = (fmi2DoStepTYPE *)                getAdr(&s, h, "fmiDoStep", preamble);
+        fmu->cancelStep                = (fmi2CancelStepTYPE *)            getAdr(&s, h, "fmiCancelStep", preamble);
+        fmu->getStatus                 = (fmi2GetStatusTYPE *)             getAdr(&s, h, "fmiGetStatus", preamble);
+        fmu->getRealStatus             = (fmi2GetRealStatusTYPE *)         getAdr(&s, h, "fmiGetRealStatus", preamble);
+        fmu->getIntegerStatus          = (fmi2GetIntegerStatusTYPE *)      getAdr(&s, h, "fmiGetIntegerStatus", preamble);
+        fmu->getBooleanStatus          = (fmi2GetBooleanStatusTYPE *)      getAdr(&s, h, "fmiGetBooleanStatus", preamble);
+        fmu->getStringStatus           = (fmi2GetStringStatusTYPE *)       getAdr(&s, h, "fmiGetStringStatus", preamble);
+    #else // FMI2 for Model Exchange
+        fmu->enterEventMode            = (fmi2EnterEventModeTYPE *)        getAdr(&s, h, "fmiEnterEventMode", preamble);
+        fmu->newDiscreteStates         = (fmi2NewDiscreteStatesTYPE *)     getAdr(&s, h, "fmiNewDiscreteStates", preamble);
+        fmu->enterContinuousTimeMode   = (fmi2EnterContinuousTimeModeTYPE *) getAdr(&s, h, "fmiEnterContinuousTimeMode", preamble);
+        fmu->completedIntegratorStep   = (fmi2CompletedIntegratorStepTYPE *) getAdr(&s, h, "fmiCompletedIntegratorStep", preamble);
+        fmu->setTime                   = (fmi2SetTimeTYPE *)               getAdr(&s, h, "fmiSetTime", preamble);
+        fmu->setContinuousStates       = (fmi2SetContinuousStatesTYPE *)   getAdr(&s, h, "fmiSetContinuousStates", preamble);
+        fmu->getDerivatives            = (fmi2GetDerivativesTYPE *)        getAdr(&s, h, "fmiGetDerivatives", preamble);
+        fmu->getEventIndicators        = (fmi2GetEventIndicatorsTYPE *)    getAdr(&s, h, "fmiGetEventIndicators", preamble);
+        fmu->getContinuousStates       = (fmi2GetContinuousStatesTYPE *)   getAdr(&s, h, "fmiGetContinuousStates", preamble);
+        fmu->getNominalsOfContinuousStates = (fmi2GetNominalsOfContinuousStatesTYPE *) getAdr(&s, h, "fmiGetNominalsOfContinuousStates", preamble);
+    #endif
+    }
+    return s;
+}
+
+//static void printModelDescription(ModelDescription* md){
+//    Element* e = (Element*)md;
+//    int i;
+//    int n; // number of attributes
+//    const char **attributes = getAttributesAsArray(e, &n);
+//    Component *component;
+//
+//    if (!attributes) {
+//        printf("ModelDescription printing aborted.");
+//        return;
+//    }
+//    printf("%s\n", getElementTypeName(e));
+//    for (i = 0; i < n; i += 2) {
+//        printf("  %s=%s\n", attributes[i], attributes[i+1]);
+//    }
+//    free((void *)attributes);
+//
+//#ifdef FMI_COSIMULATION
+//    component = getCoSimulation(md);
+//    if (!component) {
+//        printf("error: No CoSimulation element found in model description. This FMU is not for Co-Simulation.\n");
+//        exit(EXIT_FAILURE);
+//    }
+//#else // FMI_MODEL_EXCHANGE
+//    component = getModelExchange(md);
+//    if (!component) {
+//        printf("error: No ModelExchange element found in model description. This FMU is not for Model Exchange.\n");
+//        exit(EXIT_FAILURE);
+//    }
+//#endif
+//    printf("%s\n", getElementTypeName((Element *)component));
+//    attributes = getAttributesAsArray((Element *)component, &n);
+//    if (!attributes) {
+//        printf("ModelDescription printing aborted.");
+//        return;
+//    }
+//    for (i = 0; i < n; i += 2) {
+//        printf("  %s=%s\n", attributes[i], attributes[i+1]);
+//    }
+//
+//    free((void *)attributes);
+//}
+//
+//void loadFMU(const char* fmuFileName) {
+//    char* fmuPath;
+//    char* tmpPath;
+//    char* xmlPath;
+//    char* dllPath;
+//    const char *modelId;
+//
+//    // get absolute path to FMU, NULL if not found
+//    fmuPath = getFmuPath(fmuFileName);
+//    if (!fmuPath) exit(EXIT_FAILURE);
+//
+//    // unzip the FMU to the tmpPath directory
+//    tmpPath = getTmpPath();
+//    if (!unzip(fmuPath, tmpPath)) exit(EXIT_FAILURE);
+//
+//    // parse tmpPath\modelDescription.xml
+//    xmlPath = calloc(sizeof(char), strlen(tmpPath) + strlen(XML_FILE) + 1);
+//    sprintf(xmlPath, "%s%s", tmpPath, XML_FILE);
+//    fmu.modelDescription = parse(xmlPath);
+//    free(xmlPath);
+//    if (!fmu.modelDescription) exit(EXIT_FAILURE);
+//    printModelDescription(fmu.modelDescription);
+//#ifdef FMI_COSIMULATION
+//    modelId = getAttributeValue((Element *)getCoSimulation(fmu.modelDescription), att_modelIdentifier);
+//#else // FMI_MODEL_EXCHANGE
+//    modelId = getAttributeValue((Element *)getModelExchange(fmu.modelDescription), att_modelIdentifier);
+//#endif
+//    // load the FMU dll
+//    dllPath = calloc(sizeof(char), strlen(tmpPath) + strlen(DLL_DIR)
+//        + strlen(modelId) +  strlen(".dll") + 1);
+//    sprintf(dllPath, "%s%s%s.dll", tmpPath, DLL_DIR, modelId);
+//    if (!loadDll(dllPath, &fmu)) {
+//        exit(EXIT_FAILURE);
+//    }
+//    free(dllPath);
+//    free(fmuPath);
+//    free(tmpPath);
+//}
+//
+//void deleteUnzippedFiles() {
+//    const char *fmuTempPath = getTmpPath();
+//    char *cmd = (char *)calloc(15 + strlen(fmuTempPath), sizeof(char));
+//    sprintf(cmd, "rmdir /S /Q %s", fmuTempPath);
+//    system(cmd);
+//    free(cmd);
+//}
+//
+//static void doubleToCommaString(char* buffer, double r){
+//    char* comma;
+//    sprintf(buffer, "%.16g", r);
+//    comma = strchr(buffer, '.');
+//    if (comma) *comma = ',';
+//}
+//
+//// output time and all variables in CSV format
+//// if separator is ',', columns are separated by ',' and '.' is used for floating-point numbers.
+//// otherwise, the given separator (e.g. ';' or '\t') is to separate columns, and ',' is used
+//// as decimal dot in floating-point numbers.
+//void outputRow(FMU *fmu, fmi2Component c, double time, FILE* file, char separator, fmi2Boolean header) {
+//    int k;
+//    fmi2Real r;
+//    fmi2Integer i;
+//    fmi2Boolean b;
+//    fmi2String s;
+//    fmi2ValueReference vr;
+//    int n = getScalarVariableSize(fmu->modelDescription);
+//    char buffer[32];
+//
+//    // print first column
+//    if (header) {
+//        fprintf(file, "time");
+//    } else {
+//        if (separator==',')
+//            fprintf(file, "%.16g", time);
+//        else {
+//            // separator is e.g. ';' or '\t'
+//            doubleToCommaString(buffer, time);
+//            fprintf(file, "%s", buffer);
+//        }
+//    }
+//
+//    // print all other columns
+//    for (k = 0; k < n; k++) {
+//        ScalarVariable *sv = getScalarVariable(fmu->modelDescription, k);
+//        if (header) {
+//            // output names only
+//            if (separator == ',') {
+//                // treat array element, e.g. print a[1, 2] as a[1.2]
+//                const char *s = getAttributeValue((Element *)sv, att_name);
+//                fprintf(file, "%c", separator);
+//                while (*s) {
+//                    if (*s != ' ') {
+//                        fprintf(file, "%c", *s == ',' ? '.' : *s);
+//                    }
+//                    s++;
+//                }
+//            } else {
+//                fprintf(file, "%c%s", separator, getAttributeValue((Element *)sv, att_name));
+//            }
+//        } else {
+//            // output values
+//            vr = getValueReference(sv);
+//            switch (getElementType(getTypeSpec(sv))) {
+//                case elm_Real:
+//                    fmu->getReal(c, &vr, 1, &r);
+//                    if (separator == ',') {
+//                        fprintf(file, ",%.16g", r);
+//                    } else {
+//                        // separator is e.g. ';' or '\t'
+//                        doubleToCommaString(buffer, r);
+//                        fprintf(file, "%c%s", separator, buffer);
+//                    }
+//                    break;
+//                case elm_Integer:
+//                case elm_Enumeration:
+//                    fmu->getInteger(c, &vr, 1, &i);
+//                    fprintf(file, "%c%d", separator, i);
+//                    break;
+//                case elm_Boolean:
+//                    fmu->getBoolean(c, &vr, 1, &b);
+//                    fprintf(file, "%c%d", separator, b);
+//                    break;
+//                case elm_String:
+//                    fmu->getString(c, &vr, 1, &s);
+//                    fprintf(file, "%c%s", separator, s);
+//                    break;
+//                default:
+//                    fprintf(file, "%cNoValueForType=%d", separator, getElementType(getTypeSpec(sv)));
+//            }
+//        }
+//    } // for
+//
+//    // terminate this row
+//    fprintf(file, "\n");
+//}
+//
+static const char* fmi2StatusToString(fmi2Status status){
+    switch (status){
+        case fmi2OK:      return "ok";
+        case fmi2Warning: return "warning";
+        case fmi2Discard: return "discard";
+        case fmi2Error:   return "error";
+        case fmi2Fatal:   return "fatal";
+    #ifdef FMI_COSIMULATION
+        case fmi2Pending: return "fmi2Pending";
+    #endif
+        default:         return "?";
+    }
+}
+
+// search a fmu for the given variable, matching the type specified.
+// return NULL if not found
+//static ScalarVariable* getSV(FMU* fmu, char type, fmi2ValueReference vr) {
+//    return NULL;
+//    int i;
+//    int n = getScalarVariableSize(fmu->modelDescription);
+//    Elm tp;
+//
+//    switch (type) {
+//        case 'r': tp = elm_Real;    break;
+//        case 'i': tp = elm_Integer; break;
+//        case 'b': tp = elm_Boolean; break;
+//        case 's': tp = elm_String;  break;
+//        default : tp = elm_BAD_DEFINED;
+//    }
+//    for (i = 0; i < n; i++) {
+//        ScalarVariable* sv = getScalarVariable(fmu->modelDescription ,i);
+//        if (vr == getValueReference(sv) && tp == getElementType(getTypeSpec(sv))) {
+//            return sv;
+//        }
+//    }
+//    return NULL;
+//}
+
+// replace e.g. #r1365# by variable name and ## by # in message
+// copies the result to buffer
+static void replaceRefsInMessage(const char* msg, char* buffer, int nBuffer, FMU* fmu){
+    int i = 0; // position in msg
+    int k = 0; // position in buffer
+    int n;
+    char c = msg[i];
+    while (c != '\0' && k < nBuffer) {
+        if (c != '#') {
+            buffer[k++] = c;
+            i++;
+            c = msg[i];
+        } else {
+
+            char* end = strchr(msg + i + 1, '#');
+            if (!end) {
+                printf("unmatched '#' in '%s'\n", msg);
+                buffer[k++] = '#';
+                break;
+            }
+            n = end - (msg + i);
+            if (n == 1) {
+                // ## detected, output #
+                buffer[k++] = '#';
+                i += 2;
+                c = msg[i];
+
+            } else {
+                char type = msg[i + 1]; // one of ribs
+                fmi2ValueReference vr;
+                int nvr = sscanf(msg + i + 2, "%u", &vr);
+                if (nvr == 1) {
+                    // vr of type detected, e.g. #r12#
+                    //ScalarVariable* sv = getSV(fmu, type, vr);
+                    //const char* name = sv ? getAttributeValue((Element *)sv, att_name) : "?";
+                    //sprintf(buffer + k, "%s", name);
+                    //k += strlen(name);
+                    //i += (n+1);
+                    //c = msg[i];
+
+                } else {
+                    // could not parse the number
+                    printf("illegal value reference at position %d in '%s'\n", i + 2, msg);
+                    buffer[k++] = '#';
+                    break;
+                }
+            }
+        }
+    } // while
+    buffer[k] = '\0';
+}
+
+#define MAX_MSG_SIZE 1000
+void fmuLogger(void *componentEnvironment, fmi2String instanceName, fmi2Status status,
+               fmi2String category, fmi2String message, ...) {
+    char msg[MAX_MSG_SIZE];
+    char* copy;
+    va_list argp;
+
+    // replace C format strings
+    va_start(argp, message);
+    vsprintf(msg, message, argp);
+    va_end(argp);
+
+    // replace e.g. ## and #r12#
+    copy = strdup(msg);
+//    replaceRefsInMessage(copy, msg, MAX_MSG_SIZE, NULL);
+    free(copy);
+
+    // print the final message
+    if (!instanceName) instanceName = "?";
+    if (!category) category = "?";
+    printf("%s %s (%s): %s\n", fmi2StatusToString(status), instanceName, category, msg);
+}
+
+int error(const char* message){
+    printf("%s\n", message);
+    return 0;
+}
+//
+//void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tEnd, double *h,
+//                    int *loggingOn, char *csv_separator, int *nCategories, char **logCategories[]) {
+//    // parse command line arguments
+//    if (argc > 1) {
+//        *fmuFileName = argv[1];
+//    } else {
+//        printf("error: no fmu file\n");
+//        printHelp(argv[0]);
+//        exit(EXIT_FAILURE);
+//    }
+//    if (argc > 2) {
+//        if (sscanf(argv[2],"%lf", tEnd) != 1) {
+//            printf("error: The given end time (%s) is not a number\n", argv[2]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 3) {
+//        if (sscanf(argv[3],"%lf", h) != 1) {
+//            printf("error: The given stepsize (%s) is not a number\n", argv[3]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 4) {
+//        if (sscanf(argv[4],"%d", loggingOn) != 1 || *loggingOn < 0 || *loggingOn > 1) {
+//            printf("error: The given logging flag (%s) is not boolean\n", argv[4]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 5) {
+//        if (strlen(argv[5]) != 1) {
+//            printf("error: The given CSV separator char (%s) is not valid\n", argv[5]);
+//            exit(EXIT_FAILURE);
+//        }
+//        switch (argv[5][0]) {
+//            case 'c': *csv_separator = ','; break; // comma
+//            case 's': *csv_separator = ';'; break; // semicolon
+//            default:  *csv_separator = argv[5][0]; break; // any other char
+//        }
+//    }
+//    if (argc > 6) {
+//        int i;
+//        *nCategories = argc - 6;
+//        *logCategories = (char **)calloc(sizeof(char *), *nCategories);
+//        for (i = 0; i < *nCategories; i++) {
+//            (*logCategories)[i] = argv[i + 6];
+//        }
+//    }
+//}
+//
+//void printHelp(const char *fmusim) {
+//    printf("command syntax: %s <model.fmu> <tEnd> <h> <loggingOn> <csv separator>\n", fmusim);
+//    printf("   <model.fmu> .... path to FMU, relative to current dir or absolute, required\n");
+//    printf("   <tEnd> ......... end  time of simulation,   optional, defaults to 1.0 sec\n");
+//    printf("   <h> ............ step size of simulation,   optional, defaults to 0.1 sec\n");
+//    printf("   <loggingOn> .... 1 to activate logging,     optional, defaults to 0\n");
+//    printf("   <csv separator>. separator in csv file,     optional, c for ',', s for';', defaults to c\n");
+//    printf("   <logCategories>. list of active categories, optional, see modelDescription.xml for possible values\n");
+//}

+ 44 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_loop_sa/sim_support.h

@@ -0,0 +1,44 @@
+/* ------------------------------------------------------------------------- 
+ * sim_support.h
+ * Functions used by the FMU simulations fmusim_me and fmusim_cs.
+ * Copyright QTronic GmbH. All rights reserved.
+ * -------------------------------------------------------------------------*/
+#ifndef __SIM_SUPPORT_H
+#define __SIM_SUPPORT_H
+
+// Used 7z options, version 4.57:
+// -x   Extracts files from an archive with their full paths in the current dir, or in an output dir if specified
+// -aoa Overwrite All existing files without prompt
+// -o   Specifies a destination directory where files are to be extracted
+#define UNZIP_CMD "7z x -aoa -o"
+#define XML_FILE  "modelDescription.xml"
+#define RESULT_FILE "result.csv"
+#define BUFSIZE 4096
+#ifdef _WIN64
+#define DLL_DIR   "binaries\\win64\\"
+#else
+#define DLL_DIR   "binaries\\win32\\"
+#endif
+#define RESOURCES_DIR "resources\\"
+
+// return codes of the 7z command line tool
+#define SEVEN_ZIP_NO_ERROR 0 // success
+#define SEVEN_ZIP_WARNING 1  // e.g., one or more files were locked during zip
+#define SEVEN_ZIP_ERROR 2
+#define SEVEN_ZIP_COMMAND_LINE_ERROR 7
+#define SEVEN_ZIP_OUT_OF_MEMORY 8
+#define SEVEN_ZIP_STOPPED_BY_USER 255
+
+void fmuLogger(fmi2Component c, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message, ...);
+int unzip(const char *zipPath, const char *outPath);
+void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tEnd, double *h,
+                    int *loggingOn, char *csv_separator, int *nCategories, char **logCategories[]);
+void loadFMU(const char *fmuFileName);
+int loadDll(const char* dllPath, FMU *fmu, const char* preamble);
+void deleteUnzippedFiles();
+void outputRow(FMU *fmu, fmi2Component c, double time, FILE* file, char separator, fmi2Boolean header);
+int error(const char *message);
+void printHelp(const char *fmusim);
+char *getTempResourcesLocation(); // caller has to free the result
+
+#endif

File diff suppressed because it is too large
+ 134 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/.cproject


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/FMI_CM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/FMI_GM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/FMI_SEL.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/FMI_power_sa.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/libFMI_power_sa.dll


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/Debug/sim_support.o


+ 652 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/FMI_power_sa.c

@@ -0,0 +1,652 @@
+/* ---------------------------------------------------------------------------*
+ * Sample implementation of an generic master FMU -
+ * ---------------------------------------------------------------------------*/
+/*
+Template for a  FMU
+ */
+
+#define MODEL_IDENTIFIER GM
+#define MODEL_GUID "{41f87101-edf2-4eef-90f3-42db56d4565f}"
+#define FMI2_FUNCTION_PREFIX POWER_SA
+
+
+#include <stdio.h>
+#include "string.h"
+#include "fmi2Functions.h"
+#include <float.h>
+#include "FMI_power_sa.h"
+#include <math.h>
+#include "fmi2.h"
+#include "sim_support.h"
+
+
+#define MAX 100000
+
+#define NUMBER_OF_REALS 6
+#define NUMBER_OF_STRINGS 0
+#define NUMBER_OF_BOOLEANS 0
+#define NUMBER_OF_INTEGERS 0
+/*
+ * The input
+ */
+
+#define _out_i 0
+#define _out_omega 1
+#define _out_theta 2
+
+#define _in_d 3
+#define _in_tau 4
+#define _in_u 5
+
+double relativeError(double a, double b){
+	return fabs((a - b) / a);
+}
+
+/*
+ * Helper function for absolute error
+ */
+double absoluteError(double a, double b){
+	return fabs(a - b);
+}
+
+/*
+ * is_close function for double comparison
+ */
+int is_close(double a, double b, double REL_TOL, double ABS_TOL){
+	return ((absoluteError(a,b)<ABS_TOL) && (relativeError(a,b)<REL_TOL));
+}
+
+fmi2Status fmi2SetDebugLogging(fmi2Component fc, fmi2Boolean loggingOn, size_t nCategories, const fmi2String categories[])
+{
+	return fmi2OK;
+}
+
+fmi2Status fmi2SetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2String value[])
+{
+	FMUInstance*  comp = (FMUInstance *)fc;
+
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2String value[])
+{
+	return fmi2Error;
+}
+
+fmi2Status fmi2SetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Real value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		comp->r[vr[i]] = value[i];
+	}
+	//out_condition_executed := empty map
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2OK;
+}
+
+fmi2Status fmi2GetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Real value[])
+{
+
+	FMUInstance* comp = (FMUInstance *)fc;
+
+	int isEmpty = 1;
+	for (int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		if(comp->out_conditions_executed[i] !=0){
+			isEmpty = 0;
+			break;
+		}
+	}
+
+	/*Eval conditions:*/
+	if(1){
+		comp->out_conditions_executed[0] = 1;
+	}
+
+	if (isEmpty){
+		for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+			if(comp->out_conditions_executed[i]){
+				comp->r[_out_i] = comp->stored_armature_current;
+				comp->r[_out_omega] = comp->stored_speed;
+				comp->r[_out_theta] = comp->stored_displacement;
+			}
+		}
+	}
+	for (int i = 0; i < nvr; i++)
+	{
+		value[i] = comp->r[(vr[i])];
+	}
+
+	return fmi2OK;
+}
+
+fmi2Status fmi2SetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Boolean value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		comp->b[vr[i]] = value[i];
+	}
+	/*Generated: */
+		fmi2Boolean in_condition[_NR_OF_IN_CONDITIONS];
+		/*Condition checking:*/
+		// true
+		in_condition[0] = 1;
+
+		if(in_condition[0]){
+			comp->stored_windowsa_u = (fmi2Real) comp->b[_in_u];
+			comp->stored_windowsa_d = comp->b[_in_d];
+			/* If mealy do update_in and recursive call */
+		}
+		return fmi2OK;
+
+	//out_condition_executed := empty map
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2OK;
+}
+
+fmi2Status fmi2GetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Boolean value[])
+{
+	FMUInstance* comp = (FMUInstance *)fc;
+	int i;
+	for (i = 0; i < nvr; i++)
+	{
+		value[i] = comp->b[vr[i]];
+	}
+	return fmi2OK;
+}
+
+fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2String fmuGUID, fmi2String fmuLocation, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+
+	//Declare data structure for fmu instance
+	FMUInstance* fi;
+	printf("%s in fmiInstantiate\n",instanceName);
+
+	//Perform checks on passed callback functions
+	if (loggingOn) {
+
+		if (!functions->logger);
+		//return NULL;
+	}
+	//Check for instanceName
+	if (!instanceName || strlen(instanceName)==0) {
+
+		// print (and/or log) instanceName is missing
+		//return NULL;
+	}
+	//Check passed GUID to defined model GUID
+	if (strcmp(fmuGUID, MODEL_GUID))
+	{
+		// print (and/or log) GUID doesn't match
+		//return NULL;
+	}
+
+	//Allocate fmu instance Memory
+	// TODO check if "canNotUseMemoryManagementFunctions == true/false". If false memory allocation not possible
+	fi = (FMUInstance *)functions->allocateMemory(1, sizeof(FMUInstance));
+	if (fi) {
+		// Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
+		fi->r = functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
+		fi->i = functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
+		fi->b = functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
+		fi->s = functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
+	} // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
+
+
+	fi->instanceName = functions->allocateMemory(1 + strlen(instanceName), sizeof(char));
+	fi->GUID = functions->allocateMemory(1 + strlen(fmuGUID), sizeof(char));
+
+	strcpy((char*)fi->instanceName, instanceName);
+	strcpy((char*)fi->GUID, fmuGUID);
+	fi->functions = functions;
+	fi->loggingOn = loggingOn;
+	fi->isVisible = visible;
+	fi->state = fmuInstantiated;
+	/* Load the inner FMUs:*/
+
+	loadDll("PowerSystem.dll", &(fi->fmu[0]), "");
+	fi->fmuResourceLocation[0] = "PowerSystem";
+
+	/*Instantiate inner components*/
+	for (int i=0; i<1; i++){
+		fi->c_fmu[i] = fi->fmu[i].instantiate("inner", fmi2CoSimulation, "{c6327117-e5f2-4e48-abcd-318439d1e7c4}", fi->fmuResourceLocation[i] , fi->functions, visible, 0);
+	}
+
+
+
+	return fi;
+}
+
+fmi2Status fmi2SetupExperiment(fmi2Component fc, fmi2Boolean toleranceDefined, fmi2Real tolerance,
+		fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) {
+
+
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiSetupExperiment\n",fi->instanceName);
+	if (fi->state != fmuInstantiated)
+	{
+		printf("fmu: %s was not instatiated before calling fmiSetupExperiment\n", fi->instanceName);
+		return fmi2Error;
+	}
+	fi->currentTime = startTime;
+	fi->stopTimeDefined = stopTimeDefined;
+	fi->toleranceDefined = toleranceDefined;
+	if (stopTimeDefined)
+	{
+		fi->stopTime = stopTime;
+	}
+	/*
+	 * setup inner
+	 */
+	fmi2Status fmi2Flag = fmi2OK;
+	fi->state = fmuExperimentSettedUp;
+	for(int i=0; i<1; i++){
+		fmi2Flag = fi->fmu[i].setupExperiment(fi->c_fmu[i], toleranceDefined, tolerance, startTime, fmi2True, stopTime);
+		if (fmi2Flag == fmi2Error){
+			fi->state = fmuError;
+		}
+	}
+
+	fi->stored_windowsa_u = 0;
+	fi->stored_windowsa_d = 0;
+	fi->stored_tau = 0;
+	fi->stored_armature_current = 0;
+	fi->stored_speed = 0;
+	fi->stored_displacement = 0;
+
+	return fmi2Flag;
+}
+
+fmi2Status fmi2EnterInitializationMode(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiEnterInitializationMode\n",fi->instanceName);
+	if (fi->state != fmuExperimentSettedUp)
+	{
+		printf("fmu: %s experiment was not set-up before calling fmiEnterInitializationMode\n", fi->instanceName);
+		return fmi2Error;
+	}
+	fi->state = fmuInitMode;
+	fmi2Status fmi2Flag = fmi2OK;
+	for(int i=0; i<1; i++){
+		fmi2Flag = fi->fmu[i].enterInitializationMode(fi->c_fmu[i]);
+		if (fmi2Flag == fmi2Error){
+			return fi->state = fmuError;
+		}
+	}
+	return fmi2Flag;
+}
+
+fmi2Status fmi2ExitInitializationMode(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiExitInitializationMode\n",fi->instanceName);
+	if (fi->state != fmuInitMode)
+	{
+		printf("fmu: %s did not enter Initialization Mode before calling fmiExitInitializationMode\n", fi->instanceName);
+		return fmi2Error;
+	}
+	// TODO
+	//initStatus = calculateInitialUnknownValues();
+	//initialize();
+	fi->state = fmuInitialized;
+	fmi2Status fmi2Flag = fmi2OK;
+	for(int i=0; i<1;i++){
+		fmi2Flag = fi->fmu[i].exitInitializationMode(fi->c_fmu[i]);
+		if (fmi2Flag == fmi2Error){
+			return fi->state = fmuError;
+		}
+	}
+	return fmi2Flag;
+}
+
+static fmi2Status DoInnerStep(fmi2Component fc, int index, fmi2Real currentCommPoint, fmi2Real commStepSize){
+	fmi2Status status = fmi2OK;
+	FMUInstance* fi = (FMUInstance *)fc;
+
+	fmi2Real dt =   currentCommPoint - fi->time_last_fmu[index];
+	fmi2Real h = commStepSize + dt;
+	if (1){
+		fmi2ValueReference vr_toPower[3] = {7,8,9};
+		fmi2Real values[3];
+		values[0] = fi->stored_windowsa_d;
+		values[1] = fi->stored_tau;
+		values[2] = fi->stored_windowsa_u;
+		fi->fmu[index].setReal(fi->c_fmu[index],vr_toPower, 3, &values[0]);
+	}
+
+	status = fi->fmu[index].doStep(fi->c_fmu[index],fi->time_last_fmu[index],h,fmi2True);
+
+	if (1){
+		fmi2ValueReference vr_fromPower[3] = {0,1,2};
+		fmi2Real out_values[3];
+		fi->fmu[index].getReal(fi->c_fmu[index],vr_fromPower, 3, &out_values[0]);
+		fi->stored_armature_current = out_values[0];
+		fi->stored_speed = out_values[1];
+		fi->stored_displacement = out_values[2];
+	}
+	return status;
+}
+
+fmi2Status fmi2DoStep(fmi2Component fc , fmi2Real currentCommPoint, fmi2Real commStepSize, fmi2Boolean noPrevFMUState)
+{
+	FMUInstance* fi = (FMUInstance *)fc;
+	fmi2Status simStatus = fmi2OK;
+	printf("%s in fmiDoStep(), ct:%f, h:%f\n",fi->instanceName,currentCommPoint,commStepSize);
+	memset(fi->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+
+
+	/*
+	Calculate the elapsed time since the last transition
+	*/
+	fmi2Real e = MAX;
+	fmi2Real elapsed_fmu[_NR_OF_FMUS];
+	for (int i=0; i<_NR_OF_FMUS; i++){
+		elapsed_fmu[i] = currentCommPoint - fi->time_last_fmu[i];
+		e = (elapsed_fmu[i]<e)? elapsed_fmu[i]:e;
+	}
+
+	if(1){
+		simStatus= DoInnerStep(fc,0,currentCommPoint,commStepSize);
+	}
+
+	memset(fi->in_condition_executed, 0, sizeof(fmi2Boolean)*_NR_OF_IN_CONDITIONS);
+	return simStatus;
+}
+
+fmi2Status fmi2Terminate(fmi2Component fc)
+{
+	FMUInstance* fi = (FMUInstance *)fc;
+	printf("%s in fmiTerminate\n",fi->instanceName);
+	// do check if fi may be terminated
+	for (int i=0;i<1;i++){
+		fi->fmu[i].terminate(fi->c_fmu[i]);
+	}
+
+	fi->state = fmuTerminated;
+	return fmi2OK;
+}
+
+
+void fmi2FreeInstance(fmi2Component fc)
+{
+
+	FMUInstance* fi = (FMUInstance*) fc;
+	printf("%s in fmiFreeInstance\n",fi->instanceName);
+	for(int i=0;i<1;i++){
+		fi->fmu[i].freeInstance(fi->c_fmu[i]);
+	}
+
+	if (fi) {
+		fi->functions->freeMemory(fi->r);
+		fi->functions->freeMemory(fi->i);
+		fi->functions->freeMemory(fi->b);
+		fi->functions->freeMemory(fi->s);// TODO has to be done with loop
+		fi->functions->freeMemory((void*)fi->instanceName);
+		fi->functions->freeMemory((void*)fi->GUID);
+		fi->functions->freeMemory((void*)fi);
+
+	}
+}
+
+//To be implemented
+
+const char* fmi2GetVersion() {
+	printf("Function fmiGetVersion not supported\n");
+	return NULL;
+}
+
+const char* fmi2GetTypesPlatform() {
+	printf("Function fmiGetTypesPlatform not supported\n");
+	return NULL;
+}
+
+fmi2Status fmi2Reset(fmi2Component fc)
+{
+	printf("Function fmiReset not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2SetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Integer value[])
+{
+	FMUInstance * comp = (FMUInstance*) fc;
+	printf("Function fmiSetInteger not supported\n");
+	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[])
+{
+	printf("Function fmiGetInteger not supported\n");
+	return fmi2Error;
+}
+
+
+/*******OWN IMPLEMENTATION OF Get/Set FMU state*******/
+fmi2Status fmi2GetFMUstate (fmi2Component c, fmi2FMUstate* FMUstate) {
+	FMUInstance* orig = (FMUInstance*)c;
+	FMUInstance* fi = (FMUInstance *)FMUstate;
+	*FMUstate = fi;
+	fi = orig->functions->allocateMemory(1, sizeof(FMUInstance));
+	*FMUstate = fi;
+	fi->functions = orig->functions;
+
+	if (fi) {
+		// Think about what to do with variable values. Using these structs and pointers slows down simulation computations. Maybe only necessary for input, output and tunable parameters??
+		fi->r = fi->functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
+		fi->i = fi->functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
+		fi->b = fi->functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
+		fi->s = fi->functions->allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmi2String));
+
+	} // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
+	fi->instanceName = orig->functions->allocateMemory(1 + strlen(orig->instanceName), sizeof(char));
+	fi->GUID = orig->functions->allocateMemory(1 + strlen(orig->GUID), sizeof(char));
+
+	strcpy((char *)fi->instanceName, (char *)orig->instanceName);
+	strcpy((char *)fi->GUID, (char *)orig->GUID);
+	fi->functions = orig->functions;
+	fi->loggingOn = orig->loggingOn;
+	fi->isVisible = orig->isVisible;
+	fi->state = orig->state;
+	fi->startTime = orig->startTime;
+	fi->stopTime = orig->stopTime;
+	fi->currentTime = orig->currentTime;
+	/* TODO: Store all the rest here.*/
+	fi->fmu[0] = orig->fmu[0];
+	fi->c_fmu[0] = orig->c_fmu[0];
+	for(int i=0; i<_NR_OF_IN_CONDITIONS;i++){
+		fi->in_condition_executed[i] = orig->in_condition_executed[i];
+	}
+	for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		fi->out_conditions_executed[i] = orig->out_conditions_executed[i];
+	}
+	for(int i=0;i<_NR_OF_FMUS;i++){
+		fi->time_last_fmu[i] = orig->time_last_fmu[i];
+	}
+
+	/* Generated */
+	fi->stored_windowsa_u = orig->stored_windowsa_u;
+	fi->stored_windowsa_d = orig->stored_windowsa_d;
+	fi->stored_tau = orig->stored_tau;
+	fi->stored_armature_current = orig->stored_armature_current;
+	fi->stored_speed = orig->stored_speed;
+	fi->stored_displacement = orig->stored_displacement;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+	/*
+	 * This is a hierarchical call. First let the lower FMUs do their state saving
+	 * We will store the saved fmu state in the fi->c_order[i]
+	 */
+	for(int i=0;i<1;i++){
+		fi->fmu[i]=orig->fmu[i];
+		orig->fmu[i].getFMUstate(orig->c_fmu[i],fi->c_fmu[i]);
+		fi->fmuResourceLocation[i] = fi->functions->allocateMemory(1+strlen(orig->fmuResourceLocation[i]), sizeof(char));
+		strcpy((char *)fi->fmuResourceLocation[i],(char *)orig->fmuResourceLocation[i]);
+		/*make shallow copies of the stored fmus*/
+	}
+	//copy r
+	int i=0;
+	for (i=0; i< NUMBER_OF_REALS;i++){
+		printf("Setting real: %i %f\n", i, orig->r[i]);
+		fi->r[i] = orig->r[i];
+		printf("Setted real: %i %f\n", i, fi->r[i]);
+	}
+	//copy s
+	for (i=0; i< NUMBER_OF_STRINGS;i++){
+		//fi->s[i] = orig->s[i]; // why are this not deep copies?
+		fi->s[i] = fi->functions->allocateMemory(1+strlen(orig->s[i]),sizeof(char));
+		strcpy((char *)fi->s[i],(char *)orig->s[i]);
+	}
+	//copy i
+	for (i=0; i< NUMBER_OF_INTEGERS;i++){
+		fi->i[i] = orig->i[i];
+	}
+	//copy b
+	for (i=0; i< NUMBER_OF_BOOLEANS;i++){
+		fi->b[i] = orig->b[i];
+	}
+	return fmi2OK;
+}
+
+fmi2Status fmi2SetFMUstate (fmi2Component c, fmi2FMUstate FMUstate) {
+	FMUInstance* orig = (FMUInstance*)FMUstate;
+	FMUInstance* fi = (FMUInstance*)c;
+	/*
+	 * First restore the hierarchical fmus.
+	 */
+	for(int i=0;i<1;i++){
+		fi->fmu[i].setFMUstate(fi->c_fmu[i],orig->c_fmu[i]);
+		fi->fmuResourceLocation[i] = orig->functions->allocateMemory(1+strlen(orig->fmuResourceLocation[i]), sizeof(char));
+		strcpy((char *)fi->fmuResourceLocation[i],(char *)orig->fmuResourceLocation[i]);
+	}
+
+	//set time etc correct, name and GUID should still be ok ;-)
+	printf("setting time values from %f to %f\n", fi->currentTime, orig->currentTime);
+	fi->state = orig->state;
+	fi->startTime = orig->startTime;
+	fi->stopTime = orig->stopTime;
+	fi->currentTime = orig->currentTime;
+
+	fi->fmu[0] = orig->fmu[0];
+	fi->c_fmu[0] = orig->c_fmu[0];
+	for(int i=0; i<_NR_OF_IN_CONDITIONS;i++){
+		fi->in_condition_executed[i] = orig->in_condition_executed[i];
+	}
+	for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
+		fi->out_conditions_executed[i] = orig->out_conditions_executed[i];
+	}
+	for(int i=0;i<_NR_OF_FMUS;i++){
+		fi->time_last_fmu[i] = orig->time_last_fmu[i];
+	}
+
+	/* Generated */
+	fi->stored_windowsa_u = orig->stored_windowsa_u;
+	fi->stored_windowsa_d = orig->stored_windowsa_d;
+	fi->stored_tau = orig->stored_tau;
+	fi->stored_armature_current = orig->stored_armature_current;
+	fi->stored_speed = orig->stored_speed;
+	fi->stored_displacement = orig->stored_displacement;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+
+	fi->toleranceDefined = orig->toleranceDefined;
+	printf("setting real values\n");
+	//copy r
+	int i=0;
+	for (i=0; i< NUMBER_OF_REALS;i++){
+		fi->r[i] = orig->r[i];
+	}
+	printf("setting string values\n");
+	//copy s
+	for (i=0; i< NUMBER_OF_STRINGS;i++){
+
+		fi->s[i] = orig->s[i];
+	}
+	//copy i
+	for (i=0; i< NUMBER_OF_INTEGERS;i++){
+		fi->i[i] = orig->i[i];
+	}
+	//copy b
+	for (i=0; i< NUMBER_OF_BOOLEANS;i++){
+		fi->b[i] = orig->b[i];
+	}
+	return fmi2OK;
+
+
+}
+/****************************************************/
+
+fmi2Status fmi2FreeFMUstate(fmi2Component c, fmi2FMUstate* FMUstate) {
+	printf("Function fmiFreeFMUstate not supported\n");
+	return fmi2Error;
+}
+fmi2Status fmi2SerializedFMUstateSize(fmi2Component c, fmi2FMUstate FMUstate, size_t *size) {
+	printf("Function fmiSerializedFMUstateSize not supported\n");
+	return fmi2Error;
+}
+fmi2Status fmi2SerializeFMUstate (fmi2Component c, fmi2FMUstate FMUstate, fmi2Byte serializedState[], size_t size) {
+	printf("Function fmiSerializeFMUstate not supported\n");
+	return fmi2Error;
+}
+fmi2Status fmi2DeSerializeFMUstate (fmi2Component c, const fmi2Byte serializedState[], size_t size, fmi2FMUstate* FMUstate) {
+	printf("Function fmiDeSerializeFMUstate not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetDirectionalDerivative(fmi2Component c, const fmi2ValueReference vUnknown_ref[], size_t nUnknown,
+		const fmi2ValueReference vKnown_ref[] , size_t nKnown, const fmi2Real dvKnown[], fmi2Real dvUnknown[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+
+fmi2Status fmi2SetRealInputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
+		const fmi2Integer order[], const fmi2Real value[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetRealOutputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
+		const fmi2Integer order[], fmi2Real value[]) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2CancelStep(fmi2Component c) {
+	printf("Function fmiGetDirectionalDerivative not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetStatus(fmi2Component c, const fmi2StatusKind s, fmi2Status *value) {
+	printf("Function fmiGetStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetRealStatus(fmi2Component c, const fmi2StatusKind s, fmi2Real *value) {
+	if(s == fmi2LastSuccessfulTime){
+		FMUInstance* comp = (FMUInstance*) c;
+		*value = comp->currentTime;
+		return fmi2OK;
+	}
+	printf("Function fmiGetRealStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetIntegerStatus(fmi2Component c, const fmi2StatusKind s, fmi2Integer *value) {
+	printf("Function fmiGetIntegerStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetBooleanStatus(fmi2Component c, const fmi2StatusKind s, fmi2Boolean *value) {
+	printf("Function fmiGetBooleanStatus not supported\n");
+	return fmi2Error;
+}
+
+fmi2Status fmi2GetStringStatus(fmi2Component c, const fmi2StatusKind s, fmi2String *value) {
+	printf("Function fmiGetStringStatus not supported\n");
+	return fmi2Error;
+}

+ 62 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/FMI_power_sa.h

@@ -0,0 +1,62 @@
+/*
+ * PW_Controller.h
+ *
+ *  Created on: Jan 25, 2017
+ *      Author: Joachim
+ */
+
+#ifndef FMI_POWER_SA_H_
+#define FMI_POWER_SA_H_
+
+#include "fmi2.h"
+
+typedef enum {
+    fmuInstantiated = 0,
+    fmuInitMode  = 1,
+	fmuInitialized = 2,
+    fmuTerminated   = 3,
+    fmuError        = 4,
+    fmuExperimentSettedUp = 5
+} FMUState;
+
+#define _NR_OF_FMUS 1
+#define _NR_OF_IN_CONDITIONS 1
+#define _NR_OF_OUT_CONDITIONS 1
+
+typedef struct {
+	fmi2Real    *r;
+    fmi2Integer *i;
+    fmi2Boolean *b;
+    fmi2String  *s;
+    fmi2Boolean isVisible;
+    fmi2String instanceName;
+    fmi2String GUID;
+    const fmi2CallbackFunctions* functions;
+    fmi2Boolean loggingOn;
+    FMUState state;
+    fmi2Real startTime;
+    fmi2Real stopTime;
+	fmi2Real currentTime;
+    fmi2Boolean stopTimeDefined;
+    fmi2Boolean toleranceDefined;
+    /* for generic algo*/
+    FMU fmu[_NR_OF_FMUS];
+    char *fmuResourceLocation[_NR_OF_FMUS];
+    fmi2Component c_fmu[_NR_OF_FMUS];
+    fmi2Boolean in_condition_executed[_NR_OF_IN_CONDITIONS];
+    fmi2Boolean out_conditions_executed[_NR_OF_OUT_CONDITIONS];
+    fmi2Real time_last_fmu[_NR_OF_FMUS];
+    /* Generated */
+	fmi2Real stored_windowsa_u;
+	fmi2Real stored_windowsa_d;
+	fmi2Real stored_tau;
+	fmi2Real stored_armature_current;
+	fmi2Real stored_speed;
+	fmi2Real stored_displacement;
+
+} FMUInstance; // At the moment, most of the variables not really used since multiple instances of an FMU are not supported at the moment (performance issues)
+
+
+
+
+#endif /* FMI_POWER_SA_H_ */

+ 72 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/fmi2/fmi2.h

@@ -0,0 +1,72 @@
+/* -------------------------------------------------------------------------
+ * 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 "fmi2Functions.h"
+
+typedef struct {
+//    ModelDescription* modelDescription;
+
+    void  *dllHandle; // fmu.so 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
+

+ 247 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/fmi2/fmi2FunctionTypes.h

@@ -0,0 +1,247 @@
+#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 (C) 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);
+#ifdef FMU_EXPERIMENTAL
+   typedef fmi2Status fmi2GetSpecificDerivativesTYPE       (fmi2Component, fmi2Real[], const fmi2ValueReference [], size_t);
+#endif
+
+   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 */

+ 339 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/fmi2/fmi2Functions.h

@@ -0,0 +1,339 @@
+#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 (C) 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)
+#ifdef FMU_EXPERIMENTAL
+#define fmi2GetSpecificDerivatives        fmi2FullName(fmi2GetSpecificDerivatives)
+#endif
+#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;
+#ifdef FMU_EXPERIMENTAL
+   FMI2_Export fmi2GetSpecificDerivativesTYPE        fmi2GetSpecificDerivatives;
+#endif
+   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/fmu/cs/FMI_power_sa - Copy (2)/fmi2/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 (C) 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 */

+ 594 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/sim_support.c

@@ -0,0 +1,594 @@
+/* -------------------------------------------------------------------------
+ * sim_support.c
+ * Functions used by both FMU simulators fmu20sim_me and fmu20sim_cs
+ * to parse command-line arguments, to unzip and load an fmu,
+ * to write CSV file, and more.
+ *
+ * Revision history
+ *  07.03.2014 initial version released in FMU SDK 2.0.0
+ *  10.04.2014 use FMI 2.0 headers that prefix function and type names with 'fmi2'.
+ *             When 'fmi2' functions are not found in loaded DLL, look also for
+ *             FMI 2.0 RC1 function names.
+ *
+ * Author: Adrian Tirea
+ * Copyright QTronic GmbH. All rights reserved.
+ * -------------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <stdarg.h>
+#include <dlfcn.h>
+#include "fmi2.h"
+#include "sim_support.h"
+
+#define FMI_COSIMULATION
+extern FMU fmu;
+
+
+//int unzip(const char *zipPath, const char *outPath) {
+//    int code;
+//    char cwd[BUFSIZE];
+//    char binPath[BUFSIZE];
+//    int n = strlen(UNZIP_CMD) + strlen(outPath) + 3 +  strlen(zipPath) + 9;
+//    char* cmd = (char*)calloc(sizeof(char), n);
+//
+//    // remember current directory
+//    if (!GetCurrentDirectory(BUFSIZE, cwd)) {
+//        printf ("error: Could not get current directory\n");
+//        return 0; // error
+//    }
+//
+//    // change to %FMUSDK_HOME%\bin to find 7z.dll and 7z.exe
+//    if (!GetEnvironmentVariable("FMUSDK_HOME", binPath, BUFSIZE)) {
+//        if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
+//            printf ("error: Environment variable FMUSDK_HOME not defined\n");
+//        }
+//        else {
+//            printf ("error: Could not get value of FMUSDK_HOME\n");
+//        }
+//        return 0; // error
+//    }
+//    strcat(binPath, "\\bin");
+//    if (!SetCurrentDirectory(binPath)) {
+//        printf ("error: could not change to directory '%s'\n", binPath);
+//        return 0; // error
+//    }
+//
+//    // run the unzip command
+//    // remove "> NUL" to see the unzip protocol
+//    sprintf(cmd, "%s\"%s\" \"%s\" > NUL", UNZIP_CMD, outPath, zipPath);
+//    // printf("cmd='%s'\n", cmd);
+//    code = system(cmd);
+//    free(cmd);
+//    if (code != SEVEN_ZIP_NO_ERROR) {
+//        printf("7z: ");
+//        switch (code) {
+//            case SEVEN_ZIP_WARNING:            printf("warning\n"); break;
+//            case SEVEN_ZIP_ERROR:              printf("error\n"); break;
+//            case SEVEN_ZIP_COMMAND_LINE_ERROR: printf("command line error\n"); break;
+//            case SEVEN_ZIP_OUT_OF_MEMORY:      printf("out of memory\n"); break;
+//            case SEVEN_ZIP_STOPPED_BY_USER:    printf("stopped by user\n"); break;
+//            default: printf("unknown problem\n");
+//        }
+//    }
+//
+//    // restore current directory
+//    SetCurrentDirectory(cwd);
+//    return (code == SEVEN_ZIP_NO_ERROR || code == SEVEN_ZIP_WARNING) ? 1 : 0;
+//}
+//
+//// fileName is an absolute path, e.g. C:\test\a.fmu
+//// or relative to the current dir, e.g. ..\test\a.fmu
+//// Does not check for existence of the file
+//static char* getFmuPath(const char* fileName){
+//    char pathName[MAX_PATH];
+//    int n = GetFullPathName(fileName, MAX_PATH, pathName, NULL);
+//    return n ? strdup(pathName) : NULL;
+//}
+//
+//static char* getTmpPath() {
+//    char tmpPath[BUFSIZE];
+//    if(! GetTempPath(BUFSIZE, tmpPath)) {
+//        printf ("error: Could not find temporary disk space\n");
+//        return NULL;
+//    }
+//    strcat(tmpPath, "fmu\\");
+//    return strdup(tmpPath);
+//}
+//
+//char *getTempResourcesLocation() {
+//    char *tempPath = getTmpPath();
+//    char *resourcesLocation = (char *)calloc(sizeof(char), 9 + strlen(RESOURCES_DIR) + strlen(tempPath));
+//    strcpy(resourcesLocation, "file:///");
+//    strcat(resourcesLocation, tempPath);
+//    strcat(resourcesLocation, RESOURCES_DIR);
+//    free(tempPath);
+//    return resourcesLocation;
+//}
+
+static void *getAdr(int *success, void *dllHandle, const char *functionName, const char* preamble) {
+
+    int length = strlen(preamble) + strlen(functionName) + 1;
+    char* new_name = malloc(length);  // allocate memory
+    strcpy(new_name, preamble);  // copy first string
+    strcat(new_name, functionName);
+    void* fp = dlsym(dllHandle, new_name);
+    if (!fp) {
+        printf("warning: Function %s not found in dll\n", new_name);
+        *success = 0;
+    }
+    free(new_name);
+    return fp;
+}
+
+// Load the given dll and set function pointers in fmu
+// Return 0 to indicate failure
+int loadDll(const char* dllPath, FMU *fmu, const char* preamble) {
+    int x = 1, s = 1;
+    //HMODULE h = LoadLibrary(dllPath);
+    void *h = dlopen(dllPath, RTLD_LAZY);
+    printf("%s", dlerror());
+    if (!h) {
+        printf("error: Could not load %s\n", dllPath);
+        return 0; // failure
+    }
+    fmu->dllHandle = h;
+    fmu->getTypesPlatform          = (fmi2GetTypesPlatformTYPE *)      getAdr(&s, h, "fmi2GetTypesPlatform", preamble);
+    fmu->getVersion                = (fmi2GetVersionTYPE *)            getAdr(&s, h, "fmi2GetVersion", preamble);
+    fmu->setDebugLogging           = (fmi2SetDebugLoggingTYPE *)       getAdr(&s, h, "fmi2SetDebugLogging",preamble);
+    fmu->instantiate               = (fmi2InstantiateTYPE *)           getAdr(&s, h, "fmi2Instantiate", preamble);
+    fmu->freeInstance              = (fmi2FreeInstanceTYPE *)          getAdr(&s, h, "fmi2FreeInstance", preamble);
+    fmu->setupExperiment           = (fmi2SetupExperimentTYPE *)       getAdr(&s, h, "fmi2SetupExperiment", preamble);
+    fmu->enterInitializationMode   = (fmi2EnterInitializationModeTYPE *) getAdr(&s, h, "fmi2EnterInitializationMode", preamble);
+    fmu->exitInitializationMode    = (fmi2ExitInitializationModeTYPE *) getAdr(&s, h, "fmi2ExitInitializationMode", preamble);
+    fmu->terminate                 = (fmi2TerminateTYPE *)             getAdr(&s, h, "fmi2Terminate", preamble);
+    fmu->reset                     = (fmi2ResetTYPE *)                 getAdr(&s, h, "fmi2Reset", preamble);
+    fmu->getReal                   = (fmi2GetRealTYPE *)               getAdr(&s, h, "fmi2GetReal", preamble);
+    fmu->getInteger                = (fmi2GetIntegerTYPE *)            getAdr(&s, h, "fmi2GetInteger", preamble);
+    fmu->getBoolean                = (fmi2GetBooleanTYPE *)            getAdr(&s, h, "fmi2GetBoolean", preamble);
+    fmu->getString                 = (fmi2GetStringTYPE *)             getAdr(&s, h, "fmi2GetString", preamble);
+    fmu->setReal                   = (fmi2SetRealTYPE *)               getAdr(&s, h, "fmi2SetReal", preamble);
+    fmu->setInteger                = (fmi2SetIntegerTYPE *)            getAdr(&s, h, "fmi2SetInteger", preamble);
+    fmu->setBoolean                = (fmi2SetBooleanTYPE *)            getAdr(&s, h, "fmi2SetBoolean", preamble);
+    fmu->setString                 = (fmi2SetStringTYPE *)             getAdr(&s, h, "fmi2SetString", preamble);
+    fmu->getFMUstate               = (fmi2GetFMUstateTYPE *)           getAdr(&s, h, "fmi2GetFMUstate", preamble);
+    fmu->setFMUstate               = (fmi2SetFMUstateTYPE *)           getAdr(&s, h, "fmi2SetFMUstate", preamble);
+    fmu->freeFMUstate              = (fmi2FreeFMUstateTYPE *)          getAdr(&s, h, "fmi2FreeFMUstate", preamble);
+    fmu->serializedFMUstateSize    = (fmi2SerializedFMUstateSizeTYPE *) getAdr(&s, h, "fmi2SerializedFMUstateSize", preamble);
+    fmu->serializeFMUstate         = (fmi2SerializeFMUstateTYPE *)     getAdr(&s, h, "fmi2SerializeFMUstate", preamble);
+    fmu->deSerializeFMUstate       = (fmi2DeSerializeFMUstateTYPE *)   getAdr(&s, h, "fmi2DeSerializeFMUstate", preamble);
+    fmu->getDirectionalDerivative  = (fmi2GetDirectionalDerivativeTYPE *) getAdr(&s, h, "fmi2GetDirectionalDerivative", preamble);
+#ifdef FMI_COSIMULATION
+    fmu->setRealInputDerivatives   = (fmi2SetRealInputDerivativesTYPE *) getAdr(&s, h, "fmi2SetRealInputDerivatives", preamble);
+    fmu->getRealOutputDerivatives  = (fmi2GetRealOutputDerivativesTYPE *) getAdr(&s, h, "fmi2GetRealOutputDerivatives", preamble);
+    fmu->doStep                    = (fmi2DoStepTYPE *)                getAdr(&s, h, "fmi2DoStep", preamble);
+    fmu->cancelStep                = (fmi2CancelStepTYPE *)            getAdr(&s, h, "fmi2CancelStep", preamble);
+    fmu->getStatus                 = (fmi2GetStatusTYPE *)             getAdr(&s, h, "fmi2GetStatus", preamble);
+    fmu->getRealStatus             = (fmi2GetRealStatusTYPE *)         getAdr(&s, h, "fmi2GetRealStatus", preamble);
+    fmu->getIntegerStatus          = (fmi2GetIntegerStatusTYPE *)      getAdr(&s, h, "fmi2GetIntegerStatus", preamble);
+    fmu->getBooleanStatus          = (fmi2GetBooleanStatusTYPE *)      getAdr(&s, h, "fmi2GetBooleanStatus", preamble);
+    fmu->getStringStatus           = (fmi2GetStringStatusTYPE *)       getAdr(&s, h, "fmi2GetStringStatus", preamble);
+#else // FMI2 for Model Exchange
+    fmu->enterEventMode            = (fmi2EnterEventModeTYPE *)        getAdr(&s, h, "fmi2EnterEventMode", preamble);
+    fmu->newDiscreteStates         = (fmi2NewDiscreteStatesTYPE *)     getAdr(&s, h, "fmi2NewDiscreteStates", preamble);
+    fmu->enterContinuousTimeMode   = (fmi2EnterContinuousTimeModeTYPE *) getAdr(&s, h, "fmi2EnterContinuousTimeMode", preamble);
+    fmu->completedIntegratorStep   = (fmi2CompletedIntegratorStepTYPE *) getAdr(&s, h, "fmi2CompletedIntegratorStep", preamble);
+    fmu->setTime                   = (fmi2SetTimeTYPE *)               getAdr(&s, h, "fmi2SetTime", preamble);
+    fmu->setContinuousStates       = (fmi2SetContinuousStatesTYPE *)   getAdr(&s, h, "fmi2SetContinuousStates", preamble);
+    fmu->getDerivatives            = (fmi2GetDerivativesTYPE *)        getAdr(&s, h, "fmi2GetDerivatives", preamble);
+    fmu->getEventIndicators        = (fmi2GetEventIndicatorsTYPE *)    getAdr(&s, h, "fmi2GetEventIndicators", preamble);
+    fmu->getContinuousStates       = (fmi2GetContinuousStatesTYPE *)   getAdr(&s, h, "fmi2GetContinuousStates", preamble);
+    fmu->getNominalsOfContinuousStates = (fmi2GetNominalsOfContinuousStatesTYPE *) getAdr(&s, h, "fmi2GetNominalsOfContinuousStates", preamble);
+#endif
+
+    if (fmu->getVersion == NULL && fmu->instantiate == NULL) {
+        printf("warning: Functions from FMI 2.0 could not be found in %s\n", dllPath);
+        printf("warning: Simulator will look for FMI 2.0 RC1 functions names...\n");
+        fmu->getTypesPlatform          = (fmi2GetTypesPlatformTYPE *)      getAdr(&s, h, "fmiGetTypesPlatform", preamble);
+        fmu->getVersion                = (fmi2GetVersionTYPE *)            getAdr(&s, h, "fmiGetVersion", preamble);
+        fmu->setDebugLogging           = (fmi2SetDebugLoggingTYPE *)       getAdr(&s, h, "fmiSetDebugLogging", preamble);
+        fmu->instantiate               = (fmi2InstantiateTYPE *)           getAdr(&s, h, "fmiInstantiate", preamble);
+        fmu->freeInstance              = (fmi2FreeInstanceTYPE *)          getAdr(&s, h, "fmiFreeInstance", preamble);
+        fmu->setupExperiment           = (fmi2SetupExperimentTYPE *)       getAdr(&s, h, "fmiSetupExperiment", preamble);
+        fmu->enterInitializationMode   = (fmi2EnterInitializationModeTYPE *) getAdr(&s, h, "fmiEnterInitializationMode", preamble);
+        fmu->exitInitializationMode    = (fmi2ExitInitializationModeTYPE *) getAdr(&s, h, "fmiExitInitializationMode", preamble);
+        fmu->terminate                 = (fmi2TerminateTYPE *)             getAdr(&s, h, "fmiTerminate", preamble);
+        fmu->reset                     = (fmi2ResetTYPE *)                 getAdr(&s, h, "fmiReset", preamble);
+        fmu->getReal                   = (fmi2GetRealTYPE *)               getAdr(&s, h, "fmiGetReal", preamble);
+        fmu->getInteger                = (fmi2GetIntegerTYPE *)            getAdr(&s, h, "fmiGetInteger", preamble);
+        fmu->getBoolean                = (fmi2GetBooleanTYPE *)            getAdr(&s, h, "fmiGetBoolean", preamble);
+        fmu->getString                 = (fmi2GetStringTYPE *)             getAdr(&s, h, "fmiGetString", preamble);
+        fmu->setReal                   = (fmi2SetRealTYPE *)               getAdr(&s, h, "fmiSetReal", preamble);
+        fmu->setInteger                = (fmi2SetIntegerTYPE *)            getAdr(&s, h, "fmiSetInteger", preamble);
+        fmu->setBoolean                = (fmi2SetBooleanTYPE *)            getAdr(&s, h, "fmiSetBoolean", preamble);
+        fmu->setString                 = (fmi2SetStringTYPE *)             getAdr(&s, h, "fmiSetString", preamble);
+        fmu->getFMUstate               = (fmi2GetFMUstateTYPE *)           getAdr(&s, h, "fmiGetFMUstate", preamble);
+        fmu->setFMUstate               = (fmi2SetFMUstateTYPE *)           getAdr(&s, h, "fmiSetFMUstate", preamble);
+        fmu->freeFMUstate              = (fmi2FreeFMUstateTYPE *)          getAdr(&s, h, "fmiFreeFMUstate", preamble);
+        fmu->serializedFMUstateSize    = (fmi2SerializedFMUstateSizeTYPE *) getAdr(&s, h, "fmiSerializedFMUstateSize", preamble);
+        fmu->serializeFMUstate         = (fmi2SerializeFMUstateTYPE *)     getAdr(&s, h, "fmiSerializeFMUstate", preamble);
+        fmu->deSerializeFMUstate       = (fmi2DeSerializeFMUstateTYPE *)   getAdr(&s, h, "fmiDeSerializeFMUstate", preamble);
+        fmu->getDirectionalDerivative  = (fmi2GetDirectionalDerivativeTYPE *) getAdr(&s, h, "fmiGetDirectionalDerivative", preamble);
+    #ifdef FMI_COSIMULATION
+        fmu->setRealInputDerivatives   = (fmi2SetRealInputDerivativesTYPE *) getAdr(&s, h, "fmiSetRealInputDerivatives", preamble);
+        fmu->getRealOutputDerivatives  = (fmi2GetRealOutputDerivativesTYPE *) getAdr(&s, h, "fmiGetRealOutputDerivatives", preamble);
+        fmu->doStep                    = (fmi2DoStepTYPE *)                getAdr(&s, h, "fmiDoStep", preamble);
+        fmu->cancelStep                = (fmi2CancelStepTYPE *)            getAdr(&s, h, "fmiCancelStep", preamble);
+        fmu->getStatus                 = (fmi2GetStatusTYPE *)             getAdr(&s, h, "fmiGetStatus", preamble);
+        fmu->getRealStatus             = (fmi2GetRealStatusTYPE *)         getAdr(&s, h, "fmiGetRealStatus", preamble);
+        fmu->getIntegerStatus          = (fmi2GetIntegerStatusTYPE *)      getAdr(&s, h, "fmiGetIntegerStatus", preamble);
+        fmu->getBooleanStatus          = (fmi2GetBooleanStatusTYPE *)      getAdr(&s, h, "fmiGetBooleanStatus", preamble);
+        fmu->getStringStatus           = (fmi2GetStringStatusTYPE *)       getAdr(&s, h, "fmiGetStringStatus", preamble);
+    #else // FMI2 for Model Exchange
+        fmu->enterEventMode            = (fmi2EnterEventModeTYPE *)        getAdr(&s, h, "fmiEnterEventMode", preamble);
+        fmu->newDiscreteStates         = (fmi2NewDiscreteStatesTYPE *)     getAdr(&s, h, "fmiNewDiscreteStates", preamble);
+        fmu->enterContinuousTimeMode   = (fmi2EnterContinuousTimeModeTYPE *) getAdr(&s, h, "fmiEnterContinuousTimeMode", preamble);
+        fmu->completedIntegratorStep   = (fmi2CompletedIntegratorStepTYPE *) getAdr(&s, h, "fmiCompletedIntegratorStep", preamble);
+        fmu->setTime                   = (fmi2SetTimeTYPE *)               getAdr(&s, h, "fmiSetTime", preamble);
+        fmu->setContinuousStates       = (fmi2SetContinuousStatesTYPE *)   getAdr(&s, h, "fmiSetContinuousStates", preamble);
+        fmu->getDerivatives            = (fmi2GetDerivativesTYPE *)        getAdr(&s, h, "fmiGetDerivatives", preamble);
+        fmu->getEventIndicators        = (fmi2GetEventIndicatorsTYPE *)    getAdr(&s, h, "fmiGetEventIndicators", preamble);
+        fmu->getContinuousStates       = (fmi2GetContinuousStatesTYPE *)   getAdr(&s, h, "fmiGetContinuousStates", preamble);
+        fmu->getNominalsOfContinuousStates = (fmi2GetNominalsOfContinuousStatesTYPE *) getAdr(&s, h, "fmiGetNominalsOfContinuousStates", preamble);
+    #endif
+    }
+    return s;
+}
+
+//static void printModelDescription(ModelDescription* md){
+//    Element* e = (Element*)md;
+//    int i;
+//    int n; // number of attributes
+//    const char **attributes = getAttributesAsArray(e, &n);
+//    Component *component;
+//
+//    if (!attributes) {
+//        printf("ModelDescription printing aborted.");
+//        return;
+//    }
+//    printf("%s\n", getElementTypeName(e));
+//    for (i = 0; i < n; i += 2) {
+//        printf("  %s=%s\n", attributes[i], attributes[i+1]);
+//    }
+//    free((void *)attributes);
+//
+//#ifdef FMI_COSIMULATION
+//    component = getCoSimulation(md);
+//    if (!component) {
+//        printf("error: No CoSimulation element found in model description. This FMU is not for Co-Simulation.\n");
+//        exit(EXIT_FAILURE);
+//    }
+//#else // FMI_MODEL_EXCHANGE
+//    component = getModelExchange(md);
+//    if (!component) {
+//        printf("error: No ModelExchange element found in model description. This FMU is not for Model Exchange.\n");
+//        exit(EXIT_FAILURE);
+//    }
+//#endif
+//    printf("%s\n", getElementTypeName((Element *)component));
+//    attributes = getAttributesAsArray((Element *)component, &n);
+//    if (!attributes) {
+//        printf("ModelDescription printing aborted.");
+//        return;
+//    }
+//    for (i = 0; i < n; i += 2) {
+//        printf("  %s=%s\n", attributes[i], attributes[i+1]);
+//    }
+//
+//    free((void *)attributes);
+//}
+//
+//void loadFMU(const char* fmuFileName) {
+//    char* fmuPath;
+//    char* tmpPath;
+//    char* xmlPath;
+//    char* dllPath;
+//    const char *modelId;
+//
+//    // get absolute path to FMU, NULL if not found
+//    fmuPath = getFmuPath(fmuFileName);
+//    if (!fmuPath) exit(EXIT_FAILURE);
+//
+//    // unzip the FMU to the tmpPath directory
+//    tmpPath = getTmpPath();
+//    if (!unzip(fmuPath, tmpPath)) exit(EXIT_FAILURE);
+//
+//    // parse tmpPath\modelDescription.xml
+//    xmlPath = calloc(sizeof(char), strlen(tmpPath) + strlen(XML_FILE) + 1);
+//    sprintf(xmlPath, "%s%s", tmpPath, XML_FILE);
+//    fmu.modelDescription = parse(xmlPath);
+//    free(xmlPath);
+//    if (!fmu.modelDescription) exit(EXIT_FAILURE);
+//    printModelDescription(fmu.modelDescription);
+//#ifdef FMI_COSIMULATION
+//    modelId = getAttributeValue((Element *)getCoSimulation(fmu.modelDescription), att_modelIdentifier);
+//#else // FMI_MODEL_EXCHANGE
+//    modelId = getAttributeValue((Element *)getModelExchange(fmu.modelDescription), att_modelIdentifier);
+//#endif
+//    // load the FMU dll
+//    dllPath = calloc(sizeof(char), strlen(tmpPath) + strlen(DLL_DIR)
+//        + strlen(modelId) +  strlen(".dll") + 1);
+//    sprintf(dllPath, "%s%s%s.dll", tmpPath, DLL_DIR, modelId);
+//    if (!loadDll(dllPath, &fmu)) {
+//        exit(EXIT_FAILURE);
+//    }
+//    free(dllPath);
+//    free(fmuPath);
+//    free(tmpPath);
+//}
+//
+//void deleteUnzippedFiles() {
+//    const char *fmuTempPath = getTmpPath();
+//    char *cmd = (char *)calloc(15 + strlen(fmuTempPath), sizeof(char));
+//    sprintf(cmd, "rmdir /S /Q %s", fmuTempPath);
+//    system(cmd);
+//    free(cmd);
+//}
+//
+//static void doubleToCommaString(char* buffer, double r){
+//    char* comma;
+//    sprintf(buffer, "%.16g", r);
+//    comma = strchr(buffer, '.');
+//    if (comma) *comma = ',';
+//}
+//
+//// output time and all variables in CSV format
+//// if separator is ',', columns are separated by ',' and '.' is used for floating-point numbers.
+//// otherwise, the given separator (e.g. ';' or '\t') is to separate columns, and ',' is used
+//// as decimal dot in floating-point numbers.
+//void outputRow(FMU *fmu, fmi2Component c, double time, FILE* file, char separator, fmi2Boolean header) {
+//    int k;
+//    fmi2Real r;
+//    fmi2Integer i;
+//    fmi2Boolean b;
+//    fmi2String s;
+//    fmi2ValueReference vr;
+//    int n = getScalarVariableSize(fmu->modelDescription);
+//    char buffer[32];
+//
+//    // print first column
+//    if (header) {
+//        fprintf(file, "time");
+//    } else {
+//        if (separator==',')
+//            fprintf(file, "%.16g", time);
+//        else {
+//            // separator is e.g. ';' or '\t'
+//            doubleToCommaString(buffer, time);
+//            fprintf(file, "%s", buffer);
+//        }
+//    }
+//
+//    // print all other columns
+//    for (k = 0; k < n; k++) {
+//        ScalarVariable *sv = getScalarVariable(fmu->modelDescription, k);
+//        if (header) {
+//            // output names only
+//            if (separator == ',') {
+//                // treat array element, e.g. print a[1, 2] as a[1.2]
+//                const char *s = getAttributeValue((Element *)sv, att_name);
+//                fprintf(file, "%c", separator);
+//                while (*s) {
+//                    if (*s != ' ') {
+//                        fprintf(file, "%c", *s == ',' ? '.' : *s);
+//                    }
+//                    s++;
+//                }
+//            } else {
+//                fprintf(file, "%c%s", separator, getAttributeValue((Element *)sv, att_name));
+//            }
+//        } else {
+//            // output values
+//            vr = getValueReference(sv);
+//            switch (getElementType(getTypeSpec(sv))) {
+//                case elm_Real:
+//                    fmu->getReal(c, &vr, 1, &r);
+//                    if (separator == ',') {
+//                        fprintf(file, ",%.16g", r);
+//                    } else {
+//                        // separator is e.g. ';' or '\t'
+//                        doubleToCommaString(buffer, r);
+//                        fprintf(file, "%c%s", separator, buffer);
+//                    }
+//                    break;
+//                case elm_Integer:
+//                case elm_Enumeration:
+//                    fmu->getInteger(c, &vr, 1, &i);
+//                    fprintf(file, "%c%d", separator, i);
+//                    break;
+//                case elm_Boolean:
+//                    fmu->getBoolean(c, &vr, 1, &b);
+//                    fprintf(file, "%c%d", separator, b);
+//                    break;
+//                case elm_String:
+//                    fmu->getString(c, &vr, 1, &s);
+//                    fprintf(file, "%c%s", separator, s);
+//                    break;
+//                default:
+//                    fprintf(file, "%cNoValueForType=%d", separator, getElementType(getTypeSpec(sv)));
+//            }
+//        }
+//    } // for
+//
+//    // terminate this row
+//    fprintf(file, "\n");
+//}
+//
+static const char* fmi2StatusToString(fmi2Status status){
+    switch (status){
+        case fmi2OK:      return "ok";
+        case fmi2Warning: return "warning";
+        case fmi2Discard: return "discard";
+        case fmi2Error:   return "error";
+        case fmi2Fatal:   return "fatal";
+    #ifdef FMI_COSIMULATION
+        case fmi2Pending: return "fmi2Pending";
+    #endif
+        default:         return "?";
+    }
+}
+
+// search a fmu for the given variable, matching the type specified.
+// return NULL if not found
+//static ScalarVariable* getSV(FMU* fmu, char type, fmi2ValueReference vr) {
+//    return NULL;
+//    int i;
+//    int n = getScalarVariableSize(fmu->modelDescription);
+//    Elm tp;
+//
+//    switch (type) {
+//        case 'r': tp = elm_Real;    break;
+//        case 'i': tp = elm_Integer; break;
+//        case 'b': tp = elm_Boolean; break;
+//        case 's': tp = elm_String;  break;
+//        default : tp = elm_BAD_DEFINED;
+//    }
+//    for (i = 0; i < n; i++) {
+//        ScalarVariable* sv = getScalarVariable(fmu->modelDescription ,i);
+//        if (vr == getValueReference(sv) && tp == getElementType(getTypeSpec(sv))) {
+//            return sv;
+//        }
+//    }
+//    return NULL;
+//}
+
+// replace e.g. #r1365# by variable name and ## by # in message
+// copies the result to buffer
+static void replaceRefsInMessage(const char* msg, char* buffer, int nBuffer, FMU* fmu){
+    int i = 0; // position in msg
+    int k = 0; // position in buffer
+    int n;
+    char c = msg[i];
+    while (c != '\0' && k < nBuffer) {
+        if (c != '#') {
+            buffer[k++] = c;
+            i++;
+            c = msg[i];
+        } else {
+
+            char* end = strchr(msg + i + 1, '#');
+            if (!end) {
+                printf("unmatched '#' in '%s'\n", msg);
+                buffer[k++] = '#';
+                break;
+            }
+            n = end - (msg + i);
+            if (n == 1) {
+                // ## detected, output #
+                buffer[k++] = '#';
+                i += 2;
+                c = msg[i];
+
+            } else {
+                char type = msg[i + 1]; // one of ribs
+                fmi2ValueReference vr;
+                int nvr = sscanf(msg + i + 2, "%u", &vr);
+                if (nvr == 1) {
+                    // vr of type detected, e.g. #r12#
+                    //ScalarVariable* sv = getSV(fmu, type, vr);
+                    //const char* name = sv ? getAttributeValue((Element *)sv, att_name) : "?";
+                    //sprintf(buffer + k, "%s", name);
+                    //k += strlen(name);
+                    //i += (n+1);
+                    //c = msg[i];
+
+                } else {
+                    // could not parse the number
+                    printf("illegal value reference at position %d in '%s'\n", i + 2, msg);
+                    buffer[k++] = '#';
+                    break;
+                }
+            }
+        }
+    } // while
+    buffer[k] = '\0';
+}
+
+#define MAX_MSG_SIZE 1000
+void fmuLogger(void *componentEnvironment, fmi2String instanceName, fmi2Status status,
+               fmi2String category, fmi2String message, ...) {
+    char msg[MAX_MSG_SIZE];
+    char* copy;
+    va_list argp;
+
+    // replace C format strings
+    va_start(argp, message);
+    vsprintf(msg, message, argp);
+    va_end(argp);
+
+    // replace e.g. ## and #r12#
+    copy = strdup(msg);
+//    replaceRefsInMessage(copy, msg, MAX_MSG_SIZE, NULL);
+    free(copy);
+
+    // print the final message
+    if (!instanceName) instanceName = "?";
+    if (!category) category = "?";
+    printf("%s %s (%s): %s\n", fmi2StatusToString(status), instanceName, category, msg);
+}
+
+int error(const char* message){
+    printf("%s\n", message);
+    return 0;
+}
+//
+//void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tEnd, double *h,
+//                    int *loggingOn, char *csv_separator, int *nCategories, char **logCategories[]) {
+//    // parse command line arguments
+//    if (argc > 1) {
+//        *fmuFileName = argv[1];
+//    } else {
+//        printf("error: no fmu file\n");
+//        printHelp(argv[0]);
+//        exit(EXIT_FAILURE);
+//    }
+//    if (argc > 2) {
+//        if (sscanf(argv[2],"%lf", tEnd) != 1) {
+//            printf("error: The given end time (%s) is not a number\n", argv[2]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 3) {
+//        if (sscanf(argv[3],"%lf", h) != 1) {
+//            printf("error: The given stepsize (%s) is not a number\n", argv[3]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 4) {
+//        if (sscanf(argv[4],"%d", loggingOn) != 1 || *loggingOn < 0 || *loggingOn > 1) {
+//            printf("error: The given logging flag (%s) is not boolean\n", argv[4]);
+//            exit(EXIT_FAILURE);
+//        }
+//    }
+//    if (argc > 5) {
+//        if (strlen(argv[5]) != 1) {
+//            printf("error: The given CSV separator char (%s) is not valid\n", argv[5]);
+//            exit(EXIT_FAILURE);
+//        }
+//        switch (argv[5][0]) {
+//            case 'c': *csv_separator = ','; break; // comma
+//            case 's': *csv_separator = ';'; break; // semicolon
+//            default:  *csv_separator = argv[5][0]; break; // any other char
+//        }
+//    }
+//    if (argc > 6) {
+//        int i;
+//        *nCategories = argc - 6;
+//        *logCategories = (char **)calloc(sizeof(char *), *nCategories);
+//        for (i = 0; i < *nCategories; i++) {
+//            (*logCategories)[i] = argv[i + 6];
+//        }
+//    }
+//}
+//
+//void printHelp(const char *fmusim) {
+//    printf("command syntax: %s <model.fmu> <tEnd> <h> <loggingOn> <csv separator>\n", fmusim);
+//    printf("   <model.fmu> .... path to FMU, relative to current dir or absolute, required\n");
+//    printf("   <tEnd> ......... end  time of simulation,   optional, defaults to 1.0 sec\n");
+//    printf("   <h> ............ step size of simulation,   optional, defaults to 0.1 sec\n");
+//    printf("   <loggingOn> .... 1 to activate logging,     optional, defaults to 0\n");
+//    printf("   <csv separator>. separator in csv file,     optional, c for ',', s for';', defaults to c\n");
+//    printf("   <logCategories>. list of active categories, optional, see modelDescription.xml for possible values\n");
+//}

+ 44 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa - Copy (2)/sim_support.h

@@ -0,0 +1,44 @@
+/* ------------------------------------------------------------------------- 
+ * sim_support.h
+ * Functions used by the FMU simulations fmusim_me and fmusim_cs.
+ * Copyright QTronic GmbH. All rights reserved.
+ * -------------------------------------------------------------------------*/
+#ifndef __SIM_SUPPORT_H
+#define __SIM_SUPPORT_H
+
+// Used 7z options, version 4.57:
+// -x   Extracts files from an archive with their full paths in the current dir, or in an output dir if specified
+// -aoa Overwrite All existing files without prompt
+// -o   Specifies a destination directory where files are to be extracted
+#define UNZIP_CMD "7z x -aoa -o"
+#define XML_FILE  "modelDescription.xml"
+#define RESULT_FILE "result.csv"
+#define BUFSIZE 4096
+#ifdef _WIN64
+#define DLL_DIR   "binaries\\win64\\"
+#else
+#define DLL_DIR   "binaries\\win32\\"
+#endif
+#define RESOURCES_DIR "resources\\"
+
+// return codes of the 7z command line tool
+#define SEVEN_ZIP_NO_ERROR 0 // success
+#define SEVEN_ZIP_WARNING 1  // e.g., one or more files were locked during zip
+#define SEVEN_ZIP_ERROR 2
+#define SEVEN_ZIP_COMMAND_LINE_ERROR 7
+#define SEVEN_ZIP_OUT_OF_MEMORY 8
+#define SEVEN_ZIP_STOPPED_BY_USER 255
+
+void fmuLogger(fmi2Component c, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message, ...);
+int unzip(const char *zipPath, const char *outPath);
+void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tEnd, double *h,
+                    int *loggingOn, char *csv_separator, int *nCategories, char **logCategories[]);
+void loadFMU(const char *fmuFileName);
+int loadDll(const char* dllPath, FMU *fmu, const char* preamble);
+void deleteUnzippedFiles();
+void outputRow(FMU *fmu, fmi2Component c, double time, FILE* file, char separator, fmi2Boolean header);
+int error(const char *message);
+void printHelp(const char *fmusim);
+char *getTempResourcesLocation(); // caller has to free the result
+
+#endif

File diff suppressed because it is too large
+ 134 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/.cproject


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/FMI_CM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/FMI_GM.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/FMI_SEL.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/FMI_power_sa.o


BIN
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/libFMI_power_sa.dll


+ 0 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/FMI_power_sa/Debug/sim_support.o


Some files were not shown because too many files changed in this diff