Valve

Restricts the flow rate or completely blocks the flow. 

Valve has a maximum flow rate, which applies when the valve is open. When the valve is closed, the rate is forced to zero. You can open and close the valve at runtime by calling its open(), close(), and toggle() functions. You can also call the dispense() function to have the valve let through a particular amount and then close. In addition, you can define an arbitrary recurring action execute each time a portion of fluid has flown through the valve.

Valve is a zero-capacity block, it does not contain any amount of fluid.

As any other block the Valve block allows you to react to new batches appearing at the input.

Demo model: Valve

Parameters

Maximum rate when open
If selected, the flow rate through the open valve is not limited. The upper limit then must be set by other blocks up or down the flow.
Syntax: boolean maxOpenRate
Rate when open
[Visible and applies only if the Maximum rate when open option is not set] Maximum flow rate when the valve is open. 
Syntax: double openRate
Set new value at runtime: set_openRate(new value)
Initially closed
Defines the initial state of the valve, and later on can be used to change the state.
Syntax: boolean closed
Animation
Show batches in flowchart
If set, the block icon will display the current batch color.
Syntax: boolean showBatchesInFlowchart
Actions
Recurrent action on portion
If selected, you can specify the recurrent action to be executed each time a particular amount of fluid flows through the valve.
Syntax:
 boolean actionOnPortion
Portion size
[Visible and applies only if the Recurrent action on portion option is set] The amount of fluid for the Recurrent action on portion.
Syntax: double portionSize
On portion passed [code]
[Visible and applies only if the Recurrent action on portion option is set] Action executed each time the amount specified in the Portion size parameter passes through the valve. Do not confuse it with the On dispense completed action.
Portion counting does not stop when dispense() is called.
Local variable: double amount - the portion size
On dispense completed [code]
Action executed when dispensing a given amount (initiated by the call of dispense() function) is completed. Do not confuse it with the On portion passed action.
Local variable: double amount - the dispensed amount
On new batch [code]
Action executed when a new batch appears at the valve input. It will not necessarily start flowing into the valve. You can, for example, close or open the valve output in this action.
Local variable: Object batch - the batch
On rate change [code]
Action executed when the flow rate changes. Please note that changing something in the action may result in another immediate rate change and immediately following another call of On rate change, so the user can possibly create a livelock.
Local variable:  double rate - the current rate

Functions

double amountPassed() - Returns the total amount passed through the valve since the start of the simulation.

double amountPassed(AmountUnits units) - Returns the total amount (in given units) passed through the valve since the start of the simulation.

double currentRate() - Returns the current flow rate of fluid that goes out.

double currentRate(FlowRateUnits units) - Returns the current flow rate (in given units) of fluid through the valve.

double averageRate() - Returns the average actual rate through the valve throughout the total operating time. If time has ran to infinity, the current input rate is returned.

double averageRate(FlowRateUnits units) - Returns the average actual rate (in given units) through valve throughout the total operating time in given units. If time has ran to infinity, the current input rate is returned.

boolean isClosed() - Tests if the valve is currently closed. Returns true if the valve is closed, and false otherwise.

open() - Opens the valve. Sets the maximum rate to the Rate when open parameter.

close() - Closes the valve (sets the maximum rate to zero).

toggle() - Toggles the state of the valve between open and closed. If the valve is currently closed, calling this function opens it, and vice versa.

double dispense(double amount) - Opens the valve if it is closed, lets the specified amount to pass through, and then closes the valve. If Recurrent action on portion is set, On portion dispensed action is executed at the moment when the specified amount passes through, and before the valve is closed again.

double dispense(double amount, AmountUnits units) - Opens the valve if it is Initially closed, lets the specified amount (in given units) to flow through, and then closes the valve and calls On dispense completed action.

double amountDispensedSoFar() - When dispensing is in progress after a call of dispense(), returns the amount dispensed so far (in given units if specified). At other times, returns 0.

double amountDispensedSoFar(AmountUnits units) - When dispensing is in progress after a cal of dispense(), returns the amount (in given units) dispensed so far. At other times, returns 0.

double amountPassedInPortion() - When Recurrent action on portion is set, returns the amount passed through the valve in the current portion; this amount is less than the Portion size. If the action is not set, returns 0.

double amountPassedInPortion(AmountUnits units) - When Recurrent action on portion is set, returns the amount (in given units) passed through the valve within the current portion; this amount is less than the Portion size. If the action is not set, returns 0.

double utilization() - Returns the currently utilized fraction of the valve bandwidth, namely the current rate / maximum open rate. If the valve is Initially closed, the current maximum rate equals 0 or is not limited, returns 0.

double utilizationTotal() - Returns the average utilization of the valve bandwidth throughout the total operating time, i.e. the total amount of fluid that actually passed through the valve / maximum total amount that could pass through, given the (possibly changing) open rate and closing times. If time has ran to infinity, the instant utilization is returned. If the open rate has been set to unlimited even once, the function will return 0.

void resetStats() - Resets statistics collected for this block, including the statistics collected for its ports.

Ports

in
The input port.
out
The output port.