fmiFunctions.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. #ifndef BUILDFMU
  2. /* needed for source code export */
  3. #include "conf.h"
  4. #endif
  5. #include "fmiFunctions_.h"
  6. #include "fmiFunctions_fwd.h"
  7. /* This file contains wrappers for all FMI functions and is provided in
  8. the Dymola distribution instead of the actual implementation. This is
  9. necessary to avoid exposing the latter. */
  10. DYMOLA_STATIC void __enableResultStoring(fmiComponent c);
  11. /***************************************************
  12. Common Functions
  13. ****************************************************/
  14. /* For 2.0 this is common, for 1.0 it belongs to Co-sim interface only */
  15. #ifdef FMI_2
  16. const char* fmiGetTypesPlatform()
  17. {
  18. return fmiGetTypesPlatform_();
  19. }
  20. #endif
  21. /* ------------------------------------------------------ */
  22. const char* fmiGetVersion()
  23. {
  24. return fmiGetVersion_();
  25. }
  26. /* ------------------------------------------------------ */
  27. fmiStatus fmiSetDebugLogging(fmiComponent c, fmiBoolean loggingOn
  28. #ifdef FMI_2
  29. , size_t nCategories, const fmiString categories[]
  30. #endif
  31. )
  32. {
  33. return fmiSetDebugLogging_(c, loggingOn
  34. #ifdef FMI_2
  35. , nCategories, categories
  36. #endif
  37. );
  38. }
  39. /* ------------------------------------------------------ */
  40. fmiStatus fmiGetReal(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiReal value[])
  41. {
  42. return fmiGetReal_(c, vr, nvr, value);
  43. }
  44. /* ------------------------------------------------------ */
  45. fmiStatus fmiGetInteger(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiInteger value[])
  46. {
  47. return fmiGetInteger_(c, vr, nvr, value);
  48. }
  49. /* ------------------------------------------------------ */
  50. fmiStatus fmiGetBoolean(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiBoolean value[])
  51. {
  52. return fmiGetBoolean_(c, vr, nvr, value);
  53. }
  54. /* ------------------------------------------------------ */
  55. fmiStatus fmiGetString(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiString value[])
  56. {
  57. return fmiGetString_(c, vr, nvr, value);
  58. }
  59. /* ------------------------------------------------------ */
  60. fmiStatus fmiSetReal(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiReal value[])
  61. {
  62. return fmiSetReal_(c, vr, nvr, value);
  63. }
  64. /* ------------------------------------------------------ */
  65. fmiStatus fmiSetInteger(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiInteger value[])
  66. {
  67. return fmiSetInteger_(c, vr, nvr, value);
  68. }
  69. /* ------------------------------------------------------ */
  70. fmiStatus fmiSetBoolean(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiBoolean value[])
  71. {
  72. return fmiSetBoolean_(c, vr, nvr, value);
  73. }
  74. /* ------------------------------------------------------ */
  75. fmiStatus fmiSetString(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiString value[])
  76. {
  77. return fmiSetString_(c, vr, nvr, value);
  78. }
  79. #ifdef FMI_2
  80. /* ------------------------------------------------------ */
  81. fmiStatus fmiGetFMUstate(fmiComponent c, fmiFMUstate* FMUstate)
  82. {
  83. return fmiGetFMUstate_(c, FMUstate);
  84. }
  85. /* ------------------------------------------------------ */
  86. fmiStatus fmiSetFMUstate(fmiComponent c, fmiFMUstate FMUstate)
  87. {
  88. return fmiSetFMUstate_(c, FMUstate);
  89. }
  90. /* ------------------------------------------------------ */
  91. fmiStatus fmiFreeFMUstate(fmiComponent c, fmiFMUstate* FMUstate)
  92. {
  93. return fmiFreeFMUstate_(c, FMUstate);
  94. }
  95. /* ------------------------------------------------------ */
  96. fmiStatus fmiSerializedFMUstateSize(fmiComponent c, fmiFMUstate FMUstate, size_t *size)
  97. {
  98. return fmiSerializedFMUstateSize_(c, FMUstate, size);
  99. }
  100. /* ------------------------------------------------------ */
  101. fmiStatus fmiSerializeFMUstate(fmiComponent c, fmiFMUstate FMUstate, fmiByte serializedState[], size_t size)
  102. {
  103. return fmiSerializeFMUstate_(c, FMUstate, serializedState, size);
  104. }
  105. /* ------------------------------------------------------ */
  106. fmiStatus fmiDeSerializeFMUstate(fmiComponent c, const fmiByte serializedState[], size_t size, fmiFMUstate* FMUstate)
  107. {
  108. return fmiDeSerializeFMUstate_(c, serializedState, size, FMUstate);
  109. }
  110. /* ------------------------------------------------------ */
  111. fmiStatus fmiGetDirectionalDerivative(fmiComponent c,
  112. const fmiValueReference v_ref[],
  113. size_t nv,
  114. const fmiValueReference z_ref[],
  115. size_t nz,
  116. const fmiReal dv[],
  117. fmiReal dz[])
  118. {
  119. return fmiGetDirectionalDerivative_(c, v_ref, nv, z_ref, nz, dv, dz);
  120. }
  121. fmiComponent fmiInstantiate(fmiString instanceName, fmiType fmuType, fmiString fmuGUID, fmiString fmuResourceLocation, const fmiCallbackFunctions* functions, fmiBoolean visible, fmiBoolean loggingOn)
  122. {
  123. fmiComponent comp = fmiInstantiate_(instanceName, fmuType, fmuGUID, fmuResourceLocation, functions, visible, loggingOn);
  124. #ifndef FMU_SOURCE_CODE_EXPORT
  125. if (comp != NULL) {
  126. /* determine whether to store results or not */
  127. #include "dsmodel_fmuconf.h"
  128. }
  129. #endif /* FMU_SOURCE_CODE_EXPORT */
  130. return comp;
  131. }
  132. void fmiFreeInstance(fmiComponent c)
  133. {
  134. fmiFreeInstance_(c);
  135. }
  136. fmiStatus fmiSetupExperiment(fmiComponent c,
  137. fmiBoolean relativeToleranceDefined,
  138. fmiReal relativeTolerance,
  139. fmiReal tStart,
  140. fmiBoolean tStopDefined,
  141. fmiReal tStop)
  142. {
  143. return fmiSetupExperiment_(c, relativeToleranceDefined, relativeTolerance, tStart, tStopDefined, tStop);
  144. }
  145. fmiStatus fmiEnterInitializationMode(fmiComponent c)
  146. {
  147. return fmiEnterInitializationMode_(c);
  148. }
  149. fmiStatus fmiExitInitializationMode(fmiComponent c)
  150. {
  151. return fmiExitInitializationMode_(c);
  152. }
  153. fmiStatus fmiTerminate(fmiComponent c)
  154. {
  155. return fmiTerminate_(c);
  156. }
  157. fmiStatus fmiReset(fmiComponent c)
  158. {
  159. return fmiReset_(c);
  160. }
  161. #endif /* FMI_2 */
  162. /***************************************************
  163. Functions for FMI for Model Exchange
  164. ****************************************************/
  165. #ifndef FMU_SKIP_MODEL_EXCHANGE
  166. /* For 2.0 this is replaced by a common function fmiGetTypesPlatform. */
  167. #ifndef FMI_2
  168. const char* fmiGetModelTypesPlatform()
  169. {
  170. return fmiGetModelTypesPlatform_();
  171. }
  172. #endif
  173. #ifndef FMI_2
  174. fmiComponent fmiInstantiateModel(fmiString instanceName,
  175. fmiString GUID,
  176. fmiMECallbackFunctions functions,
  177. fmiBoolean loggingOn)
  178. {
  179. fmiComponent comp = fmiInstantiateModel_(instanceName, GUID, functions, loggingOn);
  180. #ifndef FMU_SOURCE_CODE_EXPORT
  181. if (comp != NULL) {
  182. /* determine whether to store results or not */
  183. #include "dsmodel_fmuconf.h"
  184. }
  185. #endif /* FMU_SOURCE_CODE_EXPORT */
  186. return comp;
  187. }
  188. #endif
  189. #ifndef FMI_2
  190. /* ------------------------------------------------------ */
  191. void fmiFreeModelInstance(fmiComponent c)
  192. {
  193. fmiFreeModelInstance_(c);
  194. }
  195. #endif
  196. /* ------------------------------------------------------ */
  197. fmiStatus fmiSetTime(fmiComponent c, fmiReal time)
  198. {
  199. return fmiSetTime_(c, time);
  200. }
  201. /* ------------------------------------------------------ */
  202. fmiStatus fmiSetContinuousStates(fmiComponent c, const fmiReal x[], size_t nx)
  203. {
  204. return fmiSetContinuousStates_(c, x, nx);
  205. }
  206. /* ------------------------------------------------------ */
  207. #ifdef FMI_2
  208. /* ------------------------------------------------------ */
  209. fmiStatus fmiEnterEventMode(fmiComponent c)
  210. {
  211. return fmiEnterEventMode_(c);
  212. }
  213. /* ------------------------------------------------------ */
  214. fmiStatus fmiNewDiscreteStates(fmiComponent c, fmiEventInfo* eventInfo)
  215. {
  216. return fmiNewDiscreteStates_(c, eventInfo);
  217. }
  218. /* ------------------------------------------------------ */
  219. fmiStatus fmiEnterContinuousTimeMode(fmiComponent c)
  220. {
  221. return fmiEnterContinuousTimeMode_(c);
  222. }
  223. /* ------------------------------------------------------ */
  224. fmiStatus fmiGetNominalsOfContinuousStates(fmiComponent c, fmiReal x_nominal[], size_t nx)
  225. {
  226. return fmiGetNominalsOfContinuousStates_(c, x_nominal, nx);
  227. }
  228. #else /* FMI_2 */
  229. /* ------------------------------------------------------ */
  230. fmiStatus fmiInitialize(fmiComponent c,
  231. fmiBoolean toleranceControlled,
  232. fmiReal relativeTolerance,
  233. fmiEventInfo* eventInfo)
  234. {
  235. return fmiInitialize_(c, toleranceControlled, relativeTolerance, eventInfo);
  236. }
  237. /* ------------------------------------------------------ */
  238. fmiStatus fmiEventUpdate(fmiComponent c, fmiBoolean intermediateResults, fmiEventInfo* eventInfo)
  239. {
  240. return fmiEventUpdate_(c, intermediateResults, eventInfo);
  241. }
  242. /* ------------------------------------------------------ */
  243. fmiStatus fmiTerminate(fmiComponent c)
  244. {
  245. return fmiTerminate_(c);
  246. }
  247. /* ------------------------------------------------------ */
  248. fmiStatus fmiGetStateValueReferences(fmiComponent c, fmiValueReference vrx[], size_t nx)
  249. {
  250. return fmiGetStateValueReferences_(c, vrx, nx);
  251. }
  252. /* ------------------------------------------------------ */
  253. fmiStatus fmiGetNominalContinuousStates(fmiComponent c, fmiReal x_nominal[], size_t nx)
  254. {
  255. return fmiGetNominalContinuousStates_(c, x_nominal, nx);
  256. }
  257. #endif /* FMI_2 */
  258. /* ------------------------------------------------------ */
  259. #ifdef FMI_2
  260. fmiStatus fmiCompletedIntegratorStep(fmiComponent c,
  261. fmiBoolean noSetFMUStatePriorToCurrentPoint,
  262. fmiBoolean* enterEventMode,
  263. fmiBoolean* terminateSimulation)
  264. {
  265. return fmiCompletedIntegratorStep_(c, noSetFMUStatePriorToCurrentPoint, enterEventMode, terminateSimulation);
  266. }
  267. #else /* FMI_2 */
  268. fmiStatus fmiCompletedIntegratorStep(fmiComponent c, fmiBoolean* callEventUpdate)
  269. {
  270. return fmiCompletedIntegratorStep_(c, callEventUpdate);
  271. }
  272. #endif /* FMI_2 */
  273. /* ------------------------------------------------------ */
  274. fmiStatus fmiGetDerivatives(fmiComponent c, fmiReal derivatives[], size_t nx)
  275. {
  276. return fmiGetDerivatives_(c, derivatives, nx);
  277. }
  278. /* ------------------------------------------------------ */
  279. fmiStatus fmiGetEventIndicators(fmiComponent c, fmiReal eventIndicators[], size_t ni)
  280. {
  281. return fmiGetEventIndicators_(c, eventIndicators, ni);
  282. }
  283. /* ------------------------------------------------------ */
  284. fmiStatus fmiGetContinuousStates(fmiComponent c, fmiReal states[], size_t nx)
  285. {
  286. return fmiGetContinuousStates_(c, states, nx);
  287. }
  288. #endif /* FMU_SKIP_MODEL_EXCHANGE */
  289. /***************************************************
  290. Functions for FMI for Co-Simulation
  291. ****************************************************/
  292. #ifndef FMU_SKIP_CO_SIM
  293. /* For 2.0 this is common, for 1.0 it belongs to Co-sim interface only */
  294. #ifndef FMI_2
  295. const char* fmiGetTypesPlatform()
  296. {
  297. return fmiGetTypesPlatform_();
  298. }
  299. #endif
  300. #ifndef FMI_2
  301. fmiComponent fmiInstantiateSlave(fmiString instanceName,
  302. fmiString fmuGUID,
  303. fmiString fmuLocation,
  304. fmiString mimeType,
  305. fmiReal timeout,
  306. fmiBoolean visible,
  307. fmiBoolean interactive,
  308. fmiCallbackFunctions functions,
  309. fmiBoolean loggingOn)
  310. {
  311. fmiComponent c = fmiInstantiateSlave_(instanceName,
  312. fmuGUID,
  313. fmuLocation,
  314. mimeType,
  315. timeout,
  316. visible,
  317. interactive,
  318. functions,
  319. loggingOn);
  320. #ifdef GenerateResultInNonDymosim
  321. __enableResultStoring(c);
  322. #endif
  323. return c;
  324. }
  325. #endif /* FMI_2 */
  326. #ifndef FMI_2
  327. /* ------------------------------------------------------ */
  328. void fmiFreeSlaveInstance(fmiComponent c)
  329. {
  330. fmiFreeSlaveInstance_(c);
  331. }
  332. #endif
  333. /* ------------------------------------------------------ */
  334. #ifndef FMI_2
  335. fmiStatus fmiInitializeSlave(fmiComponent c,
  336. fmiReal tStart,
  337. fmiBoolean StopTimeDefined,
  338. fmiReal tStop)
  339. {
  340. return fmiInitializeSlave_(c, tStart, StopTimeDefined, tStop);
  341. }
  342. /* ------------------------------------------------------ */
  343. fmiStatus fmiTerminateSlave(fmiComponent c)
  344. {
  345. return fmiTerminateSlave_(c);
  346. }
  347. /* ------------------------------------------------------ */
  348. fmiStatus fmiResetSlave(fmiComponent c)
  349. {
  350. return fmiResetSlave_(c);
  351. }
  352. #endif
  353. /* ------------------------------------------------------ */
  354. fmiStatus fmiSetRealInputDerivatives(fmiComponent c,
  355. const fmiValueReference vr[],
  356. size_t nvr,
  357. const fmiInteger order[],
  358. const fmiReal value[])
  359. {
  360. return fmiSetRealInputDerivatives_(c, vr, nvr, order, value);
  361. }
  362. /* ------------------------------------------------------ */
  363. fmiStatus fmiGetRealOutputDerivatives(fmiComponent c,
  364. const fmiValueReference vr[],
  365. size_t nvr,
  366. const fmiInteger order[],
  367. fmiReal value[])
  368. {
  369. return fmiGetRealOutputDerivatives_(c, vr, nvr, order, value);
  370. }
  371. /* ------------------------------------------------------ */
  372. fmiStatus fmiDoStep(fmiComponent c,
  373. fmiReal currentCommunicationPoint,
  374. fmiReal communicationStepSize,
  375. /* For 1.0: newStep,
  376. For 2.0: noSetFMUStatePriorToCurrentPoint */ fmiBoolean genericBool)
  377. {
  378. return fmiDoStep_(c, currentCommunicationPoint, communicationStepSize, genericBool);
  379. }
  380. /* ------------------------------------------------------ */
  381. fmiStatus fmiCancelStep(fmiComponent c)
  382. {
  383. return fmiCancelStep_(c);
  384. }
  385. /* ------------------------------------------------------ */
  386. fmiStatus fmiGetStatus(fmiComponent c, const fmiStatusKind s, fmiStatus* value)
  387. {
  388. return fmiGetStatus_(c, s, value);
  389. }
  390. /* ------------------------------------------------------ */
  391. fmiStatus fmiGetRealStatus(fmiComponent c, const fmiStatusKind s, fmiReal* value)
  392. {
  393. return fmiGetRealStatus_(c, s, value);
  394. }
  395. /* ------------------------------------------------------ */
  396. fmiStatus fmiGetIntegerStatus(fmiComponent c, const fmiStatusKind s, fmiInteger* value)
  397. {
  398. return fmiGetIntegerStatus_(c, s, value);
  399. }
  400. /* ------------------------------------------------------ */
  401. fmiStatus fmiGetBooleanStatus(fmiComponent c, const fmiStatusKind s, fmiBoolean* value)
  402. {
  403. return fmiGetBooleanStatus_(c, s, value);
  404. }
  405. /* ------------------------------------------------------ */
  406. fmiStatus fmiGetStringStatus(fmiComponent c, const fmiStatusKind s, fmiString* value)
  407. {
  408. return fmiGetStringStatus_(c, s, value);
  409. }
  410. #endif /* FMU_SKIP_CO_SIM */