Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3549 closed defect (fixed)

Evaluation of Clock parameters

Reported by: Rüdiger Franke Owned by: Lennart Ochel
Priority: high Milestone: 1.9.4
Component: Backend Version:
Keywords: Cc: Lennart Ochel, Adrian Pop, Bernhard Thiele, Maksimov Doe

Description

The following model has the evaluated parameter dt to parameterize its clock (see also Modelica_Synchronous):

model SID
  parameter Real dt = 0.1 annotation(Evaluate=true);
  Real x(start = 0);
  input Real u(start = 1);
  output Real y;
equation
  when Clock(dt) then
    x = previous(x) + u * interval(u);
    y = previous(x);
  end when;
end SID;

Exporting it as FMU with

translateModelFMU(SID, version="2.0");

gives the Clocks section:

    <Clocks>
      <Clock><Triggered/></Clock>
    </Clocks>

Triggered is used because the value of dt is not known during code generation. It should be known due to annotation(Evaluate=true). The correct Clocks section reads (e.g. replace parameter Real dt with constant):

    <Clocks>
      <Clock><Periodic
              baseInterval="0.1"
              /></Clock>
    </Clocks>

How can the evaluated value of dt be inquired during code generation?

Change History (9)

comment:1 by Adrian Pop, 9 years ago

Cc: Bernhard Thiele Maksimov Doe added

comment:2 by Lennart Ochel, 9 years ago

I think this should get already replaced in the back end.

comment:3 by Lennart Ochel, 9 years ago

Owner: changed from somebody to Lennart Ochel
Status: newaccepted

It seems that parameters get not replaced within the clocks, since they were introduces recently and the eval-module does not consider clocks yet.

comment:4 by Lennart Ochel, 9 years ago

PR279 adds missing replacement rules for clock expressions.

in reply to:  description comment:5 by Lennart Ochel, 9 years ago

Replying to rfranke:

gives the Clocks section:

    <Clocks>
      <Clock><Triggered/></Clock>
    </Clocks>

Triggered is used because the value of dt is not known during code generation. It should be known due to annotation(Evaluate=true). The correct Clocks section reads (e.g. replace parameter Real dt with constant):

    <Clocks>
      <Clock><Periodic
              baseInterval="0.1"
              /></Clock>
    </Clocks>

Where do I find this information?

in reply to:  description comment:6 by Bernhard Thiele, 9 years ago

Replying to rfranke:
I guess you are experimenting with adding clock features to FMI 2.0 since Clocks and DiscreteStates are not elements of FMI 2.0?

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

Resolution: fixed
Status: acceptedclosed

Super. The change works. 8847a737b601ca36fe2bbe4ff070b8bb8d83e37a/OpenModelica-testsuite updates the respective test.

Find the proposed spec in FCP-001_Clocks:

https://trac.modelica.org/fmi/ticket/353

The originating time events proposal had been under discussion since 2011. FCP-001 simplifies the original proposal (minimal extension to C API, no sub-clocks in the XML description). Moreover it attempts to make the extension forward compatible with FMI 2.0 and it combines time events with discrete states that had been removed shortly before the release of FMI 2.0, lacking test implementations.

By now we have test implementations in the exporting tool OpenModelica (+simCodeTarget=Cpp) and the importing tool HQP, besides the original Dymola test implementation. Hopefully this will bring us forward in the FMI standardization, because we really need such models in our applications.

Modelica was lacking behind other simulation technologies prior to Clocks -- FMI is lacking behind until today.

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

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

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

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.