@@ -345,64 +345,60 @@ void printStateSelectionInfo(DATA *data, STATE_SET_DATA *set)
345345 messageClose (LOG_DSS );
346346}
347347
348- /*! \fn stateSelection
348+ /*! \fn stateSelectionSet
349349 *
350- * function to select the actual states
350+ * function to select the actual states for an individual stateSet
351351 *
352352 * \param [ref] [data]
353353 * \param [in] [reportError]
354354 * \param [in] [switchStates] flag for switch states, function does switch only if this switchStates = 1
355- * \return ???
355+ * \return [globalres] flag for discontinuous timestep in the case of a state switch
356356 *
357- * \author Frenkel TUD
357+ * \author Abdelhak / Frenkel TUD
358358 */
359- int stateSelection (DATA * data , threadData_t * threadData , char reportError , int switchStates )
359+ int stateSelectionSet (DATA * data , threadData_t * threadData , char reportError , int switchStates , long setIndex , int globalres )
360360{
361- TRACE_PUSH
362- long i = 0 ;
363- long j = 0 ;
364- int globalres = 0 ;
365- long k = 0 ;
366- long l = 0 ;
367-
368- /* go through all the state sets */
369- for (i = 0 ; i < data -> modelData -> nStateSets ; i ++ )
370- {
361+ long j = 0 ;
362+ long k = 0 ;
363+ long l = 0 ;
364+ long m = 0 ;
371365 int res = 0 ;
372- STATE_SET_DATA * set = & (data -> simulationInfo -> stateSetData [i ]);
366+ STATE_SET_DATA * set = & (data -> simulationInfo -> stateSetData [setIndex ]);
373367 modelica_integer * oldColPivot = (modelica_integer * ) malloc (set -> nCandidates * sizeof (modelica_integer ));
374368 modelica_integer * oldRowPivot = (modelica_integer * ) malloc (set -> nDummyStates * sizeof (modelica_integer ));
375369
376370 /* debug */
377371 if (ACTIVE_STREAM (LOG_DSS ))
378372 {
379- infoStreamPrint (LOG_DSS , 1 , "StateSelection Set %ld at time = %f" , i , data -> localData [0 ]-> timeValue );
373+ infoStreamPrint (LOG_DSS , 1 , "StateSelection Set %ld at time = %f" , setIndex , data -> localData [0 ]-> timeValue );
380374 printStateSelectionInfo (data , set );
381375 messageClose (LOG_DSS );
382376 }
383377 /* generate jacobian, stored in set->J */
384- getAnalyticalJacobianSet (data , threadData , i );
378+ getAnalyticalJacobianSet (data , threadData , setIndex );
385379
386380 /* call pivoting function to select the states */
387381 memcpy (oldColPivot , set -> colPivot , set -> nCandidates * sizeof (modelica_integer ));
388382 memcpy (oldRowPivot , set -> rowPivot , set -> nDummyStates * sizeof (modelica_integer ));
389383 if ((pivot (set -> J , set -> nDummyStates , set -> nCandidates , set -> rowPivot , set -> colPivot ) != 0 ) && reportError )
390384 {
391385 /* error, report the matrix and the time */
392- char * buffer = (char * )malloc (sizeof (char )* data -> simulationInfo -> analyticJacobians [set -> jacobianIndex ].sizeCols * 10 );
393386
387+ char * buffer = (char * )malloc (sizeof (char )* data -> simulationInfo -> analyticJacobians [set -> jacobianIndex ].sizeCols * 100 + 5 );
394388 warningStreamPrint (LOG_DSS , 1 , "jacobian %dx%d [id: %ld]" , data -> simulationInfo -> analyticJacobians [set -> jacobianIndex ].sizeRows , data -> simulationInfo -> analyticJacobians [set -> jacobianIndex ].sizeCols , set -> jacobianIndex );
395- for (i = 0 ; i < data -> simulationInfo -> analyticJacobians [set -> jacobianIndex ].sizeRows ; i ++ )
389+
390+ for (m = 0 ; m < data -> simulationInfo -> analyticJacobians [set -> jacobianIndex ].sizeRows ; m ++ )
396391 {
397392 buffer [0 ] = 0 ;
398393 for (j = 0 ; j < data -> simulationInfo -> analyticJacobians [set -> jacobianIndex ].sizeCols ; j ++ )
399- sprintf (buffer , "%s%.5e " , buffer , set -> J [i * data -> simulationInfo -> analyticJacobians [set -> jacobianIndex ].sizeCols + j ]);
394+ sprintf (buffer , "%s%.5e " , buffer , set -> J [m * data -> simulationInfo -> analyticJacobians [set -> jacobianIndex ].sizeCols + j ]);
400395 warningStreamPrint (LOG_DSS , 0 , "%s" , buffer );
401396 }
397+
402398 free (buffer );
403399
404- for (i = 0 ; i < set -> nCandidates ; i ++ )
405- warningStreamPrint (LOG_DSS , 0 , "%s" , set -> statescandidates [i ]-> name );
400+ for (m = 0 ; m < set -> nCandidates ; m ++ )
401+ warningStreamPrint (LOG_DSS , 0 , "%s" , set -> statescandidates [m ]-> name );
406402 messageClose (LOG_DSS );
407403
408404 throwStreamPrint (threadData , "Error, singular Jacobian for dynamic state selection at time %f\nUse -lv LOG_DSS_JAC to get the Jacobian" , data -> localData [0 ]-> timeValue );
@@ -420,6 +416,30 @@ int stateSelection(DATA *data, threadData_t *threadData, char reportError, int s
420416
421417 free (oldColPivot );
422418 free (oldRowPivot );
419+ return globalres ;
420+ }
421+
422+ /*! \fn stateSelection
423+ *
424+ * function to select the actual states
425+ *
426+ * \param [ref] [data]
427+ * \param [in] [reportError]
428+ * \param [in] [switchStates] flag for switch states, function does switch only if this switchStates = 1
429+ * \return ???
430+ *
431+ * \author Frenkel TUD
432+ */
433+ int stateSelection (DATA * data , threadData_t * threadData , char reportError , int switchStates )
434+ {
435+ TRACE_PUSH
436+ long i = 0 ;
437+ int globalres = 0 ;
438+
439+ /* go through all the state sets */
440+ for (i = 0 ; i < data -> modelData -> nStateSets ; i ++ )
441+ {
442+ globalres = stateSelectionSet (data , threadData , reportError , switchStates , i , globalres );
423443 }
424444
425445 TRACE_POP
0 commit comments