Advanced Multi-Physics (AMP)
On-Line Documentation
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes | List of all members
AMP::LinearAlgebra::NativePetscMatrixData Class Reference

This is a thin wrapper around PETSc Mat. More...

#include <NativePetscMatrixData.h>

Inheritance diagram for AMP::LinearAlgebra::NativePetscMatrixData:
Inheritance graph
[legend]

Public Member Functions

template<class TYPE >
void addValuesByGlobalID (size_t num_rows, size_t num_cols, const size_t *rows, const size_t *cols, const TYPE *values)
 Add values to those in the matrix.
 
void addValuesByGlobalID (size_t, size_t, const size_t *, const size_t *, const void *, const typeID &) override
 Add values to those in the matrix.
 
virtual size_t beginCol () const
 Get the global id of first column in diagonal block.
 
virtual size_t beginRow () const
 Get the global id of the beginning row.
 
std::shared_ptr< MatrixDatacloneMatrixData () const override
 Clone the data.
 
void copyFromMat (Mat m)
 Copy data from a PETSc Mat.
 
std::shared_ptr< VectorcreateInputVector () const
 
std::shared_ptr< VectorcreateOutputVector () const
 
virtual size_t endCol () const
 Get the global id of last column in diagonal block.
 
virtual size_t endRow () const
 Get the global id of the ending row.
 
virtual AMP::Utilities::Backend getBackend () const
 Get the backend.
 
typeID getCoeffType () const override
 Return the typeid of the matrix coeffs.
 
std::vector< size_t > getColumnIDs (size_t) const override
 Given a row, retrieve the non-zero column indices of the matrix in compressed format.
 
AMP_MPI getComm () const override
 Get the comm.
 
uint64_t getID () const
 Get a unique id hash for the vector.
 
std::shared_ptr< Discretization::DOFManagergetLeftDOFManager () const override
 Get the DOFManager associated with a left vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{y}\) is a left vector )
 
virtual std::shared_ptr< VariablegetLeftVariable () const
 Get the variable associated with a left vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{y}\) is a left vector )
 
Mat getMat ()
 
std::shared_ptr< Discretization::DOFManagergetRightDOFManager () const override
 Get the DOFManager associated with a right vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{x}\) is a right vector )
 
virtual std::shared_ptr< VariablegetRightVariable () const
 Get the variable associated with a right vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{x}\) is a right vector )
 
void getRowByGlobalID (size_t, std::vector< size_t > &, std::vector< double > &) const override
 Retrieve a row of the matrix in compressed format.
 
template<class TYPE >
void getValuesByGlobalID (size_t num_rows, size_t num_cols, const size_t *rows, const size_t *cols, TYPE *values) const
 Get values in the matrix.
 
void getValuesByGlobalID (size_t, size_t, const size_t *, const size_t *, void *, const typeID &) const override
 Get values in the matrix.
 
void makeConsistent (AMP::LinearAlgebra::ScatterType t) override
 Perform communication to ensure values in the matrix are the same across cores.
 
virtual std::uint16_t mode () const
 Return CSR mode of the matrix.
 
 NativePetscMatrixData ()
 
 NativePetscMatrixData (Mat m, bool dele=false)
 Construct a matrix from a PETSc Mat.
 
 NativePetscMatrixData (std::shared_ptr< MatrixParametersBase > params)
 
size_t numberColumnIDs (size_t row) const override
 Given a row, retrieve the number of non-zero column indices of the matrix.
 
size_t numGlobalColumns () const override
 Get the number of global columns in the matrix.
 
size_t numGlobalRows () const override
 Get the number of global rows in the matrix.
 
virtual size_t numLocalColumns () const
 Get the number of local columns in the matrix.
 
virtual size_t numLocalRows () const
 Get the number of local rows in the matrix.
 
virtual void registerChildObjects (AMP::IO::RestartManager *manager) const
 Register any child objects.
 
void removeRange (AMP::Scalar, AMP::Scalar) override
 Remove matrix entries within given range.
 
virtual void setBackend (AMP::Utilities::Backend backend)
 
void setMat (Mat mat, bool manage=true)
 
template<class TYPE >
void setValuesByGlobalID (size_t num_rows, size_t num_cols, const size_t *rows, const size_t *cols, const TYPE *values)
 Set values in the matrix.
 
void setValuesByGlobalID (size_t, size_t, const size_t *, const size_t *, const void *, const typeID &) override
 Set values in the matrix.
 
std::shared_ptr< MatrixDatashared_from_this ()
 
std::shared_ptr< const MatrixDatashared_from_this () const
 
std::shared_ptr< MatrixDatatranspose () const override
 Transpose.
 
virtual std::string type () const override
 Return the type of the matrix.
 
virtual void writeRestart (int64_t fid) const
 Write restart data to file.
 
virtual ~NativePetscMatrixData ()
 Destructor.
 

Static Public Member Functions

static std::shared_ptr< MatrixDataduplicateMat (Mat m)
 Create a NativePetscMatrixData with the same non-zero structure.
 

Protected Attributes

uint64_t d_hash = 0
 
std::shared_ptr< MatrixParametersBased_pParameters
 
std::weak_ptr< MatrixDataweak_ptr_
 

Private Attributes

Mat d_Mat = nullptr
 
bool d_MatCreatedInternally = false
 

Detailed Description

This is a thin wrapper around PETSc Mat.

Definition at line 13 of file NativePetscMatrixData.h.

Constructor & Destructor Documentation

◆ NativePetscMatrixData() [1/3]

AMP::LinearAlgebra::NativePetscMatrixData::NativePetscMatrixData ( )

◆ NativePetscMatrixData() [2/3]

AMP::LinearAlgebra::NativePetscMatrixData::NativePetscMatrixData ( std::shared_ptr< MatrixParametersBase params)
explicit

◆ NativePetscMatrixData() [3/3]

AMP::LinearAlgebra::NativePetscMatrixData::NativePetscMatrixData ( Mat  m,
bool  dele = false 
)
explicit

Construct a matrix from a PETSc Mat.

Parameters
[in]mThe Mat to wrap
[in]deleLet this class deallocate the Mat

◆ ~NativePetscMatrixData()

virtual AMP::LinearAlgebra::NativePetscMatrixData::~NativePetscMatrixData ( )
virtual

Destructor.

Member Function Documentation

◆ addValuesByGlobalID() [1/2]

template<class TYPE >
void AMP::LinearAlgebra::MatrixData::addValuesByGlobalID ( size_t  num_rows,
size_t  num_cols,
const size_t *  rows,
const size_t *  cols,
const TYPE *  values 
)
inherited

Add values to those in the matrix.

Parameters
[in]num_rowsThe number of rows represented in values
[in]num_colsThe number of cols represented in values
[in]rowsThe row ids of values
[in]colsThe column ids of values
[in]valuesThe values to add to the matrix (row-major ordering)

This method may fail if the matrix has not allocated a particular (row,col) specified, depending on the actual subclass of matrix used.

◆ addValuesByGlobalID() [2/2]

void AMP::LinearAlgebra::NativePetscMatrixData::addValuesByGlobalID ( size_t  num_rows,
size_t  num_cols,
const size_t *  rows,
const size_t *  cols,
const void *  values,
const typeID id 
)
overridevirtual

Add values to those in the matrix.

Parameters
[in]num_rowsThe number of rows represented in values
[in]num_colsThe number of cols represented in values
[in]rowsThe row ids of values
[in]colsThe column ids of values
[in]valuesThe values to add to the matrix (row-major ordering)
[in]idtypeID of raw data

This method may fail if the matrix has not allocated a particular (row,col) specified, depending on the actual subclass of matrix used.

Implements AMP::LinearAlgebra::MatrixData.

◆ beginCol()

virtual size_t AMP::LinearAlgebra::MatrixData::beginCol ( ) const
virtualinherited

Get the global id of first column in diagonal block.

Returns
beginning global column id

Reimplemented in AMP::LinearAlgebra::CSRMatrixData< Config >.

◆ beginRow()

virtual size_t AMP::LinearAlgebra::MatrixData::beginRow ( ) const
virtualinherited

Get the global id of the beginning row.

Returns
beginning global row id

Reimplemented in AMP::LinearAlgebra::CSRMatrixData< Config >.

◆ cloneMatrixData()

std::shared_ptr< MatrixData > AMP::LinearAlgebra::NativePetscMatrixData::cloneMatrixData ( ) const
overridevirtual

Clone the data.

Implements AMP::LinearAlgebra::MatrixData.

◆ copyFromMat()

void AMP::LinearAlgebra::NativePetscMatrixData::copyFromMat ( Mat  m)

Copy data from a PETSc Mat.

Parameters
[in]mThe matrix with the data

◆ createInputVector()

std::shared_ptr< Vector > AMP::LinearAlgebra::NativePetscMatrixData::createInputVector ( ) const

◆ createOutputVector()

std::shared_ptr< Vector > AMP::LinearAlgebra::NativePetscMatrixData::createOutputVector ( ) const

◆ duplicateMat()

static std::shared_ptr< MatrixData > AMP::LinearAlgebra::NativePetscMatrixData::duplicateMat ( Mat  m)
static

Create a NativePetscMatrixData with the same non-zero structure.

Parameters
[in]mThe matrix to duplicate
Returns
A new matrix with the same non-zero structure

◆ endCol()

virtual size_t AMP::LinearAlgebra::MatrixData::endCol ( ) const
virtualinherited

Get the global id of last column in diagonal block.

Returns
ending global column id

Reimplemented in AMP::LinearAlgebra::CSRMatrixData< Config >.

◆ endRow()

virtual size_t AMP::LinearAlgebra::MatrixData::endRow ( ) const
virtualinherited

Get the global id of the ending row.

Returns
ending global row id

Reimplemented in AMP::LinearAlgebra::CSRMatrixData< Config >.

◆ getBackend()

virtual AMP::Utilities::Backend AMP::LinearAlgebra::MatrixData::getBackend ( ) const
inlinevirtualinherited

Get the backend.

Definition at line 268 of file MatrixData.h.

References AMP_ASSERT, and AMP::LinearAlgebra::MatrixData::d_pParameters.

◆ getCoeffType()

typeID AMP::LinearAlgebra::NativePetscMatrixData::getCoeffType ( ) const
inlineoverridevirtual

Return the typeid of the matrix coeffs.

Implements AMP::LinearAlgebra::MatrixData.

Definition at line 80 of file NativePetscMatrixData.h.

References type().

◆ getColumnIDs()

std::vector< size_t > AMP::LinearAlgebra::NativePetscMatrixData::getColumnIDs ( size_t  row) const
overridevirtual

Given a row, retrieve the non-zero column indices of the matrix in compressed format.

Parameters
[in]rowWhich row

Implements AMP::LinearAlgebra::MatrixData.

◆ getComm()

AMP_MPI AMP::LinearAlgebra::NativePetscMatrixData::getComm ( ) const
overridevirtual

Get the comm.

Reimplemented from AMP::LinearAlgebra::MatrixData.

◆ getID()

uint64_t AMP::LinearAlgebra::MatrixData::getID ( ) const
inherited

Get a unique id hash for the vector.

◆ getLeftDOFManager()

std::shared_ptr< Discretization::DOFManager > AMP::LinearAlgebra::NativePetscMatrixData::getLeftDOFManager ( ) const
overridevirtual

Get the DOFManager associated with a left vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{y}\) is a left vector )

Returns
The DOFManager associated with a left vector

Implements AMP::LinearAlgebra::MatrixData.

◆ getLeftVariable()

virtual std::shared_ptr< Variable > AMP::LinearAlgebra::MatrixData::getLeftVariable ( ) const
inlinevirtualinherited

Get the variable associated with a left vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{y}\) is a left vector )

Returns
The variable associated with a left vector

Definition at line 215 of file MatrixData.h.

References AMP::LinearAlgebra::MatrixData::d_pParameters.

◆ getMat()

Mat AMP::LinearAlgebra::NativePetscMatrixData::getMat ( )
inline

Definition at line 72 of file NativePetscMatrixData.h.

References d_Mat.

◆ getRightDOFManager()

std::shared_ptr< Discretization::DOFManager > AMP::LinearAlgebra::NativePetscMatrixData::getRightDOFManager ( ) const
overridevirtual

Get the DOFManager associated with a right vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{x}\) is a right vector )

Returns
The DOFManager associated with a right vector

Implements AMP::LinearAlgebra::MatrixData.

◆ getRightVariable()

virtual std::shared_ptr< Variable > AMP::LinearAlgebra::MatrixData::getRightVariable ( ) const
inlinevirtualinherited

Get the variable associated with a right vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{x}\) is a right vector )

Returns
The variable associated with a right vector

Definition at line 205 of file MatrixData.h.

References AMP::LinearAlgebra::MatrixData::d_pParameters.

◆ getRowByGlobalID()

void AMP::LinearAlgebra::NativePetscMatrixData::getRowByGlobalID ( size_t  row,
std::vector< size_t > &  cols,
std::vector< double > &  values 
) const
overridevirtual

Retrieve a row of the matrix in compressed format.

Parameters
[in]rowWhich row
[out]colsThe column ids of the returned values
[out]valuesThe values in the row

Implements AMP::LinearAlgebra::MatrixData.

◆ getValuesByGlobalID() [1/2]

template<class TYPE >
void AMP::LinearAlgebra::MatrixData::getValuesByGlobalID ( size_t  num_rows,
size_t  num_cols,
const size_t *  rows,
const size_t *  cols,
TYPE *  values 
) const
inherited

Get values in the matrix.

Parameters
[in]num_rowsThe number of rows represented in values
[in]num_colsThe number of cols represented in values
[in]rowsThe row ids of values
[in]colsThe column ids of values
[out]valuesThe values to get from the matrix (row-major ordering)

This method will return zero for any entries that have not been allocated or are not ghosts on the current processor.

◆ getValuesByGlobalID() [2/2]

void AMP::LinearAlgebra::NativePetscMatrixData::getValuesByGlobalID ( size_t  num_rows,
size_t  num_cols,
const size_t *  rows,
const size_t *  cols,
void *  values,
const typeID id 
) const
overridevirtual

Get values in the matrix.

Parameters
[in]num_rowsThe number of rows represented in values
[in]num_colsThe number of cols represented in values
[in]rowsThe row ids of values
[in]colsThe column ids of values
[out]valuesThe values to get from the matrix (row-major ordering)
[in]idtypeID of raw data

This method will return zero for any entries that have not been allocated or are not ghosts on the current processor.

Implements AMP::LinearAlgebra::MatrixData.

◆ makeConsistent()

void AMP::LinearAlgebra::NativePetscMatrixData::makeConsistent ( AMP::LinearAlgebra::ScatterType  t)
overridevirtual

Perform communication to ensure values in the matrix are the same across cores.

Implements AMP::LinearAlgebra::MatrixData.

◆ mode()

virtual std::uint16_t AMP::LinearAlgebra::MatrixData::mode ( ) const
inlinevirtualinherited

Return CSR mode of the matrix.

Reimplemented in AMP::LinearAlgebra::CSRMatrixData< Config >.

Definition at line 57 of file MatrixData.h.

◆ numberColumnIDs()

size_t AMP::LinearAlgebra::NativePetscMatrixData::numberColumnIDs ( size_t  row) const
overridevirtual

Given a row, retrieve the number of non-zero column indices of the matrix.

Parameters
[in]rowWhich row

Implements AMP::LinearAlgebra::MatrixData.

◆ numGlobalColumns()

size_t AMP::LinearAlgebra::NativePetscMatrixData::numGlobalColumns ( ) const
overridevirtual

Get the number of global columns in the matrix.

Returns
The number of global columns

Reimplemented from AMP::LinearAlgebra::MatrixData.

◆ numGlobalRows()

size_t AMP::LinearAlgebra::NativePetscMatrixData::numGlobalRows ( ) const
overridevirtual

Get the number of global rows in the matrix.

Returns
The number of global rows

Reimplemented from AMP::LinearAlgebra::MatrixData.

◆ numLocalColumns()

virtual size_t AMP::LinearAlgebra::MatrixData::numLocalColumns ( ) const
virtualinherited

Get the number of local columns in the matrix.

Returns
The number of local columns

Reimplemented in AMP::LinearAlgebra::CSRMatrixData< Config >, AMP::LinearAlgebra::DenseSerialMatrixData, and AMP::LinearAlgebra::EpetraMatrixData.

◆ numLocalRows()

virtual size_t AMP::LinearAlgebra::MatrixData::numLocalRows ( ) const
virtualinherited

Get the number of local rows in the matrix.

Returns
The number of local rows

Reimplemented in AMP::LinearAlgebra::CSRMatrixData< Config >, AMP::LinearAlgebra::DenseSerialMatrixData, and AMP::LinearAlgebra::EpetraMatrixData.

◆ registerChildObjects()

virtual void AMP::LinearAlgebra::MatrixData::registerChildObjects ( AMP::IO::RestartManager manager) const
virtualinherited

Register any child objects.

This function will register child objects with the manager

Parameters
managerRestart manager

Reimplemented in AMP::LinearAlgebra::CSRMatrixData< Config >.

◆ removeRange()

void AMP::LinearAlgebra::NativePetscMatrixData::removeRange ( AMP::Scalar  bnd_lo,
AMP::Scalar  bnd_up 
)
inlineoverridevirtual

Remove matrix entries within given range.

Implements AMP::LinearAlgebra::MatrixData.

Definition at line 49 of file NativePetscMatrixData.h.

References AMP_ERROR.

◆ setBackend()

virtual void AMP::LinearAlgebra::MatrixData::setBackend ( AMP::Utilities::Backend  backend)
inlinevirtualinherited

Definition at line 274 of file MatrixData.h.

References AMP_ASSERT, and AMP::LinearAlgebra::MatrixData::d_pParameters.

◆ setMat()

void AMP::LinearAlgebra::NativePetscMatrixData::setMat ( Mat  mat,
bool  manage = true 
)

◆ setValuesByGlobalID() [1/2]

template<class TYPE >
void AMP::LinearAlgebra::MatrixData::setValuesByGlobalID ( size_t  num_rows,
size_t  num_cols,
const size_t *  rows,
const size_t *  cols,
const TYPE *  values 
)
inherited

Set values in the matrix.

Parameters
[in]num_rowsThe number of rows represented in values
[in]num_colsThe number of cols represented in values
[in]rowsThe row ids of values
[in]colsThe column ids of values
[in]valuesThe values to set to the matrix (row-major ordering)

This method may fail if the matrix has not allocated a particular (row,col) specified, depending on the actual subclass of matrix used.

◆ setValuesByGlobalID() [2/2]

void AMP::LinearAlgebra::NativePetscMatrixData::setValuesByGlobalID ( size_t  num_rows,
size_t  num_cols,
const size_t *  rows,
const size_t *  cols,
const void *  values,
const typeID id 
)
overridevirtual

Set values in the matrix.

Parameters
[in]num_rowsThe number of rows represented in values
[in]num_colsThe number of cols represented in values
[in]rowsThe row ids of values
[in]colsThe column ids of values
[in]valuesThe values to set to the matrix (row-major ordering)
[in]idtypeID of raw data

This method may fail if the matrix has not allocated a particular (row,col) specified, depending on the actual subclass of matrix used.

Implements AMP::LinearAlgebra::MatrixData.

◆ shared_from_this() [1/2]

std::shared_ptr< MatrixData > AMP::enable_shared_from_this< MatrixData >::shared_from_this ( )
inlineinherited

Definition at line 28 of file enable_shared_from_this.h.

◆ shared_from_this() [2/2]

std::shared_ptr< const MatrixData > AMP::enable_shared_from_this< MatrixData >::shared_from_this ( ) const
inlineinherited

Definition at line 46 of file enable_shared_from_this.h.

◆ transpose()

std::shared_ptr< MatrixData > AMP::LinearAlgebra::NativePetscMatrixData::transpose ( ) const
overridevirtual

Transpose.

Implements AMP::LinearAlgebra::MatrixData.

◆ type()

virtual std::string AMP::LinearAlgebra::NativePetscMatrixData::type ( ) const
inlineoverridevirtual

Return the type of the matrix.

Implements AMP::LinearAlgebra::MatrixData.

Definition at line 43 of file NativePetscMatrixData.h.

Referenced by getCoeffType().

◆ writeRestart()

virtual void AMP::LinearAlgebra::MatrixData::writeRestart ( int64_t  fid) const
virtualinherited

Write restart data to file.

This function will write the mesh to an HDF5 file

Parameters
fidFile identifier to write

Reimplemented in AMP::LinearAlgebra::CSRMatrixData< Config >.

Member Data Documentation

◆ d_hash

uint64_t AMP::LinearAlgebra::MatrixData::d_hash = 0
protectedinherited

Definition at line 311 of file MatrixData.h.

◆ d_Mat

Mat AMP::LinearAlgebra::NativePetscMatrixData::d_Mat = nullptr
private

Definition at line 87 of file NativePetscMatrixData.h.

Referenced by getMat().

◆ d_MatCreatedInternally

bool AMP::LinearAlgebra::NativePetscMatrixData::d_MatCreatedInternally = false
private

Definition at line 88 of file NativePetscMatrixData.h.

◆ d_pParameters

std::shared_ptr<MatrixParametersBase> AMP::LinearAlgebra::MatrixData::d_pParameters
protectedinherited

◆ weak_ptr_

std::weak_ptr<MatrixData > AMP::enable_shared_from_this< MatrixData >::weak_ptr_
mutableprotectedinherited

Definition at line 69 of file enable_shared_from_this.h.


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



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:43.
Comments on this page