#3644 closed defect (fixed)
Elimination "reinit" in post-optimization module "simplifyComplexFunction"
Reported by: | Owned by: | Lennart Ochel | |
---|---|---|---|
Priority: | high | Milestone: | 1.9.4 |
Component: | Backend | Version: | |
Keywords: | Cc: |
Description
If one uses the PNlib version 1.2 with the modifikation in the Model PC from
Real disMarkChange "discrete mark change";
an after
discrete Real disMarkChange "discrete mark change";
and the following model
model TDtoPC extends Modelica.Icons.Example; PC P1(nOut = 0, nIn = 1) annotation(Placement(visible = true, transformation(origin = {20, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); PNlib.TD T1(nOut = 1, arcWeightOut={1}) annotation(Placement(visible = true, transformation(origin = {-20, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); inner PNlib.Settings settings1 annotation(Placement(visible = true, transformation(origin = {30, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); equation connect(P1.inTransition[1], T1.outPlaces[1]) annotation(Line(points = {{9.2, 0}, {9.2, 0}, {-15.2, 0}})); annotation(Diagram(coordinateSystem(extent = {{-40, -40}, {40, 40}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), experiment(StartTime = 0.0, StopTime = 10.0)); end TDtoPC;
Then the "reinit" instruction from P1
when {disMarksInOut, reStart} then reinit(t_, if reStart then reStartMarks else t_ + disMarkChange); end when;
is not explained
In the post-optimization module removeSimpleEquations ("optdaedump" on line 20970) is the "reinit" Command the last sometimes available.
Simple Equations (1, 0) ======================================== 1/1 (0): when {$whenCondition5, false} then reinit(P1.t_,P1.t_ + P1.disMarkChange); end when; [dynamic]
In the next module "simplifyComplexFunction" is the "reinit" command eliminatien.
The events are right getriggert at the time
LOG_EVENTS_V | info | check for discrete changes at time=1.0000000002 | | | | | discrete var changed: P1._disMarksInOut from 0 to 1 | | | | | discrete var changed: P1._fireIn[1] from 0 to 1 | | | | | discrete var changed: $whenCondition5 from 0 to 1 | | | | | discrete var changed: $whenCondition3 from 0 to 1 | | | | | discrete var changed: $whenCondition2 from 0 to 1 | | | | | discrete var changed: P1._disMarkChange from 0 to 1
and
LOG_EVENTS_V | info | check for discrete changes at time=1.0000000002 | | | | | discrete var changed: P1._disMarksInOut from 1 to 0 | | | | | discrete var changed: P1._fireIn[1] from 1 to 0 | | | | | discrete var changed: T1._active from 1 to 0 | | | | | discrete var changed: $whenCondition5 from 1 to 0 | | | | | discrete var changed: $whenCondition4 from 1 to 0 | | | | | discrete var changed: $whenCondition3 from 1 to 0 | | | | | discrete var changed: $whenCondition2 from 1 to 0 | | | | | discrete var changed: P1._disMarkChange from 1 to 0
In the Model
model foo Real t_(start=0.0, fixed=true); equation der(t_) = 0.0; when sample(0.0, 0.1) then reinit(t_, t_ + 1.0); end when; end foo;
if is not the problem.
"P1.disMarkChange" is in the Equation ("optdaedump" on line 20949)
18/34 (1): P1.disMarkChange = if P1.disMarksIn.vec[1] then 1.0 else 0.0 [unknown]
In the Model
model foo Real t_(start=0.0, fixed=true); Real disMarkChange; Boolean disMarksIn[2]={true,false} ; equation der(t_) = 0.0; disMarkChange = if disMarksIn[1] then 1.0 else 0.0 ; when sample(0.0, 0.1) then reinit(t_, t_ + disMarkChange); end when; end foo;
if also not the problem.
"P1.disMarksIn.vec[1]" is in the Equations ("optdaedump" line 20934 to 20963)
14/29 (1): P1.disMarksIn.vec[1] = PNlib.Functions.OddsAndEnds.allTrue({P1.enableIn.TEin_[1]}) [binding] 15/30 (1): ({P1.inTransition[1].decreasingFactor}, _) = PNlib.Functions.decreasingFactor(1, 0, P1.t_, P1.minMarks, P1.maxMarks, 0.0, 0.0, {0.0}, {}, {0.0}, {}, {1.0}, {}, {P1.disMarksIn.vec[1]} and not {true}, {} and not {}) [dynamic] 18/34 (1): P1.disMarkChange = if P1.disMarksIn.vec[1] then 1.0 else 0.0 [unknown] 19/35 (1): P1.disMarksIn.vec[1] = $whenCondition3 [dynamic] 28/44 (1): P1.fireIn[1] = P1.disMarksIn.vec[1] [binding]
Thanks for Help.
Change History (5)
comment:1 by , 9 years ago
Milestone: | Future → 1.9.4 |
---|---|
Status: | new → accepted |
comment:2 by , 9 years ago
I fixed the issue with PR378.
The reinit statement only got removed if it is in an equation system that also contains ‚complex function calls‘. That’s the reason why your minimal model doesn’t cover the issue. Maybe we could use the following model as test case:
model foo function goo input Real t; output Real a, b; algorithm a := sin(t); b := t * cos(a); end goo; Real x, y, z; equation z = -x; (x, y) = goo(time*time); when sample(0.1, 0.1) then reinit(x, pre(x) + 0.1); end when; end foo;
comment:3 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
Thanks for this ticket. As you already pointed out, reinit statements get removed in some cases from the equation system. I fixed it already (locally) and will provide a pull request soon.