Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Time not updating inside when loop

Time not updating inside when loop

Hi all,

I'm currently trying to figure out how to deal with jumps/discontinuities and maintaining a finite derivative in Modelica. My plan of attack was therefore to convert these jumps into ramp functions, and then apply the smooth function to these ramps. I've got a simplified model of what I want to do below, however what I really don't understand is why the first when statement at 5<time<7 returns P=0? From my understanding, the expression should return a ramp expression, but it only returns 0. Then at 7<time there is jump so that P = PowerGen. What am I doing wrong?  I'm fairly new to the language, so please forgive me if my question is trivial.

Hope to hear from you soon!

model SmoothPowerGenerator
  import SI = Modelica.SIunits;
  SI.Power P(start=0);
  SI.Time EventTime "Start of each event";
  parameter SI.Time EventDuration = 2 "Duration of the transient state";
  parameter SI.Power PowerGen = 3;
  output SI.Energy E;
equation
  der(E) = P;
  when (5 < time and time < 7) then
    EventTime = pre(time);
    P = PowerGen * (time-EventTime)/EventDuration;
  elsewhen (7<time) then
    EventTime = pre(time);
    P = PowerGen;
  end when;
end SmoothPowerGenerator;

Re: Time not updating inside when loop

try using If instead of when. When is a event trigger(edge) and is triggers only at the instant the event turns true.

There are 0 guests and 0 other users also viewing this topic
You are here: