@@ -355,7 +355,8 @@ fmi2Status fmi2SetDebugLogging(fmi2Component c, fmi2Boolean loggingOn, size_t nC
355355}
356356
357357fmi2Component fmi2Instantiate (fmi2String instanceName , fmi2Type fmuType , fmi2String fmuGUID , fmi2String fmuResourceLocation , const fmi2CallbackFunctions * functions ,
358- fmi2Boolean visible , fmi2Boolean loggingOn ) {
358+ fmi2Boolean visible , fmi2Boolean loggingOn )
359+ {
359360 /*
360361 TODO: We should set the interface, but we can't until it's no longer a global variable.
361362 * The problem is that we might overwrite the main simulation's copy of the interface...
@@ -492,6 +493,8 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
492493 }
493494 }
494495
496+ comp -> _need_update = 1 ;
497+
495498 FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2Instantiate: GUID=%s" , fmuGUID )
496499 resetThreadData (comp );
497500 return comp ;
@@ -591,47 +594,51 @@ fmi2Status fmi2ExitInitializationMode(fmi2Component c)
591594 FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2ExitInitializationMode..." )
592595
593596 setThreadData (comp );
594- comp -> fmuData -> callback -> updateBoundParameters (comp -> fmuData , comp -> threadData );
595- comp -> fmuData -> callback -> updateBoundVariableAttributes (comp -> fmuData , comp -> threadData );
596597
597598 /* try */
598599 MMC_TRY_INTERNAL (simulationJumpBuffer )
599600 threadData -> mmc_jumper = threadData -> simulationJumpBuffer ;
600601
601- if (initialization ( comp -> fmuData , comp -> threadData , "fmi" , "" , 0.0 ) )
602+ if (comp -> _need_update )
602603 {
603- comp -> state = modelError ;
604- FILTERED_LOG (comp , fmi2Error , LOG_FMI2_CALL , "fmi2EnterInitializationMode: failed" )
604+ comp -> fmuData -> callback -> updateBoundParameters (comp -> fmuData , comp -> threadData );
605+ comp -> fmuData -> callback -> updateBoundVariableAttributes (comp -> fmuData , comp -> threadData );
606+ if (initialization (comp -> fmuData , comp -> threadData , "fmi" , "" , 0.0 ))
607+ {
608+ comp -> state = modelError ;
609+ resetThreadData (comp );
610+ FILTERED_LOG (comp , fmi2Error , LOG_FMI2_CALL , "fmi2EnterInitializationMode: failed" )
611+ return fmi2Error ;
612+ }
605613 }
606- else
607- {
608- /* TODO: Simulation stop time is needed to calculate the sample events beforehand. */
609- initSample (comp -> fmuData , comp -> threadData , comp -> fmuData -> localData [0 ]-> timeValue , 100 /*should be stopTime*/ );
614+
615+ /* TODO: Simulation stop time is needed to calculate the sample events beforehand. */
616+ initSample (comp -> fmuData , comp -> threadData , comp -> fmuData -> localData [0 ]-> timeValue , 100 /*should be stopTime*/ );
610617#if !defined(OMC_NDELAY_EXPRESSIONS ) || OMC_NDELAY_EXPRESSIONS > 0
611- initDelay (comp -> fmuData , comp -> fmuData -> localData [0 ]-> timeValue );
618+ initDelay (comp -> fmuData , comp -> fmuData -> localData [0 ]-> timeValue );
612619#endif
613- /* overwrite old values due to an event */
614- overwriteOldSimulationData (comp -> fmuData );
620+ /* overwrite old values due to an event */
621+ overwriteOldSimulationData (comp -> fmuData );
615622
616- comp -> eventInfo .terminateSimulation = fmi2False ;
617- comp -> eventInfo .valuesOfContinuousStatesChanged = fmi2True ;
623+ comp -> eventInfo .terminateSimulation = fmi2False ;
624+ comp -> eventInfo .valuesOfContinuousStatesChanged = fmi2True ;
618625
619- /* get next event time (sample calls) */
620- nextSampleEvent = 0 ;
621- nextSampleEvent = getNextSampleTimeFMU (comp -> fmuData );
622- if (nextSampleEvent == -1 )
623- {
624- comp -> eventInfo .nextEventTimeDefined = fmi2False ;
625- }
626- else
627- {
628- comp -> eventInfo .nextEventTimeDefined = fmi2True ;
629- comp -> eventInfo .nextEventTime = nextSampleEvent ;
630- fmi2EventUpdate (comp , & (comp -> eventInfo ));
631- }
632- FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2EnterInitializationMode: succeed" )
633- res = fmi2OK ;
626+ /* get next event time (sample calls) */
627+ nextSampleEvent = 0 ;
628+ nextSampleEvent = getNextSampleTimeFMU (comp -> fmuData );
629+ if (nextSampleEvent == -1 )
630+ {
631+ comp -> eventInfo .nextEventTimeDefined = fmi2False ;
634632 }
633+ else
634+ {
635+ comp -> eventInfo .nextEventTimeDefined = fmi2True ;
636+ comp -> eventInfo .nextEventTime = nextSampleEvent ;
637+ fmi2EventUpdate (comp , & (comp -> eventInfo ));
638+ }
639+ FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2EnterInitializationMode: succeed" )
640+ res = fmi2OK ;
641+
635642 done = 1 ;
636643 /* catch */
637644 MMC_CATCH_INTERNAL (simulationJumpBuffer )
@@ -713,12 +720,21 @@ fmi2Status fmi2GetReal(fmi2Component c, const fmi2ValueReference vr[], size_t nv
713720#if NUMBER_OF_REALS > 0
714721 if (comp -> _need_update )
715722 {
716- comp -> fmuData -> callback -> functionODE (comp -> fmuData , comp -> threadData );
717- overwriteOldSimulationData (comp -> fmuData );
718- comp -> fmuData -> callback -> functionAlgebraics (comp -> fmuData , comp -> threadData );
719- comp -> fmuData -> callback -> output_function (comp -> fmuData , comp -> threadData );
720- comp -> fmuData -> callback -> function_storeDelayed (comp -> fmuData , comp -> threadData );
721- storePreValues (comp -> fmuData );
723+ if (modelInitializationMode == comp -> state )
724+ {
725+ comp -> fmuData -> callback -> updateBoundParameters (comp -> fmuData , comp -> threadData );
726+ comp -> fmuData -> callback -> updateBoundVariableAttributes (comp -> fmuData , comp -> threadData );
727+ initialization (comp -> fmuData , comp -> threadData , "fmi" , "" , 0.0 );
728+ }
729+ else
730+ {
731+ comp -> fmuData -> callback -> functionODE (comp -> fmuData , comp -> threadData );
732+ overwriteOldSimulationData (comp -> fmuData );
733+ comp -> fmuData -> callback -> functionAlgebraics (comp -> fmuData , comp -> threadData );
734+ comp -> fmuData -> callback -> output_function (comp -> fmuData , comp -> threadData );
735+ comp -> fmuData -> callback -> function_storeDelayed (comp -> fmuData , comp -> threadData );
736+ storePreValues (comp -> fmuData );
737+ }
722738 comp -> _need_update = 0 ;
723739 }
724740
@@ -749,12 +765,21 @@ fmi2Status fmi2GetInteger(fmi2Component c, const fmi2ValueReference vr[], size_t
749765 setThreadData (comp );
750766 if (comp -> _need_update )
751767 {
752- comp -> fmuData -> callback -> functionODE (comp -> fmuData , comp -> threadData );
753- overwriteOldSimulationData (comp -> fmuData );
754- comp -> fmuData -> callback -> functionAlgebraics (comp -> fmuData , comp -> threadData );
755- comp -> fmuData -> callback -> output_function (comp -> fmuData , comp -> threadData );
756- comp -> fmuData -> callback -> function_storeDelayed (comp -> fmuData , comp -> threadData );
757- storePreValues (comp -> fmuData );
768+ if (modelInitializationMode == comp -> state )
769+ {
770+ comp -> fmuData -> callback -> updateBoundParameters (comp -> fmuData , comp -> threadData );
771+ comp -> fmuData -> callback -> updateBoundVariableAttributes (comp -> fmuData , comp -> threadData );
772+ initialization (comp -> fmuData , comp -> threadData , "fmi" , "" , 0.0 );
773+ }
774+ else
775+ {
776+ comp -> fmuData -> callback -> functionODE (comp -> fmuData , comp -> threadData );
777+ overwriteOldSimulationData (comp -> fmuData );
778+ comp -> fmuData -> callback -> functionAlgebraics (comp -> fmuData , comp -> threadData );
779+ comp -> fmuData -> callback -> output_function (comp -> fmuData , comp -> threadData );
780+ comp -> fmuData -> callback -> function_storeDelayed (comp -> fmuData , comp -> threadData );
781+ storePreValues (comp -> fmuData );
782+ }
758783 comp -> _need_update = 0 ;
759784 }
760785
@@ -784,12 +809,21 @@ fmi2Status fmi2GetBoolean(fmi2Component c, const fmi2ValueReference vr[], size_t
784809 setThreadData (comp );
785810 if (comp -> _need_update )
786811 {
787- comp -> fmuData -> callback -> functionODE (comp -> fmuData , comp -> threadData );
788- overwriteOldSimulationData (comp -> fmuData );
789- comp -> fmuData -> callback -> functionAlgebraics (comp -> fmuData , comp -> threadData );
790- comp -> fmuData -> callback -> output_function (comp -> fmuData , comp -> threadData );
791- comp -> fmuData -> callback -> function_storeDelayed (comp -> fmuData , comp -> threadData );
792- storePreValues (comp -> fmuData );
812+ if (modelInitializationMode == comp -> state )
813+ {
814+ comp -> fmuData -> callback -> updateBoundParameters (comp -> fmuData , comp -> threadData );
815+ comp -> fmuData -> callback -> updateBoundVariableAttributes (comp -> fmuData , comp -> threadData );
816+ initialization (comp -> fmuData , comp -> threadData , "fmi" , "" , 0.0 );
817+ }
818+ else
819+ {
820+ comp -> fmuData -> callback -> functionODE (comp -> fmuData , comp -> threadData );
821+ overwriteOldSimulationData (comp -> fmuData );
822+ comp -> fmuData -> callback -> functionAlgebraics (comp -> fmuData , comp -> threadData );
823+ comp -> fmuData -> callback -> output_function (comp -> fmuData , comp -> threadData );
824+ comp -> fmuData -> callback -> function_storeDelayed (comp -> fmuData , comp -> threadData );
825+ storePreValues (comp -> fmuData );
826+ }
793827 comp -> _need_update = 0 ;
794828 }
795829
@@ -819,12 +853,21 @@ fmi2Status fmi2GetString(fmi2Component c, const fmi2ValueReference vr[], size_t
819853 setThreadData (comp );
820854 if (comp -> _need_update )
821855 {
822- comp -> fmuData -> callback -> functionODE (comp -> fmuData , comp -> threadData );
823- overwriteOldSimulationData (comp -> fmuData );
824- comp -> fmuData -> callback -> functionAlgebraics (comp -> fmuData , comp -> threadData );
825- comp -> fmuData -> callback -> output_function (comp -> fmuData , comp -> threadData );
826- comp -> fmuData -> callback -> function_storeDelayed (comp -> fmuData , comp -> threadData );
827- storePreValues (comp -> fmuData );
856+ if (modelInitializationMode == comp -> state )
857+ {
858+ comp -> fmuData -> callback -> updateBoundParameters (comp -> fmuData , comp -> threadData );
859+ comp -> fmuData -> callback -> updateBoundVariableAttributes (comp -> fmuData , comp -> threadData );
860+ initialization (comp -> fmuData , comp -> threadData , "fmi" , "" , 0.0 );
861+ }
862+ else
863+ {
864+ comp -> fmuData -> callback -> functionODE (comp -> fmuData , comp -> threadData );
865+ overwriteOldSimulationData (comp -> fmuData );
866+ comp -> fmuData -> callback -> functionAlgebraics (comp -> fmuData , comp -> threadData );
867+ comp -> fmuData -> callback -> output_function (comp -> fmuData , comp -> threadData );
868+ comp -> fmuData -> callback -> function_storeDelayed (comp -> fmuData , comp -> threadData );
869+ storePreValues (comp -> fmuData );
870+ }
828871 comp -> _need_update = 0 ;
829872 }
830873 resetThreadData (comp );
@@ -1196,7 +1239,8 @@ fmi2Status fmi2GetDerivatives(fmi2Component c, fmi2Real derivatives[], size_t nx
11961239 /* try */
11971240 MMC_TRY_INTERNAL (simulationJumpBuffer )
11981241
1199- if (comp -> _need_update ){
1242+ if (comp -> _need_update )
1243+ {
12001244 comp -> fmuData -> callback -> functionODE (comp -> fmuData , comp -> threadData );
12011245 overwriteOldSimulationData (comp -> fmuData );
12021246 comp -> _need_update = 0 ;
@@ -1242,7 +1286,8 @@ fmi2Status fmi2GetEventIndicators(fmi2Component c, fmi2Real eventIndicators[], s
12421286
12431287#if NUMBER_OF_EVENT_INDICATORS > 0
12441288 /* eval needed equations*/
1245- if (comp -> _need_update ){
1289+ if (comp -> _need_update )
1290+ {
12461291 comp -> fmuData -> callback -> functionODE (comp -> fmuData , comp -> threadData );
12471292 comp -> _need_update = 0 ;
12481293 }
0 commit comments