Class Bunker<T>

java.lang.Object
com.amalgamasimulation.discreterate.FlowElement<T>
com.amalgamasimulation.discreterate.Bunker<T>
Type Parameters:
T - type (class or interface) whose instances represent materials

public final class Bunker<T> extends FlowElement<T>
Bunker is a flow element that can contain material.

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 Details

    • Bunker

      public Bunker(FlowEnvironment<T> flowEnvironment, double maxInFlowRate, double capacity, double maxOutFlowRate)
      Creates a new Bunker instance.
      Parameters:
      flowEnvironment - FlowEnvironment which the new Bunker belongs to
      maxInFlowRate - total inflow rate limit
      capacity - storage capacity of the Bunker
      maxOutFlowRate - outflow rate limit
    • Bunker

      public Bunker(FlowEnvironment<T> flowEnvironment, String name, double maxInFlowRate, double capacity, double maxOutFlowRate)
      Creates a new Bunker instance.
      Parameters:
      flowEnvironment - FlowEnvironment which the new Bunker belongs to
      name - name of the Bunker
      maxInFlowRate - total inflow rate limit
      capacity - storage capacity of the Bunker
      maxOutFlowRate - 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

      public void addFullHandler(Consumer<Bunker<T>> handler)
      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

      public void removeFullHandler(Consumer<Bunker<T>> handler)
      Removes a previously added full Bunker action.
      Parameters:
      handler - a full Bunker action added by the addFullHandler(Consumer) method
    • addEmptyHandler

      public void addEmptyHandler(Consumer<Bunker<T>> handler)
      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

      public void removeEmptyHandler(Consumer<Bunker<T>> handler)
      Removes a previously added empty Bunker action.
      Parameters:
      handler - an empty Bunker action added by the addEmptyHandler(Consumer) method
    • addInRateChangedHandler

      public void addInRateChangedHandler(Consumer<Bunker<T>> handler)
      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

      public void removeInRateChangedHandler(Consumer<Bunker<T>> handler)
      Removes a previously added total inflow change handler.
      Parameters:
      handler - a total inflow change handler added by the addInRateChangedHandler(Consumer) method
    • addOutRateChangedHandler

      public void addOutRateChangedHandler(Consumer<Bunker<T>> handler)
      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

      public void removeOutRateChangedHandler(Consumer<Bunker<T>> handler)
      Removes a previously added outflow change handler.
      Parameters:
      handler - an outflow change handler added by the addOutRateChangedHandler(Consumer) method
    • addThreshold

      public Tank.Threshold 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.

      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 element
      activity - action that will be executed when the amount of material inside this flow element reaches the threshold
      See Also:
    • removeThreshold

      public void removeThreshold(Tank.Threshold threshold)
      Removes threshold action added by the addThreshold(double, Runnable) method.
      Parameters:
      threshold - description that was returned by the addThreshold(double, Runnable) method
    • clearThresholds

      public void clearThresholds()
      Removes all threshold actions added by the addThreshold(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:
      true if the Bunker is empty, false otherwise
    • isFull

      public boolean isFull()
      Indicates that this Bunker is full.
      Returns:
      true if the Bunker is full, false otherwise
    • swapContents

      public void swapContents(Bunker<T> bunker)
      Swaps the contents of this flow element with the contents of bunker Bunker element.

      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

      public void replaceContents(Accumulator<T> newContents)
      Replaces the contents of this flow element with the newContents Accumulator.

      Internally, the Tank.replaceContents(Accumulator) method is called.

      Parameters:
      newContents - new contents of the Bunker
      See Also:
    • replaceContents

      public void replaceContents(T material, double amount)
      Replaces the contents of this flow element with amount quantity of material.

      Internally, the Tank.replaceContents(Object, double) method is invoked.

      Parameters:
      material - material
      amount - amount of material to be added
      See Also:
    • replaceContents

      public void replaceContents(List<Accumulator<T>> listOfLayers)
      Removes all materials from this Bunker and sets its internal layers of materials to the listOfLayers.

      Internally, the Tank.replaceContents(List) method is invoked.

      Parameters:
      listOfLayers - new list of Tank.Layers
      See Also:
    • addContents

      public void addContents(Accumulator<T> addedContents)
      Adds the contents of the addedContents Accumulator to this flow element.

      Internally, the Tank.addContents(Accumulator) is invoked.

      Parameters:
      addedContents - contents added to this Bunker
    • getLayers

      public List<Tank<T>.Layer> getLayers()
      Returns an unmodifiable list of all Tank.Layers contained inside this Bunker.

      Internally, the Tank.getLayers() is invoked.

      Returns:
      unmodifiable list of all Tank.Layer contained inside this Bunker
      See Also:
    • getContentsAmount

      public double getContentsAmount()
      Description copied from class: FlowElement
      Returns the total quantity of all materials inside this flow element.
      Specified by:
      getContentsAmount in class FlowElement<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

      public Accumulator<T> getAnimationContentsDescriptor()
      Returns all materials contained inside this flow element as an instance of Accumulator.

      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. Calling getContentsDescriptor() from animation might result in non-reproducibility of the model.

      Returns:
      Accumulator containing all materials inside the flow element
      See Also:
    • getContentsAmount

      public double getContentsAmount(T material)
      Description copied from class: FlowElement
      Returns the current quantity of the specified material inside this flow element.
      Specified by:
      getContentsAmount in class FlowElement<T>
      Parameters:
      material - material
      Returns:
      current quantity of the specified material inside this flow element
      See Also:
    • getContentsDescriptor

      public Accumulator<T> getContentsDescriptor()
      Description copied from class: FlowElement
      Returns all materials contained inside this flow element as an instance of Accumulator.

      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:
      getContentsDescriptor in class FlowElement<T>
      Returns:
      Accumulator containing all materials inside the flow element
      See Also:
    • getTotalInflowAmount

      public double getTotalInflowAmount()
      Description copied from class: FlowElement
      Returns the total amount of all materials that have entered this flow element.
      Specified by:
      getTotalInflowAmount in class FlowElement<T>
      Returns:
      total amount of all arrived materials
    • getTotalOutflowAmount

      public double getTotalOutflowAmount()
      Description copied from class: FlowElement
      Returns the total quantity of materials that have left this flow element.
      Specified by:
      getTotalOutflowAmount in class FlowElement<T>
      Returns:
      total quantity of exported materials
      See Also:
    • getInflowRate

      public double getInflowRate()
      Description copied from class: FlowElement
      Returns the current flow rate of all materials at the input of this flow element.
      Specified by:
      getInflowRate in class FlowElement<T>
      Returns:
      current flow rate of all materials at this flow element's input
      See Also:
    • getInflowRateDescriptor

      public Accumulator<T> getInflowRateDescriptor()
      Description copied from class: FlowElement
      Returns an Accumulator instance that describes the flow rate at the input of this flow element.

      The returned Accumulator instance 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:
      getInflowRateDescriptor in class FlowElement<T>
      Returns:
      descriptor of the current inflow rate
      See Also:
    • getOutflowRate

      public double getOutflowRate()
      Description copied from class: FlowElement
      Returns the current flow rate at the output of this flow element.
      Specified by:
      getOutflowRate in class FlowElement<T>
      Returns:
      current flow rate at the output of this flow element
      See Also:
    • getOutflowRateDescriptor

      public Accumulator<T> getOutflowRateDescriptor()
      Description copied from class: FlowElement
      Returns an Accumulator instance that describes the flow rate at the output of this flow element.

      The returned Accumulator instance 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:
      getOutflowRateDescriptor in class FlowElement<T>
      Returns:
      descriptor of the current outflow rate
      See Also:
    • getOutflowRateProportions

      public Accumulator<T> getOutflowRateProportions(FlowConnection<T> flowConnection)
      Description copied from class: FlowElement
      Returns an Accumulator instance that contains flow rate proportions of materials exported through the outflowConnection outflow connection.

      Each element of the returned Accumulator corresponds to a material in the current material flow of outflowConnection. 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 of outflowConnection. The sum of values in the Accumulator is equal to 1.

      Specified by:
      getOutflowRateProportions in class FlowElement<T>
      Parameters:
      flowConnection - an outflow connection
      Returns:
      material proportions in the outflow connection
    • getTotalInflowAmount

      public double getTotalInflowAmount(T material)
      Description copied from class: FlowElement
      Returns the total amount of the specified material that has entered this flow element.
      Specified by:
      getTotalInflowAmount in class FlowElement<T>
      Parameters:
      material - material
      Returns:
      total amount of the specified material that has arrived to this flow element
      See Also:
    • getTotalInflowDescriptor

      public Accumulator<T> getTotalInflowDescriptor()
      Description copied from class: FlowElement
      Returns an Accumulator instance that contains the total quantity of each material that has entered this flow element.

      The values of each element in the returned Accumulator match 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 the FlowElement.getTotalInflowAmount() method.

      Specified by:
      getTotalInflowDescriptor in class FlowElement<T>
      Returns:
      Accumulator containing total amounts of materials that have entered this flow element
      See Also:
    • getTotalOutflowAmount

      public double getTotalOutflowAmount(T material)
      Description copied from class: FlowElement
      Returns the total quantity of the specified material that has left this flow element.
      Specified by:
      getTotalOutflowAmount in class FlowElement<T>
      Parameters:
      material - material
      Returns:
      total quantity of the specified material that has left this flow element
      See Also:
    • getTotalOutflowDescriptor

      public Accumulator<T> getTotalOutflowDescriptor()
      Description copied from class: FlowElement
      Returns an Accumulator instance that holds the total amounts of each material that has left this flow element.

      The values of each element in the returned Accumulator match 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 the FlowElement.getTotalOutflowAmount() method.

      Specified by:
      getTotalOutflowDescriptor in class FlowElement<T>
      Returns:
      Accumulator containing 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

      public Function<Accumulator<T>,Accumulator<T>> 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: