Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#6050 closed defect (fixed)

reinit with introduceOutputAliases broken

Reported by: Andreas Heuermann Owned by: Andreas Heuermann
Priority: high Milestone: 1.16.0
Component: Backend Version: v1.16.0-dev
Keywords: introduceOutputAliases reinit fmi fmi-cross-check Cc:

Description

When enabeling preOptModule introduceOutputAliases (default for FMI 2.0) reinit will not reinitialize the correct variable for top level outputs leading to wrong event behavior.

loadString("
model simpleEvent
  Real h(start=1, fixed=true);
  Real v(start=-2, fixed=true);
  Real x;
equation
  der(h) = v;
  der(v) = 0;
  when h <= 0 then
    reinit(v,-pre(v));
    x = 0.5*v;
  end when;
end simpleEvent;"); getErrorString();

loadString("
model simpleEventOutput
  Real h(start=1, fixed=true);
  output Real v(start=-2, fixed=true);
  Real x;
equation
  der(h) = v;
  der(v) = 0;
  when h <= 0 then
    reinit(v,-pre(v));
    x = 0.5*v;
  end when;
end simpleEventOutput;"); getErrorString();

setCommandLineOptions("--preOptModules+=introduceOutputAliases"); getErrorString();
mkdir("simpleEvent"); getErrorString();
cd("simpleEvent"); getErrorString();
simulate(simpleEvent); getErrorString();

cd(".."); getErrorString();
mkdir("simpleEventOutput"); getErrorString();
cd("simpleEventOutput"); getErrorString();
simulate(simpleEventOutput); getErrorString();

When v is a top level output it should get replaced with outputAlias_v everywhere but is not inside the when equation containing reinit.

Working for:

/*
equation index: 14
type: WHEN

when {$whenCondition1} then
  x = 0.5 * $outputAlias_v;
end when;
*/

Not working for:

/*
equation index: 15
type: WHEN

when {$whenCondition1} then
  reinit(v,  -pre(v));
end when;
*/

Change History (5)

comment:1 by Francesco Casella, 4 years ago

Milestone: Future1.17.0
Priority: highblocker

@AnHeuermann, I marked this as a blocker for 1.17.0; I understand it's not urgent, but it needs to be done in the not too distant future.

comment:2 by Andreas Heuermann, 4 years ago

Milestone: 1.17.0Future
Priority: blockerhigh

The problem is that equation 15 is not inside the equation array given to function BackendDAEUtil.introduceOutputAliases
Adding simple equations aka removed equations solves this.

Simple Equations (1, 0)
========================================
1/1 (0): when h <= 0.0 then
  reinit(v,-pre(v));
end when;   [dynamic |0|0|0|0|]

See PR 6665.

Version 0, edited 4 years ago by Andreas Heuermann (next)

comment:3 by Andreas Heuermann, 4 years ago

Milestone: Future1.16.0

Sorry, changed your changes back without noticing.

comment:4 by Andreas Heuermann, 4 years ago

Resolution: fixed
Status: newclosed

Fixed with 30abd44

comment:5 by Francesco Casella, 4 years ago

Great, thanks!

Note: See TracTickets for help on using tickets.