Can you explain what behavior you want?
The 1st equation,
when Period==1 then
p = pre(p) * ( T / pre(T)) ^( Gamma/(Gamma-1));
works on its own, but the 2nd equation above for p will only be active when Period becomes 0, 2, or 3. That is just a single point in time, so I cannot understand what der(p) should be in that right-hand-side.
Additionally if an equation involves both p
and der(p)
the equation is normally solved to compute der(p)
based on p
, but I'm not sure if that is the goal here.
Added:
Your comments seem to indicate that you want the equation to be valid while Period gets a new value and not only when at an instance. In Modelica when
for equations that only should be valid once when the condition becomes true, and if
is for equations that are valid while the condition is true.
That would lead to something like:
if Period==1 then
...
else
p = ( m*R_gas*der(T)+m*T*der(R_gas)+R_gas*T*der(m)-V*der(p) ) / der(V);
end if;
However, the first equation is problematic in that case. I guess you want x=T^(Gamma/(Gamma-1))/p
to remain constant in that part, and unfortunately writing that directly would lead to changing index which is currently not supported in Modelica.
However, an alternative is to say that it has zero derivative, and that would give something like:
x=T^(Gamma/(Gamma-1))/p;
if Period==1 then
der(x)=0;
else
p = ( m*R_gas*der(T)+m*T*der(R_gas)+R_gas*T*der(m)-V*der(p) ) / der(V);
end if;
But it is not certain that it will work, as I haven't seen the entire model.