Changeset 14ac561 in OpenModelica


Ignore:
Timestamp:
2022-05-16T11:43:04+02:00 (23 months ago)
Author:
Philip Hannebohm <phannebohm@…>
Parents:
e1dbd879
git-author:
Philip Hannebohm <phannebohm@…> (05/16/22 11:40:47)
git-committer:
Philip Hannebohm <phannebohm@…> (05/16/22 11:43:04)
Message:

Modularize findRoot

  • suggested by bernhardbachmann
Location:
OMCompiler/SimulationRuntime/c/simulation/solver
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/SimulationRuntime/c/simulation/solver/events.c

    re1dbd879 r14ac561  
    149149  TRACE_PUSH
    150150
    151   if (checkForStateEvent(data, eventLst))
    152   {
    153     if (useRootFinding)
    154     {
    155       *eventTime = findRoot(data, threadData, eventLst);
    156     }
     151  int found = checkForStateEvent(data, eventLst);
     152  if(found && useRootFinding)
     153  {
     154    *eventTime = findRoot(data, threadData, eventLst, data->simulationInfo->timeValueOld, data->simulationInfo->realVarsOld, data->localData[0]->timeValue, data->localData[0]->realVars);
    157155  }
    158156
     
    287285 *  \param [ref] [threadData]
    288286 *  \param [ref] [eventList]
    289  *  \return: first event of interval [oldTime, timeValue]
    290  *
    291  *  This function perform a root finding for interval = [oldTime, timeValue]
    292  */
    293 double findRoot(DATA* data, threadData_t *threadData, LIST *eventList)
     287 *  \param [in]  [time_left]
     288 *  \param [in]  [values_left]
     289 *  \param [in]  [time_right]
     290 *  \param [in]  [values_right]
     291 *  \return: first event of interval [time_left, time_right]
     292 */
     293double findRoot(DATA* data, threadData_t* threadData, LIST* eventList, double time_left, double* values_left, double time_right, double* values_right)
    294294{
    295295  TRACE_PUSH
     
    303303  static double *states_right = NULL;
    304304
    305   double time_left = data->simulationInfo->timeValueOld;
    306   double time_right = data->localData[0]->timeValue;
    307 
    308305  /* allocate memory once at first call, never free */
    309306  if(!states_left)
     
    319316
    320317  /* write states to work arrays */
    321   memcpy(states_left,  data->simulationInfo->realVarsOld, data->modelData->nStates * sizeof(double));
    322   memcpy(states_right, data->localData[0]->realVars     , data->modelData->nStates * sizeof(double));
     318  memcpy(states_left,  values_left, data->modelData->nStates * sizeof(double));
     319  memcpy(states_right, values_right, data->modelData->nStates * sizeof(double));
    323320
    324321  for(it=listFirstNode(eventList); it; it=listNextNode(it))
  • OMCompiler/SimulationRuntime/c/simulation/solver/events.h

    r83be5f2b r14ac561  
    5050void handleEvents(DATA* data, threadData_t *threadData, LIST* eventLst, double *eventTime, SOLVER_INFO* solverInfo);
    5151
    52 double findRoot(DATA *data, threadData_t *threadData, LIST *eventList);
     52double findRoot(DATA* data, threadData_t* threadData, LIST* eventList, double time_left, double* states_left, double time_right, double* states_right);
    5353
    5454#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.