Skip to content

Commit 5b156f0

Browse files
committed
Remove special case handling for single space vector
1 parent 9e867bd commit 5b156f0

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

python/dolfinx/fem/petsc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
def create_vector(
8484
V: _FunctionSpace | Sequence[_FunctionSpace | None],
8585
/,
86-
kind: str | None = None,
86+
kind: str = "mpi",
8787
) -> PETSc.Vec: # type: ignore[name-defined]
8888
"""Create a PETSc vector that is compatible with a linear form(s)
8989
or functionspace(s).

python/dolfinx/la/petsc.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ def create_vector_wrap(x: Vector) -> PETSc.Vec: # type: ignore[name-defined]
7272
)
7373

7474

75-
def create_vector(
76-
maps: typing.Sequence[tuple[IndexMap, int]], kind: str | None = None
77-
) -> PETSc.Vec: # type: ignore[name-defined]
75+
def create_vector(maps: typing.Sequence[tuple[IndexMap, int]], kind: str = "mpi") -> PETSc.Vec: # type: ignore[name-defined]
7876
"""Create a PETSc vector from a sequence of maps and blocksizes.
7977
8078
Three cases are supported:
@@ -118,28 +116,19 @@ def create_vector(
118116
A PETSc vector with the prescribed layout. The vector is not
119117
initialised to zero.
120118
"""
121-
if len(maps) == 1:
122-
# Single space case
123-
index_map, bs = maps[0]
124-
ghosts = index_map.ghosts.astype(PETSc.IntType) # type: ignore[attr-defined]
125-
size = (index_map.size_local * bs, index_map.size_global * bs)
126-
b = PETSc.Vec().createGhost(ghosts, size=size, bsize=bs, comm=index_map.comm) # type: ignore
127-
if kind == PETSc.Vec.Type.MPI:
119+
match kind:
120+
case PETSc.Vec.Type.MPI: # type: ignore[attr-defined]
121+
b = dolfinx.cpp.fem.petsc.create_vector_block(maps)
128122
_assign_block_data(maps, b)
129-
return b
130-
131-
if kind is None or kind == PETSc.Vec.Type.MPI: # type: ignore[attr-defined]
132-
b = dolfinx.cpp.fem.petsc.create_vector_block(maps)
133-
_assign_block_data(maps, b)
134-
return b
135-
elif kind == PETSc.Vec.Type.NEST: # type: ignore[attr-defined]
136-
return dolfinx.cpp.fem.petsc.create_vector_nest(maps)
137-
else:
138-
raise NotImplementedError(
139-
"Vector type must be specified for blocked/nested assembly."
140-
f"Vector type '{kind}' not supported."
141-
"Did you mean 'nest' or 'mpi'?"
142-
)
123+
return b
124+
case PETSc.Vec.Type.NEST: # type: ignore[attr-defined]
125+
return dolfinx.cpp.fem.petsc.create_vector_nest(maps)
126+
case _:
127+
raise NotImplementedError(
128+
"Vector type must be specified for blocked/nested assembly."
129+
f"Vector type '{kind}' not supported."
130+
"Did you mean 'nest' or 'mpi'?"
131+
)
143132

144133

145134
@functools.singledispatch

python/test/unit/fem/test_assembler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_vector_single_space_as_block():
184184
mesh = create_unit_square(MPI.COMM_WORLD, 3, 3)
185185
gdim = mesh.geometry.dim
186186
V = functionspace(mesh, ("Lagrange", 1, (gdim,)))
187-
assert petsc_create_vector(V).getAttr("_blocks") is None
187+
# assert petsc_create_vector(V).getAttr("_blocks") is None
188188
assert petsc_create_vector(V, kind="mpi").getAttr("_blocks") is not None
189189

190190

0 commit comments

Comments
 (0)