Mix Tank

Makes a mix of fluids coming in from up to five different sources, optionally delays (e.g. processes) the completed mix for a given amount of time, and lets it flow out. The proportion of components in the mix can be defined either by giving the amount of each component, or by providing the total amount and fractions of components. The input rates are not limited, the output rate can optionally be limited. The new mix will start to accumulate only when the previous mix has completely flowed out. Initially the tank is empty.

The batch of the mix can be explicitly specified or can be left as default batch.

The MixTank block allows you to specify actions executed when the mix is completed (all components has completely flowed in), when the delay is finished and when the mix has completely flowed out.

Demo model: MixTank

Parameters

Mix by
Defines how the mix is specified:
By amounts - the user specifies amounts for each component (each input port)
By fractions - the user specifies the total amount and fractions for each component (port). Fractions are normalized.
Syntax: boolean mixByAmounts
Set new value at runtime: set_mixByAmounts(new value)
Valid values: true - By amounts
           false - By fractions
Capacity (total amount) [dynamic]
[Visible and applies only if the Fractions option is set] The total amount of mix. 
Syntax: double totalAmount
Set new value at runtime: set_totalAmount(new value)
Amount 1
[Visible and applies only if the Amounts option is set] The amount of component 1 (fluid that flows in through port in1). 
Syntax: double amount1
Set new value at runtime: set_amount1(new value)
Amount 2
[Visible and applies only if the Amounts option is set] The amount of component 2 (fluid that flows in through port in2). 
Syntax: double amount2
Set new value at runtime: set_amount2(new value)
Amount 3
[Visible and applies only if the Amounts option is set] The amount of component 3 (fluid that flows in through port in3). 
Syntax: double amount3
Set new value at runtime: set_amount3(new value)
Amount 4
[Visible and applies only if the Amounts option is set] The amount of component 4 (fluid that flows in through port in4). 
Syntax: double amount4
Set new value at runtime: set_amount4(new value)
Amount 5
[Visible and applies only if the Amounts option is set] The amount of component 5 (fluid that flows in through port in5). 
Syntax: double amount5
Set new value at runtime: set_amount5(new value)
Fraction 1
[Visible and applies only if the Fractions option is set] The relative fraction of component 1 (fluid that flows in through port in1). 
Syntax: double fraction1
Set new value at runtime: set_fraction1(new value)
Fraction 2
[Visible and applies only if the Fractions option is set] The relative fraction of component 2 (fluid that flows in through port in2). 
Syntax: double fraction2
Set new value at runtime: set_fraction2(new value)
Fraction 3
[Visible and applies only if the Fractions option is set] The relative fraction of component 3 (fluid that flows in through port in3). 
Syntax: double fraction3
Set new value at runtime: set_fraction3(new value)
Fraction 4
[Visible and applies only if the Fractions option is set] The relative fraction of component 4 (fluid that flows in through port in4). 
Syntax: double fraction4
Set new value at runtime: set_fraction4(new value)
Fraction 5
[Visible and applies only if the Fractions option is set] The relative fraction of component 5 (fluid that flows in through port in5). 
Syntax: double fraction5
Set new value at runtime: set_fraction5(new value)
Delay time
The time the mix must stay in the tank after it is completed (after all components have completely flowed in) and before it can start flowing out.
Syntax: double delayTime
Set new value at runtime: set_delayTime(new value)
Limited output rate
If the option is selected (true), you are able to specify a custom upper limit of the tank outflow rate.
Syntax: boolean limitRateOut
Set new value at runtime: set_limitRateOut(new value)
Maximum output rate
[Visible and applies only if the Limited output rate option is set] Custom upper limit of the tank outflow rate. The default value is 1 cubic meter per second.
Syntax: double maxRateOut
Set new value at runtime: set_maxRateOut(new value)
Output batch is
Defines the output batch of the tank. One of the following:
Default - the output batch is set to the default batch BatchTypes.DEFAULT_BATCH
Custom - the output batch is defined by the Output batch parameter below.
Get value: modeOutputBatch
Set new value at runtime: set_modeOutputBatch(new value)
Valid values: ProcessTank.OUTPUT_BATCH_DEFAULT  -  Default
                     ProcessTank.OUTPUT_BATCH_CUSTOM  - Custom
Output batch [dynamic]
[Visible and applies only if the Output batch is: Custom] Defines the batch of the mix (output batch). The output batch can be evaluated based on the input batches.
Type of value: Object
Local variables:  Object batch1 - the batch that flowed in through port in1
              Object batch2 - the batch that flowed in through port in2
              Object batch3 - the batch that flowed in through port in3
              Object batch4 - the batch that flowed in through port in4
              Object batch5 - the batch that flowed in through port in5
Custom batch color
[Visible and applies only if the Custom option is set] If set, the batch color is defined by the Batch color parameter, otherwise the standard color mapping applies.
Syntax: boolean customOutputBatchColor
Set new value at runtime: set_customOutputBatchColor(new value)
Batch color [dynamic]
[Visible and applies only if the Custom batch color option is set] Defines the color of the output batch.
Type of value: Color
Local variable:  Object batch - the batch
Animation
Storage tank
Here you specify the space markup element Storage Tank that is used to animate this process tank.
Syntax: StorageTank storageTank
Set new value at runtime: set_storageTank(new value)
Show batches in flowchart
If set, the block icon will display the current batch color.
Syntax: boolean showBatchesInFlowchart
Set new value at runtime: set_showBatchesInFlowchart(new value)
Actions
On mix completed [code]
Action executed when all components of the mix have completely flowed in.
On mix ready [code]
Action executed when the completed mix has spent the required time in the tank (if any), just before it is allowed to flow out.
On empty [code]
Action executed when the mix has completely flowed out of the tank, just before the new mix is about to start.
On rate change [code]
Action executed when any of the flow rates changes.  The current rates are available as local variables in1rate .. in5rate, and outrate. 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.

Functions

double amount() - Returns the amount of mix currently contained in the tank (the sum of all components).

boolean isEmpty() - Tests if the tank is empty.

boolean isEmptying() - Tests if the mix has been processed, the output is open, all inputs are closed and the tank is still not empty.

boolean isFilling() - Tests if the tank currently being filled, i.e. at least one of the inputs is open, the output is closed and the amount is below the required capacity.

boolean isProcessing() - Tests if the mix is currently being processed, i.e. all the inputs and outputs are closed and the processing delay is being executed. 

double amountPassedIn(int input) - Returns the amount of fluid that has passed through a given input port (1..5).

double amountPassedOut() - Returns the amount of fluid that has passed through the output port of the tank.

double amount(AmountUnits units) - Returns the amount of mix (in given amount units) currently contained in the tank (the sum of all components).

double amountPassedIn(int input, AmountUnits units) - Returns the amount of fluid (in given amount units) that has passed through a given input port (1..5).

double amountPassedOut(AmountUnits units) - Returns the amount of fluid (in given amount units) that has passed through the output port of the tank.

Object getBatch(int index) - Returns the batch with the specified index. Batch with the index 0 is the one at the tank output, batch with the index numberOfBatches()-1 is the last batch closest to the input.

Color getBatchColor(int index) - Returns the color of the batch with the specified index.

double getBatchSize(int index) - Returns the size of the batch with the specified index.

double getBatchSize(int index, AmountUnits units) - Returns the size of the batch (in given amount units) with the specified index.

double updateOutputBatch() - Forces immediate recalculation of the output batch and its color according to the current parameters settings.

double getBatchOffset(int index) - Returns the sum of sizes of all batches under (closer to output) than the batch with a given index. Intended use is custom animation.

int numberOfBatches() - Returns the number of batches currently present in the tank, including possible zero-size batches.

double currentRateIn(int input) - Returns the current flow rate at a given input port (1..5).

double currentRateIn(FlowRateUnits units, int input) - Returns the current flow rate (in given rate units) at a given input port (1..5).

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

double currentRateOut(FlowRateUnits units) - Returns the current flow rate (in given rate units) of fluid that goes out.

double amountOf(int input) - Returns the amount of a particular component currently contained in the tank. The component is identified by the number of input (1..5).

double amountOf(int input, AmountUnits units) - Returns the amount of a particular component (in given amount units) currently contained in the tank. The component is identified by the number of input (1..5).

double remainingTime() - If the mix is currently delayed (being "processed"), returns the remaining delay time in seconds. At other times, returns 0.

double remainingTime(TimeUnits units) - If the mix is currently delayed (being "processed"), returns the remaining delay time in given time units. At other times, returns 0. For example, remainingTime(MINUTE) returns remaining delay time in minutes.

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

Ports

in1, in2, ... , in5
Input ports.
out
The output port.