dolfinx.la.petsc

Functions for working with PETSc linear algebra objects.

Note

Due to subtle issues in the interaction between petsc4py memory management and the Python garbage collector, it is recommended that the PETSc method destroy() is called on returned PETSc objects once the object is no longer required. Note that destroy() is collective over the object’s MPI communicator.

Functions

assign()

Assign x0 values to a PETSc vector x1.

create_vector(index_map, bs)

Create a distributed PETSc vector.

create_vector_wrap(x)

Wrap a distributed DOLFINx vector as a PETSc vector.

dolfinx.la.petsc.assign(x0: ndarray[Any, dtype[inexact]] | list[ndarray[Any, dtype[inexact]]], x1: Vec)[source]
dolfinx.la.petsc.assign(x0: Vec, x1: ndarray[Any, dtype[inexact]] | list[ndarray[Any, dtype[inexact]]])

Assign x0 values to a PETSc vector x1.

Values in x0, which is possibly a stacked collection of arrays, are assigned x1. When x0 holds a sequence of n` arrays and x1 has type NEST, the assignment is:

      [x0[0]]
x1 =  [x0[1]]
      [.....]
      [x0[n-1]]

When x0 holds a sequence of n arrays and x1 does not have type NEST, the assignment is:

      [x0_owned[0]]
x1 =  [.....]
      [x0_owned[n-1]]
      [x0_ghost[0]]
      [.....]
      [x0_ghost[n-1]]
Parameters:
  • x0 – An array or list of arrays that will be assigned to x1.

  • x1 – Vector to assign values to.

dolfinx.la.petsc.create_vector(index_map: IndexMap, bs: int) Vec[source]

Create a distributed PETSc vector.

Parameters:
  • index_map – Index map that describes the size and parallel layout of the vector to create.

  • bs – Block size of the vector.

Returns:

PETSc Vec object.

dolfinx.la.petsc.create_vector_wrap(x: Vector) Vec[source]

Wrap a distributed DOLFINx vector as a PETSc vector.

Parameters:

x – The vector to wrap as a PETSc vector.

Returns:

A PETSc vector that shares data with x.