Class Bunker<T>
- Type Parameters:
T- type (class or interface) whose instances represent materials
Bunker can have an unlimited number of inflow connections. Bunker, like a Tank, can have at most one outflow
connection.
Internally, Bunker consists of a Merge, an inflow Valve, a Tank, and an outflow Valve,
connected sequentially to one another:
- The Merge allows the Bunker to be connected to several sources of material. Its flow distribution policy is set to
FlowRateDistributionPolicy.PRIORITY - The inflow Valve sets up the maximum inflow rate of the Bunker.
- The Tank works as a storage means that provides storage capacity and material layering. Most storage-related methods in the Bunker class are proxies to the methods of the internal Tank instance.
- The outflow Valve sets up the maximum outflow rate of the Bunker.
- Author:
- Alexander Morozov
-
Constructor Summary
ConstructorsConstructorDescriptionBunker(FlowEnvironment<T> flowEnvironment, double maxInFlowRate, double capacity, double maxOutFlowRate) Creates a new Bunker instance.Bunker(FlowEnvironment<T> flowEnvironment, String name, double maxInFlowRate, double capacity, double maxOutFlowRate) Creates a new Bunker instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddContents(Accumulator<T> addedContents) Adds the contents of theaddedContentsAccumulatorto this flow element.voidaddEmptyHandler(Consumer<Bunker<T>> handler) Adds an action that will be executed every time this Bunker becomes empty.voidaddFullHandler(Consumer<Bunker<T>> handler) Adds an action that will be executed every time this Bunker becomes full.voidaddInRateChangedHandler(Consumer<Bunker<T>> handler) Adds a action that will be executed every time the total inflow rate changes.voidaddOutRateChangedHandler(Consumer<Bunker<T>> handler) Adds a 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 flow element hits the provided threshold value during simulation.voidRemoves 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 this flow element.doubleReturns the total amount of all materials contained in this Bunker divided by the Bunker's storage capacity.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.Returns the current supplier function that provides the material proportions of the input flow.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.Returns an unmodifiable list of allTank.Layers contained inside thisBunker.doubleReturns the total inflow rate limit.doubleReturns the outflow rate limit.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> flowConnection) Returns anAccumulatorinstance that contains flow rate proportions of materials exported through theoutflowConnectionoutflow connection.doubleReturns the relative fullness of this Bunker.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 Bunker is empty.booleanisFull()Indicates that this Bunker is full.voidmix()Combines all layers of materials in this Bunker into a single layer.voidremoveEmptyHandler(Consumer<Bunker<T>> handler) Removes a previously added empty Bunker action.voidremoveFullHandler(Consumer<Bunker<T>> handler) Removes a previously added full Bunker action.voidremoveInRateChangedHandler(Consumer<Bunker<T>> handler) Removes a previously added total inflow change handler.voidremoveOutRateChangedHandler(Consumer<Bunker<T>> handler) Removes a previously added outflow change handler.voidremoveThreshold(Tank.Threshold threshold) Removes threshold action added by theaddThreshold(double, Runnable)method.voidreplaceContents(Accumulator<T> newContents) Replaces the contents of this flow element with thenewContentsAccumulator.voidreplaceContents(List<Accumulator<T>> listOfLayers) Removes all materials from this Bunker and sets its internal layers of materials to thelistOfLayers.voidreplaceContents(T material, double amount) Replaces the contents of this flow element withamountquantity ofmaterial.voidsetCapacity(double newCapacity) Sets the storage capacity of this flow element.voidsetInflowMaterialsSupplier(Function<Accumulator<T>, Accumulator<T>> outflowRateProportionsSupplier) Sets the supplier of the material proportions of the input flow.voidsetMaxInflowRate(double maxInflowRate) Sets the total inflow rate limit.voidsetMaxOutflowRate(double maxOutflowRate) Sets the outflow rate limit.voidswapContents(Bunker<T> bunker) Swaps the contents of this flow element with the contents ofbunkerBunkerelement.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
-
Bunker
public Bunker(FlowEnvironment<T> flowEnvironment, double maxInFlowRate, double capacity, double maxOutFlowRate) Creates a new Bunker instance.- Parameters:
flowEnvironment-FlowEnvironmentwhich the newBunkerbelongs tomaxInFlowRate- total inflow rate limitcapacity- storage capacity of the BunkermaxOutFlowRate- outflow rate limit
-
Bunker
public Bunker(FlowEnvironment<T> flowEnvironment, String name, double maxInFlowRate, double capacity, double maxOutFlowRate) Creates a new Bunker instance.- Parameters:
flowEnvironment-FlowEnvironmentwhich the newBunkerbelongs toname- name of the BunkermaxInFlowRate- total inflow rate limitcapacity- storage capacity of the BunkermaxOutFlowRate- outflow rate limit
-
-
Method Details
-
getCapacityUtilizationFactor
public double getCapacityUtilizationFactor()Returns the total amount of all materials contained in this Bunker divided by the Bunker's storage capacity.- Returns:
- total amount of all materials in this Bunker divided by its storage capacity
-
mix
public void mix()Combines all layers of materials in this Bunker into a single layer.- See Also:
-
addFullHandler
Adds an action that will be executed every time this Bunker becomes full.- Parameters:
handler- action to be executed when the Bunker becomes full- See Also:
-
removeFullHandler
Removes a previously added full Bunker action.- Parameters:
handler- a full Bunker action added by theaddFullHandler(Consumer)method
-
addEmptyHandler
Adds an action that will be executed every time this Bunker becomes empty.- Parameters:
handler- action that will be executed every time this Bunker becomes empty- See Also:
-
removeEmptyHandler
Removes a previously added empty Bunker action.- Parameters:
handler- an empty Bunker action added by theaddEmptyHandler(Consumer)method
-
addInRateChangedHandler
Adds a action that will be executed every time the total inflow rate changes.- Parameters:
handler- action that will be executed every time the total inflow rate changes- See Also:
-
removeInRateChangedHandler
Removes a previously added total inflow change handler.- Parameters:
handler- a total inflow change handler added by theaddInRateChangedHandler(Consumer)method
-
addOutRateChangedHandler
Adds a 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:
-
removeOutRateChangedHandler
Removes a previously added outflow change handler.- Parameters:
handler- an outflow change handler added by theaddOutRateChangedHandler(Consumer)method
-
addThreshold
Adds an action that will be executed every time the amount of material in this flow element hits the provided threshold value during simulation.The 'threshold hit event' will be fired only if the threshold is reached during simulation, not as a result of manually changing the contents of the flow element.
Reaching the threshold value both from below and from above will trigger the 'threshold hit event'.
- 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- See Also:
-
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.- See Also:
-
setCapacity
public void setCapacity(double newCapacity) Sets the storage capacity of this flow element.- Parameters:
newCapacity- new storage capacity of the Tank- See Also:
-
getCapacity
public double getCapacity()Returns the storage capacity of this flow element.The storage capacity of a Bunker is equal to the storage capacity of its internal Tank.
- Returns:
- storage capacity of this flow element
- See Also:
-
getMaxInflowRate
public double getMaxInflowRate()Returns the total inflow rate limit.Bunker can have several inflow connections, and the total inflow rate limit acts as the limit to all inflow connections combined.
- Returns:
- total inflow rate limit
-
setMaxInflowRate
public void setMaxInflowRate(double maxInflowRate) Sets the total inflow rate limit.- Parameters:
maxInflowRate- new total inflow rate limit- See Also:
-
getMaxOutflowRate
public double getMaxOutflowRate()Returns the outflow rate limit.- Returns:
- outflow rate limit
-
setMaxOutflowRate
public void setMaxOutflowRate(double maxOutflowRate) Sets the outflow rate limit.- Parameters:
maxOutflowRate- new outflow rate limit- See Also:
-
isEmpty
public boolean isEmpty()Indicates that this Bunker is empty.- Returns:
trueif the Bunker is empty,falseotherwise
-
isFull
public boolean isFull()Indicates that this Bunker is full.- Returns:
trueif the Bunker is full,falseotherwise
-
swapContents
Swaps the contents of this flow element with the contents ofbunkerBunkerelement.Internally, the
Tank.swapContents(Tank)method is called.- Parameters:
bunker- bunker whose contents must be swap with contents of this flow element- See Also:
-
replaceContents
Replaces the contents of this flow element with thenewContentsAccumulator.Internally, the
Tank.replaceContents(Accumulator)method is called.- Parameters:
newContents- new contents of the Bunker- See Also:
-
replaceContents
Replaces the contents of this flow element withamountquantity ofmaterial.Internally, the
Tank.replaceContents(Object, double)method is invoked.- Parameters:
material- materialamount- amount of material to be added- See Also:
-
replaceContents
Removes all materials from this Bunker and sets its internal layers of materials to thelistOfLayers.Internally, the
Tank.replaceContents(List)method is invoked.- Parameters:
listOfLayers- new list ofTank.Layers- See Also:
-
addContents
Adds the contents of theaddedContentsAccumulatorto this flow element.Internally, the
Tank.addContents(Accumulator)is invoked.- Parameters:
addedContents- contents added to this Bunker
-
getLayers
Returns an unmodifiable list of allTank.Layers contained inside thisBunker.Internally, the
Tank.getLayers()is invoked.- Returns:
- unmodifiable list of all
Tank.Layercontained inside thisBunker - See Also:
-
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:
-
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:
-
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:
-
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:
-
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:
-
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:
-
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:
-
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:
flowConnection- 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 Bunker. Calculated as the ratio of the current contents amount to the capacity.- Returns:
- relative fullness of this Bunker
- See Also:
-
setInflowMaterialsSupplier
public void setInflowMaterialsSupplier(Function<Accumulator<T>, Accumulator<T>> outflowRateProportionsSupplier) Sets the supplier of the material proportions of the input flow. The supplier returns the current material proportions of the material flow. Can be used to change material in a flow.The amount of each material in the Accumulator is the ratio of that material's partial flow to the overall flow of this connection. The sum of materials in the Accumulator returned by the input flow materials supplier must be equal to 1.
- Parameters:
outflowRateProportionsSupplier-
-
getInflowMaterialsSupplier
Returns the current supplier function that provides the material proportions of the input flow. The supplier returns the current material proportions of the material flow as an Accumulator.- Returns:
- the current supplier function for input flow material proportions
- See Also:
-