Java Reference
In-Depth Information
double
qb
#
color[2]*level/(color[0]
!
color[1]
!
color[2]);
// quantity of paint received from the pump for each
// tonality
double
tqr
#
c[0] * microVol / (c[0]
!
c[1]
!
c[2]);
double
tqg
#
c[1] * microVol / (c[0]
!
c[1]
!
c[2]);
double
tqb
#
c[2] * microVol / (c[0]
!
c[1]
!
c[2]);
// the resulting tonality of the mixed paint
double
maxColor
#
Math.max( qr
!
tqr,qg
!
tqg );
maxColor
#
Math.max(maxColor,qb
!
tqb);
color[0]
#
255 * (qr
!
tqr) / maxColor;
color[1]
#
255 * (qg
!
tqg) / maxColor;
color[2]
#
255 * (qb
!
tqb) / maxColor;
}
level
!#
microVol;
}
// the pull method updates the current paint level in the
// tank
public void
pull(
int
microVol) { level -
#
microVol; }
}
Class
Pump
simulates the behaviour of a pump. It exports three methods:
public void setOutputFlow(int percent)
sets the pump output flow.
■
public int getOutputFlow()
gets the current pump output flow.
■
void flush(int DT)
transfers a micro-volume of paint from the upstream
tank to the downstream tank. The micro-volume is proportional to the
pump's current output flow and to the time interval DT. The micro-
volume is equal or less than the current volume in the upstream tank and
the residue volume in the downstream tank. This constraint ensures that
the pump never flushes paint from an empty tank or into a full tank.
■
package
scada.simulator;
public class
Pump {
private
Tank upstreamTank
#
null;
// reference to the upstream tank
private
Tank downstreamTank
#
null;
// referece to the downstream tank
private int
MAXFLOW
#
10000;
// max output flow (millilitres/second)
private int
outputFlow
#
0;
// current output flow (millilitres/second)
public
Pump(Tank upstream, Tank downstream) {
upstreamTank
#
upstream; downstreamTank
#
downstream;
}
// this method opens the pump's valve
public void
setOutputFlow(
int
percent) {
outputFlow
#
MAXFLOW / 100 * percent;
}