https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PetscVectorReader Class Reference

A class which helps with repeated reading from a petsc vector. More...

#include <PetscVectorReader.h>

Public Member Functions

 PetscVectorReader (PetscVector< Number > &vec)
 Construct using a pets vector.
 
 PetscVectorReader (NumericVector< Number > &vec)
 Construct using a numeric vector.
 
 ~PetscVectorReader ()
 Destructor to make sure the vector is restored every time this goes out of scope.
 
void restore ()
 Restore the array, usually upon going out of scope.
 
PetscScalar operator() (const numeric_index_type i) const
 Access a value in the petsc vector.
 

Private Member Functions

bool readable () const
 Check if this vector is readable.
 

Private Attributes

PetscVector< Number > & _vec
 Reference to the petsc vector whose values shall be read.
 
const PetscScalar * _raw_value
 The raw values in the vector.
 

Detailed Description

A class which helps with repeated reading from a petsc vector.

Its main purpose is to avoid unnecessary calls to the get_array() function in the wrapper.

Definition at line 27 of file PetscVectorReader.h.

Constructor & Destructor Documentation

◆ PetscVectorReader() [1/2]

PetscVectorReader::PetscVectorReader ( PetscVector< Number > &  vec)

Construct using a pets vector.

Definition at line 12 of file PetscVectorReader.C.

13 : _vec(vec), _raw_value(vec.get_array_read())
14{
15}
const PetscScalar * _raw_value
The raw values in the vector.
PetscVector< Number > & _vec
Reference to the petsc vector whose values shall be read.
const PetscScalar * get_array_read() const

◆ PetscVectorReader() [2/2]

PetscVectorReader::PetscVectorReader ( NumericVector< Number > &  vec)

Construct using a numeric vector.

Definition at line 17 of file PetscVectorReader.C.

18 : _vec(libMesh::cast_ref<PetscVector<Number> &>(vec)), _raw_value(_vec.get_array_read())
19{
20}
Tnew cast_ref(Told &oldvar)

◆ ~PetscVectorReader()

PetscVectorReader::~PetscVectorReader ( )

Destructor to make sure the vector is restored every time this goes out of scope.

Definition at line 22 of file PetscVectorReader.C.

22{ restore(); }
void restore()
Restore the array, usually upon going out of scope.

Member Function Documentation

◆ operator()()

PetscScalar PetscVectorReader::operator() ( const numeric_index_type  i) const
inline

Access a value in the petsc vector.

Definition at line 58 of file PetscVectorReader.h.

59{
60 mooseAssert(readable(), "Not readable");
62 return _raw_value[local_index];
63}
bool readable() const
Check if this vector is readable.
numeric_index_type map_global_to_local_index(const numeric_index_type i) const
dof_id_type numeric_index_type

◆ readable()

bool PetscVectorReader::readable ( ) const
inlineprivate

Check if this vector is readable.

Definition at line 48 of file PetscVectorReader.h.

48{ return _raw_value != nullptr; }

Referenced by operator()(), and restore().

◆ restore()

void PetscVectorReader::restore ( )

Restore the array, usually upon going out of scope.

Definition at line 25 of file PetscVectorReader.C.

26{
27 mooseAssert(readable(), "Array not retrieved");
29 _raw_value = nullptr;
30}

Referenced by ~PetscVectorReader().

Member Data Documentation

◆ _raw_value

const PetscScalar* PetscVectorReader::_raw_value
private

The raw values in the vector.

Definition at line 54 of file PetscVectorReader.h.

Referenced by operator()(), readable(), and restore().

◆ _vec

PetscVector<Number>& PetscVectorReader::_vec
private

Reference to the petsc vector whose values shall be read.

Definition at line 51 of file PetscVectorReader.h.

Referenced by operator()(), and restore().


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