Opened 10 years ago

Closed 7 years ago

Last modified 7 years ago

#2763 closed enhancement (fixed)

Propagation of start values for inputs to simulation

Reported by: Rüdiger Franke Owned by: Lennart Ochel
Priority: normal Milestone: 1.12.0
Component: Run-time Version: trunk
Keywords: Cc:

Description

If the model below is opened and simulated with OMEdit (1.9.1+dev (r21649)), the simulation assigns zero to the input u.

Couldn't the simulation use the start value of -2 instead?

How could one otherwise define values for external inputs?

Note: external inputs are needed because the model shall be exported as FMU.

within ;
model DIC_states "Double Integrator Continuous-time"
  parameter Real p = 1 "gain for input";
  parameter Real y1_start = 1 "start value for first state";
  parameter Real y2_start = 0 "start value for second state";
  input Real u(start = -2);
  output Real y1, y2;
  Real x1, x2;
initial equation
  y1 = y1_start;
  y2 = y2_start;
equation
  der(x1) = p*u;
  der(x2) = x1;
  y1 = x1;
  y2 = x2;
end DIC_states;

Change History (31)

comment:1 by Jan Kokert, 10 years ago

Hi!

(start = -2)

is the initial guess value to solve the "initial value problem" to afterwards run the DAE solver.
If you want to have u = -2 at t=0 you need to specify this as an initial equation:

initial equation
  u = -2;

But in your case this is not possible (initial equation system overdetermined) and I guess this is because u is an input and has a default value of 0 (?).

comment:2 by Lennart Ochel, 10 years ago

Well, there is no need for initial equations of inputs. They are already known and additional equations would lead to over-determined systems. If there is no input-file specified, I think start values should be used.
I am not sure if OMEdit supports input files. Maybe this should become more user friendly.

comment:3 by Vitalij Ruge, 10 years ago

There are an example:

https://trac.openmodelica.org/OpenModelica/browser/trunk/testsuite/simulation/modelica/solver/LotkaVolterraWithInput.mos

for external input. Omc take the file externalInput.csv(linear interpolation inside)
Or try simflag: -exInputFile=<name>

Omc take the inputs by sorting and not by name ref.

But it's just a prototype. No idea this would help you with FMU.
Currently I used it only for checking the inputs from optimizer with simulation methode and for initial guesss inside optimization.

Last edited 10 years ago by Vitalij Ruge (previous) (diff)

comment:4 by Rüdiger Franke, 10 years ago

Thank you for the hints!

Still I wonder, if not the start values are better suited than a constant zero in the case that nothing else is assigned to the inputs.

In particular the interactive environment OMEdit would benefit from such a feature.

comment:5 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:6 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:7 by Adeel Asghar, 10 years ago

Component: OMEditRun-time
Owner: changed from Adeel Asghar to Lennart Ochel
Status: newassigned

comment:8 by Adrian Pop, 10 years ago

Reporter: changed from rfranke@… to Rüdiger Franke

comment:9 by Lennart Ochel, 10 years ago

Status: assignedaccepted

comment:10 by Rüdiger Franke, 10 years ago

It works with +simCodeTarget=Cpp :-)

comment:11 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:12 by Lennart Ochel, 9 years ago

Resolution: fixed
Status: acceptedclosed

In the meantime this works also for c runtime.

comment:13 by Rüdiger Franke, 9 years ago

Resolution: fixed
Status: closedreopened

How did you get this result for the C runtime?

I just opened the example DIC_states given in the above description in OMEdit. Simulation with the C runtime results in y2 going on a straight line from 0 to 1, i.e. u is not -2, but 0.

Extending "Tools->Options->Simulation:OMC Flags" with "+simCodeTarget=Cpp", the start value of -2 is used for u and y2 goes from 0 to 0.25 and back to 0.

Yesterday but one I also observed that the C runtime does not use the start value when adding an FMI test, see:
https://github.com/OpenModelica/OpenModelica-testsuite/commit/449f0a68ac0bf5a2d44bafe7b92a37e8e71f284b

comment:14 by Lennart Ochel, 9 years ago

I just run this script using c and cpp target:

loadString("
within ;
model DIC_states \"Double Integrator Continuous-time\"
  parameter Real p = 1 \"gain for input\";
  parameter Real y1_start = 1 \"start value for first state\";
  parameter Real y2_start = 0 \"start value for second state\";
  input Real u(start = -2);
  output Real y1, y2;
  Real x1, x2;
initial equation
  y1 = y1_start;
  y2 = y2_start;
equation
  der(x1) = p*u;
  der(x2) = x1;
  y1 = x1;
  y2 = x2;
end DIC_states;
"); getErrorString();

simulate(DIC_states); getErrorString();
val(u, 0.0); getErrorString();
val(der(x1), 0.0); getErrorString();

I get -2 in both cases for u and der(x1).

comment:15 by Rüdiger Franke, 9 years ago

Then it might be an OMEdit / FMI import issue. Strange that it works with OMEdit and the Cpp runtime?!

comment:16 by Martin Sjölund, 9 years ago

FMI is not the same thing as the C runtime. It is a separate target.

comment:17 by Lennart Ochel, 9 years ago

Status: reopenedaccepted

Hmm – now I had a closer look at the simulation result. u is only -2 for initialization. During simulation it is constant 0.

in reply to:  16 comment:18 by Rüdiger Franke, 9 years ago

Replying to sjoelund.se:

FMI is not the same thing as the C runtime. It is a separate target.

In fact the FMI 2.0 import of the optimization solver HQP considers the start values for FMUs exported with C or with Cpp the same way (both use the same XML file).

So we have two issues here, affecting the C runtime and FMI import.

comment:19 by Lennart Ochel, 9 years ago

Using the changes from PR204 will initialize the inputs with its start values. Please, can one review the changes?

comment:20 by Lennart Ochel, 9 years ago

Well, now (71012083adc2359ce27909b0cd9b69ff31a634f6/OMCompiler) it should be fixed for the c runtime.

comment:21 by Lennart Ochel, 9 years ago

Can we close this ticket or is there still an open fmi issue?

comment:22 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:23 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:24 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:25 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:26 by Francesco Casella, 7 years ago

Resolution: invalid
Status: acceptedclosed

I see this ticket is still open, though I cannot really see the point.

If u is an input, it means it will have to be provided at runtime in some appropriate way (e.g. and input file for batch simulation, or by calling fmi2SetReal. At that point, the initialization should be solved using whatever value is provided, and the start attribute should be totally irrelevant. It is only relevant when the variable is either an unknown of a system of equations to be solved iteratively, or a state variable, but an input is neither one.

If no input is provided, then the universally accepted semantics (though it's not in the specification, I guess) is that the input is identically zero. I don't see why any other value should be used at initialization.

comment:27 by Rüdiger Franke, 7 years ago

Resolution: invalid
Status: closedreopened

comment:28 by Rüdiger Franke, 7 years ago

Resolution: fixed
Status: reopenedclosed

The point is user experience. Modelica supports start values for inputs in a standardized way. Why not exploiting them and instead asking users to write some additional, tool specific input file for the simulator?

The exploitation of start values for inputs works by today with all Modelica tools and runtimes I'm using, including also FMI.

comment:29 by Francesco Casella, 7 years ago

Do you mean that in absence of futher input (as a file or fmi2SetReal),

input Real u(start = -2);

should actually mean that u = -2 all the time?

That makes sense to me, but is it really written in the Modelica Specification?

comment:30 by Martin Sjölund, 7 years ago

It's not very well specified, but if you treat it like a state variable with der(u)=0 it would make sense to have it u = -2 all the time (unless you have some external input influencing it)

comment:31 by jmsanchez, 7 years ago

Functional Mock-up Interface 2.0
July 25, 2014
Page 47 of 126
Near the bottom:

If fmiSetXXX is not called on a variable with causality = ″input″ then the FMU must
use the start value as value of this input.

Note: See TracTickets for help on using tickets.