Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | WaterThermalTankNum | |||
integer, | intent(in) | :: | InletMode |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
SUBROUTINE CalcNodeMassFlows(WaterThermalTankNum, InletMode)
! SUBROUTINE INFORMATION:
! AUTHOR Peter Graham Ellis
! DATE WRITTEN January 2007
! MODIFIED na
!
! RE-ENGINEERED na
! PURPOSE OF THIS SUBROUTINE:
! Determines mass flow rates between nodes according to the locations of the use- and source-side inlet and outlet
! nodes.
! METHODOLOGY EMPLOYED:
! In 'Seeking' mode, nodes are searched between the user-specified inlet and outlet nodes to find the node closest
! in temperature to the inlet fluid temperature. In 'Fixed' mode, the user-specified nodes are always used.
! Upward and downward flows are added to each node between an inlet and outlet. Flows in both directions cancel out
! to leave only the net flow in one direction.
! USE STATEMENTS:
! na
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! SUBROUTINE ARGUMENT DEFINITIONS:
INTEGER, INTENT(IN) :: WaterThermalTankNum ! Water Heater being simulated
INTEGER, INTENT(IN) :: InletMode ! InletModeFixed or InletModeSeeking
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
INTEGER :: NumNodes ! Number of stratified nodes
INTEGER :: UseInletStratNode ! Use-side inlet node number
INTEGER :: UseOutletStratNode ! Use-side outlet node number
INTEGER :: SourceInletStratNode ! Source-side inlet node number
INTEGER :: SourceOutletStratNode ! Source-side outlet node number
INTEGER :: NodeNum ! Node number index
REAL(r64) :: UseMassFlowRate ! Use side flow rate, including effectiveness factor (kg/s)
REAL(r64) :: SourceMassFlowRate ! Source side flow rate, including effectiveness factor (kg/s)
INTEGER :: Step ! DO loop step direction, 1 or -1
REAL(r64) :: DeltaTemp ! Temperature difference between node and inlet (delta C)
REAL(r64) :: MinDeltaTemp ! Smallest temperature difference found so far (delta C)
! FLOW:
NumNodes = WaterThermalTank(WaterThermalTankNum)%Nodes
UseInletStratNode = WaterThermalTank(WaterThermalTankNum)%UseInletStratNode
UseOutletStratNode = WaterThermalTank(WaterThermalTankNum)%UseOutletStratNode
SourceInletStratNode = WaterThermalTank(WaterThermalTankNum)%SourceInletStratNode
SourceOutletStratNode = WaterThermalTank(WaterThermalTankNum)%SourceOutletStratNode
UseMassFlowRate = WaterThermalTank(WaterThermalTankNum)%UseMassFlowRate * &
WaterThermalTank(WaterThermalTankNum)%UseEffectiveness
SourceMassFlowRate = WaterThermalTank(WaterThermalTankNum)%SourceMassFlowRate * &
WaterThermalTank(WaterThermalTankNum)%SourceEffectiveness
WaterThermalTank(WaterThermalTankNum)%Node%UseMassFlowRate = 0.0d0
WaterThermalTank(WaterThermalTankNum)%Node%SourceMassFlowRate = 0.0d0
WaterThermalTank(WaterThermalTankNum)%Node%MassFlowFromUpper = 0.0d0
WaterThermalTank(WaterThermalTankNum)%Node%MassFlowFromLower = 0.0d0
WaterThermalTank(WaterThermalTankNum)%Node%MassFlowToUpper = 0.0d0
WaterThermalTank(WaterThermalTankNum)%Node%MassFlowToLower = 0.0d0
IF (InletMode == InletModeSeeking) THEN
! 'Seek' the node with the temperature closest to the inlet temperature
! Start at the user-specified inlet node and search to the user-specified outlet node
IF (UseMassFlowRate > 0.0d0) THEN
IF (UseInletStratNode > UseOutletStratNode) THEN
Step = -1
ELSE
Step = 1
END IF
MinDeltaTemp = 1.0d6 ! Some big number
DO NodeNum = UseInletStratNode, UseOutletStratNode, Step
DeltaTemp = ABS(WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%Temp - &
WaterThermalTank(WaterThermalTankNum)%UseInletTemp)
IF (DeltaTemp < MinDeltaTemp) THEN
MinDeltaTemp = DeltaTemp
UseInletStratNode = NodeNum
ELSE IF (DeltaTemp > MinDeltaTemp) THEN
EXIT
END IF
END DO
END IF
IF (SourceMassFlowRate > 0.0d0) THEN
IF (SourceInletStratNode > SourceOutletStratNode) THEN
Step = -1
ELSE
Step = 1
END IF
MinDeltaTemp = 1.0d6 ! Some big number
DO NodeNum = SourceInletStratNode, SourceOutletStratNode, Step
DeltaTemp = ABS(WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%Temp - &
WaterThermalTank(WaterThermalTankNum)%SourceInletTemp)
IF (DeltaTemp < MinDeltaTemp) THEN
MinDeltaTemp = DeltaTemp
SourceInletStratNode = NodeNum
ELSE IF (DeltaTemp > MinDeltaTemp) THEN
EXIT
END IF
END DO
END IF
END IF
IF (UseInletStratNode > 0) &
WaterThermalTank(WaterThermalTankNum)%Node(UseInletStratNode)%UseMassFlowRate = UseMassFlowRate
IF (SourceInletStratNode > 0) &
WaterThermalTank(WaterThermalTankNum)%Node(SourceInletStratNode)%SourceMassFlowRate = SourceMassFlowRate
IF (UseMassFlowRate > 0.0d0) THEN
IF (UseOutletStratNode > UseInletStratNode) THEN
! Use-side flow is down
DO NodeNum = UseInletStratNode, UseOutletStratNode - 1
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowToLower = &
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowToLower + UseMassFlowRate
END DO
DO NodeNum = UseInletStratNode + 1, UseOutletStratNode
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromUpper = &
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromUpper + UseMassFlowRate
END DO
ELSE IF (UseOutletStratNode < UseInletStratNode) THEN
! Use-side flow is up
DO NodeNum = UseOutletStratNode, UseInletStratNode - 1
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromLower = &
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromLower + UseMassFlowRate
END DO
DO NodeNum = UseOutletStratNode + 1, UseInletStratNode
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowToUpper = &
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowToUpper + UseMassFlowRate
END DO
ELSE
! Use-side flow is across the node; no flow to other nodes
END IF
END IF
IF (SourceMassFlowRate > 0.0d0) THEN
IF (SourceOutletStratNode > SourceInletStratNode) THEN
! Source-side flow is down
DO NodeNum = SourceInletStratNode, SourceOutletStratNode - 1
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowToLower = &
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowToLower + SourceMassFlowRate
END DO
DO NodeNum = SourceInletStratNode + 1, SourceOutletStratNode
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromUpper = &
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromUpper + SourceMassFlowRate
END DO
ELSE IF (SourceOutletStratNode < SourceInletStratNode) THEN
! Source-side flow is up
DO NodeNum = SourceOutletStratNode, SourceInletStratNode - 1
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromLower = &
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromLower + SourceMassFlowRate
END DO
DO NodeNum = SourceOutletStratNode + 1, SourceInletStratNode
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowToUpper = &
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowToUpper + SourceMassFlowRate
END DO
ELSE
! Source-side flow is across the node; no flow to other nodes
END IF
END IF
! Cancel out any up and down flows
DO NodeNum = 1, NumNodes
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromUpper = &
MAX((WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromUpper &
- WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowToUpper), 0.0d0)
WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromLower = &
MAX((WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowFromLower &
- WaterThermalTank(WaterThermalTankNum)%Node(NodeNum)%MassFlowToLower), 0.0d0)
END DO
RETURN
END SUBROUTINE CalcNodeMassFlows