Changeset 97583e7 in OpenModelica
- Timestamp:
- 2021-06-08T11:19:36+02:00 (3 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OMCompiler/SimulationRuntime/c/simulation/solver/spatialDistribution.c
r68653477 r97583e7 241 241 * @brief Store spatial distribution data for an accepted step. 242 242 * 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)`. 250 251 */ 251 252 void storeSpatialDistribution(DATA* data, threadData_t *threadData, unsigned int index, double in0, double in1, double posX, int isPositiveVelocity) { … … 255 256 DOUBLE_ENDED_LIST* storedEventsList; 256 257 int walkedOverEvents = 0; 258 double deltaX, realDirection; 257 259 258 260 /* Access spatialDistribution */ … … 271 273 errorStreamPrint(LOG_STDOUT, 0, "Discrete call of storeSpatialDistribution"); 272 274 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; 273 292 } 274 293 … … 341 360 int walkedOverEvents; 342 361 int realDirection; 362 int jumped = 0; 343 363 double deltaX; 344 364 double eventPreValue; … … 357 377 358 378 /* Get deltaX */ 359 deltaX = fabs(spatialDistribution->oldPosX - posX);360 if ( posX - spatialDistribution->oldPosX > 0) {379 deltaX = spatialDistribution->oldPosX - posX; 380 if (deltaX > 0) { 361 381 realDirection = 1 /* positive */; 362 } else if ( posX - spatialDistribution->oldPosX < 0) {382 } else if (deltaX < 0) { 363 383 realDirection = -1 /* negative */; 384 deltaX = -deltaX; 364 385 } else { 365 386 realDirection = 0 /* standing still */; 366 387 } 367 388 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 */; 372 394 } 373 395 … … 409 431 forelastNodeData = dataDoubleEndedList(getPreviousNodeDoubleEndedList(getLastNodeDoubleEndedList(transportedQuantityList))); 410 432 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) { 412 436 out0 = extrapolateTransportedQuantity(firstNodeData, secondNodeData, -posX); 413 437 } else { … … 417 441 } else { 418 442 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) { 420 446 *out1 = extrapolateTransportedQuantity(forelastNodeData, lastNodeData, -posX+1); 421 447 } else {
Note: See TracChangeset
for help on using the changeset viewer.