MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
GwfConductanceUtils.f90
Go to the documentation of this file.
1!> @brief This module contains stateless conductance functions
2!!
3!! This module contains the functions to calculate the horizontal
4!! and vertical conductance between two cells that are used in the
5!! the node property flow (NPF) package. It also contains functions
6!! to calculate the wetted cell fraction. This module does not
7!! depend on the NPF package.
8!!
9!<
11 use kindmodule, only: dp, i4b
12 use constantsmodule, only: dzero, dhalf, done, &
13 dlnlow, dlnhigh, &
15
16 implicit none
17 private
18 public :: hcond
19 public :: vcond
20 public :: condmean
21 public :: thksatnm
22 public :: staggered_thkfrac
23 public :: flow_area
24 public :: ccond_hmean
25
26 !> @brief enumerator that defines the conductance options
27 !<
28 ENUM, BIND(C)
29 ENUMERATOR :: ccond_hmean = 0 !< Harmonic mean
30 ENUMERATOR :: ccond_lmean = 1 !< Logarithmic mean
31 ENUMERATOR :: ccond_amtlmk = 2 !< Arithmetic-mean thickness and logarithmic-mean hydraulic conductivity
32 ENUMERATOR :: ccond_amthmk = 3 !< Arithmetic-mean thickness and harmonic-mean hydraulic conductivity
33 END ENUM
34
35contains
36
37 !> @brief Horizontal conductance between two cells
38 !!
39 !! This function uses a weighted transmissivity in the harmonic mean
40 !! conductance calculations. This differs from the MODFLOW-NWT and
41 !! MODFLOW-USG conductance calculations for the Newton-Raphson formulation
42 !! which use a weighted hydraulic conductivity.
43 !<
44 function hcond(ibdn, ibdm, ictn, ictm, iupstream, ihc, icellavg, &
45 condsat, hn, hm, satn, satm, hkn, hkm, topn, topm, &
46 botn, botm, cln, clm, fawidth) &
47 result(condnm)
48 ! return variable
49 real(dp) :: condnm !< horizontal conductance between two cells
50 ! dummy
51 integer(I4B), intent(in) :: ibdn !< cell n active flag
52 integer(I4B), intent(in) :: ibdm !< cell m active flag
53 integer(I4B), intent(in) :: ictn !< cell n convertible cell flag
54 integer(I4B), intent(in) :: ictm !< cell m convertible cell flag
55 integer(I4B), intent(in) :: iupstream !< flag for upstream weighting
56 integer(I4B), intent(in) :: ihc !< connection type
57 integer(I4B), intent(in) :: icellavg !< cell averaging option
58 real(dp), intent(in) :: condsat !< saturated conductance
59 real(dp), intent(in) :: hn !< cell n head
60 real(dp), intent(in) :: hm !< cell m head
61 real(dp), intent(in) :: satn !< cell n wetted cell fraction
62 real(dp), intent(in) :: satm !< cell m wetted cell fraction
63 real(dp), intent(in) :: hkn !< horizontal hydraulic conductivity for cell n (in the direction of cell m)
64 real(dp), intent(in) :: hkm !< horizontal hydraulic conductivity for cell m (in the direction of cell n)
65 real(dp), intent(in) :: topn !< top of cell n
66 real(dp), intent(in) :: topm !< top of cell m
67 real(dp), intent(in) :: botn !< bottom of cell n
68 real(dp), intent(in) :: botm !< bottom of cell m
69 real(dp), intent(in) :: cln !< distance from the center of cell n to the shared face with cell m
70 real(dp), intent(in) :: clm !< distance from the center of cell m to the shared face with cell n
71 real(dp), intent(in) :: fawidth !< width of cell perpendicular to flow
72
73 ! n or m is inactive
74 if (ibdn == 0 .or. ibdm == 0) then
75 condnm = dzero
76 ! both cells are non-convertible
77 elseif (ictn == 0 .and. ictm == 0) then
78 condnm = condsat
79 else if (iupstream == 1) then
80 condnm = convertible_upstream(hn, hm, satn, satm, condsat)
81 else
82 condnm = convertible_standard(ihc, icellavg, &
83 satn, satm, hkn, hkm, &
84 topn, topm, botn, botm, &
85 cln, clm, fawidth)
86 end if
87 end function hcond
88
89 !> @brief Convertible cell(s) with upstream weighted horizontal conductance
90 !<
91 function convertible_upstream(hn, hm, satn, satm, condsat) &
92 result(condnm)
93 ! return variable
94 real(dp) :: condnm !< horizontal conductance between two cells
95 ! dummy
96 real(dp), intent(in) :: condsat !< saturated conductance
97 real(dp), intent(in) :: hn !< cell n head
98 real(dp), intent(in) :: hm !< cell m head
99 real(dp), intent(in) :: satn !< cell n wetted cell fraction
100 real(dp), intent(in) :: satm !< cell m wetted cell fraction
101 ! local
102 real(dp) :: sat_up
103
104 if (hn > hm) then
105 sat_up = satn
106 else if (hm > hn) then
107 sat_up = satm
108 else
109 ! equal heads have no upstream cell; use the larger saturation so the
110 ! result does not depend on cell order
111 sat_up = max(satn, satm)
112 end if
113 condnm = sat_up * condsat
114 end function convertible_upstream
115
116 !> @brief Convertible cell(s) with standard weighted horizontal conductance
117 !<
118 function convertible_standard(ihc, icellavg, satn, satm, hkn, hkm, &
119 topn, topm, botn, botm, cln, clm, fawidth) &
120 result(condnm)
121 ! return variable
122 real(dp) :: condnm !< horizontal conductance between two cells
123 ! dummy
124 integer(I4B), intent(in) :: ihc !< connection type
125 integer(I4B), intent(in) :: icellavg !< cell averaging option
126 real(dp), intent(in) :: satn !< cell n wetted cell fraction
127 real(dp), intent(in) :: satm !< cell m wetted cell fraction
128 real(dp), intent(in) :: hkn !< horizontal hydraulic conductivity for cell n (in the direction of cell m)
129 real(dp), intent(in) :: hkm !< horizontal hydraulic conductivity for cell m (in the direction of cell n)
130 real(dp), intent(in) :: topn !< top of cell n
131 real(dp), intent(in) :: topm !< top of cell m
132 real(dp), intent(in) :: botn !< bottom of cell n
133 real(dp), intent(in) :: botm !< bottom of cell m
134 real(dp), intent(in) :: cln !< distance from the center of cell n to the shared face with cell m
135 real(dp), intent(in) :: clm !< distance from the center of cell m to the shared face with cell n
136 real(dp), intent(in) :: fawidth !< width of cell perpendicular to flow
137 ! local
138 real(dp) :: thksatn
139 real(dp) :: thksatm
140
141 if (ihc == c3d_staggered) then
142 thksatn = staggered_thkfrac(topn, botn, satn, topm, botm)
143 thksatm = staggered_thkfrac(topm, botm, satm, topn, botn)
144 else
145 thksatn = satn * (topn - botn)
146 thksatm = satm * (topm - botm)
147 end if
148 condnm = condmean(hkn, hkm, thksatn, thksatm, cln, clm, &
149 fawidth, icellavg)
150 end function convertible_standard
151
152 !> @brief Vertical conductance between two cells
153 !<
154 function vcond(ibdn, ibdm, ictn, ictm, inewton, ivarcv, idewatcv, &
155 condsat, hn, hm, vkn, vkm, satn, satm, topn, topm, botn, &
156 botm, flowarea) result(condnm)
157 ! return variable
158 real(dp) :: condnm
159 ! dummy
160 integer(I4B), intent(in) :: ibdn !< cell n active flag
161 integer(I4B), intent(in) :: ibdm !< cell m active flag
162 integer(I4B), intent(in) :: ictn !< cell n convertible cell flag
163 integer(I4B), intent(in) :: ictm !< cell m convertible cell flag
164 integer(I4B), intent(in) :: inewton !< flag for Newton-Raphson formulation
165 integer(I4B), intent(in) :: ivarcv !< variable vertical conductance flag
166 integer(I4B), intent(in) :: idewatcv !< dewatered vertical conductance flag
167 real(dp), intent(in) :: condsat !< saturated conductance
168 real(dp), intent(in) :: hn !< cell n head
169 real(dp), intent(in) :: hm !< cell m head
170 real(dp), intent(in) :: vkn !< vertical hydraulic conductivity for cell n (in the direction of cell m)
171 real(dp), intent(in) :: vkm !< vertical hydraulic conductivity for cell m (in the direction of cell n)
172 real(dp), intent(in) :: satn !< cell n wetted cell fraction
173 real(dp), intent(in) :: satm !< cell m wetted cell fraction
174 real(dp), intent(in) :: topn !< top of cell n
175 real(dp), intent(in) :: topm !< top of cell m
176 real(dp), intent(in) :: botn !< bottom of cell n
177 real(dp), intent(in) :: botm !< bottom of cell m
178 real(dp), intent(in) :: flowarea !< flow area between cell n and m
179 ! local
180 real(dp) :: satntmp
181 real(dp) :: satmtmp
182 real(dp) :: bovk1
183 real(dp) :: bovk2
184 real(dp) :: denom
185 !
186 ! Either n or m is inactive
187 if (ibdn == 0 .or. ibdm == 0) then
188 condnm = dzero
189 !
190 ! constantcv
191 elseif (ivarcv == 0) then
192 condnm = condsat
193 !
194 ! both cells are non-convertible
195 elseif (ictn == 0 .and. ictm == 0) then
196 condnm = condsat
197 !
198 ! both cells are fully saturated
199 elseif (hn >= topn .and. hm >= topm) then
200 condnm = condsat
201 !
202 ! At least one cell is partially saturated, so recalculate vertical
203 ! conductance for this connection
204 ! todo: upstream weighting?
205 else
206 !
207 ! Default is for CV correction (dewatered option); use underlying
208 ! saturation of 1.
209 satntmp = satn
210 satmtmp = satm
211 if (idewatcv == 0) then
212 if (botn > botm) then
213 satmtmp = done
214 else
215 satntmp = done
216 end if
217 else
218 if (botn > botm) then
219 if (satmtmp < done) then
220 satmtmp = dzero
221 end if
222 else
223 if (satntmp < done) then
224 satntmp = dzero
225 end if
226 end if
227 end if
228 bovk1 = satntmp * (topn - botn) * dhalf / vkn
229 bovk2 = satmtmp * (topm - botm) * dhalf / vkm
230 denom = (bovk1 + bovk2)
231 if (denom /= dzero) then
232 condnm = flowarea / denom
233 else
234 condnm = dzero
235 end if
236 end if
237 end function vcond
238
239 !> @brief Calculate the conductance between two cells
240 !<
241 function condmean(k1, k2, thick1, thick2, cl1, cl2, width, iavgmeth)
242 ! return variable
243 real(dp) :: condmean !< mean conductance between two cells
244 ! dummy
245 real(dp), intent(in) :: k1 !< hydraulic conductivity for cell n (in the direction of cell m)
246 real(dp), intent(in) :: k2 !< hydraulic conductivity for cell m (in the direction of celln)
247 real(dp), intent(in) :: thick1 !< saturated thickness for cell 1
248 real(dp), intent(in) :: thick2 !< saturated thickness for cell 2
249 real(dp), intent(in) :: cl1 !< distance from the center of cell n to the shared face with cell m
250 real(dp), intent(in) :: cl2 !< distance from the center of cell m to the shared face with cell n
251 real(dp), intent(in) :: width !< width of cell perpendicular to flow
252 integer(I4B), intent(in) :: iavgmeth !< averaging method
253 ! local
254 real(dp) :: t1
255 real(dp) :: t2
256 real(dp) :: tmean
257 real(dp) :: kmean
258 real(dp) :: denom
259 !
260 ! Initialize
261 t1 = k1 * thick1
262 t2 = k2 * thick2
263
264 ! Averaging method
265 select case (iavgmeth)
266
267 case (ccond_hmean)
268 if (t1 * t2 > dzero) then
269 condmean = width * t1 * t2 / (t1 * cl2 + t2 * cl1)
270 else
272 end if
273
274 case (ccond_lmean)
275 if (t1 * t2 > dzero) then
276 tmean = logmean(t1, t2)
277 else
278 tmean = dzero
279 end if
280 condmean = tmean * width / (cl1 + cl2)
281
282 case (ccond_amtlmk)
283 if (k1 * k2 > dzero) then
284 kmean = logmean(k1, k2)
285 else
286 kmean = dzero
287 end if
288 condmean = kmean * dhalf * (thick1 + thick2) * width / (cl1 + cl2)
289
290 case (ccond_amthmk)
291 denom = (k1 * cl2 + k2 * cl1)
292 if (denom > dzero) then
293 kmean = k1 * k2 / denom
294 else
295 kmean = dzero
296 end if
297 condmean = kmean * dhalf * (thick1 + thick2) * width
298 end select
299 end function condmean
300
301 !> @brief Calculate the the logarithmic mean of two double precision numbers
302 !!
303 !! Use an approximation if the ratio is near 1
304 !<
305 function logmean(d1, d2)
306 ! return variable
307 real(dp) :: logmean !< logarithmic mean for two number
308 ! dummy
309 real(dp), intent(in) :: d1 !< first number
310 real(dp), intent(in) :: d2 !< second number
311 ! local
312 real(dp) :: drat
313
314 drat = d2 / d1
315 if (drat <= dlnlow .or. drat >= dlnhigh) then
316 logmean = (d2 - d1) / log(drat)
317 else
318 logmean = dhalf * (d1 + d2)
319 end if
320 end function logmean
321
322 !> @brief Calculate wetted cell thickness at interface between two cells
323 !<
324 function thksatnm(ibdn, ibdm, ictn, ictm, iupstream, ihc, &
325 hn, hm, satn, satm, topn, topm, botn, botm) result(res)
326 ! return variable
327 real(dp) :: res !< wetted cell thickness for connection nm
328 ! dummy
329 integer(I4B), intent(in) :: ibdn !< cell n active flag
330 integer(I4B), intent(in) :: ibdm !< cell m active flag
331 integer(I4B), intent(in) :: ictn !< cell n convertible cell flag
332 integer(I4B), intent(in) :: ictm !< cell m convertible cell flag
333 integer(I4B), intent(in) :: iupstream !< flag for upstream weighting
334 integer(I4B), intent(in) :: ihc !< connection type
335 real(dp), intent(in) :: hn !< cell n head
336 real(dp), intent(in) :: hm !< cell m head
337 real(dp), intent(in) :: satn !< cell n wetted cell fraction
338 real(dp), intent(in) :: satm !< cell m wetted cell fraction
339 real(dp), intent(in) :: topn !< top of cell n
340 real(dp), intent(in) :: topm !< top of cell m
341 real(dp), intent(in) :: botn !< bottom of cell n
342 real(dp), intent(in) :: botm !< bottom of cell m
343 ! local
344 real(dp) :: thksatn
345 real(dp) :: thksatm
346 real(dp) :: sill_top
347 real(dp) :: sill_bot
348 !
349 ! n or m is inactive
350 if (ibdn == 0 .or. ibdm == 0) then
351 res = dzero
352 !
353 ! both cells are non-convertible
354 elseif (ictn == 0 .and. ictm == 0) then
355 if (ihc == c3d_staggered) then
356 sill_top = min(topn, topm)
357 sill_bot = max(botn, botm)
358
359 thksatn = max(sill_top - sill_bot, dzero)
360 thksatm = thksatn
361 else
362 thksatn = topn - botn
363 thksatm = topm - botm
364 end if
365 res = dhalf * (thksatn + thksatm)
366 !
367 ! At least one of the cells is convertible
368 elseif (iupstream == 1) then
369 if (hn > hm) then
370 res = satn * (topn - botn)
371 else if (hm > hn) then
372 res = satm * (topm - botm)
373 else
374 res = max(satn * (topn - botn), satm * (topm - botm))
375 end if
376 !
377 ! At least one of the cells is convertible and not upstream weighted
378 else
379 if (ihc == c3d_staggered) then
380 thksatn = staggered_thkfrac(topn, botn, satn, topm, botm)
381 thksatm = staggered_thkfrac(topm, botm, satm, topn, botn)
382 else
383 thksatn = satn * (topn - botn)
384 thksatm = satm * (topm - botm)
385 end if
386 res = dhalf * (thksatn + thksatm)
387 end if
388 end function thksatnm
389
390 !> @brief Calculate the thickness fraction for staggered grids
391 !<
392 function staggered_thkfrac(top, bot, sat, topc, botc) result(res)
393 ! return variable
394 real(dp) :: res !< staggered thickness fraction for cell
395 ! dummy
396 real(dp) :: top !< top of cell
397 real(dp) :: bot !< bottom of cell
398 real(dp) :: sat !< cell saturation
399 real(dp) :: topc !< top of connected cell
400 real(dp) :: botc !< bottom of connected cells
401 ! local
402 real(dp) :: sill_top
403 real(dp) :: sill_bot
404 real(dp) :: tp
405
406 sill_top = min(top, topc)
407 sill_bot = max(bot, botc)
408 tp = bot + sat * (top - bot)
409 res = max(min(tp, sill_top) - sill_bot, dzero)
410 end function staggered_thkfrac
411
412 !> @brief Calculate the saturated flow area of a cell for a connection
413 !!
414 !! Vertical connections use the connection area. Horizontal connections
415 !! use the connection width times the cell's saturated thickness, limited
416 !! to the overlap with the connected cell for vertically staggered
417 !! connections.
418 !<
419 function flow_area(ihc, hwva, top, bot, sat, topc, botc) result(res)
420 ! return variable
421 real(dp) :: res !< saturated flow area for cell
422 ! dummy
423 integer(I4B), intent(in) :: ihc !< connection type
424 real(dp), intent(in) :: hwva !< connection area or width
425 real(dp), intent(in) :: top !< top of cell
426 real(dp), intent(in) :: bot !< bottom of cell
427 real(dp), intent(in) :: sat !< cell saturation
428 real(dp), intent(in) :: topc !< top of connected cell
429 real(dp), intent(in) :: botc !< bottom of connected cell
430 ! local
431 real(dp) :: thksat
432
433 if (ihc == c3d_vertical) then
434 res = hwva
435 else
436 if (ihc == c3d_staggered) then
437 thksat = staggered_thkfrac(top, bot, sat, topc, botc)
438 else
439 thksat = (top - bot) * sat
440 end if
441 res = thksat * hwva
442 end if
443 end function flow_area
444
This module contains simulation constants.
Definition Constants.f90:9
@ c3d_staggered
horizontal connection for a vertically staggered grid
@ c3d_vertical
vertical connection
real(dp), parameter dlnlow
real constant low ratio used to calculate log mean of K
real(dp), parameter dhalf
real constant 1/2
Definition Constants.f90:68
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65
real(dp), parameter dlnhigh
real constant high ratio used to calculate log mean of K
real(dp), parameter done
real constant 1
Definition Constants.f90:76
This module contains stateless conductance functions.
real(dp) function, public thksatnm(ibdn, ibdm, ictn, ictm, iupstream, ihc, hn, hm, satn, satm, topn, topm, botn, botm)
Calculate wetted cell thickness at interface between two cells.
real(dp) function convertible_upstream(hn, hm, satn, satm, condsat)
Convertible cell(s) with upstream weighted horizontal conductance.
real(dp) function logmean(d1, d2)
Calculate the the logarithmic mean of two double precision numbers.
real(dp) function, public flow_area(ihc, hwva, top, bot, sat, topc, botc)
Calculate the saturated flow area of a cell for a connection.
@ ccond_amthmk
Arithmetic-mean thickness and harmonic-mean hydraulic conductivity.
@ ccond_amtlmk
Arithmetic-mean thickness and logarithmic-mean hydraulic conductivity.
real(dp) function convertible_standard(ihc, icellavg, satn, satm, hkn, hkm, topn, topm, botn, botm, cln, clm, fawidth)
Convertible cell(s) with standard weighted horizontal conductance.
real(dp) function, public condmean(k1, k2, thick1, thick2, cl1, cl2, width, iavgmeth)
Calculate the conductance between two cells.
real(dp) function, public hcond(ibdn, ibdm, ictn, ictm, iupstream, ihc, icellavg, condsat, hn, hm, satn, satm, hkn, hkm, topn, topm, botn, botm, cln, clm, fawidth)
Horizontal conductance between two cells.
real(dp) function, public staggered_thkfrac(top, bot, sat, topc, botc)
Calculate the thickness fraction for staggered grids.
real(dp) function, public vcond(ibdn, ibdm, ictn, ictm, inewton, ivarcv, idewatcv, condsat, hn, hm, vkn, vkm, satn, satm, topn, topm, botn, botm, flowarea)
Vertical conductance between two cells.
This module defines variable data types.
Definition kind.f90:8