Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10847 - EnergyPlus simulation crashes above a certain BaseDepth value for GroundHeatTransfer #10850

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
2 changes: 2 additions & 0 deletions cmake/Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ elseif(UNIX)
if(CMAKE_Fortran_COMPILER MATCHES "ifort")
target_compile_options(fortran_project_options INTERFACE -fpp)
target_link_options(fortran_project_options INTERFACE -static-intel)
target_compile_options(fortran_project_options INTERFACE $<$<CONFIG:Debug>:-traceback>)
else()
if(NOT "Ninja" STREQUAL ${CMAKE_GENERATOR})
target_compile_options(fortran_project_options INTERFACE -cpp)
endif()
set(FORTRAN_STATIC_EXE TRUE)
target_link_options(fortran_project_options INTERFACE -static)
target_compile_options(fortran_project_options INTERFACE $<$<CONFIG:Debug>:-fbacktrace -ffpe-trap=zero,overflow,underflow>)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass some debug options to gfortran / ifort when building debug. I havern't found much differences but it makes sense

endif()
else() # Windows
set(FORTRAN_STATIC_EXE TRUE)
Expand Down
1 change: 1 addition & 0 deletions idd/BasementGHT.idd
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ ManualGrid,
\required-field
N4, \field NZBG: Number of cells in Z direction. below grade: 10-35]
\minimum 1
\maximum 100
\required-field
N5, \field IBASE: X direction cell indicator of slab edge: 5-20]
\required-field
Expand Down
22 changes: 19 additions & 3 deletions src/Basement/3DBasementHT.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ SUBROUTINE GetSimParams(RUNID)
SimParams%F=.1d0
ENDIF
SimParams%IYRS =NumArray(2)

! Override with environment variable for quicker testing
CALL GET_ENVIRONMENT_VARIABLE("CI_BASEMENT_NUMYEARS", EnvVarNumYearsString, EnvVarNumYearsStringLength, EnvVarNumYearsStatus)
SELECT CASE (EnvVarNumYearsStatus)
Expand All @@ -1026,7 +1026,7 @@ SUBROUTINE GetSimParams(RUNID)
SimParams%IYRS = EnvVarNumYears
END IF
END SELECT

IF (SimParams%IYRS <= 0.d0) THEN
CALL ShowSevereError('GetSimParams: Entered "IYRS: Maximum number of yearly iterations:" '// &
'choice is not valid.'// &
Expand Down Expand Up @@ -2266,6 +2266,7 @@ SUBROUTINE BasementSimulator(RUNID,NMAT,CVG,XDIM,YDIM,ZDIM,TG)
REAL(r64) Elapsed_Time
INTEGER IHrStart
INTEGER IHrEnd
INTEGER CI_BAIL_EARLY_STATUS


CALL CPU_TIME(Time_Start)
Expand Down Expand Up @@ -2589,6 +2590,12 @@ SUBROUTINE BasementSimulator(RUNID,NMAT,CVG,XDIM,YDIM,ZDIM,TG)
!*** Echo input data
CALL PrelimOutput(ACEIL,AFLOOR,ARIM,ASILL,AWALL,PERIM,RUNID,TDBH,TDBC)

CALL GET_ENVIRONMENT_VARIABLE("CI_BAIL_EARLY", status=CI_BAIL_EARLY_STATUS)
IF (CI_BAIL_EARLY_STATUS == 0) THEN
print *, 'Exiting early because envionment variable CI_BAIL_EARLY was found'
CALL EXIT(0)
END IF
Comment on lines +2593 to +2597
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an environment variable "CI_BAIL_EARLY": if defined, exit after CalcTearth & PrelimOutput, which is enough to produce the crash. I don't want to add a Basement test that takes like 10 minutes, or worse like an hour (when depth is 10.3, it's looooong)


!*** Initialize temperatures in 3-D domain
!*** T(X,Y,Z)=TG(Z)
READ (GroundTemp,*) RSKY,HHEAT,HMASS,DODPG,(TG(COUNT1), COUNT1=0,NZBGM1)
Expand Down Expand Up @@ -9634,7 +9641,7 @@ SUBROUTINE CalcTearth(IEXT,JEXT,DZ,DZP,TG,CVG)


!*** DECLARATIONS:
REAL(r64) A(50), B(50), C(50), R(50), X(50), ALB, ALBEDO(2), &
REAL(r64) A(100), B(100), C(100), R(100), X(100), ALB, ALBEDO(2), &
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual fix is here

ZFACE is ZFACE(-35:100), positive indicates Below ground (NZBG).
A, B, C,R and X are used in the 1 to NZBG range, so they should be 100 elements not 50 (Note: they are 1-indexed)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the -35:100 means there are 136 array elements?

https://www-eio.upc.es/lceio/manuals/Fortran95-manual.pdf

All the following type declaration statements are legal:
 real, dimension (-10:8) :: a1 ! 1-dim array with 19 elements
 integer, dimension (-3:3, -20:0, 1:2, 6, 2, 5:6, 2) :: grid1 ! 7-dim array
The number of elements of the integer array grid1 is 7 x 21 x 2 x 6 x 2 x 2 x 2 = 14112. 

Copy link
Contributor

@rraustad rraustad Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But NZBG is a user input and I think the idd is suggesting a value of 10 to 35 for that input, so that's where the 50 came from? There is no upper limit on that field so a user could enter 150 and crash the program again.

GroundHeatTransfer:Basement:ManualGrid,
    \memo Manual Grid only necessary using manual gridding (not recommended)
       N1, \field NX: Number of cells in the X direction: 20]
          \minimum 1
          \required-field
       N2, \field NY: Number of cells in the Y direction: 20]
          \minimum 1
          \required-field
       N3, \field NZAG: Number of cells in the Z direction. above grade: 4 Always]
          \minimum 1
          \required-field
       N4, \field NZBG: Number of cells in Z direction. below grade: 10-35]
          \minimum 1
          \required-field

 NumNums=GetNumObjectsFound('ManualGrid')
 IF (NumNums > 0) THEN
   CALL GetObjectItem('ManualGrid',NUM,AlphArray,NumAlphas,NumArray,NumNums,IOSTAT)
   NX   =NumArray(1)
   NY   =NumArray(2)
   NZAG =NumArray(3)
   NZBG =NumArray(4)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ManualGrid is broken, there is ZERO way to use it (AUTOGRID is set to TRUE and it's never ressetable to FALSE):

AUTOGRID = 'TRUE'

I brought it up with @Myoldmopar, not sure if it was worth fixing (the Documentation explicitly says this is discouraged anyways).

The EquivAutoGrid BaseDepth is the one that determines the NZBG, and I agree I should probably do a bounds check there.


There are 136 elements in ZFACE, 35 < 0, the 0, and 100> 0 (1 to 100).

If you look closely at the routine, you'll see the A, B etc arrays are only used in the 1 to NZBG range, so it needs 100 elements.

& AVGWND, CG, CONST(0:100,2), CPA, DH, DODPG, DW, &
& DZ(-35:100), DZP(-35:100), ELEV, EPS, EPSLN(2), &
& GOFT, GOLD, HRAT(24), IEXT, JEXT, LAT, LONG, MSTD, PBAR(24), &
Expand Down Expand Up @@ -11425,6 +11432,8 @@ END SUBROUTINE InitializeTemps
!******************************** AUTOGRIDDING ***************************************
SUBROUTINE AutoGridding
USE BasementSimData
USE DataGlobals, ONLY: ShowSevereError,ShowContinueError,ShowFatalError
USE General, ONLY: RoundSigDigits
IMPLICIT NONE
! THIS PROGRAM WILL ESTABLISH THE SIMULATION GRID FOR A BASEMENT FOUNDATION
! WHOSE DIMENSIONS ARE INPUT BY THE USER
Expand Down Expand Up @@ -11767,6 +11776,13 @@ SUBROUTINE AutoGridding
NZ6=7 ! To the edge of the domain, cells are spaced at 2m
NZBG=NZ1+NZ2+NZ3+NZ4+NZ5+NZ6

IF(NZBG.GT.100) THEN
CALL ShowSevereError('AutoGrid BaseDepth is too high, reduce it below 17.0 meters')
CALL ShowContinueError('BaseDepth=['//trim(RoundSigDigits(BaseDepth,4))//'], '&
'resulting NZBG=['//trim(RoundSigDigits(NZBG,0))//'] (max 100).')
CALL ShowFatalError('Program terminates due to preceding condition(s).')
END IF

ZFACEINIT(-NZAG+3)=-ConcAGHeight
ZFACEINIT(-NZAG+2)=ZFACEINIT(-NZAG+3)-SillPlateHeight
ZFACEINIT(-NZAG+1)=ZFACEINIT(-NZAG+2)-RimJoistHeight
Expand Down
30 changes: 29 additions & 1 deletion src/Basement/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ set(CMAKE_SKIP_RPATH ${FORTRAN_SKIP_RPATH})
set(SKIP_BUILD_RPATH TRUE)

add_executable(Basement ${SRC})
target_compile_options(Basement PRIVATE -O1)
target_compile_options(Basement PRIVATE $<$<CONFIG:Release>:-O1>)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THIS is especially needed to get the segfault.

When building debug, do NOT ask for -O1 (the flags would be -g -O1 which is weird)

set_target_properties(Basement PROPERTIES FOLDER Auxiliary)

if(NOT UNIX) # Need to reinclude it on Windows
Expand All @@ -80,3 +80,31 @@ if(APPLE AND CPACK_CODESIGNING_DEVELOPPER_ID_APPLICATION)
include("${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/CodeSigning.cmake")
register_install_codesign_target(Basement PreProcess/GrndTempCalc)
endif()

if(BUILD_TESTING)

macro(basement_test GHT_IN_IDF_NAME)
set(TEST_DIR "${PROJECT_BINARY_DIR}/tst/${GHT_IN_IDF_NAME}") # build/src/Basement/tst
set(IDF_FILE "${PROJECT_SOURCE_DIR}/tests/${GHT_IN_IDF_NAME}.idf")

file(MAKE_DIRECTORY ${TEST_DIR})
file(COPY "${PROJECT_SOURCE_DIR}/../../idd/BasementGHT.idd" DESTINATION "${TEST_DIR}")
configure_file("${PROJECT_SOURCE_DIR}/../../weather/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw" "${TEST_DIR}/in.epw" COPYONLY)
configure_file(${IDF_FILE} "${TEST_DIR}/BasementGHTIn.idf" COPYONLY)

set(TEST_NAME "Basement.${GHT_IN_IDF_NAME}")
add_test(NAME "${TEST_NAME}"
COMMAND $<TARGET_FILE:Basement>
WORKING_DIRECTORY ${TEST_DIR}
)
set_tests_properties("${TEST_NAME}" PROPERTIES
FAIL_REGULAR_EXPRESSION "Terminated;Error(s) Detected"
ENVIRONMENT "CI_BAIL_EARLY=1"
)
endmacro()

basement_test(AutoGriddingDepthIsHigh)
basement_test(AutoGriddingDepthIsLowish)
basement_test(AutoGriddingDepthIsTooHigh)
set_tests_properties(Basement.AutoGriddingDepthIsTooHigh PROPERTIES WILL_FAIL TRUE)
endif()
79 changes: 79 additions & 0 deletions src/Basement/tests/AutoGriddingDepthIsHigh.idf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
! EquivAutoGrid BaseDepth is too high, cf #10847

SimParameters,
0.1, !- F: Multiplier for the ADI solution
15; !- IYRS: Maximum number of yearly iterations:

MatlProps,
3, !- NMAT: Number of materials in this domain
2500, !- Density for Foundation Wall {kg/m3}
2500, !- density for Floor Slab {kg/m3}
2500, !- density for Ceiling {kg/m3}
1500, !- density for Soil {kg/m3}
2000, !- density for Gravel {kg/m3}
449, !- density for Wood {kg/m3}
880, !- Specific heat for foundation wall {J/kg-K}
880, !- Specific heat for floor slab {J/kg-K}
880, !- Specific heat for ceiling {J/kg-K}
2000, !- Specific heat for soil {J/kg-K}
720, !- Specific heat for gravel {J/kg-K}
1530, !- Specific heat for wood {J/kg-K}
2.3, !- Thermal conductivity for foundation wall {W/m-K}
2.3, !- Thermal conductivity for floor slab {W/m-K}
2.3, !- Thermal conductivity for ceiling {W/m-K}
1.5, !- thermal conductivity for soil {W/m-K}
1.9, !- thermal conductivity for gravel {W/m-K}
0.12; !- thermal conductivity for wood {W/m-K}

Insulation,
5, !- REXT: R Value of any exterior insulation {m2-K/W}
True; !- INSFULL: Flag: Is the wall fully insulated?

SurfaceProps,
0.4, !- ALBEDO: Surface albedo for No snow conditions
0.4, !- ALBEDO: Surface albedo for snow conditions
0.94, !- EPSLN: Surface emissivity No Snow
0.86, !- EPSLN: Surface emissivity with Snow
6, !- VEGHT: Surface roughness No snow conditions {cm}
0.25, !- VEGHT: Surface roughness Snow conditions {cm}
True; !- PET: Flag, Potential evapotranspiration on?

BldgData,
0.72, !- DWALL: Wall thickness {m}
0.25, !- DSLAB: Floor slab thickness {m}
0.3, !- DGRAVXY: Width of gravel pit beside basement wall {m}
0.2, !- DGRAVZN: Gravel depth extending above the floor slab {m}
0.3; !- DGRAVZP: Gravel depth below the floor slab {m}

Interior,
True, !- COND: Flag: Is the basement conditioned?
0.92, !- HIN: Downward convection only heat transfer coefficient {W/m2-K}
4.04, !- HIN: Upward convection only heat transfer coefficient {W/m2-K}
3.08, !- HIN: Horizontal convection only heat transfer coefficient {W/m2-K}
6.13, !- HIN: Downward combined (convection and radiation) heat transfer coefficient {W/m2-K}
9.26, !- HIN: Upward combined (convection and radiation) heat transfer coefficient {W/m2-K}
8.29; !- HIN: Horizontal combined (convection and radiation) heat transfer coefficient {W/m2-K}

ComBldg,
19.112521, !- January average temperature {C}
19.3265, !- February average temperature {C}
19.639847, !- March average temperature {C}
20.215454, !- April average temperature {C}
20.415274, !- May average temperature {C}
21.524396, !- June average temperature {C}
21.880071, !- July average temperature {C}
21.659116, !- August average temperature {C}
21.114287, !- September average temperature {C}
20.383342, !- October average temperature {C}
19.553359, !- November average temperature {C}
19.233107, !- December average temperature {C}
; !- Daily variation sine wave amplitude {deltaC}

EquivSlab,
20.045326, !- APRatio: The area to perimeter ratio for this slab {m}
TRUE; !- EquivSizing: Flag

EquivAutoGrid,
15, !- CLEARANCE: Distance from outside of wall to edge of 3-D ground domain {m}
0.25, !- SlabDepth: Thickness of the floor slab {m}
10.3; !- BaseDepth: Depth of the basement wall below grade {m}
Comment on lines +76 to +79
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here test with depth is 10.3, which exhibits the crash

2901: Test command: /home/julien/Software/Others/EnergyPlus-build/Products/Basement
2901: Working Directory: /home/julien/Software/Others/EnergyPlus-build/src/Basement/tst/AutoGriddingDepthIsHigh
2901: Environment variables: 
2901:  CI_BAIL_EARLY=1
2901: Test timeout computed to be: 10000000
2901:  Completed Reading Weather File
2901:  Done Parsing The Energyplus Weather File
2901: 
2901:  You have selected to use an equivalent foundation based on the
2901:  area to perimeter ratio supplied in the IDF file.
2901: 
2901: 
2901:  You have selected to have the solution grid sized automatically.
2901: 
2901:        YZ Wall TS         Inside      YZ Heat flux     Base T
2901:        XZ Wall TS         Inside      XZ Heat flux     Base T
2901:        Floor TS       Inside      Floor heat flux     Base T
2901:        YZ CL           XZ CL           FX CL           FY CL
2901:   TSYZUp    TSYZUpIn     TSYZLo     TSYZLoIn    Upper q     Lower q     Base T
2901:   TSXZUp    TSXZUpIn     TSXZLo     TSXZLoIn    Upper q     Lower q     Base T
2901:   TFPerim   TFPerimIn     TFCore    TFCoreIn      Perim q   Core q     Base T
2901: 
2901: Program received signal SIGBUS: Access to an undefined portion of a memory object.
2901: 
2901: Backtrace for this error:
2901: #0  0x5678a0 in ???
2901: #1  0x566ed5 in ???
2901: #2  0x5bc5df in ???
2901: #3  0x41f283 in __base3d_MOD_calctearth
2901: 	at /home/julien/Software/Others/EnergyPlus/src/Basement/3DBasementHT.f90:9875
2901: #4  0x42e6e4 in __base3d_MOD_basementsimulator
2901: 	at /home/julien/Software/Others/EnergyPlus/src/Basement/3DBasementHT.f90:2587
2901: #5  0x52218b in __base3d_MOD_simcontroller
2901: 	at /home/julien/Software/Others/EnergyPlus/src/Basement/3DBasementHT.f90:812
2901: #6  0x5221b9 in __base3d_MOD_base3ddriver
2901: 	at /home/julien/Software/Others/EnergyPlus/src/Basement/3DBasementHT.f90:731
2901: #7  0x5221ec in basementmodel
2901: 	at /home/julien/Software/Others/EnergyPlus/src/Basement/3DBasementHT.f90:13626
2901: #8  0x52227d in main
2901: 	at /home/julien/Software/Others/EnergyPlus/src/Basement/3DBasementHT.f90:13620
1/2 Test #2901: Basement.AutoGriddingDepthIsHigh .....Bus error***Exception:   1.48 sec
test 2902
    Start 2902: Basement.AutoGriddingDepthIsLowish

79 changes: 79 additions & 0 deletions src/Basement/tests/AutoGriddingDepthIsLowish.idf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
! Regular Auto Grid case, not exceeding any bounds

SimParameters,
0.1, !- F: Multiplier for the ADI solution
15; !- IYRS: Maximum number of yearly iterations:

MatlProps,
3, !- NMAT: Number of materials in this domain
2500, !- Density for Foundation Wall {kg/m3}
2500, !- density for Floor Slab {kg/m3}
2500, !- density for Ceiling {kg/m3}
1500, !- density for Soil {kg/m3}
2000, !- density for Gravel {kg/m3}
449, !- density for Wood {kg/m3}
880, !- Specific heat for foundation wall {J/kg-K}
880, !- Specific heat for floor slab {J/kg-K}
880, !- Specific heat for ceiling {J/kg-K}
2000, !- Specific heat for soil {J/kg-K}
720, !- Specific heat for gravel {J/kg-K}
1530, !- Specific heat for wood {J/kg-K}
2.3, !- Thermal conductivity for foundation wall {W/m-K}
2.3, !- Thermal conductivity for floor slab {W/m-K}
2.3, !- Thermal conductivity for ceiling {W/m-K}
1.5, !- thermal conductivity for soil {W/m-K}
1.9, !- thermal conductivity for gravel {W/m-K}
0.12; !- thermal conductivity for wood {W/m-K}

Insulation,
5, !- REXT: R Value of any exterior insulation {m2-K/W}
True; !- INSFULL: Flag: Is the wall fully insulated?

SurfaceProps,
0.4, !- ALBEDO: Surface albedo for No snow conditions
0.4, !- ALBEDO: Surface albedo for snow conditions
0.94, !- EPSLN: Surface emissivity No Snow
0.86, !- EPSLN: Surface emissivity with Snow
6, !- VEGHT: Surface roughness No snow conditions {cm}
0.25, !- VEGHT: Surface roughness Snow conditions {cm}
True; !- PET: Flag, Potential evapotranspiration on?

BldgData,
0.72, !- DWALL: Wall thickness {m}
0.25, !- DSLAB: Floor slab thickness {m}
0.3, !- DGRAVXY: Width of gravel pit beside basement wall {m}
0.2, !- DGRAVZN: Gravel depth extending above the floor slab {m}
0.3; !- DGRAVZP: Gravel depth below the floor slab {m}

Interior,
True, !- COND: Flag: Is the basement conditioned?
0.92, !- HIN: Downward convection only heat transfer coefficient {W/m2-K}
4.04, !- HIN: Upward convection only heat transfer coefficient {W/m2-K}
3.08, !- HIN: Horizontal convection only heat transfer coefficient {W/m2-K}
6.13, !- HIN: Downward combined (convection and radiation) heat transfer coefficient {W/m2-K}
9.26, !- HIN: Upward combined (convection and radiation) heat transfer coefficient {W/m2-K}
8.29; !- HIN: Horizontal combined (convection and radiation) heat transfer coefficient {W/m2-K}

ComBldg,
19.112521, !- January average temperature {C}
19.3265, !- February average temperature {C}
19.639847, !- March average temperature {C}
20.215454, !- April average temperature {C}
20.415274, !- May average temperature {C}
21.524396, !- June average temperature {C}
21.880071, !- July average temperature {C}
21.659116, !- August average temperature {C}
21.114287, !- September average temperature {C}
20.383342, !- October average temperature {C}
19.553359, !- November average temperature {C}
19.233107, !- December average temperature {C}
; !- Daily variation sine wave amplitude {deltaC}

EquivSlab,
20.045326, !- APRatio: The area to perimeter ratio for this slab {m}
TRUE; !- EquivSizing: Flag

EquivAutoGrid,
15, !- CLEARANCE: Distance from outside of wall to edge of 3-D ground domain {m}
0.25, !- SlabDepth: Thickness of the floor slab {m}
2.4; !- BaseDepth: Depth of the basement wall below grade {m}
Comment on lines +76 to +79
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test for a "regular" case when depth is lowish.

Loading
Loading