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) this%ipc = this%ipc + 2
75 if (this%linear_settings%relax > 0.0_dp) this%ipc = this%ipc + 1
78 this%system_matrix => matrix
79 call matrix%get_aij_local(ia, ja, amat)
82 nja = matrix%nnz_local
83 call ims_calc_pcdims(neq, nja, ia, this%linear_settings%level, this%ipc, &
84 niapc, njapc, njlu, njw, nwlu)
87 call mem_allocate(this%IAPC, niapc + 1,
'IAPC', this%memory_path)
88 call mem_allocate(this%JAPC, njapc,
'JAPC', this%memory_path)
89 call mem_allocate(this%APC, njapc,
'APC', this%memory_path)
90 if (this%ipc == 1 .or. this%ipc == 2)
then
98 call mem_allocate(this%IW, niapc,
'IW', this%memory_path)
106 call mem_allocate(this%JLU, njlu,
'JLU', this%memory_path)
108 call mem_allocate(this%WLU, nwlu,
'WLU', this%memory_path)
140 this%system_matrix => null()
152 petscerrorcode :: ierr
155 real(dp),
dimension(:),
pointer :: local_x, local_y
156 integer(I4B) :: neq, nja
158 call pcshellgetcontext(pc, pc_ctx, ierr)
161 call vecgetarrayreadf90(x, local_x, ierr)
163 call vecgetarrayf90(y, local_y, ierr)
166 neq = pc_ctx%system_matrix%nrow
167 nja = pc_ctx%system_matrix%nnz_local
168 select case (pc_ctx%ipc)
170 call ims_base_ilu0a(nja, neq, pc_ctx%APC, pc_ctx%IAPC, pc_ctx%JAPC, &
173 call lusol(neq, local_x, local_y, pc_ctx%APC, pc_ctx%JLU, pc_ctx%IW)
176 call vecrestorearrayf90(x, local_x, ierr)
178 call vecrestorearrayf90(y, local_y, ierr)
188 petscerrorcode :: ierr
191 integer(I4B) :: neq, nja
192 integer(I4B) :: niapc, njapc, njlu, njw, nwlu
193 integer(I4B),
dimension(:),
contiguous,
pointer :: ia, ja
194 real(dp),
dimension(:),
contiguous,
pointer :: amat
196 call pcshellgetcontext(pc, pc_ctx, ierr)
201 call pc_ctx%system_matrix%get_aij_local(ia, ja, amat)
203 neq = pc_ctx%system_matrix%nrow
204 nja = pc_ctx%system_matrix%nnz_local
205 niapc =
size(pc_ctx%IAPC) - 1
206 njapc =
size(pc_ctx%JAPC)
207 njlu =
size(pc_ctx%JLU)
208 njw =
size(pc_ctx%JW)
209 nwlu =
size(pc_ctx%WLU)
211 pc_ctx%ipc, pc_ctx%linear_settings%relax, &
213 pc_ctx%APC, pc_ctx%IAPC, pc_ctx%JAPC, &
214 pc_ctx%IW, pc_ctx%W, &
215 pc_ctx%linear_settings%level, &
216 pc_ctx%linear_settings%droptol, &
218 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