Task:
- I have a variable
y1
whose derivative is driven by some law
e.g.y1 = sin(time)
and for which I set the starting value
e.g.y1 = 3.0
- I have a second variable
y2
that is defined byy2 = y1 + offset
- Now, I want this offset to be a
Parameter
(thus constant during the simulation) and to be evaluated based on starting/initial values ofy1
andy2
likeoffset = y2.start - y1.start
Code
Conceptually I want to achieve:
model SetParametersFromInitialValues
Real y1(start = 3.0, fixed = true);
Real y2(start = 3.0, fixed = true);
parameter Real offset(fixed = false);
initial equation
offset = y2.start - y1.start;
equation
der(y1) = sin(time);
y2 = y1 + offset;
end SetParametersFromInitialValues;
and I thought it could work since start
should be a parameter attribute of the built-in type Real, but it is not usable in this way.
I thought also of using a discrete
instead of parameter
, but I don't know if this will affect the performance.
However, even in this case, I get some dangerous warning (because of an algebraic loop), namely "It was not possible to check the given initialization system for consistency symbolically, because the relevant equations are part of an algebraic loop. This is not supported yet."
model SetParametersFromInitialValues
Real y1(start = 3.0, fixed = true);
discrete Real offset(fixed = false);
Real y2(start = 5.0, fixed = true);
equation
when initial() then
offset = y2 - y1;
end when;
der(y1) = sin(time);
y2 = y1 + offset;
end SetParametersFromInitialValues;
Questions:
- is there a way to achieve what I want with
Parameter
? Am I forced to use some more 'variable' variable? - are
fixed
attributes required? What ify1
andy2
values arefixed
from other components? and what if they are not?
(please mind that I thinks it's different from Define Model Parameter as Variable since I need to evaluate parameters based specifically on initial values)
initial algorithm
instead ofinitial equation
so to help the symbolic manipulation. Unfortunately, even in this case, you will get a warning about "over-specified initial conditions". BTW, Dymola resolve the model with rising any issue. – Tideway