Engee Physical Modeling Language Events
|
Page in progress. |
In the Engee physical modeling language, events are used to describe sudden changes in the state of a system over time, such as mode switches, constraint triggers, or transitions between states.
Conditional constructions
To write conditional equations, depending on the values of variables, the functions are used ifelse(…) and gt, lt, ge, le, eq, neq.
For a detailed description with examples and features of the work, see the article Enumerations, branches, loops, and modules of the Engee Physics Modeling language.
Discrete events
The construction is used to describe discrete events that are triggered when conditions change. @when. It allows you to specify the actions to be performed at the time of switching logical expressions.
The conditions use the operator edge. The following condition entries are allowed:
-
edge(cond)— the event is triggered when the condition changescondwithfalseontrue. -
edge(!cond)— the event is triggered when the condition changescondwithtrueonfalse. -
edge(cond1) & edge(cond2)— the event is triggered when there is a simultaneous changecond1andcond2withfalseontrue. -
edge(cond1) & cond2— the event is triggered when the change is madecond1withfalseontrueand fulfilling the conditioncond2. -
edge(cond1) | edge(cond2)— the event is triggered when the condition changescond1orcond2withfalseontrue.
Combinations of them are also possible.: (edge(cond1) & edge(cond2)) | edge(cond3).
@when edge(x > 3) begin
event_var1 ~ expr1
event_var2 ~ expr2
end
Assignments that occur simultaneously when the condition is met are specified inside the block. In each assignment, only the event value should be specified in the left part (event=true) a variable.
Previous values of the same event variables can be used in assignments.:
@when (x > 3) begin
event_var1 ~ event_var1 + 1
end
Additionally, you can specify other conditions using @elsewhen. If several conditions start to be fulfilled at the same time, the event corresponding to the first of them will be triggered.
@when edge(x > 1) begin
event_var1 ~ expr1
...
@elsewhen edge(y < 0)
event_var2 ~ expr2
...
end
You can initialize event variables using the identifier initialevent:
@when initialevent begin
V ~ x + 3
@elsewhen edge(z > 0.9)
V ~ 1
end
An example of a component using discrete events:
@engeemodel example begin
@outputs begin
out = 0
end
@variables begin
x = 0
end
@equations begin
der(x) ~ K
out.u ~ x
end
@variables [event = true] begin
K = 1
V = 2
end
@when edge(x > 1) begin
K ~ 12
end
@when edge(t >= 1.5) begin
V ~ 5
@elsewhen edge(K > 3)
V ~ 12
end
end
At the moment when x intersects the value of 1 from bottom to top, variable K The value will be set to 12.
At once V The value will be set to 12. At the moment t == 1.5 variable V it will become equal to 5.
Hybrid automata
Hybrid vending machines (@modecharts) is an extension of the concept finite automata. Like finite automata, they contain discrete states and transitions between them, but at the same time, their own continuous differential equations are solved in each state.
Construction @modecharts can be used inside physical component along with other structures (@variables, @equations and so on).
|
Thus, a hybrid automaton combines discrete logic and continuous physical dynamics: when the state changes, the solver is reinitialized and the system begins to be calculated using a new system of equations.
Construction @modecharts sets hybrid automata and enables:
-
@modechart— hybrid vending machine announcement; -
@modes— a set of modes (states); -
@mode— a separate mode containing its own equations@equations; -
@transitions— rules for the transition between states.
Additionally:
-
@entry— sets actions when entering the mode; -
@initial— defines the initial mode (if not specified, the machine initializes in the first mode in the list).
All parameters in the conditions @initial must be wrapped in default(). Use variables and port parameters in @initial cannot.
An example of a hybrid vending machine
@parameters begin
x0 = 0.5
lower_bnd = 0.0
upper_bnd = 1.0
threshhold = 0.01
e = 0.7
end
@variables begin
x = x0, [priority = "high"]
v = 0.0
F = 0.0
v_old = 0, [event=true]
end
@nodes begin
flange = EngeePhysicalFoundation.Mechanical.Translational.Flange
end
@equations begin
v ~ flange.v
der(x) ~ v
end
@branches begin
F:(flange.F,*)
end
@modecharts begin
m = @modechart begin
@modes begin
@mode FREE begin
@equations begin
F ~ 0
end
end
@mode (IMPACT, BIG_IMPACT) begin
@entry begin
v_old ~ v
end
@equations begin
v ~ -e * v_old
end
end
end
@transitions begin
(FREE, IMPACT, FREE) => x <= lower_bnd
(FREE, IMPACT, FREE) => x >= upper_bnd
end
@initial begin
BIG_IMPACT => (default(x0) < (default(lower_bnd) - default(threshhold))) ||
(default(x0) > (default(upper_bnd) + default(threshhold)))
# if this condition is met, the machine starts from the BIG_IMPACT state
end
end
# m2 = ...
end
Here:
-
In the block
@modechartsA hybrid automaton is being createdm, describing discrete modes of behavior. -
In the mode
FREEthe equation is fulfilledF ~ 0— powerFit is equal to zero. -
In composite mode
(IMPACT, BIG_IMPACT):-
In
@entryWhen entering, the previous speed value is stored.v_old ~ v. -
In
@equationsa new speed value is being setv ~ -e * v_old, that is , the velocity changes sign and is scaled by a factore.
-
-
In
@transitionsthe rules of transitions are defined:-
(FREE, IMPACT, FREE) ⇒ x ⇐ lower_bnd— when decreasingxbelowlower_bnda transition is underway toIMPACT, then return toFREE. -
(FREE, IMPACT, FREE) ⇒ x >= upper_bnd— similarly, when exceedingupper_bnd.
-
-
In
@initialthe condition for starting from the state is setBIG_IMPACTif the initial value isxgoes beyondlower_bndorupper_bndtaking into accountthreshhold. -
m2 = …shows that you can add a second one.@modechartin the same physical component.
Practical recommendations
-
If transitions don’t work as expected, reduce the Maximum step size, Absolute tolerance and Relative tolerance parameters in the block. Solver Configuration.
-
The order of declaring constructions
@whenand@modechartIn the component’s code, it can influence the behavior of the component in event chains, despite the general declarativeness of the physical modeling language.