MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
TrackFile.f90
Go to the documentation of this file.
2  use kindmodule, only: dp, i4b, lgp
3  use constantsmodule, only: dzero, dpio180
5  use geomutilmodule, only: transform
6 
7  implicit none
8  public :: trackfiletype
9  public :: save_record
10 
11  !> @brief Output file containing all or some particle pathlines.
12  !!
13  !! Can be associated with a particle release point (PRP) package
14  !! or with an entire model, and can be binary or comma-separated.
15  !!
16  !! Each particle's pathline consists of 1+ records reported as the particle
17  !! is tracked over the model domain. Records are snapshots of the particle's
18  !! state (e.g. tracking status, position) at a particular moment in time.
19  !!
20  !! Particles have no ID property. Particles can be uniquely identified
21  !! by composite key, i.e. combination of:
22  !!
23  !! - imdl: originating model ID
24  !! - iprp: originating PRP ID
25  !! - irpt: particle release location ID
26  !! - trelease: particle release time
27  !!
28  !! Each record has an "ireason" property, which identifies the cause of
29  !! the record. The user selects 1+ conditions or events for recording.
30  !! Identical records (except "ireason") may be duplicated if multiple
31  !! reporting conditions apply to particles at the same moment in time.
32  !! Each "ireason" value corresponds to an OC "trackevent" option value:
33  !!
34  !! 0: particle released
35  !! 1: particle transitioned between cells
36  !! 2: current time step ended****
37  !! 3: particle terminated
38  !! 4: particle in weak sink
39  !! 5: user-specified tracking time
40  !!
41  !! Each record has an "istatus" property, which is the tracking status;
42  !! e.g., awaiting release, active, terminated. A particle may terminate
43  !! for several reasons. Status values greater than one imply termination.
44  !! Particle status strictly increases over time, starting at zero:
45  !!
46  !! 0: pending release*
47  !! 1: active
48  !! 2: terminated at boundary face
49  !! 3: terminated in weak sink cell
50  !! 4: terminated in weak source cell**
51  !! 5: terminated in cell with no exit face
52  !! 6: terminated in cell with specified zone number
53  !! 7: terminated in inactive cell
54  !! 8: permanently unreleased***
55  !! 9: terminated in subcell with no exit face*****
56  !!
57  !! PRT shares the same status enumeration as MODPATH 7. However, some
58  !! don't apply to PRT; for instance, MODPATH 7 distinguishes forwards
59  !! and backwards tracking, but status value 4 is not used by PRT.
60  !!
61  !! Notes
62  !! -----
63  !!
64  !! * is this necessary?
65  !! ** unnecessary since PRT makes no distinction between forwards/backwards tracking
66  !! *** e.g., released into an inactive cell, a stop zone cell, or a termination zone
67  !! **** this may coincide with termination, in which case two events are reported
68  !! ***** PRT-specific status indicating a particle stopped within a cell subcell
69  !<
70  type :: trackfiletype
71  private
72  integer(I4B), public :: iun = 0 !< file unit number
73  logical(LGP), public :: csv = .false. !< whether the file is binary or CSV
74  integer(I4B), public :: iprp = -1 !< -1 is model-level file, 0 is exchange PRP
75  end type trackfiletype
76 
77  character(len=*), parameter, public :: trackheader = &
78  'kper,kstp,imdl,iprp,irpt,ilay,icell,izone,&
79  &istatus,ireason,trelease,t,x,y,z,name'
80 
81  character(len=*), parameter, public :: trackdtypes = &
82  '<i4,<i4,<i4,<i4,<i4,<i4,<i4,<i4,&
83  &<i4,<i4,<f8,<f8,<f8,<f8,<f8,|S40'
84 
85 contains
86 
87  !> @brief Save a particle track record to a binary or CSV file.
88  subroutine save_record(iun, particle, kper, kstp, reason, csv)
89  ! dummy
90  integer(I4B), intent(in) :: iun
91  type(particletype), pointer, intent(in) :: particle
92  integer(I4B), intent(in) :: kper
93  integer(I4B), intent(in) :: kstp
94  integer(I4B), intent(in) :: reason
95  logical(LGP), intent(in) :: csv
96  ! local
97  real(dp) :: x, y, z
98  integer(I4B) :: status
99 
100  ! Convert from cell-local to model coordinates if needed
101  call particle%get_model_coords(x, y, z)
102 
103  ! Set status
104  if (particle%istatus .lt. 0) then
105  status = 1
106  else
107  status = particle%istatus
108  end if
109 
110  if (csv) then
111  write (iun, '(*(G0,:,","))') &
112  kper, &
113  kstp, &
114  particle%imdl, &
115  particle%iprp, &
116  particle%irpt, &
117  particle%ilay, &
118  particle%icu, &
119  particle%izone, &
120  status, &
121  reason, &
122  particle%trelease, &
123  particle%ttrack, &
124  x, &
125  y, &
126  z, &
127  trim(adjustl(particle%name))
128  else
129  write (iun) &
130  kper, &
131  kstp, &
132  particle%imdl, &
133  particle%iprp, &
134  particle%irpt, &
135  particle%ilay, &
136  particle%icu, &
137  particle%izone, &
138  status, &
139  reason, &
140  particle%trelease, &
141  particle%ttrack, &
142  x, &
143  y, &
144  z, &
145  particle%name
146  end if
147  end subroutine
148 end module trackfilemodule
This module contains simulation constants.
Definition: Constants.f90:9
real(dp), parameter dpio180
real constant
Definition: Constants.f90:130
real(dp), parameter dzero
real constant zero
Definition: Constants.f90:65
subroutine, public transform(xin, yin, zin, xout, yout, zout, xorigin, yorigin, zorigin, sinrot, cosrot, invert)
Apply a 3D translation and optional 2D rotation to coordinates.
Definition: GeomUtil.f90:183
This module defines variable data types.
Definition: kind.f90:8
subroutine, public save_record(iun, particle, kper, kstp, reason, csv)
Save a particle track record to a binary or CSV file.
Definition: TrackFile.f90:89
character(len= *), parameter, public trackdtypes
Definition: TrackFile.f90:81
character(len= *), parameter, public trackheader
Definition: TrackFile.f90:77
Particle tracked by the PRT model.
Definition: Particle.f90:32
Output file containing all or some particle pathlines.
Definition: TrackFile.f90:70