Skip to content

Commit c7c0848

Browse files
committed
checking in today's progress. Reworked some of the previous code that unfortunately had some bad wiring
1 parent aae88d1 commit c7c0848

File tree

3 files changed

+178
-29
lines changed

3 files changed

+178
-29
lines changed

src/Model/GroundWaterEnergy/PbstBase.f90

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
!! flux.
88
!<
99
module PbstBaseModule
10-
use ConstantsModule, only: LINELENGTH, MAXCHARLEN, DZERO
10+
use ConstantsModule, only: LINELENGTH, MAXCHARLEN, DZERO, LGP
1111
use KindModule, only: I4B, DP
1212
use NumericalPackageModule, only: NumericalPackageType
1313
use SimModule, only: count_errors, store_error, ustop
@@ -34,13 +34,32 @@ module PbstBaseModule
3434
contains
3535

3636
procedure :: init
37+
procedure :: ar
38+
procedure, private :: read_options
39+
procedure :: pbst_options
40+
procedure(read_option), deferred :: read_option
3741
procedure, private :: pbstbase_allocate_scalars
3842
procedure :: da => pbstbase_da
3943

4044
end type PbstBaseType
4145

4246
abstract interface
4347

48+
!> @brief Announce package and set pointers to variables
49+
!!
50+
!! Deferred procedure called by the PbstBaseType code to process a single
51+
!! keyword from the OPTIONS block of the package input file.
52+
!<
53+
function read_option(this, keyword) result(success)
54+
! -- modules
55+
import PbstBaseType
56+
! -- dummy
57+
class(PbstBaseType) :: this
58+
character(len=*), intent(in) :: keyword
59+
! -- return
60+
logical :: success
61+
end function
62+
4463
end interface
4564

4665
contains
@@ -65,7 +84,108 @@ subroutine init(this, name_model, pakname, ftype, inunit, iout)
6584
call this%parser%Initialize(this%inunit, this%iout)
6685
end subroutine init
6786

68-
87+
!> @brief Allocate and read
88+
!!
89+
!! Method to allocate and read static data for the SHF package
90+
!<
91+
subroutine ar(this)
92+
! -- dummy
93+
class(PbstBaseType) :: this !< ShfType object
94+
!
95+
! -- Create time series manager
96+
call tsmanager_cr(this%tsmanager, this%iout, &
97+
removeTsLinksOnCompletion=.true., &
98+
extendTsToEndOfSimulation=.true.)
99+
!
100+
! -- Read options
101+
call this%read_options()
102+
end subroutine ar
103+
104+
105+
!> @brief Read the SHF-specific options from the OPTIONS block
106+
!<
107+
subroutine read_options(this)
108+
! -- dummy
109+
class(PbstBaseType) :: this
110+
! -- local
111+
character(len=LINELENGTH) :: keyword
112+
character(len=MAXCHARLEN) :: fname
113+
logical :: isfound
114+
logical :: endOfBlock
115+
logical(LGP) :: foundchildclassoption
116+
integer(I4B) :: ierr
117+
! -- formats
118+
character(len=*), parameter :: fmtts = &
119+
&"(4x, 'TIME-SERIES DATA WILL BE READ FROM FILE: ', a)"
120+
!
121+
! -- Get options block
122+
call this%parser%GetBlock('OPTIONS', isfound, ierr, &
123+
blockRequired=.false., supportOpenClose=.true.)
124+
!
125+
! -- Parse options block if detected
126+
if (isfound) then
127+
write (this%iout, '(1x,a)') &
128+
'PROCESSING '//trim(adjustl(this%packName))//' OPTIONS'
129+
do
130+
call this%parser%GetNextLine(endOfBlock)
131+
if (endOfBlock) then
132+
exit
133+
end if
134+
call this%parser%GetStringCaps(keyword)
135+
select case (keyword)
136+
case ('PRINT_INPUT')
137+
this%iprpak = 1
138+
write (this%iout, '(4x,a)') 'TIME-VARYING INPUT WILL BE PRINTED.'
139+
case ('TS6')
140+
!
141+
! -- Add a time series file
142+
call this%parser%GetStringCaps(keyword)
143+
if (trim(adjustl(keyword)) /= 'FILEIN') then
144+
errmsg = &
145+
'TS6 keyword must be followed by "FILEIN" then by filename.'
146+
call store_error(errmsg)
147+
call this%parser%StoreErrorUnit()
148+
call ustop()
149+
end if
150+
call this%parser%GetString(fname)
151+
write (this%iout, fmtts) trim(fname)
152+
call this%tsmanager%add_tsfile(fname, this%inunit)
153+
case default
154+
!
155+
! -- Check for child class options
156+
call this%pbst_options(keyword, foundchildclassoption)
157+
!
158+
! -- Defer to subtype to read the option;
159+
! -- if the subtype can't handle it, report an error
160+
if (.not. this%read_option(keyword)) then
161+
write (errmsg, '(a,3(1x,a),a)') &
162+
'Unknown', trim(adjustl(this%packName)), "option '", &
163+
trim(keyword), "'."
164+
call store_error(errmsg)
165+
end if
166+
end select
167+
end do
168+
write (this%iout, '(1x,a)') &
169+
'END OF '//trim(adjustl(this%packName))//' OPTIONS'
170+
end if
171+
end subroutine read_options
172+
173+
!> @ brief Read additional options for sub-package
174+
!!
175+
!! Read additional options for the SFE boundary package. This method should
176+
!! be overridden by option-processing routine that is in addition to the
177+
!! base options available for all PbstBase packages.
178+
!<
179+
subroutine pbst_options(this, option, found)
180+
! -- dummy
181+
class(PbstBaseType), intent(inout) :: this !< PbstBaseType object
182+
character(len=*), intent(inout) :: option !< option keyword string
183+
logical(LGP), intent(inout) :: found !< boolean indicating if the option was found
184+
!
185+
! Return with found = .false.
186+
found = .false.
187+
end subroutine pbst_options
188+
69189
!> @brief Allocate scalar variables
70190
!!
71191
!! Allocate scalar data members of the object.

src/Model/GroundWaterEnergy/gwe-sfe.f90

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,23 @@ module GweSfeModule
6969
integer(I4B), pointer :: idxbudoutf => null() !< index of outflow terms in flowbudptr
7070
integer(I4B), pointer :: idxbudsbcd => null() !< index of streambed conduction terms in flowbudptr
7171

72+
logical, pointer, public :: shf_active => null() !< logical indicating if a sensible heat flux object is active
73+
7274
real(DP), dimension(:), pointer, contiguous :: temprain => null() !< rainfall temperature
7375
real(DP), dimension(:), pointer, contiguous :: tempevap => null() !< evaporation temperature
7476
real(DP), dimension(:), pointer, contiguous :: temproff => null() !< runoff temperature
7577
real(DP), dimension(:), pointer, contiguous :: tempiflw => null() !< inflow temperature
7678
real(DP), dimension(:), pointer, contiguous :: ktf => null() !< thermal conductivity between the sfe and groundwater cell
7779
real(DP), dimension(:), pointer, contiguous :: rfeatthk => null() !< thickness of streambed material through which thermal conduction occurs
78-
80+
7981
type(ShfType), pointer :: shf => null() ! sensible heat flux (shf) object
8082
integer(I4B), pointer :: inshf => null() ! SHF (sensible heat flux utility) unit number (0 if unused)
8183

8284
contains
8385

8486
!procedure :: bnd_df => sfe_df
8587
procedure :: bnd_da => sfe_da
88+
procedure :: bnd_ar => sfe_ar
8689
procedure :: allocate_scalars
8790
procedure :: apt_allocate_arrays => sfe_allocate_arrays
8891
procedure :: find_apt_package => find_sfe_package
@@ -170,10 +173,6 @@ subroutine sfe_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, &
170173
sfeobj%depvartype = dvt
171174
sfeobj%depvarunit = dvu
172175
sfeobj%depvarunitabbrev = dvua
173-
!
174-
! -- create sensible heat flux package
175-
inshf = GetUnit()
176-
call shf_cr(sfeobj%shf, namemodel, inshf, iout)
177176
end subroutine sfe_create
178177

179178
!> @brief Override boundary package type define function
@@ -200,11 +199,11 @@ subroutine sfe_ar(this)
200199
class(GweSfeType), intent(inout) :: this
201200
!
202201
! -- call parent class _ar routine
203-
call this%tspapttype%bndtype%bnd_ar()
202+
call this%tspapttype%bnd_ar()
204203
!
205204
! -- activate appropriate pbst sub-packages
206205
if (this%inshf /= 0) then
207-
call this%shf%shf_ar()
206+
call this%shf%ar()
208207
end if
209208
end subroutine sfe_ar
210209

@@ -250,24 +249,26 @@ subroutine sfe_options(this, option, found)
250249
found = .true.
251250
select case (option)
252251
case ('SHF6')
252+
!
253253
call this%parser%GetStringCaps(keyword)
254254
if (trim(adjustl(keyword)) /= 'FILEIN') then
255255
errmsg = 'SHF6 keyword must be followed by "FILEIN" '// &
256256
'then by filename.'
257257
call store_error(errmsg)
258258
call this%parser%StoreErrorUnit()
259259
end if
260-
if (this%shf%active) then
260+
if (this%shf_active) then
261261
errmsg = 'Multiple SHF6 keywords detected in OPTIONS block. '// &
262262
'Only one SHF6 entry allowed for a package.'
263263
call store_error(errmsg)
264264
end if
265-
this%shf%active = .true.
265+
this%shf_active = .true.
266266
call this%parser%GetString(fname)
267+
!
268+
! -- create sensible heat flux object
269+
call openfile(this%inshf, this%iout, fname, 'SHF')
270+
call shf_cr(this%shf, this%name_model, this%inshf, this%iout)
267271
this%shf%inputFilename = fname
268-
!inshf = GetUnit()
269-
call openfile(this%inshf, this%iout, this%shf%inputFilename, 'SHF')
270-
!this%shf%inunit = inshf
271272
case default
272273
!
273274
! -- No options found
@@ -795,6 +796,7 @@ subroutine allocate_scalars(this)
795796
call mem_allocate(this%idxbudiflw, 'IDXBUDIFLW', this%memoryPath)
796797
call mem_allocate(this%idxbudoutf, 'IDXBUDOUTF', this%memoryPath)
797798
call mem_allocate(this%idxbudsbcd, 'IDXBUDSBCD', this%memoryPath)
799+
call mem_allocate(this%shf_active, 'SHF_ACTIVE', this%memoryPath)
798800
call mem_allocate(this%inshf, 'INSHF', this%memoryPath)
799801
!
800802
! -- Initialize
@@ -804,6 +806,7 @@ subroutine allocate_scalars(this)
804806
this%idxbudiflw = 0
805807
this%idxbudoutf = 0
806808
this%idxbudsbcd = 0
809+
this%shf_active = .false.
807810
this%inshf = 0
808811
end subroutine allocate_scalars
809812

@@ -857,6 +860,7 @@ subroutine sfe_da(this)
857860
call mem_deallocate(this%idxbudiflw)
858861
call mem_deallocate(this%idxbudoutf)
859862
call mem_deallocate(this%idxbudsbcd)
863+
call mem_deallocate(this%shf_active)
860864
call mem_deallocate(this%inshf)
861865
!
862866
! -- Deallocate time series

src/Model/GroundWaterEnergy/gwe-shf.f90

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ module SensHeatModule
3333

3434
contains
3535

36-
procedure, public :: shf_ar
3736
procedure :: da => shf_da
37+
procedure :: read_option => shf_read_option
38+
procedure :: pbst_options => shf_options
39+
procedure, private :: shf_allocate_scalars
3840

3941
end type ShfType
4042

@@ -56,24 +58,14 @@ subroutine shf_cr(shf, name_model, inunit, iout)
5658
call shf%init(name_model, 'SHF', 'SHF', inunit, iout)
5759
!
5860
! -- allocate scalars
59-
call shf%allocate_scalars()
61+
call shf%shf_allocate_scalars()
6062
end subroutine shf_cr
6163

62-
!> @brief Allocate and read
63-
!!
64-
!! Method to read and prepare period data for the SHF package
65-
!<
66-
subroutine shf_ar(this)
67-
! -- dummy
68-
class(ShfType), intent(out) :: this !< ShfType object
69-
!
70-
71-
end subroutine shf_ar
7264

7365
!> @brief Allocate scalars specific to the streamflow energy transport (SFE)
7466
!! package.
7567
!<
76-
subroutine allocate_scalars(this)
68+
subroutine shf_allocate_scalars(this)
7769
! -- modules
7870
use MemoryManagerModule, only: mem_allocate
7971
! -- dummy
@@ -88,7 +80,7 @@ subroutine allocate_scalars(this)
8880
this%rhoa = 1.225 ! kg/m3
8981
this%cpa = 717.0 ! J/kg/C
9082
this%cd = 0.002 ! unitless
91-
end subroutine allocate_scalars
83+
end subroutine shf_allocate_scalars
9284

9385
!> @brief Allocate arrays specific to the sensible heat flux (SHF) package
9486
!<
@@ -111,6 +103,23 @@ subroutine shf_allocate_arrays(this)
111103
end do
112104
end subroutine
113105

106+
!> @brief Set options specific to the ShfType
107+
!!
108+
!! This routine overrides PbstBaseType%bnd_options
109+
!<
110+
subroutine shf_options(this, option, found)
111+
112+
found = .true.
113+
foundgcclassoption = .false.
114+
select case (option)
115+
case ('FLOW_PACKAGE_NAME')
116+
call this%parser%GetStringCaps(this%flowpackagename)
117+
write (this%iout, '(4x,a)') &
118+
'THIS '//trim(adjustl(this%text))//' PACKAGE CORRESPONDS TO A GWF &
119+
&PACKAGE WITH THE NAME '//trim(adjustl(this%flowpackagename))
120+
121+
end subroutine shf_options
122+
114123
!> @brief Deallocate package memory
115124
!!
116125
!! Deallocate TVK package scalars and arrays.
@@ -129,5 +138,21 @@ subroutine shf_da(this)
129138
! -- Deallocate parent
130139
call pbstbase_da(this)
131140
end subroutine shf_da
132-
141+
142+
!> @brief Read a SHF-specific option from the OPTIONS block
143+
!!
144+
!! Process a single SHF-specific option. Used when reading the OPTIONS block
145+
!! of the SHF package input file.
146+
!<
147+
function shf_read_option(this, keyword) result(success)
148+
! -- dummy
149+
class(ShfType) :: this
150+
character(len=*), intent(in) :: keyword
151+
! -- return
152+
logical :: success
153+
!
154+
! -- There are no TVK-specific options, so just return false
155+
success = .false.
156+
end function shf_read_option
157+
133158
end module SensHeatModule

0 commit comments

Comments
 (0)