MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
MethodCell.f90
Go to the documentation of this file.
2
3 use kindmodule, only: dp, i4b, lgp
4 use errorutilmodule, only: pstop
5 use constantsmodule, only: done, dzero
13 implicit none
14
15 private
16 public :: methodcelltype
17
18 type, abstract, extends(methodtype) :: methodcelltype
19 contains
20 procedure, public :: assess
21 procedure, public :: cellexit
22 procedure, public :: forms_cycle
23 procedure, public :: store_event
24 procedure, public :: get_level
25 procedure, public :: try_pass
27 end type methodcelltype
28
29contains
30 !> @brief Try passing the particle to the next subdomain.
31 !! or to a boundary of this method's tracking domain.
32 !!
33 !! If the particle is not advancing, or if it's not at
34 !! a boundary, nothing happens. Otherwise, raise a cell
35 !! exit event. Then, if at a net outflow boundary face,
36 !! or top face of a partially saturated cell, terminate.
37 !<
38 subroutine try_pass(this, particle, nextlevel, advancing)
39 class(methodcelltype), intent(inout) :: this
40 type(particletype), pointer, intent(inout) :: particle
41 logical(LGP) :: advancing
42 integer(I4B) :: nextlevel
43 ! local
44 integer(I4B) :: ic, iboundary, icellface
45
46 if (.not. particle%advancing) then
47 advancing = .false.
48 particle%iboundary = 0
49 return
50 end if
51
52 call this%pass(particle)
53
54 iboundary = particle%iboundary(level_feature)
55 icellface = this%iboundary_to_icellface(iboundary)
56 if (icellface <= 0) return
57
58 ! on a cell face, done advancing. raise an exit event
59 advancing = .false.
60 call this%cellexit(particle)
61
62 ! assigned boundary face with net outflow? terminate
63 ic = particle%itrdomain(level_feature)
64 if (this%fmi%is_net_out_boundary_face(ic, icellface)) then
65 call this%terminate(particle, status=term_boundary)
66 return
67 end if
68
69 end subroutine try_pass
70
71 !> @brief Check reporting/terminating conditions before tracking
72 !! the particle across the cell.
73 !!
74 !! Check a number of conditions determining whether to continue
75 !! tracking the particle or terminate it, as well as whether to
76 !! record any output data as per selected reporting conditions.
77 !<
78 subroutine assess(this, particle, cell_defn, tmax)
79 ! modules
84 ! dummy
85 class(methodcelltype), intent(inout) :: this
86 type(particletype), pointer, intent(inout) :: particle
87 type(celldefntype), pointer, intent(inout) :: cell_defn
88 real(DP), intent(in) :: tmax
89 ! local
90 logical(LGP) :: dry_cell, dry_particle, no_exit_face, stop_zone, weak_sink
91 integer(I4B) :: i
92 real(DP) :: t, ttrackmax
93
94 dry_cell = cell_defn%isatstat == saturation_dry
95 dry_particle = particle%z > cell_defn%top
96 no_exit_face = cell_defn%inoexitface > 0
97 stop_zone = cell_defn%izone > 0 .and. particle%istopzone == cell_defn%izone
98 weak_sink = cell_defn%iweaksink > 0
99
100 particle%izone = cell_defn%izone
101 if (stop_zone) then
102 call this%terminate(particle, status=term_stopzone)
103 return
104 end if
105
106 if (no_exit_face .and. .not. dry_cell) then
107 call this%terminate(particle, status=term_no_exits)
108 return
109 end if
110
111 if (weak_sink) then
112 if (particle%istopweaksink > 0) then
113 call this%terminate(particle, status=term_weaksink)
114 return
115 else
116 call this%weaksink(particle)
117 end if
118 end if
119
120 if (dry_cell) then
121 if (particle%idrymeth == 0) then
122 ! drop to cell bottom. handled by pass
123 ! to bottom method, nothing to do here
124 no_exit_face = .false.
125 else if (particle%idrymeth == 1) then
126 ! stop
127 call this%terminate(particle, status=term_inactive)
128 return
129 else if (particle%idrymeth == 2) then
130 ! stay
131 particle%advancing = .false.
132 no_exit_face = .false.
133
134 ! we might report tracking times
135 ! out of order here, but we want
136 ! the particle termination event
137 ! (if this is the last time step)
138 ! to have the maximum tracking t,
139 ! so we need to keep tabs on it.
140 ttrackmax = totim
141
142 ! update tracking time to time
143 ! step end time and save record
144 particle%ttrack = totim
145 call this%timestep(particle)
146
147 ! record user tracking times
148 call this%tracktimes%advance()
149 if (this%tracktimes%any()) then
150 do i = this%tracktimes%selection(1), this%tracktimes%selection(2)
151 t = this%tracktimes%times(i)
152 if (t < totimc) cycle
153 if (t > tmax) exit
154 particle%ttrack = t
155 call this%usertime(particle)
156 if (t > ttrackmax) ttrackmax = t
157 end do
158 end if
159
160 ! terminate if last period/step
161 if (endofsimulation) then
162 particle%ttrack = ttrackmax
163 call this%terminate(particle, status=term_no_exits)
164 return
165 end if
166 end if
167 else if (dry_particle .and. this%name /= "passtobottom") then
168 if (particle%idrymeth == 0) then
169 ! drop to water table
170 particle%z = cell_defn%top
171 call this%dropped(particle)
172 else if (particle%idrymeth == 1) then
173 ! stop
174 call this%terminate(particle, status=term_inactive)
175 return
176 else if (particle%idrymeth == 2) then
177 ! stay
178 particle%advancing = .false.
179 no_exit_face = .false.
180
181 ! we might report tracking times
182 ! out of order here, but we want
183 ! the particle termination event
184 ! (if this is the last time step)
185 ! to have the maximum tracking t,
186 ! so we need to keep tabs on it.
187 ttrackmax = totim
188
189 ! update tracking time to time
190 ! step end time and save record
191 particle%ttrack = totim
192 call this%timestep(particle)
193
194 ! record user tracking times
195 call this%tracktimes%advance()
196 if (this%tracktimes%any()) then
197 do i = this%tracktimes%selection(1), this%tracktimes%selection(2)
198 t = this%tracktimes%times(i)
199 if (t < totimc) cycle
200 if (t > tmax) exit
201 particle%ttrack = t
202 call this%usertime(particle)
203 if (t > ttrackmax) ttrackmax = t
204 end do
205 end if
206 end if
207 end if
208
209 if (no_exit_face) then
210 call this%terminate(particle, status=term_no_exits)
211 return
212 end if
213
214 end subroutine assess
215
216 !> @brief Particle exits a cell.
217 subroutine cellexit(this, particle)
218 class(methodcelltype), intent(inout) :: this
219 type(particletype), pointer, intent(inout) :: particle
220 class(particleeventtype), pointer :: event
221 ! local
222 integer(I4B) :: i, nhist
223 class(*), pointer :: prev
224
225 allocate (cellexiteventtype :: event)
226 select type (event)
227 type is (cellexiteventtype)
228 event%exit_face = particle%iboundary(level_feature)
229 end select
230 call this%events%broadcast(particle, event)
231 if (particle%icycwin == 0) then
232 deallocate (event)
233 return
234 end if
235 if (this%forms_cycle(particle, event)) then
236 ! print event history
237 print *, "Cyclic pathline detected"
238 nhist = particle%history%Count()
239 do i = 1, nhist
240 prev => particle%history%GetItem(i)
241 select type (prev)
242 class is (particleeventtype)
243 print *, "Back ", nhist - i + 1, ": ", prev%get_text()
244 end select
245 end do
246 print *, "Current :", event%get_text()
247 call pstop(1, 'Cyclic pathline detected, aborting')
248 else
249 call this%store_event(particle, event)
250 end if
251 end subroutine cellexit
252
253 !> @brief Check if the event forms a cycle in the particle path.
254 function forms_cycle(this, particle, event) result(found_cycle)
255 ! dummy
256 class(methodcelltype), intent(inout) :: this
257 type(particletype), pointer, intent(inout) :: particle
258 class(particleeventtype), pointer, intent(in) :: event
259 ! local
260 class(iteratortype), allocatable :: itr
261 logical(LGP) :: found_cycle
262
263 found_cycle = .false.
264 select type (event)
265 type is (cellexiteventtype)
266 itr = particle%history%Iterator()
267 do while (itr%has_next())
268 call itr%next()
269 select type (prev => itr%value())
270 class is (cellexiteventtype)
271 if (event%icu == prev%icu .and. &
272 event%ilay == prev%ilay .and. &
273 event%izone == prev%izone .and. &
274 event%exit_face == prev%exit_face .and. &
275 event%exit_face /= 0) then
276 found_cycle = .true.
277 exit
278 end if
279 end select
280 end do
281 type is (subcellexiteventtype)
282 itr = particle%history%Iterator()
283 do while (itr%has_next())
284 call itr%next()
285 select type (prev => itr%value())
286 class is (subcellexiteventtype)
287 if (event%icu == prev%icu .and. &
288 event%ilay == prev%ilay .and. &
289 event%isc == prev%isc .and. &
290 event%exit_face == prev%exit_face .and. &
291 event%exit_face /= 0) then
292 found_cycle = .true.
293 exit
294 end if
295 end select
296 end do
297 end select
298 end function forms_cycle
299
300 !> @brief Save the event in the particle's history.
301 !! Acts like a queue, the oldest event is removed
302 !! when the event count exceeds the maximum size.
303 subroutine store_event(this, particle, event)
304 ! dummy
305 class(methodcelltype), intent(inout) :: this
306 type(particletype), pointer, intent(inout) :: particle
307 class(particleeventtype), pointer, intent(in) :: event
308 ! local
309 class(*), pointer :: p
310
311 select type (event)
312 type is (cellexiteventtype)
313 p => event
314 call particle%history%Add(p)
315 if (particle%history%Count() > particle%icycwin) &
316 call particle%history%RemoveNode(1, .true.)
317 type is (subcellexiteventtype)
318 p => event
319 call particle%history%Add(p)
320 if (particle%history%Count() > particle%icycwin) &
321 call particle%history%RemoveNode(1, .true.)
322 end select
323 end subroutine store_event
324
325 !> @brief Get the cell method's level.
326 function get_level(this) result(level)
327 class(methodcelltype), intent(in) :: this
328 integer(I4B) :: level
329 level = level_feature
330 end function get_level
331
332 !> @brief Convert an iboundary number to an iface number
333 function iboundary_to_icellface(this, iboundary) result(iface)
334 class(methodcelltype), intent(inout) :: this
335 integer(I4B), intent(in) :: iboundary
336 integer(I4B) :: iface
337 integer(I4B) :: nfaces
338
339 iface = iboundary
340 nfaces = this%cell%defn%npolyverts + 2
341 if (iface >= nfaces) &
342 ! uncompress and drop wraparound index
343 iface = iface + (this%fmi%max_faces - nfaces) - 1
344 end function iboundary_to_icellface
345
346end module methodcellmodule
This module contains simulation constants.
Definition Constants.f90:9
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65
real(dp), parameter done
real constant 1
Definition Constants.f90:76
subroutine pstop(status, message)
Stop the program, optionally specifying an error status code.
Definition ErrorUtil.f90:24
This module defines variable data types.
Definition kind.f90:8
logical(lgp) function forms_cycle(this, particle, event)
Check if the event forms a cycle in the particle path.
integer(i4b) function iboundary_to_icellface(this, iboundary)
Convert an iboundary number to an iface number.
subroutine store_event(this, particle, event)
Save the event in the particle's history. Acts like a queue, the oldest event is removed when the eve...
subroutine cellexit(this, particle)
Particle exits a cell.
Particle tracking strategies.
Definition Method.f90:2
subroutine try_pass(this, particle, nextlevel, advancing)
Try passing the particle to the next subdomain.
Definition Method.f90:167
integer(i4b) function get_level(this)
Get tracking method level.
Definition Method.f90:188
@ usertime
user-specified tracking time
@ terminate
particle terminated
@ timestep
time step ended
@ weaksink
particle entered a weak sink
@ term_weaksink
terminated in a weak sink cell
Definition Particle.f90:34
@ term_inactive
terminated in an inactive cell
Definition Particle.f90:37
@ term_no_exits
terminated in a cell with no exit face
Definition Particle.f90:35
@ term_stopzone
terminated in a cell with a stop zone number
Definition Particle.f90:36
@ term_boundary
terminated at a boundary face
Definition Particle.f90:33
logical(lgp), pointer, public endofsimulation
flag indicating end of simulation
Definition tdis.f90:31
real(dp), pointer, public totim
time relative to start of simulation
Definition tdis.f90:35
real(dp), pointer, public totimc
simulation time at start of time step
Definition tdis.f90:36
Base grid cell definition.
Definition CellDefn.f90:25
Base type for particle tracking methods.
Definition Method.f90:57
Base type for particle events.
Particle tracked by the PRT model.
Definition Particle.f90:64