MODFLOW 6  version 6.7.0.dev3
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
 Manages particle track output (logging/writing). More...
 

Functions/Subroutines

subroutine init_file (this, iun, csv, iprp)
 Initialize a binary or CSV file. More...
 
subroutine destroy (this)
 
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_log (this)
 Log output unit valid? More...
 
subroutine handle_event (this, particle, event)
 Handle a particle event. 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 123 of file ParticleTracks.f90.

124  class(ParticleTracksType) :: this
125  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 129 of file ParticleTracks.f90.

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

◆ handle_event()

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

Definition at line 279 of file ParticleTracks.f90.

280  ! dummy
281  class(ParticleTracksType), intent(inout) :: this
282  type(ParticleType), pointer, intent(in) :: particle
283  class(ParticleEventType), pointer, intent(in) :: event
284  ! local
285  integer(I4B) :: i
286  type(ParticleTrackFileType) :: file
287 
288  if (this%should_log()) &
289  call event%log(this%iout)
290 
291  if (this%is_selected(event)) then
292  do i = 1, this%ntrackfiles
293  file = this%files(i)
294  if (this%should_save(particle, file)) &
295  call save_event(file%iun, particle, event, csv=file%csv)
296  end do
297  end if
Here is the call graph for this function:

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

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

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

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

◆ should_log()

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

Definition at line 273 of file ParticleTracks.f90.

274  class(ParticleTracksType), intent(inout) :: this
275  should_log = 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 217 of file ParticleTracks.f90.

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

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'