MODFLOW 6  version 6.7.0.dev2
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)
 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 121 of file ParticleTracks.f90.

122  class(ParticleTracksType) :: this
123  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 127 of file ParticleTracks.f90.

128  ! dummy
129  class(ParticleTracksType) :: this
130  integer(I4B), optional, intent(in) :: increment
131  ! local
132  integer(I4B) :: inclocal
133  integer(I4B) :: isize
134  integer(I4B) :: newsize
135  type(ParticleTrackFileType), allocatable, dimension(:) :: temp
136 
137  if (present(increment)) then
138  inclocal = increment
139  else
140  inclocal = 1
141  end if
142 
143  if (allocated(this%files)) then
144  isize = size(this%files)
145  newsize = isize + inclocal
146  allocate (temp(newsize))
147  temp(1:isize) = this%files
148  deallocate (this%files)
149  call move_alloc(temp, this%files)
150  else
151  allocate (this%files(inclocal))
152  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 272 of file ParticleTracks.f90.

273  ! dummy
274  class(ParticleTracksType), intent(inout) :: this
275  type(ParticleType), pointer, intent(in) :: particle
276  class(ParticleEventType), pointer, intent(in) :: event
277  ! local
278  integer(I4B) :: i
279  type(ParticleTrackFileType) :: file
280 
281  if (this%should_log()) &
282  call event%log(this%iout)
283 
284  if (this%is_selected(event)) then
285  do i = 1, this%ntrackfiles
286  file = this%files(i)
287  if (this%should_save(particle, file)) &
288  call save_event(file%iun, particle, event, csv=file%csv)
289  end do
290  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 98 of file ParticleTracks.f90.

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

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

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

Definition at line 156 of file ParticleTracks.f90.

164  class(ParticleTracksType) :: this
165  logical(LGP), intent(in) :: release
166  logical(LGP), intent(in) :: featexit
167  logical(LGP), intent(in) :: timestep
168  logical(LGP), intent(in) :: terminate
169  logical(LGP), intent(in) :: weaksink
170  logical(LGP), intent(in) :: usertime
171  logical(LGP), intent(in) :: subfexit
172  this%selected%release = release
173  this%selected%featexit = featexit
174  this%selected%timestep = timestep
175  this%selected%terminate = terminate
176  this%selected%weaksink = weaksink
177  this%selected%usertime = usertime
178  this%selected%subfexit = subfexit

◆ should_log()

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

Definition at line 266 of file ParticleTracks.f90.

267  class(ParticleTracksType), intent(inout) :: this
268  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 210 of file ParticleTracks.f90.

211  class(ParticleTracksType), intent(inout) :: this
212  type(ParticleType), pointer, intent(in) :: particle
213  type(ParticleTrackFileType), intent(in) :: file
214  save = (file%iun > 0 .and. &
215  (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 46 of file ParticleTracks.f90.

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

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