MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
methodsubcellpollockmodule Module Reference

Data Types

type  methodsubcellpollocktype
 Rectangular subcell tracking method. More...

Functions/Subroutines

subroutine, public create_method_subcell_pollock (method)
 Create a new Pollock's subcell method.
subroutine deallocate (this)
 Deallocate the Pollock's subcell method.
subroutine apply_msp (this, particle, tmax)
 Apply Pollock's method to a rectangular subcell.
subroutine track_subcell (this, subcell, particle, tmax)
 Track a particle across a rectangular subcell using Pollock's method.
integer(i4b) function pick_exit (exit_solutions)
 Pick the exit solution with the shortest travel time.
subroutine find_exits (particle, domain, exit_solutions, x0, y0, z0)
 Compute candidate exit solutions.
type(linearexitsolutiontype) function find_exit (v1, v2, dx, xl)
 Find an exit solution for one dimension.
integer(i4b) function, public calculate_dt (v1, v2, dx, xl, v, dvdx, dt)
 Calculate particle travel time to exit and exit status.
pure real(dp) function new_x (v, dvdx, v1, v2, dt, x, dx, velocity_profile)
 Update a cell-local coordinate based on a time increment.

Function/Subroutine Documentation

◆ apply_msp()

subroutine methodsubcellpollockmodule::apply_msp ( class(methodsubcellpollocktype), intent(inout) this,
type(particletype), intent(inout), pointer particle,
real(dp), intent(in) tmax )
private

Definition at line 58 of file MethodSubcellPollock.f90.

59 ! dummy
60 class(MethodSubcellPollockType), intent(inout) :: this
61 type(ParticleType), pointer, intent(inout) :: particle
62 real(DP), intent(in) :: tmax
63 ! local
64 real(DP) :: x_origin
65 real(DP) :: y_origin
66 real(DP) :: sinrot
67 real(DP) :: cosrot
68
69 select type (subcell => this%subcell)
70 type is (subcellrecttype)
71 ! Transform particle position into local subcell coordinates,
72 ! track particle across subcell, convert back to model coords
73 ! (sinrot and cosrot should be 0 and 1, respectively, i.e. no
74 ! rotation, also no z translation; only x and y translations,
75 ! since subcell%zOrigin is always 0 -- z is translated once,
76 ! at the cell level, not again here)
77 x_origin = subcell%xOrigin
78 y_origin = subcell%yOrigin
79 sinrot = subcell%sinrot
80 cosrot = subcell%cosrot
81 call particle%transform(x_origin, y_origin)
82
83 ! Clamp the particle into the subcell in case roundoff in the
84 ! model-to-local coordinate transform (e.g. under grid rotation)
85 ! left it just outside, analogous to the nudge applied to the
86 ! ternary method's barycentric coordinates.
87 particle%x = min(max(particle%x, dzero), subcell%dx)
88 particle%y = min(max(particle%y, dzero), subcell%dy)
89 particle%z = min(max(particle%z, dzero), subcell%dz)
90
91 call this%track_subcell(subcell, particle, tmax)
92 call particle%transform(x_origin, y_origin, invert=.true.)
93 end select

◆ calculate_dt()

integer(i4b) function, public methodsubcellpollockmodule::calculate_dt ( real(dp) v1,
real(dp) v2,
real(dp) dx,
real(dp) xl,
real(dp) v,
real(dp) dvdx,
real(dp) dt )

This subroutine consists partly of code written by and/or adapted from David W. Pollock of the USGS for MODPATH 7. The authors of the present code are responsible for its appropriate application in this context and for any modifications or errors.

Definition at line 334 of file MethodSubcellPollock.f90.

335 ! dummy
336 real(DP) :: v1
337 real(DP) :: v2
338 real(DP) :: dx
339 real(DP) :: xL
340 real(DP) :: v
341 real(DP) :: dvdx
342 real(DP) :: dt
343 ! result
344 integer(I4B) :: status
345 ! local
346 real(DP) :: v2a
347 real(DP) :: v1a
348 real(DP) :: dv
349 real(DP) :: dva
350 real(DP) :: vv
351 real(DP) :: vvv
352 real(DP) :: zro
353 real(DP) :: zrom
354 real(DP) :: x
355 real(DP) :: tol
356 real(DP) :: vr1
357 real(DP) :: vr2
358 real(DP) :: vr
359 real(DP) :: v1v2
360 logical(LGP) :: noOutflow
361
362 ! Initialize variables.
363 status = -1
364 dt = 1.0d+20
365 v2a = v2
366 if (v2a .lt. dzero) v2a = -v2a
367 v1a = v1
368 if (v1a .lt. dzero) v1a = -v1a
369 dv = v2 - v1
370 dva = dv
371 if (dva .lt. dzero) dva = -dva
372
373 ! Check for a uniform zero velocity in this direction.
374 ! If so, set status = 2 and return (dt = 1.0d+20).
375 tol = 1.0d-15
376 if ((v2a .lt. tol) .and. (v1a .lt. tol)) then
377 v = dzero
378 dvdx = dzero
379 status = no_exit_stationary
380 return
381 end if
382
383 ! Check for uniform non-zero velocity in this direction.
384 ! If so, set compute dt using the constant velocity,
385 ! set status = 1 and return.
386 vv = v1a
387 if (v2a .gt. vv) vv = v2a
388 vvv = dva / vv
389 if (vvv .lt. 1.0d-4) then
390 zro = tol
391 zrom = -zro
392 v = v1
393 x = xl * dx
394 if (v1 .gt. zro) dt = (dx - x) / v1
395 if (v1 .lt. zrom) dt = -x / v1
396 if (dt < dzero) dt = dzero
397 dvdx = dzero
398 status = ok_exit_constant
399 return
400 end if
401
402 ! Velocity has a linear variation.
403 ! Compute velocity corresponding to particle position.
404 ! Take the face velocity exactly if the particle is on a face,
405 ! rather than rely on the interpolation reproducing it.
406 dvdx = dv / dx
407 if (xl <= dzero) then
408 v = v1
409 else if (xl >= done) then
410 v = v2
411 else
412 v = (done - xl) * v1 + xl * v2
413 end if
414
415 ! If flow is into the cell from both sides there is no outflow.
416 ! In that case, set status = 3 and return.
417 nooutflow = .true.
418 if (v1 .lt. dzero) nooutflow = .false.
419 if (v2 .gt. dzero) nooutflow = .false.
420 if (nooutflow) then
421 status = no_exit_no_outflow
422 return
423 end if
424
425 ! If there is a divide in the cell for this flow direction, check to
426 ! see if the particle is located exactly on the divide. If it is, move
427 ! it very slightly to get it off the divide. This avoids possible
428 ! numerical problems related to stagnation points.
429 if ((v1 .le. dzero) .and. (v2 .ge. dzero)) then
430 if (abs(v) .le. dzero) then
431 v = 1.0d-20
432 if (v2 .le. dzero) v = -v
433 end if
434 end if
435
436 ! If there is a flow divide, this check finds out what side of the
437 ! divide the particle is on and sets the value of vr appropriately
438 ! to reflect that location.
439 vr1 = v1 / v
440 vr2 = v2 / v
441 vr = vr1
442 if (vr .le. dzero) then
443 vr = vr2
444 end if
445
446 ! If the product v1*v2 > 0, the velocity is in the same direction
447 ! throughout the cell (i.e. no flow divide). If so, set the value
448 ! of vr to reflect the appropriate direction.
449 v1v2 = v1 * v2
450 if (v1v2 .gt. dzero) then
451 if (v .gt. dzero) vr = vr2
452 if (v .lt. dzero) vr = vr1
453 end if
454
455 ! Check if vr is (very close to) zero.
456 ! If so, set status = 2 and return (dt = 1.0d+20).
457 if (dabs(vr) .lt. 1.0d-10) then
458 v = dzero
459 dvdx = dzero
460 status = no_exit_stationary
461 return
462 end if
463
464 ! Compute travel time to exit face. Return with status = 0.
465 ! A particle on the face it's moving towards exits immediately.
466 if ((xl <= dzero .and. v < dzero) .or. (xl >= done .and. v > dzero)) then
467 dt = dzero
468 else
469 dt = max(log(vr) / dvdx, dzero)
470 end if
471 status = ok_exit
472
Here is the caller graph for this function:

◆ create_method_subcell_pollock()

subroutine, public methodsubcellpollockmodule::create_method_subcell_pollock ( type(methodsubcellpollocktype), pointer method)

Definition at line 38 of file MethodSubcellPollock.f90.

39 ! dummy
40 type(MethodSubcellPollockType), pointer :: method
41 ! local
42 type(SubcellRectType), pointer :: subcell
43
44 allocate (method)
45 call create_subcell_rect(subcell)
46 method%subcell => subcell
47 method%name => method%subcell%type
48 method%delegates = .false.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deallocate()

subroutine methodsubcellpollockmodule::deallocate ( class(methodsubcellpollocktype), intent(inout) this)
private

Definition at line 52 of file MethodSubcellPollock.f90.

53 class(MethodSubcellPollockType), intent(inout) :: this
54 deallocate (this%name)

◆ find_exit()

type(linearexitsolutiontype) function methodsubcellpollockmodule::find_exit ( real(dp), intent(in) v1,
real(dp), intent(in) v2,
real(dp), intent(in) dx,
real(dp), intent(in) xl )
private

Definition at line 314 of file MethodSubcellPollock.f90.

315 ! dummy
316 real(DP), intent(in) :: v1
317 real(DP), intent(in) :: v2
318 real(DP), intent(in) :: dx
319 real(DP), intent(in) :: xL
320 type(LinearExitSolutionType) :: solution
321
322 solution = linearexitsolutiontype()
323 solution%status = calculate_dt(v1, v2, dx, xl, &
324 solution%v, solution%dvdx, solution%dt)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_exits()

subroutine methodsubcellpollockmodule::find_exits ( type(particletype), intent(inout), pointer particle,
class(domaintype), intent(in) domain,
type(linearexitsolutiontype), dimension(3), intent(out) exit_solutions,
real(dp), intent(out) x0,
real(dp), intent(out) y0,
real(dp), intent(out) z0 )
private

Also returns the local subcell coordinates used (x0, y0, z0), so track_subcell doesn't need to recompute them from the particle's position.

Definition at line 274 of file MethodSubcellPollock.f90.

275 type(ParticleType), pointer, intent(inout) :: particle
276 class(DomainType), intent(in) :: domain
277 type(LinearExitSolutionType), intent(out) :: exit_solutions(3)
278 real(DP), intent(out) :: x0, y0, z0
279
280 select type (domain)
281 type is (subcellrecttype)
282 ! Initial particle location in scaled subcell coordinates
283 x0 = particle%x / domain%dx
284 y0 = particle%y / domain%dy
285 z0 = particle%z / domain%dz
286
287 ! Calculate exit solutions for each coordinate direction
288 exit_solutions = [ &
289 find_exit(domain%vx1, domain%vx2, domain%dx, x0), &
290 find_exit(domain%vy1, domain%vy2, domain%dy, y0), &
291 find_exit(domain%vz1, domain%vz2, domain%dz, z0) &
292 ]
293
294 ! Set exit faces
295 if (exit_solutions(1)%v < dzero) then
296 exit_solutions(1)%iboundary = 1
297 else if (exit_solutions(1)%v > dzero) then
298 exit_solutions(1)%iboundary = 2
299 end if
300 if (exit_solutions(2)%v < dzero) then
301 exit_solutions(2)%iboundary = 3
302 else if (exit_solutions(2)%v > dzero) then
303 exit_solutions(2)%iboundary = 4
304 end if
305 if (exit_solutions(3)%v < dzero) then
306 exit_solutions(3)%iboundary = 5
307 else if (exit_solutions(3)%v > dzero) then
308 exit_solutions(3)%iboundary = 6
309 end if
310 end select
Here is the call graph for this function:
Here is the caller graph for this function:

◆ new_x()

pure real(dp) function methodsubcellpollockmodule::new_x ( real(dp), intent(in) v,
real(dp), intent(in) dvdx,
real(dp), intent(in) v1,
real(dp), intent(in) v2,
real(dp), intent(in) dt,
real(dp), intent(in) x,
real(dp), intent(in) dx,
logical(lgp), intent(in), optional velocity_profile )
private

This subroutine consists partly or entirely of code written by David W. Pollock of the USGS for MODPATH 7. The authors of the present code are responsible for its appropriate application in this context and for any modifications or errors.

Definition at line 482 of file MethodSubcellPollock.f90.

483 ! dummy
484 real(DP), intent(in) :: v
485 real(DP), intent(in) :: dvdx
486 real(DP), intent(in) :: v1
487 real(DP), intent(in) :: v2
488 real(DP), intent(in) :: dt
489 real(DP), intent(in) :: x
490 real(DP), intent(in) :: dx
491 logical(LGP), intent(in), optional :: velocity_profile
492 ! result
493 real(DP) :: newx
494 logical(LGP) :: lprofile
495
496 ! process optional arguments
497 if (present(velocity_profile)) then
498 lprofile = velocity_profile
499 else
500 lprofile = .false.
501 end if
502
503 ! recompute coordinate
504 newx = x
505 if (lprofile) then
506 newx = newx + (v1 * dt / dx)
507 else if (v .ne. dzero) then
508 newx = newx + (v * (exp(dvdx * dt) - done) / dvdx / dx)
509 end if
510
511 ! clamp to [0, 1]
512 if (newx .lt. dzero) newx = dzero
513 if (newx .gt. done) newx = done
514
Here is the caller graph for this function:

◆ pick_exit()

integer(i4b) function methodsubcellpollockmodule::pick_exit ( type(linearexitsolutiontype), dimension(3), intent(in) exit_solutions)
private

Definition at line 243 of file MethodSubcellPollock.f90.

244 type(LinearExitSolutionType), intent(in) :: exit_solutions(3)
245 integer(I4B) :: exit_soln
246 ! local
247 real(DP) :: dtmin
248
249 exit_soln = 0
250 dtmin = 1.0d+30
251
252 if (exit_solutions(1)%status < 2) then
253 exit_soln = 1 ! x
254 dtmin = exit_solutions(1)%dt
255 end if
256 if (exit_solutions(2)%status < 2 .and. &
257 exit_solutions(2)%dt < dtmin) then
258 exit_soln = 2 ! y
259 dtmin = exit_solutions(2)%dt
260 end if
261 if (exit_solutions(3)%status < 2 .and. &
262 exit_solutions(3)%dt < dtmin) then
263 exit_soln = 3 ! z
264 end if
265
Here is the caller graph for this function:

◆ track_subcell()

subroutine methodsubcellpollockmodule::track_subcell ( class(methodsubcellpollocktype), intent(inout) this,
class(subcellrecttype), intent(in) subcell,
type(particletype), intent(inout), pointer particle,
real(dp), intent(in) tmax )
private

This subroutine consists partly of code written by David W. Pollock of the USGS for MODPATH 7. PRT's authors take responsibility for its application in this context and for any modifications or errors.

Definition at line 103 of file MethodSubcellPollock.f90.

106 ! dummy
107 class(MethodSubcellPollockType), intent(inout) :: this
108 class(SubcellRectType), intent(in) :: subcell
109 type(ParticleType), pointer, intent(inout) :: particle
110 real(DP), intent(in) :: tmax
111 ! local
112 real(DP) :: dt, dtexit, texit
113 real(DP) :: t, x, y, z
114 real(DP) :: t0, x0, y0, z0
115 integer(I4B) :: i, exit_face, exit_soln
116 type(LinearExitSolutionType) :: exit_solutions(3)
117 type(LinearExitSolutionType) :: exit_x, exit_y, exit_z
118
119 t0 = particle%ttrack
120
121 ! Find exit solution in each direction; also returns the
122 ! local subcell coordinates used, so we don't recompute them
123 call find_exits(particle, subcell, exit_solutions, x0, y0, z0)
124 exit_x = exit_solutions(1)
125 exit_y = exit_solutions(2)
126 exit_z = exit_solutions(3)
127
128 ! Set solution, face, & travel time
129 exit_soln = pick_exit(exit_solutions)
130 if (exit_soln == 0) then
131 exit_face = 0
132 dtexit = 1.0d+30
133 else
134 exit_face = exit_solutions(exit_soln)%iboundary
135 dtexit = exit_solutions(exit_soln)%dt
136 end if
137 texit = particle%ttrack + dtexit
138
139 ! Terminate if no valid exit solution was found.
140 ! MP7 is more nuanced in determining what to do
141 ! here. It considers whether this stress period
142 ! is steady state or transient, and whether the
143 ! flow is stationary, in determining whether to
144 ! terminate or allow the particle to survive to
145 ! the next time step. It does not compute paths
146 ! within the subcell even for particles it lets
147 ! remain active under this circumstance, though.
148 ! While we may consider that someday, we simply
149 ! terminate and sidestep the complexity for now.
150 if (all([exit_solutions%status] >= no_exit_stationary)) then
151 call this%terminate(particle, status=term_no_exits_sub)
152 return
153 end if
154
155 ! Select user tracking times to solve. If this is the first time step
156 ! of the simulation, include all times before it begins; if it is the
157 ! last time step include all times after it ends only if the 'extend'
158 ! option is on, otherwise times in this period and time step only.
159 call this%tracktimes%advance()
160 if (this%tracktimes%any()) then
161 do i = this%tracktimes%selection(1), this%tracktimes%selection(2)
162 t = this%tracktimes%times(i)
163 if (t <= particle%tusertime) cycle ! already reported
164 if (t < particle%ttrack) cycle
165 if (t > texit .or. t > tmax) exit
166 dt = t - t0
167 x = new_x(exit_x%v, exit_x%dvdx, subcell%vx1, subcell%vx2, &
168 dt, x0, subcell%dx, exit_x%status == 1)
169 y = new_x(exit_y%v, exit_y%dvdx, subcell%vy1, subcell%vy2, &
170 dt, y0, subcell%dy, exit_y%status == 1)
171 z = new_x(exit_z%v, exit_z%dvdx, subcell%vz1, subcell%vz2, &
172 dt, z0, subcell%dz, exit_z%status == 1)
173 particle%x = x * subcell%dx
174 particle%y = y * subcell%dy
175 particle%z = z * subcell%dz
176 particle%ttrack = t
177 call this%usertime(particle)
178 end do
179 end if
180
181 ! Computed exit time greater than the maximum time? Set the
182 ! tracking time to tmax and calculate the particle location.
183 if (texit .gt. tmax) then
184 t = tmax
185 dt = t - t0
186 x = new_x(exit_x%v, exit_x%dvdx, subcell%vx1, subcell%vx2, &
187 dt, x0, subcell%dx, exit_x%status == 1)
188 y = new_x(exit_y%v, exit_y%dvdx, subcell%vy1, subcell%vy2, &
189 dt, y0, subcell%dy, exit_y%status == 1)
190 z = new_x(exit_z%v, exit_z%dvdx, subcell%vz1, subcell%vz2, &
191 dt, z0, subcell%dz, exit_z%status == 1)
192 exit_face = 0
193 particle%advancing = .false.
194 particle%x = x * subcell%dx
195 particle%y = y * subcell%dy
196 particle%z = z * subcell%dz
197 particle%ttrack = t
198 particle%iboundary(level_subfeature) = exit_face
199 call this%timestep(particle)
200 return
201 end if
202
203 ! If we get to here, the particle is exiting the subcell.
204 ! Its exit time is less than or equal to the maximum time.
205 ! Set tracking time to the exit time and set exit location.
206 t = texit
207 dt = dtexit
208 if ((exit_face .eq. 1) .or. (exit_face .eq. 2)) then
209 x = dzero
210 y = new_x(exit_y%v, exit_y%dvdx, subcell%vy1, subcell%vy2, &
211 dt, y0, subcell%dy, exit_y%status == 1)
212 z = new_x(exit_z%v, exit_z%dvdx, subcell%vz1, subcell%vz2, &
213 dt, z0, subcell%dz, exit_z%status == 1)
214 if (exit_face .eq. 2) x = done
215 else if ((exit_face .eq. 3) .or. (exit_face .eq. 4)) then
216 x = new_x(exit_x%v, exit_x%dvdx, subcell%vx1, subcell%vx2, dt, &
217 x0, subcell%dx, exit_x%status == 1)
218 y = dzero
219 z = new_x(exit_z%v, exit_z%dvdx, subcell%vz1, subcell%vz2, dt, &
220 z0, subcell%dz, exit_z%status == 1)
221 if (exit_face .eq. 4) y = done
222 else if ((exit_face .eq. 5) .or. (exit_face .eq. 6)) then
223 x = new_x(exit_x%v, exit_x%dvdx, subcell%vx1, subcell%vx2, &
224 dt, x0, subcell%dx, exit_x%status == 1)
225 y = new_x(exit_y%v, exit_y%dvdx, subcell%vy1, subcell%vy2, &
226 dt, y0, subcell%dy, exit_y%status == 1)
227 z = dzero
228 if (exit_face .eq. 6) z = done
229 else
230 print *, "programmer error, invalid exit face", exit_face
231 call pstop(1)
232 end if
233 particle%x = x * subcell%dx
234 particle%y = y * subcell%dy
235 particle%z = z * subcell%dz
236 particle%ttrack = t
237 particle%iboundary(level_subfeature) = exit_face
238 call this%subcellexit(particle, tmax)
239
@ timestep
time step ended
@ featexit
particle exited a grid feature
@ term_no_exits_sub
terminated in a subcell with no exit face
Definition Particle.f90:38
Here is the call graph for this function: