Skip to content

Commit

Permalink
Insert zero blocks on matrix diagonals
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjward committed Aug 22, 2023
1 parent d230953 commit e62d57b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pyop2/sparsity.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ def fill_with_zeros(PETSc.Mat mat not None, dims, maps, iteration_regions, set_d
cdef:
PetscInt rdim, cdim
PetscScalar *values
PetscScalar *diag_values
int set_entry
int set_size
int region_selector
bint constant_layers, extruded_periodic
PetscInt layer_start, layer_end, layer_bottom, num_layers, effective_offset, layer
PetscInt[:, ::1] layers
PetscInt i, k, irem
PetscScalar zero = 0.0
PetscInt nrow, ncol
PetscInt rarity, carity, tmp_rarity, tmp_carity
PetscInt[:, ::1] rmap, cmap, tempmap
Expand All @@ -211,9 +211,11 @@ def fill_with_zeros(PETSc.Mat mat not None, dims, maps, iteration_regions, set_d
# Always allocate space for diagonal
nrow, ncol = mat.getLocalSize()
if set_diag:
for i in range(nrow):
if i < ncol:
CHKERR(MatSetValuesLocal(mat.mat, 1, &i, 1, &i, &zero, PETSC_INSERT_VALUES))
CHKERR(PetscCalloc1(rdim*cdim, &diag_values))
for i in range(nrow // rdim):
if i < ncol // cdim:
CHKERR(MatSetValuesBlockedLocal(mat.mat, 1, &i, 1, &i, diag_values, PETSC_INSERT_VALUES))
CHKERR(PetscFree(diag_values))
extruded = maps[0][0].iterset._extruded
for iteration_region, pair in zip(iteration_regions, maps):
# Iterate over row map values including value entries
Expand Down

0 comments on commit e62d57b

Please sign in to comment.