@@ -508,6 +508,23 @@ void fmi2FreeInstance(fmi2Component c)
508508
509509 FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2FreeInstance" )
510510
511+ /* call external objects destructors */
512+ comp -> fmuData -> callback -> callExternalObjectDestructors (comp -> fmuData , comp -> threadData );
513+ #if !defined(OMC_NUM_NONLINEAR_SYSTEMS ) || OMC_NUM_NONLINEAR_SYSTEMS > 0
514+ /* free nonlinear system data */
515+ freeNonlinearSystems (comp -> fmuData , comp -> threadData );
516+ #endif
517+ #if !defined(OMC_NUM_MIXED_SYSTEMS ) || OMC_NUM_MIXED_SYSTEMS > 0
518+ /* free mixed system data */
519+ freeMixedSystems (comp -> fmuData , comp -> threadData );
520+ #endif
521+ #if !defined(OMC_NUM_LINEAR_SYSTEMS ) || OMC_NUM_LINEAR_SYSTEMS > 0
522+ /* free linear system data */
523+ freeLinearSystems (comp -> fmuData , comp -> threadData );
524+ #endif
525+ /* free data struct */
526+ deInitializeDataStruc (comp -> fmuData );
527+
511528 comp -> functions -> freeMemory (comp -> fmuData -> modelData -> resourcesDir );
512529
513530 /* free simuation data */
@@ -623,6 +640,14 @@ fmi2Status fmi2ExitInitializationMode(fmi2Component c)
623640 return fmi2OK ;
624641}
625642
643+ /*
644+ * fmi2Status fmi2Terminate(fmi2Component c);
645+ * Informs the FMU that the simulation run is terminated. After calling this function, the final
646+ * values of all variables can be inquired with the fmi2GetXXX(..) functions. It is not allowed
647+ * to call this function after one of the functions returned with a status flag of fmi2Error or
648+ * fmi2Fatal.
649+ *
650+ */
626651fmi2Status fmi2Terminate (fmi2Component c )
627652{
628653 ModelInstance * comp = (ModelInstance * )c ;
@@ -631,24 +656,6 @@ fmi2Status fmi2Terminate(fmi2Component c)
631656 FILTERED_LOG (comp , fmi2OK , LOG_FMI2_CALL , "fmi2Terminate" )
632657
633658 setThreadData (comp );
634-
635- /* call external objects destructors */
636- comp -> fmuData -> callback -> callExternalObjectDestructors (comp -> fmuData , comp -> threadData );
637- #if !defined(OMC_NUM_NONLINEAR_SYSTEMS ) || OMC_NUM_NONLINEAR_SYSTEMS > 0
638- /* free nonlinear system data */
639- freeNonlinearSystems (comp -> fmuData , comp -> threadData );
640- #endif
641- #if !defined(OMC_NUM_MIXED_SYSTEMS ) || OMC_NUM_MIXED_SYSTEMS > 0
642- /* free mixed system data */
643- freeMixedSystems (comp -> fmuData , comp -> threadData );
644- #endif
645- #if !defined(OMC_NUM_LINEAR_SYSTEMS ) || OMC_NUM_LINEAR_SYSTEMS > 0
646- /* free linear system data */
647- freeLinearSystems (comp -> fmuData , comp -> threadData );
648- #endif
649- /* free data struct */
650- deInitializeDataStruc (comp -> fmuData );
651-
652659 comp -> state = modelTerminated ;
653660 resetThreadData (comp );
654661 return fmi2OK ;
0 commit comments