MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
particletracksmodule Module Reference

Particle track output module. More...

Data Types

type  particletrackeventselectiontype
 Selection of particle events. More...
type  particletrackstype
 Particle track output manager. Handles printing as well as writing to files. One output unit can be configured for printing. Multiple files can be configured for writing, with each file optionally associated with a PRP package or with the full model. Events can be filtered by type, so that only certain event types are printed or written to files. Particle events are buffered in memory or in a scratch file, flushed to disk only when the time step is successfully solved for the last time (there may be multiple solves per time step, depending on ATS and Picard options). More...

Functions/Subroutines

subroutine init_file (this, iun, csv, iprp)
 Initialize a binary or CSV output file.
subroutine init_buffer (this, scratch)
 Initialize the event buffer strategy.
subroutine destroy (this)
 Destroy the particle track manager.
subroutine expand_files (this, increment)
 Grow the array of track files.
subroutine select_events (this, release, featexit, timestep, terminate, weaksink, usertime, subfexit, dropped)
 Pick events to track.
logical function is_selected (this, event)
 Check if a given event code is selected for tracking.
subroutine buffer_event (this, particle, event)
 Buffer an event for deferred write.
subroutine flush_buffer (this)
 Flush the event buffer to disk.
subroutine discard_buffer (this)
 Discard buffered events without writing.
logical(lgp) function, public add_particle_event (context, particle, event)
 Add a particle event to be written to eligible files and printed to an output file unit if requested. This function should be subscribed as an event handler to particle event dispatchers. Events are buffered to be written to output files upon successful completion of a time step when the framework OT hook is executed.

Variables

character(len= *), parameter, public trackheader = 'kper,kstp,imdl,iprp,irpt,ilay,icell,izone,istatus,ireason,trelease,t,x,y,z,name'
character(len= *), parameter, public trackdtypes = '<i4,<i4,<i4,<i4,<i4,<i4,<i4,<i4,<i4,<i4,<f8,<f8,<f8,<f8,<f8,|S40'

Detailed Description

Each particle's track consists of events reported as the particle is advected through the model domain. Events are snapshots of particle state, along with optional metadata, at a particular moment in time.

Particles have no ID property. A particle can be uniquely identified by the unique combination of its release attributes (model, package, position, and time). This is possible because only one particle may be released from a given point at a given time.

This module consumes particle events and is responsible for writing them to one or more track files, binary or CSV, and for logging the events if requested. Each track file is associated with either a PRP package or with the full PRT model (there may only be 1 such latter).

Events can be buffered in memory or in a scratch file, and in either case are flushed to disk only when a time step successfully finishes.

Function/Subroutine Documentation

◆ add_particle_event()

logical(lgp) function, public particletracksmodule::add_particle_event ( class(*), pointer context,
type(particletype), intent(inout), pointer particle,
class(particleeventtype), intent(in), pointer event )

Definition at line 253 of file ParticleTracks.f90.

254 class(*), pointer :: context
255 type(ParticleType), pointer, intent(inout) :: particle
256 class(ParticleEventType), pointer, intent(in) :: event
257 logical(LGP) :: handled
258
259 select type (context)
260 type is (particletrackstype)
261 if (context%iout >= 0) &
262 call event%log(context%iout)
263 if (context%ntrackfiles > 0) then
264 if (context%is_selected(event)) &
265 call context%buffer_event(particle, event)
266 end if
267 handled = .true.
268 end select
Here is the caller graph for this function:

◆ buffer_event()

subroutine particletracksmodule::buffer_event ( class(particletrackstype) this,
type(particletype), intent(in), pointer particle,
class(particleeventtype), intent(in), pointer event )
private

Definition at line 217 of file ParticleTracks.f90.

218 class(ParticleTracksType) :: this
219 type(ParticleType), pointer, intent(in) :: particle
220 class(ParticleEventType), pointer, intent(in) :: event
221 type(ParticleTrackRecordType) :: rec
222
223 rec%kper = event%kper; rec%kstp = event%kstp
224 rec%imdl = event%imdl; rec%iprp = event%iprp
225 rec%irpt = event%irpt; rec%ilay = event%ilay
226 rec%icu = event%icu; rec%izone = event%izone
227 rec%istatus = event%istatus; rec%ireason = event%get_code()
228 rec%trelease = event%trelease; rec%ttrack = event%ttrack
229 rec%x = event%x; rec%y = event%y; rec%z = event%z
230 rec%name = trim(adjustl(particle%name))
231
232 call this%buffer%append(rec)

◆ destroy()

subroutine particletracksmodule::destroy ( class(particletrackstype) this)
private

Definition at line 129 of file ParticleTracks.f90.

130 class(ParticleTracksType) :: this
131 call this%buffer%destroy()

◆ discard_buffer()

subroutine particletracksmodule::discard_buffer ( class(particletrackstype) this)
private

Definition at line 242 of file ParticleTracks.f90.

243 class(ParticleTracksType) :: this
244 call this%buffer%discard()

◆ expand_files()

subroutine particletracksmodule::expand_files ( class(particletrackstype) this,
integer(i4b), intent(in), optional increment )
private

Definition at line 135 of file ParticleTracks.f90.

136 class(ParticleTracksType) :: this
137 integer(I4B), optional, intent(in) :: increment
138 integer(I4B) :: inclocal, isize, newsize
139 type(ParticleTrackFileType), allocatable, dimension(:) :: temp
140
141 if (present(increment)) then
142 inclocal = increment
143 else
144 inclocal = 1
145 end if
146
147 if (allocated(this%files)) then
148 isize = size(this%files)
149 newsize = isize + inclocal
150 allocate (temp(newsize))
151 temp(1:isize) = this%files
152 deallocate (this%files)
153 call move_alloc(temp, this%files)
154 else
155 allocate (this%files(inclocal))
156 end if

◆ flush_buffer()

subroutine particletracksmodule::flush_buffer ( class(particletrackstype) this)
private

Definition at line 236 of file ParticleTracks.f90.

237 class(ParticleTracksType) :: this
238 call this%buffer%flush(this%files)

◆ init_buffer()

subroutine particletracksmodule::init_buffer ( class(particletrackstype) this,
logical(lgp), intent(in) scratch )
private

Definition at line 115 of file ParticleTracks.f90.

116 class(ParticleTracksType) :: this
117 logical(LGP), intent(in) :: scratch
118
119 if (.not. allocated(this%files)) allocate (this%files(0))
120 if (scratch) then
121 allocate (scratchfilebuffertype :: this%buffer)
122 else
123 allocate (memorybuffertype :: this%buffer)
124 end if
125 call this%buffer%init()

◆ init_file()

subroutine particletracksmodule::init_file ( class(particletrackstype) this,
integer(i4b), intent(in) iun,
logical(lgp), intent(in), optional csv,
integer(i4b), intent(in), optional iprp )

Definition at line 97 of file ParticleTracks.f90.

98 class(ParticleTracksType) :: this
99 integer(I4B), intent(in) :: iun
100 logical(LGP), intent(in), optional :: csv
101 integer(I4B), intent(in), optional :: iprp
102 type(ParticleTrackFileType), pointer :: file
103
104 call this%expand_files(increment=1)
105
106 allocate (file)
107 file%iun = iun
108 if (present(csv)) file%csv = csv
109 if (present(iprp)) file%iprp = iprp
110 this%ntrackfiles = size(this%files)
111 this%files(this%ntrackfiles) = file

◆ is_selected()

logical function particletracksmodule::is_selected ( class(particletrackstype), intent(inout) this,
class(particleeventtype), intent(in) event )
private

Definition at line 189 of file ParticleTracks.f90.

190 class(ParticleTracksType), intent(inout) :: this
191 class(ParticleEventType), intent(in) :: event
192
193 select type (event)
194 type is (releaseeventtype)
195 selected = this%selected%release
196 type is (cellexiteventtype)
197 selected = this%selected%featexit
198 type is (subcellexiteventtype)
199 selected = this%selected%subfexit
200 type is (timestepeventtype)
201 selected = this%selected%timestep
202 type is (terminationeventtype)
203 selected = this%selected%terminate
204 type is (weaksinkeventtype)
205 selected = this%selected%weaksink
206 type is (usertimeeventtype)
207 selected = this%selected%usertime
208 type is (droppedeventtype)
209 selected = this%selected%dropped
210 class default
211 call pstop(1, "unknown event type")
212 selected = .false.
213 end select
Here is the call graph for this function:

◆ select_events()

subroutine particletracksmodule::select_events ( class(particletrackstype) this,
logical(lgp), intent(in) release,
logical(lgp), intent(in) featexit,
logical(lgp), intent(in) timestep,
logical(lgp), intent(in) terminate,
logical(lgp), intent(in) weaksink,
logical(lgp), intent(in) usertime,
logical(lgp), intent(in) subfexit,
logical(lgp), intent(in) dropped )
private

Definition at line 160 of file ParticleTracks.f90.

169 class(ParticleTracksType) :: this
170 logical(LGP), intent(in) :: release
171 logical(LGP), intent(in) :: featexit
172 logical(LGP), intent(in) :: timestep
173 logical(LGP), intent(in) :: terminate
174 logical(LGP), intent(in) :: weaksink
175 logical(LGP), intent(in) :: usertime
176 logical(LGP), intent(in) :: subfexit
177 logical(LGP), intent(in) :: dropped
178 this%selected%release = release
179 this%selected%featexit = featexit
180 this%selected%timestep = timestep
181 this%selected%terminate = terminate
182 this%selected%weaksink = weaksink
183 this%selected%usertime = usertime
184 this%selected%subfexit = subfexit
185 this%selected%dropped = dropped

Variable Documentation

◆ trackdtypes

character(len=*), parameter, public particletracksmodule::trackdtypes = '<i4,<i4,<i4,<i4,<i4,<i4,<i4,<i4,<i4,<i4,<f8,<f8,<f8,<f8,<f8,|S40'

Definition at line 50 of file ParticleTracks.f90.

◆ trackheader

character(len=*), parameter, public particletracksmodule::trackheader = 'kper,kstp,imdl,iprp,irpt,ilay,icell,izone,istatus,ireason,trelease,t,x,y,z,name'

Definition at line 46 of file ParticleTracks.f90.