﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3644	"Elimination ""reinit"" in post-optimization module ""simplifyComplexFunction"""	timo.lask@…	Lennart Ochel	"If one uses the PNlib version 1.2 with the modifikation in the Model PC from 
{{{#!mo
Real disMarkChange ""discrete mark change"";
}}}
an after 
{{{#!mo
discrete Real disMarkChange ""discrete mark change"";
}}}
and the following model

{{{#!mo
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 
{{{#!mo
 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.

{{{#!mo
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
{{{#!mo
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
{{{#!mo
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
{{{#!mo
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)
{{{#!mo
18/34 (1): P1.disMarkChange = if P1.disMarksIn.vec[1] then 1.0 else 0.0   [unknown]
}}}
In the Model
{{{#!mo
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)
{{{#!mo
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."	defect	closed	high	1.9.4	Backend		fixed		
