Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
|
#include <PetscMatTools.hpp>
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) |
static void | TurnOffVariableAllocationError (Mat matrix) |
template<size_t MATRIX_SIZE> | |
static void | AddMultipleValues (Mat matrix, unsigned *matrixRowAndColIndices, c_matrix< double, MATRIX_SIZE, MATRIX_SIZE > &rSmallMatrix) |
A collection of static methods for working with PETSc matrices.
Definition at line 48 of file PetscMatTools.hpp.
|
inlinestatic |
Add multiple values to a matrix.
matrix | the matrix |
matrixRowAndColIndices | mapping from index of the ublas matrix (see param below) to index of the PETSc matrix of this linear system |
rSmallMatrix | Ublas 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 237 of file PetscMatTools.hpp.
References GetOwnershipRange().
Referenced by LinearSystem::AddLhsMultipleValues().
Add the specified value to an entry of a matrix.
matrix | the matrix |
row | the row index |
col | the column index |
value | the value for this entry |
Definition at line 56 of file PetscMatTools.cpp.
References GetOwnershipRange().
Referenced by LinearSystem::AddToMatrixElement(), and NodeBasedCellPopulationWithBuskeUpdate< DIM >::UpdateNodeLocations().
mat1 | the first matrix |
mat2 | the second matrix |
tol | the tolerance |
Definition at line 378 of file PetscMatTools.cpp.
References PetscTools::Destroy().
Referenced by CheckSymmetry(), and AbstractNonlinearAssemblerSolverHybrid< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::VerifyJacobian().
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.
matrix | the matrix to check |
tol | the tolerance |
Definition at line 401 of file PetscMatTools.cpp.
References CheckEquality(), and PetscTools::Destroy().
|
static |
Display a matrix.
matrix | the matrix |
Definition at line 79 of file PetscMatTools.cpp.
Referenced by LinearSystem::DisplayMatrix().
|
static |
Sets up the matrix ready for use, e.g. in solving a linear system. This is a wrapper to PETSc functions like MatAssemblyBegin(matrix, MAT_FINAL_ASSEMBLY).
matrix | the matrix |
Definition at line 67 of file PetscMatTools.cpp.
Referenced by AbstractContinuumMechanicsSolver< DIM >::ApplyDirichletBoundaryConditions(), BoundaryConditionsContainer< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::ApplyDirichletToNonlinearJacobian(), StokesFlowSolver< DIM >::AssembleSystem(), AbstractNonlinearAssemblerSolverHybrid< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::ComputeJacobian(), AbstractNonlinearAssemblerSolverHybrid< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::ComputeJacobianNumerically(), LinearSystem::FinaliseLhsMatrix(), LinearSystem::FinalisePrecondMatrix(), AbstractNonlinearElasticitySolver< DIM >::FinishAssembleSystem(), NodePartitioner< ELEMENT_DIM, SPACE_DIM >::PetscMatrixPartitioning(), BidomainSolver< ELEMENT_DIM, SPACE_DIM >::SetupLinearSystem(), ExtendedBidomainSolver< ELEM_DIM, SPACE_DIM >::SetupLinearSystem(), MonodomainPurkinjeSolver< ELEMENT_DIM, SPACE_DIM >::SetupLinearSystem(), MonodomainSolver< ELEMENT_DIM, SPACE_DIM >::SetupLinearSystem(), OperatorSplittingMonodomainSolver< ELEMENT_DIM, SPACE_DIM >::SetupLinearSystem(), NodeBasedCellPopulationWithBuskeUpdate< DIM >::UpdateNodeLocations(), ZeroColumn(), ZeroRowsAndColumnsWithValueOnDiagonal(), and ZeroRowsWithValueOnDiagonal().
matrix | the matrix |
row | the row index |
col | the column index |
Definition at line 310 of file PetscMatTools.cpp.
References GetOwnershipRange().
Referenced by LinearSystem::GetMatrixElement(), and ZeroColumn().
Returns the i-th row of the LHS matrix as a distributed PETSc Vec
matrix | the matrix |
rowIndex | the row index |
Definition at line 337 of file PetscMatTools.cpp.
References PetscTools::CreateVec(), GetOwnershipRange(), and GetSize().
Referenced by AbstractContinuumMechanicsSolver< DIM >::ApplyDirichletBoundaryConditions(), and LinearSystem::GetMatrixRowDistributed().
Returns this process's ownership range of the contents of the matrix via arguments.
matrix | the matrix |
lo | lowest index owned by this process (returned) |
hi | highest index owned by this process (returned) |
Definition at line 305 of file PetscMatTools.cpp.
Referenced by AddMultipleValues(), AddToElement(), GetElement(), GetMatrixRowDistributed(), SetElement(), SetRow(), ZeroColumn(), and ZeroRowsAndColumnsWithValueOnDiagonal().
matrix | the matrix |
Definition at line 296 of file PetscMatTools.cpp.
Referenced by AbstractContinuumMechanicsAssembler< DIM, CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX >::DoAssemble(), and GetMatrixRowDistributed().
Change one of the entries of a matrix to the specified value.
matrix | the matrix |
row | the row index |
col | the column index |
value | the value for this entry |
Definition at line 45 of file PetscMatTools.cpp.
References GetOwnershipRange().
Referenced by AbstractContinuumMechanicsSolver< DIM >::AddIdentityBlockForDummyPressureVariables(), BoundaryConditionsContainer< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::ApplyPeriodicBcsToLinearProblem(), AbstractNonlinearAssemblerSolverHybrid< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::ComputeJacobianNumerically(), AbstractBidomainSolver< ELEMENT_DIM, SPACE_DIM >::FinaliseForBath(), MonodomainPurkinjeSolver< ELEMENT_DIM, SPACE_DIM >::SetIdentityBlockToLhsMatrix(), LinearSystem::SetMatrixElement(), and SetRow().
|
static |
Set a PETSc matrix option to be true, using the PETSc method MatSetOption.
matrix | the matrix for which to set the option |
option | the option to set |
Definition at line 328 of file PetscMatTools.cpp.
Referenced by LinearSystem::SetMatrixIsSymmetric().
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)
matrix | the matrix |
row | the row index |
value | the value to set each entry in this row |
Definition at line 93 of file PetscMatTools.cpp.
References GetOwnershipRange(), and SetElement().
Referenced by LinearSystem::SetMatrixRow().
|
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).
matrix | the 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(), MonodomainPurkinjeSolver< ELEMENT_DIM, SPACE_DIM >::SetIdentityBlockToLhsMatrix(), and LinearSystem::SwitchWriteModeLhsMatrix().
|
static |
Tells PETSc to set MAT_NEW_NONZERO_ALLOCATION_ERR to false.
This should be called immediately after PetscTools::SetupMat and before any other operations on the matrix.
** Currently only used in PETSc 3.3 and later ** in PETSc 3.2 and earlier MAT_NEW_NONZERO_ALLOCATION_ERR defaults to false in PETSc 3.3 MAT_NEW_NONZERO_ALLOCATION_ERR defaults to true
matrix | The matrix to set |
Definition at line 414 of file PetscMatTools.cpp.
Referenced by AbstractBidomainSolver< DIM, DIM >::InitialiseForSolve(), and AbstractExtendedBidomainSolver< ELEMENT_DIM, SPACE_DIM >::InitialiseForSolve().
|
static |
Zero all entries of a matrix.
matrix | the matrix |
Definition at line 291 of file PetscMatTools.cpp.
Referenced by CompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), IncompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), AbstractContinuumMechanicsAssembler< DIM, CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX >::DoAssemble(), AbstractFeCableIntegralAssembler< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX, INTERPOLATION_LEVEL >::DoAssemble(), AbstractFeVolumeIntegralAssembler< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX, INTERPOLATION_LEVEL >::DoAssemble(), and LinearSystem::ZeroLhsMatrix().
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.
matrix | the matrix |
col | the column index |
Definition at line 255 of file PetscMatTools.cpp.
References Finalise(), GetElement(), and GetOwnershipRange().
Referenced by LinearSystem::ZeroMatrixColumn().
|
static |
Zero several rows and columns of a matrix, putting a given value on the diagonal.
matrix | the matrix |
rowColIndices | A 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 |
diagonalValue | value to put in the diagonal entries (of the zeroed rows) |
Definition at line 191 of file PetscMatTools.cpp.
References CHASTE_PETSC_NULLPTR, Finalise(), GetOwnershipRange(), and ZeroRowsWithValueOnDiagonal().
Referenced by AbstractContinuumMechanicsSolver< DIM >::ApplyDirichletBoundaryConditions(), and LinearSystem::ZeroMatrixRowsAndColumnsWithValueOnDiagonal().
|
static |
Zero several rows of a matrix, putting a given value in the diagonal entries.
*Massively* less expensive than zeroing each matrix row individually
matrix | the matrix |
rRows | std::vector of rows to be zeroed |
diagonalValue | value to put in the diagonal entries (of the zeroed rows) |
Definition at line 109 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().