@@ -22,6 +22,22 @@ module MethodModule
2222 use MathUtilModule, only: is_close
2323 implicit none
2424
25+ public :: LEVEL_MODEL, LEVEL_FEATURE, LEVEL_SUBFEATURE
26+
27+ ! > @brief Tracking method level enumeration.
28+ ! !
29+ ! > Tracking levels: 1: model, 2: grid feature, 3: grid subfeature.
30+ ! ! A tracking level identifies the domain through which a tracking
31+ ! ! method is responsible for moving a particle. Methods operate on
32+ ! ! a particular level and delegate to submethods for levels higher
33+ ! ! than (i.e. below the scope of) their own.
34+ ! <
35+ enum, bind(C)
36+ enumerator :: LEVEL_MODEL = 1
37+ enumerator :: LEVEL_FEATURE = 2
38+ enumerator :: LEVEL_SUBFEATURE = 3
39+ end enum
40+
2541 private
2642 public :: MethodType
2743
@@ -55,6 +71,7 @@ module MethodModule
5571 ! Overridden in subtypes that delegate
5672 procedure :: pass ! < pass the particle to the next subdomain
5773 procedure :: load ! < load the subdomain tracking method
74+ procedure :: get_level ! < get the tracking method level
5875 ! Implemented here
5976 procedure :: init
6077 procedure :: track
@@ -131,7 +148,6 @@ recursive subroutine track(this, particle, level, tmax)
131148 integer (I4B) :: nextlevel
132149 class(methodType), pointer :: submethod
133150
134- ! Advance the particle over subdomains
135151 advancing = .true.
136152 nextlevel = level + 1
137153 do while (advancing)
@@ -148,16 +164,17 @@ subroutine try_pass(this, particle, nextlevel, advancing)
148164 integer (I4B) :: nextlevel
149165 logical (LGP) :: advancing
150166
151- ! if the particle is done advancing, reset the domain boundary flag.
152- if (.not. particle% advancing) then
153- particle% iboundary = 0
154- advancing = .false.
155- else
156- ! otherwise pass the particle to the next subdomain.
157- ! if that leaves it on a boundary, stop advancing.
167+ if (particle% advancing) then
168+ ! if still advancing, pass to the next subdomain.
169+ ! if that puts us on a boundary, then we're done.
158170 call this% pass(particle)
159171 if (particle% iboundary(nextlevel - 1 ) .ne. 0 ) &
160172 advancing = .false.
173+ else
174+ ! otherwise we're already done so
175+ ! reset the domain boundary value.
176+ advancing = .false.
177+ particle% iboundary = 0
161178 end if
162179 end subroutine try_pass
163180
@@ -170,6 +187,14 @@ subroutine load(this, particle, next_level, submethod)
170187 call pstop(1 , " load must be overridden" )
171188 end subroutine load
172189
190+ ! > @brief Get the tracking method's level.
191+ function get_level (this ) result(level)
192+ class(MethodType), intent (in ) :: this
193+ integer (I4B) :: level
194+ level = - 1 ! suppress compiler warning
195+ call pstop(1 , " get_level must be overridden" )
196+ end function get_level
197+
173198 ! > @brief Pass the particle to the next subdomain.
174199 subroutine pass (this , particle )
175200 class(MethodType), intent (inout ) :: this
@@ -182,7 +207,6 @@ subroutine release(this, particle)
182207 class(MethodType), intent (inout ) :: this
183208 type (ParticleType), pointer , intent (inout ) :: particle
184209 class(ParticleEventType), pointer :: event
185-
186210 allocate (ReleaseEventType :: event)
187211 call this% events% dispatch(particle, event)
188212 deallocate (event)
@@ -194,7 +218,6 @@ subroutine terminate(this, particle, status)
194218 type (ParticleType), pointer , intent (inout ) :: particle
195219 integer (I4B), intent (in ), optional :: status
196220 class(ParticleEventType), pointer :: event
197-
198221 particle% advancing = .false.
199222 if (present (status)) particle% istatus = status
200223 allocate (TerminationEventType :: event)
@@ -207,7 +230,6 @@ subroutine timestep(this, particle)
207230 class(MethodType), intent (inout ) :: this
208231 type (ParticleType), pointer , intent (inout ) :: particle
209232 class(ParticleEventType), pointer :: event
210-
211233 allocate (TimeStepEventType :: event)
212234 call this% events% dispatch(particle, event)
213235 deallocate (event)
@@ -218,7 +240,6 @@ subroutine weaksink(this, particle)
218240 class(MethodType), intent (inout ) :: this
219241 type (ParticleType), pointer , intent (inout ) :: particle
220242 class(ParticleEventType), pointer :: event
221-
222243 allocate (WeakSinkEventType :: event)
223244 call this% events% dispatch(particle, event)
224245 deallocate (event)
@@ -229,7 +250,6 @@ subroutine usertime(this, particle)
229250 class(MethodType), intent (inout ) :: this
230251 type (ParticleType), pointer , intent (inout ) :: particle
231252 class(ParticleEventType), pointer :: event
232-
233253 allocate (UserTimeEventType :: event)
234254 call this% events% dispatch(particle, event)
235255 deallocate (event)
0 commit comments