Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | GlheNum | |||
real(kind=r64), | intent(in) | :: | LnTTsVal | |||
real(kind=r64), | intent(out) | :: | GfuncVal |
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 INTERP(GlheNum,LnTTsVal,GfuncVal)
! SUBROUTINE INFORMATION:
! AUTHOR Chris L. Marshall, Jeffrey D. Spitler
! DATE WRITTEN 1993
! MODIFIED August, 2000
! RE-ENGINEERED Dan Fisher
! PURPOSE OF THIS SUBROUTINE:
! To interpolate or extrapolate data in GFILE
! to find the correct g-function value for a
! known value of the natural log of (T/Ts)
! METHODOLOGY EMPLOYED:
!
! REFERENCE: Thermal Analysis of Heat Extraction
! Boreholes. Per Eskilson, Dept. of
! Mathematical Physics, University of
! Lund, Sweden, June 1987.
!
! USE STATEMENTS: na
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! SUBROUTINE ARGUMENT DEFINITIONS:
INTEGER, INTENT(IN) :: GlheNum ! Ground loop heat exchanger ID number
REAL(r64), INTENT(IN) :: LnTTsVal ! The value of LN(t/TimeSS) that a g-function
! needs to be found for.
REAL(r64), INTENT(OUT) :: GfuncVal ! The value of the g-function at LnTTsVal; found by
! either extrapolation or interpolation
! SUBROUTINE PARAMETER DEFINITIONS:
! na
! INTERFACE BLOCK SPECIFICATIONS
! na
! DERIVED TYPE DEFINITIONS
! na
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
INTEGER :: NumPairs
REAL(r64) :: RATIO
REAL(r64) :: ReferenceRatio
!Binary Search Algorithms Variables
! REFERENCE : DATA STRUCTURES AND ALGORITHM ANALYSIS IN C BY MARK ALLEN WEISS
INTEGER :: Mid
INTEGER :: Low
INTEGER :: High
LOGICAL :: Found
NumPairs =VerticalGlhe(GlheNum)%NPairs
RATIO=VerticalGlhe(GlheNum)%BoreholeRadius/VerticalGlhe(GlheNum)%BoreholeLength
ReferenceRatio = VerticalGlhe(GlheNum)%gReferenceRatio
! The following IF loop determines the g-function for the case
! when LnTTsVal is less than the first element of the LnTTs array.
! In this case, the g-function must be found by extrapolation.
IF(LnTTsVal <= VerticalGlhe(GlheNum)%LNTTS(1)) THEN
GfuncVal=(( LnTTsVal - VerticalGlhe(GlheNum)%LNTTS(1)) &
/(VerticalGlhe(GlheNum)%LNTTS(2) - VerticalGlhe(GlheNum)%LNTTS(1))) &
*(VerticalGlhe(GlheNum)%GFNC(2) - VerticalGlhe(GlheNum)%GFNC(1)) &
+ VerticalGlhe(GlheNum)%GFNC(1)
! The following IF statement determines the condition of the ratio
! between the borehole radius and the active borehole length.
! If RATIO does not equal 0.0005 then a correction factor for
! the g-function must be used.
IF(RATIO /= ReferenceRatio) THEN
GfuncVal=GfuncVal-LOG(VerticalGlhe(GlheNum)%BoreholeRadius/(VerticalGlhe(GlheNum)%BoreholeLength*ReferenceRatio))
ENDIF
RETURN
ENDIF
! The following IF loop determines the g-function for the case
! when LnTTsVal is greater than the last element of the LnTTs array.
! In this case, the g-function must be found by extrapolation.
IF(LnTTsVal > VerticalGlhe(GlheNum)%LNTTS(NumPairs)) THEN
GfuncVal=(( LnTTsVal - VerticalGlhe(GlheNum)%LNTTS(NumPairs)) &
/(VerticalGlhe(GlheNum)%LNTTS(NumPairs-1) - VerticalGlhe(GlheNum)%LNTTS(NumPairs))) &
*(VerticalGlhe(GlheNum)%GFNC(NumPairs-1) - VerticalGlhe(GlheNum)%GFNC(NumPairs)) &
+ VerticalGlhe(GlheNum)%GFNC(NumPairs)
! Apply correction factor if necessary
IF(RATIO /= ReferenceRatio) THEN
GfuncVal=GfuncVal-LOG(VerticalGlhe(GlheNum)%BoreholeRadius/(VerticalGlhe(GlheNum)%BoreholeLength*ReferenceRatio))
ENDIF
RETURN
ENDIF
! The following DO loop is for the case when LnTTsVal falls within
! the first and last elements of the LnTTs array, or is identically
! equal to one of the LnTTs elements. In this case the g-function
! must be found by interpolation.
! USING BINARY SEARCH TO FIND THE ELEMENET
Found = .FALSE.
Low = 1
High = NumPairs
LOOP: DO WHILE(Low<=High)
Mid = (Low+high)/2
IF(VerticalGlhe(GlheNum)%LNTTS(Mid)<LnTTsVal)THEN
Low = Mid+1
ELSE
IF( VerticalGlhe(GlheNum)%LNTTS(Mid)>LnTTsVal)THEN
High = Mid-1
ELSE
Found=.true.
EXIT LOOP
END IF
END IF
END DO LOOP
!LnTTsVal is identical to one of the LnTTS array elements return
!the GfuncVal after applying the correction
IF(Found)THEN
GfuncVal = VerticalGlhe(GlheNum)%GFNC(Mid)
! Apply correction factor if necessary
IF(RATIO.NE.ReferenceRatio) THEN
GfuncVal=GfuncVal-LOG(VerticalGlhe(GlheNum)%BoreholeRadius/(VerticalGlhe(GlheNum)%BoreholeLength*ReferenceRatio))
ENDIF
RETURN
END IF
!LnTTsVal is in between any of the two LnTTS array elements find the
! gfunction value by interplation and apply the correction and return
IF(.NOT.Found)THEN
IF(VerticalGlhe(GlheNum)%LNTTS(Mid)<LnTTsVal)Mid=Mid+1
GfuncVal=(( LnTTsVal - VerticalGlhe(GlheNum)%LNTTS(Mid)) &
/(VerticalGlhe(GlheNum)%LNTTS(Mid-1) - VerticalGlhe(GlheNum)%LNTTS(Mid))) &
*(VerticalGlhe(GlheNum)%GFNC(Mid-1) - VerticalGlhe(GlheNum)%GFNC(Mid)) &
+ VerticalGlhe(GlheNum)%GFNC(Mid)
! Apply correction factor if necessary
IF(RATIO /= ReferenceRatio) THEN
GfuncVal=GfuncVal-LOG(VerticalGlhe(GlheNum)%BoreholeRadius/(VerticalGlhe(GlheNum)%BoreholeLength*ReferenceRatio))
ENDIF
RETURN
END IF
RETURN
END SUBROUTINE INTERP