Skip to content

Commit 4d45c97

Browse files
committed
Support mat_type="is"
1 parent 6e1f8b9 commit 4d45c97

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

firedrake/assemble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ def _get_mat_type(mat_type, sub_mat_type, arguments):
12951295
for arg in arguments
12961296
for V in arg.function_space()):
12971297
mat_type = "nest"
1298-
if mat_type not in {"matfree", "aij", "baij", "nest", "dense"}:
1298+
if mat_type not in {"matfree", "aij", "baij", "nest", "dense", "is"}:
12991299
raise ValueError(f"Unrecognised matrix type, '{mat_type}'")
13001300
if sub_mat_type is None:
13011301
sub_mat_type = parameters.parameters["default_sub_matrix_type"]

pyop2/types/mat.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,16 @@ def _init_monolithic(self):
618618
rset, cset = self.sparsity.dsets
619619
rlgmap = rset.unblocked_lgmap
620620
clgmap = cset.unblocked_lgmap
621-
mat.createAIJ(size=((self.nrows, None), (self.ncols, None)),
622-
nnz=(self.sparsity.nnz, self.sparsity.onnz),
623-
bsize=1,
624-
comm=self.comm)
621+
if self.mat_type == "is":
622+
create = mat.createIS
623+
elif self.mat_type.endswith("aij"):
624+
create = mat.createAIJ
625+
else:
626+
raise ValueError(f"Unsupported mat_type {mat_type}")
627+
size = ((self.nrows, None), (self.ncols, None))
628+
create(size, bsize=1, comm=self.comm)
625629
mat.setLGMap(rmap=rlgmap, cmap=clgmap)
630+
mat.setPreallocationNNZ((self.sparsity.nnz, self.sparsity.onnzi))
626631
self.handle = mat
627632
self._blocks = []
628633
rows, cols = self.sparsity.shape
@@ -685,7 +690,10 @@ def _init_block(self):
685690
col_lg = cset.lgmap
686691
rdim, cdim = self.dims[0][0]
687692

688-
if rdim == cdim and rdim > 1 and self.sparsity._block_sparse:
693+
if self.mat_type == "is":
694+
block_sparse = False
695+
create = mat.createIS
696+
elif rdim == cdim and rdim > 1 and self.sparsity._block_sparse:
689697
# Size is total number of rows and columns, but the
690698
# /sparsity/ is the block sparsity.
691699
block_sparse = True
@@ -697,10 +705,10 @@ def _init_block(self):
697705
create = mat.createAIJ
698706
create(size=((self.nrows, None),
699707
(self.ncols, None)),
700-
nnz=(self.sparsity.nnz, self.sparsity.onnz),
701708
bsize=(rdim, cdim),
702709
comm=self.comm)
703710
mat.setLGMap(rmap=row_lg, cmap=col_lg)
711+
mat.setPreallocationNNZ((self.sparsity.nnz, self.sparsity.onnz))
704712
# Stash entries destined for other processors
705713
mat.setOption(mat.Option.IGNORE_OFF_PROC_ENTRIES, False)
706714
# Any add or insertion that would generate a new entry that has not
@@ -716,7 +724,8 @@ def _init_block(self):
716724
mat.setOption(mat.Option.KEEP_NONZERO_PATTERN, True)
717725
# We completely fill the allocated matrix when zeroing the
718726
# entries, so raise an error if we "missed" one.
719-
mat.setOption(mat.Option.UNUSED_NONZERO_LOCATION_ERR, True)
727+
if self.mat_type != "is":
728+
mat.setOption(mat.Option.UNUSED_NONZERO_LOCATION_ERR, True)
720729
# Put zeros in all the places we might eventually put a value.
721730
with profiling.timed_region("MatZeroInitial"):
722731
sparsity.fill_with_zeros(mat, self.sparsity.dims[0][0],

0 commit comments

Comments
 (0)