MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
exg-gwfgwf.f90
Go to the documentation of this file.
1!> @brief This module contains the GwfGwfExchangeModule Module
2!!
3!! This module contains the code for connecting two GWF Models.
4!! The methods are based on the simple two point flux approximation
5!! with the option to use ghost nodes to improve accuracy. This
6!! exchange is used by GwfGwfConnection with the more sophisticated
7!! interface model coupling approach when XT3D is needed.
8!!
9!<
11
12 use kindmodule, only: dp, i4b, lgp
13 use simvariablesmodule, only: errmsg
18 use basedismodule, only: disbasetype
21 use listmodule, only: listtype
22 use listsmodule, only: basemodellist
24 use gwfmodule, only: gwfmodeltype
28 use observemodule, only: observetype
29 use obsmodule, only: obstype
33
34 implicit none
35
36 private
37 public :: gwfexchangetype
38 public :: gwfexchange_create
40 public :: castasgwfexchange
41
42 !> @brief Derived type for GwfExchangeType
43 !!
44 !! This derived type contains information and methods for
45 !! connecting two GWF models.
46 !<
48 class(gwfmodeltype), pointer :: gwfmodel1 => null() !< pointer to GWF Model 1
49 class(gwfmodeltype), pointer :: gwfmodel2 => null() !< pointer to GWF Model 2
50 !
51 ! -- GWF specific option block:
52 integer(I4B), pointer :: inewton => null() !< newton flag (1 newton is on)
53 integer(I4B), pointer :: icellavg => null() !< cell averaging
54 integer(I4B), pointer :: ivarcv => null() !< variable cv
55 integer(I4B), pointer :: idewatcv => null() !< dewatered cv
56 integer(I4B), pointer :: ingnc => null() !< unit number for gnc (0 if off)
57 type(ghostnodetype), pointer :: gnc => null() !< gnc object
58 integer(I4B), pointer :: inmvr => null() !< unit number for mover (0 if off)
59 class(gwfexgmovertype), pointer :: mvr => null() !< water mover object
60 integer(I4B), pointer :: inobs => null() !< unit number for GWF-GWF observations
61 type(obstype), pointer :: obs => null() !< observation object
62 !
63 ! -- internal data
64 real(dp), dimension(:), pointer, contiguous :: cond => null() !< conductance
65 real(dp), dimension(:), pointer, contiguous :: condsat => null() !< saturated conductance
66 integer(I4B), dimension(:), pointer, contiguous :: idxglo => null() !< mapping to global (solution) amat
67 integer(I4B), dimension(:), pointer, contiguous :: idxsymglo => null() !< mapping to global (solution) symmetric amat
68 real(dp), pointer :: satomega => null() !< saturation smoothing
69 real(dp), dimension(:), pointer, contiguous :: simvals => null() !< simulated flow rate for each exchange
70 !
71 ! -- table objects
72 type(tabletype), pointer :: outputtab1 => null()
73 type(tabletype), pointer :: outputtab2 => null()
74
75 contains
76
77 procedure :: exg_df => gwf_gwf_df
78 procedure :: exg_ac => gwf_gwf_ac
79 procedure :: exg_mc => gwf_gwf_mc
80 procedure :: exg_ar => gwf_gwf_ar
81 procedure :: exg_rp => gwf_gwf_rp
82 procedure :: exg_ad => gwf_gwf_ad
83 procedure :: exg_cf => gwf_gwf_cf
84 procedure :: exg_fc => gwf_gwf_fc
85 procedure :: exg_fn => gwf_gwf_fn
86 procedure :: exg_cq => gwf_gwf_cq
87 procedure :: exg_bd => gwf_gwf_bd
88 procedure :: exg_ot => gwf_gwf_ot
89 procedure :: exg_da => gwf_gwf_da
90 procedure :: exg_fp => gwf_gwf_fp
91 procedure :: get_iasym => gwf_gwf_get_iasym
94 procedure :: allocate_scalars
95 procedure :: allocate_arrays
96 procedure :: source_options
97 procedure :: read_gnc
98 procedure :: read_mvr
99 procedure, private :: calc_cond_sat
100 procedure, private :: condcalc
101 procedure, private :: calc_hy_horizontal
102 procedure, private :: rewet
103 procedure, private :: qcalc
104 procedure, private :: gwf_gwf_chd_bd
105 procedure :: gwf_gwf_bdsav
106 procedure, private :: gwf_gwf_bdsav_model
107 procedure, private :: gwf_gwf_df_obs
108 procedure, private :: gwf_gwf_rp_obs
109 procedure, public :: gwf_gwf_save_simvals
110 procedure, private :: gwf_gwf_calc_simvals
111 procedure, public :: gwf_gwf_set_flow_to_npf
112 procedure, private :: validate_exchange
114 end type gwfexchangetype
115
116contains
117
118 !> @brief Create GWF GWF exchange
119 !!
120 !! Create a new GWF to GWF exchange object.
121 !<
122 subroutine gwfexchange_create(filename, name, id, m1_id, m2_id, input_mempath)
123 ! -- modules
127 use obsmodule, only: obs_cr
129 ! -- dummy
130 character(len=*), intent(in) :: filename !< filename for reading
131 character(len=*) :: name !< exchange name
132 integer(I4B), intent(in) :: id !< id for the exchange
133 integer(I4B), intent(in) :: m1_id !< id for model 1
134 integer(I4B), intent(in) :: m2_id !< id for model 2
135 character(len=*), intent(in) :: input_mempath
136 ! -- local
137 type(gwfexchangetype), pointer :: exchange
138 class(basemodeltype), pointer :: mb
139 class(baseexchangetype), pointer :: baseexchange
140 integer(I4B) :: m1_index, m2_index
141 !
142 ! -- Create a new exchange and add it to the baseexchangelist container
143 allocate (exchange)
144 baseexchange => exchange
145 call addbaseexchangetolist(baseexchangelist, baseexchange)
146 !
147 ! -- Assign id and name
148 exchange%id = id
149 exchange%name = name
150 exchange%memoryPath = create_mem_path(exchange%name)
151 exchange%input_mempath = input_mempath
152 !
153 ! -- allocate scalars and set defaults
154 call exchange%allocate_scalars()
155 exchange%filename = filename
156 exchange%typename = 'GWF-GWF'
157 !
158 ! -- set gwfmodel1
159 m1_index = model_loc_idx(m1_id)
160 if (m1_index > 0) then
161 mb => getbasemodelfromlist(basemodellist, m1_index)
162 select type (mb)
163 type is (gwfmodeltype)
164 exchange%model1 => mb
165 exchange%gwfmodel1 => mb
166 end select
167 end if
168 exchange%v_model1 => get_virtual_model(m1_id)
169 exchange%is_datacopy = .not. exchange%v_model1%is_local
170 !
171 ! -- set gwfmodel2
172 m2_index = model_loc_idx(m2_id)
173 if (m2_index > 0) then
174 mb => getbasemodelfromlist(basemodellist, m2_index)
175 select type (mb)
176 type is (gwfmodeltype)
177 exchange%model2 => mb
178 exchange%gwfmodel2 => mb
179 end select
180 end if
181 exchange%v_model2 => get_virtual_model(m2_id)
182 !
183 ! -- Verify that gwf model1 is of the correct type
184 if (.not. associated(exchange%gwfmodel1) .and. m1_index > 0) then
185 write (errmsg, '(3a)') 'Problem with GWF-GWF exchange ', &
186 trim(exchange%name), &
187 '. First specified GWF Model does not appear to be of the correct type.'
188 call store_error(errmsg, terminate=.true.)
189 end if
190 !
191 ! -- Verify that gwf model2 is of the correct type
192 if (.not. associated(exchange%gwfmodel2) .and. m2_index > 0) then
193 write (errmsg, '(3a)') 'Problem with GWF-GWF exchange ', &
194 trim(exchange%name), &
195 '. Second specified GWF Model does not appear to be of the correct type.'
196 call store_error(errmsg, terminate=.true.)
197 end if
198 !
199 ! -- Create the obs package
200 call obs_cr(exchange%obs, exchange%inobs)
201 end subroutine gwfexchange_create
202
203 !> @brief Define GWF GWF exchange
204 !!
205 !! Define GWF to GWF exchange object.
206 !<
207 subroutine gwf_gwf_df(this)
208 ! -- modules
209 use simvariablesmodule, only: iout
211 use ghostnodemodule, only: gnc_cr
212 ! -- dummy
213 class(gwfexchangetype) :: this !< GwfExchangeType
214 ! -- local
215 !
216 ! -- log the exchange
217 write (iout, '(/a,a)') ' Creating exchange: ', this%name
218 !
219 ! -- Ensure models are in same solution
220 if (this%v_model1%idsoln%get() /= this%v_model2%idsoln%get()) then
221 call store_error('Two models are connected in a GWF '// &
222 'exchange but they are in different solutions. '// &
223 'GWF models must be in same solution: '// &
224 trim(this%v_model1%name)//' '// &
225 trim(this%v_model2%name))
226 call store_error_filename(this%filename)
227 end if
228 !
229 ! -- source options
230 call this%source_options(iout)
231 !
232 ! -- source dimensions
233 call this%source_dimensions(iout)
234 !
235 ! -- allocate arrays
236 call this%allocate_arrays()
237 !
238 ! -- source exchange data
239 call this%source_data(iout)
240 !
241 ! -- call each model and increase the edge count
242 if (associated(this%gwfmodel1)) then
243 call this%gwfmodel1%npf%increase_edge_count(this%nexg)
244 end if
245 if (associated(this%gwfmodel2)) then
246 call this%gwfmodel2%npf%increase_edge_count(this%nexg)
247 end if
248 !
249 ! -- Create and read ghost node information
250 if (this%ingnc > 0) then
251 if (associated(this%gwfmodel1) .and. associated(this%gwfmodel2)) then
252 call gnc_cr(this%gnc, this%name, this%ingnc, iout)
253 call this%read_gnc()
254 end if
255 end if
256 !
257 ! -- Read mover information
258 if (this%inmvr > 0) then
259 call this%read_mvr(iout)
260 end if
261 !
262 ! -- Store obs
263 call this%gwf_gwf_df_obs()
264 if (associated(this%gwfmodel1)) then
265 call this%obs%obs_df(iout, this%name, 'GWF-GWF', this%gwfmodel1%dis)
266 end if
267 !
268 ! -- validate
269 call this%validate_exchange()
270 end subroutine gwf_gwf_df
271
272 !> @brief validate exchange data after reading
273 !<
274 subroutine validate_exchange(this)
275 ! -- modules
276 class(gwfexchangetype) :: this !< GwfExchangeType
277 ! -- local
278 logical(LGP) :: has_k22, has_spdis, has_vsc
279 !
280 ! Periodic boundary condition in exchange don't allow XT3D (=interface model)
281 if (this%v_model1 == this%v_model2) then
282 if (this%ixt3d > 0) then
283 write (errmsg, '(3a)') 'GWF-GWF exchange ', trim(this%name), &
284 ' is a periodic boundary condition which cannot'// &
285 ' be configured with XT3D'
286 call store_error(errmsg, terminate=.true.)
287 end if
288 end if
289 !
290 ! XT3D needs angle information
291 if (this%ixt3d > 0 .and. this%ianglex == 0) then
292 write (errmsg, '(3a)') 'GWF-GWF exchange ', trim(this%name), &
293 ' requires that ANGLDEGX be specified as an'// &
294 ' auxiliary variable because XT3D is enabled'
295 call store_error(errmsg, terminate=.true.)
296 end if
297 !
298 ! determine if specific functionality is demanded,
299 ! in model 1 or model 2 (in parallel, only one of
300 ! the models is checked, but the exchange is duplicated)
301 has_k22 = .false.
302 has_spdis = .false.
303 has_vsc = .false.
304 if (associated(this%gwfmodel1)) then
305 has_k22 = (this%gwfmodel1%npf%ik22 /= 0)
306 has_spdis = (this%gwfmodel1%npf%icalcspdis /= 0)
307 has_vsc = (this%gwfmodel1%npf%invsc /= 0)
308 end if
309 if (associated(this%gwfmodel2)) then
310 has_k22 = has_k22 .or. (this%gwfmodel2%npf%ik22 /= 0)
311 has_spdis = has_spdis .or. (this%gwfmodel2%npf%icalcspdis /= 0)
312 has_vsc = has_vsc .or. (this%gwfmodel2%npf%invsc /= 0)
313 end if
314 !
315 ! If horizontal anisotropy is in either model1 or model2,
316 ! ANGLDEGX must be provided as an auxiliary variable for this
317 ! GWF-GWF exchange (this%ianglex > 0).
318 if (has_k22) then
319 if (this%ianglex == 0) then
320 write (errmsg, '(3a)') 'GWF-GWF exchange ', trim(this%name), &
321 ' requires that ANGLDEGX be specified as an'// &
322 ' auxiliary variable because K22 was specified'// &
323 ' in one or both groundwater models.'
324 call store_error(errmsg, terminate=.true.)
325 end if
326 end if
327 !
328 ! If specific discharge is needed for model1 or model2,
329 ! ANGLDEGX must be provided as an auxiliary variable for this
330 ! GWF-GWF exchange (this%ianglex > 0).
331 if (has_spdis) then
332 if (this%ianglex == 0) then
333 write (errmsg, '(3a)') 'GWF-GWF exchange ', trim(this%name), &
334 ' requires that ANGLDEGX be specified as an'// &
335 ' auxiliary variable because specific discharge'// &
336 ' is being calculated in one or both'// &
337 ' groundwater models.'
338 call store_error(errmsg, terminate=.true.)
339 end if
340 if (this%icdist == 0) then
341 write (errmsg, '(3a)') 'GWF-GWF exchange ', trim(this%name), &
342 ' requires that CDIST be specified as an'// &
343 ' auxiliary variable because specific discharge'// &
344 ' is being calculated in one or both'// &
345 ' groundwater models.'
346 call store_error(errmsg, terminate=.true.)
347 end if
348 end if
349 !
350 ! If viscosity is on in either model, then terminate with an
351 ! error as viscosity package doesn't work yet with exchanges.
352 if (has_vsc) then
353 write (errmsg, '(3a)') 'GWF-GWF exchange ', trim(this%name), &
354 ' requires that the Viscosity Package is inactive'// &
355 ' in both of the connected models.'
356 call store_error(errmsg, terminate=.true.)
357 end if
358 end subroutine validate_exchange
359
360 !> @brief Add connections
361 !!
362 !! Override parent exg_ac so that gnc can add connections here.
363 !<
364 subroutine gwf_gwf_ac(this, sparse)
365 ! -- modules
366 use sparsemodule, only: sparsematrix
367 ! -- dummy
368 class(gwfexchangetype) :: this !< GwfExchangeType
369 type(sparsematrix), intent(inout) :: sparse
370 ! -- local
371 integer(I4B) :: n, iglo, jglo
372 !
373 ! -- add exchange connections
374 do n = 1, this%nexg
375 iglo = this%nodem1(n) + this%gwfmodel1%moffset
376 jglo = this%nodem2(n) + this%gwfmodel2%moffset
377 call sparse%addconnection(iglo, jglo, 1)
378 call sparse%addconnection(jglo, iglo, 1)
379 end do
380 !
381 ! -- add gnc connections
382 if (this%ingnc > 0) then
383 call this%gnc%gnc_ac(sparse)
384 end if
385 end subroutine gwf_gwf_ac
386
387 !> @brief Map connections
388 !!
389 !! Map the connections in the global matrix
390 !<
391 subroutine gwf_gwf_mc(this, matrix_sln)
392 ! -- modules
393 use sparsemodule, only: sparsematrix
394 ! -- dummy
395 class(gwfexchangetype) :: this !< GwfExchangeType
396 class(matrixbasetype), pointer :: matrix_sln !< the system matrix
397 ! -- local
398 integer(I4B) :: n, iglo, jglo
399 !
400 ! -- map exchange connections
401 do n = 1, this%nexg
402 iglo = this%nodem1(n) + this%gwfmodel1%moffset
403 jglo = this%nodem2(n) + this%gwfmodel2%moffset
404 this%idxglo(n) = matrix_sln%get_position(iglo, jglo)
405 this%idxsymglo(n) = matrix_sln%get_position(jglo, iglo)
406 end do
407 !
408 ! -- map gnc connections
409 if (this%ingnc > 0) then
410 call this%gnc%gnc_mc(matrix_sln)
411 end if
412 end subroutine gwf_gwf_mc
413
414 !> @brief Allocate and read
415 !!
416 !! Allocated and read and calculate saturated conductance
417 !<
418 subroutine gwf_gwf_ar(this)
419 ! -- dummy
420 class(gwfexchangetype) :: this !< GwfExchangeType
421 !
422 ! -- If mover is active, then call ar routine
423 if (this%inmvr > 0) call this%mvr%mvr_ar()
424 !
425 ! -- Calculate the saturated conductance for all connections
426 if (.not. this%use_interface_model()) call this%calc_cond_sat()
427 !
428 ! -- Observation AR
429 call this%obs%obs_ar()
430 end subroutine gwf_gwf_ar
431
432 !> @brief Read and prepare
433 !!
434 !! Read new data for mover and obs
435 !<
436 subroutine gwf_gwf_rp(this)
437 ! -- modules
438 use tdismodule, only: readnewdata
439 ! -- dummy
440 class(gwfexchangetype) :: this !< GwfExchangeType
441 !
442 ! -- Check with TDIS on whether or not it is time to RP
443 if (.not. readnewdata) return
444 !
445 ! -- Read and prepare for mover
446 if (this%inmvr > 0) call this%mvr%mvr_rp()
447 !
448 ! -- Read and prepare for observations
449 call this%gwf_gwf_rp_obs()
450 end subroutine gwf_gwf_rp
451
452 !> @brief Advance
453 !!
454 !! Advance mover and obs
455 !<
456 subroutine gwf_gwf_ad(this)
457 ! -- dummy
458 class(gwfexchangetype) :: this !< GwfExchangeType
459 !
460 ! -- Advance mover
461 if (this%inmvr > 0) call this%mvr%mvr_ad()
462 !
463 ! -- Push simulated values to preceding time step
464 call this%obs%obs_ad()
465 end subroutine gwf_gwf_ad
466
467 !> @brief Calculate coefficients
468 !!
469 !! Rewet as necessary
470 !<
471 subroutine gwf_gwf_cf(this, kiter)
472 ! -- dummy
473 class(gwfexchangetype) :: this !< GwfExchangeType
474 integer(I4B), intent(in) :: kiter
475 ! -- local
476 !
477 ! -- Call mvr cf routine
478 if (this%inmvr > 0) call this%mvr%xmvr_cf()
479 !
480 ! -- Rewet cells across models using the wetdry parameters in each model's
481 ! npf package, and the head in the connected model.
482 call this%rewet(kiter)
483 end subroutine gwf_gwf_cf
484
485 !> @brief Fill coefficients
486 !!
487 !! Calculate conductance and fill coefficient matrix
488 !<
489 subroutine gwf_gwf_fc(this, kiter, matrix_sln, rhs_sln, inwtflag)
490 ! -- modules
491 use constantsmodule, only: dhalf
493 ! -- dummy
494 class(gwfexchangetype) :: this !< GwfExchangeType
495 integer(I4B), intent(in) :: kiter
496 class(matrixbasetype), pointer :: matrix_sln
497 real(DP), dimension(:), intent(inout) :: rhs_sln
498 integer(I4B), optional, intent(in) :: inwtflag
499 ! -- local
500 integer(I4B) :: inwt, iexg
501 integer(I4B) :: i, nodem1sln, nodem2sln
502 !
503 ! -- calculate the conductance for each exchange connection
504 call this%condcalc()
505 !
506 ! -- if gnc is active, then copy cond into gnc cond (might consider a
507 ! pointer here in the future)
508 if (this%ingnc > 0) then
509 do iexg = 1, this%nexg
510 this%gnc%cond(iexg) = this%cond(iexg)
511 end do
512 end if
513 !
514 ! -- Put this%cond into amatsln
515 do i = 1, this%nexg
516 call matrix_sln%set_value_pos(this%idxglo(i), this%cond(i))
517 call matrix_sln%set_value_pos(this%idxsymglo(i), this%cond(i))
518
519 nodem1sln = this%nodem1(i) + this%gwfmodel1%moffset
520 nodem2sln = this%nodem2(i) + this%gwfmodel2%moffset
521 call matrix_sln%add_diag_value(nodem1sln, -this%cond(i))
522 call matrix_sln%add_diag_value(nodem2sln, -this%cond(i))
523 end do
524 !
525 ! -- Fill the gnc terms in the solution matrix
526 if (this%ingnc > 0) then
527 call this%gnc%gnc_fc(kiter, matrix_sln)
528 end if
529 !
530 ! -- Call mvr fc routine
531 if (this%inmvr > 0) call this%mvr%mvr_fc()
532 !
533 ! -- Set inwt to exchange newton, but shut off if requested by caller
534 inwt = this%inewton
535 if (present(inwtflag)) then
536 if (inwtflag == 0) inwt = 0
537 end if
538 if (inwt /= 0) then
539 call this%exg_fn(kiter, matrix_sln)
540 end if
541 !
542 ! -- Ghost node Newton-Raphson
543 if (this%ingnc > 0) then
544 if (inwt /= 0) then
545 call this%gnc%gnc_fn(kiter, matrix_sln, this%condsat, &
546 ihc_opt=this%ihc, ivarcv_opt=this%ivarcv, &
547 ictm1_opt=this%gwfmodel1%npf%icelltype, &
548 ictm2_opt=this%gwfmodel2%npf%icelltype)
549 end if
550 end if
551 end subroutine gwf_gwf_fc
552
553 !> @brief Fill Newton
554 !!
555 !! Fill amatsln with Newton terms
556 !<
557 subroutine gwf_gwf_fn(this, kiter, matrix_sln)
558 ! -- modules
560 ! -- dummy
561 class(gwfexchangetype) :: this !< GwfExchangeType
562 integer(I4B), intent(in) :: kiter
563 class(matrixbasetype), pointer :: matrix_sln
564 ! -- local
565 logical :: nisup
566 integer(I4B) :: iexg
567 integer(I4B) :: n, m
568 integer(I4B) :: nodensln, nodemsln
569 integer(I4B) :: ibdn, ibdm
570 real(DP) :: topn, topm
571 real(DP) :: botn, botm
572 real(DP) :: topup, botup
573 real(DP) :: hn, hm
574 real(DP) :: hup, hdn
575 real(DP) :: cond
576 real(DP) :: term
577 real(DP) :: consterm
578 real(DP) :: derv
579 !
580 do iexg = 1, this%nexg
581 n = this%nodem1(iexg)
582 m = this%nodem2(iexg)
583 nodensln = this%nodem1(iexg) + this%gwfmodel1%moffset
584 nodemsln = this%nodem2(iexg) + this%gwfmodel2%moffset
585 ibdn = this%gwfmodel1%ibound(n)
586 ibdm = this%gwfmodel2%ibound(m)
587 topn = this%gwfmodel1%dis%top(n)
588 topm = this%gwfmodel2%dis%top(m)
589 botn = this%gwfmodel1%dis%bot(n)
590 botm = this%gwfmodel2%dis%bot(m)
591 hn = this%gwfmodel1%x(n)
592 hm = this%gwfmodel2%x(m)
593 if (this%ihc(iexg) == 0) then
594 ! -- vertical connection, newton not supported
595 else
596 ! -- determine upstream node
597 nisup = .false.
598 if (hm < hn) nisup = .true.
599 !
600 ! -- set upstream top and bot
601 if (nisup) then
602 topup = topn
603 botup = botn
604 hup = hn
605 hdn = hm
606 else
607 topup = topm
608 botup = botm
609 hup = hm
610 hdn = hn
611 end if
612 !
613 ! -- no newton terms if upstream cell is confined
614 if (nisup) then
615 if (this%gwfmodel1%npf%icelltype(n) == 0) cycle
616 else
617 if (this%gwfmodel2%npf%icelltype(m) == 0) cycle
618 end if
619 !
620 ! -- set topup and botup
621 if (this%ihc(iexg) == 2) then
622 topup = min(topn, topm)
623 botup = max(botn, botm)
624 end if
625 !
626 ! get saturated conductivity for derivative
627 cond = this%condsat(iexg)
628 !
629 ! -- TO DO deal with MODFLOW-NWT upstream weighting option
630 !
631 ! -- compute terms
632 consterm = -cond * (hup - hdn)
633 derv = squadraticsaturationderivative(topup, botup, hup)
634 if (nisup) then
635 !
636 ! -- fill jacobian with n being upstream
637 term = consterm * derv
638 this%gwfmodel1%rhs(n) = this%gwfmodel1%rhs(n) + term * hn
639 this%gwfmodel2%rhs(m) = this%gwfmodel2%rhs(m) - term * hn
640 call matrix_sln%add_diag_value(nodensln, term)
641 if (ibdm > 0) then
642 call matrix_sln%add_value_pos(this%idxsymglo(iexg), -term)
643 end if
644 else
645 !
646 ! -- fill jacobian with m being upstream
647 term = -consterm * derv
648 this%gwfmodel1%rhs(n) = this%gwfmodel1%rhs(n) + term * hm
649 this%gwfmodel2%rhs(m) = this%gwfmodel2%rhs(m) - term * hm
650 call matrix_sln%add_diag_value(nodemsln, -term)
651 if (ibdn > 0) then
652 call matrix_sln%add_value_pos(this%idxglo(iexg), term)
653 end if
654 end if
655 end if
656 end do
657 end subroutine gwf_gwf_fn
658
659 !> @brief Calculate flow
660 !!
661 !! Calculate flow between two cells and store in simvals, also set
662 !! information needed for specific discharge calculation
663 !<
664 subroutine gwf_gwf_cq(this, icnvg, isuppress_output, isolnid)
665 ! -- dummy
666 class(gwfexchangetype) :: this !< GwfExchangeType
667 integer(I4B), intent(inout) :: icnvg
668 integer(I4B), intent(in) :: isuppress_output
669 integer(I4B), intent(in) :: isolnid
670 !
671 ! -- calculate flow and store in simvals
672 call this%gwf_gwf_calc_simvals()
673 !
674 ! -- set flows to model edges in NPF
675 call this%gwf_gwf_set_flow_to_npf()
676 !
677 ! -- add exchange flows to model's flowja diagonal
678 call this%gwf_gwf_add_to_flowja()
679 end subroutine gwf_gwf_cq
680
681 !> @brief Calculate flow rates for the exchanges and store them in a member
682 !! array
683 !<
684 subroutine gwf_gwf_calc_simvals(this)
685 ! -- modules
686 use constantsmodule, only: dzero
687 ! -- dummy
688 class(gwfexchangetype) :: this !< GwfExchangeType
689 ! -- local
690 integer(I4B) :: i
691 integer(I4B) :: n1, n2
692 integer(I4B) :: ibdn1, ibdn2
693 real(DP) :: rrate
694 !
695 do i = 1, this%nexg
696 rrate = dzero
697 n1 = this%nodem1(i)
698 n2 = this%nodem2(i)
699 ibdn1 = this%gwfmodel1%ibound(n1)
700 ibdn2 = this%gwfmodel2%ibound(n2)
701 if (ibdn1 /= 0 .and. ibdn2 /= 0) then
702 rrate = this%qcalc(i, n1, n2)
703 if (this%ingnc > 0) then
704 rrate = rrate + this%gnc%deltaqgnc(i)
705 end if
706 end if
707 this%simvals(i) = rrate
708 end do
709 end subroutine gwf_gwf_calc_simvals
710
711 !> @brief Add exchange flow to each model flowja diagonal position so that
712 !! residual is calculated correctly.
713 !<
714 subroutine gwf_gwf_add_to_flowja(this)
715 ! -- modules
716 class(gwfexchangetype) :: this !< GwfExchangeType
717 ! -- local
718 integer(I4B) :: i
719 integer(I4B) :: n
720 integer(I4B) :: idiag
721 real(DP) :: flow
722 !
723 do i = 1, this%nexg
724 !
725 if (associated(this%gwfmodel1)) then
726 n = this%nodem1(i)
727 if (this%gwfmodel1%ibound(n) > 0) then
728 flow = this%simvals(i)
729 idiag = this%gwfmodel1%ia(n)
730 this%gwfmodel1%flowja(idiag) = this%gwfmodel1%flowja(idiag) + flow
731 end if
732 end if
733 !
734 if (associated(this%gwfmodel2)) then
735 n = this%nodem2(i)
736 if (this%gwfmodel2%ibound(n) > 0) then
737 flow = -this%simvals(i)
738 idiag = this%gwfmodel2%ia(n)
739 this%gwfmodel2%flowja(idiag) = this%gwfmodel2%flowja(idiag) + flow
740 end if
741 end if
742 !
743 end do
744 end subroutine gwf_gwf_add_to_flowja
745
746 !> @brief Set flow rates to the edges in the models
747 !<
748 subroutine gwf_gwf_set_flow_to_npf(this)
749 ! -- modules
750 use constantsmodule, only: dzero, dpio180
752 ! -- dummy
753 class(gwfexchangetype) :: this !< GwfExchangeType
754 ! -- local
755 integer(I4B) :: i
756 integer(I4B) :: n1, n2
757 integer(I4B) :: ibdn1, ibdn2
758 integer(I4B) :: ictn1, ictn2
759 integer(I4B) :: ihc
760 real(DP) :: rrate
761 real(DP) :: topn1, topn2
762 real(DP) :: botn1, botn2
763 real(DP) :: satn1, satn2
764 real(DP) :: hn1, hn2
765 real(DP) :: nx, ny
766 real(DP) :: distance
767 real(DP) :: dltot
768 real(DP) :: hwva
769 real(DP) :: area
770 real(DP) :: thksat
771 real(DP) :: angle
772 !
773 ! -- Return if there neither model needs to calculate specific discharge
774 if (this%gwfmodel1%npf%icalcspdis == 0 .and. &
775 this%gwfmodel2%npf%icalcspdis == 0) return
776 !
777 ! -- Loop through all exchanges using the flow rate
778 ! stored in simvals
779 do i = 1, this%nexg
780 rrate = this%simvals(i)
781 n1 = this%nodem1(i)
782 n2 = this%nodem2(i)
783 ihc = this%ihc(i)
784 hwva = this%hwva(i)
785 ibdn1 = this%gwfmodel1%ibound(n1)
786 ibdn2 = this%gwfmodel2%ibound(n2)
787 ictn1 = this%gwfmodel1%npf%icelltype(n1)
788 ictn2 = this%gwfmodel2%npf%icelltype(n2)
789 topn1 = this%gwfmodel1%dis%top(n1)
790 topn2 = this%gwfmodel2%dis%top(n2)
791 botn1 = this%gwfmodel1%dis%bot(n1)
792 botn2 = this%gwfmodel2%dis%bot(n2)
793 satn1 = this%gwfmodel1%npf%sat(n1)
794 satn2 = this%gwfmodel2%npf%sat(n2)
795 hn1 = this%gwfmodel1%x(n1)
796 hn2 = this%gwfmodel2%x(n2)
797 !
798 ! -- Calculate face normal components
799 if (ihc == 0) then
800 nx = dzero
801 ny = dzero
802 area = hwva
803 if (botn1 < botn2) then
804 ! -- n1 is beneath n2, so rate is positive downward. Flip rate
805 ! upward so that points in positive z direction
806 rrate = -rrate
807 end if
808 else
809 if (this%ianglex > 0) then
810 angle = this%auxvar(this%ianglex, i) * dpio180
811 nx = cos(angle)
812 ny = sin(angle)
813 else
814 ! error?
815 call store_error('error in gwf_gwf_cq', terminate=.true.)
816 end if
817 !
818 ! -- Calculate the saturated thickness at interface between n1 and n2
819 thksat = thksatnm(ibdn1, ibdn2, ictn1, ictn2, this%inewton, ihc, &
820 hn1, hn2, satn1, satn2, &
821 topn1, topn2, botn1, botn2)
822 area = hwva * thksat
823 end if
824 !
825 ! -- Submit this connection and flow information to the npf
826 ! package of gwfmodel1
827 if (this%icdist > 0) then
828 dltot = this%auxvar(this%icdist, i)
829 else
830 call store_error('error in gwf_gwf_cq', terminate=.true.)
831 end if
832 distance = dltot * this%cl1(i) / (this%cl1(i) + this%cl2(i))
833 if (this%gwfmodel1%npf%icalcspdis == 1) then
834 call this%gwfmodel1%npf%set_edge_properties(n1, ihc, rrate, area, &
835 nx, ny, distance)
836 end if
837 !
838 ! -- Submit this connection and flow information to the npf
839 ! package of gwfmodel2
840 if (this%icdist > 0) then
841 dltot = this%auxvar(this%icdist, i)
842 else
843 call store_error('error in gwf_gwf_cq', terminate=.true.)
844 end if
845 if (this%gwfmodel2%npf%icalcspdis == 1) then
846 distance = dltot * this%cl2(i) / (this%cl1(i) + this%cl2(i))
847 if (ihc /= 0) rrate = -rrate
848 call this%gwfmodel2%npf%set_edge_properties(n2, ihc, rrate, area, &
849 -nx, -ny, distance)
850 end if
851 !
852 end do
853 end subroutine gwf_gwf_set_flow_to_npf
854
855 !> @brief Budget
856 !!
857 !! Accumulate budget terms
858 !<
859 subroutine gwf_gwf_bd(this, icnvg, isuppress_output, isolnid)
860 ! -- modules
863 ! -- dummy
864 class(gwfexchangetype) :: this !< GwfExchangeType
865 integer(I4B), intent(inout) :: icnvg
866 integer(I4B), intent(in) :: isuppress_output
867 integer(I4B), intent(in) :: isolnid
868 ! -- local
869 character(len=LENBUDTXT), dimension(1) :: budtxt
870 real(DP), dimension(2, 1) :: budterm
871 real(DP) :: ratin, ratout
872 !
873 ! -- initialize
874 budtxt(1) = ' FLOW-JA-FACE'
875 !
876 ! -- Calculate ratin/ratout and pass to model budgets
877 call rate_accumulator(this%simvals, ratin, ratout)
878 !
879 ! -- Add the budget terms to model 1
880 if (associated(this%gwfmodel1)) then
881 budterm(1, 1) = ratin
882 budterm(2, 1) = ratout
883 call this%gwfmodel1%model_bdentry(budterm, budtxt, this%name)
884 end if
885 !
886 ! -- Add the budget terms to model 2
887 if (associated(this%gwfmodel2)) then
888 budterm(1, 1) = ratout
889 budterm(2, 1) = ratin
890 call this%gwfmodel2%model_bdentry(budterm, budtxt, this%name)
891 end if
892 !
893 ! -- Add any flows from one model into a constant head in another model
894 ! as a separate budget term called FLOW-JA-FACE-CHD
895 call this%gwf_gwf_chd_bd()
896 !
897 ! -- Call mvr bd routine
898 if (this%inmvr > 0) call this%mvr%mvr_bd()
899 end subroutine gwf_gwf_bd
900
901 !> @brief gwf-gwf-chd-bd
902 !!
903 !! Account for flow from an external model into a chd cell
904 !<
905 subroutine gwf_gwf_chd_bd(this)
906 ! -- modules
909 ! -- dummy
910 class(gwfexchangetype) :: this !< GwfExchangeType
911 ! -- local
912 character(len=LENBUDTXT), dimension(1) :: budtxt
913 integer(I4B) :: n
914 integer(I4B) :: i
915 real(DP), dimension(2, 1) :: budterm
916 real(DP) :: ratin, ratout
917 real(DP) :: q
918 !
919 ! -- initialize
920 budtxt(1) = 'FLOW-JA-FACE-CHD'
921 !
922 ! -- Add the constant-head budget terms for flow from model 2 into model 1
923 if (associated(this%gwfmodel1)) then
924 ratin = dzero
925 ratout = dzero
926 do i = 1, this%nexg
927 n = this%nodem1(i)
928 if (this%gwfmodel1%ibound(n) < 0) then
929 q = this%simvals(i)
930 if (q > dzero) then
931 ratout = ratout + q
932 else
933 ratin = ratin - q
934 end if
935 end if
936 end do
937 budterm(1, 1) = ratin
938 budterm(2, 1) = ratout
939 call this%gwfmodel1%model_bdentry(budterm, budtxt, this%name)
940 end if
941 !
942 ! -- Add the constant-head budget terms for flow from model 1 into model 2
943 if (associated(this%gwfmodel2)) then
944 ratin = dzero
945 ratout = dzero
946 do i = 1, this%nexg
947 n = this%nodem2(i)
948 if (this%gwfmodel2%ibound(n) < 0) then
949 ! -- flip flow sign as flow is relative to model 1
950 q = -this%simvals(i)
951 if (q > dzero) then
952 ratout = ratout + q
953 else
954 ratin = ratin - q
955 end if
956 end if
957 end do
958 budterm(1, 1) = ratin
959 budterm(2, 1) = ratout
960 call this%gwfmodel2%model_bdentry(budterm, budtxt, this%name)
961 end if
962 end subroutine gwf_gwf_chd_bd
963
964 !> @brief Budget save
965 !!
966 !! Output individual flows to listing file and binary budget files
967 !<
968 subroutine gwf_gwf_bdsav(this)
969 ! -- dummy
970 class(gwfexchangetype) :: this !< GwfExchangeType
971 ! -- local
972 integer(I4B) :: icbcfl, ibudfl
973 !
974 ! -- budget for model1
975 if (associated(this%gwfmodel1)) then
976 call this%gwf_gwf_bdsav_model(this%gwfmodel1)
977 end if
978 !
979 ! -- budget for model2
980 if (associated(this%gwfmodel2)) then
981 call this%gwf_gwf_bdsav_model(this%gwfmodel2)
982 end if
983 !
984 ! -- Set icbcfl, ibudfl to zero so that flows will be printed and
985 ! saved, if the options were set in the MVR package
986 icbcfl = 1
987 ibudfl = 1
988 !
989 ! -- Call mvr bd routine
990 if (this%inmvr > 0) call this%mvr%mvr_bdsav(icbcfl, ibudfl, 0)
991 !
992 ! -- Calculate and write simulated values for observations
993 if (this%inobs /= 0) then
994 call this%gwf_gwf_save_simvals()
995 end if
996 end subroutine gwf_gwf_bdsav
997
998 subroutine gwf_gwf_bdsav_model(this, model)
999 ! -- modules
1001 use tdismodule, only: kstp, kper
1002 ! -- dummy
1003 class(gwfexchangetype) :: this !< this exchange
1004 class(gwfmodeltype), pointer :: model !< the model to save budget for
1005 ! -- local
1006 character(len=LENPACKAGENAME + 4) :: packname
1007 character(len=LENBUDTXT), dimension(1) :: budtxt
1008 type(tabletype), pointer :: output_tab
1009 class(virtualmodeltype), pointer :: nbr_model
1010 character(len=20) :: nodestr
1011 character(len=LENBOUNDNAME) :: bname
1012 integer(I4B) :: ntabrows
1013 integer(I4B) :: nodeu
1014 integer(I4B) :: i, n1, n2, n1u, n2u
1015 integer(I4B) :: ibinun
1016 real(DP) :: ratin, ratout, rrate
1017 logical(LGP) :: is_for_model1
1018 real(DP), dimension(this%naux) :: auxrow
1019 !
1020 budtxt(1) = ' FLOW-JA-FACE'
1021 packname = 'EXG '//this%name
1022 packname = adjustr(packname)
1023 if (associated(model, this%gwfmodel1)) then
1024 output_tab => this%outputtab1
1025 nbr_model => this%v_model2
1026 is_for_model1 = .true.
1027 else
1028 output_tab => this%outputtab2
1029 nbr_model => this%v_model1
1030 is_for_model1 = .false.
1031 end if
1032 !
1033 ! -- update output tables
1034 if (this%iprflow /= 0) then
1035 !
1036 ! -- update titles
1037 if (model%oc%oc_save('BUDGET')) then
1038 call output_tab%set_title(packname)
1039 end if
1040 !
1041 ! -- set table kstp and kper
1042 call output_tab%set_kstpkper(kstp, kper)
1043 !
1044 ! -- update maxbound of tables
1045 ntabrows = 0
1046 do i = 1, this%nexg
1047 n1 = this%nodem1(i)
1048 n2 = this%nodem2(i)
1049 !
1050 ! -- If both cells are active then calculate flow rate
1051 if (this%v_model1%ibound%get(n1) /= 0 .and. &
1052 this%v_model2%ibound%get(n2) /= 0) then
1053 ntabrows = ntabrows + 1
1054 end if
1055 end do
1056 if (ntabrows > 0) then
1057 call output_tab%set_maxbound(ntabrows)
1058 end if
1059 end if
1060 !
1061 ! -- Print and write budget terms
1062 !
1063 ! -- Set binary unit numbers for saving flows
1064 if (this%ipakcb /= 0) then
1065 ibinun = model%oc%oc_save_unit('BUDGET')
1066 else
1067 ibinun = 0
1068 end if
1069 !
1070 ! -- If save budget flag is zero for this stress period, then
1071 ! shut off saving
1072 if (.not. model%oc%oc_save('BUDGET')) ibinun = 0
1073 !
1074 ! -- If cell-by-cell flows will be saved as a list, write header.
1075 if (ibinun /= 0) then
1076 call model%dis%record_srcdst_list_header(budtxt(1), &
1077 model%name, &
1078 this%name, &
1079 nbr_model%name, &
1080 this%name, &
1081 this%naux, this%auxname, &
1082 ibinun, this%nexg, &
1083 model%iout)
1084 end if
1085 !
1086 ! Initialize accumulators
1087 ratin = dzero
1088 ratout = dzero
1089 !
1090 ! -- Loop through all exchanges
1091 do i = 1, this%nexg
1092 !
1093 ! -- Assign boundary name
1094 if (this%inamedbound > 0) then
1095 bname = this%boundname(i)
1096 else
1097 bname = ''
1098 end if
1099 !
1100 ! -- Calculate the flow rate between n1 and n2
1101 rrate = dzero
1102 n1 = this%nodem1(i)
1103 n2 = this%nodem2(i)
1104 !
1105 ! -- If both cells are active then calculate flow rate
1106 if (this%v_model1%ibound%get(n1) /= 0 .and. &
1107 this%v_model2%ibound%get(n2) /= 0) then
1108 rrate = this%simvals(i)
1109 !
1110 ! -- Print the individual rates to model list files if requested
1111 if (this%iprflow /= 0) then
1112 if (model%oc%oc_save('BUDGET')) then
1113 !
1114 ! -- set nodestr and write outputtab table
1115 if (is_for_model1) then
1116 nodeu = model%dis%get_nodeuser(n1)
1117 call model%dis%nodeu_to_string(nodeu, nodestr)
1118 call output_tab%print_list_entry(i, trim(adjustl(nodestr)), &
1119 rrate, bname)
1120 else
1121 nodeu = model%dis%get_nodeuser(n2)
1122 call model%dis%nodeu_to_string(nodeu, nodestr)
1123 call output_tab%print_list_entry(i, trim(adjustl(nodestr)), &
1124 -rrate, bname)
1125 end if
1126 end if
1127 end if
1128 if (rrate < dzero) then
1129 ratout = ratout - rrate
1130 else
1131 ratin = ratin + rrate
1132 end if
1133 end if
1134 !
1135 ! -- If saving cell-by-cell flows in list, write flow
1136 n1u = this%v_model1%dis_get_nodeuser(n1)
1137 n2u = this%v_model2%dis_get_nodeuser(n2)
1138 if (ibinun /= 0) then
1139 if (this%naux > 0) then
1140 auxrow(:) = this%auxvar(:, i)
1141 end if
1142 if (is_for_model1) then
1143 call model%dis%record_mf6_list_entry(ibinun, n1u, n2u, rrate, &
1144 this%naux, auxrow, &
1145 .false., .false.)
1146 else
1147 call model%dis%record_mf6_list_entry(ibinun, n2u, n1u, -rrate, &
1148 this%naux, auxrow, &
1149 .false., .false.)
1150 end if
1151 end if
1152 !
1153 end do
1154 end subroutine gwf_gwf_bdsav_model
1155
1156 !> @brief Output
1157 !!
1158 !! Write output
1159 !<
1160 subroutine gwf_gwf_ot(this)
1161 ! -- modules
1162 use simvariablesmodule, only: iout
1163 use constantsmodule, only: dzero
1164 ! -- dummy
1165 class(gwfexchangetype) :: this !< GwfExchangeType
1166 ! -- local
1167 integer(I4B) :: iexg, n1, n2
1168 integer(I4B) :: ibudfl
1169 real(DP) :: flow, deltaqgnc
1170 character(len=LINELENGTH) :: node1str, node2str
1171 ! -- format
1172 character(len=*), parameter :: fmtheader = &
1173 "(/1x, 'SUMMARY OF EXCHANGE RATES FOR EXCHANGE ', a, ' WITH ID ', i0, /, &
1174 &2a16, 5a16, /, 112('-'))"
1175 character(len=*), parameter :: fmtheader2 = &
1176 "(/1x, 'SUMMARY OF EXCHANGE RATES FOR EXCHANGE ', a, ' WITH ID ', i0, /, &
1177 &2a16, 4a16, /, 96('-'))"
1178 character(len=*), parameter :: fmtdata = &
1179 "(2a16, 5(1pg16.6))"
1180 !
1181 ! -- Call bdsave
1182 call this%gwf_gwf_bdsav()
1183 !
1184 ! -- Initialize
1185 deltaqgnc = dzero
1186 !
1187 ! -- Write a table of exchanges
1188 if (this%iprflow /= 0) then
1189 if (this%ingnc > 0) then
1190 write (iout, fmtheader) trim(adjustl(this%name)), this%id, 'NODEM1', &
1191 'NODEM2', 'COND', 'X_M1', 'X_M2', 'DELTAQGNC', &
1192 'FLOW'
1193 else
1194 write (iout, fmtheader2) trim(adjustl(this%name)), this%id, 'NODEM1', &
1195 'NODEM2', 'COND', 'X_M1', 'X_M2', 'FLOW'
1196 end if
1197 do iexg = 1, this%nexg
1198 n1 = this%nodem1(iexg)
1199 n2 = this%nodem2(iexg)
1200 flow = this%simvals(iexg)
1201 call this%v_model1%dis_noder_to_string(n1, node1str)
1202 call this%v_model2%dis_noder_to_string(n2, node2str)
1203
1204 if (this%ingnc > 0) then
1205 deltaqgnc = this%gnc%deltaqgnc(iexg)
1206 write (iout, fmtdata) trim(adjustl(node1str)), &
1207 trim(adjustl(node2str)), &
1208 this%cond(iexg), this%v_model1%x%get(n1), &
1209 this%v_model2%x%get(n2), deltaqgnc, flow
1210 else
1211 write (iout, fmtdata) trim(adjustl(node1str)), &
1212 trim(adjustl(node2str)), &
1213 this%cond(iexg), this%v_model1%x%get(n1), &
1214 this%v_model2%x%get(n2), flow
1215 end if
1216 end do
1217 end if
1218 !
1219 ! -- Mover budget output
1220 ibudfl = 1
1221 if (this%inmvr > 0) call this%mvr%mvr_ot_bdsummary(ibudfl)
1222 !
1223 ! -- OBS output
1224 call this%obs%obs_ot()
1225 end subroutine gwf_gwf_ot
1226
1227 !> @brief Source options
1228 !!
1229 !! Source the options block
1230 !<
1231 subroutine source_options(this, iout)
1232 ! -- modules
1233 use constantsmodule, only: lenvarname, dem6
1239 ! -- dummy
1240 class(gwfexchangetype) :: this !< GwfExchangeType
1241 integer(I4B), intent(in) :: iout
1242 ! -- local
1243 type(exggwfgwfparamfoundtype) :: found
1244 character(len=LENVARNAME), dimension(3) :: cellavg_method = &
1245 &[character(len=LENVARNAME) :: 'HARMONIC', 'LOGARITHMIC', 'AMT-LMK']
1246 character(len=linelength) :: gnc_fname, mvr_fname
1247 !
1248 ! -- update defaults with idm sourced values
1249 call mem_set_value(this%icellavg, 'CELL_AVERAGING', this%input_mempath, &
1250 cellavg_method, found%cell_averaging)
1251 call mem_set_value(this%inewton, 'NEWTON', this%input_mempath, found%newton)
1252 call mem_set_value(this%ixt3d, 'XT3D', this%input_mempath, found%xt3d)
1253 call mem_set_value(this%ivarcv, 'VARIABLECV', this%input_mempath, &
1254 found%variablecv)
1255 call mem_set_value(this%idewatcv, 'DEWATERED', this%input_mempath, &
1256 found%dewatered)
1257 !
1258 write (iout, '(1x,a)') 'PROCESSING GWF-GWF EXCHANGE OPTIONS'
1259 !
1260 ! -- source base class options
1261 call this%DisConnExchangeType%source_options(iout)
1262 !
1263 if (found%cell_averaging) then
1264 if (this%icellavg == 0) then
1265 call store_error('Unrecognized input value for CELL_AVERAGING option.')
1266 call store_error_filename(this%filename)
1267 else
1268 ! -- count from 0
1269 this%icellavg = this%icellavg - 1
1270 write (iout, '(4x,a,a)') &
1271 'CELL AVERAGING METHOD HAS BEEN SET TO: ', &
1272 trim(cellavg_method(this%icellavg + 1))
1273 end if
1274 end if
1275 !
1276 if (found%newton) then
1277 write (iout, '(4x,a)') &
1278 'NEWTON-RAPHSON method used for unconfined cells'
1279 end if
1280 !
1281 if (found%xt3d) then
1282 write (iout, '(4x,a)') 'XT3D WILL BE APPLIED ON THE INTERFACE'
1283 end if
1284 !
1285 if (found%variablecv) then
1286 write (iout, '(4x,a)') &
1287 'VERTICAL CONDUCTANCE VARIES WITH WATER TABLE.'
1288 end if
1289 !
1290 if (found%dewatered) then
1291 write (iout, '(4x,a)') &
1292 'VERTICAL CONDUCTANCE ACCOUNTS FOR DEWATERED PORTION OF '// &
1293 'AN UNDERLYING CELL.'
1294 end if
1295 !
1296 ! -- enforce 0 or 1 GNC6_FILENAME entries in option block
1297 if (filein_fname(gnc_fname, 'GNC6_FILENAME', this%input_mempath, &
1298 this%filename)) then
1299 this%ingnc = getunit()
1300 call openfile(this%ingnc, iout, gnc_fname, 'GNC')
1301 write (iout, '(4x,a)') &
1302 'GHOST NODES WILL BE READ FROM ', trim(gnc_fname)
1303 end if
1304 !
1305 ! -- enforce 0 or 1 MVR6_FILENAME entries in option block
1306 if (filein_fname(mvr_fname, 'MVR6_FILENAME', this%input_mempath, &
1307 this%filename)) then
1308 this%inmvr = getunit()
1309 call openfile(this%inmvr, iout, mvr_fname, 'MVR')
1310 write (iout, '(4x,a)') &
1311 'WATER MOVER INFORMATION WILL BE READ FROM ', trim(mvr_fname)
1312 end if
1313 !
1314 ! -- enforce 0 or 1 OBS6_FILENAME entries in option block
1315 if (.not. this%is_datacopy) then
1316 if (filein_fname(this%obs%inputFilename, 'OBS6_FILENAME', &
1317 this%input_mempath, this%filename)) then
1318 this%obs%active = .true.
1319 this%obs%inUnitObs = getunit()
1320 call openfile(this%obs%inUnitObs, iout, this%obs%inputFilename, 'OBS')
1321 end if
1322 end if
1323 !
1324 write (iout, '(1x,a)') 'END OF GWF-GWF EXCHANGE OPTIONS'
1325 !
1326 ! -- set omega value used for saturation calculations
1327 if (this%inewton > 0) then
1328 this%satomega = dem6
1329 end if
1330 end subroutine source_options
1331
1332 !> @brief Read ghost nodes
1333 !!
1334 !! Read and process ghost nodes
1335 !<
1336 subroutine read_gnc(this)
1337 ! -- modules
1338 use constantsmodule, only: linelength
1339 ! -- dummy
1340 class(gwfexchangetype) :: this !< GwfExchangeType
1341 ! -- local
1342 integer(I4B) :: i, nm1, nm2, nmgnc1, nmgnc2
1343 character(len=*), parameter :: fmterr = &
1344 "('EXCHANGE NODES ', i0, ' AND ', i0,"// &
1345 "' NOT CONSISTENT WITH GNC NODES ', "// &
1346 "i0, ' AND ', i0)"
1347 !
1348 ! -- If exchange has ghost nodes, then initialize ghost node object
1349 ! This will read the ghost node blocks from the gnc input file.
1350 call this%gnc%gnc_df(this%gwfmodel1, m2=this%gwfmodel2)
1351 !
1352 ! -- Verify gnc is implicit if exchange has Newton Terms
1353 if (.not. this%gnc%implicit .and. this%inewton /= 0) then
1354 call store_error('GNC is explicit, but GWF exchange has active newton.')
1355 call store_error('Add implicit option to GNC or remove NEWTON from '// &
1356 'GWF exchange.')
1357 call store_error_unit(this%ingnc)
1358 end if
1359 !
1360 ! -- Perform checks to ensure GNCs match with GWF-GWF nodes
1361 if (this%nexg /= this%gnc%nexg) then
1362 call store_error('Number of exchanges does not match number of GNCs')
1363 call store_error_unit(this%ingnc)
1364 end if
1365 !
1366 ! -- Go through each entry and confirm
1367 do i = 1, this%nexg
1368 if (this%nodem1(i) /= this%gnc%nodem1(i) .or. &
1369 this%nodem2(i) /= this%gnc%nodem2(i)) then
1370 nm1 = this%gwfmodel1%dis%get_nodeuser(this%nodem1(i))
1371 nm2 = this%gwfmodel2%dis%get_nodeuser(this%nodem2(i))
1372 nmgnc1 = this%gwfmodel1%dis%get_nodeuser(this%gnc%nodem1(i))
1373 nmgnc2 = this%gwfmodel2%dis%get_nodeuser(this%gnc%nodem2(i))
1374 write (errmsg, fmterr) nm1, nm2, nmgnc1, nmgnc2
1375 call store_error(errmsg)
1376 end if
1377 end do
1378 if (count_errors() > 0) then
1379 call store_error_unit(this%ingnc)
1380 end if
1381 !
1382 ! -- close the file
1383 close (this%ingnc)
1384 end subroutine read_gnc
1385
1386 !> @brief Read mover
1387 !!
1388 !! Read and process movers
1389 !<
1390 subroutine read_mvr(this, iout)
1391 ! -- modules
1392 use gwfexgmovermodule, only: exg_mvr_cr
1393 ! -- dummy
1394 class(gwfexchangetype) :: this !< GwfExchangeType
1395 integer(I4B), intent(in) :: iout
1396 class(disbasetype), pointer :: dis
1397 ! -- local
1398 !
1399 ! -- Create and initialize the mover object Here, dis is set to the one
1400 ! for gwfmodel1 so that a call to save flows has an associated dis
1401 ! object. Because the conversion flags for the mover are both false,
1402 ! the dis object does not convert from reduced to user node numbers.
1403 ! So in this case, the dis object is just writing unconverted package
1404 ! numbers to the binary budget file.
1405 dis => null()
1406 if (this%v_model1%is_local) then
1407 dis => this%gwfmodel1%dis
1408 else if (this%v_model2%is_local) then
1409 dis => this%gwfmodel2%dis
1410 end if
1411 call exg_mvr_cr(this%mvr, this%name, this%inmvr, iout, dis)
1412 this%mvr%model1 => this%v_model1
1413 this%mvr%model2 => this%v_model2
1414 this%mvr%suppress_fileout = this%is_datacopy
1415 end subroutine read_mvr
1416
1417 !> @brief Rewet
1418 !!
1419 !! Check if rewetting should propagate from one model to another
1420 !<
1421 subroutine rewet(this, kiter)
1422 ! -- modules
1423 use tdismodule, only: kper, kstp
1424 ! -- dummy
1425 class(gwfexchangetype) :: this !< GwfExchangeType
1426 integer(I4B), intent(in) :: kiter
1427 ! -- local
1428 integer(I4B) :: iexg
1429 integer(I4B) :: n, m
1430 integer(I4B) :: ibdn, ibdm
1431 integer(I4B) :: ihc
1432 real(DP) :: hn, hm
1433 integer(I4B) :: irewet
1434 character(len=30) :: nodestrn, nodestrm
1435 character(len=*), parameter :: fmtrwt = &
1436 "(1x, 'CELL ',A,' REWET FROM GWF MODEL ',A,' CELL ',A, &
1437 &' FOR ITER. ',I0, ' STEP ',I0, ' PERIOD ', I0)"
1438 !
1439 ! -- Use model 1 to rewet model 2 and vice versa
1440 do iexg = 1, this%nexg
1441 n = this%nodem1(iexg)
1442 m = this%nodem2(iexg)
1443 hn = this%gwfmodel1%x(n)
1444 hm = this%gwfmodel2%x(m)
1445 ibdn = this%gwfmodel1%ibound(n)
1446 ibdm = this%gwfmodel2%ibound(m)
1447 ihc = this%ihc(iexg)
1448 call this%gwfmodel1%npf%rewet_check(kiter, n, hm, ibdm, ihc, &
1449 this%gwfmodel1%x, irewet)
1450 if (irewet == 1) then
1451 call this%gwfmodel1%dis%noder_to_string(n, nodestrn)
1452 call this%gwfmodel2%dis%noder_to_string(m, nodestrm)
1453 write (this%gwfmodel1%iout, fmtrwt) trim(nodestrn), &
1454 trim(this%gwfmodel2%name), trim(nodestrm), kiter, kstp, kper
1455 end if
1456 call this%gwfmodel2%npf%rewet_check(kiter, m, hn, ibdn, ihc, &
1457 this%gwfmodel2%x, irewet)
1458 if (irewet == 1) then
1459 call this%gwfmodel1%dis%noder_to_string(n, nodestrm)
1460 call this%gwfmodel2%dis%noder_to_string(m, nodestrn)
1461 write (this%gwfmodel2%iout, fmtrwt) trim(nodestrn), &
1462 trim(this%gwfmodel1%name), trim(nodestrm), kiter, kstp, kper
1463 end if
1464 !
1465 end do
1466 end subroutine rewet
1467
1468 subroutine calc_cond_sat(this)
1469 ! -- modules
1472 ! -- dummy
1473 class(gwfexchangetype) :: this !< GwfExchangeType
1474 ! -- local
1475 integer(I4B) :: iexg
1476 integer(I4B) :: n, m, ihc
1477 real(DP) :: topn, topm
1478 real(DP) :: botn, botm
1479 real(DP) :: satn, satm
1480 real(DP) :: thickn, thickm
1481 real(DP) :: hyn, hym
1482 real(DP) :: csat
1483 real(DP) :: fawidth
1484 real(DP), dimension(3) :: vg
1485 !
1486 do iexg = 1, this%nexg
1487 !
1488 ihc = this%ihc(iexg)
1489 n = this%nodem1(iexg)
1490 m = this%nodem2(iexg)
1491 topn = this%gwfmodel1%dis%top(n)
1492 topm = this%gwfmodel2%dis%top(m)
1493 botn = this%gwfmodel1%dis%bot(n)
1494 botm = this%gwfmodel2%dis%bot(m)
1495 satn = this%gwfmodel1%npf%sat(n)
1496 satm = this%gwfmodel2%npf%sat(m)
1497 thickn = (topn - botn) * satn
1498 thickm = (topm - botm) * satm
1499 !
1500 ! -- Calculate conductance depending on connection orientation
1501 if (ihc == 0) then
1502 !
1503 ! -- Vertical conductance for fully saturated conditions
1504 vg(1) = dzero
1505 vg(2) = dzero
1506 vg(3) = done
1507 hyn = this%gwfmodel1%npf%hy_eff(n, 0, ihc, vg=vg)
1508 hym = this%gwfmodel2%npf%hy_eff(m, 0, ihc, vg=vg)
1509 csat = vcond(1, 1, 1, 1, 0, 1, 1, done, &
1510 botn, botm, &
1511 hyn, hym, &
1512 satn, satm, &
1513 topn, topm, &
1514 botn, botm, &
1515 this%hwva(iexg))
1516 else
1517 !
1518 ! -- Calculate horizontal conductance
1519 call this%calc_hy_horizontal(iexg, hyn, hym)
1520 !
1521 fawidth = this%hwva(iexg)
1522 csat = hcond(1, 1, 1, 1, 0, ihc, &
1523 this%icellavg, done, &
1524 topn, topm, satn, satm, hyn, hym, &
1525 topn, topm, &
1526 botn, botm, &
1527 this%cl1(iexg), this%cl2(iexg), &
1528 fawidth)
1529 end if
1530 !
1531 ! -- store csat in condsat
1532 this%condsat(iexg) = csat
1533 end do
1534 end subroutine calc_cond_sat
1535
1536 !> @brief Calculate the conductance
1537 !!
1538 !! Calculate the conductance based on state
1539 !<
1540 subroutine condcalc(this)
1541 ! -- modules
1542 use constantsmodule, only: dhalf, dzero, done
1544 ! -- dummy
1545 class(gwfexchangetype) :: this !< GwfExchangeType
1546 ! -- local
1547 integer(I4B) :: iexg
1548 integer(I4B) :: n, m, ihc
1549 integer(I4B) :: ibdn, ibdm
1550 integer(I4B) :: ictn, ictm
1551 real(DP) :: topn, topm
1552 real(DP) :: botn, botm
1553 real(DP) :: satn, satm
1554 real(DP) :: hyn, hym
1555 real(DP) :: hn, hm
1556 real(DP) :: cond
1557 real(DP) :: fawidth
1558 real(DP), dimension(3) :: vg
1559 !
1560 ! -- Calculate conductance and put into amat
1561 do iexg = 1, this%nexg
1562 ihc = this%ihc(iexg)
1563 n = this%nodem1(iexg)
1564 m = this%nodem2(iexg)
1565 ibdn = this%gwfmodel1%ibound(n)
1566 ibdm = this%gwfmodel2%ibound(m)
1567 ictn = this%gwfmodel1%npf%icelltype(n)
1568 ictm = this%gwfmodel2%npf%icelltype(m)
1569 topn = this%gwfmodel1%dis%top(n)
1570 topm = this%gwfmodel2%dis%top(m)
1571 botn = this%gwfmodel1%dis%bot(n)
1572 botm = this%gwfmodel2%dis%bot(m)
1573 satn = this%gwfmodel1%npf%sat(n)
1574 satm = this%gwfmodel2%npf%sat(m)
1575 hn = this%gwfmodel1%x(n)
1576 hm = this%gwfmodel2%x(m)
1577 !
1578 ! -- Calculate conductance depending on connection orientation
1579 if (ihc == 0) then
1580 !
1581 ! -- Vertical connection
1582 vg(1) = dzero
1583 vg(2) = dzero
1584 vg(3) = done
1585 hyn = this%gwfmodel1%npf%hy_eff(n, 0, ihc, vg=vg)
1586 hym = this%gwfmodel2%npf%hy_eff(m, 0, ihc, vg=vg)
1587 cond = vcond(ibdn, ibdm, ictn, ictm, this%inewton, this%ivarcv, &
1588 this%idewatcv, this%condsat(iexg), hn, hm, hyn, hym, &
1589 satn, satm, topn, topm, botn, botm, this%hwva(iexg))
1590 else
1591 !
1592 ! -- Horizontal Connection
1593 call this%calc_hy_horizontal(iexg, hyn, hym)
1594 !
1595 fawidth = this%hwva(iexg)
1596 cond = hcond(ibdn, ibdm, ictn, ictm, this%inewton, &
1597 this%ihc(iexg), this%icellavg, this%condsat(iexg), &
1598 hn, hm, satn, satm, hyn, hym, topn, topm, botn, botm, &
1599 this%cl1(iexg), this%cl2(iexg), fawidth)
1600 end if
1601 !
1602 this%cond(iexg) = cond
1603 !
1604 end do
1605 end subroutine condcalc
1606
1607 !> @brief Calculate horizontal hydraulic conductivity for an exchange
1608 !!
1609 !! Use K11, or the effective K in the direction of ANGLDEGX
1610 !! for a model with K22.
1611 !<
1612 subroutine calc_hy_horizontal(this, iexg, hyn, hym)
1613 use constantsmodule, only: dzero, dpio180
1614 ! -- dummy
1615 class(gwfexchangetype) :: this !< GwfExchangeType
1616 integer(I4B), intent(in) :: iexg !< exchange index
1617 real(DP), intent(out) :: hyn !< K for the model 1 cell
1618 real(DP), intent(out) :: hym !< K for the model 2 cell
1619 ! -- local
1620 integer(I4B) :: n, m
1621 real(DP) :: angle
1622 real(DP), dimension(3) :: vg
1623 !
1624 n = this%nodem1(iexg)
1625 m = this%nodem2(iexg)
1626 hyn = this%gwfmodel1%npf%k11(n)
1627 hym = this%gwfmodel2%npf%k11(m)
1628 if (this%ianglex == 0) return
1629 angle = this%auxvar(this%ianglex, iexg) * dpio180
1630 vg(1) = abs(cos(angle))
1631 vg(2) = abs(sin(angle))
1632 vg(3) = dzero
1633 if (this%gwfmodel1%npf%ik22 /= 0) then
1634 hyn = this%gwfmodel1%npf%hy_eff(n, 0, 1, vg=vg)
1635 end if
1636 if (this%gwfmodel2%npf%ik22 /= 0) then
1637 hym = this%gwfmodel2%npf%hy_eff(m, 0, 1, vg=vg)
1638 end if
1639 end subroutine calc_hy_horizontal
1640
1641 !> @brief Allocate scalars
1642 !!
1643 !! Allocate scalar variables
1644 !<
1645 subroutine allocate_scalars(this)
1646 ! -- modules
1648 use constantsmodule, only: dzero
1649 ! -- dummy
1650 class(gwfexchangetype) :: this !< GwfExchangeType
1651 !
1652 call this%DisConnExchangeType%allocate_scalars()
1653 !
1654 call mem_allocate(this%icellavg, 'ICELLAVG', this%memoryPath)
1655 call mem_allocate(this%ivarcv, 'IVARCV', this%memoryPath)
1656 call mem_allocate(this%idewatcv, 'IDEWATCV', this%memoryPath)
1657 call mem_allocate(this%inewton, 'INEWTON', this%memoryPath)
1658 call mem_allocate(this%ingnc, 'INGNC', this%memoryPath)
1659 call mem_allocate(this%inmvr, 'INMVR', this%memoryPath)
1660 call mem_allocate(this%inobs, 'INOBS', this%memoryPath)
1661 call mem_allocate(this%satomega, 'SATOMEGA', this%memoryPath)
1662 this%icellavg = 0
1663 this%ivarcv = 0
1664 this%idewatcv = 0
1665 this%inewton = 0
1666 this%ingnc = 0
1667 this%inmvr = 0
1668 this%inobs = 0
1669 this%satomega = dzero
1670 end subroutine allocate_scalars
1671
1672 !> @brief Deallocate
1673 !!
1674 !! Deallocate memory associated with this object
1675 !<
1676 subroutine gwf_gwf_da(this)
1677 ! -- modules
1679 ! -- dummy
1680 class(gwfexchangetype) :: this !< GwfExchangeType
1681 !
1682 ! -- objects
1683 if (this%ingnc > 0) then
1684 call this%gnc%gnc_da()
1685 deallocate (this%gnc)
1686 end if
1687 if (this%inmvr > 0) then
1688 call this%mvr%mvr_da()
1689 deallocate (this%mvr)
1690 end if
1691 call this%obs%obs_da()
1692 deallocate (this%obs)
1693 !
1694 ! -- arrays
1695 call mem_deallocate(this%cond)
1696 call mem_deallocate(this%condsat)
1697 call mem_deallocate(this%idxglo)
1698 call mem_deallocate(this%idxsymglo)
1699 call mem_deallocate(this%simvals, 'SIMVALS', this%memoryPath)
1700 !
1701 ! -- output table objects
1702 if (associated(this%outputtab1)) then
1703 call this%outputtab1%table_da()
1704 deallocate (this%outputtab1)
1705 nullify (this%outputtab1)
1706 end if
1707 if (associated(this%outputtab2)) then
1708 call this%outputtab2%table_da()
1709 deallocate (this%outputtab2)
1710 nullify (this%outputtab2)
1711 end if
1712 !
1713 ! -- scalars
1714 deallocate (this%filename)
1715 !
1716 call mem_deallocate(this%icellavg)
1717 call mem_deallocate(this%ivarcv)
1718 call mem_deallocate(this%idewatcv)
1719 call mem_deallocate(this%inewton)
1720 call mem_deallocate(this%ingnc)
1721 call mem_deallocate(this%inmvr)
1722 call mem_deallocate(this%inobs)
1723 call mem_deallocate(this%satomega)
1724 !
1725 ! -- deallocate base
1726 call this%DisConnExchangeType%disconnex_da()
1727 end subroutine gwf_gwf_da
1728
1729 !> @brief Allocate arrays
1730 !!
1731 !! Allocate arrays
1732 !<
1733 subroutine allocate_arrays(this)
1734 ! -- modules
1736 ! -- dummy
1737 class(gwfexchangetype) :: this !< GwfExchangeType
1738 ! -- local
1739 character(len=LINELENGTH) :: text
1740 integer(I4B) :: ntabcol, i
1741 !
1742 call this%DisConnExchangeType%allocate_arrays()
1743 !
1744 call mem_allocate(this%cond, this%nexg, 'COND', this%memoryPath)
1745 call mem_allocate(this%idxglo, this%nexg, 'IDXGLO', this%memoryPath)
1746 call mem_allocate(this%idxsymglo, this%nexg, 'IDXSYMGLO', this%memoryPath) !
1747 call mem_allocate(this%condsat, this%nexg, 'CONDSAT', this%memoryPath)
1748 call mem_allocate(this%simvals, this%nexg, 'SIMVALS', this%memoryPath)
1749 !
1750 ! -- Initialize
1751 do i = 1, this%nexg
1752 this%cond(i) = dnodata
1753 end do
1754 !
1755 ! -- allocate and initialize the output table
1756 if (this%iprflow /= 0) then
1757 !
1758 ! -- dimension table
1759 ntabcol = 3
1760 if (this%inamedbound > 0) then
1761 ntabcol = ntabcol + 1
1762 end if
1763 !
1764 ! -- initialize the output table objects
1765 ! outouttab1
1766 if (this%v_model1%is_local) then
1767 call table_cr(this%outputtab1, this%name, ' ')
1768 call this%outputtab1%table_df(this%nexg, ntabcol, this%gwfmodel1%iout, &
1769 transient=.true.)
1770 text = 'NUMBER'
1771 call this%outputtab1%initialize_column(text, 10, alignment=tabcenter)
1772 text = 'CELLID'
1773 call this%outputtab1%initialize_column(text, 20, alignment=tableft)
1774 text = 'RATE'
1775 call this%outputtab1%initialize_column(text, 15, alignment=tabcenter)
1776 if (this%inamedbound > 0) then
1777 text = 'NAME'
1778 call this%outputtab1%initialize_column(text, 20, alignment=tableft)
1779 end if
1780 end if
1781 ! outouttab2
1782 if (this%v_model2%is_local) then
1783 call table_cr(this%outputtab2, this%name, ' ')
1784 call this%outputtab2%table_df(this%nexg, ntabcol, this%gwfmodel2%iout, &
1785 transient=.true.)
1786 text = 'NUMBER'
1787 call this%outputtab2%initialize_column(text, 10, alignment=tabcenter)
1788 text = 'CELLID'
1789 call this%outputtab2%initialize_column(text, 20, alignment=tableft)
1790 text = 'RATE'
1791 call this%outputtab2%initialize_column(text, 15, alignment=tabcenter)
1792 if (this%inamedbound > 0) then
1793 text = 'NAME'
1794 call this%outputtab2%initialize_column(text, 20, alignment=tableft)
1795 end if
1796 end if
1797 end if
1798 end subroutine allocate_arrays
1799
1800 !> @brief Define observations
1801 !!
1802 !! Define the observations associated with this object
1803 !<
1804 subroutine gwf_gwf_df_obs(this)
1805 ! -- dummy
1806 class(gwfexchangetype) :: this !< GwfExchangeType
1807 ! -- local
1808 integer(I4B) :: indx
1809 !
1810 ! -- Store obs type and assign procedure pointer
1811 ! for gwf-gwf observation type.
1812 call this%obs%StoreObsType('flow-ja-face', .true., indx)
1813 this%obs%obsData(indx)%ProcessIdPtr => gwf_gwf_process_obsid
1814 end subroutine gwf_gwf_df_obs
1815
1816 !> @brief Read and prepare observations
1817 !!
1818 !! Handle observation exchanges exchange-boundary names.
1819 !<
1820 subroutine gwf_gwf_rp_obs(this)
1821 ! -- modules
1822 use constantsmodule, only: dzero
1823 ! -- dummy
1824 class(gwfexchangetype) :: this !< GwfExchangeType
1825 ! -- local
1826 integer(I4B) :: i
1827 integer(I4B) :: j
1828 class(observetype), pointer :: obsrv => null()
1829 character(len=LENBOUNDNAME) :: bname
1830 logical :: jfound
1831 ! -- formats
183210 format('Exchange "', a, '" for observation "', a, &
1833 '" is invalid in package "', a, '"')
183420 format('Exchange id "', i0, '" for observation "', a, &
1835 '" is invalid in package "', a, '"')
1836 !
1837 do i = 1, this%obs%npakobs
1838 obsrv => this%obs%pakobs(i)%obsrv
1839 !
1840 ! -- indxbnds needs to be reset each stress period because
1841 ! list of boundaries can change each stress period.
1842 ! -- Not true for exchanges, but leave this in for now anyway.
1843 call obsrv%ResetObsIndex()
1844 obsrv%BndFound = .false.
1845 !
1846 bname = obsrv%FeatureName
1847 if (bname /= '') then
1848 ! -- Observation location(s) is(are) based on a boundary name.
1849 ! Iterate through all boundaries to identify and store
1850 ! corresponding index(indices) in bound array.
1851 jfound = .false.
1852 if (this%inamedbound /= 0) then
1853 do j = 1, this%nexg
1854 if (this%boundname(j) == bname) then
1855 jfound = .true.
1856 obsrv%BndFound = .true.
1857 obsrv%CurrentTimeStepEndValue = dzero
1858 call obsrv%AddObsIndex(j)
1859 end if
1860 end do
1861 end if
1862 if (.not. jfound) then
1863 write (errmsg, 10) trim(bname), trim(obsrv%ObsTypeId), trim(this%name)
1864 call store_error(errmsg)
1865 end if
1866 else
1867 ! -- Observation location is a single exchange number
1868 if (obsrv%intPak1 <= this%nexg .and. obsrv%intPak1 > 0) then
1869 jfound = .true.
1870 obsrv%BndFound = .true.
1871 obsrv%CurrentTimeStepEndValue = dzero
1872 call obsrv%AddObsIndex(obsrv%intPak1)
1873 else
1874 jfound = .false.
1875 end if
1876 if (.not. jfound) then
1877 write (errmsg, 20) obsrv%intPak1, trim(obsrv%ObsTypeId), trim(this%name)
1878 call store_error(errmsg)
1879 end if
1880 end if
1881 end do
1882 !
1883 ! -- write summary of error messages
1884 if (count_errors() > 0) then
1885 call store_error_filename(this%obs%inputFilename)
1886 end if
1887 end subroutine gwf_gwf_rp_obs
1888
1889 !> @brief Final processing
1890 !!
1891 !! Conduct any final processing
1892 !<
1893 subroutine gwf_gwf_fp(this)
1894 ! -- dummy
1895 class(gwfexchangetype) :: this !< GwfExchangeType
1896 end subroutine gwf_gwf_fp
1897
1898 !> @brief Calculate flow
1899 !!
1900 !! Calculate the flow for the specified exchange and node numbers
1901 !<
1902 function qcalc(this, iexg, n1, n2)
1903 ! -- return
1904 real(dp) :: qcalc
1905 ! -- dummy
1906 class(gwfexchangetype) :: this !< GwfExchangeType
1907 integer(I4B), intent(in) :: iexg
1908 integer(I4B), intent(in) :: n1
1909 integer(I4B), intent(in) :: n2
1910 ! -- local
1911 !
1912 ! -- Calculate flow between nodes in the two models
1913 qcalc = this%cond(iexg) * (this%gwfmodel2%x(n2) - this%gwfmodel1%x(n1))
1914 end function qcalc
1915
1916 !> @brief Set symmetric flag
1917 !!
1918 !! Return flag indicating whether or not this exchange will cause the
1919 !! coefficient matrix to be asymmetric.
1920 !<
1921 function gwf_gwf_get_iasym(this) result(iasym)
1922 ! -- dummy
1923 class(gwfexchangetype) :: this !< GwfExchangeType
1924 ! -- local
1925 integer(I4B) :: iasym
1926 !
1927 ! -- Start by setting iasym to zero
1928 iasym = 0
1929 !
1930 ! -- Groundwater flow
1931 if (this%inewton /= 0) iasym = 1
1932 !
1933 ! -- GNC
1934 if (this%ingnc > 0) then
1935 if (this%gnc%iasym /= 0) iasym = 1
1936 end if
1937 end function gwf_gwf_get_iasym
1938
1939 !> @brief Return true when this exchange provides matrix
1940 !! coefficients for solving @p model
1941 !<
1942 function gwf_gwf_connects_model(this, model) result(is_connected)
1943 ! -- dummy
1944 class(gwfexchangetype) :: this !< GwfExchangeType
1945 class(basemodeltype), pointer, intent(in) :: model !< the model to which the exchange might hold a connection
1946 ! -- return
1947 logical(LGP) :: is_connected !< true, when connected
1948 !
1949 is_connected = .false.
1950 !
1951 ! only connected when model is GwfModelType of course
1952 select type (model)
1953 class is (gwfmodeltype)
1954 if (associated(this%gwfmodel1, model)) then
1955 is_connected = .true.
1956 else if (associated(this%gwfmodel2, model)) then
1957 is_connected = .true.
1958 end if
1959 end select
1960 end function gwf_gwf_connects_model
1961
1962 !> @brief Should interface model be used for this exchange
1963 !<
1964 function use_interface_model(this) result(use_im)
1966 ! -- dummy
1967 class(gwfexchangetype) :: this !< GwfExchangeType
1968 ! -- return
1969 logical(LGP) :: use_im !< true when interface model should be used
1970 ! -- local
1971 integer(I4B) :: inbuy_m1
1972
1973 use_im = this%DisConnExchangeType%use_interface_model()
1974 use_im = use_im .or. (this%ixt3d > 0)
1975
1976 inbuy_m1 = 0
1977 select type (m => this%v_model1)
1978 class is (virtualgwfmodeltype)
1979 inbuy_m1 = m%inbuy%get()
1980 end select
1981 use_im = use_im .or. (inbuy_m1 > 0)
1982 end function
1983
1984 !> @brief Save simulated flow observations
1985 !!
1986 !! Save the simulated flows for each exchange
1987 !<
1988 subroutine gwf_gwf_save_simvals(this)
1989 ! -- modules
1990 use simvariablesmodule, only: errmsg
1991 use constantsmodule, only: dzero
1992 use observemodule, only: observetype
1993 ! -- dummy
1994 class(gwfexchangetype), intent(inout) :: this
1995 ! -- local
1996 integer(I4B) :: i
1997 integer(I4B) :: j
1998 integer(I4B) :: n1
1999 integer(I4B) :: n2
2000 integer(I4B) :: iexg
2001 real(DP) :: v
2002 type(observetype), pointer :: obsrv => null()
2003 !
2004 ! -- Write simulated values for all gwf-gwf observations
2005 if (this%obs%npakobs > 0) then
2006 call this%obs%obs_bd_clear()
2007 do i = 1, this%obs%npakobs
2008 obsrv => this%obs%pakobs(i)%obsrv
2009 do j = 1, obsrv%indxbnds_count
2010 iexg = obsrv%indxbnds(j)
2011 v = dzero
2012 select case (obsrv%ObsTypeId)
2013 case ('FLOW-JA-FACE')
2014 n1 = this%nodem1(iexg)
2015 n2 = this%nodem2(iexg)
2016 v = this%simvals(iexg)
2017 case default
2018 errmsg = 'Unrecognized observation type: '// &
2019 trim(obsrv%ObsTypeId)
2020 call store_error(errmsg)
2021 call store_error_filename(this%obs%inputFilename)
2022 end select
2023 call this%obs%SaveOneSimval(obsrv, v)
2024 end do
2025 end do
2026 end if
2027 end subroutine gwf_gwf_save_simvals
2028
2029 !> @brief Obs ID processor
2030 !!
2031 !! Process observations for this exchange
2032 !<
2033 subroutine gwf_gwf_process_obsid(obsrv, dis, inunitobs, iout)
2034 ! -- modules
2035 use constantsmodule, only: linelength
2036 use inputoutputmodule, only: urword
2037 use observemodule, only: observetype
2038 use basedismodule, only: disbasetype
2039 ! -- dummy
2040 type(observetype), intent(inout) :: obsrv
2041 class(disbasetype), intent(in) :: dis
2042 integer(I4B), intent(in) :: inunitobs
2043 integer(I4B), intent(in) :: iout
2044 ! -- local
2045 integer(I4B) :: n, iexg, istat
2046 integer(I4B) :: icol, istart, istop
2047 real(DP) :: r
2048 character(len=LINELENGTH) :: string
2049 !
2050 string = obsrv%IDstring
2051 icol = 1
2052 ! -- get exchange index
2053 call urword(string, icol, istart, istop, 1, n, r, iout, inunitobs)
2054 read (string(istart:istop), '(i10)', iostat=istat) iexg
2055 if (istat == 0) then
2056 obsrv%intPak1 = iexg
2057 else
2058 ! Integer can't be read from string; it's presumed to be an exchange
2059 ! boundary name (already converted to uppercase)
2060 obsrv%FeatureName = trim(adjustl(string))
2061 ! -- Observation may require summing rates from multiple exchange
2062 ! boundaries, so assign intPak1 as a value that indicates observation
2063 ! is for a named exchange boundary or group of exchange boundaries.
2064 obsrv%intPak1 = namedboundflag
2065 end if
2066 end subroutine gwf_gwf_process_obsid
2067
2068 !> @brief Cast polymorphic object as exchange
2069 !!
2070 !! Cast polymorphic object as exchange
2071 !<
2072 function castasgwfexchange(obj) result(res)
2073 implicit none
2074 ! -- dummy
2075 class(*), pointer, intent(inout) :: obj
2076 ! -- return
2077 class(gwfexchangetype), pointer :: res
2078 !
2079 res => null()
2080 if (.not. associated(obj)) return
2081 !
2082 select type (obj)
2083 class is (gwfexchangetype)
2084 res => obj
2085 end select
2086 end function castasgwfexchange
2087
2088 !> @brief Get exchange from list
2089 !!
2090 !! Return an exchange from the list for specified index
2091 !<
2092 function getgwfexchangefromlist(list, idx) result(res)
2093 implicit none
2094 ! -- dummy
2095 type(listtype), intent(inout) :: list
2096 integer(I4B), intent(in) :: idx
2097 ! -- return
2098 class(gwfexchangetype), pointer :: res
2099 ! -- local
2100 class(*), pointer :: obj
2101 !
2102 obj => list%GetItem(idx)
2103 res => castasgwfexchange(obj)
2104 end function getgwfexchangefromlist
2105
2106end module gwfgwfexchangemodule
2107
subroutine exg_fp(this)
Final processing.
subroutine exg_da(this)
Deallocate memory.
subroutine exg_rp(this)
Read and prepare.
logical(lgp) function connects_model(this, model)
Should return true when the exchange should be added to the solution where the model resides.
subroutine, public addbaseexchangetolist(list, exchange)
Add the exchange object (BaseExchangeType) to a list.
subroutine exg_ot(this)
Run output routines.
subroutine exg_ad(this)
Advance.
class(basemodeltype) function, pointer, public getbasemodelfromlist(list, idx)
This module contains the BudgetModule.
Definition Budget.f90:20
subroutine, public rate_accumulator(flow, rin, rout)
Rate accumulator subroutine.
Definition Budget.f90:634
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
@ tabcenter
centered table column
@ tableft
left justified table column
integer(i4b), parameter lenpackagename
maximum length of the package name
Definition Constants.f90:23
integer(i4b), parameter namedboundflag
named bound flag
Definition Constants.f90:49
real(dp), parameter dnodata
real no data constant
Definition Constants.f90:95
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition Constants.f90:17
real(dp), parameter dhalf
real constant 1/2
Definition Constants.f90:68
integer(i4b), parameter lenauxname
maximum length of a aux variable
Definition Constants.f90:35
integer(i4b), parameter lenboundname
maximum length of a bound name
Definition Constants.f90:36
real(dp), parameter dpio180
real constant
real(dp), parameter dem6
real constant 1e-6
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65
integer(i4b), parameter lenbudtxt
maximum length of a budget component names
Definition Constants.f90:37
real(dp), parameter done
real constant 1
Definition Constants.f90:76
logical(lgp) function use_interface_model(this)
Should interface model be used to handle these exchanges, to be overridden for inheriting types.
subroutine allocate_scalars(this)
Allocate scalars and initialize to defaults.
subroutine allocate_arrays(this)
Allocate array data, using the number of connected nodes nexg.
subroutine source_options(this, iout)
Source options from input context.
subroutine, public gnc_cr(gncobj, name_parent, inunit, iout)
Create new GNC exchange object.
Definition GhostNode.f90:61
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, 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 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.
subroutine, public exg_mvr_cr(exg_mvr, name_parent, inunit, iout, dis)
This module contains the GwfGwfExchangeModule Module.
integer(i4b) function gwf_gwf_get_iasym(this)
Set symmetric flag.
subroutine calc_hy_horizontal(this, iexg, hyn, hym)
Calculate horizontal hydraulic conductivity for an exchange.
subroutine gwf_gwf_fp(this)
Final processing.
subroutine gwf_gwf_cq(this, icnvg, isuppress_output, isolnid)
Calculate flow.
class(gwfexchangetype) function, pointer, public getgwfexchangefromlist(list, idx)
Get exchange from list.
subroutine gwf_gwf_process_obsid(obsrv, dis, inunitobs, iout)
Obs ID processor.
subroutine rewet(this, kiter)
Rewet.
subroutine gwf_gwf_add_to_flowja(this)
Add exchange flow to each model flowja diagonal position so that residual is calculated correctly.
subroutine gwf_gwf_ac(this, sparse)
Add connections.
subroutine gwf_gwf_save_simvals(this)
Save simulated flow observations.
subroutine calc_cond_sat(this)
subroutine gwf_gwf_ar(this)
Allocate and read.
subroutine gwf_gwf_bdsav(this)
Budget save.
subroutine gwf_gwf_ad(this)
Advance.
subroutine gwf_gwf_fn(this, kiter, matrix_sln)
Fill Newton.
subroutine gwf_gwf_fc(this, kiter, matrix_sln, rhs_sln, inwtflag)
Fill coefficients.
subroutine gwf_gwf_bd(this, icnvg, isuppress_output, isolnid)
Budget.
subroutine gwf_gwf_da(this)
Deallocate.
subroutine gwf_gwf_rp(this)
Read and prepare.
real(dp) function qcalc(this, iexg, n1, n2)
Calculate flow.
subroutine gwf_gwf_df(this)
Define GWF GWF exchange.
subroutine gwf_gwf_df_obs(this)
Define observations.
logical(lgp) function gwf_gwf_connects_model(this, model)
Return true when this exchange provides matrix coefficients for solving model.
subroutine gwf_gwf_set_flow_to_npf(this)
Set flow rates to the edges in the models.
subroutine gwf_gwf_ot(this)
Output.
subroutine validate_exchange(this)
validate exchange data after reading
class(gwfexchangetype) function, pointer, public castasgwfexchange(obj)
Cast polymorphic object as exchange.
subroutine gwf_gwf_rp_obs(this)
Read and prepare observations.
subroutine, public gwfexchange_create(filename, name, id, m1_id, m2_id, input_mempath)
Create GWF GWF exchange.
subroutine gwf_gwf_mc(this, matrix_sln)
Map connections.
subroutine gwf_gwf_cf(this, kiter)
Calculate coefficients.
subroutine gwf_gwf_bdsav_model(this, model)
subroutine gwf_gwf_calc_simvals(this)
Calculate flow rates for the exchanges and store them in a member array.
subroutine gwf_gwf_chd_bd(this)
gwf-gwf-chd-bd
subroutine read_mvr(this, iout)
Read mover.
subroutine condcalc(this)
Calculate the conductance.
subroutine read_gnc(this)
Read ghost nodes.
integer(i4b) function, public getunit()
Get a free unit number.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
subroutine, public urword(line, icol, istart, istop, ncode, n, r, iout, in)
Extract a word from a string.
This module defines variable data types.
Definition kind.f90:8
type(listtype), public basemodellist
Definition mf6lists.f90:16
type(listtype), public baseexchangelist
Definition mf6lists.f90:25
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
This module contains the derived types ObserveType and ObsDataType.
Definition Observe.f90:15
This module contains the derived type ObsType.
Definition Obs.f90:127
subroutine, public obs_cr(obs, inobs)
Create a new ObsType object.
Definition Obs.f90:225
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition Sim.f90:94
integer(i4b) function, public count_errors()
Return number of errors.
Definition Sim.f90:60
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition Sim.f90:208
subroutine, public store_error_unit(iunit, terminate)
Store the file unit number.
Definition Sim.f90:172
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
integer(i4b), dimension(:), allocatable model_loc_idx
equals the local index into the basemodel list (-1 when not available)
integer(i4b) iout
file unit number for simulation output
real(dp) function squadraticsaturationderivative(top, bot, x, eps)
Derivative of the quadratic saturation function.
This module contains the SourceCommonModule.
logical(lgp) function, public filein_fname(filename, tagname, input_mempath, input_fname)
enforce and set a single input filename provided via FILEIN keyword
subroutine, public table_cr(this, name, title)
Definition Table.f90:87
logical(lgp), pointer, public readnewdata
flag indicating time to read new data
Definition tdis.f90:29
integer(i4b), pointer, public kstp
current time step number
Definition tdis.f90:27
integer(i4b), pointer, public kper
current stress period number
Definition tdis.f90:26
Highest level model type. All models extend this parent type.
Definition BaseModel.f90:16
This class is used to store a single deferred-length character string. It was designed to work in an ...
Exchange based on connection between discretizations of DisBaseType. The data specifies the connectio...
Extends model mover for exchanges to also handle the.
Derived type for GwfExchangeType.
A generic heterogeneous doubly-linked list.
Definition List.f90:14