MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
ImsLinear.f90
Go to the documentation of this file.
2
3 use kindmodule, only: dp, i4b
7 dhalf, done, dtwo, &
18
19 IMPLICIT NONE
20 private
21
22 TYPE, PUBLIC :: imslineardatatype
23 character(len=LENMEMPATH) :: memorypath !< the path for storing variables in the memory manager
24 integer(I4B), POINTER :: iout => null() !< simulation listing file unit
25 integer(I4B), POINTER :: iprims => null() !< print flag
26 ! input variables (pointing to fields in input structure)
27 real(dp), pointer :: dvclose => null() !< dependent variable closure criterion
28 real(dp), pointer :: rclose => null() !< residual closure criterion
29 integer(I4B), pointer :: icnvgopt => null() !< convergence option
30 integer(I4B), pointer :: iter1 => null() !< max. iterations
31 integer(I4B), pointer :: ilinmeth => null() !< linear solver method
32 integer(I4B), pointer :: iscl => null() !< scaling method
33 integer(I4B), pointer :: iord => null() !< reordering method
34 integer(I4B), pointer :: north => null() !< number of orthogonalizations
35
36 real(dp), pointer :: relax => null() !< relaxation factor
37 integer(I4B), pointer :: level => null() !< nr. of preconditioner levels
38 real(dp), pointer :: droptol => null() !< drop tolerance for preconditioner
39 !
40 integer(I4B), POINTER :: ipc => null() !< preconditioner flag
41 integer(I4B), POINTER :: iacpc => null() !< preconditioner CRS row pointers
42 integer(I4B), POINTER :: niterc => null() !<
43 integer(I4B), POINTER :: niabcgs => null() !< size of working vectors for BCGS linear accelerator
44 integer(I4B), POINTER :: niapc => null() !< preconditioner number of rows
45 integer(I4B), POINTER :: njapc => null() !< preconditioner number of non-zero entries
46 real(dp), POINTER :: epfact => null() !< factor for decreasing convergence criteria in seubsequent Picard iterations
47 real(dp), POINTER :: l2norm0 => null() !< initial L2 norm
48 ! -- ilut variables
49 integer(I4B), POINTER :: njlu => null() !< length of jlu work vector
50 integer(I4B), POINTER :: njw => null() !< length of jw work vector
51 integer(I4B), POINTER :: nwlu => null() !< length of wlu work vector
52 ! -- pointers to solution variables
53 integer(I4B), POINTER :: neq => null() !< number of equations (rows in matrix)
54 integer(I4B), POINTER :: nja => null() !< number of non-zero values in amat
55 integer(I4B), dimension(:), pointer, contiguous :: ia => null() !< position of start of each row
56 integer(I4B), dimension(:), pointer, contiguous :: ja => null() !< column pointer
57 real(dp), dimension(:), pointer, contiguous :: amat => null() !< coefficient matrix
58 real(dp), dimension(:), pointer, contiguous :: rhs => null() !< right-hand side of equation
59 real(dp), dimension(:), pointer, contiguous :: x => null() !< dependent variable
60 ! VECTORS
61 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: dscale => null() !< scaling factor
62 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: dscale2 => null() !< unscaling factor
63 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: rscale => null() !< factor returning the residual to model units
64 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: hscale => null() !< factor returning the head change to model units
65 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: iapc => null() !< position of start of each row in preconditioner matrix
66 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: japc => null() !< preconditioner matrix column pointer
67 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: apc => null() !< preconditioner coefficient matrix
68 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: lorder => null() !< reordering mapping
69 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: iorder => null() !< mapping to restore reordered matrix
70 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: iaro => null() !< position of start of each row in reordered matrix
71 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: jaro => null() !< reordered matrix column pointer
72 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: aro => null() !< reordered coefficient matrix
73 ! WORKING ARRAYS
74 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: iw => null() !< integer working array
75 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: w => null() !< real working array
76 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: id => null() !< integer working array
77 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: d => null() !< real working array
78 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: p => null() !< real working array
79 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: q => null() !< real working array
80 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: z => null() !< real working array
81 ! BICGSTAB WORKING ARRAYS
82 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: t => null() !< BICGSTAB real working array
83 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: v => null() !< BICGSTAB real working array
84 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: dhat => null() !< BICGSTAB real working array
85 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: phat => null() !< BICGSTAB real working array
86 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: qhat => null() !< rBICGSTAB eal working array
87 ! POINTERS FOR USE WITH BOTH ORIGINAL AND RCM ORDERINGS
88 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: ia0 => null() !< pointer to current CRS row pointers
89 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: ja0 => null() !< pointer to current CRS column pointers
90 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: a0 => null() !< pointer to current coefficient matrix
91 ! ILUT WORKING ARRAYS
92 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: jlu => null() !< ilut integer working array
93 integer(I4B), POINTER, DIMENSION(:), CONTIGUOUS :: jw => null() !< ilut integer working array
94 real(dp), POINTER, DIMENSION(:), CONTIGUOUS :: wlu => null() !< ilut real working array
95
96 ! PROCEDURES (METHODS)
97 CONTAINS
98 PROCEDURE :: imslinear_allocate => imslinear_ar
99 procedure :: imslinear_summary
100 PROCEDURE :: imslinear_apply => imslinear_ap
102 procedure, private :: allocate_scalars
103 ! -- PRIVATE PROCEDURES
104 PROCEDURE, PRIVATE :: set_imslinear_input => imslinear_set_input
105 END TYPE imslineardatatype
106
107CONTAINS
108
109 !> @brief Allocate storage and read data
110 !!
111 !! Allocate storage for linear accelerators and read data
112 !!
113 !<
114 SUBROUTINE imslinear_ar(this, NAME, IOUT, IPRIMS, MXITER, &
115 NEQ, matrix, RHS, X, linear_settings)
116 ! -- modules
119 use simmodule, only: store_error, count_errors, &
121 ! -- dummy variables
122 CLASS(imslineardatatype), INTENT(INOUT) :: this !< ImsLinearDataType instance
123 CHARACTER(LEN=LENSOLUTIONNAME), INTENT(IN) :: NAME !< solution name
124 integer(I4B), INTENT(IN) :: IOUT !< simulation listing file unit
125 integer(I4B), TARGET, INTENT(IN) :: IPRIMS !< print option
126 integer(I4B), INTENT(IN) :: MXITER !< maximum outer iterations
127 integer(I4B), TARGET, INTENT(IN) :: NEQ !< number of equations
128 class(matrixbasetype), pointer :: matrix
129 real(DP), DIMENSION(NEQ), TARGET, INTENT(INOUT) :: RHS !< right-hand side
130 real(DP), DIMENSION(NEQ), TARGET, INTENT(INOUT) :: X !< dependent variables
131 type(imslinearsettingstype), pointer :: linear_settings !< the settings form the IMS file
132 ! -- local variables
133 character(len=LINELENGTH) :: errmsg
134 integer(I4B) :: n
135 integer(I4B) :: i0
136 integer(I4B) :: iscllen, iolen
137
138 !
139 ! -- DEFINE NAME
140 this%memoryPath = create_mem_path(name, 'IMSLINEAR')
141 !
142 ! -- SET pointers to IMS settings
143 this%DVCLOSE => linear_settings%dvclose
144 this%RCLOSE => linear_settings%rclose
145 this%ICNVGOPT => linear_settings%icnvgopt
146 this%ITER1 => linear_settings%iter1
147 this%ILINMETH => linear_settings%ilinmeth
148 this%ISCL => linear_settings%iscl
149 this%IORD => linear_settings%iord
150 this%NORTH => linear_settings%north
151 this%RELAX => linear_settings%relax
152 this%LEVEL => linear_settings%level
153 this%DROPTOL => linear_settings%droptol
154 !
155 ! -- SET POINTERS TO SOLUTION STORAGE
156 this%IPRIMS => iprims
157 this%NEQ => neq
158 call matrix%get_aij(this%IA, this%JA, this%AMAT)
159 call mem_allocate(this%NJA, 'NJA', this%memoryPath)
160 this%NJA = size(this%AMAT)
161 this%RHS => rhs
162 this%X => x
163 !
164 ! -- ALLOCATE SCALAR VARIABLES
165 call this%allocate_scalars()
166 !
167 ! -- initialize iout
168 this%iout = iout
169 !
170 ! -- DEFAULT VALUES
171 this%IPC = ipc_unknown
172 !
173 this%IACPC = 0
174 !
175 ! -- PRINT A MESSAGE IDENTIFYING IMSLINEAR SOLVER PACKAGE
176 write (iout, 2000)
17702000 FORMAT(1x, /1x, 'IMSLINEAR -- UNSTRUCTURED LINEAR SOLUTION', &
178 ' PACKAGE, VERSION 8, 04/28/2017')
179 !
180 ! -- DETERMINE PRECONDITIONER
181 this%IPC = resolve_ipc(this%LEVEL, this%RELAX)
182 !
183 ! -- ERROR CHECKING FOR OPTIONS
184 IF (this%ISCL < 0) this%ISCL = 0
185 IF (this%ISCL > 2) THEN
186 WRITE (errmsg, '(A)') 'IMSLINEAR7AR ISCL MUST BE <= 2'
187 call store_error(errmsg)
188 END IF
189 IF (this%IORD < 0) this%IORD = 0
190 IF (this%IORD > 2) THEN
191 WRITE (errmsg, '(A)') 'IMSLINEAR7AR IORD MUST BE <= 2'
192 call store_error(errmsg)
193 END IF
194 IF (this%NORTH < 0) THEN
195 WRITE (errmsg, '(A)') 'IMSLINEAR7AR NORTH MUST >= 0'
196 call store_error(errmsg)
197 END IF
198 IF (this%RCLOSE == dzero) THEN
199 IF (this%ICNVGOPT /= 3) THEN
200 WRITE (errmsg, '(A)') 'IMSLINEAR7AR RCLOSE MUST > 0.0'
201 call store_error(errmsg)
202 END IF
203 END IF
204 IF (this%RELAX < dzero) THEN
205 WRITE (errmsg, '(A)') 'IMSLINEAR7AR RELAX MUST BE >= 0.0'
206 call store_error(errmsg)
207 END IF
208 IF (this%RELAX > done) THEN
209 WRITE (errmsg, '(A)') 'IMSLINEAR7AR RELAX MUST BE <= 1.0'
210 call store_error(errmsg)
211 END IF
212 !
213 ! -- INITIALIZE IMSLINEAR VARIABLES
214 this%NITERC = 0
215 !
216 ! -- ALLOCATE AND INITIALIZE MEMORY FOR IMSLINEAR
217 iscllen = 1
218 IF (this%ISCL .NE. 0) iscllen = neq
219 CALL mem_allocate(this%DSCALE, iscllen, 'DSCALE', trim(this%memoryPath))
220 CALL mem_allocate(this%DSCALE2, iscllen, 'DSCALE2', trim(this%memoryPath))
221 CALL mem_allocate(this%RSCALE, iscllen, 'RSCALE', trim(this%memoryPath))
222 CALL mem_allocate(this%HSCALE, iscllen, 'HSCALE', trim(this%memoryPath))
223 !
224 ! -- allocate and initialize the preconditioner work arrays
225 call precond_allocate(this)
226 !
227 ! -- ALLOCATE SPACE FOR PERMUTATION VECTOR
228 i0 = 1
229 iolen = 1
230 IF (this%IORD .NE. 0) THEN
231 i0 = this%NEQ
232 iolen = this%NJA
233 END IF
234 CALL mem_allocate(this%LORDER, i0, 'LORDER', trim(this%memoryPath))
235 CALL mem_allocate(this%IORDER, i0, 'IORDER', trim(this%memoryPath))
236 CALL mem_allocate(this%IARO, i0 + 1, 'IARO', trim(this%memoryPath))
237 CALL mem_allocate(this%JARO, iolen, 'JARO', trim(this%memoryPath))
238 CALL mem_allocate(this%ARO, iolen, 'ARO', trim(this%memoryPath))
239 !
240 ! -- ALLOCATE WORKING VECTORS FOR IMSLINEAR SOLVER
241 CALL mem_allocate(this%ID, this%NEQ, 'ID', trim(this%memoryPath))
242 CALL mem_allocate(this%D, this%NEQ, 'D', trim(this%memoryPath))
243 CALL mem_allocate(this%P, this%NEQ, 'P', trim(this%memoryPath))
244 CALL mem_allocate(this%Q, this%NEQ, 'Q', trim(this%memoryPath))
245 CALL mem_allocate(this%Z, this%NEQ, 'Z', trim(this%memoryPath))
246 !
247 ! -- ALLOCATE MEMORY FOR BCGS WORKING ARRAYS
248 this%NIABCGS = 1
249 IF (this%ILINMETH == 2) THEN
250 this%NIABCGS = this%NEQ
251 END IF
252 CALL mem_allocate(this%T, this%NIABCGS, 'T', trim(this%memoryPath))
253 CALL mem_allocate(this%V, this%NIABCGS, 'V', trim(this%memoryPath))
254 CALL mem_allocate(this%DHAT, this%NIABCGS, 'DHAT', trim(this%memoryPath))
255 CALL mem_allocate(this%PHAT, this%NIABCGS, 'PHAT', trim(this%memoryPath))
256 CALL mem_allocate(this%QHAT, this%NIABCGS, 'QHAT', trim(this%memoryPath))
257 !
258 ! -- INITIALIZE IMSLINEAR VECTORS
259 DO n = 1, iscllen
260 this%DSCALE(n) = done
261 this%DSCALE2(n) = done
262 this%RSCALE(n) = done
263 this%HSCALE(n) = done
264 END DO
265 !
266 ! -- WORKING VECTORS
267 DO n = 1, this%NEQ
268 this%ID(n) = izero
269 this%D(n) = dzero
270 this%P(n) = dzero
271 this%Q(n) = dzero
272 this%Z(n) = dzero
273 END DO
274 DO n = 1, this%NIAPC
275 this%IW(n) = izero
276 this%W(n) = dzero
277 END DO
278 !
279 ! -- BCGS WORKING VECTORS
280 DO n = 1, this%NIABCGS
281 this%T(n) = dzero
282 this%V(n) = dzero
283 this%DHAT(n) = dzero
284 this%PHAT(n) = dzero
285 this%QHAT(n) = dzero
286 END DO
287 !
288 ! -- ILUT AND MILUT WORKING VECTORS
289 DO n = 1, this%NJLU
290 this%JLU(n) = izero
291 END DO
292 DO n = 1, this%NJW
293 this%JW(n) = izero
294 END DO
295 DO n = 1, this%NWLU
296 this%WLU(n) = dzero
297 END DO
298 !
299 ! -- REORDERING VECTORS
300 DO n = 1, i0 + 1
301 this%IARO(n) = izero
302 END DO
303 DO n = 1, iolen
304 this%JARO(n) = izero
305 this%ARO(n) = dzero
306 END DO
307 !
308 ! -- REVERSE CUTHILL MCKEE AND MINIMUM DEGREE ORDERING
309 IF (this%IORD .NE. 0) THEN
310 CALL ims_base_calc_order(this%IORD, this%NEQ, this%NJA, this%IA, &
311 this%JA, this%LORDER, this%IORDER)
312 END IF
313 !
314 ! -- ALLOCATE MEMORY FOR STORING ITERATION CONVERGENCE DATA
315 end SUBROUTINE imslinear_ar
316
317 !> @brief Write summary of settings
318 !!
319 !! Write summary of linear accelerator settings.
320 !!
321 !<
322 subroutine imslinear_summary(this, mxiter)
323 ! -- dummy variables
324 class(imslineardatatype), intent(inout) :: this !< ImsLinearDataType instance
325 integer(I4B), intent(in) :: mxiter !< maximum number of outer iterations
326 ! -- local variables
327 CHARACTER(LEN=10) :: clin(0:2)
328 CHARACTER(LEN=31) :: clintit(0:2)
329 CHARACTER(LEN=20) :: cipc(0:4)
330 CHARACTER(LEN=20) :: cscale(0:2)
331 CHARACTER(LEN=25) :: corder(0:2)
332 CHARACTER(LEN=16), DIMENSION(0:4) :: ccnvgopt
333 CHARACTER(LEN=15) :: clevel
334 CHARACTER(LEN=15) :: cdroptol
335 integer(I4B) :: i
336 integer(I4B) :: j
337 ! -- data
338 DATA clin/'UNKNOWN ', &
339 &'CG ', &
340 &'BCGS '/
341 DATA clintit/' UNKNOWN ', &
342 &' CONJUGATE-GRADIENT ', &
343 &'BICONJUGATE-GRADIENT STABILIZED'/
344 DATA cipc/'UNKNOWN ', &
345 &'INCOMPLETE LU ', &
346 &'MOD. INCOMPLETE LU ', &
347 &'INCOMPLETE LUT ', &
348 &'MOD. INCOMPLETE LUT '/
349 DATA cscale/'NO SCALING ', &
350 &'SYMMETRIC SCALING ', &
351 &'L2 NORM SCALING '/
352 DATA corder/'ORIGINAL ORDERING ', &
353 &'RCM ORDERING ', &
354 &'MINIMUM DEGREE ORDERING '/
355 DATA ccnvgopt/'INFINITY NORM ', &
356 &'INFINITY NORM S ', &
357 &'L2 NORM ', &
358 &'RELATIVE L2NORM ', &
359 &'L2 NORM W. REL. '/
360 ! -- formats
36102010 FORMAT(1x, /, 7x, 'SOLUTION BY THE', 1x, a31, 1x, 'METHOD', &
362 /, 1x, 66('-'), /, &
363 ' MAXIMUM OF ', i0, ' CALLS OF SOLUTION ROUTINE', /, &
364 ' MAXIMUM OF ', i0, &
365 ' INTERNAL ITERATIONS PER CALL TO SOLUTION ROUTINE', /, &
366 ' LINEAR ACCELERATION METHOD =', 1x, a, /, &
367 ' MATRIX PRECONDITIONING TYPE =', 1x, a, /, &
368 ' MATRIX SCALING APPROACH =', 1x, a, /, &
369 ' MATRIX REORDERING APPROACH =', 1x, a, /, &
370 ' NUMBER OF ORTHOGONALIZATIONS =', 1x, i0, /, &
371 ' HEAD CHANGE CRITERION FOR CLOSURE =', e15.5, /, &
372 ' RESIDUAL CHANGE CRITERION FOR CLOSURE =', e15.5, /, &
373 ' RESIDUAL CONVERGENCE OPTION =', 1x, i0, /, &
374 ' RESIDUAL CONVERGENCE NORM =', 1x, a, /, &
375 ' RELAXATION FACTOR =', e15.5)
37602015 FORMAT(' NUMBER OF LEVELS =', a15, /, &
377 ' DROP TOLERANCE =', a15, //)
3782030 FORMAT(1x, a20, 1x, 6(i6, 1x))
3792040 FORMAT(1x, 20('-'), 1x, 6(6('-'), 1x))
3802050 FORMAT(1x, 62('-'),/) !
381! -- -----------------------------------------------------------
382 !
383 ! -- initialize clevel and cdroptol
384 clevel = ''
385 cdroptol = ''
386 !
387 ! -- write common variables to all linear accelerators
388 write (this%iout, 2010) &
389 clintit(this%ILINMETH), mxiter, this%ITER1, &
390 clin(this%ILINMETH), cipc(this%IPC), &
391 cscale(this%ISCL), corder(this%IORD), &
392 this%NORTH, this%DVCLOSE, this%RCLOSE, &
393 this%ICNVGOPT, ccnvgopt(this%ICNVGOPT), &
394 this%RELAX
395 if (this%level > 0) then
396 write (clevel, '(i15)') this%level
397 end if
398 if (this%droptol > dzero) then
399 write (cdroptol, '(e15.5)') this%droptol
400 end if
401 IF (this%level > 0 .or. this%droptol > dzero) THEN
402 write (this%iout, 2015) trim(adjustl(clevel)), &
403 trim(adjustl(cdroptol))
404 ELSE
405 write (this%iout, '(//)')
406 END IF
407
408 if (this%iord /= 0) then
409 !
410 ! -- WRITE SUMMARY OF REORDERING INFORMATION TO LIST FILE
411 if (this%iprims == 2) then
412 DO i = 1, this%neq, 6
413 write (this%iout, 2030) 'ORIGINAL NODE :', &
414 (j, j=i, min(i + 5, this%neq))
415 write (this%iout, 2040)
416 write (this%iout, 2030) 'REORDERED INDEX :', &
417 (this%lorder(j), j=i, min(i + 5, this%neq))
418 write (this%iout, 2030) 'REORDERED NODE :', &
419 (this%iorder(j), j=i, min(i + 5, this%neq))
420 write (this%iout, 2050)
421 END DO
422 END IF
423 end if
424 end subroutine imslinear_summary
425
426 !> @brief Allocate and initialize scalars
427 !!
428 !! Allocate and initialize linear accelerator scalars
429 !!
430 !<
431 subroutine allocate_scalars(this)
432 ! -- modules
434 ! -- dummy variables
435 class(imslineardatatype), intent(inout) :: this !< ImsLinearDataType instance
436 !
437 ! -- allocate scalars
438 call mem_allocate(this%iout, 'IOUT', this%memoryPath)
439 call mem_allocate(this%ipc, 'IPC', this%memoryPath)
440 call mem_allocate(this%iacpc, 'IACPC', this%memoryPath)
441 call mem_allocate(this%niterc, 'NITERC', this%memoryPath)
442 call mem_allocate(this%niabcgs, 'NIABCGS', this%memoryPath)
443 call mem_allocate(this%niapc, 'NIAPC', this%memoryPath)
444 call mem_allocate(this%njapc, 'NJAPC', this%memoryPath)
445 call mem_allocate(this%epfact, 'EPFACT', this%memoryPath)
446 call mem_allocate(this%l2norm0, 'L2NORM0', this%memoryPath)
447 call mem_allocate(this%njlu, 'NJLU', this%memoryPath)
448 call mem_allocate(this%njw, 'NJW', this%memoryPath)
449 call mem_allocate(this%nwlu, 'NWLU', this%memoryPath)
450 !
451 ! -- initialize scalars
452 this%iout = 0
453 this%ipc = 0
454 this%iacpc = 0
455 this%niterc = 0
456 this%niabcgs = 0
457 this%niapc = 0
458 this%njapc = 0
459 this%epfact = dzero
460 this%l2norm0 = 0
461 this%njlu = 0
462 this%njw = 0
463 this%nwlu = 0
464 end subroutine allocate_scalars
465
466 !> @brief Deallocate memory
467 !!
468 !! Deallocate linear accelerator memory.
469 !!
470 !<
471 subroutine imslinear_da(this)
472 ! -- modules
474 ! -- dummy variables
475 class(imslineardatatype), intent(inout) :: this !< linear datatype instance
476 !
477 ! -- arrays
478 call mem_deallocate(this%dscale)
479 call mem_deallocate(this%dscale2)
480 call mem_deallocate(this%rscale)
481 call mem_deallocate(this%hscale)
482 call precond_destroy(this)
483 call mem_deallocate(this%lorder)
484 call mem_deallocate(this%iorder)
485 call mem_deallocate(this%iaro)
486 call mem_deallocate(this%jaro)
487 call mem_deallocate(this%aro)
488 call mem_deallocate(this%id)
489 call mem_deallocate(this%d)
490 call mem_deallocate(this%p)
491 call mem_deallocate(this%q)
492 call mem_deallocate(this%z)
493 call mem_deallocate(this%t)
494 call mem_deallocate(this%v)
495 call mem_deallocate(this%dhat)
496 call mem_deallocate(this%phat)
497 call mem_deallocate(this%qhat)
498 !
499 ! -- scalars
500 call mem_deallocate(this%iout)
501 call mem_deallocate(this%ipc)
502 call mem_deallocate(this%iacpc)
503 call mem_deallocate(this%niterc)
504 call mem_deallocate(this%niabcgs)
505 call mem_deallocate(this%niapc)
506 call mem_deallocate(this%njapc)
507 call mem_deallocate(this%epfact)
508 call mem_deallocate(this%l2norm0)
509 call mem_deallocate(this%njlu)
510 call mem_deallocate(this%njw)
511 call mem_deallocate(this%nwlu)
512 call mem_deallocate(this%NJA)
513 !
514 ! -- nullify pointers
515 nullify (this%iprims)
516 nullify (this%neq)
517 nullify (this%nja)
518 nullify (this%ia)
519 nullify (this%ja)
520 nullify (this%amat)
521 nullify (this%rhs)
522 nullify (this%x)
523 end subroutine imslinear_da
524
525 !> @brief Allocate and initialize the preconditioner work arrays
526 !!
527 !! Determines the preconditioner array dimensions from the current
528 !! NEQ/NJA/LEVEL/IPC and allocates the ILU-family work arrays
529 !! (IAPC/JAPC/APC/IW/W/JLU/JW/WLU); for ILU0/MILU0 the IAPC/JAPC sparsity is
530 !! generated. Separated from imslinear_ar so the preconditioner can be
531 !! (re)allocated at runtime.
532 !<
533 subroutine precond_allocate(this)
535 ! -- dummy variables
536 class(imslineardatatype), intent(inout) :: this !< ImsLinearDataType instance
537 ! -- local variables
538 integer(I4B) :: n
539 !
540 ! -- release any existing preconditioner arrays so this routine is
541 ! idempotent and can be called again to reallocate at runtime
542 if (associated(this%IAPC)) call precond_destroy(this)
543 !
544 ! -- determine dimensions for preconditioning arrays
545 call ims_calc_pcdims(this%NEQ, this%NJA, this%IA, this%LEVEL, this%IPC, &
546 this%NIAPC, this%NJAPC, this%NJLU, this%NJW, this%NWLU)
547 !
548 ! -- allocate base preconditioner vectors
549 call mem_allocate(this%IAPC, this%NIAPC + 1, 'IAPC', trim(this%memoryPath))
550 call mem_allocate(this%JAPC, this%NJAPC, 'JAPC', trim(this%memoryPath))
551 call mem_allocate(this%APC, this%NJAPC, 'APC', trim(this%memoryPath))
552 !
553 ! -- allocate ILU0/MILU0 non-zero row entry vectors
554 call mem_allocate(this%IW, this%NIAPC, 'IW', trim(this%memoryPath))
555 call mem_allocate(this%W, this%NIAPC, 'W', trim(this%memoryPath))
556 !
557 ! -- allocate ILUT vectors
558 call mem_allocate(this%JLU, this%NJLU, 'JLU', trim(this%memoryPath))
559 call mem_allocate(this%JW, this%NJW, 'JW', trim(this%memoryPath))
560 call mem_allocate(this%WLU, this%NWLU, 'WLU', trim(this%memoryPath))
561 !
562 ! -- generate IAPC and JAPC for ILU0 and MILU0
563 if (this%IPC == ipc_ilu0 .or. this%IPC == ipc_milu0) then
564 call ims_base_pccrs(this%NEQ, this%NJA, this%IA, this%JA, &
565 this%IAPC, this%JAPC)
566 end if
567 !
568 ! -- initialize preconditioner values
569 do n = 1, this%NJAPC
570 this%APC(n) = dzero
571 end do
572 end subroutine precond_allocate
573
574 !> @brief Deallocate the preconditioner work arrays
575 !!
576 !! Preconditioner-only teardown, separated from imslinear_da so the
577 !! preconditioner can be destroyed and reallocated at runtime without
578 !! disturbing the solver work arrays.
579 !<
580 subroutine precond_destroy(this)
582 ! -- dummy variables
583 class(imslineardatatype), intent(inout) :: this !< ImsLinearDataType instance
584 !
585 ! -- mem_deallocate is a no-op in the memory manager, so releasing the named
586 ! store entries (and nullifying the aliases below) is what actually frees
587 ! these arrays and lets the preconditioner be reallocated at runtime
588 call memorystore_release('IAPC', trim(this%memoryPath))
589 call memorystore_release('JAPC', trim(this%memoryPath))
590 call memorystore_release('APC', trim(this%memoryPath))
591 call memorystore_release('IW', trim(this%memoryPath))
592 call memorystore_release('W', trim(this%memoryPath))
593 call memorystore_release('JLU', trim(this%memoryPath))
594 call memorystore_release('JW', trim(this%memoryPath))
595 call memorystore_release('WLU', trim(this%memoryPath))
596 !
597 nullify (this%IAPC)
598 nullify (this%JAPC)
599 nullify (this%APC)
600 nullify (this%IW)
601 nullify (this%W)
602 nullify (this%JLU)
603 nullify (this%JW)
604 nullify (this%WLU)
605 end subroutine precond_destroy
606
607 !> @brief Set default settings
608 !!
609 !! Set default linear accelerator settings.
610 !!
611 !<
612 SUBROUTINE imslinear_set_input(this, IFDPARAM)
613 ! -- dummy variables
614 CLASS(imslineardatatype), INTENT(INOUT) :: this !< ImsLinearDataType instance
615 integer(I4B), INTENT(IN) :: IFDPARAM !< complexity option
616 ! -- code
617 SELECT CASE (ifdparam)
618 !
619 ! -- Simple option
620 CASE (1)
621 this%ITER1 = 50
622 this%ILINMETH = 1
623 this%IPC = ipc_ilu0
624 this%ISCL = 0
625 this%IORD = 0
626 this%DVCLOSE = dem3
627 this%RCLOSE = dem1
628 this%RELAX = dzero
629 this%LEVEL = 0
630 this%DROPTOL = dzero
631 this%NORTH = 0
632 !
633 ! -- Moderate
634 CASE (2)
635 this%ITER1 = 100
636 this%ILINMETH = 2
637 this%IPC = ipc_milu0
638 this%ISCL = 0
639 this%IORD = 0
640 this%DVCLOSE = dem2
641 this%RCLOSE = dem1
642 this%RELAX = 0.97d0
643 this%LEVEL = 0
644 this%DROPTOL = dzero
645 this%NORTH = 0
646 !
647 ! -- Complex
648 CASE (3)
649 this%ITER1 = 500
650 this%ILINMETH = 2
651 this%IPC = ipc_ilut
652 this%ISCL = 0
653 this%IORD = 0
654 this%DVCLOSE = dem1
655 this%RCLOSE = dem1
656 this%RELAX = dzero
657 this%LEVEL = 5
658 this%DROPTOL = dem4
659 this%NORTH = 2
660 END SELECT
661 end SUBROUTINE imslinear_set_input
662
663 !> @brief Base linear accelerator subroutine
664 !!
665 !! Base linear accelerator subroutine that scales and reorders
666 !! the system of equations, if necessary, updates the preconditioner,
667 !! and calls the appropriate linear accelerator.
668 !!
669 !<
670 SUBROUTINE imslinear_ap(this, ICNVG, KSTP, KITER, IN_ITER, &
671 NCONV, CONVNMOD, CONVMODSTART, &
672 CACCEL, summary)
673 ! -- modules
674 USE simmodule
675 ! -- dummy variables
676 CLASS(imslineardatatype), INTENT(INOUT) :: this !< ImsLinearDataType instance
677 integer(I4B), INTENT(INOUT) :: ICNVG !< convergence flag (1) non-convergence (0)
678 integer(I4B), INTENT(IN) :: KSTP !< time step number
679 integer(I4B), INTENT(IN) :: KITER !< outer iteration number
680 integer(I4B), INTENT(INOUT) :: IN_ITER !< inner iteration number
681 ! -- convergence information dummy variables
682 integer(I4B), INTENT(IN) :: NCONV !<
683 integer(I4B), INTENT(IN) :: CONVNMOD !<
684 integer(I4B), DIMENSION(CONVNMOD + 1), INTENT(INOUT) :: CONVMODSTART !<
685 character(len=31), DIMENSION(NCONV), INTENT(INOUT) :: CACCEL !<
686 type(convergencesummarytype), pointer, intent(in) :: summary !< Convergence summary report
687 ! -- local variables
688 integer(I4B) :: n
689 integer(I4B) :: innerit
690 integer(I4B) :: irc
691 integer(I4B) :: itmax
692 real(DP) :: dnrm2
693 !
694 ! -- set epfact based on timestep
695 this%EPFACT = ims_base_epfact(this%ICNVGOPT, kstp)
696 !
697 ! -- SCALE PROBLEM
698 IF (this%ISCL .NE. 0) THEN
699 CALL ims_base_scale(0, this%ISCL, &
700 this%NEQ, this%NJA, this%IA, this%JA, &
701 this%AMAT, this%X, this%RHS, &
702 this%DSCALE, this%DSCALE2)
703 END IF
704 !
705 ! -- PERMUTE ROWS, COLUMNS, AND RHS
706 IF (this%IORD /= 0) THEN
707 CALL dperm(this%NEQ, this%AMAT, this%JA, this%IA, &
708 this%ARO, this%JARO, this%IARO, &
709 this%LORDER, this%ID, 1)
710 CALL dvperm(this%NEQ, this%X, this%LORDER)
711 CALL dvperm(this%NEQ, this%RHS, this%LORDER)
712 this%IA0 => this%IARO
713 this%JA0 => this%JARO
714 this%A0 => this%ARO
715 ELSE
716 this%IA0 => this%IA
717 this%JA0 => this%JA
718 this%A0 => this%AMAT
719 END IF
720 !
721 ! -- FACTORS RETURNING THE RESIDUAL AND HEAD CHANGE TO MODEL UNITS
722 IF (this%ISCL /= 0) THEN
723 CALL ims_base_cnvg_scale(this%NEQ, this%IORD, this%DSCALE, &
724 this%DSCALE2, this%LORDER, &
725 this%RSCALE, this%HSCALE)
726 END IF
727 !
728 ! -- UPDATE PRECONDITIONER
729 CALL ims_base_pcu(this%iout, this%NJA, this%NEQ, this%NIAPC, this%NJAPC, &
730 this%IPC, this%RELAX, this%A0, this%IA0, this%JA0, &
731 this%APC, this%IAPC, this%JAPC, this%IW, this%W, &
732 this%LEVEL, this%DROPTOL, this%NJLU, this%NJW, &
733 this%NWLU, this%JLU, this%JW, this%WLU)
734 !
735 ! -- INITIALIZE SOLUTION VARIABLE AND ARRAYS
736 IF (kiter == 1) then
737 this%NITERC = 0
738 summary%iter_cnt = 0
739 end if
740 irc = 1
741 icnvg = 0
742 DO n = 1, this%NEQ
743 this%D(n) = dzero
744 this%P(n) = dzero
745 this%Q(n) = dzero
746 this%Z(n) = dzero
747 END DO
748 !
749 ! -- CALCULATE INITIAL RESIDUAL
750 call ims_base_residual(this%NEQ, this%NJA, this%X, this%RHS, this%D, &
751 this%A0, this%IA0, this%JA0)
752 IF (this%ISCL /= 0) THEN
753 this%L2NORM0 = dzero
754 DO n = 1, this%NEQ
755 this%L2NORM0 = this%L2NORM0 + (this%D(n) * this%RSCALE(n))**2
756 END DO
757 this%L2NORM0 = sqrt(this%L2NORM0)
758 ELSE
759 this%L2NORM0 = dnrm2(this%NEQ, this%D, 1)
760 END IF
761 !
762 ! -- CHECK FOR EXACT SOLUTION
763 itmax = this%ITER1
764 IF (this%L2NORM0 == dzero) THEN
765 itmax = 0
766 icnvg = 1
767 END IF
768 !
769 ! -- SOLUTION BY THE CONJUGATE GRADIENT METHOD
770 IF (this%ILINMETH == 1) THEN
771 CALL ims_base_cg(icnvg, itmax, innerit, &
772 this%NEQ, this%NJA, this%NIAPC, this%NJAPC, &
773 this%IPC, this%ICNVGOPT, this%NORTH, &
774 this%ISCL, this%RSCALE, this%HSCALE, &
775 this%DVCLOSE, this%RCLOSE, this%L2NORM0, &
776 this%EPFACT, this%IA0, this%JA0, this%A0, &
777 this%IAPC, this%JAPC, this%APC, &
778 this%X, this%RHS, this%D, this%P, this%Q, this%Z, &
779 this%NJLU, this%IW, this%JLU, &
780 nconv, convnmod, convmodstart, &
781 caccel, summary)
782 !
783 ! -- SOLUTION BY THE BICONJUGATE GRADIENT STABILIZED METHOD
784 ELSE IF (this%ILINMETH == 2) THEN
785 CALL ims_base_bcgs(icnvg, itmax, innerit, &
786 this%NEQ, this%NJA, this%NIAPC, this%NJAPC, &
787 this%IPC, this%ICNVGOPT, this%NORTH, &
788 this%ISCL, this%RSCALE, this%HSCALE, &
789 this%DVCLOSE, this%RCLOSE, this%L2NORM0, &
790 this%EPFACT, this%IA0, this%JA0, this%A0, &
791 this%IAPC, this%JAPC, this%APC, &
792 this%X, this%RHS, this%D, this%P, this%Q, &
793 this%T, this%V, this%DHAT, this%PHAT, this%QHAT, &
794 this%NJLU, this%IW, this%JLU, &
795 nconv, convnmod, convmodstart, &
796 caccel, summary)
797 END IF
798 !
799 ! -- BACK PERMUTE AMAT, SOLUTION, AND RHS
800 IF (this%IORD /= 0) THEN
801 CALL dperm(this%NEQ, this%A0, this%JA0, this%IA0, &
802 this%AMAT, this%JA, this%IA, &
803 this%IORDER, this%ID, 1)
804 CALL dvperm(this%NEQ, this%X, this%IORDER)
805 CALL dvperm(this%NEQ, this%RHS, this%IORDER)
806 END IF
807 !
808 ! -- UNSCALE PROBLEM
809 IF (this%ISCL .NE. 0) THEN
810 CALL ims_base_scale(1, this%ISCL, &
811 this%NEQ, this%NJA, this%IA, this%JA, &
812 this%AMAT, this%X, this%RHS, &
813 this%DSCALE, this%DSCALE2)
814 END IF
815 !
816 ! -- SET IMS INNER ITERATION NUMBER (IN_ITER) TO NUMBER OF
817 ! IMSLINEAR INNER ITERATIONS (innerit)
818 in_iter = innerit
819 end SUBROUTINE imslinear_ap
820
821END MODULE imslinearmodule
This module contains block parser methods.
This module contains simulation constants.
Definition Constants.f90:9
real(dp), parameter dsame
real constant for values that are considered the same based on machine precision
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
integer(i4b), parameter lensolutionname
maximum length of the solution name
Definition Constants.f90:21
real(dp), parameter dem8
real constant 1e-8
real(dp), parameter dem1
real constant 1e-1
real(dp), parameter dhalf
real constant 1/2
Definition Constants.f90:68
real(dp), parameter dem3
real constant 1e-3
integer(i4b), parameter izero
integer constant zero
Definition Constants.f90:51
real(dp), parameter dem4
real constant 1e-4
real(dp), parameter dem6
real constant 1e-6
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65
real(dp), parameter dem5
real constant 1e-5
real(dp), parameter dprec
real constant machine precision
@ vdebug
write debug output
real(dp), parameter dem2
real constant 1e-2
real(dp), parameter dtwo
real constant 2
Definition Constants.f90:79
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition Constants.f90:27
real(dp), parameter done
real constant 1
Definition Constants.f90:76
This module contains the IMS linear accelerator subroutines.
subroutine ims_base_pcu(iout, nja, neq, niapc, njapc, ipc, relax, amat, ia, ja, apc, iapc, japc, iw, w, level, droptol, njlu, njw, nwlu, jlu, jw, wlu)
Update the preconditioner.
subroutine ims_calc_pcdims(neq, nja, ia, level, ipc, niapc, njapc, njlu, njw, nwlu)
real(dp) function ims_base_epfact(icnvgopt, kstp)
Function returning EPFACT.
subroutine ims_base_residual(neq, nja, x, b, d, a, ia, ja)
Calculate residual.
subroutine ims_base_cnvg_scale(neq, iord, dscale, dscale2, lorder, rscale, hscale)
Set the factors that return the residual and head change to model units, in the order of the reordere...
subroutine ims_base_cg(icnvg, itmax, innerit, neq, nja, niapc, njapc, ipc, icnvgopt, north, iscl, rscale, hscale, dvclose, rclose, l2norm0, epfact, ia0, ja0, a0, iapc, japc, apc, x, b, d, p, q, z, njlu, iw, jlu, nconv, convnmod, convmodstart, caccel, summary)
Preconditioned Conjugate Gradient linear accelerator.
subroutine ims_base_calc_order(iord, neq, nja, ia, ja, lorder, iorder)
Calculate LORDER AND IORDER.
subroutine ims_base_bcgs(icnvg, itmax, innerit, neq, nja, niapc, njapc, ipc, icnvgopt, north, iscl, rscale, hscale, dvclose, rclose, l2norm0, epfact, ia0, ja0, a0, iapc, japc, apc, x, b, d, p, q, t, v, dhat, phat, qhat, njlu, iw, jlu, nconv, convnmod, convmodstart, caccel, summary)
Preconditioned BiConjugate Gradient Stabilized linear accelerator.
subroutine ims_base_scale(iopt, iscl, neq, nja, ia, ja, amat, x, b, dscale, dscale2)
Scale the coefficient matrix.
subroutine ims_base_pccrs(neq, nja, ia, ja, iapc, japc)
Generate CRS pointers for the preconditioner.
subroutine allocate_scalars(this)
Allocate and initialize scalars.
subroutine precond_allocate(this)
Allocate and initialize the preconditioner work arrays.
subroutine imslinear_summary(this, mxiter)
Write summary of settings.
subroutine imslinear_da(this)
Deallocate memory.
subroutine precond_destroy(this)
Deallocate the preconditioner work arrays.
subroutine imslinear_ar(this, name, iout, iprims, mxiter, neq, matrix, rhs, x, linear_settings)
Allocate storage and read data.
subroutine imslinear_set_input(this, ifdparam)
Set default settings.
subroutine imslinear_ap(this, icnvg, kstp, kiter, in_iter, nconv, convnmod, convmodstart, caccel, summary)
Base linear accelerator subroutine.
@ ipc_ilut
ILUT (incomplete LU with threshold).
@ ipc_ilu0
ILU0 (incomplete LU, zero fill).
@ ipc_unknown
preconditioner type not set
pure integer(i4b) function, public resolve_ipc(level, relax)
Resolve the preconditioner enum from the ILU controls.
This module defines variable data types.
Definition kind.f90:8
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
subroutine, public memorystore_release(varname, memory_path)
Release a single variable from the memory store.
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 deprecation_warning(cblock, cvar, cver, endmsg, iunit)
Store deprecation warning message.
Definition Sim.f90:261
subroutine dvperm(n, x, perm)
Definition sparsekit.f90:62
subroutine dperm(nrow, a, ja, ia, ao, jao, iao, perm, qperm, job)
This structure stores the generic convergence info for a solution.