MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
exg-olfgwf.f90
Go to the documentation of this file.
1 !> @brief This module contains the OlfGwfExchangeModule Module
2 !!
3 !! This module contains a lightweight OLF-GWF exchange class which is
4 !! primarily based on the underlying and generic SWF-GWF code for connecting
5 !< a SWF model (either CHF or OLF) with a GWF model.
7 
8  use kindmodule, only: dp, i4b, lgp
16  use gwfmodule, only: gwfmodeltype
17  use swfmodule, only: swfmodeltype
18  use obsmodule, only: obs_cr
19 
20  implicit none
21  private
22  public :: olfgwf_cr
23 
25  contains
26  procedure :: exg_df => olf_gwf_df
27  procedure :: source_options
28  procedure :: source_dimensions
29  procedure :: source_data
30  end type olfgwfexchangetype
31 
32 contains
33 
34  !> @ brief Create OLF GWF exchange
35  !!
36  !! High level wrapper over the SWF-GWF exchange, which is generic in that
37  !! it can be used to couple either a CHF or OLF surface water model to a
38  !! GWF model.
39  !<
40  subroutine olfgwf_cr(filename, name, id, m1_id, m2_id, input_mempath)
41  ! modules
42  ! dummy
43  character(len=*), intent(in) :: filename !< filename for reading
44  character(len=*) :: name !< exchange name
45  integer(I4B), intent(in) :: id !< id for the exchange
46  integer(I4B), intent(in) :: m1_id !< id for model 1
47  integer(I4B), intent(in) :: m2_id !< id for model 2
48  character(len=*), intent(in) :: input_mempath
49  ! local
50  type(olfgwfexchangetype), pointer :: exchange
51  class(baseexchangetype), pointer :: baseexchange
52 
53  ! Create a new exchange and add it to the baseexchangelist container
54  allocate (exchange)
55  baseexchange => exchange
56  call addbaseexchangetolist(baseexchangelist, baseexchange)
57 
58  call exchange%initialize(filename, name, 'OLF', id, m1_id, m2_id, &
59  input_mempath)
60 
61  end subroutine olfgwf_cr
62 
63  !> @ brief Define OLF GWF exchange
64  !<
65  subroutine olf_gwf_df(this)
66  ! modules
67  ! dummy
68  class(olfgwfexchangetype) :: this !< SwfGwfExchangeType
69  ! local
70 
71  ! log the exchange
72  write (iout, '(/a,a)') ' Creating exchange: ', this%name
73  !
74  ! Ensure models are in same solution
75  if (associated(this%swfmodel) .and. associated(this%gwfmodel)) then
76  if (this%swfmodel%idsoln /= this%gwfmodel%idsoln) then
77  call store_error('Two models are connected in a SWF-GWF '// &
78  'exchange but they are in different solutions. '// &
79  'Models must be in same solution: '// &
80  trim(this%swfmodel%name)//' '// &
81  trim(this%gwfmodel%name))
82  call store_error_filename(this%filename)
83  end if
84  end if
85 
86  ! source options
87  call this%source_options(iout)
88 
89  ! source dimensions
90  call this%source_dimensions(iout)
91 
92  ! allocate arrays
93  call this%allocate_arrays()
94 
95  ! source exchange data
96  call this%source_data(iout)
97 
98  ! Store obs
99  ! call this%swf_gwf_df_obs()
100  ! if (associated(this%swfmodel1)) then
101  ! call this%obs%obs_df(iout, this%name, 'SWF-GWF', this%swfmodel1%dis)
102  ! end if
103 
104  ! ! validate
105  ! call this%validate_exchange()
106 
107  end subroutine olf_gwf_df
108 
109  !> @ brief Source options
110  !<
111  subroutine source_options(this, iout)
112  ! modules
113  use constantsmodule, only: lenvarname, dem6
119  ! dummy
120  class(olfgwfexchangetype) :: this !< GwfExchangeType
121  integer(I4B), intent(in) :: iout
122  ! local
123  type(exgolfgwfparamfoundtype) :: found
124 
125  ! update defaults with idm sourced values
126  call mem_set_value(this%ipr_input, 'IPR_INPUT', &
127  this%input_mempath, found%ipr_input)
128  call mem_set_value(this%ipr_flow, 'IPR_FLOW', &
129  this%input_mempath, found%ipr_flow)
130  call mem_set_value(this%ifixedcond, 'IFIXEDCOND', &
131  this%input_mempath, found%ifixedcond)
132 
133  write (iout, '(1x,a)') 'Processing OLF-GWF exchange options'
134 
135  if (found%ipr_input) then
136  write (iout, '(4x,a)') &
137  'The list of exchanges will be printed.'
138  end if
139 
140  if (found%ipr_flow) then
141  write (iout, '(4x,a)') &
142  'Exchange flows will be printed to list files.'
143  end if
144 
145  if (found%ifixedcond) then
146  write (iout, '(4x,a)') &
147  'Conductance is fixed as product of BEDLEAK and CFACT.'
148  end if
149 
150  ! enforce 0 or 1 OBS6_FILENAME entries in option block
151  ! if (.not. this%is_datacopy) then
152  ! if (filein_fname(this%obs%inputFilename, 'OBS6_FILENAME', &
153  ! this%input_mempath, this%filename)) then
154  ! this%obs%active = .true.
155  ! this%obs%inUnitObs = GetUnit()
156  ! call openfile(this%obs%inUnitObs, iout, this%obs%inputFilename, 'OBS')
157  ! end if
158  ! end if
159 
160  write (iout, '(1x,a)') 'End of OLF-GWF exchange options'
161 
162  end subroutine source_options
163 
164  !> @brief Source dimension from input context
165  !<
166  subroutine source_dimensions(this, iout)
167  ! modules
170  ! dummy
171  class(olfgwfexchangetype) :: this !< instance of exchange object
172  integer(I4B), intent(in) :: iout !< for logging
173  ! local
174  type(exgolfgwfparamfoundtype) :: found
175 
176  ! update defaults with idm sourced values
177  call mem_set_value(this%nexg, 'NEXG', this%input_mempath, found%nexg)
178 
179  write (iout, '(1x,a)') 'PROCESSING EXCHANGE DIMENSIONS'
180 
181  if (found%nexg) then
182  write (iout, '(4x,a,i0)') 'NEXG = ', this%nexg
183  end if
184 
185  write (iout, '(1x,a)') 'END OF EXCHANGE DIMENSIONS'
186 
187  end subroutine source_dimensions
188 
189  !> @brief Source exchange data from input context
190  !<
191  subroutine source_data(this, iout)
192  ! modules
194  ! dummy
195  class(olfgwfexchangetype) :: this !< instance of exchange object
196  integer(I4B), intent(in) :: iout !< the output file unit
197  ! local
198  integer(I4B), dimension(:, :), contiguous, pointer :: cellidm1
199  integer(I4B), dimension(:, :), contiguous, pointer :: cellidm2
200  real(DP), dimension(:), contiguous, pointer :: bedleak
201  real(DP), dimension(:), contiguous, pointer :: cfact
202  character(len=20) :: cellstr1, cellstr2
203  integer(I4B) :: nerr
204  integer(I4B) :: iexg, nodeswf, nodegwf
205  ! format
206  character(len=*), parameter :: fmtexglabel = "(1x, 3a10, 50(a16))"
207  character(len=*), parameter :: fmtexgdata = &
208  "(5x, a, 1x, a ,50(1pg16.6))"
209 
210  call mem_setptr(cellidm1, 'CELLIDM1', this%input_mempath)
211  call mem_setptr(cellidm2, 'CELLIDM2', this%input_mempath)
212  call mem_setptr(bedleak, 'BEDLEAK', this%input_mempath)
213  call mem_setptr(cfact, 'CFACT', this%input_mempath)
214 
215  write (iout, '(1x,a)') 'PROCESSING EXCHANGEDATA'
216 
217  if (this%ipr_input /= 0) then
218  write (iout, fmtexglabel) 'NODEM1', 'NODEM2', 'BEDLEAK', 'CFACT'
219  end if
220 
221  do iexg = 1, this%nexg
222 
223  if (associated(this%model1)) then
224  ! Determine user node number
225  nodeswf = this%noder(this%model1, cellidm1(:, iexg), iout)
226  this%nodeswf(iexg) = nodeswf
227  else
228  this%nodeswf(iexg) = -1
229  end if
230 
231  if (associated(this%model2)) then
232  ! Determine user node number
233  nodegwf = this%noder(this%model2, cellidm2(:, iexg), iout)
234  this%nodegwf(iexg) = nodegwf
235  else
236  this%nodegwf(iexg) = -1
237  end if
238 
239  ! Read rest of input line
240  this%bedleak(iexg) = bedleak(iexg)
241  this%cfact(iexg) = cfact(iexg)
242 
243  ! Write the data to listing file if requested
244  if (this%ipr_input /= 0) then
245  cellstr1 = this%cellstr(this%model1, cellidm1(:, iexg), iout)
246  cellstr2 = this%cellstr(this%model2, cellidm2(:, iexg), iout)
247  write (iout, fmtexgdata) trim(cellstr1), trim(cellstr2), &
248  this%bedleak(iexg), this%cfact(iexg)
249  end if
250 
251  ! Check to see if nodeswf is outside of active domain
252  if (associated(this%model1)) then
253  if (nodeswf <= 0) then
254  cellstr1 = this%cellstr(this%model1, cellidm1(:, iexg), iout)
255  write (errmsg, *) &
256  trim(adjustl(this%model1%name))// &
257  ' Cell is outside active grid domain ('// &
258  trim(adjustl(cellstr1))//').'
259  call store_error(errmsg)
260  end if
261  end if
262 
263  ! Check to see if nodegwf is outside of active domain
264  if (associated(this%model2)) then
265  if (nodegwf <= 0) then
266  cellstr2 = this%cellstr(this%model2, cellidm2(:, iexg), iout)
267  write (errmsg, *) &
268  trim(adjustl(this%model2%name))// &
269  ' Cell is outside active grid domain ('// &
270  trim(adjustl(cellstr2))//').'
271  call store_error(errmsg)
272  end if
273  end if
274  end do
275 
276  write (iout, '(1x,a)') 'END OF EXCHANGEDATA'
277 
278  ! Stop if errors
279  nerr = count_errors()
280  if (nerr > 0) then
281  call store_error('Errors encountered in exchange input file.')
282  call store_error_filename(this%filename)
283  end if
284 
285  end subroutine source_data
286 
287 end module olfgwfexchangemodule
subroutine, public addbaseexchangetolist(list, exchange)
Add the exchange object (BaseExchangeType) to a list.
class(basemodeltype) function, pointer, public getbasemodelfromlist(list, idx)
Definition: BaseModel.f90:172
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition: Constants.f90:17
real(dp), parameter dem6
real constant 1e-6
Definition: Constants.f90:109
Definition: gwf.f90:1
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.
Definition: InputOutput.f90:30
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 type ObsType.
Definition: Obs.f90:127
subroutine, public obs_cr(obs, inobs)
@ brief Create a new ObsType object
Definition: Obs.f90:225
This module contains the OlfGwfExchangeModule Module.
Definition: exg-olfgwf.f90:6
subroutine source_dimensions(this, iout)
Source dimension from input context.
Definition: exg-olfgwf.f90:167
subroutine source_data(this, iout)
Source exchange data from input context.
Definition: exg-olfgwf.f90:192
subroutine source_options(this, iout)
@ brief Source options
Definition: exg-olfgwf.f90:112
subroutine olf_gwf_df(this)
@ brief Define OLF GWF exchange
Definition: exg-olfgwf.f90:66
subroutine, public olfgwf_cr(filename, name, id, m1_id, m2_id, input_mempath)
@ brief Create OLF GWF exchange
Definition: exg-olfgwf.f90:41
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
integer(i4b) function, public count_errors()
Return number of errors.
Definition: Sim.f90:59
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition: Sim.f90:203
This module contains simulation variables.
Definition: SimVariables.f90:9
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
This module contains the SourceCommonModule.
Definition: SourceCommon.f90:7
logical(lgp) function, public filein_fname(filename, tagname, input_mempath, input_fname)
enforce and set a single input filename provided via FILEIN keyword
This module contains the SwfGwfExchangeModule Module.
Definition: exg-swfgwf.f90:8
Surface Water Flow (SWF) Module.
Definition: swf.f90:3
Highest level model type. All models extend this parent type.
Definition: BaseModel.f90:13
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23