Class Valve<T>
- Type Parameters:
T- type (class or interface) whose instances represent materials
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 Summary
ConstructorsConstructorDescriptionValve(FlowEnvironment<T> flowEnvironment, double maxRate) Creates a new Valve instance.Valve(FlowEnvironment<T> flowEnvironment, String name, double maxRate) Creates a new Valve instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFlowRateChangedHandler(Consumer<Valve<T>> handler) Adds an action that will be executed every time the rate changes.doubleReturns the total amount of all materials inside this flow element.doublegetContentsAmount(T material) Returns the current amount of the specified material contained inside this flow element.Returns the material currently contained inside this flow element asAccumulatorinstance.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 max allowed flow rate through this Valve.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 total amount of all materials that have passed through this Valve.doublegetRate()Returns the current flow rate through this Valve.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.voidremoveFlowRateChangedHandler(Consumer<Valve<T>> handler) Removes the previously added flow rate change handler.voidsetMaxRate(double maxRate) Sets the max allowed flow rate through this Valve.voidsetOutflowMaterialsSupplier(Function<Accumulator<T>, Accumulator<T>> outflowRateProportionsSupplier) Sets the supplier of the material proportions of the outflowConnection.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
-
Valve
Creates a new Valve instance.- Parameters:
flowEnvironment-FlowEnvironmentwhich this Valve belongs tomaxRate- max allowed flow rate through the Valve
-
Valve
Creates a new Valve instance.- Parameters:
flowEnvironment-FlowEnvironmentwhich this Valve belongs toname- name of this valvemaxRate- 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- ifmaxRateis 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:
getContentsAmountin classFlowElement<T>- Returns:
- 0
- See Also:
-
getContentsAmount
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:
getContentsAmountin classFlowElement<T>- Parameters:
material- material- Returns:
- 0
- See Also:
-
getContentsDescriptor
Returns the material currently contained inside this flow element asAccumulatorinstance. Always returns an emptyAccumulatorfor any Valve because valves do not contain any material.- Specified by:
getContentsDescriptorin classFlowElement<T>- Returns:
- empty
Accumulator - 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
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
-
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
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:
-
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:
-
addFlowRateChangedHandler
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
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 flowThe amount of each material in the
Accumulatoris 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-
-