Skip to content

Commit 4c78690

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

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
@@ -70,20 +70,23 @@ module GweSfeModule
7070
integer(I4B), pointer :: idxbudiflw => null() !< index of inflow terms in flowbudptr
7171
integer(I4B), pointer :: idxbudoutf => null() !< index of outflow terms in flowbudptr
7272

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

8385
contains
8486

8587
!procedure :: bnd_df => sfe_df
8688
procedure :: bnd_da => sfe_da
89+
procedure :: bnd_ar => sfe_ar
8790
procedure :: allocate_scalars
8891
procedure :: apt_allocate_arrays => sfe_allocate_arrays
8992
procedure :: find_apt_package => find_sfe_package
@@ -172,10 +175,6 @@ subroutine sfe_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, &
172175
sfeobj%depvartype = dvt
173176
sfeobj%depvarunit = dvu
174177
sfeobj%depvarunitabbrev = dvua
175-
!
176-
! -- create sensible heat flux package
177-
inshf = GetUnit()
178-
call shf_cr(sfeobj%shf, namemodel, inshf, iout)
179178
end subroutine sfe_create
180179

181180
!> @brief Override boundary package type define function
@@ -202,11 +201,11 @@ subroutine sfe_ar(this)
202201
class(GweSfeType), intent(inout) :: this
203202
!
204203
! -- call parent class _ar routine
205-
call this%tspapttype%bndtype%bnd_ar()
204+
call this%tspapttype%bnd_ar()
206205
!
207206
! -- activate appropriate pbst sub-packages
208207
if (this%inshf /= 0) then
209-
call this%shf%shf_ar()
208+
call this%shf%ar()
210209
end if
211210
end subroutine sfe_ar
212211

@@ -252,24 +251,26 @@ subroutine sfe_options(this, option, found)
252251
found = .true.
253252
select case (option)
254253
case ('SHF6')
254+
!
255255
call this%parser%GetStringCaps(keyword)
256256
if (trim(adjustl(keyword)) /= 'FILEIN') then
257257
errmsg = 'SHF6 keyword must be followed by "FILEIN" '// &
258258
'then by filename.'
259259
call store_error(errmsg)
260260
call this%parser%StoreErrorUnit()
261261
end if
262-
if (this%shf%active) then
262+
if (this%shf_active) then
263263
errmsg = 'Multiple SHF6 keywords detected in OPTIONS block. '// &
264264
'Only one SHF6 entry allowed for a package.'
265265
call store_error(errmsg)
266266
end if
267-
this%shf%active = .true.
267+
this%shf_active = .true.
268268
call this%parser%GetString(fname)
269+
!
270+
! -- create sensible heat flux object
271+
call openfile(this%inshf, this%iout, fname, 'SHF')
272+
call shf_cr(this%shf, this%name_model, this%inshf, this%iout)
269273
this%shf%inputFilename = fname
270-
!inshf = GetUnit()
271-
call openfile(this%inshf, this%iout, this%shf%inputFilename, 'SHF')
272-
!this%shf%inunit = inshf
273274
case default
274275
!
275276
! -- No options found
@@ -773,6 +774,7 @@ subroutine allocate_scalars(this)
773774
call mem_allocate(this%idxbudroff, 'IDXBUDROFF', this%memoryPath)
774775
call mem_allocate(this%idxbudiflw, 'IDXBUDIFLW', this%memoryPath)
775776
call mem_allocate(this%idxbudoutf, 'IDXBUDOUTF', this%memoryPath)
777+
call mem_allocate(this%shf_active, 'SHF_ACTIVE', this%memoryPath)
776778
call mem_allocate(this%inshf, 'INSHF', this%memoryPath)
777779
!
778780
! -- Initialize
@@ -782,6 +784,7 @@ subroutine allocate_scalars(this)
782784
this%idxbudiflw = 0
783785
this%idxbudoutf = 0
784786
!
787+
this%shf_active = .false.
785788
this%inshf = 0
786789
end subroutine allocate_scalars
787790

@@ -835,6 +838,7 @@ subroutine sfe_da(this)
835838
call mem_deallocate(this%idxbudiflw)
836839
call mem_deallocate(this%idxbudoutf)
837840
!
841+
call mem_deallocate(this%shf_active)
838842
call mem_deallocate(this%inshf)
839843
!
840844
! -- 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)