Fluid Source

Generates the flow; is a typical starting block of a Fluid Library flowchart. 

Can work as a source with infinite capacity or as source with limited initial amount that can be refilled by calling the inject() function. This block has a desired output rate, and the actual rate may be less or equal to the desired rate.

The Fluid Library will try to maximize the out flow of all fluid sources; therefore, the priority of FluidSource out flow is set to 1 by default. Sometimes, to resolve flow priority conflicts, you may need to customize the out flow priority by further increasing it.

The batch type generated by FluidSource can be customized. To change the batch type dynamically in the infinite capacity mode you should change the parameter Batch (call set_customBatch() ), while the parameter Custom batch should be selected. In the limited amount mode, you can specify the batch type and color as optional arguments of the inject() function.

Demo model: FluidSource

Parameters

Maximum rate
If selected, this block does not set an upper limit for the output rate (the limit must be set by other blocks down the flow).
Syntax: boolean maxRate
Set new value at runtime: set_maxRate(true or false)
Rate
[Visible and applies only if the Maximum rate option is not set] The maximum (desired) output rate.  
Syntax: double rate
Set new value at runtime: set_rate(new value)
Mode
Here you define whether the FluidSource block will be able to generate infinite amount of flow (Infinite capacity option), or – a limited amount, which, however, can be refilled by calling the inject() function (Limited amount, call inject() to refill option).
Syntax: boolean infiniteCapacity
Set new value at runtime: set_infiniteCapacity(true or false)
Initial amount
[Visible and applies only if the Mode is set to Limited amount, call inject() to refill] The amount initially contained in the block in the limited amount mode.
Syntax: double initialAmount
Set new value at runtime: set_initialAmount(new value)
Custom priority
If the option is set (the value equals true), the priority of outflow will be defined by the Output flow priority parameter below, otherwise it equals 1. Priority affects the LP solver when it tries to maximize the flow through the system.
Syntax: boolean customPriority
Set new value at runtime: set_customPriority(true or false) 
Output flow priority
[Visible and applies only if the Custom priority option is set] Custom priority of the outflow of this block in the overall flowchart. Must be a positive integer.
Syntax: int priorityOutCustom
Set new value at runtime: set_priorityOutCustom(new value)
Custom batch
If the option is selected (the value is true), the output batch will be defined by the Batch parameter below. If not, it will be the same as the input batch.
Syntax: boolean modeBatchCustom
Set new value at runtime: set_modeBatchCustom(true or false) 
Batch
[Visible and applies only if the Custom batch option is set] Defines the output batch. Applies in both modes, but in the limited amount mode can be overridden by the inject() function.
Syntax: Object customBatch
Set new value at runtime: set_customBatch(new value)
Custom batch color
[Visible and applies only if the Custom batch option is set] If set, the batch color is defined by the Batch color parameter below, otherwise the standard color mapping applies. Applies in both modes, but in the limited amount mode can be overridden by the inject() function.
Syntax: boolean customBatchColor
Set new value at runtime: set_customBatchColor(true or false)
Batch color [dynamic]
[Visible and applies only if the Custom batch color option is set] Defines the color of the output batch. Applies in both modes, but in the limited amount mode can be overridden by the inject() function.
Type of the value:  Color
Local variable: Object batch - the output batch
Animation
Storage tank
Here you can specify the name of Storage tank space markup shape used to animate FluidSource (both in 2D and 3D animation). The storage tank will be animated if the FluidSource block is set to generate batches, i.e. the Custom batch option must be checked and the Batch must be specified.
Syntax: StorageTank storageTank
Show batches in flowchart
If set, the block icon will display the current batch color.
Syntax: boolean showBatchesInFlowchart
Actions
On empty [code]
[Visible and applies only if the Mode option is set to Limited amount...] Action executed in the limited amount mode when there is no more fluid to output.
On new batch at output [code]
[Visible and applies only if the Mode option is set to Limited amount...] Action executed in the limited amount when a new batch appears at the block output.
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 outrate - the current output rate

Functions

double amount() - In infinite capacity mode returns +infinity. Otherwise returns the amount remaining in the block, possibly belonging to multiple batches.

double amount(AmountUnits units) - Returns +infinity in infinite capacity mode. Otherwise returns the amount of fluid (in given units) remaining in the block, possibly belonging to multiple batches.

double amountPassed() - Returns the total amount of fluid passed through the output port of the pipeline 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.

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

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

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

Object getBatch(int index) - Returns the batch with the specified index. Batch with index 0 is the closest to the block output.

double getBatchSize(int index) - Returns the size of the batch with the specified indexBatch with index 0 is the closest to the block output.

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

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

double getBatchOffset(int index) - Returns the total size of all batches located closer to output than the batch with the given index. Intended use is custom animation.

double inject(double amount, Object batch, Color color)- In limited amount mode adds a batch of the specified type and color to the output queue of the block. In infinite capacity mode does nothing,

double inject(double amount, AmountUnits units, Object batch, Color color) - In limited amount mode adds a batch (in given units) of the specified type and color to the output queue of the block. In infinite capacity mode does nothing.

double inject(double amount, Object batch)- In limited amount mode adds a batch of the specified type to the output queue of the block. The color of the batch is determined according to the parameter setting of the block. In infinite capacity mode does nothing.

double inject(double amount, AmountUnits units, Object batch) - In limited amount mode adds a batch of the specified type (in given units) to the output queue of the block. The color of the batch is determined according to the parameter setting of the block. In infinite capacity mode does nothing.

double inject(double amount) - In limited amount mode adds the specified amount to the output queue of the block. The batch and color of the amount are determined according to the parameter setting of the block. In infinite capacity mode does nothing.

double inject(double amount, AmountUnits units) - In limited amount mode adds the specified amount of fluid (in given units) to the output queue of the block. The batch and color of the amount are determined according to the parameter setting of the block. In infinite capacity mode does nothing.

Ports

out
The output port.