MODFLOW 6  version 6.8.0.dev0
USGS Modular Hydrologic Model
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. More...
 
subroutine init_buffer (this, scratch)
 Initialize the event buffer strategy. More...
 
subroutine destroy (this)
 Destroy the particle track manager. More...
 
subroutine expand_files (this, increment)
 Grow the array of track files. More...
 
subroutine select_events (this, release, featexit, timestep, terminate, weaksink, usertime, subfexit, dropped)
 Pick events to track. More...
 
logical function is_selected (this, event)
 Check if a given event code is selected for tracking. More...
 
subroutine buffer_event (this, particle, event)
 Buffer an event for deferred write. More...
 
subroutine flush_buffer (this)
 Flush the event buffer to disk. More...
 
subroutine discard_buffer (this)
 Discard buffered events without writing. More...
 
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. More...
 

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 252 of file ParticleTracks.f90.

253  class(*), pointer :: context
254  type(ParticleType), pointer, intent(inout) :: particle
255  class(ParticleEventType), pointer, intent(in) :: event
256  logical(LGP) :: handled
257 
258  select type (context)
259  type is (particletrackstype)
260  if (context%iout >= 0) &
261  call event%log(context%iout)
262  if (context%is_selected(event)) &
263  call context%buffer_event(particle, event)
264  handled = .true.
265  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 
)

Definition at line 216 of file ParticleTracks.f90.

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

◆ destroy()

subroutine particletracksmodule::destroy ( class(particletrackstype this)

Definition at line 128 of file ParticleTracks.f90.

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

◆ discard_buffer()

subroutine particletracksmodule::discard_buffer ( class(particletrackstype this)

Definition at line 241 of file ParticleTracks.f90.

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

◆ expand_files()

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

Definition at line 134 of file ParticleTracks.f90.

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

◆ flush_buffer()

subroutine particletracksmodule::flush_buffer ( class(particletrackstype this)

Definition at line 235 of file ParticleTracks.f90.

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

◆ init_buffer()

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

Definition at line 115 of file ParticleTracks.f90.

116  class(ParticleTracksType) :: this
117  logical(LGP), intent(in) :: scratch
118 
119  if (scratch) then
120  allocate (scratchfilebuffertype :: this%buffer)
121  else
122  allocate (memorybuffertype :: this%buffer)
123  end if
124  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 
)

Definition at line 188 of file ParticleTracks.f90.

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

Definition at line 159 of file ParticleTracks.f90.

168  class(ParticleTracksType) :: this
169  logical(LGP), intent(in) :: release
170  logical(LGP), intent(in) :: featexit
171  logical(LGP), intent(in) :: timestep
172  logical(LGP), intent(in) :: terminate
173  logical(LGP), intent(in) :: weaksink
174  logical(LGP), intent(in) :: usertime
175  logical(LGP), intent(in) :: subfexit
176  logical(LGP), intent(in) :: dropped
177  this%selected%release = release
178  this%selected%featexit = featexit
179  this%selected%timestep = timestep
180  this%selected%terminate = terminate
181  this%selected%weaksink = weaksink
182  this%selected%usertime = usertime
183  this%selected%subfexit = subfexit
184  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.

50  character(len=*), parameter, public :: TRACKDTYPES = &
51  '<i4,<i4,<i4,<i4,<i4,<i4,<i4,<i4,&
52  &<i4,<i4,<f8,<f8,<f8,<f8,<f8,|S40'

◆ 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.

46  character(len=*), parameter, public :: TRACKHEADER = &
47  'kper,kstp,imdl,iprp,irpt,ilay,icell,izone,&
48  &istatus,ireason,trelease,t,x,y,z,name'