Changeset c9e6dd3 in OpenModelica
- Timestamp:
- 2022-05-18T10:13:51+02:00 (2 years ago)
- Children:
- 5211c46
- Parents:
- e4b7953
- Location:
- OMCompiler/SimulationRuntime/c/simulation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
OMCompiler/SimulationRuntime/c/simulation/simulation_input_xml.c
r6cbe437 rc9e6dd3 207 207 208 208 // function to handle command line settings override 209 void doOverride(omc_ModelInput *mi, MODEL_DATA* modelData, const char* override, const char*overrideFile);209 modelica_boolean doOverride(omc_ModelInput *mi, MODEL_DATA *modelData, const char *override, const char *overrideFile); 210 210 211 211 static const double REAL_MIN = -DBL_MAX; … … 528 528 override = omc_flagValue[FLAG_OVERRIDE]; 529 529 overrideFile = omc_flagValue[FLAG_OVERRIDE_FILE]; 530 doOverride(&mi, modelData, override, overrideFile);530 modelica_boolean reCalcStepSize = doOverride(&mi, modelData, override, overrideFile); 531 531 532 532 /* read all the DefaultExperiment values */ … … 539 539 infoStreamPrint(LOG_SIMULATION, 0, "stopTime = %g", simulationInfo->stopTime); 540 540 541 read_value_real(findHashStringString(mi.de,"stepSize"), &(simulationInfo->stepSize), (simulationInfo->stopTime - simulationInfo->startTime) / 500); 541 if (reCalcStepSize) { 542 simulationInfo->stepSize = (simulationInfo->stopTime - simulationInfo->startTime) / 500; 543 warningStreamPrint(LOG_STDOUT, 1, "Start or stop time was overwritten, but no new integrator step size was provided."); 544 infoStreamPrint(LOG_STDOUT, 0, "Re-calculating step size for 500 intervals."); 545 infoStreamPrint(LOG_STDOUT, 0, "Add `stepSize=<value>` to `-override=` or override file to silence this warning."); 546 messageClose(LOG_STDOUT); 547 } else { 548 read_value_real(findHashStringString(mi.de,"stepSize"), &(simulationInfo->stepSize), (simulationInfo->stopTime - simulationInfo->startTime) / 500); 549 } 542 550 infoStreamPrint(LOG_SIMULATION, 0, "stepSize = %g", simulationInfo->stepSize); 543 551 … … 942 950 } 943 951 944 voiddoOverride(omc_ModelInput *mi, MODEL_DATA *modelData, const char *override, const char *overrideFile)952 modelica_boolean doOverride(omc_ModelInput *mi, MODEL_DATA *modelData, const char *override, const char *overrideFile) 945 953 { 946 954 omc_CommandLineOverrides *mOverrides = NULL; 947 955 omc_CommandLineOverridesUses *mOverridesUses = NULL, *it = NULL, *ittmp = NULL; 948 956 mmc_sint_t i; 957 modelica_boolean changedStartStop = 0 /* false */; 958 modelica_boolean changedStepSize = 0 /* false */; 959 modelica_boolean reCalcStepSize = 0 /* false */; 949 960 char* overrideStr1 = NULL, *overrideStr2 = NULL, *overrideStr = NULL; 950 961 if((override != NULL) && (overrideFile != NULL)) { … … 1081 1092 } 1082 1093 1083 // now we have all overrides in mOverrides, override mi now 1094 // Now we have all overrides in mOverrides, override mi now 1095 // Also check if we need to re-calculate stepSize (start / stop time changed, but stepSize not) 1084 1096 for (i=0; i<sizeof(strs)/sizeof(char*); i++) { 1085 1097 if (findHashStringStringNull(mOverrides, strs[i])) { 1086 1098 addHashStringString(&mi->de, strs[i], getOverrideValue(mOverrides, &mOverridesUses, strs[i])); 1099 if (i==1 /* startTime */ || i ==2 /* stopTime */ ) { 1100 changedStartStop = 1 /* true */; 1101 } 1102 if (i==3 /* stepSize */) { 1103 changedStepSize = 1 /* true */; 1104 } 1087 1105 } 1106 } 1107 if(changedStartStop && ! changedStepSize) { 1108 reCalcStepSize = 1 /* true */; 1088 1109 } 1089 1110 … … 1159 1180 infoStreamPrint(LOG_SOLVER, 0, "NO override given on the command line."); 1160 1181 } 1182 1183 return reCalcStepSize; 1161 1184 } 1162 1185 -
OMCompiler/SimulationRuntime/c/simulation/solver/perform_simulation.c.inc
r834a38b rc9e6dd3 506 506 } 507 507 508 solverInfo->currentStepSize = (double)(__currStepNo*(simInfo->stopTime-simInfo->startTime))/(simInfo->numSteps) + simInfo->startTime - solverInfo->currentTime; 508 if(simInfo->numSteps == 0) { 509 if(fabs(simInfo->stopTime-simInfo->startTime) < 1e-16) { 510 solverInfo->currentStepSize = 0; 511 } else { 512 errorStreamPrint(LOG_STDOUT, 1, "Number of integrator steps to do is 0, but experiment start time is not equal stop time."); 513 infoStreamPrint(LOG_STDOUT, 0, "start time: %f, stop time: %f, integrator step size: %f",simInfo->startTime, simInfo->stopTime, simInfo->stepSize); 514 messageClose(LOG_STDOUT); 515 errorStreamPrint(LOG_STDOUT, 0, "model terminate | Integrator failed. | Simulation terminated at time %g", solverInfo->currentTime); 516 retValue = -1; 517 break; 518 } 519 } else { 520 solverInfo->currentStepSize = (double)(__currStepNo*(simInfo->stopTime-simInfo->startTime))/(simInfo->numSteps) + simInfo->startTime - solverInfo->currentTime; 521 } 509 522 510 523 solverInfo->lastdesiredStep = solverInfo->currentTime + solverInfo->currentStepSize;
Note: See TracChangeset
for help on using the changeset viewer.