Changeset 97583e7 in OpenModelica


Ignore:
Timestamp:
2021-06-08T11:19:36+02:00 (3 years ago)
Author:
GitHub <noreply@…>
Branches:
Added-citation-metadata, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, master, omlib-staging
Children:
41f9a35e, ac9546c5
Parents:
16b10d40
git-author:
Andreas <38031952+AnHeuermann@…> (06/08/21 11:19:36)
git-committer:
GitHub <noreply@…> (06/08/21 11:19:36)
Message:

Remove error about wrong direction in spatialDistribution (#7510)

File:
1 edited

Legend:

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

    r68653477 r97583e7  
    241241 * @brief Store spatial distribution data for an accepted step.
    242242 *
    243  * @param data
    244  * @param threadData
    245  * @param index
    246  * @param in0
    247  * @param in1
    248  * @param posX
    249  * @param isPositiveVelocity
     243 * @param data                Data
     244 * @param threadData          Thread data for error handling
     245 * @param index               Index of spatial distribution.
     246 * @param in0                 First input to spatial distribution.
     247 * @param in1                 Second input to spatial distribution
     248 * @param posX                Value of position x.
     249 * @param isPositiveVelocity  Boolean describing if velocity v is positive (>=0).
     250 *                            Velocity v is `v:=der(x)`.
    250251 */
    251252void storeSpatialDistribution(DATA* data, threadData_t *threadData, unsigned int index, double in0, double in1, double posX, int isPositiveVelocity) {
     
    255256  DOUBLE_ENDED_LIST* storedEventsList;
    256257  int walkedOverEvents = 0;
     258  double deltaX, realDirection;
    257259
    258260  /* Access spatialDistribution */
     
    271273    errorStreamPrint(LOG_STDOUT, 0, "Discrete call of storeSpatialDistribution");
    272274    omc_throw_function(threadData);
     275  }
     276
     277  /* Get deltaX */
     278  deltaX = spatialDistribution->oldPosX - posX;
     279  if (deltaX > 0) {
     280    realDirection = 1 /* positive */;
     281  } else if (deltaX < 0) {
     282    realDirection = -1 /* negative */;
     283    deltaX = -deltaX;
     284  } else {
     285    realDirection = 0 /* standing still */;
     286  }
     287
     288  /* If real direction doesn't match isPositiveVelocity just flip isPositiveVelocity. */
     289  if (deltaX > SPATIAL_ZERO_DELTA_X && isPositiveVelocity*realDirection > 0) {
     290    // TODO: This is probably still a sign that we didn't handle some event or event search correctly.
     291    isPositiveVelocity  = !isPositiveVelocity;
    273292  }
    274293
     
    341360  int walkedOverEvents;
    342361  int realDirection;
     362  int jumped = 0;
    343363  double deltaX;
    344364  double eventPreValue;
     
    357377
    358378  /* Get deltaX */
    359   deltaX = fabs(spatialDistribution->oldPosX - posX);
    360   if (posX - spatialDistribution->oldPosX > 0) {
     379  deltaX = spatialDistribution->oldPosX - posX;
     380  if (deltaX > 0) {
    361381    realDirection = 1 /* positive */;
    362   } else if (posX - spatialDistribution->oldPosX < 0) {
     382  } else if (deltaX < 0) {
    363383    realDirection = -1 /* negative */;
     384    deltaX = -deltaX;
    364385  } else {
    365386    realDirection = 0 /* standing still */;
    366387  }
    367388
    368   /* What should happen if realDirection doesn't match given isPositiveVelocity and velocity is not 0? */
    369   if ((isPositiveVelocity && realDirection==-1 && deltaX > SPATIAL_ZERO_DELTA_X) || (!isPositiveVelocity && realDirection!= -1 && deltaX > SPATIAL_ZERO_DELTA_X)) {
    370     errorStreamPrint(LOG_STDOUT, 0, "Boolean isPositiveDirection doesn't match with direction x is moving.");
    371     omc_throw_function(threadData);
     389  /* If real direction doesn't match isPositiveVelocity just flip isPositiveVelocity.
     390   * This still indicates something wrong, so we don't extrapolate the output */
     391  if (deltaX > SPATIAL_ZERO_DELTA_X && isPositiveVelocity*realDirection > 0) {
     392    isPositiveVelocity  = !isPositiveVelocity;
     393    jumped = 1 /* true */;
    372394  }
    373395
     
    409431  forelastNodeData = dataDoubleEndedList(getPreviousNodeDoubleEndedList(getLastNodeDoubleEndedList(transportedQuantityList)));
    410432  if (isPositiveVelocity) {
    411     if (deltaX > SPATIAL_EPS && fabs(firstNodeData->position-secondNodeData->position)>SPATIAL_EPS ) {
     433    if (jumped) {
     434      out0 = in0;
     435    } else if (deltaX > SPATIAL_EPS && fabs(firstNodeData->position-secondNodeData->position)>SPATIAL_EPS) {
    412436      out0 = extrapolateTransportedQuantity(firstNodeData, secondNodeData, -posX);
    413437    } else {
     
    417441  } else {
    418442    out0 = outValue;
    419     if (deltaX > SPATIAL_EPS && fabs(forelastNodeData->position-lastNodeData->position)>SPATIAL_EPS ) {
     443    if (jumped) {
     444      *out1 = in1;
     445    } else if (deltaX > SPATIAL_EPS && fabs(forelastNodeData->position-lastNodeData->position)>SPATIAL_EPS) {
    420446      *out1 = extrapolateTransportedQuantity(forelastNodeData, lastNodeData, -posX+1);
    421447    } else {
Note: See TracChangeset for help on using the changeset viewer.