MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
NumericalModel.f90
Go to the documentation of this file.
2
3 use kindmodule, only: dp, i4b
8 use listmodule, only: listtype
11
12 implicit none
13 private
16
18 integer(I4B), pointer :: neq => null() !< number of equations
19 integer(I4B), pointer :: moffset => null() !< offset of this model in the solution
20 integer(I4B), pointer :: icnvg => null() !< convergence flag
21 integer(I4B), dimension(:), pointer, contiguous :: ia => null() !< csr row pointer
22 integer(I4B), dimension(:), pointer, contiguous :: ja => null() !< csr columns
23 real(dp), dimension(:), pointer, contiguous :: x => null() !< dependent variable (head, conc, etc)
24 real(dp), dimension(:), pointer, contiguous :: rhs => null() !< right-hand side vector
25 real(dp), dimension(:), pointer, contiguous :: cond => null() !< conductance matrix
26 integer(I4B), dimension(:), pointer, contiguous :: idxglo => null() !< pointer to position in solution matrix
27 real(dp), dimension(:), pointer, contiguous :: xold => null() !< dependent variable for previous timestep
28
29 contains
30 ! Overridden methods
31 procedure :: model_df
32 procedure :: model_ar
33 procedure :: model_fp
34 procedure :: model_da
35 ! Specific methods
36 procedure :: model_ac
37 procedure :: model_mc
38 procedure :: model_rp
39 procedure :: model_ad
40 procedure :: model_reset
41 procedure :: model_solve
42 procedure :: model_cf
43 procedure :: model_fc
44 procedure :: model_ptcchk
45 procedure :: model_ptc
46 procedure :: model_nr
47 procedure :: model_cc
48 procedure :: model_nur
49 procedure :: model_cq
50 procedure :: model_bd
51 procedure :: model_bdcalc
52 procedure :: model_bdsave
53 procedure :: model_ot
54 procedure :: model_bdentry
55 ! Utility methods
56 procedure :: allocate_scalars
57 procedure :: allocate_arrays
58 procedure :: set_moffset
59 procedure :: set_idsoln
60 procedure :: set_xptr
61 procedure :: set_rhsptr
62 procedure :: set_iboundptr
63 procedure :: get_mrange
64 procedure :: get_mcellid
65 procedure :: get_mnodeu
66 procedure :: get_iasym
67 procedure :: get_idv_scale
68 end type numericalmodeltype
69
70contains
71
72 subroutine model_df(this)
73 class(numericalmodeltype) :: this
74 end subroutine model_df
75
76 subroutine model_ac(this, sparse)
77 class(numericalmodeltype) :: this
78 type(sparsematrix), intent(inout) :: sparse
79 end subroutine model_ac
80
81 subroutine model_mc(this, matrix_sln)
82 class(numericalmodeltype) :: this
83 class(matrixbasetype), pointer :: matrix_sln
84 end subroutine model_mc
85
86 subroutine model_ar(this)
87 class(numericalmodeltype) :: this
88 end subroutine model_ar
89
90 subroutine model_rp(this)
91 class(numericalmodeltype) :: this
92 end subroutine model_rp
93
94 subroutine model_ad(this)
95 class(numericalmodeltype) :: this
96 end subroutine model_ad
97
98 subroutine model_reset(this)
100 class(numericalmodeltype) :: this
101 ! local
102 class(bndtype), pointer :: packobj
103 integer(I4B) :: ip
104
105 do ip = 1, this%bndlist%Count()
106 packobj => getbndfromlist(this%bndlist, ip)
107 call packobj%bnd_reset()
108 end do
109
110 end subroutine model_reset
111
112 subroutine model_solve(this)
113 class(numericalmodeltype) :: this
114 end subroutine model_solve
115
116 subroutine model_cf(this, kiter)
117 class(numericalmodeltype) :: this
118 integer(I4B), intent(in) :: kiter
119 end subroutine model_cf
120
121 subroutine model_fc(this, kiter, matrix_sln, inwtflag)
122 class(numericalmodeltype) :: this
123 integer(I4B), intent(in) :: kiter
124 class(matrixbasetype), pointer :: matrix_sln
125 integer(I4B), intent(in) :: inwtflag
126 end subroutine model_fc
127
128 subroutine model_ptcchk(this, iptc)
129 class(numericalmodeltype) :: this
130 integer(I4B), intent(inout) :: iptc
131 iptc = 0
132 end subroutine model_ptcchk
133
134 subroutine model_ptc(this, vec_residual, iptc, ptcf)
135 class(numericalmodeltype) :: this
136 class(vectorbasetype), pointer :: vec_residual
137 integer(I4B), intent(inout) :: iptc
138 real(DP), intent(inout) :: ptcf
139 end subroutine model_ptc
140
141 subroutine model_nr(this, kiter, matrix, inwtflag)
142 class(numericalmodeltype) :: this
143 integer(I4B), intent(in) :: kiter
144 class(matrixbasetype), pointer :: matrix
145 integer(I4B), intent(in) :: inwtflag
146 end subroutine model_nr
147
148 subroutine model_cc(this, innertot, kiter, iend, icnvgmod, cpak, ipak, dpak)
149 class(numericalmodeltype) :: this
150 integer(I4B), intent(in) :: innertot
151 integer(I4B), intent(in) :: kiter
152 integer(I4B), intent(in) :: iend
153 integer(I4B), intent(in) :: icnvgmod
154 character(len=LENPAKLOC), intent(inout) :: cpak
155 integer(I4B), intent(inout) :: ipak
156 real(DP), intent(inout) :: dpak
157 end subroutine model_cc
158
159 subroutine model_nur(this, neqmod, x, xtemp, dx, inewtonur, dxmax, locmax)
160 class(numericalmodeltype) :: this
161 integer(I4B), intent(in) :: neqmod
162 real(DP), dimension(neqmod), intent(inout) :: x
163 real(DP), dimension(neqmod), intent(in) :: xtemp
164 real(DP), dimension(neqmod), intent(inout) :: dx
165 integer(I4B), intent(inout) :: inewtonur
166 real(DP), intent(inout) :: dxmax
167 integer(I4B), intent(inout) :: locmax
168 end subroutine model_nur
169
170 subroutine model_cq(this, icnvg, isuppress_output)
171 class(numericalmodeltype) :: this
172 integer(I4B), intent(in) :: icnvg
173 integer(I4B), intent(in) :: isuppress_output
174 end subroutine model_cq
175
176 subroutine model_bd(this, icnvg, isuppress_output)
177 class(numericalmodeltype) :: this
178 integer(I4B), intent(in) :: icnvg
179 integer(I4B), intent(in) :: isuppress_output
180 end subroutine model_bd
181
182 subroutine model_bdcalc(this, icnvg)
183 class(numericalmodeltype) :: this
184 integer(I4B), intent(in) :: icnvg
185 end subroutine model_bdcalc
186
187 subroutine model_bdsave(this, icnvg)
188 class(numericalmodeltype) :: this
189 integer(I4B), intent(in) :: icnvg
190 end subroutine model_bdsave
191
192 subroutine model_ot(this)
193 class(numericalmodeltype) :: this
194 end subroutine model_ot
195
196 subroutine model_bdentry(this, budterm, budtxt, rowlabel)
197 class(numericalmodeltype) :: this
198 real(DP), dimension(:, :), intent(in) :: budterm
199 character(len=LENBUDTXT), dimension(:), intent(in) :: budtxt
200 character(len=*), intent(in) :: rowlabel
201 end subroutine model_bdentry
202
203 subroutine model_fp(this)
204 class(numericalmodeltype) :: this
205 end subroutine model_fp
206
207 subroutine model_da(this)
208 ! modules
210 class(numericalmodeltype) :: this
211
212 ! deallocate scalars
213 call mem_deallocate(this%neq)
214 call mem_deallocate(this%nja)
215 call mem_deallocate(this%icnvg)
216 call mem_deallocate(this%moffset)
217 deallocate (this%filename)
218
219 ! deallocate arrays
220 call mem_deallocate(this%xold)
221 call mem_deallocate(this%flowja, 'FLOWJA', this%memoryPath)
222 call mem_deallocate(this%idxglo)
223
224 ! deallocate derived types
225 call this%bndlist%Clear()
226 deallocate (this%bndlist)
227
228 ! nullify pointers
229 call mem_deallocate(this%x, 'X', this%memoryPath)
230 call mem_deallocate(this%rhs, 'RHS', this%memoryPath)
231 call mem_deallocate(this%ibound, 'IBOUND', this%memoryPath)
232
233 ! base deallocation
234 call this%BaseModelType%model_da()
235
236 end subroutine model_da
237
238 subroutine set_moffset(this, moffset)
239 class(numericalmodeltype) :: this
240 integer(I4B), intent(in) :: moffset
241 this%moffset = moffset
242 end subroutine set_moffset
243
244 subroutine get_mrange(this, mstart, mend)
245 class(numericalmodeltype) :: this
246 integer(I4B), intent(inout) :: mstart
247 integer(I4B), intent(inout) :: mend
248 mstart = this%moffset + 1
249 mend = mstart + this%neq - 1
250 end subroutine get_mrange
251
252 subroutine set_idsoln(this, id)
253 class(numericalmodeltype) :: this
254 integer(I4B), intent(in) :: id
255 this%idsoln = id
256 end subroutine set_idsoln
257
258 subroutine allocate_scalars(this, modelname)
260 class(numericalmodeltype) :: this
261 character(len=*), intent(in) :: modelname
262
263 ! allocate base members
264 call this%BaseModelType%allocate_scalars(modelname)
265
266 ! allocate members from this type
267 call mem_allocate(this%neq, 'NEQ', this%memoryPath)
268 call mem_allocate(this%nja, 'NJA', this%memoryPath)
269 call mem_allocate(this%icnvg, 'ICNVG', this%memoryPath)
270 call mem_allocate(this%moffset, 'MOFFSET', this%memoryPath)
271 allocate (this%filename)
272 allocate (this%bndlist)
273
274 this%filename = ''
275 this%neq = 0
276 this%nja = 0
277 this%icnvg = 0
278 this%moffset = 0
279 end subroutine allocate_scalars
280
281 subroutine allocate_arrays(this)
282 use constantsmodule, only: dzero
284 class(numericalmodeltype) :: this
285 integer(I4B) :: i
286
287 call mem_allocate(this%xold, this%neq, 'XOLD', this%memoryPath)
288 call mem_allocate(this%flowja, this%nja, 'FLOWJA', this%memoryPath)
289 call mem_allocate(this%idxglo, this%nja, 'IDXGLO', this%memoryPath)
290
291 do i = 1, size(this%flowja)
292 this%flowja(i) = dzero
293 end do
294 end subroutine allocate_arrays
295
296 subroutine set_xptr(this, xsln, sln_offset, varNameTgt, memPathTgt)
298 ! dummy
299 class(numericalmodeltype) :: this
300 real(DP), dimension(:), pointer, contiguous, intent(in) :: xsln
301 integer(I4B) :: sln_offset
302 character(len=*), intent(in) :: varNameTgt
303 character(len=*), intent(in) :: memPathTgt
304 ! local
305 integer(I4B) :: offset
306
307 offset = this%moffset - sln_offset
308 this%x => xsln(offset + 1:offset + this%neq)
309 call mem_checkin(this%x, 'X', this%memoryPath, varnametgt, mempathtgt)
310 end subroutine set_xptr
311
312 subroutine set_rhsptr(this, rhssln, sln_offset, varNameTgt, memPathTgt)
314 ! dummy
315 class(numericalmodeltype) :: this
316 real(DP), dimension(:), pointer, contiguous, intent(in) :: rhssln
317 integer(I4B) :: sln_offset
318 character(len=*), intent(in) :: varNameTgt
319 character(len=*), intent(in) :: memPathTgt
320 ! local
321 integer(I4B) :: offset
322
323 offset = this%moffset - sln_offset
324 this%rhs => rhssln(offset + 1:offset + this%neq)
325 call mem_checkin(this%rhs, 'RHS', this%memoryPath, varnametgt, mempathtgt)
326 end subroutine set_rhsptr
327
328 subroutine set_iboundptr(this, iboundsln, sln_offset, varNameTgt, memPathTgt)
330 ! dummy
331 class(numericalmodeltype) :: this
332 integer(I4B), dimension(:), pointer, contiguous, intent(in) :: iboundsln
333 integer(I4B) :: sln_offset
334 character(len=*), intent(in) :: varNameTgt
335 character(len=*), intent(in) :: memPathTgt
336 ! local
337 integer(I4B) :: offset
338
339 offset = this%moffset - sln_offset
340 this%ibound => iboundsln(offset + 1:offset + this%neq)
341 call mem_checkin(this%ibound, 'IBOUND', this%memoryPath, varnametgt, &
342 mempathtgt)
343 end subroutine set_iboundptr
344
345 subroutine get_mcellid(this, node, mcellid)
347 ! dummy
348 class(numericalmodeltype) :: this
349 integer(I4B), intent(in) :: node
350 character(len=*), intent(inout) :: mcellid
351 ! local
352 character(len=20) :: cellid
353 integer(I4B) :: ip, ipaknode, istart, istop
354 class(bndtype), pointer :: packobj
355
356 if (node < 1) then
357 cellid = ''
358 else if (node <= this%dis%nodes) then
359 call this%dis%noder_to_string(node, cellid)
360 else
361 cellid = '***ERROR***'
362 ipaknode = node - this%dis%nodes
363 istart = 1
364 do ip = 1, this%bndlist%Count()
365 packobj => getbndfromlist(this%bndlist, ip)
366 if (packobj%npakeq == 0) cycle
367 istop = istart + packobj%npakeq - 1
368 if (istart <= ipaknode .and. ipaknode <= istop) then
369 write (cellid, '(a, a, a, i0, a, i0, a)') '(', &
370 trim(packobj%filtyp), '_', &
371 packobj%ibcnum, '-', ipaknode - packobj%ioffset, ')'
372 exit
373 end if
374 istart = istop + 1
375 end do
376 end if
377 write (mcellid, '(i0, a, a, a, a)') this%id, '_', this%macronym, '-', &
378 trim(adjustl(cellid))
379 end subroutine get_mcellid
380
381 subroutine get_mnodeu(this, node, nodeu)
383 class(numericalmodeltype) :: this
384 integer(I4B), intent(in) :: node
385 integer(I4B), intent(inout) :: nodeu
386
387 if (node <= this%dis%nodes) then
388 nodeu = this%dis%get_nodeuser(node)
389 else
390 nodeu = -(node - this%dis%nodes)
391 end if
392 end subroutine get_mnodeu
393
394 function get_iasym(this) result(iasym)
395 class(numericalmodeltype) :: this
396 integer(I4B) :: iasym
397 iasym = 0
398 end function get_iasym
399
400 function get_idv_scale(this) result(idv_scale)
401 class(numericalmodeltype) :: this
402 integer(I4B) :: idv_scale
403 idv_scale = 0
404 end function get_idv_scale
405
406 function castasnumericalmodelclass(obj) result(res)
407 implicit none
408 class(*), pointer, intent(inout) :: obj
409 class(numericalmodeltype), pointer :: res
410
411 res => null()
412 if (.not. associated(obj)) return
413
414 select type (obj)
415 class is (numericalmodeltype)
416 res => obj
417 end select
418 end function castasnumericalmodelclass
419
420 subroutine addnumericalmodeltolist(list, model)
421 implicit none
422 ! dummy
423 type(listtype), intent(inout) :: list
424 class(numericalmodeltype), pointer, intent(inout) :: model
425 ! local
426 class(*), pointer :: obj
427
428 obj => model
429 call list%Add(obj)
430 end subroutine addnumericalmodeltolist
431
432 function getnumericalmodelfromlist(list, idx) result(res)
433 implicit none
434 ! dummy
435 type(listtype), intent(inout) :: list
436 integer(I4B), intent(in) :: idx
437 class(numericalmodeltype), pointer :: res
438 ! local
439 class(*), pointer :: obj
440
441 obj => list%GetItem(idx)
442 res => castasnumericalmodelclass(obj)
443 end function getnumericalmodelfromlist
444
445end module numericalmodelmodule
subroutine model_ar(this)
Allocate and read.
Definition BaseModel.f90:55
subroutine model_ot(this)
Output results.
Definition BaseModel.f90:70
subroutine allocate_scalars(this, modelname)
Allocate scalar variables.
Definition BaseModel.f90:98
subroutine model_rp(this)
Read and prepare.
Definition BaseModel.f90:60
subroutine model_df(this)
Define the model.
Definition BaseModel.f90:50
subroutine model_fp(this)
Final processing.
Definition BaseModel.f90:93
subroutine model_da(this)
Deallocate.
This module contains the base boundary package.
class(bndtype) function, pointer, public getbndfromlist(list, idx)
Get boundary from package list.
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
integer(i4b), parameter lenpakloc
maximum length of a package location
Definition Constants.f90:50
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
This module defines variable data types.
Definition kind.f90:8
subroutine, public addnumericalmodeltolist(list, model)
subroutine model_ac(this, sparse)
subroutine set_iboundptr(this, iboundsln, sln_offset, varnametgt, mempathtgt)
subroutine model_cc(this, innertot, kiter, iend, icnvgmod, cpak, ipak, dpak)
subroutine model_bdsave(this, icnvg)
subroutine model_ad(this)
subroutine model_solve(this)
subroutine get_mrange(this, mstart, mend)
subroutine model_mc(this, matrix_sln)
class(numericalmodeltype) function, pointer, public getnumericalmodelfromlist(list, idx)
subroutine model_nr(this, kiter, matrix, inwtflag)
subroutine set_idsoln(this, id)
subroutine get_mnodeu(this, node, nodeu)
subroutine model_nur(this, neqmod, x, xtemp, dx, inewtonur, dxmax, locmax)
subroutine model_cq(this, icnvg, isuppress_output)
subroutine set_xptr(this, xsln, sln_offset, varnametgt, mempathtgt)
subroutine model_bd(this, icnvg, isuppress_output)
subroutine model_bdcalc(this, icnvg)
subroutine get_mcellid(this, node, mcellid)
subroutine model_reset(this)
class(numericalmodeltype) function, pointer castasnumericalmodelclass(obj)
subroutine model_ptc(this, vec_residual, iptc, ptcf)
subroutine set_moffset(this, moffset)
subroutine model_ptcchk(this, iptc)
subroutine set_rhsptr(this, rhssln, sln_offset, varnametgt, mempathtgt)
subroutine allocate_arrays(this)
integer(i4b) function get_iasym(this)
integer(i4b) function get_idv_scale(this)
subroutine model_fc(this, kiter, matrix_sln, inwtflag)
subroutine model_cf(this, kiter)
subroutine model_bdentry(this, budterm, budtxt, rowlabel)
Highest level model type. All models extend this parent type.
Definition BaseModel.f90:16
A generic heterogeneous doubly-linked list.
Definition List.f90:14