FMI_Window_sa.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /* ---------------------------------------------------------------------------*
  2. * Sample implementation of an generic master FMU -
  3. * ---------------------------------------------------------------------------*/
  4. /*
  5. Template for a FMU
  6. */
  7. #define MODEL_IDENTIFIER GM
  8. #define MODEL_GUID "{41f87101-edf2-4eef-90f3-42db56d4565f}"
  9. #define FMI2_FUNCTION_PREFIX WINDOW_SA
  10. #include <stdio.h>
  11. #include "string.h"
  12. #include "fmi2Functions.h"
  13. #include <float.h>
  14. #include "FMI_Window_sa.h"
  15. #include <math.h>
  16. #include "fmi2.h"
  17. #include "sim_support.h"
  18. #define MAX 100000
  19. #define NUMBER_OF_REALS 5
  20. #define NUMBER_OF_STRINGS 0
  21. #define NUMBER_OF_BOOLEANS 0
  22. #define NUMBER_OF_INTEGERS 0
  23. /*
  24. * The input
  25. */
  26. #define _out_tau 0
  27. #define _out_height 1
  28. #define _in_reaction_force 2
  29. #define _in_displacement 3
  30. #define _in_speed 4
  31. double relativeError(double a, double b){
  32. if(a==0){
  33. return 0;
  34. }
  35. return fabs((a - b) / a);
  36. }
  37. /*
  38. * Helper function for absolute error
  39. */
  40. double absoluteError(double a, double b){
  41. return fabs(a - b);
  42. }
  43. /*
  44. * is_close function for double comparison
  45. */
  46. int is_close(double a, double b, double REL_TOL, double ABS_TOL){
  47. return ((absoluteError(a,b)<ABS_TOL) && (relativeError(a,b)<REL_TOL));
  48. }
  49. fmi2Status fmi2SetDebugLogging(fmi2Component fc, fmi2Boolean loggingOn, size_t nCategories, const fmi2String categories[])
  50. {
  51. return fmi2OK;
  52. }
  53. fmi2Status fmi2SetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2String value[])
  54. {
  55. FMUInstance* comp = (FMUInstance *)fc;
  56. memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
  57. return fmi2Error;
  58. }
  59. fmi2Status fmi2GetString(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2String value[])
  60. {
  61. return fmi2Error;
  62. }
  63. fmi2Status fmi2SetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Real value[])
  64. {
  65. FMUInstance* comp = (FMUInstance *)fc;
  66. int i;
  67. int isset[NUMBER_OF_REALS];
  68. memset(isset, 0, sizeof(int)*NUMBER_OF_REALS);
  69. for (i = 0; i < nvr; i++)
  70. {
  71. comp->r[vr[i]] = value[i];
  72. isset[vr[i]] = 1;
  73. }
  74. /*Generated: */
  75. fmi2Boolean in_condition[_NR_OF_IN_CONDITIONS];
  76. /*Condition checking:*/
  77. // true
  78. in_condition[0] = 1;
  79. if(in_condition[0]){
  80. if(isset[_in_reaction_force]){
  81. comp->stored_windowsa_reaction_force = comp->r[_in_reaction_force];
  82. }
  83. if(isset[_in_speed]){
  84. comp->stored_windowsa_speed = comp->r[_in_speed];
  85. }
  86. if(isset[_in_displacement]){
  87. comp->stored_windowsa_displacement = comp->r[_in_displacement];
  88. }
  89. /* If mealy do update_in and recursive call */
  90. }
  91. //out_condition_executed := empty map
  92. memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
  93. return fmi2OK;
  94. }
  95. fmi2Status fmi2GetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Real value[])
  96. {
  97. FMUInstance* comp = (FMUInstance *)fc;
  98. int isEmpty = 1;
  99. for (int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
  100. if(comp->out_conditions_executed[i] !=0){
  101. isEmpty = 0;
  102. break;
  103. }
  104. }
  105. /*Eval conditions:*/
  106. if(1){
  107. comp->out_conditions_executed[0] = 1;
  108. }
  109. for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
  110. if(comp->out_conditions_executed[i]){
  111. comp->r[_out_tau] = comp->stored_window_reaction_torque;
  112. printf("setted out_tau: %f\n",comp->r[_out_tau]);
  113. comp->r[_out_height] = comp->stored_window_height;
  114. printf("setted out_height: %f\n",comp->r[_out_height]);
  115. }
  116. }
  117. for (int i = 0; i < nvr; i++)
  118. {
  119. value[i] = comp->r[(vr[i])];
  120. }
  121. return fmi2OK;
  122. }
  123. fmi2Status fmi2SetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Boolean value[])
  124. {
  125. FMUInstance* comp = (FMUInstance *)fc;
  126. int i;
  127. for (i = 0; i < nvr; i++)
  128. {
  129. comp->b[vr[i]] = value[i];
  130. }
  131. /*Generated: */
  132. fmi2Boolean in_condition[_NR_OF_IN_CONDITIONS];
  133. /*Condition checking:*/
  134. // true
  135. in_condition[0] = 1;
  136. if(in_condition[0]){
  137. /* If mealy do update_in and recursive call */
  138. }
  139. return fmi2OK;
  140. //out_condition_executed := empty map
  141. memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
  142. return fmi2OK;
  143. }
  144. fmi2Status fmi2GetBoolean(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Boolean value[])
  145. {
  146. FMUInstance* comp = (FMUInstance *)fc;
  147. int i;
  148. for (i = 0; i < nvr; i++)
  149. {
  150. value[i] = comp->b[vr[i]];
  151. }
  152. return fmi2OK;
  153. }
  154. fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2String fmuGUID, fmi2String fmuLocation, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
  155. {
  156. //Declare data structure for fmu instance
  157. FMUInstance* fi;
  158. printf("%s in fmiInstantiate\n",instanceName);
  159. //Perform checks on passed callback functions
  160. if (loggingOn) {
  161. if (!functions->logger);
  162. //return NULL;
  163. }
  164. //Check for instanceName
  165. if (!instanceName || strlen(instanceName)==0) {
  166. // print (and/or log) instanceName is missing
  167. //return NULL;
  168. }
  169. //Check passed GUID to defined model GUID
  170. if (strcmp(fmuGUID, MODEL_GUID))
  171. {
  172. // print (and/or log) GUID doesn't match
  173. //return NULL;
  174. }
  175. //Allocate fmu instance Memory
  176. // TODO check if "canNotUseMemoryManagementFunctions == true/false". If false memory allocation not possible
  177. fi = (FMUInstance *)functions->allocateMemory(1, sizeof(FMUInstance));
  178. if (fi) {
  179. // 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??
  180. fi->r = functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
  181. fi->i = functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
  182. fi->b = functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
  183. fi->s = functions->allocateMemory(NUMBER_OF_STRINGS, sizeof(fmi2String));
  184. } // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
  185. fi->instanceName = functions->allocateMemory(1 + strlen(instanceName), sizeof(char));
  186. fi->GUID = functions->allocateMemory(1 + strlen(fmuGUID), sizeof(char));
  187. strcpy((char*)fi->instanceName, instanceName);
  188. strcpy((char*)fi->GUID, fmuGUID);
  189. fi->functions = functions;
  190. fi->loggingOn = loggingOn;
  191. fi->isVisible = visible;
  192. fi->state = fmuInstantiated;
  193. /* Load the inner FMUs:*/
  194. loadDll("Window.dll", &(fi->fmu[0]), "");
  195. fi->fmuResourceLocation[0] = "Window";
  196. /*Instantiate inner components*/
  197. for (int i=0; i<1; i++){
  198. fi->c_fmu[i] = fi->fmu[i].instantiate("Window", fmi2CoSimulation, "{bead1740-5500-42db-88d5-eb3872b63305}", fi->fmuResourceLocation[i] , fi->functions, visible, 0);
  199. }
  200. return fi;
  201. }
  202. fmi2Status fmi2SetupExperiment(fmi2Component fc, fmi2Boolean toleranceDefined, fmi2Real tolerance,
  203. fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) {
  204. FMUInstance* fi = (FMUInstance*) fc;
  205. printf("%s in fmiSetupExperiment\n",fi->instanceName);
  206. if (fi->state != fmuInstantiated)
  207. {
  208. printf("fmu: %s was not instatiated before calling fmiSetupExperiment\n", fi->instanceName);
  209. return fmi2Error;
  210. }
  211. fi->currentTime = startTime;
  212. fi->stopTimeDefined = stopTimeDefined;
  213. fi->toleranceDefined = toleranceDefined;
  214. if (stopTimeDefined)
  215. {
  216. fi->stopTime = stopTime;
  217. }
  218. /*
  219. * setup inner
  220. */
  221. fmi2Status fmi2Flag = fmi2OK;
  222. fi->state = fmuExperimentSettedUp;
  223. for(int i=0; i<1; i++){
  224. fmi2Flag = fi->fmu[i].setupExperiment(fi->c_fmu[i], toleranceDefined, tolerance, startTime, fmi2True, stopTime);
  225. if (fmi2Flag == fmi2Error){
  226. fi->state = fmuError;
  227. }
  228. }
  229. fi->stored_windowsa_reaction_force=0;
  230. fi->stored_windowsa_displacement=0;
  231. fi->stored_windowsa_speed=0;
  232. fi->stored_window_reaction_torque=0;
  233. fi->stored_window_height=0;
  234. return fmi2Flag;
  235. }
  236. fmi2Status fmi2EnterInitializationMode(fmi2Component fc)
  237. {
  238. FMUInstance* fi = (FMUInstance*) fc;
  239. printf("%s in fmiEnterInitializationMode\n",fi->instanceName);
  240. if (fi->state != fmuExperimentSettedUp)
  241. {
  242. printf("fmu: %s experiment was not set-up before calling fmiEnterInitializationMode\n", fi->instanceName);
  243. return fmi2Error;
  244. }
  245. fi->state = fmuInitMode;
  246. fmi2Status fmi2Flag = fmi2OK;
  247. for(int i=0; i<1; i++){
  248. fmi2Flag = fi->fmu[i].enterInitializationMode(fi->c_fmu[i]);
  249. if (fmi2Flag == fmi2Error){
  250. return fi->state = fmuError;
  251. }
  252. }
  253. return fmi2Flag;
  254. }
  255. fmi2Status fmi2ExitInitializationMode(fmi2Component fc)
  256. {
  257. FMUInstance* fi = (FMUInstance*) fc;
  258. printf("%s in fmiExitInitializationMode\n",fi->instanceName);
  259. if (fi->state != fmuInitMode)
  260. {
  261. printf("fmu: %s did not enter Initialization Mode before calling fmiExitInitializationMode\n", fi->instanceName);
  262. return fmi2Error;
  263. }
  264. // TODO
  265. //initStatus = calculateInitialUnknownValues();
  266. //initialize();
  267. fi->state = fmuInitialized;
  268. fmi2Status fmi2Flag = fmi2OK;
  269. for(int i=0; i<1;i++){
  270. fmi2Flag = fi->fmu[i].exitInitializationMode(fi->c_fmu[i]);
  271. if (fmi2Flag == fmi2Error){
  272. return fi->state = fmuError;
  273. }
  274. }
  275. return fmi2Flag;
  276. }
  277. static fmi2Status DoInnerStep(fmi2Component fc, int index, fmi2Real currentCommPoint, fmi2Real commStepSize){
  278. fmi2Status status = fmi2OK;
  279. FMUInstance* fi = (FMUInstance *)fc;
  280. fmi2Real dt = currentCommPoint - fi->time_last_fmu[index];
  281. fmi2Real h = commStepSize + dt;
  282. if (1){
  283. fmi2ValueReference vr_toWindow[3] = {1,2,4};
  284. fmi2Real values[3];
  285. values[0] = fi->stored_windowsa_reaction_force;
  286. values[1] = fi->stored_windowsa_speed;
  287. values[2] = fi->stored_windowsa_displacement;
  288. fi->fmu[index].setReal(fi->c_fmu[index],vr_toWindow, 3, &values[0]);
  289. }
  290. status = fi->fmu[index].doStep(fi->c_fmu[index],fi->time_last_fmu[index],h,fmi2True);
  291. if(status == fmi2OK){
  292. fi->time_last_fmu[index]+= h;
  293. }
  294. if (1){
  295. fmi2ValueReference vr_fromWindow[2] = {3,6};
  296. fmi2Real out_values[2];
  297. fi->fmu[index].getReal(fi->c_fmu[index],vr_fromWindow, 3, &out_values[0]);
  298. fi->stored_window_reaction_torque = out_values[0];
  299. fi->stored_window_height = out_values[1];
  300. }
  301. return status;
  302. }
  303. fmi2Status fmi2DoStep(fmi2Component fc , fmi2Real currentCommPoint, fmi2Real commStepSize, fmi2Boolean noPrevFMUState)
  304. {
  305. FMUInstance* fi = (FMUInstance *)fc;
  306. fmi2Status simStatus = fmi2OK;
  307. printf("%s in fmiDoStep(), ct:%f, h:%f\n",fi->instanceName,currentCommPoint,commStepSize);
  308. memset(fi->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
  309. /*
  310. Calculate the elapsed time since the last transition
  311. */
  312. fmi2Real e = MAX;
  313. fmi2Real elapsed_fmu[_NR_OF_FMUS];
  314. for (int i=0; i<_NR_OF_FMUS; i++){
  315. elapsed_fmu[i] = currentCommPoint - fi->time_last_fmu[i];
  316. e = (elapsed_fmu[i]<e)? elapsed_fmu[i]:e;
  317. }
  318. if(1){
  319. simStatus= DoInnerStep(fc,0,currentCommPoint,commStepSize);
  320. }
  321. memset(fi->in_condition_executed, 0, sizeof(fmi2Boolean)*_NR_OF_IN_CONDITIONS);
  322. return simStatus;
  323. }
  324. fmi2Status fmi2Terminate(fmi2Component fc)
  325. {
  326. FMUInstance* fi = (FMUInstance *)fc;
  327. printf("%s in fmiTerminate\n",fi->instanceName);
  328. // do check if fi may be terminated
  329. for (int i=0;i<1;i++){
  330. fi->fmu[i].terminate(fi->c_fmu[i]);
  331. }
  332. fi->state = fmuTerminated;
  333. return fmi2OK;
  334. }
  335. void fmi2FreeInstance(fmi2Component fc)
  336. {
  337. FMUInstance* fi = (FMUInstance*) fc;
  338. printf("%s in fmiFreeInstance\n",fi->instanceName);
  339. for(int i=0;i<_NR_OF_FMUS;i++){
  340. fi->fmu[i].freeInstance(fi->c_fmu[i]);
  341. }
  342. if (fi) {
  343. fi->functions->freeMemory(fi->r);
  344. fi->functions->freeMemory(fi->i);
  345. fi->functions->freeMemory(fi->b);
  346. fi->functions->freeMemory(fi->s);// TODO has to be done with loop
  347. fi->functions->freeMemory((void*)fi->instanceName);
  348. fi->functions->freeMemory((void*)fi->GUID);
  349. fi->functions->freeMemory((void*)fi);
  350. }
  351. }
  352. //To be implemented
  353. const char* fmi2GetVersion() {
  354. printf("Function fmiGetVersion not supported\n");
  355. return NULL;
  356. }
  357. const char* fmi2GetTypesPlatform() {
  358. printf("Function fmiGetTypesPlatform not supported\n");
  359. return NULL;
  360. }
  361. fmi2Status fmi2Reset(fmi2Component fc)
  362. {
  363. printf("Function fmiReset not supported\n");
  364. return fmi2Error;
  365. }
  366. fmi2Status fmi2SetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, const fmi2Integer value[])
  367. {
  368. FMUInstance * comp = (FMUInstance*) fc;
  369. printf("Function fmiSetInteger not supported\n");
  370. memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);
  371. return fmi2Error;
  372. }
  373. fmi2Status fmi2GetInteger(fmi2Component fc, const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[])
  374. {
  375. printf("Function fmiGetInteger not supported\n");
  376. return fmi2Error;
  377. }
  378. /*******OWN IMPLEMENTATION OF Get/Set FMU state*******/
  379. fmi2Status fmi2GetFMUstate (fmi2Component c, fmi2FMUstate* FMUstate) {
  380. FMUInstance* orig = (FMUInstance*)c;
  381. FMUInstance* fi = (FMUInstance *)FMUstate;
  382. *FMUstate = fi;
  383. fi = orig->functions->allocateMemory(1, sizeof(FMUInstance));
  384. *FMUstate = fi;
  385. fi->functions = orig->functions;
  386. if (fi) {
  387. // 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??
  388. fi->r = fi->functions->allocateMemory(NUMBER_OF_REALS, sizeof(fmi2Real));
  389. fi->i = fi->functions->allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmi2Integer));
  390. fi->b = fi->functions->allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmi2Boolean));
  391. fi->s = fi->functions->allocateMemory(NUMBER_OF_STRINGS, sizeof(fmi2String));
  392. } // variables in predefined arrays (performance issue) --> makes multiple instances of fmu impossible
  393. fi->instanceName = orig->functions->allocateMemory(1 + strlen(orig->instanceName), sizeof(char));
  394. fi->GUID = orig->functions->allocateMemory(1 + strlen(orig->GUID), sizeof(char));
  395. strcpy((char *)fi->instanceName, (char *)orig->instanceName);
  396. strcpy((char *)fi->GUID, (char *)orig->GUID);
  397. fi->functions = orig->functions;
  398. fi->loggingOn = orig->loggingOn;
  399. fi->isVisible = orig->isVisible;
  400. fi->state = orig->state;
  401. fi->startTime = orig->startTime;
  402. fi->stopTime = orig->stopTime;
  403. fi->currentTime = orig->currentTime;
  404. /* TODO: Store all the rest here.*/
  405. fi->fmu[0] = orig->fmu[0];
  406. fi->c_fmu[0] = orig->c_fmu[0];
  407. for(int i=0; i<_NR_OF_IN_CONDITIONS;i++){
  408. fi->in_condition_executed[i] = orig->in_condition_executed[i];
  409. }
  410. for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
  411. fi->out_conditions_executed[i] = orig->out_conditions_executed[i];
  412. }
  413. for(int i=0;i<_NR_OF_FMUS;i++){
  414. fi->time_last_fmu[i] = orig->time_last_fmu[i];
  415. }
  416. /* Generated */
  417. fi->stored_windowsa_reaction_force=orig->stored_windowsa_reaction_force;
  418. fi->stored_windowsa_displacement=orig->stored_windowsa_displacement;
  419. fi->stored_windowsa_speed=orig->stored_windowsa_speed;
  420. fi->stored_window_reaction_torque=orig->stored_window_reaction_torque;
  421. fi->stored_window_height=orig->stored_window_height;
  422. fi->toleranceDefined = orig->toleranceDefined;
  423. /*
  424. * This is a hierarchical call. First let the lower FMUs do their state saving
  425. * We will store the saved fmu state in the fi->c_order[i]
  426. */
  427. for(int i=0;i<_NR_OF_FMUS;i++){
  428. fi->fmu[i]=orig->fmu[i];
  429. orig->fmu[i].getFMUstate(orig->c_fmu[i],fi->c_fmu[i]);
  430. fi->fmuResourceLocation[i] = fi->functions->allocateMemory(1+strlen(orig->fmuResourceLocation[i]), sizeof(char));
  431. strcpy((char *)fi->fmuResourceLocation[i],(char *)orig->fmuResourceLocation[i]);
  432. /*make shallow copies of the stored fmus*/
  433. }
  434. //copy r
  435. int i=0;
  436. for (i=0; i< NUMBER_OF_REALS;i++){
  437. //printf("Setting real: %i %f\n", i, orig->r[i]);
  438. fi->r[i] = orig->r[i];
  439. //printf("Setted real: %i %f\n", i, fi->r[i]);
  440. }
  441. //copy s
  442. for (i=0; i< NUMBER_OF_STRINGS;i++){
  443. //fi->s[i] = orig->s[i]; // why are this not deep copies?
  444. fi->s[i] = fi->functions->allocateMemory(1+strlen(orig->s[i]),sizeof(char));
  445. strcpy((char *)fi->s[i],(char *)orig->s[i]);
  446. }
  447. //copy i
  448. for (i=0; i< NUMBER_OF_INTEGERS;i++){
  449. fi->i[i] = orig->i[i];
  450. }
  451. //copy b
  452. for (i=0; i< NUMBER_OF_BOOLEANS;i++){
  453. fi->b[i] = orig->b[i];
  454. }
  455. return fmi2OK;
  456. }
  457. fmi2Status fmi2SetFMUstate (fmi2Component c, fmi2FMUstate FMUstate) {
  458. FMUInstance* orig = (FMUInstance*)FMUstate;
  459. FMUInstance* fi = (FMUInstance*)c;
  460. /*
  461. * First restore the hierarchical fmus.
  462. */
  463. for(int i=0;i<_NR_OF_FMUS;i++){
  464. fi->fmu[i].setFMUstate(fi->c_fmu[i],orig->c_fmu[i]);
  465. fi->fmuResourceLocation[i] = orig->functions->allocateMemory(1+strlen(orig->fmuResourceLocation[i]), sizeof(char));
  466. strcpy((char *)fi->fmuResourceLocation[i],(char *)orig->fmuResourceLocation[i]);
  467. }
  468. //set time etc correct, name and GUID should still be ok ;-)
  469. printf("setting time values from %f to %f\n", fi->currentTime, orig->currentTime);
  470. fi->state = orig->state;
  471. fi->startTime = orig->startTime;
  472. fi->stopTime = orig->stopTime;
  473. fi->currentTime = orig->currentTime;
  474. fi->fmu[0] = orig->fmu[0];
  475. fi->c_fmu[0] = orig->c_fmu[0];
  476. for(int i=0; i<_NR_OF_IN_CONDITIONS;i++){
  477. fi->in_condition_executed[i] = orig->in_condition_executed[i];
  478. }
  479. for(int i=0; i<_NR_OF_OUT_CONDITIONS;i++){
  480. fi->out_conditions_executed[i] = orig->out_conditions_executed[i];
  481. }
  482. for(int i=0;i<_NR_OF_FMUS;i++){
  483. fi->time_last_fmu[i] = orig->time_last_fmu[i];
  484. }
  485. /* Generated */
  486. fi->stored_windowsa_reaction_force=orig->stored_windowsa_reaction_force;
  487. fi->stored_windowsa_displacement=orig->stored_windowsa_displacement;
  488. fi->stored_windowsa_speed=orig->stored_windowsa_speed;
  489. fi->stored_window_reaction_torque=orig->stored_window_reaction_torque;
  490. fi->stored_window_height=orig->stored_window_height;
  491. fi->toleranceDefined = orig->toleranceDefined;
  492. fi->toleranceDefined = orig->toleranceDefined;
  493. printf("setting real values\n");
  494. //copy r
  495. int i=0;
  496. for (i=0; i< NUMBER_OF_REALS;i++){
  497. fi->r[i] = orig->r[i];
  498. }
  499. printf("setting string values\n");
  500. //copy s
  501. for (i=0; i< NUMBER_OF_STRINGS;i++){
  502. fi->s[i] = orig->s[i];
  503. }
  504. //copy i
  505. for (i=0; i< NUMBER_OF_INTEGERS;i++){
  506. fi->i[i] = orig->i[i];
  507. }
  508. //copy b
  509. for (i=0; i< NUMBER_OF_BOOLEANS;i++){
  510. fi->b[i] = orig->b[i];
  511. }
  512. return fmi2OK;
  513. }
  514. /****************************************************/
  515. fmi2Status fmi2FreeFMUstate(fmi2Component c, fmi2FMUstate* FMUstate) {
  516. printf("Function fmiFreeFMUstate not supported\n");
  517. return fmi2Error;
  518. }
  519. fmi2Status fmi2SerializedFMUstateSize(fmi2Component c, fmi2FMUstate FMUstate, size_t *size) {
  520. printf("Function fmiSerializedFMUstateSize not supported\n");
  521. return fmi2Error;
  522. }
  523. fmi2Status fmi2SerializeFMUstate (fmi2Component c, fmi2FMUstate FMUstate, fmi2Byte serializedState[], size_t size) {
  524. printf("Function fmiSerializeFMUstate not supported\n");
  525. return fmi2Error;
  526. }
  527. fmi2Status fmi2DeSerializeFMUstate (fmi2Component c, const fmi2Byte serializedState[], size_t size, fmi2FMUstate* FMUstate) {
  528. printf("Function fmiDeSerializeFMUstate not supported\n");
  529. return fmi2Error;
  530. }
  531. fmi2Status fmi2GetDirectionalDerivative(fmi2Component c, const fmi2ValueReference vUnknown_ref[], size_t nUnknown,
  532. const fmi2ValueReference vKnown_ref[] , size_t nKnown, const fmi2Real dvKnown[], fmi2Real dvUnknown[]) {
  533. printf("Function fmiGetDirectionalDerivative not supported\n");
  534. return fmi2Error;
  535. }
  536. fmi2Status fmi2SetRealInputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
  537. const fmi2Integer order[], const fmi2Real value[]) {
  538. printf("Function fmiGetDirectionalDerivative not supported\n");
  539. return fmi2Error;
  540. }
  541. fmi2Status fmi2GetRealOutputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
  542. const fmi2Integer order[], fmi2Real value[]) {
  543. printf("Function fmiGetDirectionalDerivative not supported\n");
  544. return fmi2Error;
  545. }
  546. fmi2Status fmi2CancelStep(fmi2Component c) {
  547. printf("Function fmiGetDirectionalDerivative not supported\n");
  548. return fmi2Error;
  549. }
  550. fmi2Status fmi2GetStatus(fmi2Component c, const fmi2StatusKind s, fmi2Status *value) {
  551. printf("Function fmiGetStatus not supported\n");
  552. return fmi2Error;
  553. }
  554. fmi2Status fmi2GetRealStatus(fmi2Component c, const fmi2StatusKind s, fmi2Real *value) {
  555. if(s == fmi2LastSuccessfulTime){
  556. FMUInstance* comp = (FMUInstance*) c;
  557. *value = comp->currentTime;
  558. return fmi2OK;
  559. }
  560. printf("Function fmiGetRealStatus not supported\n");
  561. return fmi2Error;
  562. }
  563. fmi2Status fmi2GetIntegerStatus(fmi2Component c, const fmi2StatusKind s, fmi2Integer *value) {
  564. printf("Function fmiGetIntegerStatus not supported\n");
  565. return fmi2Error;
  566. }
  567. fmi2Status fmi2GetBooleanStatus(fmi2Component c, const fmi2StatusKind s, fmi2Boolean *value) {
  568. printf("Function fmiGetBooleanStatus not supported\n");
  569. return fmi2Error;
  570. }
  571. fmi2Status fmi2GetStringStatus(fmi2Component c, const fmi2StatusKind s, fmi2String *value) {
  572. printf("Function fmiGetStringStatus not supported\n");
  573. return fmi2Error;
  574. }