Reputation: 666
Is there a way to get the maximum value from a CombiTimeTable (tableOnFile==true) and use it as a parameter?
I want to be able to use the max value in an equation without the need to set the Max Value for each component. Thinking about how others have handled this I'm pretty sure it's not possible, but should be in my opinion.
The Time table Docs doesn't have any indication that what I'd like to do is possible, but maybe someone has an idea how to handle this without setting a parameter for the max value.
Upvotes: 0
Views: 114
Reputation: 12507
There is support for min/max of times, but for x-values I guess you would need to write something like:
block CombiTimeTableWithMax
import Modelica.Blocks.Tables.Internal;
extends Modelica.Blocks.Sources.CombiTimeTable;
// The min/max for time are t_minScaled etc
final parameter Real xMin[nout](each fixed=false),xMax[nout](each fixed=false);
function getMinMax
input Modelica.Blocks.Types.ExternalCombiTimeTable tableID;
input Integer nout;
input Real p_offset[nout];
output Real xMin[nout],xMax[nout];
protected
Real t;
Real x[nout];
algorithm
t:=Internal.getTimeTableTmin(tableID);
x:=p_offset+Internal.getTimeTableValue(tableID, 1:nout, t, t, t);
xMin:=x;
xMax:=x;
while t<Internal.getTimeTableTmax(tableID) loop
t:=Internal.getNextTimeEvent(tableID, t);
x:=p_offset+Internal.getTimeTableValue(tableID, 1:nout, t, t, t);
for i in 1:nout loop
if x[i]<xMin[i] then xMin[i]:=x[i]; end if;
if x[i]>xMax[i] then xMax[i]:=x[i]; end if;
end for;
end while;
end getMinMax;
initial equation
(xMin,xMax)=getMinMax(tableID, nout, p_offset);
annotation (uses(Modelica(version="4.0.0")));
end CombiTimeTableWithMax;
Upvotes: 1