fmi2Functions.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. #ifndef BUILDFMU
  2. /* needed for source code export */
  3. #include "conf.h"
  4. #endif
  5. #ifdef FMI_2
  6. #include "fmiFunctions_.h"
  7. #include "fmi2Functions_fwd.h"
  8. /* This file contains wrappers for all FMI functions and is provided in
  9. the Dymola distribution instead of the actual implementation. This is
  10. necessary to avoid exposing the latter. */
  11. DYMOLA_STATIC void __enableResultStoring(fmi2Component c);
  12. /***************************************************
  13. Common Functions
  14. ****************************************************/
  15. const char* fmi2GetTypesPlatform()
  16. {
  17. return fmiGetTypesPlatform_();
  18. }
  19. /* ------------------------------------------------------ */
  20. const char* fmi2GetVersion()
  21. {
  22. return fmiGetVersion_();
  23. }
  24. /* ------------------------------------------------------ */
  25. fmi2Status fmi2SetDebugLogging(fmi2Component c, fmi2Boolean loggingOn, size_t nCategories, const fmi2String categories[])
  26. {
  27. return fmiSetDebugLogging_(c, loggingOn, nCategories, categories);
  28. }
  29. /* ------------------------------------------------------ */
  30. fmi2Status fmi2GetReal(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, fmi2Real value[])
  31. {
  32. return fmiGetReal_(c, vr, nvr, value);
  33. }
  34. /* ------------------------------------------------------ */
  35. fmi2Status fmi2GetInteger(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[])
  36. {
  37. return fmiGetInteger_(c, vr, nvr, value);
  38. }
  39. /* ------------------------------------------------------ */
  40. fmi2Status fmi2GetBoolean(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, fmi2Boolean value[])
  41. {
  42. return fmiGetBoolean_(c, vr, nvr, value);
  43. }
  44. /* ------------------------------------------------------ */
  45. fmi2Status fmi2GetString(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, fmi2String value[])
  46. {
  47. return fmiGetString_(c, vr, nvr, value);
  48. }
  49. /* ------------------------------------------------------ */
  50. fmi2Status fmi2SetReal(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, const fmi2Real value[])
  51. {
  52. return fmiSetReal_(c, vr, nvr, value);
  53. }
  54. /* ------------------------------------------------------ */
  55. fmi2Status fmi2SetInteger(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, const fmi2Integer value[])
  56. {
  57. return fmiSetInteger_(c, vr, nvr, value);
  58. }
  59. /* ------------------------------------------------------ */
  60. fmi2Status fmi2SetBoolean(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, const fmi2Boolean value[])
  61. {
  62. return fmiSetBoolean_(c, vr, nvr, value);
  63. }
  64. /* ------------------------------------------------------ */
  65. fmi2Status fmi2SetString(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, const fmi2String value[])
  66. {
  67. return fmiSetString_(c, vr, nvr, value);
  68. }
  69. /* ------------------------------------------------------ */
  70. fmi2Status fmi2GetFMUstate(fmi2Component c, fmi2FMUstate* FMUstate)
  71. {
  72. return fmiGetFMUstate_(c, FMUstate);
  73. }
  74. /* ------------------------------------------------------ */
  75. fmi2Status fmi2SetFMUstate(fmi2Component c, fmi2FMUstate FMUstate)
  76. {
  77. return fmiSetFMUstate_(c, FMUstate);
  78. }
  79. /* ------------------------------------------------------ */
  80. fmi2Status fmi2FreeFMUstate(fmi2Component c, fmi2FMUstate* FMUstate)
  81. {
  82. return fmiFreeFMUstate_(c, FMUstate);
  83. }
  84. /* ------------------------------------------------------ */
  85. fmi2Status fmi2SerializedFMUstateSize(fmi2Component c, fmi2FMUstate FMUstate, size_t *size)
  86. {
  87. return fmiSerializedFMUstateSize_(c, FMUstate, size);
  88. }
  89. /* ------------------------------------------------------ */
  90. fmi2Status fmi2SerializeFMUstate(fmi2Component c, fmi2FMUstate FMUstate, fmi2Byte serializedState[], size_t size)
  91. {
  92. return fmiSerializeFMUstate_(c, FMUstate, serializedState, size);
  93. }
  94. /* ------------------------------------------------------ */
  95. fmi2Status fmi2DeSerializeFMUstate(fmi2Component c, const fmi2Byte serializedState[], size_t size, fmi2FMUstate* FMUstate)
  96. {
  97. return fmiDeSerializeFMUstate_(c, serializedState, size, FMUstate);
  98. }
  99. /* ------------------------------------------------------ */
  100. fmi2Status fmi2GetDirectionalDerivative(fmi2Component c,
  101. const fmi2ValueReference z_ref[],
  102. size_t nz,
  103. const fmi2ValueReference v_ref[],
  104. size_t nv,
  105. const fmi2Real dv[],
  106. fmi2Real dz[])
  107. {
  108. return fmiGetDirectionalDerivative_(c, z_ref, nz, v_ref, nv, dv, dz);
  109. }
  110. fmi2Component fmi2Instantiate(fmi2String instanceName,
  111. fmi2Type fmuType,
  112. fmi2String fmuGUID,
  113. fmi2String fmuResourceLocation,
  114. const fmi2CallbackFunctions* functions,
  115. fmi2Boolean visible,
  116. fmi2Boolean loggingOn)
  117. {
  118. fmi2Component comp = fmiInstantiate_(instanceName, fmuType, fmuGUID, fmuResourceLocation, functions, visible, loggingOn);
  119. #ifndef FMU_SOURCE_CODE_EXPORT
  120. if (comp != NULL) {
  121. /* determine whether to store results or not */
  122. #include "dsmodel_fmuconf.h"
  123. }
  124. #endif /* FMU_SOURCE_CODE_EXPORT */
  125. return comp;
  126. }
  127. void fmi2FreeInstance(fmi2Component c)
  128. {
  129. fmiFreeInstance_(c);
  130. }
  131. fmi2Status fmi2SetupExperiment(fmi2Component c,
  132. fmi2Boolean relativeToleranceDefined,
  133. fmi2Real relativeTolerance,
  134. fmi2Real tStart,
  135. fmi2Boolean tStopDefined,
  136. fmi2Real tStop)
  137. {
  138. return fmiSetupExperiment_(c, relativeToleranceDefined, relativeTolerance, tStart, tStopDefined, tStop);
  139. }
  140. fmi2Status fmi2EnterInitializationMode(fmi2Component c)
  141. {
  142. return fmiEnterInitializationMode_(c);
  143. }
  144. fmi2Status fmi2ExitInitializationMode(fmi2Component c)
  145. {
  146. return fmiExitInitializationMode_(c);
  147. }
  148. fmi2Status fmi2Terminate(fmi2Component c)
  149. {
  150. return fmiTerminate_(c);
  151. }
  152. fmi2Status fmi2Reset(fmi2Component c)
  153. {
  154. return fmiReset_(c);
  155. }
  156. /***************************************************
  157. Functions for FMI for Model Exchange
  158. ****************************************************/
  159. #ifndef FMU_SKIP_MODEL_EXCHANGE
  160. /* ------------------------------------------------------ */
  161. fmi2Status fmi2SetTime(fmi2Component c, fmi2Real time)
  162. {
  163. return fmiSetTime_(c, time);
  164. }
  165. /* ------------------------------------------------------ */
  166. fmi2Status fmi2SetContinuousStates(fmi2Component c, const fmi2Real x[], size_t nx)
  167. {
  168. return fmiSetContinuousStates_(c, x, nx);
  169. }
  170. /* ------------------------------------------------------ */
  171. fmi2Status fmi2EnterEventMode(fmi2Component c)
  172. {
  173. return fmiEnterEventMode_(c);
  174. }
  175. /* ------------------------------------------------------ */
  176. fmi2Status fmi2NewDiscreteStates(fmi2Component c, fmi2EventInfo* eventInfo)
  177. {
  178. return fmiNewDiscreteStates_(c, eventInfo);
  179. }
  180. /* ------------------------------------------------------ */
  181. fmi2Status fmi2EnterContinuousTimeMode(fmi2Component c)
  182. {
  183. return fmiEnterContinuousTimeMode_(c);
  184. }
  185. /* ------------------------------------------------------ */
  186. fmi2Status fmi2GetNominalsOfContinuousStates(fmi2Component c, fmi2Real x_nominal[], size_t nx)
  187. {
  188. return fmiGetNominalsOfContinuousStates_(c, x_nominal, nx);
  189. }
  190. /* ------------------------------------------------------ */
  191. fmi2Status fmi2CompletedIntegratorStep(fmi2Component c,
  192. fmi2Boolean noSetFMUStatePriorToCurrentPoint,
  193. fmi2Boolean* enterEventMode,
  194. fmi2Boolean* terminateSimulation)
  195. {
  196. return fmiCompletedIntegratorStep_(c, noSetFMUStatePriorToCurrentPoint, enterEventMode, terminateSimulation);
  197. }
  198. /* ------------------------------------------------------ */
  199. fmi2Status fmi2GetDerivatives(fmi2Component c, fmi2Real derivatives[], size_t nx)
  200. {
  201. return fmiGetDerivatives_(c, derivatives, nx);
  202. }
  203. /* ------------------------------------------------------ */
  204. fmi2Status fmi2GetEventIndicators(fmi2Component c, fmi2Real eventIndicators[], size_t ni)
  205. {
  206. return fmiGetEventIndicators_(c, eventIndicators, ni);
  207. }
  208. /* ------------------------------------------------------ */
  209. fmi2Status fmi2GetContinuousStates(fmi2Component c, fmi2Real states[], size_t nx)
  210. {
  211. return fmiGetContinuousStates_(c, states, nx);
  212. }
  213. #endif /* FMU_SKIP_MODEL_EXCHANGE */
  214. /***************************************************
  215. Functions for FMI for Co-Simulation
  216. ****************************************************/
  217. #ifndef FMU_SKIP_CO_SIM
  218. /* ------------------------------------------------------ */
  219. fmi2Status fmi2SetRealInputDerivatives(fmi2Component c,
  220. const fmi2ValueReference vr[],
  221. size_t nvr,
  222. const fmi2Integer order[],
  223. const fmi2Real value[])
  224. {
  225. return fmiSetRealInputDerivatives_(c, vr, nvr, order, value);
  226. }
  227. /* ------------------------------------------------------ */
  228. fmi2Status fmi2GetRealOutputDerivatives(fmi2Component c,
  229. const fmi2ValueReference vr[],
  230. size_t nvr,
  231. const fmi2Integer order[],
  232. fmi2Real value[])
  233. {
  234. return fmiGetRealOutputDerivatives_(c, vr, nvr, order, value);
  235. }
  236. /* ------------------------------------------------------ */
  237. fmi2Status fmi2DoStep(fmi2Component c,
  238. fmi2Real currentCommunicationPoint,
  239. fmi2Real communicationStepSize,
  240. fmi2Boolean noSetFMUStatePriorToCurrentPoint)
  241. {
  242. return fmiDoStep_(c, currentCommunicationPoint, communicationStepSize, noSetFMUStatePriorToCurrentPoint);
  243. }
  244. /* ------------------------------------------------------ */
  245. fmi2Status fmi2CancelStep(fmi2Component c)
  246. {
  247. return fmiCancelStep_(c);
  248. }
  249. /* ------------------------------------------------------ */
  250. fmi2Status fmi2GetStatus(fmi2Component c, const fmi2StatusKind s, fmi2Status* value)
  251. {
  252. return fmiGetStatus_(c, s, value);
  253. }
  254. /* ------------------------------------------------------ */
  255. fmi2Status fmi2GetRealStatus(fmi2Component c, const fmi2StatusKind s, fmi2Real* value)
  256. {
  257. return fmiGetRealStatus_(c, s, value);
  258. }
  259. /* ------------------------------------------------------ */
  260. fmi2Status fmi2GetIntegerStatus(fmi2Component c, const fmi2StatusKind s, fmi2Integer* value)
  261. {
  262. return fmiGetIntegerStatus_(c, s, value);
  263. }
  264. /* ------------------------------------------------------ */
  265. fmi2Status fmi2GetBooleanStatus(fmi2Component c, const fmi2StatusKind s, fmi2Boolean* value)
  266. {
  267. return fmiGetBooleanStatus_(c, s, value);
  268. }
  269. /* ------------------------------------------------------ */
  270. fmi2Status fmi2GetStringStatus(fmi2Component c, const fmi2StatusKind s, fmi2String* value)
  271. {
  272. return fmiGetStringStatus_(c, s, value);
  273. }
  274. #endif /* FMU_SKIP_CO_SIM */
  275. #endif /* FMI_2 */