MODFLOW 6  version 6.7.0.dev3
USGS Modular Hydrologic Model
petscimspreconditionermodule Module Reference

Data Types

type  pcshellctxtype
 
interface  PCShellGetContext
 

Functions/Subroutines

subroutine pctx_create (this, matrix, lin_settings)
 Create the preconditioner context from the system matrix. More...
 
subroutine pctx_destroy (this)
 Cleanup the context. More...
 
subroutine, public pcshell_apply (pc, x, y, ierr)
 Apply shell preconditioner. More...
 
subroutine, public pcshell_setup (pc, ierr)
 Set up the custom preconditioner. More...
 

Variables

character(len=9), dimension(4) ims_pc_type = ["IMS ILU0 ", "IMS MILU0", "IMS ILUT ", "IMS MILUT"]
 

Function/Subroutine Documentation

◆ pcshell_apply()

subroutine, public petscimspreconditionermodule::pcshell_apply (   pc,
  x,
  y,
  ierr 
)

Definition at line 148 of file PetscImsPreconditioner.F90.

150  external lusol ! from ilut.f90
151  pc :: pc !< the shell preconditioner
152  vec :: x !< the input vector
153  vec :: y !< the output vector
154  petscerrorcode :: ierr !< PETSc error code
155  ! local
156  type(PcShellCtxType), pointer :: pc_ctx => null()
157  real(DP), dimension(:), pointer :: local_x, local_y
158  integer(I4B) :: neq, nja
159 
160  call pcshellgetcontext(pc, pc_ctx, ierr)
161  chkerrq(ierr)
162 
163  call vecgetarrayreadf90(x, local_x, ierr)
164  chkerrq(ierr)
165  call vecgetarrayf90(y, local_y, ierr)
166  chkerrq(ierr)
167 
168  neq = pc_ctx%system_matrix%nrow
169  nja = pc_ctx%system_matrix%nnz_local
170  select case (pc_ctx%ipc)
171  case (1, 2)
172  call ims_base_ilu0a(nja, neq, pc_ctx%APC, pc_ctx%IAPC, pc_ctx%JAPC, &
173  local_x, local_y)
174  case (3, 4)
175  call lusol(neq, local_x, local_y, pc_ctx%APC, pc_ctx%JLU, pc_ctx%IW)
176  end select
177 
178  call vecrestorearrayf90(x, local_x, ierr)
179  chkerrq(ierr)
180  call vecrestorearrayf90(y, local_y, ierr)
181  chkerrq(ierr)
182 
subroutine lusol(n, y, x, alu, jlu, ju)
Definition: ilut.f90:466
This module contains the IMS linear accelerator subroutines.
subroutine ims_base_ilu0a(NJA, NEQ, APC, IAPC, JAPC, R, D)
@ brief Apply the ILU0 and MILU0 preconditioners
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pcshell_setup()

subroutine, public petscimspreconditionermodule::pcshell_setup (   pc,
  ierr 
)

Definition at line 187 of file PetscImsPreconditioner.F90.

189  pc :: pc !< the shell preconditioner
190  petscerrorcode :: ierr !< PETSc error code
191  ! local
192  type(PcShellCtxType), pointer :: pc_ctx => null()
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
197 
198  call pcshellgetcontext(pc, pc_ctx, ierr)
199  chkerrq(ierr)
200 
201  ! note the two different matrix types here:
202  ! bridging between PETSc and IMS
203  call pc_ctx%system_matrix%get_aij_local(ia, ja, amat)
204 
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)
212  call ims_base_pcu(iout, nja, neq, niapc, njapc, &
213  pc_ctx%ipc, pc_ctx%linear_settings%relax, &
214  amat, ia, ja, &
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, &
219  njlu, njw, nwlu, &
220  pc_ctx%JLU, pc_ctx%JW, pc_ctx%WLU)
221 
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pctx_create()

subroutine petscimspreconditionermodule::pctx_create ( class(pcshellctxtype this,
class(petscmatrixtype), pointer  matrix,
type(imslinearsettingstype), pointer  lin_settings 
)
private
Parameters
thisthis instance
matrixthe linear system matrix
lin_settingslinear settings from IMS

Definition at line 58 of file PetscImsPreconditioner.F90.

61  class(PcShellCtxType) :: this !< this instance
62  class(PetscMatrixType), pointer :: matrix !< the linear system matrix
63  type(ImsLinearSettingsType), pointer :: lin_settings !< linear settings from IMS
64  ! local
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
69 
70  this%memory_path = matrix%memory_path
71  this%linear_settings => lin_settings
72 
73  this%ipc = 1
74  if (this%linear_settings%level > 0) then
75  this%ipc = this%ipc + 2
76  end if
77  if (this%linear_settings%relax > 0.0_dp) this%ipc = this%ipc + 1
78  this%ims_pc_type = ims_pc_type(this%ipc)
79 
80  this%system_matrix => matrix
81  call matrix%get_aij_local(ia, ja, amat)
82 
83  neq = matrix%nrow
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)
87 
88  ! preconditioner matrix
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
93  call ims_base_pccrs(niapc, njapc, ia, ja, this%IAPC, this%JAPC)
94  end if
95  do n = 1, njapc
96  this%APC(n) = dzero
97  end do
98 
99  ! (M)ILU0 work arrays
100  call mem_allocate(this%IW, niapc, 'IW', this%memory_path)
101  call mem_allocate(this%W, niapc, 'W', this%memory_path)
102  do n = 1, niapc
103  this%IW(n) = izero
104  this%W(n) = dzero
105  end do
106 
107  ! (M)ILUT work arrays
108  call mem_allocate(this%JLU, njlu, 'JLU', this%memory_path)
109  call mem_allocate(this%JW, njw, 'JW', this%memory_path)
110  call mem_allocate(this%WLU, nwlu, 'WLU', this%memory_path)
111 
112  do n = 1, njlu
113  this%JLU(n) = izero
114  end do
115  do n = 1, njw
116  this%JW(n) = izero
117  end do
118  do n = 1, nwlu
119  this%WLU(n) = dzero
120  end do
121 
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)
Here is the call graph for this function:

◆ pctx_destroy()

subroutine petscimspreconditionermodule::pctx_destroy ( class(pcshellctxtype this)

Definition at line 126 of file PetscImsPreconditioner.F90.

128  class(PcShellCtxType) :: this
129 
130  ! matrix
131  call mem_deallocate(this%IAPC)
132  call mem_deallocate(this%JAPC)
133  call mem_deallocate(this%APC)
134 
135  ! work arrays
136  call mem_deallocate(this%IW)
137  call mem_deallocate(this%W)
138  call mem_deallocate(this%JLU)
139  call mem_deallocate(this%JW)
140  call mem_deallocate(this%WLU)
141 
142  this%system_matrix => null()
143 

Variable Documentation

◆ ims_pc_type

character(len=9), dimension(4) petscimspreconditionermodule::ims_pc_type = ["IMS ILU0 ", "IMS MILU0", "IMS ILUT ", "IMS MILUT"]
private

Definition at line 18 of file PetscImsPreconditioner.F90.

18  character(len=9), dimension(4) :: IMS_PC_TYPE = ["IMS ILU0 ", &
19  "IMS MILU0", &
20  "IMS ILUT ", &
21  "IMS MILUT"]