Class Tank<T>
- Type Parameters:
T- type (class or interface) whose instances represent materials
Tank can have at most one inflow connection and at most one outflow connection.
Max storage capacity of a Tank is defined during its construction and may also be changed later.
Inside a Tank, several material mix portions can coexist in a form of a sequence.
Each such portion is called a 'Layer' and is represented by an instance of Tank<T>.Layer class.
Materials from different layers are separated, but layers can be mixed into one layer (see mix() method).
Layers are ordered according to the FIFO rule:
the 1st portion of material mix that was added to the Tank becomes the 1st portion of material mix to be exported.
Layers can be requested by the getLayers() method that returns the Tank's layers sorted,
the first Layer being the most recently added Layer and the last Layer representing the Layer
ready to export its material mix from the Tank.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassLayer represents a portion of material mix contained within aTank.static class -
Constructor Summary
ConstructorsConstructorDescriptionTank(FlowEnvironment<T> flowEnvironment, double capacity) Creates a newTankinstance.Tank(FlowEnvironment<T> flowEnvironment, String name, double capacity) Creates a newTankinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddContents(Accumulator<T> addedContents) Adds the contents of theaddedContentsAccumulatorto this Tank.voidaddEmptyHandler(Consumer<Tank<T>> handler) Adds an action that will be executed every time this Tank becomes empty.voidaddFullHandler(Consumer<Tank<T>> handler) Adds an action that will be executed every time this Tank becomes full.voidaddInflowRateChangedHandler(Consumer<Tank<T>> handler) Adds an action that will be executed every time the inflow rate changes.voidaddOutflowRateChangedHandler(Consumer<Tank<T>> handler) Adds an action that will be executed every time the outflow rate changes.addThreshold(double threshold, Runnable activity) Adds an action that will be executed every time the amount of material in this Tank hits the provided threshold value during simulation.protected voidvoidRemoves all threshold actions added by theaddThreshold(double, Runnable)method.doubleReturns the total quantity of all materials inside this flow element.Returns all materials contained inside this flow element as an instance ofAccumulator.doubleReturns the storage capacity of the Tank.protected List<org.apache.commons.math3.optim.linear.LinearConstraint> getConstraints(com.amalgamasimulation.discreterate.LPArea<T> lpArea) doubleReturns the total quantity of all materials inside this flow element.doublegetContentsAmount(T material) Returns the current quantity of the specifiedmaterialinside this flow element.Returns all materials contained inside this flow element as an instance ofAccumulator.doubleReturns the difference between the input rate and the output rate.doubleReturns the current flow rate of all materials at the input of thisflow element.Returns anAccumulatorinstance that describes the flow rate at the input of this flow element.doubleReturns the current flow rate at the output of this flow element.Returns anAccumulatorinstance that describes the flow rate at the output of this flow element.getOutflowRateProportions(FlowConnection<T> outflowConnection) Returns anAccumulatorinstance that contains flow rate proportions of materials exported through theoutflowConnectionoutflow connection.doubleReturns the relative fullness of this Tank.doubleReturns the total amount of all materials that have entered this flow element.doublegetTotalInflowAmount(T material) Returns the total amount of the specifiedmaterialthat has entered this flow element.Returns anAccumulatorinstance that contains the total quantity of each material that has entered this flow element.doubleReturns the total quantity of materials that have left this flow element.doublegetTotalOutflowAmount(T material) Returns the total quantity of the specifiedmaterialthat has left this flow element.Returns anAccumulatorinstance that holds the total amounts of each material that has left this flow element.booleanisEmpty()Indicates that this Tank is empty.booleanisFull()Indicates that this Tank is full.voidmix()Combines all layers of materials in this Tank into a single layer.voidremoveEmptyHandler(Consumer<Tank<T>> handler) Removes the previously added empty Tank action.voidremoveFullHandler(Consumer<Tank<T>> handler) Removes the previously added full Tank action.voidremoveInflowRateChangedHandler(Consumer<Tank<T>> handler) Removes the previously added inflow rate change handler.voidremoveOutflowRateChangedHandler(Consumer<Tank<T>> handler) Removes the previously added outflow rate change handler.voidremoveThreshold(Tank.Threshold threshold) Removes threshold action added by theaddThreshold(double, Runnable)method.voidreplaceContents(Accumulator<T> newContents) Replaces the contents of this Tank with thenewContentsAccumulator.voidreplaceContents(List<Accumulator<T>> listOfLayers) Removes all materials from this Tank and sets its internal layers of materials to thelistOfLayers.voidreplaceContents(T material, double amount) Replaces the contents of this Tank withamountquantity ofmaterialmaterial.voidsetCapacity(double newCapacity) Sets the storage capacity of this Tank.voidswapContents(Tank<T> tank) Swaps the contents of this flow element with the contents oftankTankelement.Methods inherited from class com.amalgamasimulation.discreterate.FlowElement
addInflowElementConnectedHandler, addInflowElementDisconnectedHandler, addOutflowElementConnectedHandler, addOutflowElementDisconnectedHandler, connectToElement, disconnectFrom, getFlowEnvironment, getInflowConnections, getName, getOutflowConnections, inflowConnectionExists, isConnectedWith, outflowConnectionExists, removeInflowElementConnectedHandler, removeInflowElementDisconnectedHandler, removeOutflowElementConnectedHandler, removeOutflowElementDisconnectedHandler, toString
-
Constructor Details
-
Tank
Creates a newTankinstance.- Parameters:
flowEnvironment-FlowEnvironmentwhich thisTankbelongs tocapacity- tank storage capacity
-
Tank
Creates a newTankinstance.- Parameters:
flowEnvironment-FlowEnvironmentwhich thisTankbelongs toname- tank namecapacity- tank storage capacity
-
-
Method Details
-
addFullHandler
Adds an action that will be executed every time this Tank becomes full.- Parameters:
handler- action that will be executed every time the Tank becomes full- See Also:
-
removeFullHandler
Removes the previously added full Tank action.- Parameters:
handler- previously added full Tank action- See Also:
-
addEmptyHandler
Adds an action that will be executed every time this Tank becomes empty.- Parameters:
handler- action that will be executed every time the Tank becomes empty- See Also:
-
removeEmptyHandler
Removes the previously added empty Tank action.- Parameters:
handler- previously added empty Tank action- See Also:
-
addInflowRateChangedHandler
Adds an action that will be executed every time the inflow rate changes.- Parameters:
handler- action that will be executed every time the inflow rate changes- See Also:
-
removeInflowRateChangedHandler
Removes the previously added inflow rate change handler.- Parameters:
handler- previously added inflow rate change handler- See Also:
-
addOutflowRateChangedHandler
Adds an action that will be executed every time the outflow rate changes.- Parameters:
handler- action that will be executed every time the outflow rate changes- See Also:
-
removeOutflowRateChangedHandler
Removes the previously added outflow rate change handler.- Parameters:
handler- previously added outflow rate change handler- See Also:
-
setCapacity
public void setCapacity(double newCapacity) Sets the storage capacity of this Tank.- Parameters:
newCapacity- new storage capacity of the Tank, must be non-negative
-
getCapacity
public double getCapacity()Returns the storage capacity of the Tank.- Returns:
- storage capacity of the Tank
-
getFillingRate
public double getFillingRate()Returns the difference between the input rate and the output rate. May be negative.- Returns:
- difference between the input rate and the output rate
-
getContentsAmount
public double getContentsAmount()Description copied from class:FlowElementReturns the total quantity of all materials inside this flow element.- Specified by:
getContentsAmountin classFlowElement<T>- Returns:
- current sum of all material quantities inside this flow element
- See Also:
-
getAnimationContentsAmount
public double getAnimationContentsAmount()Returns the total quantity of all materials inside this flow element.This method must be called from animation when it is needed to determine quantity of all materials. Calling
getContentsAmount()from animation might result in non-reproducibility of the model.- Returns:
- current sum of all material quantities inside this flow element
- See Also:
-
isFull
public boolean isFull()Indicates that this Tank is full.- Returns:
trueif the Tank is full,falseotherwise
-
isEmpty
public boolean isEmpty()Indicates that this Tank is empty.- Returns:
trueif that at the tank is empty,falseotherwise
-
checkForRecalculation
protected void checkForRecalculation() -
getConstraints
-
getInflowRate
public double getInflowRate()Description copied from class:FlowElementReturns the current flow rate of all materials at the input of thisflow element.- Specified by:
getInflowRatein classFlowElement<T>- Returns:
- current flow rate of all materials at this
flow element's input - See Also:
-
getOutflowRate
public double getOutflowRate()Description copied from class:FlowElementReturns the current flow rate at the output of this flow element.- Specified by:
getOutflowRatein classFlowElement<T>- Returns:
- current flow rate at the output of this flow element
- See Also:
-
getTotalInflowAmount
public double getTotalInflowAmount()Description copied from class:FlowElementReturns the total amount of all materials that have entered this flow element.- Specified by:
getTotalInflowAmountin classFlowElement<T>- Returns:
- total amount of all arrived materials
-
getTotalOutflowAmount
public double getTotalOutflowAmount()Description copied from class:FlowElementReturns the total quantity of materials that have left this flow element.- Specified by:
getTotalOutflowAmountin classFlowElement<T>- Returns:
- total quantity of exported materials
- See Also:
-
addThreshold
Adds an action that will be executed every time the amount of material in this Tank hits the provided threshold value during simulation.The 'threshold hit event' will be fired only if the threshold is reached during simulation, as a result of modeling the material flow. Specifically, manually changing the contents of the flow element (via
replaceContents(Accumulator)method, for example) will NOT trigger the event. If this method is invoked (even during simulation) with thethresholdvalue equal to the current amount of material inside the Tank, this will not trigger a 'threshold hit event' either.Reaching the threshold value either from below and from above will trigger the 'threshold hit event'.
The event will be fired each time the threshold is reached (i.e. it is not a one-time handler).
- Parameters:
threshold- the material amount threshold value in this flow elementactivity- action that will be executed when the amount of material inside this flow element reaches thethreshold- Returns:
- a new
Tank.Threshold, description of the added threshold
-
removeThreshold
Removes threshold action added by theaddThreshold(double, Runnable)method.- Parameters:
threshold- description that was returned by theaddThreshold(double, Runnable)method
-
clearThresholds
public void clearThresholds()Removes all threshold actions added by theaddThreshold(double, Runnable)method. -
getLayers
-
mix
public void mix() -
swapContents
Swaps the contents of this flow element with the contents oftankTankelement.- Parameters:
tank- tank whose contents must be swap with contents of this flow element- See Also:
-
replaceContents
Replaces the contents of this Tank with thenewContentsAccumulator.If the amount of material in
newContentsis positive, the Tank will contain a singleTank<T>.Layer. Otherwise, the Tank will have no layers.- Parameters:
newContents- an Accumulator instance with new contents of the Tank- See Also:
-
replaceContents
Replaces the contents of this Tank withamountquantity ofmaterialmaterial.If the
amountofmaterialis positive, the Tank will contain a singleTank<T>.Layer. Otherwise, the Tank will have no layers.- Parameters:
material- materialamount- amount of the material- See Also:
-
replaceContents
Removes all materials from this Tank and sets its internal layers of materials to thelistOfLayers. TheTank<T>.Layers in thelistOfLayersshould be sorted: the 1st layer is near the Tank's entrance, and the last is next to the the Tank's exit.Layers from
listOfLayerswith zero or negative amount of material are ignored.- Parameters:
listOfLayers- new layers of the Tank- Throws:
IllegalArgumentException- if total amount of materials inlistOfLayersexceeds the current storage capacity of this Tank, or if total amount of materials inlistOfLayersis less than 0.- See Also:
-
addContents
Adds the contents of theaddedContentsAccumulatorto this Tank.If the total amount of materials in
addedContentsis positive, a new tankTank<T>.Layeris created. The layer's contents will match theaddedContents. The created layer will be the 'topmost' layer in the Tank, i.e., the layer closest to the Tank's 'input' and the first layer in the list returned by thegetLayers()method.If the total amount of materials in
addedContentsis 0, no new layer is added.- Parameters:
addedContents- materials and their amounts to be added to this Tank- Throws:
IllegalArgumentException- if total amount of materials inaddedContentsis less than 0IllegalArgumentException- if the sum of the current material amount in the Tank and the amount of added contents exceeds the storage capacity of this Tank
-
getContentsDescriptor
Description copied from class:FlowElementReturns all materials contained inside this flow element as an instance ofAccumulator.Each element of the Accumulator matches the amount of the corresponding material inside this flow element. The sum of amounts of materials in the Accumulator instance is equal to the value returned by the
FlowElement.getContentsAmount()method.- Specified by:
getContentsDescriptorin classFlowElement<T>- Returns:
Accumulatorcontaining all materials inside the flow element- See Also:
-
getAnimationContentsDescriptor
Returns all materials contained inside this flow element as an instance ofAccumulator.Each element of the Accumulator matches the amount of the corresponding material inside this flow element. The sum of amounts of materials in the Accumulator instance is equal to the value returned by the
getContentsAmount()method.This method must be called from animation when it is needed to determine all materials inside this flow element as an instance of
Accumulator. CallinggetContentsDescriptor()from animation might result in non-reproducibility of the model.- Returns:
Accumulatorcontaining all materials inside the flow element- See Also:
-
getContentsAmount
Description copied from class:FlowElementReturns the current quantity of the specifiedmaterialinside this flow element.- Specified by:
getContentsAmountin classFlowElement<T>- Parameters:
material- material- Returns:
- current quantity of the specified material inside this flow element
- See Also:
-
getInflowRateDescriptor
Description copied from class:FlowElementReturns anAccumulatorinstance that describes the flow rate at the input of this flow element.The returned
Accumulatorinstance contains the respective rates of all materials currently entering the flow element. The sum of values in the Accumulator is equal to 1.- Specified by:
getInflowRateDescriptorin classFlowElement<T>- Returns:
- descriptor of the current inflow rate
- See Also:
-
getOutflowRateDescriptor
Description copied from class:FlowElementReturns anAccumulatorinstance that describes the flow rate at the output of this flow element.The returned
Accumulatorinstance contains the respective rates of all materials currently leaving the flow element. The sum of values in the Accumulator is equal to 1.- Specified by:
getOutflowRateDescriptorin classFlowElement<T>- Returns:
- descriptor of the current outflow rate
- See Also:
-
getOutflowRateProportions
Description copied from class:FlowElementReturns anAccumulatorinstance that contains flow rate proportions of materials exported through theoutflowConnectionoutflow connection.Each element of the returned
Accumulatorcorresponds to a material in the current material flow ofoutflowConnection. The value of each element in the Accumulator is the ratio of the rate of that material's partial flow to the overall flow rate ofoutflowConnection. The sum of values in the Accumulator is equal to 1.- Specified by:
getOutflowRateProportionsin classFlowElement<T>- Parameters:
outflowConnection- an outflow connection- Returns:
- material proportions in the outflow connection
-
getTotalInflowAmount
Description copied from class:FlowElementReturns the total amount of the specifiedmaterialthat has entered this flow element.- Specified by:
getTotalInflowAmountin classFlowElement<T>- Parameters:
material- material- Returns:
- total amount of the specified
materialthat has arrived to this flow element - See Also:
-
getTotalInflowDescriptor
Description copied from class:FlowElementReturns anAccumulatorinstance that contains the total quantity of each material that has entered this flow element.The values of each element in the returned
Accumulatormatch the quantities of the respective materials that have entered the flow element. The sum of values in the Accumulator is equal to the value returned by theFlowElement.getTotalInflowAmount()method.- Specified by:
getTotalInflowDescriptorin classFlowElement<T>- Returns:
Accumulatorcontaining total amounts of materials that have entered this flow element- See Also:
-
getTotalOutflowAmount
Description copied from class:FlowElementReturns the total quantity of the specifiedmaterialthat has left this flow element.- Specified by:
getTotalOutflowAmountin classFlowElement<T>- Parameters:
material- material- Returns:
- total quantity of the specified material that has left this flow element
- See Also:
-
getTotalOutflowDescriptor
Description copied from class:FlowElementReturns anAccumulatorinstance that holds the total amounts of each material that has left this flow element.The values of each element in the returned
Accumulatormatch the quantities of the respective materials that have left the flow element. The sum of values in the Accumulator is equal to the value returned by theFlowElement.getTotalOutflowAmount()method.- Specified by:
getTotalOutflowDescriptorin classFlowElement<T>- Returns:
Accumulatorcontaining total amounts of materials that have left this flow element- See Also:
-
getRelativeContentsAmount
public double getRelativeContentsAmount()Returns the relative fullness of this Tank. Calculated as the ratio of the current contents amount to the capacity.- Returns:
- relative fullness of this Tank
- See Also:
-