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
Public Types | Public Member Functions | Static Public Member Functions | List of all members
dolfinx::la::PETScMatrix Class Reference

It is a simple wrapper for a PETSc matrix pointer (Mat). Its main purpose is to assist memory management of PETSc Mat objects. More...

#include <PETScMatrix.h>

Inheritance diagram for dolfinx::la::PETScMatrix:
Inheritance graph
[legend]
Collaboration diagram for dolfinx::la::PETScMatrix:
Collaboration graph
[legend]

Public Types

enum  AssemblyType : std::int32_t { FINAL, FLUSH }
 Assembly type FINAL - corresponds to PETSc MAT_FINAL_ASSEMBLY FLUSH - corresponds to PETSc MAT_FLUSH_ASSEMBLY.
 

Public Member Functions

 PETScMatrix (MPI_Comm comm, const SparsityPattern &sparsity_pattern, const std::string &type=std::string())
 Create holder for a PETSc Mat object from a sparsity pattern.
 
 PETScMatrix (Mat A, bool inc_ref_count)
 Create holder of a PETSc Mat object/pointer. The Mat A object should already be created. If inc_ref_count is true, the reference counter of the Mat will be increased. The Mat reference count will always be decreased upon destruction of the the PETScMatrix.
 
 PETScMatrix (const PETScMatrix &A)=delete
 
 PETScMatrix (PETScMatrix &&A)=default
 Move constructor (falls through to base class move constructor)
 
 ~PETScMatrix ()=default
 Destructor.
 
PETScMatrixoperator= (const PETScMatrix &A)=delete
 Assignment operator (deleted)
 
PETScMatrixoperator= (PETScMatrix &&A)=default
 Move assignment operator.
 
void apply (AssemblyType type)
 Finalize assembly of tensor. The following values are recognized for the mode parameter: More...
 
double norm (la::Norm norm_type) const
 Return norm of matrix.
 
void set_options_prefix (std::string options_prefix)
 Sets the prefix used by PETSc when searching the options database.
 
std::string get_options_prefix () const
 Returns the prefix used by PETSc when searching the options database.
 
void set_from_options ()
 Call PETSc function MatSetFromOptions on the PETSc Mat object.
 
void set_nullspace (const la::VectorSpaceBasis &nullspace)
 Attach nullspace to matrix (typically used by Krylov solvers when solving singular systems)
 
void set_near_nullspace (const la::VectorSpaceBasis &nullspace)
 Attach 'near' nullspace to matrix (used by preconditioners, such as smoothed aggregation algerbraic multigrid)
 
- Public Member Functions inherited from dolfinx::la::PETScOperator
 PETScOperator (Mat A, bool inc_ref_count)
 Constructor.
 
 PETScOperator (const PETScOperator &A)=delete
 
 PETScOperator (PETScOperator &&A)
 Move constructor.
 
virtual ~PETScOperator ()
 Destructor.
 
PETScOperatoroperator= (const PETScOperator &A)=delete
 Assignment operator (deleted)
 
PETScOperatoroperator= (PETScOperator &&A)
 Move assignment operator.
 
std::array< std::int64_t, 2 > size () const
 Return number of rows and columns (num_rows, num_cols). PETSc returns -1 if size has not been set.
 
PETScVector create_vector (std::size_t dim) const
 Initialize vector to be compatible with the matrix-vector product y = Ax. In the parallel case, size and layout are both important. More...
 
Mat mat () const
 Return PETSc Mat pointer.
 

Static Public Member Functions

static std::function< int(std::int32_t, const std::int32_t *, std::int32_t, const std::int32_t *, const PetscScalar *)> set_fn (Mat A, InsertMode mode)
 Return a function with an interface for adding or inserting values into the matrix A (calls MatSetValuesLocal) More...
 
static std::function< int(std::int32_t, const std::int32_t *, std::int32_t, const std::int32_t *, const PetscScalar *)> set_block_fn (Mat A, InsertMode mode)
 Return a function with an interface for adding or inserting values into the matrix A using blocked indices (calls MatSetValuesBlockedLocal) More...
 
static std::function< int(std::int32_t, const std::int32_t *, std::int32_t, const std::int32_t *, const PetscScalar *)> set_block_expand_fn (Mat A, int bs0, int bs1, InsertMode mode)
 Return a function with an interface for adding or inserting blocked values to the matrix A using non-blocked insertion (calls MatSetValuesLocal). Internally it expands the blocked indices into non-blocked arrays. More...
 

Detailed Description

It is a simple wrapper for a PETSc matrix pointer (Mat). Its main purpose is to assist memory management of PETSc Mat objects.

For advanced usage, access the PETSc Mat pointer using the function mat() and use the standard PETSc interface.

Member Function Documentation

◆ apply()

void PETScMatrix::apply ( AssemblyType  type)

Finalize assembly of tensor. The following values are recognized for the mode parameter:

Parameters
typeFINAL - corresponds to PETSc MatAssemblyBegin+End(MAT_FINAL_ASSEMBLY) FLUSH - corresponds to PETSc MatAssemblyBegin+End(MAT_FLUSH_ASSEMBLY)

◆ set_block_expand_fn()

std::function< int(std::int32_t, const std::int32_t *, std::int32_t, const std::int32_t *, const PetscScalar *)> PETScMatrix::set_block_expand_fn ( Mat  A,
int  bs0,
int  bs1,
InsertMode  mode 
)
static

Return a function with an interface for adding or inserting blocked values to the matrix A using non-blocked insertion (calls MatSetValuesLocal). Internally it expands the blocked indices into non-blocked arrays.

Parameters
[in]AThe matrix to set values in
[in]bs0Block size for the matrix rows
[in]bs1Block size for the matrix columns
[in]modeThe PETSc insert mode (ADD_VALUES, INSERT_VALUES, ...)

◆ set_block_fn()

std::function< int(std::int32_t, const std::int32_t *, std::int32_t, const std::int32_t *, const PetscScalar *)> PETScMatrix::set_block_fn ( Mat  A,
InsertMode  mode 
)
static

Return a function with an interface for adding or inserting values into the matrix A using blocked indices (calls MatSetValuesBlockedLocal)

Parameters
[in]AThe matrix to set values in
[in]modeThe PETSc insert mode (ADD_VALUES, INSERT_VALUES, ...)

◆ set_fn()

std::function< int(std::int32_t, const std::int32_t *, std::int32_t, const std::int32_t *, const PetscScalar *)> PETScMatrix::set_fn ( Mat  A,
InsertMode  mode 
)
static

Return a function with an interface for adding or inserting values into the matrix A (calls MatSetValuesLocal)

Parameters
[in]AThe matrix to set values in
[in]modeThe PETSc insert mode (ADD_VALUES, INSERT_VALUES, ...)

The documentation for this class was generated from the following files: