2 #include <petsc/finclude/petscksp.h>
6 use petscmatrixmodule,
only: petscmatrixtype
18 character(len=9),
dimension(4) ::
ims_pc_type = [
"IMS ILU0 ", &
24 character(len=LENMEMPATH) :: memory_path
25 class(petscmatrixtype),
pointer :: system_matrix
30 integer(I4B),
dimension(:),
contiguous,
pointer :: iapc => null()
31 integer(I4B),
dimension(:),
contiguous,
pointer :: japc => null()
32 real(dp),
dimension(:),
contiguous,
pointer :: apc => null()
34 integer(I4B),
dimension(:),
contiguous,
pointer :: iw => null()
35 real(dp),
dimension(:),
contiguous,
pointer :: w => null()
36 integer(I4B),
dimension(:),
contiguous,
pointer :: jlu => null()
37 integer(I4B),
dimension(:),
contiguous,
pointer :: jw => null()
38 real(dp),
dimension(:),
contiguous,
pointer :: wlu => null()
46 subroutine pcshellgetcontext(pc, ctx, ierr)
62 class(petscmatrixtype),
pointer :: matrix
65 integer(I4B) :: n, neq, nja
66 integer(I4B),
dimension(:),
contiguous,
pointer :: ia, ja
67 real(DP),
dimension(:),
contiguous,
pointer :: amat
68 integer(I4B) :: niapc, njapc, njlu, njw, nwlu
70 this%memory_path = matrix%memory_path
71 this%linear_settings => lin_settings
74 if (this%linear_settings%level > 0)
then
75 this%ipc = this%ipc + 2
77 if (this%linear_settings%relax > 0.0_dp) this%ipc = this%ipc + 1
80 this%system_matrix => matrix
81 call matrix%get_aij_local(ia, ja, amat)
84 nja = matrix%nnz_local
85 call ims_calc_pcdims(neq, nja, ia, this%linear_settings%level, this%ipc, &
86 niapc, njapc, njlu, njw, nwlu)
89 call mem_allocate(this%IAPC, niapc + 1,
'IAPC', this%memory_path)
90 call mem_allocate(this%JAPC, njapc,
'JAPC', this%memory_path)
91 call mem_allocate(this%APC, njapc,
'APC', this%memory_path)
92 if (this%ipc == 1 .or. this%ipc == 2)
then
100 call mem_allocate(this%IW, niapc,
'IW', this%memory_path)
108 call mem_allocate(this%JLU, njlu,
'JLU', this%memory_path)
110 call mem_allocate(this%WLU, nwlu,
'WLU', this%memory_path)
142 this%system_matrix => null()
154 petscerrorcode :: ierr
157 real(dp),
dimension(:),
pointer :: local_x, local_y
158 integer(I4B) :: neq, nja
160 call pcshellgetcontext(pc, pc_ctx, ierr)
163 call vecgetarrayreadf90(x, local_x, ierr)
165 call vecgetarrayf90(y, local_y, ierr)
168 neq = pc_ctx%system_matrix%nrow
169 nja = pc_ctx%system_matrix%nnz_local
170 select case (pc_ctx%ipc)
172 call ims_base_ilu0a(nja, neq, pc_ctx%APC, pc_ctx%IAPC, pc_ctx%JAPC, &
175 call lusol(neq, local_x, local_y, pc_ctx%APC, pc_ctx%JLU, pc_ctx%IW)
178 call vecrestorearrayf90(x, local_x, ierr)
180 call vecrestorearrayf90(y, local_y, ierr)
190 petscerrorcode :: ierr
193 integer(I4B) :: neq, nja
194 integer(I4B) :: niapc, njapc, njlu, njw, nwlu
195 integer(I4B),
dimension(:),
contiguous,
pointer :: ia, ja
196 real(dp),
dimension(:),
contiguous,
pointer :: amat
198 call pcshellgetcontext(pc, pc_ctx, ierr)
203 call pc_ctx%system_matrix%get_aij_local(ia, ja, amat)
205 neq = pc_ctx%system_matrix%nrow
206 nja = pc_ctx%system_matrix%nnz_local
207 niapc =
size(pc_ctx%IAPC) - 1
208 njapc =
size(pc_ctx%JAPC)
209 njlu =
size(pc_ctx%JLU)
210 njw =
size(pc_ctx%JW)
211 nwlu =
size(pc_ctx%WLU)
213 pc_ctx%ipc, pc_ctx%linear_settings%relax, &
215 pc_ctx%APC, pc_ctx%IAPC, pc_ctx%JAPC, &
216 pc_ctx%IW, pc_ctx%W, &
217 pc_ctx%linear_settings%level, &
218 pc_ctx%linear_settings%droptol, &
220 pc_ctx%JLU, pc_ctx%JW, pc_ctx%WLU)
subroutine lusol(n, y, x, alu, jlu, ju)
This module contains simulation constants.
integer(i4b), parameter izero
integer constant zero
real(dp), parameter dzero
real constant zero
integer(i4b), parameter lenmempath
maximum length of the memory path
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)
@ brief Update the preconditioner
subroutine ims_base_pccrs(NEQ, NJA, IA, JA, IAPC, JAPC)
@ brief Generate CRS pointers for the preconditioner
subroutine ims_calc_pcdims(neq, nja, ia, level, ipc, niapc, njapc, njlu, njw, nwlu)
subroutine ims_base_ilu0a(NJA, NEQ, APC, IAPC, JAPC, R, D)
@ brief Apply the ILU0 and MILU0 preconditioners
This module defines variable data types.
subroutine, public pcshell_setup(pc, ierr)
Set up the custom preconditioner.
subroutine pctx_destroy(this)
Cleanup the context.
subroutine, public pcshell_apply(pc, x, y, ierr)
Apply shell preconditioner.
subroutine pctx_create(this, matrix, lin_settings)
Create the preconditioner context from the system matrix.
character(len=9), dimension(4) ims_pc_type
This module contains simulation variables.
integer(i4b) iout
file unit number for simulation output