- Index
- » Developer
- » OpenModelica development
- » Accessing instant values of a variable
Accessing instant values of a variable
Accessing instant values of a variable
Hello,
I'm working with Modelica since April and for attend my goals, I need to get a values of a variable in certain instant of time.
For exemple, I created a model with 3 inputs (Temperature-0,Temperature-1,Temperature-2 ).
I want to test:
(Temperature-1 - Temperature-0) > 20°C during 20s,if true, I want to set un error message.
Temperatura-3 > 60°C during 10s, if true, I want to set un error message.
So, The only way, I thought to do, is get a values of a variable in certain instant of time and do the tests.
Thank you
Re: Accessing instant values of a variable
You can just use when. For example:
Code:
Boolean error_message;
Real Temperature-1;
Real Temperature-0;
equation
when time > 20.0 and time < 20.1 and (Temperature-1 - Temperature-0) > 20 then
error_message=true;
end when;
- dersh
- 66 Posts
Re: Accessing instant values of a variable
Thank your for the answer, but I do not undestand how a when-statement can resolve my problem.
The condition (Temperature-1 - Temperature-2 > 20°C) can happen, but it can't be true for more than 20 seconds.
So, this condition can happen in instant of time (30 seconds, for exemple), but it can't stay true until 51 seconds.
Thank you
Re: Accessing instant values of a variable
You can do something like this:
Code:
model M
Real t1=15,t2=if time < 20 then -time else (if time < 21 then time else -time),td=t1-t2;
Real timer(start=20);
Boolean timerEnabled;
equation
der(timer) = if timerEnabled then -1.0 else 0.0;
assert(timer > 0.0 or not timerEnabled, "...");
when td > 20 then
timerEnabled = true;
reinit(timer, 20);
elsewhen td < 20 then
timerEnabled = false;
end when;
end M;
- sjoelund.se
- 1700 Posts
- Index
- » Developer
- » OpenModelica development
- » Accessing instant values of a variable