Loading...
Searching...
No Matches
dolfin::PETScVector Class Reference

`#include <PETScVector.h>`

Inheritance diagram for dolfin::PETScVector:
[legend]
Collaboration diagram for dolfin::PETScVector:
[legend]

## Public Member Functions

| PETScVector ()
| Create empty vector (on MPI_COMM_WORLD).
| PETScVector (MPI_Comm comm)
| Create empty vector on an MPI communicator.
| PETScVector (MPI_Comm comm, std::size_t N)
| Create vector of size N.
| PETScVector (const SparsityPattern &sparsity_pattern)
| Create vector.
| PETScVector (const PETScVector &x)
| Copy constructor.
| PETScVector (Vec x)
virtual | ~PETScVector ()
| Destructor.
virtual void | zero ()
| Set all entries to zero and keep any sparse structure.
virtual void | apply (std::string mode)
| Finalize assembly of tensor.
virtual MPI_Comm | mpi_comm () const
| Return MPI communicator.
virtual std::string | str (bool verbose) const
| Return informal string representation (pretty-print).
virtual std::shared_ptr< GenericVector > | copy () const
| Return copy of vector.
virtual void | init (std::size_t N)
| Initialize vector to global size N.
virtual void | init (std::pair< std::size_t, std::size_t > range)
| Initialize vector with given ownership range.
virtual void | init (std::pair< std::size_t, std::size_t > range, const std::vector< std::size_t > &local_to_global_map, const std::vector< la_index > &ghost_indices)
virtual bool | empty () const
| Return true if vector is empty.
virtual std::size_t | size () const
| Return size of vector.
virtual std::size_t | local_size () const
| Return local size of vector.
virtual std::pair< std::int64_t, std::int64_t > | local_range () const
| Return ownership range of a vector.
virtual bool | owns_index (std::size_t i) const
| Determine whether global vector index is owned by this process.
virtual void | get (double *block, std::size_t m, const dolfin::la_index *rows) const
virtual void | get_local (double *block, std::size_t m, const dolfin::la_index *rows) const
| Get block of values using local indices.
virtual void | set (const double *block, std::size_t m, const dolfin::la_index *rows)
| Set block of values using global indices.
virtual void | set_local (const double *block, std::size_t m, const dolfin::la_index *rows)
| Set block of values using local indices.
virtual void | add (const double *block, std::size_t m, const dolfin::la_index *rows)
| Add block of values using global indices.
virtual void | add_local (const double *block, std::size_t m, const dolfin::la_index *rows)
| Add block of values using local indices.
virtual void | get_local (std::vector< double > &values) const
| Get all values on local process.
virtual void | set_local (const std::vector< double > &values)
| Set all values on local process.
virtual void | add_local (const Array< double > &values)
| Add values to each entry on local process.
virtual void | gather (GenericVector &y, const std::vector< dolfin::la_index > &indices) const
virtual void | gather (std::vector< double > &x, const std::vector< dolfin::la_index > &indices) const
virtual void | gather_on_zero (std::vector< double > &x) const
virtual void | axpy (double a, const GenericVector &x)
| Add multiple of given vector (AXPY operation).
virtual void | abs ()
| Replace all entries in the vector by their absolute values.
virtual double | inner (const GenericVector &v) const
| Return inner product with given vector.
virtual double | norm (std::string norm_type) const
| Return norm of vector.
virtual double | min () const
| Return minimum value of vector.
virtual double | max () const
| Return maximum value of vector.
virtual double | sum () const
| Return sum of values of vector.
virtual double | sum (const Array< std::size_t > &rows) const
| Return sum of selected rows in vector.
virtual const PETScVector & | operator*= (double a)
| Multiply vector by given number.
virtual const PETScVector & | operator*= (const GenericVector &x)
| Multiply vector by another vector pointwise.
virtual const PETScVector & | operator/= (double a)
| Divide vector by given number.
virtual const PETScVector & | operator+= (const GenericVector &x)
| Add given vector.
virtual const PETScVector & | operator+= (double a)
| Add number to all components of a vector.
virtual const PETScVector & | operator-= (const GenericVector &x)
| Subtract given vector.
virtual const PETScVector & | operator-= (double a)
| Subtract number from all components of a vector.
virtual const GenericVector & | operator= (const GenericVector &x)
| Assignment operator.
virtual const PETScVector & | operator= (double a)
| Assignment operator.
virtual void | update_ghost_values ()
| Update values shared from remote processes.
virtual GenericLinearAlgebraFactory & | factory () const
| Return linear algebra backend factory.
void | set_options_prefix (std::string options_prefix)
std::string | get_options_prefix () const
void | set_from_options ()
Vec | vec () const
| Return pointer to PETSc Vec object.
const PETScVector & | operator= (const PETScVector &x)
| Assignment operator.
void | reset (Vec vec)
virtual void | init (const TensorLayout &tensor_layout)
Public Member Functions inherited from dolfin::GenericVector
virtual | ~GenericVector ()
| Destructor.
virtual std::size_t | rank () const
| Return tensor rank (number of dimensions).
virtual std::size_t | size (std::size_t dim) const
| Return size of given dimension.
virtual std::pair< std::int64_t, std::int64_t > | local_range (std::size_t dim) const
| Return local ownership range.
virtual void | get (double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows) const
| Get block of values using global indices.
virtual void | get_local (double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows) const
| Get block of values using local indices.
virtual void | set (const double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows)
| Set block of values using global indices.
virtual void | set_local (const double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows)
| Set block of values using local indices.
virtual void | add (const double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows)
| Add block of values using global indices.
virtual void | add_local (const double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows)
| Add block of values using local indices.
virtual void | add (const double *block, const std::vector< ArrayView< const dolfin::la_index > > &rows)
| Add block of values using global indices.
virtual void | add_local (const double *block, const std::vector< ArrayView< const dolfin::la_index > > &rows)
| Add block of values using local indices.
std::shared_ptr< GenericVector > | operator+ (const GenericVector &x)
| Sum two vectors (returns a new vector).
std::shared_ptr< GenericVector > | operator+ (double a)
| Add scalar to a vector (returns a new vector).
std::shared_ptr< GenericVector > | operator* (double a)
| Multiply vector by a scalar (returns a new vector).
virtual double | operator[] (dolfin::la_index i) const
| Get value of given entry.
virtual double | getitem (dolfin::la_index i) const
| Get value of given entry.
virtual void | setitem (dolfin::la_index i, double value)
Public Member Functions inherited from dolfin::GenericTensor
virtual | ~GenericTensor ()
| Destructor.
Public Member Functions inherited from dolfin::LinearAlgebraObject
virtual const LinearAlgebraObject * | instance () const
| Return concrete instance / unwrap (const version).
virtual LinearAlgebraObject * | instance ()
| Return concrete instance / unwrap (non-const version).
virtual std::shared_ptr< const LinearAlgebraObject > | shared_instance () const
| Return concrete shared ptr instance / unwrap (const version).
virtual std::shared_ptr< LinearAlgebraObject > | shared_instance ()
| Return concrete shared ptr instance / unwrap (non-const version).
Public Member Functions inherited from dolfin::Variable
| Variable ()
| Create unnamed variable.
| Variable (const std::string name, const std::string label)
| Create variable with given name and label.
| Variable (const Variable &variable)
| Copy constructor.
virtual | ~Variable ()
| Destructor.
const Variable & | operator= (const Variable &variable)
| Assignment operator.
void | rename (const std::string name, const std::string label)
| Rename variable.
std::string | name () const
| Return name.
std::string | label () const
| Return label (description).
std::size_t | id () const
Public Member Functions inherited from dolfin::PETScObject
| PETScObject ()
| Constructor. Ensures that PETSc has been initialised.
virtual | ~PETScObject ()
| Destructor.

## Friends

class | PETScNestMatrix

## Additional Inherited Members

Static Public Member Functions inherited from dolfin::PETScObject
static void | petsc_error (int error_code, std::string filename, std::string petsc_function)
| Print error message for PETSc calls that return an error.
Public Attributes inherited from dolfin::Variable
Parameters | parameters
| Parameters.

## Detailed Description

A simple vector class based on PETSc.

It is a simple wrapper for a PETSc vector pointer (Vec) implementing the GenericVector interface.

The interface is intentionally simple. For advanced usage, access the PETSc Vec pointer using the function vec() and use the standard PETSc interface.

## Constructor & Destructor Documentation

## PETScVector()

PETScVector::PETScVector | ( | Vec | x | ) |

explicit

Create vector wrapper of PETSc Vec pointer. The reference counter of the Vec will be increased, and decreased upon destruction of this object.

## Member Function Documentation

## abs()

void PETScVector::abs | ( |  | ) |

virtual

Replace all entries in the vector by their absolute values.

Implements dolfin::GenericVector.

## add()

void PETScVector::add | ( | const double * | block,
|  | std::size_t | m,
|  | const dolfin::la_index * | rows )

virtual

Add block of values using global indices.

Implements dolfin::GenericVector.

## add_local() [1/2]

void PETScVector::add_local | ( | const Array< double > & | values | ) |

virtual

Add values to each entry on local process.

Implements dolfin::GenericVector.

## add_local() [2/2]

void PETScVector::add_local | ( | const double * | block,
|  | std::size_t | m,
|  | const dolfin::la_index * | rows )

virtual

Add block of values using local indices.

Implements dolfin::GenericVector.

## apply()

void PETScVector::apply | ( | std::string | mode | ) |

virtual

Finalize assembly of tensor.

Implements dolfin::GenericVector.

## axpy()

void PETScVector::axpy | ( | double | a,
|  | const GenericVector & | x )

virtual

Add multiple of given vector (AXPY operation).

Implements dolfin::GenericVector.

## copy()

std::shared_ptr< GenericVector > PETScVector::copy | ( |  | ) | const

virtual

Return copy of vector.

Implements dolfin::GenericVector.

## empty()

bool PETScVector::empty | ( |  | ) | const

virtual

Return true if vector is empty.

Implements dolfin::GenericTensor.

## factory()

GenericLinearAlgebraFactory & PETScVector::factory | ( |  | ) | const

virtual

Return linear algebra backend factory.

Implements dolfin::GenericTensor.

## gather() [1/2]

void PETScVector::gather | ( | GenericVector & | y,
|  | const std::vector< dolfin::la_index > & | indices ) const

virtual

Gather entries (given by global indices) into local (MPI_COMM_SELF) vector x. Provided x must be empty or of correct dimension (same as provided indices). This operation is collective

Implements dolfin::GenericVector.

## gather() [2/2]

void PETScVector::gather | ( | std::vector< double > & | x,
|  | const std::vector< dolfin::la_index > & | indices ) const

virtual

Gather entries (given by global indices) into x. This operation is collective

Implements dolfin::GenericVector.

## gather_on_zero()

void PETScVector::gather_on_zero | ( | std::vector< double > & | x | ) | const

virtual

Gather all entries into x on process 0. This operation is collective

Implements dolfin::GenericVector.

## get()

void PETScVector::get | ( | double * | block,
|  | std::size_t | m,
|  | const dolfin::la_index * | rows ) const

virtual

Get block of values using global indices (all values must be owned by local process, ghosts cannot be accessed)

Implements dolfin::GenericVector.

## get_local() [1/2]

void PETScVector::get_local | ( | double * | block,
|  | std::size_t | m,
|  | const dolfin::la_index * | rows ) const

virtual

Get block of values using local indices.

Implements dolfin::GenericVector.

## get_local() [2/2]

void PETScVector::get_local | ( | std::vector< double > & | values | ) | const

virtual

Get all values on local process.

Implements dolfin::GenericVector.

## get_options_prefix()

std::string PETScVector::get_options_prefix | ( |  | ) | const

Returns the prefix used by PETSc when searching the options database

## init() [1/4]

virtual void dolfin::GenericVector::init | ( | const TensorLayout & | tensor_layout | ) |

inline virtual

Initialize zero tensor using sparsity pattern FIXME: This needs to be implemented on backend side! Remove it!

Reimplemented from dolfin::GenericVector.

## init() [2/4]

void PETScVector::init | ( | std::pair< std::size_t, std::size_t > | range | ) |

virtual

Initialize vector with given ownership range.

Implements dolfin::GenericVector.

## init() [3/4]

void PETScVector::init | ( | std::pair< std::size_t, std::size_t > | range,
|  | const std::vector< std::size_t > & | local_to_global_map,
|  | const std::vector< la_index > & | ghost_indices )

virtual

Initialize vector with given ownership range and with ghost values

Implements dolfin::GenericVector.

## init() [4/4]

void PETScVector::init | ( | std::size_t | N | ) |

virtual

Initialize vector to global size N.

Implements dolfin::GenericVector.

## inner()

double PETScVector::inner | ( | const GenericVector & | v | ) | const

virtual

Return inner product with given vector.

Implements dolfin::GenericVector.

## local_range()

std::pair< std::int64_t, std::int64_t > PETScVector::local_range | ( |  | ) | const

virtual

Return ownership range of a vector.

Implements dolfin::GenericVector.

## local_size()

std::size_t PETScVector::local_size | ( |  | ) | const

virtual

Return local size of vector.

Implements dolfin::GenericVector.

## max()

double PETScVector::max | ( |  | ) | const

virtual

Return maximum value of vector.

Implements dolfin::GenericVector.

## min()

double PETScVector::min | ( |  | ) | const

virtual

Return minimum value of vector.

Implements dolfin::GenericVector.

## mpi_comm()

MPI_Comm PETScVector::mpi_comm | ( |  | ) | const

virtual

Return MPI communicator.

Implements dolfin::LinearAlgebraObject.

## norm()

double PETScVector::norm | ( | std::string | norm_type | ) | const

virtual

Return norm of vector.

Implements dolfin::GenericVector.

## operator*=() [1/2]

const PETScVector & PETScVector::operator*= | ( | const GenericVector & | x | ) |

virtual

Multiply vector by another vector pointwise.

Implements dolfin::GenericVector.

## operator*=() [2/2]

const PETScVector & PETScVector::operator*= | ( | double | a | ) |

virtual

Multiply vector by given number.

Implements dolfin::GenericVector.

## operator+=() [1/2]

const PETScVector & PETScVector::operator+= | ( | const GenericVector & | x | ) |

virtual

Add given vector.

Implements dolfin::GenericVector.

## operator+=() [2/2]

const PETScVector & PETScVector::operator+= | ( | double | a | ) |

virtual

Add number to all components of a vector.

Implements dolfin::GenericVector.

## operator-=() [1/2]

const PETScVector & PETScVector::operator-= | ( | const GenericVector & | x | ) |

virtual

Subtract given vector.

Implements dolfin::GenericVector.

## operator-=() [2/2]

const PETScVector & PETScVector::operator-= | ( | double | a | ) |

virtual

Subtract number from all components of a vector.

Implements dolfin::GenericVector.

## operator/=()

const PETScVector & PETScVector::operator/= | ( | double | a | ) |

virtual

Divide vector by given number.

Implements dolfin::GenericVector.

## operator=() [1/2]

const GenericVector & PETScVector::operator= | ( | const GenericVector & | x | ) |

virtual

Assignment operator.

Implements dolfin::GenericVector.

## operator=() [2/2]

const PETScVector & PETScVector::operator= | ( | double | a | ) |

virtual

Assignment operator.

Implements dolfin::GenericVector.

## owns_index()

bool PETScVector::owns_index | ( | std::size_t | i | ) | const

virtual

Determine whether global vector index is owned by this process.

Implements dolfin::GenericVector.

## reset()

void PETScVector::reset | ( | Vec | vec | ) |

Switch underlying PETSc object. Intended for internal library usage.

## set()

void PETScVector::set | ( | const double * | block,
|  | std::size_t | m,
|  | const dolfin::la_index * | rows )

virtual

Set block of values using global indices.

Implements dolfin::GenericVector.

## set_from_options()

void PETScVector::set_from_options | ( |  | ) |

Call PETSc function VecSetFromOptions on the underlying Vec object

## set_local() [1/2]

void PETScVector::set_local | ( | const double * | block,
|  | std::size_t | m,
|  | const dolfin::la_index * | rows )

virtual

Set block of values using local indices.

Implements dolfin::GenericVector.

## set_local() [2/2]

void PETScVector::set_local | ( | const std::vector< double > & | values | ) |

virtual

Set all values on local process.

Implements dolfin::GenericVector.

## set_options_prefix()

void PETScVector::set_options_prefix | ( | std::string | options_prefix | ) |

Sets the prefix used by PETSc when searching the options database

## size()

std::size_t PETScVector::size | ( |  | ) | const

virtual

Return size of vector.

Implements dolfin::GenericVector.

## str()

std::string PETScVector::str | ( | bool | verbose | ) | const

virtual

Return informal string representation (pretty-print).

Implements dolfin::GenericVector.

## sum() [1/2]

double PETScVector::sum | ( |  | ) | const

virtual

Return sum of values of vector.

Implements dolfin::GenericVector.

## sum() [2/2]

double PETScVector::sum | ( | const Array< std::size_t > & | rows | ) | const

virtual

Return sum of selected rows in vector.

Implements dolfin::GenericVector.

## zero()

void PETScVector::zero | ( |  | ) |

virtual

Set all entries to zero and keep any sparse structure.

Implements dolfin::GenericVector.

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

- /build/dolfin-wwk1CC/dolfin-2019.2.0~legacy20240219.1c52e83/dolfin/la/PETScVector.h
- /build/dolfin-wwk1CC/dolfin-2019.2.0~legacy20240219.1c52e83/dolfin/la/PETScVector.cpp