https://mooseframework.inl.gov
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. More...
 
 PetscVectorReader (NumericVector< Number > &vec)
 Construct using a numeric vector. More...
 
 ~PetscVectorReader ()
 Destructor to make sure the vector is restored every time this goes out of scope. More...
 
void restore ()
 Restore the array, usually upon going out of scope. More...
 
PetscScalar operator() (const numeric_index_type i) const
 Access a value in the petsc vector. More...
 

Private Member Functions

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

Private Attributes

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

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.

◆ PetscVectorReader() [2/2]

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

Construct using a numeric vector.

◆ ~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");
61  const numeric_index_type local_index = _vec.map_global_to_local_index(i);
62  return _raw_value[local_index];
63 }
const PetscScalar * _raw_value
The raw values in the vector.
PetscVector< Number > & _vec
Reference to the petsc vector whose values shall be read.
dof_id_type numeric_index_type
numeric_index_type map_global_to_local_index(const numeric_index_type i) const
bool readable() const
Check if this vector is readable.

◆ readable()

bool PetscVectorReader::readable ( ) const
inlineprivate

Check if this vector is readable.

Definition at line 48 of file PetscVectorReader.h.

Referenced by operator()().

48 { return _raw_value != nullptr; }
const PetscScalar * _raw_value
The raw values in the vector.

◆ 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 }
const PetscScalar * _raw_value
The raw values in the vector.
PetscVector< Number > & _vec
Reference to the petsc vector whose values shall be read.
bool readable() const
Check if this vector is readable.

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()(), and readable().

◆ _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()().


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