GEOSX
Protected Types | Protected Attributes | Friends | List of all members
geosx::VectorBase< VECTOR > Class Template Referenceabstract

Common base template for all vector wrapper types. More...

#include <VectorBase.hpp>

Protected Types

using Vector = VECTOR
 Alias for VECTOR.
 

Protected Member Functions

Constructors/destructor/assignment
 VectorBase ()
 Constructs a vector in default state.
 
 VectorBase (VectorBase const &)=default
 Copy constructor.
 
 VectorBase (VectorBase &&)=default
 Move constructor.
 
VectorBaseoperator= (VectorBase const &)=default
 Copy assignment. More...
 
VectorBaseoperator= (VectorBase &&)=default
 Move assignment. More...
 
 ~VectorBase ()=default
 Destructor.
 
Status query methods
bool closed () const
 Query vector closed status. More...
 
virtual bool created () const =0
 Query vector creation status. More...
 
bool ready () const
 Query vector ready status. More...
 
Create Methods
virtual void createWithLocalSize (localIndex const localSize, MPI_Comm const &comm)=0
 Create a vector based on local number of elements. More...
 
virtual void createWithGlobalSize (globalIndex const globalSize, MPI_Comm const &comm)=0
 Create a vector based on global number of elements. More...
 
virtual void create (arrayView1d< real64 const > const &localValues, MPI_Comm const &comm)=0
 Construct parallel vector from a local array. More...
 
Open/close methods
virtual void open ()=0
 Open the vector for modifying entries.
 
virtual void close ()=0
 Assemble vector. More...
 
virtual void reset ()
 Reset the matrix to default state.
 
Add/Set Methods
virtual void set (globalIndex const globalRow, real64 const value)=0
 Set vector value. More...
 
virtual void add (globalIndex const globalRow, real64 const value)=0
 Add into vector value. More...
 
virtual void set (globalIndex const *globalIndices, real64 const *values, localIndex const size)=0
 Set vector values. More...
 
virtual void add (globalIndex const *globalIndices, real64 const *values, localIndex const size)=0
 Add vector values. More...
 
virtual void set (arraySlice1d< globalIndex const > const &globalIndices, arraySlice1d< real64 const > const &values)=0
 Set vector values using array1d. More...
 
virtual void add (arraySlice1d< globalIndex const > const &globalIndices, arraySlice1d< real64 const > const &values)=0
 Add into vector values using array1d. More...
 
virtual void set (real64 const value)=0
 Set all elements to a constant value. More...
 
virtual void zero ()=0
 Set vector elements to zero.
 
virtual void rand (unsigned const seed=1984)=0
 Set vector elements to random entries. More...
 
Algebraic Operations
virtual void scale (real64 const scalingFactor)=0
 Multiply all elements by scalingFactor. More...
 
virtual void reciprocal ()=0
 Replace vector elements by their reciprocals. More...
 
virtual real64 dot (Vector const &vec) const =0
 Dot product with the vector vec. More...
 
virtual void copy (Vector const &x)=0
 Update vector y as y = x. More...
 
virtual void axpy (real64 const alpha, Vector const &x)=0
 Update vector y as y = alpha*x + y. More...
 
virtual void axpby (real64 const alpha, Vector const &x, real64 const beta)=0
 Update vector y as y = alpha*x + beta*y. More...
 
virtual void pointwiseProduct (Vector const &x, Vector &y) const =0
 Compute the componentwise multiplication y = v * x. More...
 
virtual real64 norm1 () const =0
 1-norm of the vector. More...
 
virtual real64 norm2 () const =0
 2-norm of the vector. More...
 
virtual real64 normInf () const =0
 Infinity-norm of the vector. More...
 
Accessor Methods
virtual globalIndex globalSize () const =0
 Returns the global of the vector. More...
 
virtual localIndex localSize () const =0
 Returns the local size of the vector. More...
 
virtual globalIndex ilower () const =0
 Get lower bound of local partition. More...
 
virtual globalIndex iupper () const =0
 Get upper bound of local partition. More...
 
virtual real64 get (globalIndex globalRow) const =0
 Get a value by index. More...
 
virtual void get (arraySlice1d< globalIndex const > const &globalIndices, arraySlice1d< real64 > const &values) const =0
 Get a sequence of values by index. More...
 
virtual localIndex getLocalRowID (globalIndex const globalRow) const =0
 Map a global row index to local row index. More...
 
virtual globalIndex getGlobalRowID (localIndex const localRow) const =0
 Map a local row index to global row index. More...
 
virtual real64 const * extractLocalVector () const =0
 Extract a view of the local portion of the array. More...
 
virtual real64extractLocalVector ()=0
 Extract a view of the local portion of the array. More...
 
virtual void extract (arrayView1d< real64 > const &localVector) const
 Extract local solution by copying into a user-provided array. More...
 
virtual MPI_Comm getComm () const =0
 Get the communicator used by this vector. More...
 
I/O Methods
virtual void print (std::ostream &os=std::cout) const =0
 Print the vector in Trilinos format to the terminal. More...
 
virtual void write (string const &filename, LAIOutputFormat const format=LAIOutputFormat::MATRIX_MARKET) const =0
 Write the vector to a file. More...
 

Protected Attributes

bool m_closed
 Flag indicating whether the vector is closed.
 

Friends

std::ostream & operator<< (std::ostream &os, Vector const &vec)
 Stream insertion operator for all vector types. More...
 

Detailed Description

template<typename VECTOR>
class geosx::VectorBase< VECTOR >

Common base template for all vector wrapper types.

Template Parameters
VECTORderived vector type

This class template provides a common interface for all derived vector wrapper types. Most methods are pure abstract in order to get the compiler to enforce a common interface in all derived classes; however there is no runtime polymorphism or virtual dispatch - derived classes are not related between each other, and pointers/references to base should never be used - the destructor is protected to enforce that.

As an added benefit, the documentation for vector interface also lives here and does not need to be duplicated across vector wrappers. Derived classes should still document specific functions in case a particular LA package's behavior deviates from expectations or has unexpected performance impacts. In that case, @copydoc tag can be used to copy over the documentation.

Definition at line 47 of file VectorBase.hpp.

Member Function Documentation

◆ add() [1/3]

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::add ( globalIndex const  globalRow,
real64 const  value 
)
protectedpure virtual

Add into vector value.

Parameters
globalRowglobal row
valueValues to add in given row

Add into vector value at given row.

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ add() [2/3]

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::add ( globalIndex const *  globalIndices,
real64 const *  values,
localIndex const  size 
)
protectedpure virtual

Add vector values.

Parameters
globalIndicesglobal row indices
valuesvalues to add in given rows
sizenumber of elements

Add vector values at given elements.

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ add() [3/3]

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::add ( arraySlice1d< globalIndex const > const &  globalIndices,
arraySlice1d< real64 const > const &  values 
)
protectedpure virtual

Add into vector values using array1d.

Parameters
globalIndicesglobal rows indices
valuesvalues to add in given rows

Add into vector values at given rows.

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ axpby()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::axpby ( real64 const  alpha,
Vector const &  x,
real64 const  beta 
)
protectedpure virtual

Update vector y as y = alpha*x + beta*y.

Parameters
alphascaling factor for added vector
xvector to add
betascaling factor for self vector

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ axpy()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::axpy ( real64 const  alpha,
Vector const &  x 
)
protectedpure virtual

Update vector y as y = alpha*x + y.

Parameters
alphascaling factor for added vector
xvector to add

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ close()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::close ( )
protectedpure virtual

Assemble vector.

Performs parallel communication to scatter assembled entries to appropriate locations

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ closed()

template<typename VECTOR>
bool geosx::VectorBase< VECTOR >::closed ( ) const
inlineprotected

Query vector closed status.

Returns
true if vector has been opened and has not been closed since; false otherwise

Definition at line 104 of file VectorBase.hpp.

◆ copy()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::copy ( Vector const &  x)
protectedpure virtual

Update vector y as y = x.

Parameters
xvector to copy

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ create()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::create ( arrayView1d< real64 const > const &  localValues,
MPI_Comm const &  comm 
)
protectedpure virtual

Construct parallel vector from a local array.

Parameters
localValueslocal data to put into vector
commMPI communicator to use

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ created()

template<typename VECTOR>
virtual bool geosx::VectorBase< VECTOR >::created ( ) const
protectedpure virtual

Query vector creation status.

Returns
true if vector has been created

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ createWithGlobalSize()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::createWithGlobalSize ( globalIndex const  globalSize,
MPI_Comm const &  comm 
)
protectedpure virtual

Create a vector based on global number of elements.

Parameters
globalSizeGlobal number of elements
commMPI communicator to use

Create a vector based on global number of elements. Every processors gets the same number of local elements except proc 0, which gets any remainder elements as well if the split can't be done evenly.

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ createWithLocalSize()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::createWithLocalSize ( localIndex const  localSize,
MPI_Comm const &  comm 
)
protectedpure virtual

Create a vector based on local number of elements.

Parameters
localSizelocal number of elements
commMPI communicator to use

Create a vector based on local number of elements. Global size is the sum across processors. For specifying a global size and having automatic partitioning, see createWithGlobalSize().

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ dot()

template<typename VECTOR>
virtual real64 geosx::VectorBase< VECTOR >::dot ( Vector const &  vec) const
protectedpure virtual

Dot product with the vector vec.

Parameters
vecvector to dot-product with
Returns
dot product

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ extract()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::extract ( arrayView1d< real64 > const &  localVector) const
inlineprotectedvirtual

Extract local solution by copying into a user-provided array.

Parameters
localVectorthe array view to write to (must be properly sized)

Definition at line 423 of file VectorBase.hpp.

◆ extractLocalVector() [1/2]

template<typename VECTOR>
virtual real64 const* geosx::VectorBase< VECTOR >::extractLocalVector ( ) const
protectedpure virtual

Extract a view of the local portion of the array.

Returns
pointer to local vector data

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ extractLocalVector() [2/2]

template<typename VECTOR>
virtual real64* geosx::VectorBase< VECTOR >::extractLocalVector ( )
protectedpure virtual

Extract a view of the local portion of the array.

Returns
pointer to local vector data

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ get() [1/2]

template<typename VECTOR>
virtual real64 geosx::VectorBase< VECTOR >::get ( globalIndex  globalRow) const
protectedpure virtual

Get a value by index.

Parameters
globalRowglobal row index
Returns
value at global index globalRow

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ get() [2/2]

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::get ( arraySlice1d< globalIndex const > const &  globalIndices,
arraySlice1d< real64 > const &  values 
) const
protectedpure virtual

Get a sequence of values by index.

Parameters
[in]globalIndicesarray of global row indices
[out]valuesarray of vector values

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ getComm()

template<typename VECTOR>
virtual MPI_Comm geosx::VectorBase< VECTOR >::getComm ( ) const
protectedpure virtual

Get the communicator used by this vector.

Returns
the MPI communicator

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ getGlobalRowID()

template<typename VECTOR>
virtual globalIndex geosx::VectorBase< VECTOR >::getGlobalRowID ( localIndex const  localRow) const
protectedpure virtual

Map a local row index to global row index.

Parameters
[in]localRowthe local row index
Returns
global row index corresponding to localRow

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ getLocalRowID()

template<typename VECTOR>
virtual localIndex geosx::VectorBase< VECTOR >::getLocalRowID ( globalIndex const  globalRow) const
protectedpure virtual

Map a global row index to local row index.

Parameters
[in]globalRowthe global row index
Returns
global row index corresponding to globalRow

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ globalSize()

template<typename VECTOR>
virtual globalIndex geosx::VectorBase< VECTOR >::globalSize ( ) const
protectedpure virtual

Returns the global of the vector.

Returns
the global size

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ ilower()

template<typename VECTOR>
virtual globalIndex geosx::VectorBase< VECTOR >::ilower ( ) const
protectedpure virtual

Get lower bound of local partition.

Returns
index of the first global row owned by this processor

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ iupper()

template<typename VECTOR>
virtual globalIndex geosx::VectorBase< VECTOR >::iupper ( ) const
protectedpure virtual

Get upper bound of local partition.

Returns
next index after last global row owned by that processor
Note
The intention is for [ilower; iupper) to be used as a half-open index range

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ localSize()

template<typename VECTOR>
virtual localIndex geosx::VectorBase< VECTOR >::localSize ( ) const
protectedpure virtual

Returns the local size of the vector.

Returns
the local size (on this processor)

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ norm1()

template<typename VECTOR>
virtual real64 geosx::VectorBase< VECTOR >::norm1 ( ) const
protectedpure virtual

1-norm of the vector.

Returns
the 1-norm value

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ norm2()

template<typename VECTOR>
virtual real64 geosx::VectorBase< VECTOR >::norm2 ( ) const
protectedpure virtual

2-norm of the vector.

Returns
the 2-norm value

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ normInf()

template<typename VECTOR>
virtual real64 geosx::VectorBase< VECTOR >::normInf ( ) const
protectedpure virtual

Infinity-norm of the vector.

Returns
the inf-norm value

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ operator=() [1/2]

template<typename VECTOR>
VectorBase& geosx::VectorBase< VECTOR >::operator= ( VectorBase< VECTOR > const &  )
protecteddefault

Copy assignment.

Returns
reference to this object

◆ operator=() [2/2]

template<typename VECTOR>
VectorBase& geosx::VectorBase< VECTOR >::operator= ( VectorBase< VECTOR > &&  )
protecteddefault

Move assignment.

Returns
reference to this object

◆ pointwiseProduct()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::pointwiseProduct ( Vector const &  x,
Vector y 
) const
protectedpure virtual

Compute the componentwise multiplication y = v * x.

Parameters
xfirst vector (input)
ysecond vector (output)

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ print()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::print ( std::ostream &  os = std::cout) const
protectedpure virtual

Print the vector in Trilinos format to the terminal.

Parameters
osthe output stream to print to

Implemented in geosx::HypreVector, geosx::EpetraVector, and geosx::PetscVector.

◆ rand()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::rand ( unsigned const  seed = 1984)
protectedpure virtual

Set vector elements to random entries.

Parameters
seedthe random number seed to use

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ ready()

template<typename VECTOR>
bool geosx::VectorBase< VECTOR >::ready ( ) const
inlineprotected

Query vector ready status.

Returns
true if vector has been created and is currently closed

Definition at line 116 of file VectorBase.hpp.

◆ reciprocal()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::reciprocal ( )
protectedpure virtual

Replace vector elements by their reciprocals.

Note
No guarding is done against division by zero.

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ scale()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::scale ( real64 const  scalingFactor)
protectedpure virtual

Multiply all elements by scalingFactor.

Parameters
scalingFactorscaling Factor

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ set() [1/4]

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::set ( globalIndex const  globalRow,
real64 const  value 
)
protectedpure virtual

Set vector value.

Parameters
globalRowglobal row index
valueValue to add at given row

Set vector value at given element.

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ set() [2/4]

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::set ( globalIndex const *  globalIndices,
real64 const *  values,
localIndex const  size 
)
protectedpure virtual

Set vector values.

Parameters
globalIndicesglobal row indices
valuesValues to add in given rows
sizeNumber of elements

Set vector values at given elements.

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ set() [3/4]

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::set ( arraySlice1d< globalIndex const > const &  globalIndices,
arraySlice1d< real64 const > const &  values 
)
protectedpure virtual

Set vector values using array1d.

Parameters
globalIndicesglobal row indices
valuesvalues to add in given rows

Set vector values at given elements.

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ set() [4/4]

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::set ( real64 const  value)
protectedpure virtual

Set all elements to a constant value.

Parameters
valuevalue to set vector elements to

Implemented in geosx::HypreVector, geosx::PetscVector, and geosx::EpetraVector.

◆ write()

template<typename VECTOR>
virtual void geosx::VectorBase< VECTOR >::write ( string const &  filename,
LAIOutputFormat const  format = LAIOutputFormat::MATRIX_MARKET 
) const
protectedpure virtual

Write the vector to a file.

Parameters
filenamename of the output file
[in]formatoutput format

Implemented in geosx::HypreVector, geosx::EpetraVector, and geosx::PetscVector.

Friends And Related Function Documentation

◆ operator<<

template<typename VECTOR>
std::ostream& operator<< ( std::ostream &  os,
Vector const &  vec 
)
friend

Stream insertion operator for all vector types.

Parameters
osthe output stream to print to
vecthe vector to print
Returns
reference to os

Definition at line 467 of file VectorBase.hpp.


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