Consider the following model:
model min_ex
Real x(start = 3);
Real z(start = 0);
Real t;
Boolean b;
discrete Real output_state(start = 0);
equation
b = x < 2;
x + t + z = 3;
if b then
t = 2*time;
else
t = time;
end if;
if x < 1.9 then
z = 1;
else
z = 0;
end if;
when b then
output_state = x;
end when;
end min_ex;
- Initial solution for
x is 3, and decreases as time increases as per t = time.
- At
time = 1 (x = 2), there will be an event:
- first:
b becomes true => t becomes 2, new solution: x = 1
- second:
x < 1.9 becomes false => z becomes 1, new solution: x = 0
- Note: This example can be expanded to make this an
N step process.
- The when construct is to capture the value of
x with the change in b (which was also the intention of the modeller), but what is the expected value?
1 as the value of the iteration when b first becomes true?
0 as the final value after the value for x has been fully resolved? (which was what the modeller expected)
- Something else?
- The modeler expected this value to be
0 in this reproducer
- The example can simplified by replacing the use of
b with x < 2. This gives fewer dependencies, while effectively being the same model.
What should be the correct solution here and more importantly: why?
Disclaimer: OCT currently yields output_state = 1 for this model. We suspect this is not the correct result, but it is not evident to us from the specification.
Specification for pre()
Chapter 3 Operators and Expressions ‣ Modelica® Language Specification version 3.7 states a lot of things, but it is still not quite clear:
- What does “mask event iteration“ mean to begin with?
- Is this type of example the non-normative text refers to with “global fix point iteration scheme, similarly to the event iteration“?
- I.e., a fixed point iteration that resolves the chain of “if” evaluations required to compute “x“, before evaluating the when block for the first time.
Edit: fixed mistake pointed out in comment.
Consider the following model:
xis3, and decreases as time increases as pert = time.time = 1 (x = 2), there will be an event:bbecomestrue=>tbecomes2, new solution:x = 1x < 1.9becomesfalse=>zbecomes1, new solution:x = 0Nstep process.xwith the change inb(which was also the intention of the modeller), but what is the expected value?1as the value of the iteration whenbfirst becomestrue?0as the final value after the value forxhas been fully resolved? (which was what the modeller expected)0in this reproducerbwithx < 2. This gives fewer dependencies, while effectively being the same model.What should be the correct solution here and more importantly: why?
Disclaimer: OCT currently yields
output_state = 1for this model. We suspect this is not the correct result, but it is not evident to us from the specification.Specification for pre()
Chapter 3 Operators and Expressions ‣ Modelica® Language Specification version 3.7 states a lot of things, but it is still not quite clear:
Edit: fixed mistake pointed out in comment.