Skip to content

Commit c0ac5bb

Browse files
committed
feat(prt): configurable event buffering
1 parent a96526e commit c0ac5bb

5 files changed

Lines changed: 288 additions & 95 deletions

File tree

doc/mf6io/mf6ivar/dfn/prt-oc.dfn

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ mf6internal dev_dump_evtrace
292292
longname print particle tracking events
293293
description print a verbose particle tracking event trace to standard output
294294

295+
block options
296+
name scratch_buffer
297+
type keyword
298+
reader urword
299+
optional true
300+
longname buffer track events in scratch file instead of memory
301+
description keyword to stage track events in a scratch file instead of an in-memory buffer, which prevents out-of-memory errors for simulations with very many particles or events
302+
295303
# --------------------- prt oc dimensions ------------------
296304

297305
block dimensions

src/Idm/prt-ocidm.f90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module PrtOcInputModule
4040
logical :: track_timesfile = .false.
4141
logical :: timesfile = .false.
4242
logical :: dev_dump_evtrace = .false.
43+
logical :: scratch_buffer = .false.
4344
logical :: ntracktimes = .false.
4445
logical :: time = .false.
4546
logical :: saverecord = .false.
@@ -594,6 +595,25 @@ module PrtOcInputModule
594595
.false. & ! timeseries
595596
)
596597

598+
type(InputParamDefinitionType), parameter :: &
599+
prtoc_scratch_buffer = InputParamDefinitionType &
600+
( &
601+
'PRT', & ! component
602+
'OC', & ! subcomponent
603+
'OPTIONS', & ! block
604+
'SCRATCH_BUFFER', & ! tag name
605+
'SCRATCH_BUFFER', & ! fortran variable
606+
'KEYWORD', & ! type
607+
'', & ! shape
608+
'buffer track events in scratch file instead of memory', & ! longname
609+
.false., & ! required
610+
.false., & ! developmode
611+
.false., & ! multi-record
612+
.false., & ! preserve case
613+
.false., & ! layered
614+
.false. & ! timeseries
615+
)
616+
597617
type(InputParamDefinitionType), parameter :: &
598618
prtoc_ntracktimes = InputParamDefinitionType &
599619
( &
@@ -853,6 +873,7 @@ module PrtOcInputModule
853873
prtoc_track_timesfile, &
854874
prtoc_timesfile, &
855875
prtoc_dev_dump_evtrace, &
876+
prtoc_scratch_buffer, &
856877
prtoc_ntracktimes, &
857878
prtoc_time, &
858879
prtoc_saverecord, &

src/Model/ParticleTracking/prt-oc.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module PrtOcModule
3333
logical(LGP), pointer :: trackdropped => null() !< whether to track drops to water table
3434
integer(I4B), pointer :: ntracktimes => null() !< number of user-specified tracking times
3535
logical(LGP), pointer :: dump_event_trace => null() !< whether to dump event trace for debugging
36+
logical(LGP), pointer :: scratch_buffer => null() !< whether to use scratch file instead of memory for event buffering
3637
type(TimeSelectType), pointer :: tracktimes !< user-specified tracking times
3738

3839
contains
@@ -78,6 +79,7 @@ subroutine prt_oc_allocate_scalars(this, name_model, input_mempath)
7879
allocate (this%name_model)
7980
allocate (this%input_fname)
8081
call mem_allocate(this%dump_event_trace, 'DUMP_EVENT_TRACE', this%memoryPath)
82+
call mem_allocate(this%scratch_buffer, 'SCRATCH_BUFFER', this%memoryPath)
8183
call mem_allocate(this%inunit, 'INUNIT', this%memoryPath)
8284
call mem_allocate(this%iout, 'IOUT', this%memoryPath)
8385
call mem_allocate(this%ibudcsv, 'IBUDCSV', this%memoryPath)
@@ -101,6 +103,7 @@ subroutine prt_oc_allocate_scalars(this, name_model, input_mempath)
101103
this%input_mempath = input_mempath
102104
this%input_fname = ''
103105
this%dump_event_trace = .false.
106+
this%scratch_buffer = .false.
104107
this%inunit = 0
105108
this%iout = 0
106109
this%ibudcsv = 0
@@ -178,6 +181,7 @@ subroutine prt_oc_da(this)
178181

179182
deallocate (this%name_model)
180183
call mem_deallocate(this%dump_event_trace)
184+
call mem_deallocate(this%scratch_buffer)
181185
call mem_deallocate(this%inunit)
182186
call mem_deallocate(this%iout)
183187
call mem_deallocate(this%ibudcsv)
@@ -251,6 +255,8 @@ subroutine prt_oc_source_options(this)
251255
found%track_usertime)
252256
call mem_set_value(evinput, 'DEV_DUMP_EVTRACE', this%input_mempath, &
253257
found%dev_dump_evtrace)
258+
call mem_set_value(evinput, 'SCRATCH_BUFFER', this%input_mempath, &
259+
found%scratch_buffer)
254260

255261
if (found%track_release) this%trackrelease = .true.
256262
if (found%track_exit) this%trackfeatexit = .true.
@@ -261,6 +267,7 @@ subroutine prt_oc_source_options(this)
261267
if (found%track_weaksink) this%trackweaksink = .true.
262268
if (found%track_usertime) this%trackusertime = .true.
263269
if (found%dev_dump_evtrace) this%dump_event_trace = .true.
270+
if (found%scratch_buffer) this%scratch_buffer = .true.
264271

265272
! default to all events
266273
if (.not. (found%track_release .or. &

src/Model/ParticleTracking/prt.f90

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module PrtModule
2222
use ParticleEventsModule, only: ParticleEventDispatcherType, handle_event
2323
use ParticleTracksModule, only: ParticleTracksType, &
2424
ParticleTrackFileType, &
25-
write_particle_event
25+
add_particle_event
2626
use SimModule, only: count_errors, store_error, store_error_filename
2727
use MemoryManagerModule, only: mem_allocate
2828
use MethodModule, only: MethodType, LEVEL_FEATURE
@@ -53,7 +53,7 @@ module PrtModule
5353
type(MethodDisType), pointer :: method_dis => null() ! DIS tracking method
5454
type(MethodDisvType), pointer :: method_disv => null() ! DISV tracking method
5555
type(ParticleEventDispatcherType), pointer :: events => null() ! event dispatcher
56-
class(ParticleTracksType), pointer :: tracks ! track output manager
56+
type(ParticleTracksType), pointer :: tracks ! track output manager
5757
integer(I4B), pointer :: infmi => null() ! unit number FMI
5858
integer(I4B), pointer :: inmip => null() ! unit number MIP
5959
integer(I4B), pointer :: inmvt => null() ! unit number MVT
@@ -262,6 +262,9 @@ subroutine prt_ar(this)
262262
call this%oc%oc_ar(this%dis, DHNOFLO)
263263
call this%budget%set_ibudcsv(this%oc%ibudcsv)
264264

265+
! Initialize the event buffer (memory or scratch file per OC option)
266+
call this%tracks%init_buffer(this%oc%scratch_buffer)
267+
265268
! Select tracking events
266269
call this%tracks%select_events( &
267270
this%oc%trackrelease, &
@@ -331,7 +334,7 @@ subroutine prt_ar(this)
331334

332335
! Subscribe particle track output manager to events
333336
p => this%tracks
334-
call this%events%subscribe(write_particle_event, p)
337+
call this%events%subscribe(add_particle_event, p)
335338

336339
! Set verbose tracing if requested
337340
if (this%oc%dump_event_trace) this%tracks%iout = 0
@@ -573,7 +576,8 @@ subroutine prt_ot(this)
573576
integer(I4B) :: ibudfl
574577
integer(I4B) :: ipflag
575578

576-
! Note: particle tracking output is handled elsewhere
579+
! Flush buffered events to disk
580+
call this%tracks%flush_buffer()
577581

578582
! Set write and print flags
579583
idvsave = 0

0 commit comments

Comments
 (0)