Fluid Merge


Merges two streams of flow into one; the output flow rate equals the sum of the input rates. 

Can work in three modes:

FluidMerge is a zero-capacity block, it does not contain any amount.

The output batch of FluidMerge may be the same as the one at the chosen input, same as at the priority input, default, or custom. The latter option is useful when, for example, the block models mixing of two different substances that results in creating the third one. The On new batch … actions can be used to change the mode and/or priorities depending on the input batches.

Demo model: FluidMerge

Parameters

Mode
The mode of merge. One of the following:
Neutral - neither of the inputs gets priority
Proportional – input rates must obey the proportion rules
Priority – one of the inputs has priority over another
Get value: mode
Set new value at runtime: set_mode(new value)
Valid values: FluidMerge.SPLITMERGE_NEUTRALFluidMerge.SPLITMERGE_PROPORTIONALFluidMerge.SPLITMERGE_PRIORITY
Fraction 1
[Visible and applies only if the Mode is Proportional] In proportion mode, the (relative) fraction of input 1 rate. If the user dynamically changes the parameter value, the output batch is updated according to the current parameters settings.
Syntax: double fraction1
Set new value at runtime: set_fraction1(new value) 
Fraction 2
[Visible and applies only if the Mode is Proportional] In proportion mode, the (relative) fraction of input 2 rate. If the user dynamically changes the parameter value, the output batch is updated according to the current parameters settings.
Syntax: double fraction2
Set new value at runtime: set_fraction2(new value) 
Custom priorities
[Visible and applies only if the Mode is Priority] If the option is selected (the value is equal to true), the priorities of inflows will be set to custom values, otherwise – to 0 and 1. Priorities affects the LP solver when it tries to maximize the flow through the system.
Syntax: boolean customPriorities
Change the value at runtime: set_customPriorities(true or false)
Priority
[Visible and applies only if the Mode is Priority and the Custom properties option is not set] Applies in priority mode with default (non-custom) priorities. If the Input 1 option is selected (the value is equal to true), input 1 has priority over input 2, otherwise Input 2 has the priority. This results in priority values 1 and 0. 
Syntax: boolean priorityInput1
Change the value at runtime: set_priorityInput1(true or false)
Priority of input 1
[Visible and applies only if the Mode is Priority and the Custom properties option is set] Applies in the priority mode with custom priorities. Defines the priority of the input 1 flow of this block in the overall flowchart. Must be a nonnegative integer.
Syntax: int priorityInput1Custom
Change the value at runtime: set_priorityInput1Custom(new value
Priority of input 2
[Visible and applies only if the Mode is Priority and the Custom properties option is set] Applies in the priority mode with custom priorities. Defines the priority of the input 2 flow of this block in the overall flowchart. Must be a nonnegative integer.
Syntax: int priorityInput2Custom
Change the value at runtime: set_priorityInput2Custom(new value
Output batch is
Defines how the output batch of this block is formed. One of the following:
Same as at input 1 – same is the batch at input 1
Same as at input 2 – same is the batch at input 2
Same as at priority input – same is the batch at the priority input (priority mode only)
Default – set to default batch
Custom – defined by the Output batch parameter below
Get value: modeBatch
Set new value at runtime: set_modeBatch(new value) 
Valid values: FluidMerge.OUTPUT_BATCH_IN1; FluidMerge.OUTPUT_BATCH_IN2; FluidMerge.OUTPUT_BATCH_PRIORITY; FluidMerge.OUTPUT_BATCH_DEFAULT; FluidMerge.OUTPUT_BATCH_CUSTOM
Output batch [dynamic]
[Visible and applies only if the Output batch is: Custom] Defines the batch to be created at the output, which may depend on the input batches.
Type of the value: Object
Local variables: Object batch1 - the batch at input 1
                          Object batch2 - the batch at input 2
Custom batch color
[Visible and applies only if the Output batch is: Custom] If set, the output batch color is defined by the Batch color parameter below, otherwise the standard color mapping applies.
Syntax: boolean customBatchColor
Set new value at runtime: set_customBatchColor(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 the value:  Color
Local variable: Object batch - the output batch
Limited output rate
If the option is selected (the value is equal to true), you are able to specify a custom upper limit of the output rate.
Syntax: boolean limitRateOut
Change the value at runtime: set_limitRateOut(true or false
Maximum output rate
[Visible and applies only if the Limited output rate option is set] Custom upper limit of the output rate. The default value is 10 cubic meters per second.
Syntax: double maxRateOut
Set new value at runtime: set_maxRateOut(new value)
Animation
Show batches in flowchart
If set, the block icon will display the current batch color.
Syntax: boolean showBatchesInFlowchart
Actions
On new batch at input 1 [code]
Action executed when a new batch appears at the input 1. It will not necessarily start flowing into the block. 
Local variable: Object batch - the batch
On new batch at input 2 [code]
Action executed when a new batch appears at the input 2. It will not necessarily start flowing into the block. 
Local variable: Object batch - the batch
On new batch at output [code]
Action executed when a new batch appears at either of the inputs, or the mode, priority, or other parameters of the block change, which may (or may not) result in a new batch going out.
Local variable: Object batch - the batch
On rate change [code]
Action executed when any of the flow rates 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 variables:  double in1rate - the current input rate at port in1
             double in2rate - the current input rate at port in2
                          double outrate - the current output rate

Functions

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

double amountPassed(AmountUnits units) - Returns the total amount of fluid (in given units) passed through the out port of the block 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 at the block output.

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

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

Ports

in1
The upper input port, input 1.
in2
The lower input port, input 2.
out
The output port.