Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.1.0/v0.9.0/cpp
DOLFINx  0.1.0
DOLFINx C++ interface
Classes | Enumerations | Functions
dolfinx::la Namespace Reference

Linear algebra interface. More...

Classes

class  PETScKrylovSolver
 This class implements Krylov methods for linear systems of the form Ax = b. It is a wrapper for the Krylov solvers of PETSc. More...
 
class  PETScMatrix
 It is a simple wrapper for a PETSc matrix pointer (Mat). Its main purpose is to assist memory management of PETSc Mat objects. More...
 
class  PETScOperator
 This class is a base class for matrices that can be used in PETScKrylovSolver. More...
 
class  PETScOptions
 These class provides static functions that permit users to set and retrieve PETSc options via the PETSc option/parameter system. The option must not be prefixed by '-', e.g. More...
 
class  PETScVector
 A simple wrapper for a PETSc vector pointer (Vec). Its main purpose is to assist with memory/lifetime management of PETSc Vec objects. More...
 
class  SparsityPattern
 This class provides a sparsity pattern data structure that can be used to initialize sparse matrices. More...
 
class  Vector
 Distributed vector. More...
 
class  VectorSpaceBasis
 This class defines a basis for vector spaces, typically used for expressing nullspaces of singular operators and 'near nullspaces' used in smoothed aggregation algebraic multigrid. More...
 

Enumerations

enum  Norm { l1, l2, linf, frobenius }
 Norm types.
 

Functions

Mat create_petsc_matrix (MPI_Comm comm, const SparsityPattern &sparsity_pattern, const std::string &type=std::string())
 Create a PETSc Mat. Caller is responsible for destroying the returned object.
 
MatNullSpace create_petsc_nullspace (MPI_Comm comm, const VectorSpaceBasis &nullspace)
 Create PETSc MatNullSpace. Caller is responsible for destruction returned object.
 
Vec create_ghosted_vector (const common::IndexMap &map, int bs, xtl::span< PetscScalar > x)
 Create a PETSc Vec that wraps the data in an array. More...
 
void petsc_error (int error_code, std::string filename, std::string petsc_function)
 Print error message for PETSc calls that return an error.
 
std::vector< IS > create_petsc_index_sets (const std::vector< std::pair< std::reference_wrapper< const common::IndexMap >, int >> &maps)
 
Vec create_petsc_vector (const common::IndexMap &map, int bs)
 Create a ghosted PETSc Vec. More...
 
Vec create_petsc_vector (MPI_Comm comm, std::array< std::int64_t, 2 > range, const std::vector< std::int64_t > &ghosts, int bs)
 Create a ghosted PETSc Vec from a local range and ghost indices. More...
 
std::vector< std::vector< PetscScalar > > get_local_vectors (const Vec x, const std::vector< std::pair< std::reference_wrapper< const common::IndexMap >, int >> &maps)
 Copy blocks from Vec into local vectors.
 
void scatter_local_vectors (Vec x, const std::vector< xtl::span< const PetscScalar >> &x_b, const std::vector< std::pair< std::reference_wrapper< const common::IndexMap >, int >> &maps)
 Scatter local vectors to Vec.
 
template<typename T >
void scatter_fwd (Vector< T > &v)
 Scatter la::Vector local data to ghost values. More...
 
template<typename T >
void scatter_rev (Vector< T > &v, dolfinx::common::IndexMap::Mode op)
 Scatter la::Vector ghost data to owner. This process will result in multiple incoming values, which can be summed or inserted into the local vector. More...
 

Detailed Description

Linear algebra interface.

Interface to linear algebra data structures and solvers

Function Documentation

◆ create_ghosted_vector()

Vec dolfinx::la::create_ghosted_vector ( const common::IndexMap map,
int  bs,
xtl::span< PetscScalar >  x 
)

Create a PETSc Vec that wraps the data in an array.

Parameters
[in]mapThe index map that describes the parallel layout of the distributed vector (by block)
[in]bsBlock size
[in]xThe local part of the vector, including ghost entries
Returns
A PETSc Vec object that shares the data in x. The caller is responsible for destroying the Vec.

◆ create_petsc_index_sets()

std::vector< IS > dolfinx::la::create_petsc_index_sets ( const std::vector< std::pair< std::reference_wrapper< const common::IndexMap >, int >> &  maps)
Todo:
This function could take just the local sizes

Compute PETSc IndexSets (IS) for a stack of index maps. E.g., if map[0] = {0, 1, 2, 3, 4, 5, 6} and map[1] = {0, 1, 2, 4} (in local indices) then IS[0] = {0, 1, 2, 3, 4, 5, 6} and IS[1] = {7, 8, 9, 10}.

The caller is responsible for destruction of each IS.

Parameters
[in]mapsVector of IndexMaps and corresponding block sizes
Returns
Vector of PETSc Index Sets, created onPETSC_COMM_SELF

◆ create_petsc_vector() [1/2]

Vec dolfinx::la::create_petsc_vector ( const common::IndexMap map,
int  bs 
)

Create a ghosted PETSc Vec.

Caller is responsible for destroying the returned object.

Parameters
[in]mapThe index map describing the parallel layout (by block)
[in]bsThe block size
Returns
A PETSc Vec

◆ create_petsc_vector() [2/2]

Vec dolfinx::la::create_petsc_vector ( MPI_Comm  comm,
std::array< std::int64_t, 2 >  range,
const std::vector< std::int64_t > &  ghosts,
int  bs 
)

Create a ghosted PETSc Vec from a local range and ghost indices.

Caller is responsible for destroying the returned object.

Parameters
[in]commThe MPI communicator
[in]rangeThe local ownership range (by blocks)
[in]ghostsGhost blocks
[in]bsThe block size. The total number of local entries is bs * (range[1] - range[0]).
Returns
A PETSc Vec

◆ scatter_fwd()

template<typename T >
void dolfinx::la::scatter_fwd ( Vector< T > &  v)

Scatter la::Vector local data to ghost values.

Parameters
[in,out]vla::Vector to update

◆ scatter_rev()

template<typename T >
void dolfinx::la::scatter_rev ( Vector< T > &  v,
dolfinx::common::IndexMap::Mode  op 
)

Scatter la::Vector ghost data to owner. This process will result in multiple incoming values, which can be summed or inserted into the local vector.

Parameters
[in,out]vla::Vector to update
opIndexMap operation (add or insert)