MODFLOW 6  version 6.8.0.dev0
USGS Modular Hydrologic Model
particletracksmodule Module Reference

Particle track output module. More...

Data Types

type  particletrackfiletype
 Output file containing all or some particle pathlines. More...
 
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. More...
 

Functions/Subroutines

subroutine init_file (this, iun, csv, iprp)
 Initialize a binary or CSV file. 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...
 
logical function should_save (this, particle, file)
 Check whether a particle belongs in a given file i.e. if the file is enabled and its group matches the particle's. More...
 
subroutine, private save_event (iun, particle, event, csv)
 Save an event to a binary or CSV file. More...
 
logical function should_print (this)
 Is the output unit valid? More...
 
logical(lgp) function, public write_particle_event (context, particle, event)
 Write a particle event to files for which the particle is eligible, and print the event to output unit if requested. This function is the module's main entry point. It should be subscribed as an event handler to particle event dispatchers. 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).

Function/Subroutine Documentation

◆ destroy()

subroutine particletracksmodule::destroy ( class(particletrackstype this)

Definition at line 124 of file ParticleTracks.f90.

125  class(ParticleTracksType) :: this
126  if (allocated(this%files)) deallocate (this%files)

◆ expand_files()

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

Definition at line 130 of file ParticleTracks.f90.

131  ! dummy
132  class(ParticleTracksType) :: this
133  integer(I4B), optional, intent(in) :: increment
134  ! local
135  integer(I4B) :: inclocal
136  integer(I4B) :: isize
137  integer(I4B) :: 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

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

101  ! dummy
102  class(ParticleTracksType) :: this
103  integer(I4B), intent(in) :: iun
104  logical(LGP), intent(in), optional :: csv
105  integer(I4B), intent(in), optional :: iprp
106  ! local
107  type(ParticleTrackFileType), pointer :: file
108 
109  if (.not. allocated(this%files)) then
110  allocate (this%files(1))
111  else
112  call this%expand_files(increment=1)
113  end if
114 
115  allocate (file)
116  file%iun = iun
117  if (present(csv)) file%csv = csv
118  if (present(iprp)) file%iprp = iprp
119  this%ntrackfiles = size(this%files)
120  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
213 
Here is the call graph for this function:

◆ save_event()

subroutine, private particletracksmodule::save_event ( integer(i4b), intent(in)  iun,
type(particletype), intent(in), pointer  particle,
class(particleeventtype), intent(in), pointer  event,
logical(lgp), intent(in)  csv 
)
private

Definition at line 227 of file ParticleTracks.f90.

228  ! dummy
229  integer(I4B), intent(in) :: iun
230  type(ParticleType), pointer, intent(in) :: particle
231  class(ParticleEventType), pointer, intent(in) :: event
232  logical(LGP), intent(in) :: csv
233 
234  if (csv) then
235  write (iun, '(*(G0,:,","))') &
236  event%kper, &
237  event%kstp, &
238  event%imdl, &
239  event%iprp, &
240  event%irpt, &
241  event%ilay, &
242  event%icu, &
243  event%izone, &
244  event%istatus, &
245  event%get_code(), &
246  event%trelease, &
247  event%ttrack, &
248  event%x, &
249  event%y, &
250  event%z, &
251  trim(adjustl(particle%name))
252  else
253  write (iun) &
254  event%kper, &
255  event%kstp, &
256  event%imdl, &
257  event%iprp, &
258  event%irpt, &
259  event%ilay, &
260  event%icu, &
261  event%izone, &
262  event%istatus, &
263  event%get_code(), &
264  event%trelease, &
265  event%ttrack, &
266  event%x, &
267  event%y, &
268  event%z, &
269  particle%name
270  end if
Here is the caller 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

◆ should_print()

logical function particletracksmodule::should_print ( class(particletrackstype), intent(inout)  this)

Definition at line 274 of file ParticleTracks.f90.

275  class(ParticleTracksType), intent(inout) :: this
276  should_print = this%iout >= 0

◆ should_save()

logical function particletracksmodule::should_save ( class(particletrackstype), intent(inout)  this,
type(particletype), intent(in), pointer  particle,
type(particletrackfiletype), intent(in)  file 
)

Definition at line 218 of file ParticleTracks.f90.

219  class(ParticleTracksType), intent(inout) :: this
220  type(ParticleType), pointer, intent(in) :: particle
221  type(ParticleTrackFileType), intent(in) :: file
222  save = (file%iun > 0 .and. &
223  (file%iprp == -1 .or. file%iprp == particle%iprp))

◆ write_particle_event()

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

Definition at line 283 of file ParticleTracks.f90.

284  ! dummy
285  class(*), pointer :: context
286  type(ParticleType), pointer, intent(inout) :: particle
287  class(ParticleEventType), pointer, intent(in) :: event
288  logical(LGP) :: handled
289  ! local
290  integer(I4B) :: i
291  type(ParticleTrackFileType) :: file
292 
293  select type (context)
294  type is (particletrackstype)
295  if (context%should_print()) &
296  call event%log(context%iout)
297  if (context%is_selected(event)) then
298  do i = 1, context%ntrackfiles
299  file = context%files(i)
300  if (context%should_save(particle, file)) &
301  call save_event(file%iun, particle, event, csv=file%csv)
302  end do
303  end if
304  handled = .true.
305  end select
Here is the call graph for this function:
Here is the caller graph for this function:

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

47  character(len=*), parameter, public :: TRACKDTYPES = &
48  '<i4,<i4,<i4,<i4,<i4,<i4,<i4,<i4,&
49  &<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 43 of file ParticleTracks.f90.

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