MODFLOW 6  version 6.8.0.dev0
USGS Modular Hydrologic Model
explicitsolutionmodule Module Reference

Explicit solutions for solving explicit models. More...

Data Types

type  explicitsolutiontype
 Manages and solves explicit models. More...
 

Functions/Subroutines

subroutine, public create_explicit_solution (exp_sol, filename, id)
 Create a new solution. More...
 
subroutine allocate_scalars (this)
 Allocate scalars. More...
 
subroutine sln_df (this)
 Define the solution. More...
 
subroutine sln_ar (this)
 Allocate and read. More...
 
subroutine sln_dt (this)
 Calculate time step length. More...
 
subroutine sln_ad (this)
 Advance the solution. More...
 
subroutine sln_ot (this)
 Output. More...
 
subroutine sln_fp (this)
 
subroutine sln_da (this)
 Deallocate. More...
 
subroutine sln_ca (this, isgcnvg, isuppress_output)
 Calculate. More...
 
subroutine preparesolve (this)
 Prepare to solve. More...
 
subroutine solve (this, kiter)
 Solve models. More...
 
subroutine finalizesolve (this, kiter, isgcnvg, isuppress_output)
 Finalize solve. More...
 
subroutine save (this, filename)
 Save output. More...
 
subroutine add_model (this, mp)
 Add explicit model to list. More...
 
type(listtype) function, pointer get_models (this)
 Get a pointer to a list of models in the solution. More...
 
subroutine add_exchange (this, exchange)
 Add exchange to list of exchanges. More...
 
type(listtype) function, pointer get_exchanges (this)
 Get list of exchanges. More...
 

Detailed Description

Explicit solutions manage and solve explicit models. An explicit model solves itself, as opposed to a numerical model which requires a numerical solution procedure. An explicit solution involves a double loop: an outer loop that continues until no model has pending work, as well as an inner loop that scrolls through the models in the solution and tells each to solve itself. The outer loop is necessary because the explicit models may be coupled by exchanges; models may send work during each solve to other models. The outer loop continues until all models have completed all work.

Function/Subroutine Documentation

◆ add_exchange()

subroutine explicitsolutionmodule::add_exchange ( class(explicitsolutiontype this,
class(baseexchangetype), intent(in), pointer  exchange 
)
private

Definition at line 338 of file ExplicitSolution.f90.

339  class(ExplicitSolutionType) :: this
340  class(BaseExchangeType), pointer, intent(in) :: exchange
341  class(*), pointer :: obj
342  obj => exchange
343  call this%exchangelist%Add(obj)

◆ add_model()

subroutine explicitsolutionmodule::add_model ( class(explicitsolutiontype this,
class(basemodeltype), intent(in), pointer  mp 
)
private
Parameters
thisExplicitSolutionType instance
[in]mpmodel instance

Definition at line 319 of file ExplicitSolution.f90.

320  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
321  class(BaseModelType), pointer, intent(in) :: mp !< model instance
322  class(ExplicitModelType), pointer :: m => null()
323  select type (mp)
324  class is (explicitmodeltype)
325  m => mp
326  call addexplicitmodeltolist(this%modellist, m)
327  end select
Here is the call graph for this function:

◆ allocate_scalars()

subroutine explicitsolutionmodule::allocate_scalars ( class(explicitsolutiontype this)
Parameters
thisExplicitSolutionType instance

Definition at line 119 of file ExplicitSolution.f90.

120  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
121 
122  ! allocate
123  call mem_allocate(this%id, 'ID', this%memoryPath)
124  call mem_allocate(this%iu, 'IU', this%memoryPath)
125  call mem_allocate(this%ttsoln, 'TTSOLN', this%memoryPath)
126  call mem_allocate(this%icnvg, 'ICNVG', this%memoryPath)
127 
128  ! initialize
129  this%id = 0
130  this%iu = 0
131  this%ttsoln = dzero
132  this%icnvg = 0

◆ create_explicit_solution()

subroutine, public explicitsolutionmodule::create_explicit_solution ( class(explicitsolutiontype), pointer  exp_sol,
character(len=*), intent(in)  filename,
integer(i4b), intent(in)  id 
)

Create a new solution using the data in filename, assign this new solution an id number and store the solution in the basesolutionlist. Also open the filename for later reading.

Parameters
exp_solthe create solution
[in]filenamesolution input file name
[in]idsolution id

Definition at line 82 of file ExplicitSolution.f90.

83  ! modules
85  ! dummy
86  class(ExplicitSolutionType), pointer :: exp_sol !< the create solution
87  character(len=*), intent(in) :: filename !< solution input file name
88  integer(I4B), intent(in) :: id !< solution id
89  ! local
90  integer(I4B) :: inunit
91  class(BaseSolutionType), pointer :: solbase => null()
92  character(len=LENSOLUTIONNAME) :: solutionname
93 
94  ! Create a new solution and add it to the basesolutionlist container
95  solbase => exp_sol
96  write (solutionname, '(a, i0)') 'SLN_', id
97  exp_sol%name = solutionname
98  exp_sol%memoryPath = create_mem_path(solutionname)
99  allocate (exp_sol%modellist)
100  allocate (exp_sol%exchangelist)
101  call exp_sol%allocate_scalars()
102  call addbasesolutiontolist(basesolutionlist, solbase)
103  exp_sol%id = id
104 
105  ! Open solution input file for reading later after problem size is known
106  ! Check to see if the file is already opened, which can happen when
107  ! running in single model mode
108  inquire (file=filename, number=inunit)
109  if (inunit < 0) inunit = getunit()
110  exp_sol%iu = inunit
111  write (iout, '(/a,a/)') ' Creating explicit solution (EMS): ', exp_sol%name
112  call openfile(exp_sol%iu, iout, filename, 'EMS')
113 
114  ! Initialize block parser
115  call exp_sol%parser%Initialize(exp_sol%iu, iout)
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ finalizesolve()

subroutine explicitsolutionmodule::finalizesolve ( class(explicitsolutiontype this,
integer(i4b), intent(in)  kiter,
integer(i4b), intent(inout)  isgcnvg,
integer(i4b), intent(in)  isuppress_output 
)
private
Parameters
thisExplicitSolutionType instance
[in]kiterPicard iteration number (always 1 for explicit)
[in,out]isgcnvgsolution group convergence flag
[in]isuppress_outputflag for suppressing output

Definition at line 284 of file ExplicitSolution.f90.

285  ! dummy
286  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
287  integer(I4B), intent(in) :: kiter !< Picard iteration number (always 1 for explicit)
288  integer(I4B), intent(inout) :: isgcnvg !< solution group convergence flag
289  integer(I4B), intent(in) :: isuppress_output !< flag for suppressing output
290  ! local
291  integer(I4B) :: im
292  class(ExplicitModelType), pointer :: mp => null()
293 
294  ! Calculate flow for each model
295  do im = 1, this%modellist%Count()
296  mp => getexplicitmodelfromlist(this%modellist, im)
297  call mp%model_cq(this%icnvg, isuppress_output)
298  end do
299 
300  ! Budget terms for each model
301  do im = 1, this%modellist%Count()
302  mp => getexplicitmodelfromlist(this%modellist, im)
303  call mp%model_bd(this%icnvg, isuppress_output)
304  end do
Here is the call graph for this function:

◆ get_exchanges()

type(listtype) function, pointer explicitsolutionmodule::get_exchanges ( class(explicitsolutiontype this)
private

Definition at line 347 of file ExplicitSolution.f90.

348  class(ExplicitSolutionType) :: this
349  type(ListType), pointer :: exchanges
350  exchanges => this%exchangelist

◆ get_models()

type(listtype) function, pointer explicitsolutionmodule::get_models ( class(explicitsolutiontype this)
private
Returns
pointer to the model list
Parameters
thisExplicitSolutionType instance

Definition at line 331 of file ExplicitSolution.f90.

332  type(ListType), pointer :: models !< pointer to the model list
333  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
334  models => this%modellist

◆ preparesolve()

subroutine explicitsolutionmodule::preparesolve ( class(explicitsolutiontype this)
private
Parameters
thisExplicitSolutionType instance

Definition at line 222 of file ExplicitSolution.f90.

223  ! dummy
224  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
225  ! local
226  integer(I4B) :: i
227  class(ExplicitModelType), pointer :: mp => null()
228  class(BaseExchangeType), pointer :: ep => null()
229 
230  ! advance exchanges
231  do i = 1, this%exchangelist%Count()
232  ep => getbaseexchangefromlist(this%exchangelist, i)
233  call ep%exg_ad()
234  end do
235 
236  ! advance models
237  do i = 1, this%modellist%Count()
238  mp => getexplicitmodelfromlist(this%modellist, i)
239  call mp%model_ad()
240  end do
241 
242  ! advance solution
243  call this%sln_ad()
Here is the call graph for this function:

◆ save()

subroutine explicitsolutionmodule::save ( class(explicitsolutiontype this,
character(len=*), intent(in)  filename 
)
private
Parameters
thisExplicitSolutionType instance
[in]filenamefilename to save solution data

Definition at line 308 of file ExplicitSolution.f90.

309  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
310  character(len=*), intent(in) :: filename !< filename to save solution data
311  integer(I4B) :: inunit
312  inunit = getunit()
313  open (unit=inunit, file=filename, status='unknown')
314  write (inunit, *) 'The save routine currently writes nothing'
315  close (inunit)
Here is the call graph for this function:

◆ sln_ad()

subroutine explicitsolutionmodule::sln_ad ( class(explicitsolutiontype this)
private
Parameters
thisExplicitSolutionType instance

Definition at line 153 of file ExplicitSolution.f90.

154  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
155 
156  ! reset convergence flag
157  this%icnvg = 0

◆ sln_ar()

subroutine explicitsolutionmodule::sln_ar ( class(explicitsolutiontype this)
private
Parameters
thisExplicitSolutionType instance

Definition at line 141 of file ExplicitSolution.f90.

142  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
143  ! close ems input file
144  call this%parser%Clear()

◆ sln_ca()

subroutine explicitsolutionmodule::sln_ca ( class(explicitsolutiontype this,
integer(i4b), intent(inout)  isgcnvg,
integer(i4b), intent(in)  isuppress_output 
)
private
Parameters
thisExplicitSolutionType instance
[in,out]isgcnvgsolution group convergence flag
[in]isuppress_outputflag for suppressing output

Definition at line 187 of file ExplicitSolution.f90.

188  ! dummy
189  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
190  integer(I4B), intent(inout) :: isgcnvg !< solution group convergence flag
191  integer(I4B), intent(in) :: isuppress_output !< flag for suppressing output
192  ! local
193  class(ExplicitModelType), pointer :: mp => null()
194  character(len=LINELENGTH) :: line
195  character(len=LINELENGTH) :: fmt
196  integer(I4B) :: im
197  integer(I4B) :: kiter
198 
199  kiter = 1
200 
201  call this%prepareSolve()
202 
203  select case (isim_mode)
204  case (mvalidate)
205  line = 'mode="validation" -- Skipping assembly and solution.'
206  fmt = "(/,1x,a,/)"
207  do im = 1, this%modellist%Count()
208  mp => getexplicitmodelfromlist(this%modellist, im)
209  call mp%model_message(line, fmt=fmt)
210  end do
211  case (mnormal)
212 
213  ! solve the models
214  call this%solve(kiter)
215 
216  ! finish up
217  call this%finalizeSolve(kiter, isgcnvg, isuppress_output)
218  end select
Here is the call graph for this function:

◆ sln_da()

subroutine explicitsolutionmodule::sln_da ( class(explicitsolutiontype this)
private
Parameters
thisExplicitSolutionType instance

Definition at line 170 of file ExplicitSolution.f90.

171  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
172 
173  ! lists
174  call this%modellist%Clear()
175  deallocate (this%modellist)
176  call this%exchangelist%Clear()
177  deallocate (this%exchangelist)
178 
179  ! scalars
180  call mem_deallocate(this%id)
181  call mem_deallocate(this%iu)
182  call mem_deallocate(this%ttsoln)
183  call mem_deallocate(this%icnvg)

◆ sln_df()

subroutine explicitsolutionmodule::sln_df ( class(explicitsolutiontype this)
private

Definition at line 136 of file ExplicitSolution.f90.

137  class(ExplicitSolutionType) :: this

◆ sln_dt()

subroutine explicitsolutionmodule::sln_dt ( class(explicitsolutiontype this)
private
Parameters
thisExplicitSolutionType instance

Definition at line 148 of file ExplicitSolution.f90.

149  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance

◆ sln_fp()

subroutine explicitsolutionmodule::sln_fp ( class(explicitsolutiontype this)
private
Parameters
thisExplicitSolutionType instance

Definition at line 165 of file ExplicitSolution.f90.

166  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance

◆ sln_ot()

subroutine explicitsolutionmodule::sln_ot ( class(explicitsolutiontype this)
private
Parameters
thisExplicitSolutionType instance

Definition at line 161 of file ExplicitSolution.f90.

162  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance

◆ solve()

subroutine explicitsolutionmodule::solve ( class(explicitsolutiontype this,
integer(i4b), intent(in)  kiter 
)
private
Parameters
thisExplicitSolutionType instance
[in]kiterPicard iteration (1 for explicit)

Definition at line 247 of file ExplicitSolution.f90.

248  ! dummy
249  class(ExplicitSolutionType) :: this !< ExplicitSolutionType instance
250  integer(I4B), intent(in) :: kiter !< Picard iteration (1 for explicit)
251  ! local
252  class(ExplicitModelType), pointer :: mp => null()
253  integer(I4B) :: im
254  logical :: any_pending
255  real(DP) :: ttsoln
256 
257  call code_timer(0, ttsoln, this%ttsoln)
258 
259  ! Outer loop: repeat until no model has pending work
260  do
261  ! Solve every model in the solution
262  do im = 1, this%modellist%Count()
263  mp => getexplicitmodelfromlist(this%modellist, im)
264  call mp%model_solve()
265  end do
266 
267  ! Continue if any have pending work
268  any_pending = .false.
269  do im = 1, this%modellist%Count()
270  mp => getexplicitmodelfromlist(this%modellist, im)
271  if (mp%has_pending()) then
272  any_pending = .true.
273  exit
274  end if
275  end do
276  if (.not. any_pending) exit
277  end do
278 
279  call code_timer(1, ttsoln, this%ttsoln)
280  this%icnvg = 1
Here is the call graph for this function: