@@ -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
0 commit comments