Skip to content

Commit

Permalink
fix(GweInputData): large GWE models were throwing stackoverflow error
Browse files Browse the repository at this point in the history
  • Loading branch information
emorway-usgs committed Aug 27, 2024
1 parent af26abf commit 16cac6d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 127 deletions.
3 changes: 0 additions & 3 deletions src/Model/Connection/GweInterfaceModel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ subroutine gweifmod_df(this)
this%ia => this%dis%con%ia
this%ja => this%dis%con%ja
!
! -- Define shared data (cpw, rhow, latent heat of vaporization)
call this%gwecommon%gweshared_dat_df(this%neq)
!
! -- Allocate model arrays, now that neq and nja are assigned
call this%allocate_arrays()
!
Expand Down
4 changes: 0 additions & 4 deletions src/Model/GroundWaterEnergy/gwe.f90
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ end subroutine gwe_cr
subroutine gwe_df(this)
! -- modules
use SimModule, only: store_error
use GweInputDataModule, only: gweshared_dat_df
! -- dummy
class(GweModelType) :: this
! -- local
Expand Down Expand Up @@ -181,9 +180,6 @@ subroutine gwe_df(this)
this%ia => this%dis%con%ia
this%ja => this%dis%con%ja
!
! -- Define shared data (cpw, rhow, latent heat of vaporization)
call this%gwecommon%gweshared_dat_df(this%neq)
!
! -- Allocate model arrays, now that neq and nja are assigned
call this%allocate_arrays()
!
Expand Down
181 changes: 61 additions & 120 deletions src/Model/ModelUtilities/GweInputData.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module GweInputDataModule
private
public :: GweInputDataType
public :: gweshared_dat_cr
public :: gweshared_dat_df
public :: set_gwe_dat_ptrs

!> Data for sharing among multiple packages. Originally read in from
Expand All @@ -30,78 +29,28 @@ module GweInputDataModule

contains

! -- public
procedure, public :: gweshared_dat_df
! public
procedure, public :: set_gwe_dat_ptrs
procedure, public :: gweshared_dat_da
! -- private
procedure, private :: allocate_shared_vars
procedure, private :: set_gwe_shared_scalars
procedure, private :: set_gwe_shared_arrays
! private
procedure, private :: set_gwe_scalar_ptrs
procedure, private :: set_gwe_array_ptrs

end type GweInputDataType

contains

!> @brief Allocate the shared data
!<
!> @brief Allocate the shared data
!<
subroutine gweshared_dat_cr(gwe_dat)
! -- modules
! -- dummy
! modules
! dummy
type(GweInputDataType), pointer :: gwe_dat !< the input data block
!
! -- Create the object

! create the object
allocate (gwe_dat)
!
! -- Return
return
end subroutine gweshared_dat_cr

!> @brief Define the shared data
!<
subroutine gweshared_dat_df(this, nodes)
! -- dummy
class(GweInputDataType) :: this !< the input data block
integer(I4B), intent(in) :: nodes
! -- local
!
! -- Allocate variables
call this%allocate_shared_vars(nodes)
!
! -- Return
return
end subroutine gweshared_dat_df

!> @brief Define the information this object holds
!!
!! Allocate strings for storing label names
!! Intended to be analogous to allocate_scalars()
!<
subroutine allocate_shared_vars(this, nodes)
! -- dummy
class(GweInputDataType) :: this !< TspLabelsType object
integer(I4B), intent(in) :: nodes
! -- local
integer(I4B) :: i
!
allocate (this%gwecpw)
allocate (this%gwerhow)
allocate (this%gwelatheatvap)
allocate (this%gwerhos(nodes))
allocate (this%gwecps(nodes))
!
! -- Initialize values
this%gwecpw = 4.184e3 !< J/(kg*C) @ 20C
this%gwerhow = DEP3 !< kg/m3 @ 20C
this%gwelatheatvap = 2.4535e6 !< J/kg @ 20C
do i = 1, nodes
this%gwecps(i) = DZERO
this%gwerhos(i) = DZERO
end do
!
! -- Return
return
end subroutine allocate_shared_vars
end subroutine gweshared_dat_cr

!> @brief Allocate and read data from EST
!!
Expand All @@ -110,24 +59,23 @@ end subroutine allocate_shared_vars
!! the aquifer material (cps), and density of the aquifer material
!! (rhow) is used among other packages and is therefore stored in a
!! separate class
!<
subroutine set_gwe_dat_ptrs(this, gwerhow, gwecpw, gwelatheatvap, &
gwerhos, gwecps)
! -- dummy
! dummy
class(GweInputDataType) :: this !< the input data block
real(DP), intent(in) :: gwerhow !< ptr to density of water specified in EST
real(DP), intent(in) :: gwecpw !< ptr to heat capacity of water specified in EST
real(DP), intent(in) :: gwelatheatvap !< ptr to latent heat of vaporization specified in EST
real(DP), intent(in), pointer :: gwerhow !< ptr to density of water specified in EST
real(DP), intent(in), pointer :: gwecpw !< ptr to heat capacity of water specified in EST
real(DP), intent(in), pointer :: gwelatheatvap !< ptr to latent heat of vaporization specified in EST
real(DP), dimension(:), pointer, contiguous :: gwerhos !< ptr to sptially-variably density of aquifer material specified in EST
real(DP), dimension(:), pointer, contiguous :: gwecps !< ptr to sptially-variably heat capacity of aquifer material specified in EST
!
! -- Allocate scalars
call this%set_gwe_shared_scalars(gwerhow, gwecpw, gwelatheatvap)
!
! -- Allocate arrays
call this%set_gwe_shared_arrays(gwerhos, gwecps)
!
! -- Return
return

! allocate scalars
call this%set_gwe_scalar_ptrs(gwerhow, gwecpw, gwelatheatvap)

! allocate arrays
call this%set_gwe_array_ptrs(gwerhos, gwecps)

end subroutine set_gwe_dat_ptrs

!> @brief Set pointers to scalars read by the EST package
Expand All @@ -138,68 +86,61 @@ end subroutine set_gwe_dat_ptrs
!! simulating evaporation will need access to latent heat of
!! of vaporization.
!<
subroutine set_gwe_shared_scalars(this, gwerhow, gwecpw, gwelatheatvap)
! -- dummy
subroutine set_gwe_scalar_ptrs(this, gwerhow, gwecpw, gwelatheatvap)
! dummy
class(GweInputDataType) :: this !< GweInputDataType object
real(DP), intent(in) :: gwerhow
real(DP), intent(in) :: gwecpw
real(DP), intent(in), optional :: gwelatheatvap
!
! -- Set the pointers
! -- Fixed density of water to be used by GWE
this%gwerhow = gwerhow
! -- Spatially constant heat capacity of water ! kluge note: "specific heat" (which is heat capacity per unit mass) is probably the more correct term
this%gwecpw = gwecpw
! -- Latent heat of vaporization
real(DP), pointer, intent(in) :: gwerhow !< density of water
real(DP), pointer, intent(in) :: gwecpw !< mass-based heat capacity of water
real(DP), pointer, intent(in), optional :: gwelatheatvap !< latent heat of vaporization

! set the pointers
! fixed density of water to be used by GWE (vs GWT-based density)
this%gwerhow => gwerhow
! spatially constant heat capacity of water ! kluge note: "specific heat" (which is heat capacity per unit mass) is probably the more correct term
this%gwecpw => gwecpw
! latent heat of vaporization
if (present(gwelatheatvap)) then
this%gwelatheatvap = gwelatheatvap
this%gwelatheatvap => gwelatheatvap
end if
!
! -- Return
return
end subroutine set_gwe_shared_scalars

end subroutine set_gwe_scalar_ptrs

!> @brief Set pointers to data arrays read by the EST package
!! for use by other packages
!!
!! Set pointers to GWE-related arrays for use
!! by multiple packages.
!! Set pointers to GWE-related arrays for use by multiple packages
!<
subroutine set_gwe_shared_arrays(this, gwerhos, gwecps)
! -- dummy
subroutine set_gwe_array_ptrs(this, gwerhos, gwecps)
! dummy
class(GweInputDataType) :: this !< GweInputDataType object
real(DP), dimension(:), pointer, contiguous, intent(in) :: gwerhos
real(DP), dimension(:), pointer, contiguous, intent(in) :: gwecps
!
! -- Set the pointers
! -- Spatially-variable density of aquifer solid material
this%gwerhos = gwerhos
! -- Spatially-variable heat capacity of aquifer solid material
this%gwecps = gwecps
!
! -- Return
return
end subroutine set_gwe_shared_arrays

! set the pointers
! spatially-variable density of aquifer solid material
this%gwerhos => gwerhos
! spatially-variable heat capacity of aquifer solid material
this%gwecps => gwecps

end subroutine set_gwe_array_ptrs

!> @ brief Deallocate memory
!!
!! Deallocate GWE shared data array memory
!! Set pointers to null
!<
subroutine gweshared_dat_da(this)
! -- dummy
! dummy
class(GweInputDataType) :: this !< the input data block
!
! -- Scalars
deallocate (this%gwelatheatvap)
deallocate (this%gwerhow)
deallocate (this%gwecpw)
!
! -- Arrays
deallocate (this%gwerhos)
deallocate (this%gwecps)
!
! -- Return
return

! scalars
this%gwelatheatvap => null()
this%gwerhow => null()
this%gwecpw => null()

! arrays
this%gwerhos => null()
this%gwecps => null()

end subroutine gweshared_dat_da

end module GweInputDataModule

0 comments on commit 16cac6d

Please sign in to comment.