Chaste Release::3.1
PetscMatTools Class Reference

#include <PetscMatTools.hpp>

List of all members.

Static Public Member Functions

static void SetElement (Mat matrix, PetscInt row, PetscInt col, double value)
static void AddToElement (Mat matrix, PetscInt row, PetscInt col, double value)
static void Finalise (Mat matrix)
static void SwitchWriteMode (Mat matrix)
static void Display (Mat matrix)
static void SetRow (Mat matrix, PetscInt row, double value)
static void ZeroRowsWithValueOnDiagonal (Mat matrix, std::vector< unsigned > &rRows, double diagonalValue)
static void ZeroRowsAndColumnsWithValueOnDiagonal (Mat matrix, std::vector< unsigned > rowColIndices, double diagonalValue)
static void ZeroColumn (Mat matrix, PetscInt col)
static void Zero (Mat matrix)
static unsigned GetSize (Mat matrix)
static void GetOwnershipRange (Mat matrix, PetscInt &lo, PetscInt &hi)
static double GetElement (Mat matrix, PetscInt row, PetscInt col)
static void SetOption (Mat matrix, MatOption option)
static Vec GetMatrixRowDistributed (Mat matrix, unsigned rowIndex)
static bool CheckEquality (const Mat mat1, const Mat mat2, double tol=1e-10)
static bool CheckSymmetry (const Mat matrix, double tol=1e-10)
template<size_t MATRIX_SIZE>
static void AddMultipleValues (Mat matrix, unsigned *matrixRowAndColIndices, c_matrix< double, MATRIX_SIZE, MATRIX_SIZE > &rSmallMatrix)

Detailed Description

A collection of static methods for working with PETSc matrices.

Definition at line 48 of file PetscMatTools.hpp.


Member Function Documentation

template<size_t MATRIX_SIZE>
static void PetscMatTools::AddMultipleValues ( Mat  matrix,
unsigned matrixRowAndColIndices,
c_matrix< double, MATRIX_SIZE, MATRIX_SIZE > &  rSmallMatrix 
) [inline, static]

Add multiple values to a matrix.

Parameters:
matrixthe matrix
matrixRowAndColIndicesmapping from index of the ublas matrix (see param below) to index of the PETSc matrix of this linear system
rSmallMatrixUblas matrix containing the values to be added

N.B. Values which are not local (ie the row is not owned) will be skipped.

Definition at line 222 of file PetscMatTools.hpp.

References GetOwnershipRange().

Referenced by LinearSystem::AddLhsMultipleValues().

void PetscMatTools::AddToElement ( Mat  matrix,
PetscInt  row,
PetscInt  col,
double  value 
) [static]

Add the specified value to an entry of a matrix.

Parameters:
matrixthe matrix
rowthe row index
colthe column index
valuethe value for this entry

Definition at line 56 of file PetscMatTools.cpp.

References GetOwnershipRange().

Referenced by LinearSystem::AddToMatrixElement(), and NodeBasedCellPopulationWithBuskeUpdate< DIM >::UpdateNodeLocations().

bool PetscMatTools::CheckEquality ( const Mat  mat1,
const Mat  mat2,
double  tol = 1e-10 
) [static]

Check whether two matrices are equal to within a given tolerance.

Parameters:
mat1the first matrix
mat2the second matrix
tolthe tolerance

Definition at line 369 of file PetscMatTools.cpp.

References PetscTools::Destroy().

Referenced by CheckSymmetry(), and AbstractNonlinearAssemblerSolverHybrid< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::VerifyJacobian().

bool PetscMatTools::CheckSymmetry ( const Mat  matrix,
double  tol = 1e-10 
) [static]

Check whether a matrix is symmetrix, to within a given tolerance, by checking if it is (approximately) equal to its transpose.

Note that while there is a PETSc method MatIsSymmetric, it won't work in parallel on some PETSc versions: "Matrix of type <mpiaij> does not support checking for symmetric!"

Also checking for exact equality of the transpose can break on 32bit systems.

Parameters:
matrixthe matrix to check
tolthe tolerance

Definition at line 392 of file PetscMatTools.cpp.

References CheckEquality(), and PetscTools::Destroy().

void PetscMatTools::Display ( Mat  matrix) [static]

Display a matrix.

Parameters:
matrixthe matrix

Definition at line 79 of file PetscMatTools.cpp.

Referenced by LinearSystem::DisplayMatrix().

double PetscMatTools::GetElement ( Mat  matrix,
PetscInt  row,
PetscInt  col 
) [static]

Return an element of a matrix. May only be called for elements you own.

Parameters:
matrixthe matrix
rowthe row index
colthe column index

Definition at line 301 of file PetscMatTools.cpp.

References GetOwnershipRange().

Referenced by LinearSystem::GetMatrixElement(), and ZeroColumn().

Vec PetscMatTools::GetMatrixRowDistributed ( Mat  matrix,
unsigned  rowIndex 
) [static]

Returns the i-th row of the LHS matrix as a distributed PETSc Vec

Parameters:
matrixthe matrix
rowIndexthe row index
Returns:
rowIndex-th row of the matrix in distributed format

Definition at line 328 of file PetscMatTools.cpp.

References PetscTools::CreateVec(), GetOwnershipRange(), and GetSize().

Referenced by AbstractContinuumMechanicsSolver< DIM >::ApplyDirichletBoundaryConditions().

void PetscMatTools::GetOwnershipRange ( Mat  matrix,
PetscInt lo,
PetscInt hi 
) [static]

Get this process's ownership range of the contents of the system.

Parameters:
matrixthe matrix
lolowest index owned by this process
hihighest index owned by this process

Definition at line 296 of file PetscMatTools.cpp.

Referenced by AddMultipleValues(), AddToElement(), GetElement(), GetMatrixRowDistributed(), SetElement(), SetRow(), ZeroColumn(), and ZeroRowsAndColumnsWithValueOnDiagonal().

unsigned PetscMatTools::GetSize ( Mat  matrix) [static]

Get the size of a matrix

Parameters:
matrixthe matrix

Definition at line 287 of file PetscMatTools.cpp.

Referenced by AbstractContinuumMechanicsAssembler< DIM, CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX >::DoAssemble(), and GetMatrixRowDistributed().

void PetscMatTools::SetElement ( Mat  matrix,
PetscInt  row,
PetscInt  col,
double  value 
) [static]
void PetscMatTools::SetOption ( Mat  matrix,
MatOption  option 
) [static]

Set a PETSc matrix option to be true, using the PETSc method MatSetOption.

Parameters:
matrixthe matrix for which to set the option
optionthe option to set

Definition at line 319 of file PetscMatTools.cpp.

Referenced by LinearSystem::SetMatrixIsSymmetric().

void PetscMatTools::SetRow ( Mat  matrix,
PetscInt  row,
double  value 
) [static]

Set all entries in a given row of a matrix to a certain value. This must be called by the process who owns the row, (but other processors will treat it as a null-op

Parameters:
matrixthe matrix
rowthe row index
valuethe value to set each entry in this row

Definition at line 84 of file PetscMatTools.cpp.

References GetOwnershipRange(), and SetElement().

Referenced by LinearSystem::SetMatrixRow().

void PetscMatTools::SwitchWriteMode ( Mat  matrix) [static]

This must be called if switching between inserting or adding values to the matrix, to ensure all processes are in sync. This is a wrapper to PETSc functions like MatAssemblyBegin(matrix, MAT_FLUSH_ASSEMBLY).

Parameters:
matrixthe matrix

Definition at line 73 of file PetscMatTools.cpp.

Referenced by StokesFlowSolver< DIM >::AssembleSystem(), IncompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), AbstractNonlinearAssemblerSolverHybrid< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::ComputeJacobian(), AbstractNonlinearElasticitySolver< DIM >::FinishAssembleSystem(), and LinearSystem::SwitchWriteModeLhsMatrix().

void PetscMatTools::ZeroColumn ( Mat  matrix,
PetscInt  col 
) [static]

Zero a column of a matrix.

Unfortunately there is no equivalent method in Petsc, so this has to be done carefully to ensure that the sparsity structure of the matrix is not broken. Only owned entries which are non-zero are zeroed.

Parameters:
matrixthe matrix
colthe column index

Definition at line 246 of file PetscMatTools.cpp.

References Finalise(), GetElement(), and GetOwnershipRange().

Referenced by LinearSystem::ZeroMatrixColumn().

void PetscMatTools::ZeroRowsAndColumnsWithValueOnDiagonal ( Mat  matrix,
std::vector< unsigned rowColIndices,
double  diagonalValue 
) [static]

Zero several rows and columns of a matrix, putting a given value on the diagonal.

Parameters:
matrixthe matrix
rowColIndicesA list of indices. All the rows with these indices, and all the columns with these indices, will be zeroed. This vector is copied (ie not passed in by reference), as it will be sorted into ascending order
diagonalValuevalue to put in the diagonal entries (of the zeroed rows)

Definition at line 182 of file PetscMatTools.cpp.

References Finalise(), GetOwnershipRange(), and ZeroRowsWithValueOnDiagonal().

Referenced by AbstractContinuumMechanicsSolver< DIM >::ApplyDirichletBoundaryConditions(), and LinearSystem::ZeroMatrixRowsAndColumnsWithValueOnDiagonal().

void PetscMatTools::ZeroRowsWithValueOnDiagonal ( Mat  matrix,
std::vector< unsigned > &  rRows,
double  diagonalValue 
) [static]

Zero several rows of a matrix, putting a given value in the diagonal entries.

*Massively* less expensive than zeroing each matrix row individually

Parameters:
matrixthe matrix
rRowsstd::vector of rows to be zeroed
diagonalValuevalue to put in the diagonal entries (of the zeroed rows)

Definition at line 100 of file PetscMatTools.cpp.

References Finalise(), and PETSC_DESTROY_PARAM.

Referenced by AbstractContinuumMechanicsSolver< DIM >::ApplyDirichletBoundaryConditions(), BoundaryConditionsContainer< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::ApplyDirichletToNonlinearJacobian(), LinearSystem::ZeroMatrixRowsWithValueOnDiagonal(), and ZeroRowsAndColumnsWithValueOnDiagonal().


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