Skip to content

Commit f516f1b

Browse files
authored
refactor(prt): introduce enum for tracking level (#2456)
Use an enum for tracking level, where levels correspond to (sub)method delegation for model, feature, subfeature etc
1 parent f98da70 commit f516f1b

File tree

15 files changed

+143
-97
lines changed

15 files changed

+143
-97
lines changed

src/Model/ParticleTracking/prt-prp.f90

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module PrtPrpModule
2323
use DisvModule, only: DisvType
2424
use ErrorUtilModule, only: pstop
2525
use MathUtilModule, only: arange, is_close
26+
use MethodModule, only: LEVEL_MODEL, LEVEL_FEATURE, LEVEL_SUBFEATURE
2627

2728
implicit none
2829

@@ -535,12 +536,12 @@ subroutine initialize_particle(this, particle, ip, trelease)
535536
end if
536537

537538
particle%ttrack = particle%trelease
538-
particle%itrdomain(1) = 0
539-
particle%iboundary(1) = 0
540-
particle%itrdomain(2) = ic
541-
particle%iboundary(2) = 0
542-
particle%itrdomain(3) = 0
543-
particle%iboundary(3) = 0
539+
particle%itrdomain(LEVEL_MODEL) = 0
540+
particle%iboundary(LEVEL_MODEL) = 0
541+
particle%itrdomain(LEVEL_FEATURE) = ic
542+
particle%iboundary(LEVEL_FEATURE) = 0
543+
particle%itrdomain(LEVEL_SUBFEATURE) = 0
544+
particle%iboundary(LEVEL_SUBFEATURE) = 0
544545
particle%ifrctrn = this%ifrctrn
545546
particle%iexmeth = this%iexmeth
546547
particle%iextend = this%iextend

src/Model/ParticleTracking/prt.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ module PrtModule
1818
use PrtOcModule, only: PrtOcType
1919
use BudgetModule, only: BudgetType
2020
use ListModule, only: ListType
21-
use ParticleModule, only: ParticleType, create_particle
21+
use ParticleModule, only: ParticleType, create_particle, TERM_UNRELEASED
2222
use ParticleEventsModule, only: ParticleEventDispatcherType, &
2323
ParticleEventConsumerType
2424
use ParticleTracksModule, only: ParticleTracksType, &
2525
ParticleTrackFileType
2626
use SimModule, only: count_errors, store_error, store_error_filename
2727
use MemoryManagerModule, only: mem_allocate
28-
use MethodModule, only: MethodType
28+
use MethodModule, only: MethodType, LEVEL_FEATURE
2929

3030
implicit none
3131

@@ -463,8 +463,8 @@ subroutine prt_cq_sto(this)
463463
do np = 1, packobj%nparticles
464464
istatus = packobj%particles%istatus(np)
465465
! this may need to change if istatus flags change
466-
if ((istatus > 0) .and. (istatus /= 8)) then
467-
n = packobj%particles%itrdomain(np, 2)
466+
if ((istatus > 0) .and. (istatus /= TERM_UNRELEASED)) then
467+
n = packobj%particles%itrdomain(np, LEVEL_FEATURE)
468468
! Each particle currently assigned unit mass
469469
this%masssto(n) = this%masssto(n) + DONE
470470
end if

src/Solution/ParticleTracker/Method/Method.f90

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/Solution/ParticleTracker/Method/MethodCell.f90

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module MethodCellModule
33
use KindModule, only: DP, I4B, LGP
44
use ErrorUtilModule, only: pstop
55
use ConstantsModule, only: DONE, DZERO
6-
use MethodModule, only: MethodType
6+
use MethodModule, only: MethodType, LEVEL_FEATURE
77
use ParticleModule, only: ParticleType, TERM_NO_EXITS, TERM_BOUNDARY
88
use ParticleEventModule, only: ParticleEventType
99
use CellExitEventModule, only: CellExitEventType
@@ -20,6 +20,7 @@ module MethodCellModule
2020
procedure, public :: cellexit
2121
procedure, public :: forms_cycle
2222
procedure, public :: store_event
23+
procedure, public :: get_level
2324
end type MethodCellType
2425

2526
contains
@@ -182,7 +183,7 @@ subroutine cellexit(this, particle)
182183
allocate (CellExitEventType :: event)
183184
select type (event)
184185
type is (CellExitEventType)
185-
event%exit_face = particle%iboundary(2)
186+
event%exit_face = particle%iboundary(LEVEL_FEATURE)
186187
end select
187188
call this%events%dispatch(particle, event)
188189
if (particle%icycwin == 0) then
@@ -258,4 +259,11 @@ subroutine store_event(this, particle, event)
258259
end select
259260
end subroutine store_event
260261

262+
!> @brief Get the cell method's level.
263+
function get_level(this) result(level)
264+
class(MethodCellType), intent(in) :: this
265+
integer(I4B) :: level
266+
level = LEVEL_FEATURE
267+
end function get_level
268+
261269
end module MethodCellModule

src/Solution/ParticleTracker/Method/MethodCellPassToBot.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module MethodCellPassToBotModule
22

33
use KindModule, only: DP, I4B
4+
use MethodModule, only: LEVEL_FEATURE
45
use MethodCellModule, only: MethodCellType
56
use CellDefnModule, only: CellDefnType, create_defn
67
use PrtFmiModule, only: PrtFmiType
@@ -55,7 +56,7 @@ subroutine apply_ptb(this, particle, tmax)
5556

5657
! Pass to bottom face
5758
particle%z = this%cell%defn%bot
58-
particle%iboundary(2) = this%cell%defn%npolyverts + 2
59+
particle%iboundary(LEVEL_FEATURE) = this%cell%defn%npolyverts + 2
5960

6061
! Terminate if in bottom layer
6162
select type (dis => this%fmi%dis)

src/Solution/ParticleTracker/Method/MethodCellPollock.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module MethodCellPollockModule
22

33
use KindModule, only: DP, I4B
44
use ConstantsModule, only: DONE, DZERO
5-
use MethodModule, only: MethodType
5+
use MethodModule, only: MethodType, LEVEL_FEATURE, LEVEL_SUBFEATURE
66
use MethodCellModule, only: MethodCellType
77
use MethodSubcellPoolModule, only: method_subcell_plck, &
88
method_subcell_tern
@@ -82,7 +82,7 @@ subroutine pass_mcp(this, particle)
8282
integer(I4B) :: exitface
8383
integer(I4B) :: entryface
8484

85-
exitface = particle%iboundary(3)
85+
exitface = particle%iboundary(LEVEL_SUBFEATURE)
8686
! Map subcell exit face to cell face
8787
select case (exitface) ! note: exitFace uses Dave's iface convention
8888
case (0)
@@ -101,7 +101,7 @@ subroutine pass_mcp(this, particle)
101101
entryface = 7
102102
end select
103103
if (entryface .eq. -1) then
104-
particle%iboundary(2) = 0
104+
particle%iboundary(LEVEL_FEATURE) = 0
105105
else
106106
if ((entryface .ge. 1) .and. (entryface .le. 4)) then
107107
! Account for local cell rotation
@@ -111,7 +111,7 @@ subroutine pass_mcp(this, particle)
111111
end select
112112
if (entryface .gt. 4) entryface = entryface - 4
113113
end if
114-
particle%iboundary(2) = entryface
114+
particle%iboundary(LEVEL_FEATURE) = entryface
115115
end if
116116
end subroutine pass_mcp
117117

@@ -152,7 +152,7 @@ subroutine apply_mcp(this, particle, tmax)
152152
call particle%reset_transform()
153153
end select
154154

155-
if (particle%iboundary(2) > 0) call this%cellexit(particle)
155+
if (particle%iboundary(LEVEL_FEATURE) > 0) call this%cellexit(particle)
156156
end subroutine apply_mcp
157157

158158
!> @brief Loads the lone rectangular subcell from the rectangular cell

0 commit comments

Comments
 (0)