Skip to content

Commit 667c7b5

Browse files
authored
refactor(prt): move events to separate modules (#2454)
Reorganizing as the shared module was getting big. Also defer get_text so each event provides its own string representation.
1 parent 518a719 commit 667c7b5

18 files changed

+621
-179
lines changed

make/makefile

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,27 @@ SOURCEDIR25=../src/Solution/ParticleTracker
3232
SOURCEDIR26=../src/Solution/ParticleTracker/Domain
3333
SOURCEDIR27=../src/Solution/ParticleTracker/Method
3434
SOURCEDIR28=../src/Solution/ParticleTracker/Particle
35-
SOURCEDIR29=../src/Timing
36-
SOURCEDIR30=../src/Utilities
37-
SOURCEDIR31=../src/Utilities/ArrayRead
38-
SOURCEDIR32=../src/Utilities/Export
39-
SOURCEDIR33=../src/Utilities/Idm
40-
SOURCEDIR34=../src/Utilities/Idm/mf6blockfile
41-
SOURCEDIR35=../src/Utilities/Idm/netcdf
42-
SOURCEDIR36=../src/Utilities/Libraries
43-
SOURCEDIR37=../src/Utilities/Libraries/blas
44-
SOURCEDIR38=../src/Utilities/Libraries/daglib
45-
SOURCEDIR39=../src/Utilities/Libraries/rcm
46-
SOURCEDIR40=../src/Utilities/Libraries/sparsekit
47-
SOURCEDIR41=../src/Utilities/Libraries/sparskit2
48-
SOURCEDIR42=../src/Utilities/Matrix
49-
SOURCEDIR43=../src/Utilities/Memory
50-
SOURCEDIR44=../src/Utilities/Observation
51-
SOURCEDIR45=../src/Utilities/OutputControl
52-
SOURCEDIR46=../src/Utilities/Performance
53-
SOURCEDIR47=../src/Utilities/TimeSeries
54-
SOURCEDIR48=../src/Utilities/Vector
35+
SOURCEDIR29=../src/Solution/ParticleTracker/Particle/Events
36+
SOURCEDIR30=../src/Timing
37+
SOURCEDIR31=../src/Utilities
38+
SOURCEDIR32=../src/Utilities/ArrayRead
39+
SOURCEDIR33=../src/Utilities/Export
40+
SOURCEDIR34=../src/Utilities/Idm
41+
SOURCEDIR35=../src/Utilities/Idm/mf6blockfile
42+
SOURCEDIR36=../src/Utilities/Idm/netcdf
43+
SOURCEDIR37=../src/Utilities/Libraries
44+
SOURCEDIR38=../src/Utilities/Libraries/blas
45+
SOURCEDIR39=../src/Utilities/Libraries/daglib
46+
SOURCEDIR40=../src/Utilities/Libraries/rcm
47+
SOURCEDIR41=../src/Utilities/Libraries/sparsekit
48+
SOURCEDIR42=../src/Utilities/Libraries/sparskit2
49+
SOURCEDIR43=../src/Utilities/Matrix
50+
SOURCEDIR44=../src/Utilities/Memory
51+
SOURCEDIR45=../src/Utilities/Observation
52+
SOURCEDIR46=../src/Utilities/OutputControl
53+
SOURCEDIR47=../src/Utilities/Performance
54+
SOURCEDIR48=../src/Utilities/TimeSeries
55+
SOURCEDIR49=../src/Utilities/Vector
5556

5657
VPATH = \
5758
${SOURCEDIR1} \
@@ -101,7 +102,8 @@ ${SOURCEDIR44} \
101102
${SOURCEDIR45} \
102103
${SOURCEDIR46} \
103104
${SOURCEDIR47} \
104-
${SOURCEDIR48}
105+
${SOURCEDIR48} \
106+
${SOURCEDIR49}
105107

106108
.SUFFIXES: .f90 .F90 .o
107109

@@ -293,6 +295,7 @@ $(OBJDIR)/TimeArraySeriesManager.o \
293295
$(OBJDIR)/PackageMover.o \
294296
$(OBJDIR)/Obs.o \
295297
$(OBJDIR)/NumericalPackage.o \
298+
$(OBJDIR)/Particle.o \
296299
$(OBJDIR)/PackageBudget.o \
297300
$(OBJDIR)/HeadFileReader.o \
298301
$(OBJDIR)/GridFileReader.o \
@@ -305,22 +308,29 @@ $(OBJDIR)/Dis2d.o \
305308
$(OBJDIR)/BudgetObject.o \
306309
$(OBJDIR)/BoundaryPackage.o \
307310
$(OBJDIR)/CellDefn.o \
308-
$(OBJDIR)/Particle.o \
311+
$(OBJDIR)/ParticleEvent.o \
309312
$(OBJDIR)/sort.o \
310313
$(OBJDIR)/FlowModelInterface.o \
311314
$(OBJDIR)/Cell.o \
312-
$(OBJDIR)/ParticleEvent.o \
315+
$(OBJDIR)/FeatExitEvent.o \
316+
$(OBJDIR)/WeakSinkEvent.o \
317+
$(OBJDIR)/UserTimeEvent.o \
318+
$(OBJDIR)/TimeStepEvent.o \
313319
$(OBJDIR)/TimeSelect.o \
320+
$(OBJDIR)/TerminationEvent.o \
314321
$(OBJDIR)/Subcell.o \
322+
$(OBJDIR)/ReleaseEvent.o \
315323
$(OBJDIR)/prt-fmi.o \
316324
$(OBJDIR)/ParticleEvents.o \
325+
$(OBJDIR)/SubcellExitEvent.o \
317326
$(OBJDIR)/Method.o \
318327
$(OBJDIR)/TernarySolveUtils.o \
319328
$(OBJDIR)/SubcellTri.o \
320329
$(OBJDIR)/MethodSubcell.o \
321330
$(OBJDIR)/SubcellRect.o \
322331
$(OBJDIR)/MethodSubcellTernary.o \
323332
$(OBJDIR)/MethodSubcellPollock.o \
333+
$(OBJDIR)/CellExitEvent.o \
324334
$(OBJDIR)/TimeStepSelect.o \
325335
$(OBJDIR)/LinearAlgebraUtils.o \
326336
$(OBJDIR)/SfrCrossSectionUtils.o \

msvs/mf6core.vfproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,17 @@
443443
<File RelativePath="..\src\Solution\ParticleTracker\Method\MethodSubcellPool.f90"/>
444444
<File RelativePath="..\src\Solution\ParticleTracker\Method\MethodSubcellTernary.f90"/>
445445
<File RelativePath="..\src\Solution\ParticleTracker\Method\TernarySolveUtils.f90"/></Filter>
446+
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Events\ParticleEvent.f90"/>
447+
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Events\ParticleEvents.f90"/>
448+
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Events\ReleaseEvent.f90"/>
449+
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Events\FeatExitEvent.f90"/>
450+
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Events\CellExitEvent.f90"/>
451+
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Events\SubcellExitEvent.f90"/>
452+
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Events\TerminationEvent.f90"/>
453+
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Events\UserTimeEvent.f90"/>
454+
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Events\TimeStepEvent.f90"/>
455+
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Events\WeakSinkEvent.f90"/>
446456
<File RelativePath="..\src\Solution\ParticleTracker\Particle\Particle.f90"/>
447-
<File RelativePath="..\src\Solution\ParticleTracker\Particle\ParticleEvent.f90"/>
448-
<File RelativePath="..\src\Solution\ParticleTracker\Particle\ParticleEvents.f90"/>
449457
<File RelativePath="..\src\Solution\ParticleTracker\Particle\ParticleReleaseSchedule.f90"/>
450458
<File RelativePath="..\src\Solution\ParticleTracker\Particle\ParticleTracks.f90"/>
451459
<Filter Name="PETSc">

src/Solution/ParticleTracker/Method/Method.f90

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ module MethodModule
77
use SubcellModule, only: SubcellType
88
use ParticleModule, only: ParticleType
99
use ParticleEventsModule, only: ParticleEventDispatcherType
10-
use ParticleEventModule, only: ParticleEventType, &
11-
ReleaseEventType, &
12-
TimeStepEventType, &
13-
TerminationEventType, &
14-
WeakSinkEventType, &
15-
UserTimeEventType, &
16-
FeatExitEventType
10+
use ParticleEventModule, only: ParticleEventType
11+
use ReleaseEventModule, only: ReleaseEventType
12+
use TimeStepEventModule, only: TimeStepEventType
13+
use TerminationEventModule, only: TerminationEventType
14+
use WeakSinkEventModule, only: WeakSinkEventType
15+
use UserTimeEventModule, only: UserTimeEventType
16+
use FeatExitEventModule, only: FeatExitEventType
1717
use BaseDisModule, only: DisBaseType
1818
use PrtFmiModule, only: PrtFmiType
1919
use CellModule, only: CellType

src/Solution/ParticleTracker/Method/MethodCell.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module MethodCellModule
44
use ConstantsModule, only: DONE, DZERO
55
use MethodModule, only: MethodType
66
use ParticleModule, only: ParticleType
7-
use ParticleEventModule, only: ParticleEventType, CellExitEventType
7+
use ParticleEventModule, only: ParticleEventType
8+
use CellExitEventModule, only: CellExitEventType
89
use CellDefnModule, only: CellDefnType
910
implicit none
1011

src/Solution/ParticleTracker/Method/MethodSubcell.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module MethodSubcellModule
33
use MethodModule, only: MethodType
44
use ParticleModule, only: ParticleType
55
use CellDefnModule, only: CellDefnType
6-
use ParticleEventModule, only: ParticleEventType, SubcellExitEventType
6+
use ParticleEventModule, only: ParticleEventType
7+
use SubcellExitEventModule, only: SubcellExitEventType
78

89
private
910
public :: MethodSubcellType
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module CellExitEventModule
2+
use KindModule, only: DP, I4B, LGP
3+
use ConstantsModule, only: LENHUGELINE
4+
use ErrorUtilModule, only: pstop
5+
use ParticleModule, only: ParticleType
6+
use ParticleEventModule, only: FEATEXIT
7+
use FeatExitEventModule, only: FeatExitEventType
8+
implicit none
9+
10+
private
11+
public :: CellExitEventType
12+
13+
type, extends(FeatExitEventType) :: CellExitEventType
14+
integer(I4B) :: exit_face ! face through which the particle exited
15+
contains
16+
procedure :: get_code
17+
procedure :: get_verb
18+
procedure :: get_text
19+
end type CellExitEventType
20+
21+
contains
22+
23+
function get_code(this) result(code)
24+
class(CellExitEventType), intent(in) :: this
25+
integer(I4B) :: code
26+
code = FEATEXIT
27+
end function get_code
28+
29+
function get_verb(this) result(verb)
30+
class(CellExitEventType), intent(in) :: this
31+
character(len=:), allocatable :: verb
32+
verb = 'exited cell'
33+
end function get_verb
34+
35+
function get_text(this) result(text)
36+
class(CellExitEventType), intent(in) :: this
37+
character(len=:), allocatable :: text
38+
character(len=LENHUGELINE) :: temp
39+
40+
write (temp, '(*(G0))') &
41+
'Particle from model ', this%imdl, &
42+
', package ', this%iprp, &
43+
', point ', this%irpt, &
44+
', time ', this%trelease, &
45+
' '//this%get_verb()// &
46+
' in layer ', this%ilay, &
47+
', cell ', this%icu, &
48+
', zone ', this%izone, &
49+
' through face ', this%exit_face, &
50+
' at x ', this%x, &
51+
', y ', this%y, &
52+
', z ', this%z, &
53+
', time ', this%ttrack, &
54+
', period ', this%kper, &
55+
', timestep ', this%kstp, &
56+
' with status ', this%istatus
57+
text = trim(adjustl(temp))
58+
end function get_text
59+
60+
end module CellExitEventModule
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module FeatExitEventModule
2+
use KindModule, only: DP, I4B, LGP
3+
use ConstantsModule, only: LENHUGELINE
4+
use ErrorUtilModule, only: pstop
5+
use ParticleModule, only: ParticleType
6+
use ParticleEventModule, only: ParticleEventType, FEATEXIT
7+
implicit none
8+
9+
private
10+
public :: FeatExitEventType
11+
12+
type, extends(ParticleEventType) :: FeatExitEventType
13+
contains
14+
procedure :: get_code
15+
procedure :: get_verb
16+
procedure :: get_text
17+
end type FeatExitEventType
18+
19+
contains
20+
21+
function get_code(this) result(code)
22+
class(FeatExitEventType), intent(in) :: this
23+
integer(I4B) :: code
24+
code = FEATEXIT
25+
end function get_code
26+
27+
function get_verb(this) result(verb)
28+
class(FeatExitEventType), intent(in) :: this
29+
character(len=:), allocatable :: verb
30+
verb = 'exited grid feature'
31+
end function get_verb
32+
33+
function get_text(this) result(text)
34+
class(FeatExitEventType), intent(in) :: this
35+
character(len=:), allocatable :: text
36+
character(len=LENHUGELINE) :: temp
37+
38+
write (temp, '(*(G0))') &
39+
'Particle from model ', this%imdl, &
40+
', package ', this%iprp, &
41+
', point ', this%irpt, &
42+
', time ', this%trelease, &
43+
' '//this%get_verb()// &
44+
' in layer ', this%ilay, &
45+
', cell ', this%icu, &
46+
', zone ', this%izone, &
47+
' at x ', this%x, &
48+
', y ', this%y, &
49+
', z ', this%z, &
50+
', time ', this%ttrack, &
51+
', period ', this%kper, &
52+
', timestep ', this%kstp, &
53+
' with status ', this%istatus
54+
text = trim(adjustl(temp))
55+
end function get_text
56+
57+
end module FeatExitEventModule
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module ParticleEventModule
2+
use KindModule, only: DP, I4B, LGP
3+
use ConstantsModule, only: LENHUGELINE
4+
use ErrorUtilModule, only: pstop
5+
use ParticleModule, only: ParticleType
6+
implicit none
7+
8+
private
9+
public :: ParticleEventType
10+
public :: RELEASE
11+
public :: FEATEXIT
12+
public :: TIMESTEP
13+
public :: TERMINATE
14+
public :: WEAKSINK
15+
public :: USERTIME
16+
17+
!> @brief Particle event enumeration.
18+
!!
19+
!! A number of events may occur to particles, each of which may (or may
20+
!! not) be of interest to the user. The user selects events to report.
21+
!<
22+
enum, bind(C)
23+
enumerator :: RELEASE = 0 !< particle was released
24+
enumerator :: FEATEXIT = 1 !< particle exited a grid feature
25+
enumerator :: TIMESTEP = 2 !< time step ended
26+
enumerator :: TERMINATE = 3 !< particle terminated
27+
enumerator :: WEAKSINK = 4 !< particle entered a weak sink
28+
enumerator :: USERTIME = 5 !< user-specified tracking time
29+
end enum
30+
31+
!> @brief Base type for particle events.
32+
!!
33+
!! Events may be identical except for their type/code, reflecting the
34+
!! fact that several events of interest may occur at a given moment.
35+
type, abstract :: ParticleEventType
36+
integer(I4B) :: imdl, iprp, irpt ! release model, package, and point
37+
real(DP) :: trelease = 0.0_DP ! release time
38+
integer(I4B) :: kper = 0, kstp = 0 ! period and step
39+
integer(I4B) :: ilay, icu, izone = 0
40+
real(DP) :: ttrack = 0.0_DP ! simulation time
41+
real(DP) :: x = 0.0_DP, y = 0.0_DP, z = 0.0_DP ! particle position
42+
integer(I4B) :: istatus = -1 ! status code
43+
contains
44+
procedure(get_int), deferred :: get_code
45+
procedure(get_str), deferred :: get_verb
46+
procedure(get_str), deferred :: get_text
47+
procedure :: log
48+
end type ParticleEventType
49+
50+
abstract interface
51+
function get_int(this) result(int)
52+
IMPORT I4B
53+
IMPORT ParticleEventType
54+
class(ParticleEventType), intent(in) :: this
55+
integer(I4B) :: int
56+
end function get_int
57+
58+
function get_str(this) result(str)
59+
IMPORT ParticleEventType
60+
class(ParticleEventType), intent(in) :: this
61+
character(len=:), allocatable :: str
62+
end function get_str
63+
end interface
64+
65+
contains
66+
67+
subroutine log(this, iun)
68+
class(ParticleEventType), intent(inout) :: this
69+
integer(I4B), intent(in) :: iun
70+
if (iun >= 0) write (iun, '(*(G0))') this%get_text()
71+
end subroutine log
72+
73+
end module ParticleEventModule

src/Solution/ParticleTracker/Particle/ParticleEvents.f90 renamed to src/Solution/ParticleTracker/Particle/Events/ParticleEvents.f90

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ module ParticleEventsModule
22
use KindModule, only: DP, I4B, LGP
33
use ListModule, only: ListType
44
use ParticleModule, only: ParticleType
5-
use ParticleEventModule, only: ParticleEventType, &
6-
ReleaseEventType, &
7-
FeatExitEventType, &
8-
TimestepEventType, &
9-
TerminationEventType, &
10-
WeakSinkEventType, &
11-
UserTimeEventType
5+
use ParticleEventModule, only: ParticleEventType
126
implicit none
137

148
private
@@ -54,6 +48,7 @@ subroutine dispatch(this, particle, event)
5448
class(ParticleEventType), pointer, intent(inout) :: event
5549
! local
5650
integer(I4B) :: i, per, stp
51+
real(DP) :: x, y, z
5752
class(*), pointer :: p
5853

5954
! If tracking time falls exactly on a boundary between time steps,
@@ -72,6 +67,12 @@ subroutine dispatch(this, particle, event)
7267
end if
7368
end if
7469

70+
! Convert to model coordinates if we need to
71+
x = particle%x
72+
y = particle%y
73+
z = particle%z
74+
call particle%get_model_coords(x, y, z)
75+
7576
event%kper = per
7677
event%kstp = stp
7778
event%imdl = particle%imdl
@@ -82,8 +83,10 @@ subroutine dispatch(this, particle, event)
8283
event%izone = particle%izone
8384
event%trelease = particle%trelease
8485
event%ttrack = particle%ttrack
86+
event%x = x
87+
event%y = y
88+
event%z = z
8589
event%istatus = particle%istatus
86-
call particle%get_model_coords(event%x, event%y, event%z)
8790

8891
do i = 1, this%consumers%Count()
8992
p => this%consumers%GetItem(i)

0 commit comments

Comments
 (0)