4

For simple test models, I commonly a syntax similar to:

// Assuming the start time is 0 and stop time is 1
x = xMin + (xMax - xMin) * time;
y = f(x);

To be correct no matter the simulation setup, I would like to use:

x = xMin + (xMax - xMin) * (time - startTime) / (stopTime - startTime);
y = f(x);

However, I am unsure how I can reference the values defined in the Simulation Setup / General form.

I have tried simply referencing StartTime, startTime, starttime, timestart, timeStart, etc. with no success.

I understand that it is possible to set StartTime and StopTime using an annotation, but those values are only set the first time a model is opened and so may not truly reflect a simulation's start time and stop time.

Justin Kauffman
  • 423
  • 3
  • 10

2 Answers2

3

It is currently not possible to access the stop-time of a simulation inside Dymola to use in the model, but you can get the start-time as follows:

  parameter Real startTime(fixed=false);
initial equation
  startTime=time;

Note that if you use Simulation>Continue>Continue the startTime will not be updated, but continue with its original value.

Hans Olsson
  • 11,123
  • 15
  • 38
2

Not perfect, but you could provide the information from outside:

Add the start- and stop-time as parameters to your model

parameter Modelica.SIunits.Time stopTime = 0;
parameter Modelica.SIunits.Time startTime = 1;

and use a function to perform the simulations

function sim
  input Modelica.SIunits.Time startTime = 1;
  input Modelica.SIunits.Time stopTime = 2;
algorithm 
  DymolaCommands.SimulatorAPI.simulateExtendedModel(
    "model-name", startTime, stopTime, 
    initialNames={"startTime", "stopTime"}, 
    initialValues={startTime, stopTime});
end sim;
marco
  • 5,944
  • 10
  • 22