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

PetscVector is a bridge between AMP::LinearAlgebra::Vector and the PETSc Vec data structure. More...

#include <PetscVector.h>

Public Member Functions

std::shared_ptr< VectorgetManagedVec ()
 
std::shared_ptr< const VectorgetManagedVec () const
 
VecgetNativeVec ()
 
const VecgetNativeVec () const
 
VecgetVec ()
 Obtain PETSc Vec for use in PETSc routines.
 
const VecgetVec () const
 Obtain PETSc Vec for use in PETSc routines.
 
virtual ~PetscVector ()
 Destructor.
 

Static Public Member Functions

static std::shared_ptr< const PetscVectorconstView (Vector::const_shared_ptr AmpVector)
 If needed, create a PETSc wrapper for AmpVector. Otherwise, return AmpVector.
 
static std::shared_ptr< PetscVectorview (Vector::shared_ptr AmpVector)
 If needed, create a PETSc wrapper for AmpVector. Otherwise, return AmpVector.
 

Protected Member Functions

 PetscVector ()
 Empty constructor.
 
 PetscVector (std::shared_ptr< Vector > vec)
 Default constructor.
 

Protected Attributes

Vec d_Vec
 
std::shared_ptr< Vectord_vector
 

Detailed Description

PetscVector is a bridge between AMP::LinearAlgebra::Vector and the PETSc Vec data structure.

A PetscVector has a Vec data structure. Given an AMP::LinearAlgebra::Vector, this class can create a PETSc view without copying the data. As such, this class serves three purposes:

  1. Provides a PETSc Vec for derived classes to use, fill, manage, etc.
  2. Provides an interface for accessing this PETSc Vec independent of derived classes
  3. Provides a static method for creating a PETSc view of an AMP Vector.

Definition at line 26 of file PetscVector.h.

Constructor & Destructor Documentation

◆ ~PetscVector()

virtual AMP::LinearAlgebra::PetscVector::~PetscVector ( )
virtual

Destructor.

◆ PetscVector() [1/2]

AMP::LinearAlgebra::PetscVector::PetscVector ( )
protected

Empty constructor.

◆ PetscVector() [2/2]

AMP::LinearAlgebra::PetscVector::PetscVector ( std::shared_ptr< Vector vec)
explicitprotected

Default constructor.

Member Function Documentation

◆ constView()

static std::shared_ptr< const PetscVector > AMP::LinearAlgebra::PetscVector::constView ( Vector::const_shared_ptr  AmpVector)
static

If needed, create a PETSc wrapper for AmpVector. Otherwise, return AmpVector.

The function attempts to return a view with the least amount of work. It will never copy data. If the vector cannot be wrapped it wll return an error.

Parameters
AmpVectora shared pointer to a Vector

◆ getManagedVec() [1/2]

std::shared_ptr< Vector > AMP::LinearAlgebra::PetscVector::getManagedVec ( )
inline

Definition at line 102 of file PetscVector.h.

References d_vector.

◆ getManagedVec() [2/2]

std::shared_ptr< const Vector > AMP::LinearAlgebra::PetscVector::getManagedVec ( ) const
inline

Definition at line 103 of file PetscVector.h.

References d_vector.

◆ getNativeVec() [1/2]

Vec & AMP::LinearAlgebra::PetscVector::getNativeVec ( )
inline

Definition at line 100 of file PetscVector.h.

References d_Vec.

◆ getNativeVec() [2/2]

const Vec & AMP::LinearAlgebra::PetscVector::getNativeVec ( ) const
inline

Definition at line 101 of file PetscVector.h.

References d_Vec.

◆ getVec() [1/2]

Vec & AMP::LinearAlgebra::PetscVector::getVec ( )
inline

Obtain PETSc Vec for use in PETSc routines.

This function is used to get a PETSc vector. The following idiom should be used since it fails gracefully. In this function, a view may be created before the Vec is extracted

double DoPETScMax ( Vector::shared_ptr &in )
{
double ans;
// Create a PETSc Vec if necessary
Vector::shared_ptr in_petsc_view = PetscVector::view( in );
// Extract the Vec
Vec in_vec = std::dynamic_pointer_cast<PetscVector>(in_petsc_view)->getVec();
// Perform a PETSc operation
VecMax ( in_vec , &abs );
return ans;
}
static std::shared_ptr< PetscVector > view(Vector::shared_ptr AmpVector)
If needed, create a PETSc wrapper for AmpVector. Otherwise, return AmpVector.
std::shared_ptr< Vector > shared_ptr
Shorthand for shared pointer to Vector.
Definition Vector.h:60
PETSc vector.

Definition at line 56 of file PetscVector.h.

References d_Vec.

◆ getVec() [2/2]

const Vec & AMP::LinearAlgebra::PetscVector::getVec ( ) const
inline

Obtain PETSc Vec for use in PETSc routines.

This function is used to get a PETSc vector. The following idiom should be used since it fails gracefully. In this function, a view may be created before the Vec is extracted

double DoPETScMax ( Vector::shared_ptr &in )
{
double ans;
// Create a PETSc Vec if necessary
Vector::shared_ptr in_petsc_view = PetscVector::view( in );
// Extract the Vec
Vec in_vec = std::dynamic_pointer_cast<PetscVector>(in_petsc_view)->getVec();
// Perform a PETSc operation
VecMax ( in_vec , &abs );
return ans;
}

Definition at line 80 of file PetscVector.h.

References d_Vec.

◆ view()

static std::shared_ptr< PetscVector > AMP::LinearAlgebra::PetscVector::view ( Vector::shared_ptr  AmpVector)
static

If needed, create a PETSc wrapper for AmpVector. Otherwise, return AmpVector.

The function attempts to return a view with the least amount of work. It will never copy data. If the vector cannot be wrapped it wll return an error.

Parameters
AmpVectora shared pointer to a Vector

Referenced by AMP::LinearAlgebra::PetscViewFactory::getVec().

Member Data Documentation

◆ d_Vec

Vec AMP::LinearAlgebra::PetscVector::d_Vec
protected

Definition at line 114 of file PetscVector.h.

Referenced by getNativeVec(), getNativeVec(), getVec(), and getVec().

◆ d_vector

std::shared_ptr<Vector> AMP::LinearAlgebra::PetscVector::d_vector
protected

Definition at line 115 of file PetscVector.h.

Referenced by getManagedVec(), and getManagedVec().


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