MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
petscmatrixmodule Module Reference

Data Types

type  petscmatrixtype

Functions/Subroutines

subroutine pm_init (this, sparse, mem_path)
subroutine pm_update (this)
 Copies the values from the CSR array into.
subroutine pm_destroy (this)
class(vectorbasetype) function, pointer pm_create_vec_mm (this, n, name, mem_path)
class(vectorbasetype) function, pointer pm_create_vec (this, n)
real(dp) function pm_get_value_pos (this, ipos)
real(dp) function pm_get_diag_value (this, irow)
subroutine pm_set_diag_value (this, irow, diag_value)
subroutine pm_set_value_pos (this, ipos, value)
subroutine pm_add_value_pos (this, ipos, value)
subroutine pm_add_diag_value (this, irow, value)
integer(i4b) function pm_get_first_col_pos (this, irow)
integer(i4b) function pm_get_last_col_pos (this, irow)
integer(i4b) function pm_get_column (this, ipos)
integer(i4b) function pm_get_position (this, irow, icol)
 Return position index for (irow,icol) element in the matrix. This index can be used in other routines for direct access.
integer(i4b) function pm_get_position_diag (this, irow)
subroutine pm_zero_entries (this)
 Set all entries in the matrix to zero.
subroutine pm_zero_row_offdiag (this, irow)
 Set all off-diagonal entries in the matrix to zero.
subroutine pm_get_aij (this, ia, ja, amat)
subroutine pm_get_aij_local (this, ia, ja, amat)
 Get the ia/ja and amat values for the local diagonal block of this matrix. It is a copy.
integer(i4b) function pm_get_row_offset (this)
subroutine pm_multiply (this, vec_x, vec_y)
 Calculates global matrix vector product: y = A * x.

Function/Subroutine Documentation

◆ pm_add_diag_value()

subroutine petscmatrixmodule::pm_add_diag_value ( class(petscmatrixtype) this,
integer(i4b) irow,
real(dp) value )
private

Definition at line 260 of file PetscMatrix.F90.

261 class(PetscMatrixType) :: this
262 integer(I4B) :: irow
263 real(DP) :: value
264 ! local
265 integer(I4B) :: idiag
266
267 idiag = this%get_position_diag(irow)
268 this%amat_petsc(idiag) = this%amat_petsc(idiag) + value
269

◆ pm_add_value_pos()

subroutine petscmatrixmodule::pm_add_value_pos ( class(petscmatrixtype) this,
integer(i4b) ipos,
real(dp) value )
private

Definition at line 251 of file PetscMatrix.F90.

252 class(PetscMatrixType) :: this
253 integer(I4B) :: ipos
254 real(DP) :: value
255
256 this%amat_petsc(ipos) = this%amat_petsc(ipos) + value
257

◆ pm_create_vec()

class(vectorbasetype) function, pointer petscmatrixmodule::pm_create_vec ( class(petscmatrixtype) this,
integer(i4b) n )
private
Parameters
nthe nr. of elements in the vector
Returns
the vector object to return

Definition at line 196 of file PetscMatrix.F90.

197 class(PetscMatrixType) :: this
198 integer(I4B) :: n !< the nr. of elements in the vector
199 class(VectorBaseType), pointer :: vec !< the vector object to return
200 ! local
201 class(PetscVectorType), pointer :: petsc_vec
202
203 allocate (petsc_vec)
204 call petsc_vec%create(n)
205 vec => petsc_vec
206

◆ pm_create_vec_mm()

class(vectorbasetype) function, pointer petscmatrixmodule::pm_create_vec_mm ( class(petscmatrixtype) this,
integer(i4b) n,
character(len=*) name,
character(len=*) mem_path )
private
Parameters
nthe nr. of elements in the vector
namethe variable name (for access through memory manager)
mem_pathmemory path for storing the underlying memory items
Returns
the vector object to return

Definition at line 181 of file PetscMatrix.F90.

182 class(PetscMatrixType) :: this
183 integer(I4B) :: n !< the nr. of elements in the vector
184 character(len=*) :: name !< the variable name (for access through memory manager)
185 character(len=*) :: mem_path !< memory path for storing the underlying memory items
186 class(VectorBaseType), pointer :: vec !< the vector object to return
187 ! local
188 class(PetscVectorType), pointer :: petsc_vec
189
190 allocate (petsc_vec)
191 call petsc_vec%create_mm(n, name, mem_path)
192 vec => petsc_vec
193

◆ pm_destroy()

subroutine petscmatrixmodule::pm_destroy ( class(petscmatrixtype) this)
private

Definition at line 164 of file PetscMatrix.F90.

165 class(PetscMatrixType) :: this
166 ! local
167 petscerrorcode :: ierr
168
169 call matdestroy(this%mat, ierr)
170 chkerrq(ierr)
171
172 call mem_deallocate(this%ia_local)
173 call mem_deallocate(this%ja_local)
174 call mem_deallocate(this%amat_local)
175 call mem_deallocate(this%ia_petsc)
176 call mem_deallocate(this%ja_petsc)
177 call mem_deallocate(this%amat_petsc)
178

◆ pm_get_aij()

subroutine petscmatrixmodule::pm_get_aij ( class(petscmatrixtype) this,
integer(i4b), dimension(:), pointer, contiguous ia,
integer(i4b), dimension(:), pointer, contiguous ja,
real(dp), dimension(:), pointer, contiguous amat )
private

Definition at line 378 of file PetscMatrix.F90.

379 use simmodule, only: ustop
380 class(PetscMatrixType) :: this
381 integer(I4B), dimension(:), pointer, contiguous :: ia
382 integer(I4B), dimension(:), pointer, contiguous :: ja
383 real(DP), dimension(:), pointer, contiguous :: amat
384
385 call ustop("pm_get_aij not implemented")
386
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public ustop(stopmess, ioutlocal)
Stop the simulation.
Definition Sim.f90:313
Here is the call graph for this function:

◆ pm_get_aij_local()

subroutine petscmatrixmodule::pm_get_aij_local ( class(petscmatrixtype) this,
integer(i4b), dimension(:), pointer, contiguous ia,
integer(i4b), dimension(:), pointer, contiguous ja,
real(dp), dimension(:), pointer, contiguous amat )
private

Definition at line 391 of file PetscMatrix.F90.

392 class(PetscMatrixType) :: this
393 integer(I4B), dimension(:), pointer, contiguous :: ia
394 integer(I4B), dimension(:), pointer, contiguous :: ja
395 real(DP), dimension(:), pointer, contiguous :: amat
396 ! local
397 petscerrorcode :: ierr
398 integer(I4B) :: irow, icol, ipos
399 integer(I4B), dimension(1) :: irow_idxs, icol_idxs
400 real(DP), dimension(1) :: values
401 mat :: local_mat
402
403 call matgetdiagonalblock(this%mat, local_mat, ierr)
404 chkerrq(ierr)
405
406 do irow = 1, this%nrow
407 do ipos = this%ia_local(irow), this%ia_local(irow + 1) - 1
408 icol = this%ja_local(ipos)
409 irow_idxs(1) = irow - 1
410 icol_idxs(1) = icol - 1
411 call matgetvalues(local_mat, 1, irow_idxs, 1, icol_idxs, values, ierr)
412 chkerrq(ierr)
413 this%amat_local(ipos) = values(1)
414 end do
415 end do
416
417 ia => this%ia_local
418 ja => this%ja_local
419 amat => this%amat_local
420

◆ pm_get_column()

integer(i4b) function petscmatrixmodule::pm_get_column ( class(petscmatrixtype) this,
integer(i4b) ipos )
private

Definition at line 302 of file PetscMatrix.F90.

303 class(PetscMatrixType) :: this
304 integer(I4B) :: ipos
305 integer(I4B) :: icol
306
307 ! includes conversion to Fortran's 1-based
308 icol = this%ja_petsc(ipos) + 1
309

◆ pm_get_diag_value()

real(dp) function petscmatrixmodule::pm_get_diag_value ( class(petscmatrixtype) this,
integer(i4b) irow )
private

Definition at line 218 of file PetscMatrix.F90.

219 class(PetscMatrixType) :: this
220 integer(I4B) :: irow
221 real(DP) :: diag_value
222 ! local
223 integer(I4B) :: idiag
224
225 idiag = this%get_position_diag(irow)
226 diag_value = this%amat_petsc(idiag)
227

◆ pm_get_first_col_pos()

integer(i4b) function petscmatrixmodule::pm_get_first_col_pos ( class(petscmatrixtype) this,
integer(i4b) irow )
private

Definition at line 272 of file PetscMatrix.F90.

273 class(PetscMatrixType) :: this
274 integer(I4B) :: irow
275 integer(I4B) :: first_col_pos
276 ! local
277 integer(I4B) :: irow_local
278
279 ! convert to local row index
280 irow_local = irow - this%offset
281
282 ! includes conversion to Fortran's 1-based
283 first_col_pos = this%ia_petsc(irow_local) + 1
284

◆ pm_get_last_col_pos()

integer(i4b) function petscmatrixmodule::pm_get_last_col_pos ( class(petscmatrixtype) this,
integer(i4b) irow )
private

Definition at line 287 of file PetscMatrix.F90.

288 class(PetscMatrixType) :: this
289 integer(I4B) :: irow
290 integer(I4B) :: last_col_pos
291 ! local
292 integer(I4B) :: irow_local
293
294 ! convert to local row index
295 irow_local = irow - this%offset
296
297 ! includes conversion to Fortran's 1-based
298 last_col_pos = this%ia_petsc(irow_local + 1)
299

◆ pm_get_position()

integer(i4b) function petscmatrixmodule::pm_get_position ( class(petscmatrixtype) this,
integer(i4b) irow,
integer(i4b) icol )
private

Definition at line 316 of file PetscMatrix.F90.

317 class(PetscMatrixType) :: this
318 integer(I4B) :: irow
319 integer(I4B) :: icol
320 integer(I4B) :: ipos
321 ! local
322 integer(I4B) :: ipos_f
323 integer(I4B) :: irow_local
324
325 ipos = -1
326
327 ! convert to local row index
328 irow_local = irow - this%offset
329
330 ! includes conversion to Fortran's 1-based
331 do ipos_f = this%ia_petsc(irow_local) + 1, this%ia_petsc(irow_local + 1)
332 if (this%ja_petsc(ipos_f) + 1 == icol) then
333 ipos = ipos_f
334 return
335 end if
336 end do
337

◆ pm_get_position_diag()

integer(i4b) function petscmatrixmodule::pm_get_position_diag ( class(petscmatrixtype) this,
integer(i4b) irow )
private

Definition at line 340 of file PetscMatrix.F90.

341 class(PetscMatrixType) :: this
342 integer(I4B) :: irow
343 integer(I4B) :: ipos_diag
344
345 ipos_diag = this%pm_get_position(irow, irow)
346

◆ pm_get_row_offset()

integer(i4b) function petscmatrixmodule::pm_get_row_offset ( class(petscmatrixtype) this)
private

Definition at line 423 of file PetscMatrix.F90.

424 class(PetscMatrixType) :: this
425 integer(I4B) :: offset
426
427 offset = this%offset
428

◆ pm_get_value_pos()

real(dp) function petscmatrixmodule::pm_get_value_pos ( class(petscmatrixtype) this,
integer(i4b) ipos )
private

Definition at line 209 of file PetscMatrix.F90.

210 class(PetscMatrixType) :: this
211 integer(I4B) :: ipos
212 real(DP) :: value
213
214 value = this%amat_petsc(ipos)
215

◆ pm_init()

subroutine petscmatrixmodule::pm_init ( class(petscmatrixtype) this,
type(sparsematrix) sparse,
character(len=*) mem_path )

Definition at line 64 of file PetscMatrix.F90.

66 class(PetscMatrixType) :: this
67 type(sparsematrix) :: sparse
68 character(len=*) :: mem_path
69 ! local
70 petscerrorcode :: ierr
71 integer(I4B) :: i, ierror
72 mat :: local_mat
73 integer(I4B), dimension(:), pointer :: ia_tmp, ja_tmp
74 integer(I4B) :: nrows_local
75 logical(LGP) :: done
76
77 this%memory_path = mem_path
78 this%nrow = sparse%nrow
79 this%ncol = sparse%ncol
80 this%nnz = sparse%nnz
81 this%nnz_local = sparse%nnz - sparse%nnz_od
82 this%offset = sparse%offset
83
84 ! allocate the diagonal block of the matrix
85 call mem_allocate(this%ia_local, this%nrow + 1, 'IA_LOCAL', this%memory_path)
86 call mem_allocate(this%ja_local, this%nnz_local, 'JA_LOCAL', this%memory_path)
87 call mem_allocate(this%amat_local, this%nnz_local, 'AMAT_LOCAL', &
88 this%memory_path)
89 call mem_allocate(this%ia_petsc, this%nrow + 1, 'IA_PETSC', this%memory_path)
90 call mem_allocate(this%ja_petsc, this%nnz, 'JA_PETSC', this%memory_path)
91 call mem_allocate(this%amat_petsc, this%nnz, 'AMAT_PETSC', this%memory_path)
92
93 call sparse%sort(with_csr=.true.) !< PETSc has full row sorting, MF6 had diagonal first and then sorted
94 call sparse%filliaja(this%ia_petsc, this%ja_petsc, ierror)
95
96 ! go to C indexing for PETSc internals
97 do i = 1, this%nrow + 1
98 this%ia_petsc(i) = this%ia_petsc(i) - 1
99 end do
100 do i = 1, this%nnz
101 this%ja_petsc(i) = this%ja_petsc(i) - 1
102 this%amat_petsc(i) = dzero
103 end do
104
105 ! create PETSc matrix object
106 if (simulation_mode == 'PARALLEL') then
107 this%is_parallel = .true.
108 call matcreatempiaijwitharrays(petsc_comm_world, &
109 sparse%nrow, sparse%nrow, &
110 sparse%ncol, sparse%ncol, &
111 this%ia_petsc, this%ja_petsc, &
112 this%amat_petsc, this%mat, &
113 ierr)
114 else
115 this%is_parallel = .false.
116 call matcreateseqaijwitharrays(petsc_comm_world, &
117 sparse%nrow, sparse%ncol, &
118 this%ia_petsc, this%ja_petsc, &
119 this%amat_petsc, this%mat, &
120 ierr)
121 end if
122 chkerrq(ierr)
123
124 ! set up local block sparsity structure
125 nrows_local = 0
126 call matgetdiagonalblock(this%mat, local_mat, ierr)
127 chkerrq(ierr)
128
129 call matgetrowijf90(local_mat, 1, petsc_false, petsc_false, &
130 nrows_local, ia_tmp, ja_tmp, &
131 done, ierr)
132 chkerrq(ierr)
133
134 do i = 1, size(ia_tmp)
135 this%ia_local(i) = ia_tmp(i)
136 end do
137 do i = 1, size(ja_tmp) - 1
138 this%ja_local(i) = ja_tmp(i)
139 end do
140
141 call matrestorerowijf90(local_mat, 1, petsc_false, petsc_false, &
142 nrows_local, ia_tmp, ja_tmp, done, ierr)
143 chkerrq(ierr)
144
This module contains simulation variables.
character(len=linelength) simulation_mode

◆ pm_multiply()

subroutine petscmatrixmodule::pm_multiply ( class(petscmatrixtype) this,
class(vectorbasetype), pointer vec_x,
class(vectorbasetype), pointer vec_y )
private

Definition at line 433 of file PetscMatrix.F90.

434 class(PetscMatrixType) :: this
435 class(VectorBaseType), pointer :: vec_x
436 class(VectorBaseType), pointer :: vec_y
437 ! local
438 petscerrorcode :: ierr
439 class(PetscVectorType), pointer :: x, y
440
441 x => null()
442 select type (vec_x)
443 class is (petscvectortype)
444 x => vec_x
445 end select
446 y => null()
447 select type (vec_y)
448 class is (petscvectortype)
449 y => vec_y
450 end select
451
452 ! copy data into petsc object
453 call this%update()
454 ! and multiply
455 call matmult(this%mat, x%vec_impl, y%vec_impl, ierr)
456 chkerrq(ierr)
457

◆ pm_set_diag_value()

subroutine petscmatrixmodule::pm_set_diag_value ( class(petscmatrixtype) this,
integer(i4b) irow,
real(dp) diag_value )
private

Definition at line 230 of file PetscMatrix.F90.

231 class(PetscMatrixType) :: this
232 integer(I4B) :: irow
233 real(DP) :: diag_value
234 ! local
235 integer(I4B) :: idiag
236
237 idiag = this%get_position_diag(irow)
238 this%amat_petsc(idiag) = diag_value
239

◆ pm_set_value_pos()

subroutine petscmatrixmodule::pm_set_value_pos ( class(petscmatrixtype) this,
integer(i4b) ipos,
real(dp) value )
private

Definition at line 242 of file PetscMatrix.F90.

243 class(PetscMatrixType) :: this
244 integer(I4B) :: ipos
245 real(DP) :: value
246
247 this%amat_petsc(ipos) = value
248

◆ pm_update()

subroutine petscmatrixmodule::pm_update ( class(petscmatrixtype) this)
private

Definition at line 149 of file PetscMatrix.F90.

150 class(PetscMatrixType) :: this
151 ! local
152 petscerrorcode :: ierr
153
154 if (this%is_parallel) then
155 call matupdatempiaijwitharrays(this%mat, this%nrow, this%nrow, &
156 this%ncol, this%ncol, &
157 this%ia_petsc, this%ja_petsc, &
158 this%amat_petsc, ierr)
159 chkerrq(ierr)
160 end if
161

◆ pm_zero_entries()

subroutine petscmatrixmodule::pm_zero_entries ( class(petscmatrixtype) this)
private

Definition at line 351 of file PetscMatrix.F90.

352 class(PetscMatrixType) :: this
353 ! local
354 integer(I4B) :: i
355
356 do i = 1, this%nnz
357 this%amat_petsc(i) = dzero
358 end do
359

◆ pm_zero_row_offdiag()

subroutine petscmatrixmodule::pm_zero_row_offdiag ( class(petscmatrixtype) this,
integer(i4b) irow )
private

Definition at line 364 of file PetscMatrix.F90.

365 class(PetscMatrixType) :: this
366 integer(I4B) :: irow
367 ! local
368 integer(I4B) :: ipos, idiag
369
370 idiag = this%get_position_diag(irow)
371 do ipos = this%get_first_col_pos(irow), this%get_last_col_pos(irow)
372 if (ipos == idiag) cycle
373 this%amat_petsc(ipos) = dzero
374 end do
375