|
| 1 | +module MethodCellModule |
| 2 | + |
| 3 | + use KindModule, only: DP, I4B, LGP |
| 4 | + use ConstantsModule, only: DONE, DZERO |
| 5 | + use MethodModule, only: MethodType |
| 6 | + use ParticleModule, only: ParticleType |
| 7 | + use CellDefnModule, only: CellDefnType |
| 8 | + implicit none |
| 9 | + |
| 10 | + private |
| 11 | + public :: MethodCellType |
| 12 | + |
| 13 | + type, abstract, extends(MethodType) :: MethodCellType |
| 14 | + contains |
| 15 | + procedure, public :: check |
| 16 | + end type MethodCellType |
| 17 | + |
| 18 | +contains |
| 19 | + |
| 20 | + !> @brief Check reporting/terminating conditions before tracking |
| 21 | + !! the particle across the cell. |
| 22 | + !! |
| 23 | + !! Check a number of conditions determining whether to continue |
| 24 | + !! tracking the particle or terminate it, as well as whether to |
| 25 | + !! record any output data as per selected reporting conditions. |
| 26 | + !< |
| 27 | + subroutine check(this, particle, cell_defn, tmax) |
| 28 | + ! modules |
| 29 | + use TdisModule, only: endofsimulation, totimc, totim |
| 30 | + use ParticleModule, only: TERM_WEAKSINK, TERM_NO_EXITS, & |
| 31 | + TERM_STOPZONE, TERM_INACTIVE |
| 32 | + ! dummy |
| 33 | + class(MethodCellType), intent(inout) :: this |
| 34 | + type(ParticleType), pointer, intent(inout) :: particle |
| 35 | + type(CellDefnType), pointer, intent(inout) :: cell_defn |
| 36 | + real(DP), intent(in) :: tmax |
| 37 | + ! local |
| 38 | + logical(LGP) :: dry_cell, dry_particle, no_exit_face, stop_zone, weak_sink |
| 39 | + integer(I4B) :: i |
| 40 | + real(DP) :: t, ttrackmax |
| 41 | + |
| 42 | + dry_cell = this%fmi%ibdgwfsat0(cell_defn%icell) == 0 |
| 43 | + dry_particle = particle%z > cell_defn%top |
| 44 | + no_exit_face = cell_defn%inoexitface > 0 |
| 45 | + stop_zone = cell_defn%izone > 0 .and. particle%istopzone == cell_defn%izone |
| 46 | + weak_sink = cell_defn%iweaksink > 0 |
| 47 | + |
| 48 | + particle%izone = cell_defn%izone |
| 49 | + if (stop_zone) then |
| 50 | + particle%advancing = .false. |
| 51 | + particle%istatus = TERM_STOPZONE |
| 52 | + call this%save(particle, reason=3) |
| 53 | + return |
| 54 | + end if |
| 55 | + |
| 56 | + if (no_exit_face .and. .not. dry_cell) then |
| 57 | + particle%advancing = .false. |
| 58 | + particle%istatus = TERM_NO_EXITS |
| 59 | + call this%save(particle, reason=3) |
| 60 | + return |
| 61 | + end if |
| 62 | + |
| 63 | + if (weak_sink) then |
| 64 | + if (particle%istopweaksink > 0) then |
| 65 | + particle%advancing = .false. |
| 66 | + particle%istatus = TERM_WEAKSINK |
| 67 | + call this%save(particle, reason=3) |
| 68 | + return |
| 69 | + else |
| 70 | + call this%save(particle, reason=4) |
| 71 | + end if |
| 72 | + end if |
| 73 | + |
| 74 | + if (dry_cell) then |
| 75 | + if (particle%idrymeth == 0) then |
| 76 | + ! drop to cell bottom. handled by pass |
| 77 | + ! to bottom method, nothing to do here |
| 78 | + no_exit_face = .false. |
| 79 | + else if (particle%idrymeth == 1) then |
| 80 | + ! stop |
| 81 | + particle%advancing = .false. |
| 82 | + particle%istatus = TERM_INACTIVE |
| 83 | + call this%save(particle, reason=3) |
| 84 | + return |
| 85 | + else if (particle%idrymeth == 2) then |
| 86 | + ! stay |
| 87 | + particle%advancing = .false. |
| 88 | + no_exit_face = .false. |
| 89 | + |
| 90 | + ! we might report tracking times |
| 91 | + ! out of order here, but we want |
| 92 | + ! the particle termination event |
| 93 | + ! (if this is the last time step) |
| 94 | + ! to have the maximum tracking t, |
| 95 | + ! so we need to keep tabs on it. |
| 96 | + ttrackmax = totim |
| 97 | + |
| 98 | + ! update tracking time to time |
| 99 | + ! step end time and save record |
| 100 | + particle%ttrack = totim |
| 101 | + call this%save(particle, reason=2) |
| 102 | + |
| 103 | + ! record user tracking times |
| 104 | + call this%tracktimes%advance() |
| 105 | + if (this%tracktimes%any()) then |
| 106 | + do i = this%tracktimes%selection(1), this%tracktimes%selection(2) |
| 107 | + t = this%tracktimes%times(i) |
| 108 | + if (t < totimc) cycle |
| 109 | + if (t >= tmax) exit |
| 110 | + particle%ttrack = t |
| 111 | + call this%save(particle, reason=5) |
| 112 | + if (t > ttrackmax) ttrackmax = t |
| 113 | + end do |
| 114 | + end if |
| 115 | + |
| 116 | + ! terminate if last period/step |
| 117 | + if (endofsimulation) then |
| 118 | + particle%istatus = TERM_NO_EXITS |
| 119 | + particle%ttrack = ttrackmax |
| 120 | + call this%save(particle, reason=3) |
| 121 | + return |
| 122 | + end if |
| 123 | + end if |
| 124 | + else if (dry_particle .and. this%name /= "passtobottom") then |
| 125 | + if (particle%idrymeth == 0) then |
| 126 | + ! drop to water table |
| 127 | + particle%z = cell_defn%top |
| 128 | + call this%save(particle, reason=1) |
| 129 | + else if (particle%idrymeth == 1) then |
| 130 | + ! stop |
| 131 | + particle%advancing = .false. |
| 132 | + particle%istatus = TERM_INACTIVE |
| 133 | + call this%save(particle, reason=3) |
| 134 | + return |
| 135 | + else if (particle%idrymeth == 2) then |
| 136 | + ! stay |
| 137 | + particle%advancing = .false. |
| 138 | + no_exit_face = .false. |
| 139 | + |
| 140 | + ! we might report tracking times |
| 141 | + ! out of order here, but we want |
| 142 | + ! the particle termination event |
| 143 | + ! (if this is the last time step) |
| 144 | + ! to have the maximum tracking t, |
| 145 | + ! so we need to keep tabs on it. |
| 146 | + ttrackmax = totim |
| 147 | + |
| 148 | + ! update tracking time to time |
| 149 | + ! step end time and save record |
| 150 | + particle%ttrack = totim |
| 151 | + call this%save(particle, reason=2) |
| 152 | + |
| 153 | + ! record user tracking times |
| 154 | + call this%tracktimes%advance() |
| 155 | + if (this%tracktimes%any()) then |
| 156 | + do i = this%tracktimes%selection(1), this%tracktimes%selection(2) |
| 157 | + t = this%tracktimes%times(i) |
| 158 | + if (t < totimc) cycle |
| 159 | + if (t >= tmax) exit |
| 160 | + particle%ttrack = t |
| 161 | + call this%save(particle, reason=5) |
| 162 | + if (t > ttrackmax) ttrackmax = t |
| 163 | + end do |
| 164 | + end if |
| 165 | + end if |
| 166 | + end if |
| 167 | + |
| 168 | + if (no_exit_face) then |
| 169 | + particle%advancing = .false. |
| 170 | + particle%istatus = TERM_NO_EXITS |
| 171 | + call this%save(particle, reason=3) |
| 172 | + return |
| 173 | + end if |
| 174 | + |
| 175 | + end subroutine check |
| 176 | + |
| 177 | +end module MethodCellModule |
0 commit comments