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

reset continuous increasing variable and continue the increase

reset continuous increasing variable and continue the increase

Hey, im just starting with OM and i think my problem is really basic, but anyway i don't find a solution, here it is:

I have a diameter that should be increased continous and after reaching a specific diameter it should be set to the beginning value, but the increasing should continue after this. So it should be like:

0:  0.1
1:  0.2
2:  0.3
3:  0.1 <- reset point
4:  0.2

My Code looks like this

Code:


if s>s_max then
     s= s_0;
  else
     der(s)= + v_grow;
  end if;

where v_grow is the growing speed in m/s, s the diameter and s_0 the diameter for reset and start.

The Problem is, that if when s>s_max is reached, modelica tries to calculate the der(s) term anyway and runs into an error. But i don't know why....

Edited by: dave1990 - May-17-17 13:12:39

Re: reset continuous increasing variable and continue the increase

I am guessing you want a saw-tooth wave form. I suggest a use of when for such event trigger situations.

Try this:

Code:


model ResetVariable
Real s;
Real v_grow = 2;
parameter Real s_0 = 0;
parameter Real s_max = 10;

initial equation
s = s_0;

equation

der(s) = v_grow;

when s>s_max then
     reinit(s, s_0);
  end when;
end ResetVariable;

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