Skip to content

Commit 9a93eeb

Browse files
authored
add swr to options block of sfe (#16)
1 parent 9d416b1 commit 9a93eeb

File tree

3 files changed

+177
-3
lines changed

3 files changed

+177
-3
lines changed

autotest/test_gwe_sfe_swr00.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
[10.0],
5656
]
5757
# shortwave radiation parameter values
58-
solr = 4788.08709 # unrealistically high to drive a 1 deg C rise in stream temperature
58+
solr = 47880870.9 # unrealistically high to drive a 1 deg C rise in stream temperature
5959
shd = 0.1
6060
swrefl = 0.03
6161

@@ -435,7 +435,7 @@ def check_output(idx, test):
435435
df = pd.read_csv(fpth)
436436
calc_strm_wid = df.loc[0, "RCH1_WETWIDTH"].copy()
437437
# confirm stream width is 1.0 m
438-
assert np.isclose(calc_strm_wid, 1.0, atol=1e-9), msg0
438+
assert np.isclose(calc_strm_wid, 1.0, atol=1e-7), msg0
439439

440440
# confirm that the energy added to the stream results in a 1 deg C rise in temp
441441
# temperature gradient
@@ -458,7 +458,7 @@ def check_output(idx, test):
458458
)
459459

460460
assert np.isclose(df.loc[0, "RCH1_OUTFTEMP"], strm_temp + temp_rise, atol=1e-5), (
461-
msg1
461+
msg1 + " " + str(df.loc[0, "RCH1_OUTFTEMP"])
462462
)
463463

464464

doc/mf6io/mf6ivar/dfn/gwe-sfe.dfn

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,38 @@ tagged false
286286
longname file name of SHF information
287287
description defines a sensible heat flux (SHF) input file. Records in the SHF file are used to calculate the flux of thermal energy in or out of a stream reach resulting from sensible heat exchange.
288288

289+
block options
290+
name swr_filerecord
291+
type record swr6 filein swr6_filename
292+
shape
293+
reader urword
294+
tagged true
295+
optional true
296+
longname
297+
description
298+
299+
block options
300+
name swr6
301+
type keyword
302+
shape
303+
in_record true
304+
reader urword
305+
tagged true
306+
optional false
307+
longname swr keyword
308+
description keyword to specify that record corresponds to the shortwave radiation (SWR) file. The behavior of the SWR utility and a description of the input file is provided separately.
309+
310+
block options
311+
name swr6_filename
312+
type string
313+
preserve_case true
314+
in_record true
315+
reader urword
316+
optional false
317+
tagged false
318+
longname file name of SWR information
319+
description defines a shortwave radiation (SWR) input file. Records in the SWR file are used to calculate the flux of thermal energy in or out of a stream reach resulting from shortwave radiation heat flux.
320+
289321
# --------------------- gwe sfe packagedata ---------------------
290322

291323
block packagedata

src/Model/GroundWaterEnergy/gwe-sfe.f90

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
! -- SFE terms
2424
! STRMBD-COND idxbudsbcd STRMBD-COND ktf * wa / sbthk * (t_cell - t_feat)
2525
! SENSIBLE HEAT FLUX idxbudshf SENS HEAT cd * rho_a * C_p_a * wspd * (t_air - t_feat)
26+
! SHORTWAVE RADIATION idxbudsWR SHORTWAVE (1 - shd) * (1 - swrefl) * solr
2627

2728
! -- terms from a flow file that should be skipped
2829
! CONSTANT none none none
@@ -49,6 +50,7 @@ module GweSfeModule
4950
apt_process_obsID12
5051
use GweInputDataModule, only: GweInputDataType
5152
use SensHeatModule, only: ShfType, shf_cr
53+
use ShortwaveModule, only: SwrType, swr_cr
5254
use MatrixBaseModule
5355
use InputOutputModule, only: openfile
5456
!
@@ -72,6 +74,7 @@ module GweSfeModule
7274
integer(I4B), pointer :: idxbudoutf => null() !< index of outflow terms in flowbudptr
7375

7476
logical, pointer, public :: shf_active => null() !< logical indicating if a sensible heat flux object is active
77+
logical, pointer, public :: swr_active => null() !< logical indicating if a shortwave radition heat flux object is active
7578

7679
real(DP), dimension(:), pointer, contiguous :: temprain => null() !< rainfall temperature
7780
real(DP), dimension(:), pointer, contiguous :: tempevap => null() !< evaporation temperature
@@ -81,7 +84,10 @@ module GweSfeModule
8184
real(DP), dimension(:), pointer, contiguous :: rfeatthk => null() !< thickness of streambed material through which thermal conduction occurs
8285

8386
type(ShfType), pointer :: shf => null() ! sensible heat flux (shf) object
87+
type(SwrType), pointer :: swr => null() ! shortwave radiation heat flux (swr) object
88+
8489
integer(I4B), pointer :: inshf => null() ! SHF (sensible heat flux utility) unit number (0 if unused)
90+
integer(I4B), pointer :: inswr => null() ! SWR (shortwave radiation heat flux utility) unit number (0 if unused)
8591

8692
contains
8793

@@ -104,6 +110,7 @@ module GweSfeModule
104110
procedure :: sfe_outf_term
105111
procedure, private :: sfe_sbcd_term
106112
procedure, private :: sfe_shf_term
113+
procedure, private :: sfe_swr_term
107114
procedure :: pak_df_obs => sfe_df_obs
108115
procedure :: pak_rp_obs => sfe_rp_obs
109116
procedure :: pak_bd_obs => sfe_bd_obs
@@ -231,6 +238,37 @@ subroutine sfe_options(this, option, found)
231238
! would be from bnd_ar(), however, shf is only callable from
232239
! sfe and not apt.
233240
call this%shf%ar()
241+
case ('SWR6')
242+
!
243+
call this%parser%GetStringCaps(keyword)
244+
if (trim(adjustl(keyword)) /= 'FILEIN') then
245+
errmsg = 'SWR6 keyword must be followed by "FILEIN" '// &
246+
'then by filename.'
247+
call store_error(errmsg)
248+
call this%parser%StoreErrorUnit()
249+
end if
250+
if (this%swr_active) then
251+
errmsg = 'Multiple SWR6 keywords detected in OPTIONS block. '// &
252+
'Only one SWR6 entry allowed for a package.'
253+
call store_error(errmsg)
254+
end if
255+
this%swr_active = .true.
256+
call this%parser%GetString(fname)
257+
!
258+
! -- create sensible heat flux object
259+
call openfile(this%inswr, this%iout, fname, 'SWR')
260+
call swr_cr(this%swr, this%name_model, this%inswr, this%iout, this%ncv)
261+
this%swr%inputFilename = fname
262+
!
263+
! -- call _ar routine for swr sub-package
264+
! note: this is the best place to call the sub-package (swr) for
265+
! now because SFE does not override apt_ar(), and since sfe
266+
! does not run its own customized set of _ar() functionality
267+
! there is no opportunity to run swr%ar() from a more
268+
! natural point. In other words, one place to call swr%ar
269+
! would be from bnd_ar(), however, swr is only callable from
270+
! sfe and not apt.
271+
call this%swr%ar()
234272
case default
235273
!
236274
! -- No options found
@@ -465,6 +503,16 @@ subroutine sfe_fc_expanded(this, rhs, ia, idxglo, matrix_sln)
465503
rhs(iloc) = rhs(iloc) + rhsval
466504
end do
467505
end if
506+
! -- Add shortwave radiation heat flux contribution
507+
if (this%inswr /= 0) then
508+
do j = 1, this%flowbudptr%budterm(this%idxbudgwf)%nlist
509+
call this%sfe_swr_term(j, n1, n2, rrate, rhsval, hcofval)
510+
iloc = this%idxlocnode(n1)
511+
iposd = this%idxpakdiag(n1)
512+
call matrix_sln%add_value_pos(iposd, hcofval)
513+
rhs(iloc) = rhs(iloc) + rhsval
514+
end do
515+
end if
468516
end subroutine sfe_fc_expanded
469517

470518
!> @ brief Add terms specific to sfr to the explicit sfe solve
@@ -547,6 +595,9 @@ function sfe_get_nbudterms(this) result(nbudterms)
547595
if (this%inshf /= 0) then
548596
nbudterms = nbudterms + 1
549597
end if
598+
if (this%inswr /= 0) then
599+
nbudterms = nbudterms + 1
600+
end if
550601
!
551602
end function sfe_get_nbudterms
552603

@@ -670,6 +721,27 @@ subroutine sfe_setup_budobj(this, idx)
670721
call this%budobj%budterm(idx)%update_term(n1, n2, q)
671722
end do
672723
end if
724+
! -- Shortwave radiation heat flux
725+
if (this%inswr /= 0) then
726+
text = ' SHORTWAVE-RADIATION'
727+
idx = idx + 1
728+
maxlist = this%flowbudptr%budterm(this%idxbudgwf)%maxlist
729+
naux = 0
730+
call this%budobj%budterm(idx)%initialize(text, &
731+
this%name_model, &
732+
this%packName, &
733+
this%name_model, &
734+
this%packName, &
735+
maxlist, .false., .false., &
736+
naux)
737+
call this%budobj%budterm(idx)%reset(maxlist)
738+
q = DZERO
739+
do n = 1, maxlist
740+
n1 = this%flowbudptr%budterm(this%idxbudgwf)%id1(n)
741+
n2 = this%flowbudptr%budterm(this%idxbudgwf)%id2(n)
742+
call this%budobj%budterm(idx)%update_term(n1, n2, q)
743+
end do
744+
end if
673745
end subroutine sfe_setup_budobj
674746

675747
!> @brief Copy flow terms into this%budobj
@@ -771,6 +843,17 @@ subroutine sfe_fill_budobj(this, idx, x, flowja, ccratin, ccratout)
771843
call this%apt_accumulate_ccterm(n1, q, ccratin, ccratout)
772844
end do
773845
end if
846+
! -- Shortwave-radiation
847+
if (this%inswr /= 0) then
848+
idx = idx + 1
849+
nlist = this%flowbudptr%budterm(this%idxbudgwf)%nlist
850+
call this%budobj%budterm(idx)%reset(nlist)
851+
do j = 1, nlist
852+
call this%sfe_swr_term(j, n1, n2, q)
853+
call this%budobj%budterm(idx)%update_term(n1, n2, q)
854+
call this%apt_accumulate_ccterm(n1, q, ccratin, ccratout)
855+
end do
856+
end if
774857
end subroutine sfe_fill_budobj
775858

776859
!> @brief Allocate scalars specific to the streamflow energy transport (SFE)
@@ -792,7 +875,9 @@ subroutine allocate_scalars(this)
792875
call mem_allocate(this%idxbudiflw, 'IDXBUDIFLW', this%memoryPath)
793876
call mem_allocate(this%idxbudoutf, 'IDXBUDOUTF', this%memoryPath)
794877
call mem_allocate(this%shf_active, 'SHF_ACTIVE', this%memoryPath)
878+
call mem_allocate(this%swr_active, 'SWR_ACTIVE', this%memoryPath)
795879
call mem_allocate(this%inshf, 'INSHF', this%memoryPath)
880+
call mem_allocate(this%inswr, 'INSWR', this%memoryPath)
796881
!
797882
! -- Initialize
798883
this%idxbudrain = 0
@@ -802,7 +887,9 @@ subroutine allocate_scalars(this)
802887
this%idxbudoutf = 0
803888
!
804889
this%shf_active = .false.
890+
this%swr_active = .false.
805891
this%inshf = 0
892+
this%inswr = 0
806893
end subroutine allocate_scalars
807894

808895
!> @brief Allocate arrays specific to the streamflow energy transport (SFE)
@@ -837,6 +924,9 @@ subroutine sfe_allocate_arrays(this)
837924
if (this%inshf /= 0) then
838925
call this%shf%pbst_allocate_arrays()
839926
end if
927+
if (this%inswr /= 0) then
928+
call this%swr%pbst_allocate_arrays()
929+
end if
840930
end subroutine sfe_allocate_arrays
841931

842932
!> @brief Call Read and prepare routines for any active pbst subpackages
@@ -853,6 +943,10 @@ subroutine pbst_rp(this)
853943
if (this%inshf /= 0) then
854944
call this%shf%rp()
855945
end if
946+
! -- call shortwave radiation heat flux sub-package _rp() routine
947+
if (this%inswr /= 0) then
948+
call this%swr%rp()
949+
end if
856950
end subroutine pbst_rp
857951

858952
!> @brief Deallocate memory
@@ -868,6 +962,11 @@ subroutine sfe_da(this)
868962
call this%shf%da()
869963
deallocate (this%shf)
870964
end if
965+
! -- SWR (shortwave radiation heat flux)
966+
if (this%inswr /= 0) then
967+
call this%swr%da()
968+
deallocate (this%swr)
969+
end if
871970
!
872971
! -- Deallocate scalars
873972
call mem_deallocate(this%idxbudrain)
@@ -877,7 +976,9 @@ subroutine sfe_da(this)
877976
call mem_deallocate(this%idxbudoutf)
878977
!
879978
call mem_deallocate(this%shf_active)
979+
call mem_deallocate(this%swr_active)
880980
call mem_deallocate(this%inshf)
981+
call mem_deallocate(this%inswr)
881982
!
882983
! -- Deallocate time series
883984
call mem_deallocate(this%temprain)
@@ -1090,6 +1191,36 @@ subroutine sfe_shf_term(this, ientry, n1, n2, rrate, rhsval, hcofval)
10901191
if (present(hcofval)) hcofval = DZERO
10911192
end subroutine sfe_shf_term
10921193

1194+
!> @brief Shortwave Radiation (SWR) term
1195+
!<
1196+
subroutine sfe_swr_term(this, ientry, n1, n2, rrate, rhsval, hcofval)
1197+
! -- dummy
1198+
class(GweSfeType) :: this
1199+
integer(I4B), intent(in) :: ientry
1200+
integer(I4B), intent(inout) :: n1
1201+
integer(I4B), intent(inout) :: n2
1202+
real(DP), intent(inout), optional :: rrate
1203+
real(DP), intent(inout), optional :: rhsval
1204+
real(DP), intent(inout), optional :: hcofval
1205+
! -- local
1206+
real(DP) :: shrtwvheat
1207+
real(DP) :: strmtemp
1208+
integer(I4B) :: auxpos
1209+
real(DP) :: sa !< surface area of stream reach, different than wetted area
1210+
!
1211+
n1 = this%flowbudptr%budterm(this%idxbudevap)%id1(ientry)
1212+
! -- For now, there is only 1 aux variable under 'EVAPORATION'
1213+
auxpos = this%flowbudptr%budterm(this%idxbudevap)%naux
1214+
sa = this%flowbudptr%budterm(this%idxbudevap)%auxvar(auxpos, ientry)
1215+
!
1216+
strmtemp = this%xnewpak(n1)
1217+
call this%swr%swr_cq(n1, shrtwvheat)
1218+
!
1219+
if (present(rrate)) rrate = shrtwvheat * sa
1220+
if (present(rhsval)) rhsval = -rrate
1221+
if (present(hcofval)) hcofval = DZERO
1222+
end subroutine sfe_swr_term
1223+
10931224
!> @brief Observations
10941225
!!
10951226
!! Store the observation type supported by the APT package and override
@@ -1171,6 +1302,11 @@ subroutine sfe_df_obs(this)
11711302
! for sens-heat-flux observation type.
11721303
call this%obs%StoreObsType('shf', .true., indx)
11731304
this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsID
1305+
!
1306+
! -- Store obs type and assign procedure pointer
1307+
! for shortwave-radiation-flux observation type.
1308+
call this%obs%StoreObsType('swr', .true., indx)
1309+
this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsID
11741310
end subroutine sfe_df_obs
11751311

11761312
!> @brief Process package specific obs
@@ -1202,6 +1338,8 @@ subroutine sfe_rp_obs(this, obsrv, found)
12021338
call this%rp_obs_byfeature(obsrv)
12031339
case ('SHF')
12041340
call this%rp_obs_byfeature(obsrv)
1341+
case ('SWR')
1342+
call this%rp_obs_byfeature(obsrv)
12051343
case default
12061344
found = .false.
12071345
end select
@@ -1249,6 +1387,10 @@ subroutine sfe_bd_obs(this, obstypeid, jj, v, found)
12491387
if (this%iboundpak(jj) /= 0) then
12501388
call this%sfe_shf_term(jj, n1, n2, v)
12511389
end if
1390+
case ('SWR')
1391+
if (this%iboundpak(jj) /= 0) then
1392+
call this%sfe_swr_term(jj, n1, n2, v)
1393+
end if
12521394
case default
12531395
found = .false.
12541396
end select

0 commit comments

Comments
 (0)