Opened 16 years ago
Last modified 14 years ago
#1092 closed defect (invalid)
Simulation of tank model fails
Reported by: | krsta | Owned by: | krsta |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Version: | ||
Keywords: | Cc: | krsta, |
Description
From: owner-openmodelicainterest@…
owner-openmodelicainterest@… On Behalf Of Vasaiely, Parham
Sent: den 23 mars 2009 14:24
To: OpenModelicaInterest@ida.liu.se
Subject:
Hello OpenModelica users,
we have discovered some behavior of OMC that we didn't expect: When we
simulate the 2 tanks model (OMNotebook chapter 12.1 "Modeling a Tank
System", the part "Object Oriented Component-based (p. 386)" than the last
part "7. Simulation of TanksConnectedPI") from startTime greater than 0 then
OMC (version 1.4.5) doesn't return the results starting form the startTime
but results starting from startTime=0. Here are our commands and resulting
data:
*Note: "numberOfIntervals" is used for integer time steps.
simulate(Demo.TwoTanks.TanksConnectedPI, startTime=0, stopTime=400, numberOfIntervals=400, tolerance=1e-4) plot(tank1.h) T -> tank1.h 0 -> 0 1 -> 0.02 2 -> 0.04 3 -> 0.06 4 -> 0.08 5 -> 0.1 6 -> 0.12 7 -> 0.14 simulate(Demo.TwoTanks.TanksConnectedPI, startTime=5, stopTime=400, numberOfIntervals=395, tolerance=1e-4) plot(tank1.h) T -> tank1.h 5 -> 0 (THIS SHOULD BE 0.1) 6 -> 0.02 (THIS SHOULD BE 0.12) 7 -> 0.04 (THIS SHOULD BE 0.14)
You can see more difference by using a start time grater than 100.
Is it a correct behavior or a bug of the OMC?
Here is the Modelica code for the two tank model:
package TwoTanks model TanksConnectedPI LiquidSource source(flowLevel = 0.02); Tank tank1(area = 1); Tank tank2(area = 1.3); PIcontinuousController piContinuous1(ref = 0.25); PIcontinuousController piContinuous2(ref = 0.4); equation connect(source.qOut,tank1.qIn); connect(tank1.tActuator,piContinuous1.cOut); connect(tank1.tSensor,piContinuous1.cIn); connect(tank1.qOut,tank2.qIn); connect(tank2.tActuator,piContinuous2.cOut); connect(tank2.tSensor,piContinuous2.cIn); end TanksConnectedPI; model Tank ReadSignal tSensor "Connector, sensor reading tank level (m)"; ActSignal tActuator "Connector, actuator controlling input flow"; LiquidFlow qIn "Connector, flow (m3/s) through input valve"; LiquidFlow qOut "Connector, flow (m3/s) through output valve"; parameter Real area(unit = "m2") = 0.5; parameter Real flowGain(unit = "m2/s") = 0.05; parameter Real minV = 0,maxV = 10; Real h(start = 0.0, unit = "m") "Tank level"; equation assert(minV >= 0, "minV - minimum Valve level must be >= 0 "); der(h) = (qIn.lflow - qOut.lflow) / area; qOut.lflow = limitValue(minV, maxV, -flowGain * tActuator.act); tSensor.val = h; end Tank; connector ReadSignal "Reading fluid level" Real val(unit = "m"); end ReadSignal; model PIcontinuousController extends BaseController(K = 2, T = 10); Real x "State variable of continuous PI controller"; equation der(x) = error / T; outCtr = K * (error + x); end PIcontinuousController; model LiquidSource LiquidFlow qOut; parameter Real flowLevel = 0.02; equation qOut.lflow = if time > 150 then 3 * flowLevel else flowLevel; end LiquidSource; connector LiquidFlow "Liquid flow at inlets or outlets" Real lflow(unit = "m3/s"); end LiquidFlow; function limitValue input Real pMin; input Real pMax; input Real p; output Real pLim; algorithm pLim:=if p > pMax then pMax else if p < pMin then pMin else p; end limitValue; partial model BaseController parameter Real Ts(unit = "s") = 0.1 "Time period between discrete samples"; parameter Real K = 2 "Gain"; parameter Real T(unit = "s") = 10 "Time constant"; ReadSignal cIn "Input sensor level, connector"; ActSignal cOut "Control to actuator, connector"; parameter Real ref "Reference level"; Real error "Deviation from reference level"; Real outCtr "Output control signal"; equation error = ref - cIn.val; cOut.act = outCtr; end BaseController; connector ActSignal "Signal to actuator for setting valve position" Real act; end ActSignal; end TwoTanks;
Thanks for your support!
Pharham
Attachments (2)
Change History (4)
comment:1 by , 16 years ago
by , 13 years ago
Attachment: | 10.1.1.58.8788.pdf added |
---|
by , 13 years ago
Attachment: | 10.1.1.58.8788.2.pdf added |
---|
Look at the declaration of {{Tank.h}}:
{{
}}
The {{start = 0.0}} refers to the value at the start of simulation, no matter what the actual value of {{time}} is. Setting the {{startTime}} only affects the value of {{time}} at the start of the simulation, not the starting values of the dependent variables.
I think what is wanted here is a feature for starting the data output after an initial period of discarded results. (The solver can't just jump to a later point in time, after all.)
So I don't think this is a bug.