Download Modeling, Simulation and Control with Modelica 3.0 and Dymola 7
Transcript
Draft, Jan. 21, 2009
7.2 Sampled data systems and initialization
119
The initial vibration of y is no longer present and the computational delay of one sample instant is clearly
shown in variable y_delayed.
A when-clause can be triggered by several conditions that are defined as a vector of conditions of the
form:
when {condition1, condition2, ..., conditionN} then
...
end when;
The semantics is that whenever one of the conditions changes from false to true, the when-clause is activated. The definition in the discrete first order block
when {initial(), sample(0,T)} then
...;
end when;
states that the equations in the when-clause are active both at sample instants and during the initialization
phase. Together with the stationary initialization equation “pre(y) = y” we have therefore a linear system
of equations during initialization to compute the unknowns “y” and “pre(y)”:
y = a*pre(y) + b*u;
pre(y) = y;
that has the solution
y := b*u/(1-a);
pre(y) := y;
This means that the output y remains constant, as long as the input u does not change, because pre(y) is
initialized in such a way that every evaluation of “y = a*pre(y) + b*u” results in pre(y).
7.3
Prioritizing event actions
We will now analyze an often occurring situation, by means of the following example:
// Wrong Modelica model
when h1 > level1 then
openValve = true;
end when;
...
when h2 < level2 then
openValve = false;
end when;
The intention of the modeler is to open a valve when “h1 > level1” and to close the valve when “h2 <
level2”. This definition is problematic, because the value of openValve is not well defined, when both
conditions become true at the same time instant (accidentally or by purpose). Mapping the above whenclauses to instantaneous equations leads to:
c1 = h1 >
c2 = h2 <
openValve
openValve
level1;
level2;
= if edge(c1) then true else pre(openValve);
= if edge(c2) then false else pre(openValve);
It is now clear that we have two equations for one unknown “openValve” and this system of equations does
not have a unique solution. A Modelica translator will therefore report an error. Due to the fundamental property of Modelica that all language elements are mapped to equations and that every model evaluation requires to solve n equations in n unknowns, a Modelica translator can easily detect this type of non-determinism and therefore forces the modeler to resolve this problem by defining an explicit priority of the event actions.
One solution is to rewrite the equations as:
c1 = h1 > level1;