Skip to content

Commit caa5803

Browse files
authored
chore(prt): tidy up fmi module (#2482)
argument validation for functions introduced in #2477, misc code/comment format cleanup
1 parent 14bd593 commit caa5803

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

src/Model/ParticleTracking/prt-fmi.f90

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ subroutine fmi_cr(fmiobj, name_model, input_mempath, inunit, iout)
4545
character(len=*), intent(in) :: input_mempath
4646
integer(I4B), intent(inout) :: inunit
4747
integer(I4B), intent(in) :: iout
48-
!
48+
4949
! Create the object
5050
allocate (fmiobj)
51-
!
51+
5252
! create name and memory path
5353
call fmiobj%set_names(1, name_model, 'FMI', 'FMI', input_mempath)
5454
fmiobj%text = text
55-
!
55+
5656
! Allocate scalars
5757
call fmiobj%allocate_scalars()
58-
!
58+
5959
! Set variables
6060
fmiobj%inunit = inunit
6161
fmiobj%iout = iout
62-
!
62+
6363
! Assign dependent variable label
6464
fmiobj%depvartype = 'TRACKS '
6565

@@ -78,41 +78,35 @@ subroutine fmi_ad(this)
7878
&"(/1X,'WARNING: DRY CELL ENCOUNTERED AT ',a,'; RESET AS INACTIVE')"
7979
character(len=*), parameter :: fmtrewet = &
8080
&"(/1X,'DRY CELL REACTIVATED AT ', a)"
81-
!
81+
8282
! Set flag to indicated that flows are being updated. For the case where
8383
! flows may be reused (only when flows are read from a file) then set
8484
! the flag to zero to indicated that flows were not updated
8585
this%iflowsupdated = 1
86-
!
86+
8787
! If reading flows from a budget file, read the next set of records
88-
if (this%iubud /= 0) then
89-
call this%advance_bfr()
90-
end if
91-
!
88+
if (this%iubud /= 0) call this%advance_bfr()
89+
9290
! If reading heads from a head file, read the next set of records
93-
if (this%iuhds /= 0) then
94-
call this%advance_hfr()
95-
end if
96-
!
91+
if (this%iuhds /= 0) call this%advance_hfr()
92+
9793
! If mover flows are being read from file, read the next set of records
98-
if (this%iumvr /= 0) then
94+
if (this%iumvr /= 0) &
9995
call this%mvrbudobj%bfr_advance(this%dis, this%iout)
100-
end if
101-
!
96+
10297
! Accumulate flows
10398
call this%accumulate_flows()
104-
!
99+
105100
! if flow cell is dry, then set this%ibound = 0
106101
do n = 1, this%dis%nodes
107-
!
108102
! Calculate the ibound-like array that has 0 if saturation
109103
! is zero and 1 otherwise
110104
if (this%gwfsat(n) > DZERO) then
111105
this%ibdgwfsat0(n) = 1
112106
else
113107
this%ibdgwfsat0(n) = 0
114108
end if
115-
!
109+
116110
! Check if active model cell is inactive for flow
117111
if (this%ibound(n) > 0) then
118112
if (this%gwfhead(n) == DHDRY) then
@@ -122,7 +116,7 @@ subroutine fmi_ad(this)
122116
write (this%iout, fmtdry) trim(nodestr)
123117
end if
124118
end if
125-
!
119+
126120
! Convert dry model cell to active if flow has rewet
127121
if (this%ibound(n) == 0) then
128122
if (this%gwfhead(n) /= DHDRY) then
@@ -138,17 +132,12 @@ end subroutine fmi_ad
138132

139133
!> @brief Define the flow model interface
140134
subroutine prtfmi_df(this, dis, idryinactive)
141-
! modules
142-
use SimModule, only: store_error
143-
! dummy
144135
class(PrtFmiType) :: this
145136
class(DisBaseType), pointer, intent(in) :: dis
146137
integer(I4B), intent(in) :: idryinactive
147-
!
148-
! Call parent class define
138+
149139
call this%FlowModelInterfaceType%fmi_df(dis, idryinactive)
150-
!
151-
! Allocate arrays
140+
152141
this%max_faces = this%dis%get_max_npolyverts() + 2
153142
allocate (this%StorageFlows(this%dis%nodes))
154143
allocate (this%SourceFlows(this%dis%nodes))
@@ -160,7 +149,6 @@ end subroutine prtfmi_df
160149

161150
!> @brief Accumulate flows
162151
subroutine accumulate_flows(this)
163-
implicit none
164152
! dummy
165153
class(PrtFmiType) :: this
166154
! local
@@ -172,11 +160,9 @@ subroutine accumulate_flows(this)
172160

173161
this%StorageFlows = DZERO
174162
if (this%igwfstrgss /= 0) &
175-
this%StorageFlows = this%StorageFlows + &
176-
this%gwfstrgss
163+
this%StorageFlows = this%StorageFlows + this%gwfstrgss
177164
if (this%igwfstrgsy /= 0) &
178-
this%StorageFlows = this%StorageFlows + &
179-
this%gwfstrgsy
165+
this%StorageFlows = this%StorageFlows + this%gwfstrgsy
180166

181167
this%SourceFlows = DZERO
182168
this%SinkFlows = DZERO
@@ -196,8 +182,7 @@ subroutine accumulate_flows(this)
196182
end if
197183
do ib = 1, this%gwfpackages(ip)%nbound
198184
i = this%gwfpackages(ip)%nodelist(ib)
199-
if (i <= 0) cycle
200-
if (this%ibound(i) <= 0) cycle
185+
if (i <= 0 .or. this%ibound(i) <= 0) cycle
201186
qbnd = this%gwfpackages(ip)%get_flow(ib)
202187
! todo, after initial release: default iflowface values for different packages
203188
iflowface = 0 ! iflowface number
@@ -231,8 +216,16 @@ subroutine mark_boundary_face(this, ic, iface)
231216
! local
232217
integer(I4B) :: bit_pos
233218

234-
if (ic <= 0 .or. ic > size(this%BoundaryFaces)) return
235-
if (iface == 0) return
219+
if (ic <= 0 .or. ic > this%dis%nodes) then
220+
print *, 'Invalid cell number: ', ic
221+
print *, 'Expected a value in range [1, ', this%dis%nodes, ']'
222+
call pstop(1)
223+
end if
224+
if (iface <= 0) then
225+
print *, 'Invalid face number: ', iface
226+
print *, 'Expected a value in range [1, ', this%max_faces, ']'
227+
call pstop(1)
228+
end if
236229
bit_pos = iface - 1 ! bit position 0-based
237230
if (bit_pos < 0 .or. bit_pos > 31) then
238231
print *, 'Invalid bitmask position: ', iface
@@ -252,8 +245,16 @@ function is_boundary_face(this, ic, iface) result(is_boundary)
252245
integer(I4B) :: bit_pos
253246

254247
is_boundary = .false.
255-
if (ic <= 0 .or. ic > size(this%BoundaryFaces)) return
256-
if (iface == 0) return
248+
if (ic <= 0 .or. ic > this%dis%nodes) then
249+
print *, 'Invalid cell number: ', ic
250+
print *, 'Expected a value in range [1, ', this%dis%nodes, ']'
251+
call pstop(1)
252+
end if
253+
if (iface <= 0) then
254+
print *, 'Invalid face number: ', iface
255+
print *, 'Expected a value in range [1, ', this%max_faces, ']'
256+
call pstop(1)
257+
end if
257258
bit_pos = iface - 1 ! bit position 0-based
258259
if (bit_pos < 0 .or. bit_pos > 31) then
259260
print *, 'Invalid bitmask position: ', iface

0 commit comments

Comments
 (0)