2#include <petsc/finclude/petscksp.h>
20 integer(I4B) :: nnz_local
21 integer(I4B) :: offset
22 integer(I4B),
dimension(:),
pointer,
contiguous,
private :: ia_local
23 integer(I4B),
dimension(:),
pointer,
contiguous,
private :: ja_local
24 real(dp),
dimension(:),
pointer,
contiguous,
private :: amat_local
25 integer(I4B),
dimension(:),
pointer,
contiguous :: ia_petsc
26 integer(I4B),
dimension(:),
pointer,
contiguous :: ja_petsc
27 real(dp),
dimension(:),
pointer,
contiguous :: amat_petsc
28 logical(LGP) :: is_parallel
64 subroutine pm_init(this, sparse, mem_path)
68 character(len=*) :: mem_path
70 petscerrorcode :: ierr
71 integer(I4B) :: i, ierror
73 integer(I4B),
dimension(:),
pointer :: ia_tmp, ja_tmp
74 integer(I4B) :: nrows_local
77 this%memory_path = mem_path
78 this%nrow = sparse%nrow
79 this%ncol = sparse%ncol
81 this%nnz_local = sparse%nnz - sparse%nnz_od
82 this%offset = sparse%offset
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', &
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)
93 call sparse%sort(with_csr=.true.)
94 call sparse%filliaja(this%ia_petsc, this%ja_petsc, ierror)
97 do i = 1, this%nrow + 1
98 this%ia_petsc(i) = this%ia_petsc(i) - 1
101 this%ja_petsc(i) = this%ja_petsc(i) - 1
102 this%amat_petsc(i) =
dzero
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, &
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, &
126 call matgetdiagonalblock(this%mat, local_mat, ierr)
129 call matgetrowijf90(local_mat, 1, petsc_false, petsc_false, &
130 nrows_local, ia_tmp, ja_tmp, &
134 do i = 1,
size(ia_tmp)
135 this%ia_local(i) = ia_tmp(i)
137 do i = 1,
size(ja_tmp) - 1
138 this%ja_local(i) = ja_tmp(i)
141 call matrestorerowijf90(local_mat, 1, petsc_false, petsc_false, &
142 nrows_local, ia_tmp, ja_tmp, done, ierr)
152 petscerrorcode :: ierr
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)
167 petscerrorcode :: ierr
169 call matdestroy(this%mat, ierr)
184 character(len=*) :: name
185 character(len=*) :: mem_path
191 call petsc_vec%create_mm(n, name, mem_path)
204 call petsc_vec%create(n)
214 value = this%amat_petsc(ipos)
221 real(dp) :: diag_value
223 integer(I4B) :: idiag
225 idiag = this%get_position_diag(irow)
226 diag_value = this%amat_petsc(idiag)
233 real(DP) :: diag_value
235 integer(I4B) :: idiag
237 idiag = this%get_position_diag(irow)
238 this%amat_petsc(idiag) = diag_value
247 this%amat_petsc(ipos) =
value
256 this%amat_petsc(ipos) = this%amat_petsc(ipos) +
value
265 integer(I4B) :: idiag
267 idiag = this%get_position_diag(irow)
268 this%amat_petsc(idiag) = this%amat_petsc(idiag) +
value
275 integer(I4B) :: first_col_pos
277 integer(I4B) :: irow_local
280 irow_local = irow - this%offset
283 first_col_pos = this%ia_petsc(irow_local) + 1
290 integer(I4B) :: last_col_pos
292 integer(I4B) :: irow_local
295 irow_local = irow - this%offset
298 last_col_pos = this%ia_petsc(irow_local + 1)
308 icol = this%ja_petsc(ipos) + 1
322 integer(I4B) :: ipos_f
323 integer(I4B) :: irow_local
328 irow_local = irow - this%offset
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
343 integer(I4B) :: ipos_diag
345 ipos_diag = this%pm_get_position(irow, irow)
357 this%amat_petsc(i) =
dzero
368 integer(I4B) :: ipos, idiag
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
381 integer(I4B),
dimension(:),
pointer,
contiguous :: ia
382 integer(I4B),
dimension(:),
pointer,
contiguous :: ja
383 real(DP),
dimension(:),
pointer,
contiguous :: amat
385 call ustop(
"pm_get_aij not implemented")
393 integer(I4B),
dimension(:),
pointer,
contiguous :: ia
394 integer(I4B),
dimension(:),
pointer,
contiguous :: ja
395 real(DP),
dimension(:),
pointer,
contiguous :: amat
397 petscerrorcode :: ierr
398 integer(I4B) :: irow, icol, ipos
399 integer(I4B),
dimension(1) :: irow_idxs, icol_idxs
400 real(DP),
dimension(1) :: values
403 call matgetdiagonalblock(this%mat, local_mat, ierr)
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)
413 this%amat_local(ipos) = values(1)
419 amat => this%amat_local
425 integer(I4B) :: offset
438 petscerrorcode :: ierr
455 call matmult(this%mat, x%vec_impl, y%vec_impl, ierr)
This module contains simulation constants.
real(dp), parameter dzero
real constant zero
This module defines variable data types.
real(dp) function pm_get_diag_value(this, irow)
class(vectorbasetype) function, pointer pm_create_vec(this, n)
subroutine pm_zero_row_offdiag(this, irow)
Set all off-diagonal entries in the matrix to zero.
real(dp) function pm_get_value_pos(this, ipos)
subroutine pm_multiply(this, vec_x, vec_y)
Calculates global matrix vector product: y = A * x.
subroutine pm_destroy(this)
subroutine pm_init(this, sparse, mem_path)
subroutine pm_update(this)
Copies the values from the CSR array into.
subroutine pm_zero_entries(this)
Set all entries in the matrix to zero.
subroutine pm_get_aij(this, ia, ja, amat)
integer(i4b) function pm_get_position_diag(this, irow)
integer(i4b) function pm_get_last_col_pos(this, irow)
integer(i4b) function pm_get_row_offset(this)
class(vectorbasetype) function, pointer pm_create_vec_mm(this, n, name, mem_path)
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...
subroutine pm_add_value_pos(this, ipos, value)
subroutine pm_set_diag_value(this, irow, diag_value)
integer(i4b) function pm_get_first_col_pos(this, irow)
integer(i4b) function pm_get_column(this, ipos)
subroutine pm_set_value_pos(this, ipos, value)
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.
subroutine pm_add_diag_value(this, irow, value)
This module contains simulation methods.
subroutine, public ustop(stopmess, ioutlocal)
Stop the simulation.
This module contains simulation variables.
character(len=linelength) simulation_mode