Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(in) | :: | Ti | |||
real(kind=r64), | intent(in) | :: | Tf | |||
real(kind=r64), | intent(in) | :: | Ta | |||
real(kind=r64), | intent(in) | :: | T1 | |||
real(kind=r64), | intent(in) | :: | T2 | |||
real(kind=r64), | intent(in) | :: | m | |||
real(kind=r64), | intent(in) | :: | Cp | |||
real(kind=r64), | intent(in) | :: | m1 | |||
real(kind=r64), | intent(in) | :: | m2 | |||
real(kind=r64), | intent(in) | :: | UA | |||
real(kind=r64), | intent(in) | :: | Q |
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.
REAL(r64) FUNCTION CalcTimeNeeded(Ti, Tf, Ta, T1, T2, m, Cp, m1, m2, UA, Q)
! SUBROUTINE INFORMATION:
! AUTHOR Peter Graham Ellis
! DATE WRITTEN February 2005
! MODIFIED na
! RE-ENGINEERED na
! PURPOSE OF THIS SUBROUTINE:
! Calculates the time needed for the tank temperature to change from Ti to Tf given heat loss,
! mass flow rates and temperatures, and net heat transfer due to heater and parasitics.
! METHODOLOGY EMPLOYED:
! Equations are derived by solving the differential equation governing the tank energy balance.
! Special cases which cause the natural logarithm to blow up are trapped and interpreted as
! requiring an infinite amount of time because Tf can never be reached under the given conditions.
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! SUBROUTINE ARGUMENT DEFINITIONS:
REAL(r64), INTENT(IN) :: Ti ! Initial tank temperature (C)
REAL(r64), INTENT(IN) :: Tf ! Final tank temperature (C)
REAL(r64), INTENT(IN) :: Ta ! Ambient environment temperature (C)
REAL(r64), INTENT(IN) :: T1 ! Temperature of flow 1 (C)
REAL(r64), INTENT(IN) :: T2 ! Temperature of flow 2 (C)
REAL(r64), INTENT(IN) :: m ! Mass of tank fluid (kg)
REAL(r64), INTENT(IN) :: Cp ! Specific heat of fluid (J/kg deltaC)
REAL(r64), INTENT(IN) :: m1 ! Mass flow rate 1 (kg/s)
REAL(r64), INTENT(IN) :: m2 ! Mass flow rate 2 (kg/s)
REAL(r64), INTENT(IN) :: UA ! Heat loss coefficient to ambient environment (W/deltaC)
REAL(r64), INTENT(IN) :: Q ! Net heating rate for non-temp dependent sources, i.e. heater and parasitics (W)
! SUBROUTINE PARAMETER DEFINITIONS:
REAL(r64), PARAMETER :: Infinity = 99999999.9d0 ! A time interval much larger than any single timestep (s)
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
REAL(r64) :: a ! Intermediate variable
REAL(r64) :: b ! Intermediate variable
REAL(r64) :: Tm ! Mixed temperature after an infinite amount of time has passed (C)
REAL(r64) :: quotient ! Intermediate variable
REAL(r64) :: t ! Time elapsed from Ti to Tf (s)
! FLOW:
IF (Tf == Ti) THEN
! Already at Tf; no time is needed
t = 0.0d0
ELSE
IF (UA / Cp + m1 + m2 == 0.0d0) THEN
IF (Q == 0.0d0) THEN
! With no mass flow and no heat flow and Tf<>Ti, then Tf can never be reached
t = Infinity
ELSE
a = Q / (m * Cp)
t = (Tf - Ti) / a
END IF
ELSE
a = (Q / Cp + UA * Ta / Cp + m1 * T1 + m2 * T2) / m
b = -(UA / Cp + m1 + m2) / m
! Calculate the mixed temperature Tm of the tank after an infinite amount of time has passed
Tm = -a / b
IF (Tm == Ti) THEN
! Mixed temperature is the same as Ti; if Tf<>Ti, then Tf can never be reached
t = Infinity
ELSE IF (Tm == Tf) THEN
! Tf only approaches Tm; it can never actually get there in finite time (also avoids divide by zero error)
t = Infinity
ELSE
quotient = (Tf - Tm) / (Ti - Tm)
IF (quotient <= 0.0d0) THEN !Objexx:Num Changed < to <= to elim poss floating point error in LOG call
! Tm is in between Ti and Tf; Tf can never be reached
t = Infinity
ELSE
t = LOG(quotient) / b
END IF
END IF
END IF
IF (t < 0.0d0) t = Infinity ! If negative time, Tf can never be reached in the future
END IF
CalcTimeNeeded = t
RETURN
END FUNCTION CalcTimeNeeded