@@ -561,6 +561,22 @@ fmi2Status fmi2SetupExperiment(fmi2Component c, fmi2Boolean toleranceDefined, fm
561561}
562562
563563fmi2Status fmi2EnterInitializationMode (fmi2Component c )
564+ {
565+ ModelInstance * comp = (ModelInstance * )c ;
566+
567+ if (invalidState (comp , "fmi2EnterInitializationMode" , modelInstantiated , ~0 ))
568+ return fmi2Error ;
569+ FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2EnterInitializationMode..." )
570+
571+ setZCtol (comp -> tolerance ); /* set zero-crossing tolerance */
572+ setStartValues (comp );
573+ copyStartValuestoInitValues (comp -> fmuData );
574+ comp -> state = modelInitializationMode ;
575+
576+ return fmi2OK ;
577+ }
578+
579+ fmi2Status fmi2ExitInitializationMode (fmi2Component c )
564580{
565581 fmi2Status res = fmi2Error ;
566582 ModelInstance * comp = (ModelInstance * )c ;
@@ -570,81 +586,67 @@ fmi2Status fmi2EnterInitializationMode(fmi2Component c)
570586 int done = 0 ;
571587
572588 threadData -> currentErrorStage = ERROR_SIMULATION ;
573- if (invalidState (comp , "fmi2EnterInitializationMode " , modelInstantiated , ~0 ))
589+ if (invalidState (comp , "fmi2ExitInitializationMode " , modelInitializationMode , ~0 ))
574590 return fmi2Error ;
591+ FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2ExitInitializationMode..." )
575592
576593 setThreadData (comp );
577-
578- FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2EnterInitializationMode..." )
579- /* set zero-crossing tolerance */
580- setZCtol (comp -> tolerance );
581-
582- setStartValues (comp );
583- copyStartValuestoInitValues (comp -> fmuData );
594+ comp -> fmuData -> callback -> updateBoundParameters (comp -> fmuData , comp -> threadData );
595+ comp -> fmuData -> callback -> updateBoundVariableAttributes (comp -> fmuData , comp -> threadData );
584596
585597 /* try */
586598 MMC_TRY_INTERNAL (simulationJumpBuffer )
587- threadData -> mmc_jumper = threadData -> simulationJumpBuffer ;
599+ threadData -> mmc_jumper = threadData -> simulationJumpBuffer ;
588600
589- if (initialization (comp -> fmuData , comp -> threadData , "" , "" , 0.0 )) {
590- comp -> state = modelError ;
591- FILTERED_LOG ( comp , fmi2Error , LOG_FMI2_CALL , "fmi2EnterInitializationMode: failed" )
592- }
593- else
594- {
595- /*TODO: Simulation stop time is need to calculate in before hand all sample events
596- We shouldn't generate them all in beforehand */
597- initSample (comp -> fmuData , comp -> threadData , comp -> fmuData -> localData [0 ]-> timeValue , 100 /*should be stopTime*/ );
601+ if (initialization (comp -> fmuData , comp -> threadData , "fmi " , "" , 0.0 ))
602+ {
603+ comp -> state = modelError ;
604+ FILTERED_LOG ( comp , fmi2Error , LOG_FMI2_CALL , "fmi2EnterInitializationMode: failed" )
605+ }
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*/ );
598610#if !defined(OMC_NDELAY_EXPRESSIONS ) || OMC_NDELAY_EXPRESSIONS > 0
599- initDelay (comp -> fmuData , comp -> fmuData -> localData [0 ]-> timeValue );
611+ initDelay (comp -> fmuData , comp -> fmuData -> localData [0 ]-> timeValue );
600612#endif
601- /* due to an event overwrite old values */
602- overwriteOldSimulationData (comp -> fmuData );
613+ /* overwrite old values due to an event */
614+ overwriteOldSimulationData (comp -> fmuData );
603615
604- comp -> eventInfo .terminateSimulation = fmi2False ;
605- comp -> eventInfo .valuesOfContinuousStatesChanged = fmi2True ;
606-
607- /* Get next event time (sample calls)*/
608- nextSampleEvent = 0 ;
609- nextSampleEvent = getNextSampleTimeFMU (comp -> fmuData );
610- if (nextSampleEvent == -1 ) {
611- comp -> eventInfo .nextEventTimeDefined = fmi2False ;
612- } else {
613- comp -> eventInfo .nextEventTimeDefined = fmi2True ;
614- comp -> eventInfo .nextEventTime = nextSampleEvent ;
615- fmi2EventUpdate (comp , & (comp -> eventInfo ));
616- }
617- comp -> state = modelInitializationMode ;
618- FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2EnterInitializationMode: succeed" )
619- res = fmi2OK ;
616+ comp -> eventInfo .terminateSimulation = fmi2False ;
617+ comp -> eventInfo .valuesOfContinuousStatesChanged = fmi2True ;
618+
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 ));
620631 }
621- done = 1 ;
632+ FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2EnterInitializationMode: succeed" )
633+ res = fmi2OK ;
634+ }
635+ done = 1 ;
622636 /* catch */
623637 MMC_CATCH_INTERNAL (simulationJumpBuffer )
624638 threadData -> mmc_jumper = old_jmp ;
625639
626- if (!done ) {
640+ if (!done )
641+ {
627642 FILTERED_LOG (comp , fmi2Error , LOG_FMI2_CALL , "fmi2EnterInitializationMode: terminated by an assertion." )
628643 }
629- resetThreadData (comp );
630- return res ;
631- }
632-
633- fmi2Status fmi2ExitInitializationMode (fmi2Component c )
634- {
635- ModelInstance * comp = (ModelInstance * )c ;
636- if (invalidState (comp , "fmi2ExitInitializationMode" , modelInitializationMode , ~0 ))
637- return fmi2Error ;
638- FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2ExitInitializationMode..." )
639644
640- setThreadData (comp );
641- comp -> fmuData -> callback -> updateBoundParameters (comp -> fmuData , comp -> threadData );
642- comp -> fmuData -> callback -> updateBoundVariableAttributes (comp -> fmuData , comp -> threadData );
643645 comp -> state = modelEventMode ;
644646 resetThreadData (comp );
645647
646648 FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2ExitInitializationMode: succeed" )
647- return fmi2OK ;
649+ return res ;
648650}
649651
650652/*
0 commit comments