Changeset c9e6dd3 in OpenModelica


Ignore:
Timestamp:
2022-05-18T10:13:51+02:00 (2 years ago)
Author:
AnHeuermann <andreas.heuermann@…>
Children:
5211c46
Parents:
e4b7953
Message:

Re-calculate stepSize if start/stop time was overwritten

Location:
OMCompiler/SimulationRuntime/c/simulation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/SimulationRuntime/c/simulation/simulation_input_xml.c

    r6cbe437 rc9e6dd3  
    207207
    208208// function to handle command line settings override
    209 void doOverride(omc_ModelInput *mi, MODEL_DATA* modelData, const char* override, const char* overrideFile);
     209modelica_boolean doOverride(omc_ModelInput *mi, MODEL_DATA *modelData, const char *override, const char *overrideFile);
    210210
    211211static const double REAL_MIN = -DBL_MAX;
     
    528528  override = omc_flagValue[FLAG_OVERRIDE];
    529529  overrideFile = omc_flagValue[FLAG_OVERRIDE_FILE];
    530   doOverride(&mi, modelData, override, overrideFile);
     530  modelica_boolean reCalcStepSize = doOverride(&mi, modelData, override, overrideFile);
    531531
    532532  /* read all the DefaultExperiment values */
     
    539539  infoStreamPrint(LOG_SIMULATION, 0, "stopTime = %g", simulationInfo->stopTime);
    540540
    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  }
    542550  infoStreamPrint(LOG_SIMULATION, 0, "stepSize = %g", simulationInfo->stepSize);
    543551
     
    942950}
    943951
    944 void doOverride(omc_ModelInput *mi, MODEL_DATA *modelData, const char *override, const char *overrideFile)
     952modelica_boolean doOverride(omc_ModelInput *mi, MODEL_DATA *modelData, const char *override, const char *overrideFile)
    945953{
    946954  omc_CommandLineOverrides *mOverrides = NULL;
    947955  omc_CommandLineOverridesUses *mOverridesUses = NULL, *it = NULL, *ittmp = NULL;
    948956  mmc_sint_t i;
     957  modelica_boolean changedStartStop = 0 /* false */;
     958  modelica_boolean changedStepSize = 0 /* false */;
     959  modelica_boolean reCalcStepSize = 0 /* false */;
    949960  char* overrideStr1 = NULL, *overrideStr2 = NULL, *overrideStr = NULL;
    950961  if((override != NULL) && (overrideFile != NULL)) {
     
    10811092    }
    10821093
    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)
    10841096    for (i=0; i<sizeof(strs)/sizeof(char*); i++) {
    10851097      if (findHashStringStringNull(mOverrides, strs[i])) {
    10861098        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        }
    10871105      }
     1106    }
     1107    if(changedStartStop && ! changedStepSize) {
     1108      reCalcStepSize = 1 /* true */;
    10881109    }
    10891110
     
    11591180    infoStreamPrint(LOG_SOLVER, 0, "NO override given on the command line.");
    11601181  }
     1182
     1183  return reCalcStepSize;
    11611184}
    11621185
  • OMCompiler/SimulationRuntime/c/simulation/solver/perform_simulation.c.inc

    r834a38b rc9e6dd3  
    506506        }
    507507
    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        }
    509522
    510523        solverInfo->lastdesiredStep = solverInfo->currentTime + solverInfo->currentStepSize;
Note: See TracChangeset for help on using the changeset viewer.