Class Valve<T>

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

public final class Valve<T> extends FlowElement<T>
Valve is a flow element that regulates the rate of the material flow.

Valve has no storage capacity.

Valve can have at most one inflow connection and at most one outflow connection. The incoming flow rate of the Valve is always equal to its outgoing flow rate.

Author:
Alexander Morozov
  • Constructor Details

    • Valve

      public Valve(FlowEnvironment<T> flowEnvironment, double maxRate)
      Creates a new Valve instance.
      Parameters:
      flowEnvironment - FlowEnvironment which this Valve belongs to
      maxRate - max allowed flow rate through the Valve
    • Valve

      public Valve(FlowEnvironment<T> flowEnvironment, String name, double maxRate)
      Creates a new Valve instance.
      Parameters:
      flowEnvironment - FlowEnvironment which this Valve belongs to
      name - name of this valve
      maxRate - max allowed flow rate through the Valve
  • Method Details

    • getMaxRate

      public double getMaxRate()
      Returns the max allowed flow rate through this Valve.
      Returns:
      max allowed flow rate through the Valve
      See Also:
    • setMaxRate

      public void setMaxRate(double maxRate)
      Sets the max allowed flow rate through this Valve.
      Parameters:
      maxRate - max allowed rate to be set to this Valve
      Throws:
      IllegalArgumentException - if maxRate is negative
      See Also:
    • getRate

      public double getRate()
      Returns the current flow rate through this Valve.
      Returns:
      current flow rate through the Valve
    • getPassedMaterialsAmount

      public double getPassedMaterialsAmount()
      Returns the total amount of all materials that have passed through this Valve.
      Returns:
      total amount of all materials that have passed through the Valve
    • getContentsAmount

      public double getContentsAmount()
      Returns the total amount of all materials inside this flow element. Always returns zero for any Valve because valves do not contain any material.
      Specified by:
      getContentsAmount in class FlowElement<T>
      Returns:
      0
      See Also:
    • getContentsAmount

      public double getContentsAmount(T material)
      Returns the current amount of the specified material contained inside this flow element. Always returns zero for any Valve because valves do not contain any material.
      Specified by:
      getContentsAmount in class FlowElement<T>
      Parameters:
      material - material
      Returns:
      0
      See Also:
    • getContentsDescriptor

      public Accumulator<T> getContentsDescriptor()
      Returns the material currently contained inside this flow element as Accumulator instance. Always returns an empty Accumulator for any Valve because valves do not contain any material.
      Specified by:
      getContentsDescriptor in class FlowElement<T>
      Returns:
      empty Accumulator
      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()
      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
    • 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()
      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:
    • 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:
    • addFlowRateChangedHandler

      public void addFlowRateChangedHandler(Consumer<Valve<T>> handler)
      Adds an action that will be executed every time the rate changes.

      Consumer has one parameters:
      - Valve

      Parameters:
      handler - action that will be executed every time the rate changes
      See Also:
    • removeFlowRateChangedHandler

      public void removeFlowRateChangedHandler(Consumer<Valve<T>> handler)
      Removes the previously added flow rate change handler.
      Parameters:
      handler - previously added flow rate change handler
      See Also:
    • setOutflowMaterialsSupplier

      public void setOutflowMaterialsSupplier(Function<Accumulator<T>,Accumulator<T>> outflowRateProportionsSupplier)
      Sets the supplier of the material proportions of the outflowConnection. 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 flowto the overall flow of this connection. The sum of materials in the Accumulator returned by the outflow materials supplier must be equal to 1.

      Parameters:
      outflowRateProportionsSupplier -