Feel++ 0.91.0
|
Wrapper for petsc matrices. More...
#include <vectorpetsc.hpp>
Public Types | |
Typedefs | |
typedef super::value_type | value_type |
typedef super::real_type | real_type |
typedef super::clone_ptrtype | clone_ptrtype |
Public Member Functions | |
VectorPetsc (VectorPetsc const &v) | |
template<> | |
void | localize (std::vector< double > &v_local) const |
template<> | |
void | localizeToOneProcessor (std::vector< Real > &v_local, const size_type pid) const |
Constructors, destructor | |
VectorPetsc () | |
VectorPetsc (const size_type n) | |
VectorPetsc (const size_type n, const size_type n_local) | |
VectorPetsc (Vec v) | |
~VectorPetsc () | |
clone_ptrtype | clone () const |
void | init (const size_type N, const size_type n_local, const bool fast=false) |
void | init (const size_type N, const bool fast=false) |
Operator overloads | |
value_type | operator() (const size_type i) const |
Vector< T > & | operator+= (const Vector< value_type > &V) |
Vector< T > & | operator-= (const Vector< value_type > &V) |
Accessors | |
size_type | size () const |
size_type | localSize () const |
Vec | vec () const |
Methods | |
void | close () |
void | zero () |
void | zero (size_type, size_type) |
void | setConstant (value_type v) |
FEEL_DONT_INLINE void | clear () |
void | set (const value_type &value) |
void | set (size_type i, const value_type &value) |
void | add (size_type i, const value_type &value) |
void | addVector (int *i, int n, value_type *v) |
void | addVector (const std::vector< value_type > &v, const std::vector< size_type > &dof_indices) |
void | addVector (const Vector< value_type > &V, const std::vector< size_type > &dof_indices) |
void | addVector (const Vector< value_type > &V_in, const MatrixSparse< value_type > &A_in) |
void | addVector (const ublas::vector< value_type > &V, const std::vector< size_type > &dof_indices) |
void | insert (const std::vector< T > &, const std::vector< size_type > &) |
void | insert (const Vector< T > &V, const std::vector< size_type > &dof_indices) |
void | insert (const ublas::vector< T > &V, const std::vector< size_type > &dof_indices) |
void | scale (const T factor) |
void | add (const value_type &v_in) |
void | add (const Vector< value_type > &v) |
void | add (const value_type &a_in, const Vector< value_type > &v_in) |
real_type | min () const |
real_type | max () const |
real_type | l1Norm () const |
real_type | l2Norm () const |
value_type | sum () const |
real_type | linftyNorm () const |
size_type | firstLocalIndex () const |
size_type | lastLocalIndex () const |
void | localize (std::vector< T > &v_local) const |
void | localize (Vector< T > &v_local) const |
void | localize (Vector< T > &v_local, const std::vector< size_type > &send_list) const |
void | localize (const size_type first_local_idx, const size_type last_local_idx, const std::vector< size_type > &send_list) |
void | localizeToOneProcessor (std::vector< T > &v_local, const size_type proc_id=0) const |
void | printMatlab (const std::string name="NULL") const |
Wrapper for petsc matrices.
Petsc vector. Provides a nice interface to the Petsc C-based data structures for parallel, sparse matrices.
Feel::VectorPetsc< T >::VectorPetsc | ( | ) | [inline] |
Dummy-Constructor. Dimension=0
Feel::VectorPetsc< T >::VectorPetsc | ( | const size_type | n | ) | [inline] |
Constructor. Set dimension to n
and initialize all elements with zero.
References Feel::VectorPetsc< T >::init().
Feel::VectorPetsc< T >::VectorPetsc | ( | const size_type | n, |
const size_type | n_local | ||
) | [inline] |
Constructor. Set local dimension to n_local
, the global dimension to n
, and initialize all elements with zero.
References Feel::VectorPetsc< T >::init().
Feel::VectorPetsc< T >::VectorPetsc | ( | Vec | v | ) | [inline] |
Constructor. Creates a VectorPetsc assuming you already have a valid PETSc Vec object. In this case, v is NOT destroyed by the VectorPetsc constructor when this object goes out of scope. This allows ownership of v to remain with the original creator, and to simply provide additional functionality with the VectorPetsc.
References Feel::Vector< T >::M_is_initialized.
Feel::VectorPetsc< T >::~VectorPetsc | ( | ) | [inline] |
Destructor, deallocates memory. Made virtual to allow for derived classes to behave properly.
References Feel::VectorPetsc< T >::clear().
void Feel::VectorPetsc< T >::add | ( | size_type | i, |
const value_type & | value | ||
) | [virtual] |
v(i) += value
Implements Feel::Vector< T >.
Referenced by Feel::VectorPetsc< T >::addVector(), Feel::VectorPetsc< T >::operator+=(), and Feel::VectorPetsc< T >::operator-=().
void Feel::VectorPetsc< T >::add | ( | const value_type & | v_in | ) | [virtual] |
. Addition of
s
to all components. Note that s
is a scalar and not a vector.
Implements Feel::Vector< T >.
void Feel::VectorPetsc< T >::add | ( | const Vector< value_type > & | v | ) | [virtual] |
. Simple vector addition, equal to the
operator
+=.
Implements Feel::Vector< T >.
void Feel::VectorPetsc< T >::add | ( | const value_type & | a_in, |
const Vector< value_type > & | v_in | ||
) | [virtual] |
. Simple vector addition, equal to the
operator
+=.
Implements Feel::Vector< T >.
References Feel::VectorPetsc< T >::size().
void Feel::VectorPetsc< T >::addVector | ( | int * | i, |
int | n, | ||
value_type * | v | ||
) | [virtual] |
v([i1,i2,...,in]) += [value1,...,valuen]
Implements Feel::Vector< T >.
void Feel::VectorPetsc< T >::addVector | ( | const std::vector< value_type > & | v, |
const std::vector< size_type > & | dof_indices | ||
) | [inline, virtual] |
where
v
is a std::vector<T> and you want to specify WHERE to add it
Implements Feel::Vector< T >.
References Feel::VectorPetsc< T >::add().
void Feel::VectorPetsc< T >::addVector | ( | const Vector< value_type > & | V, |
const std::vector< size_type > & | dof_indices | ||
) | [inline, virtual] |
where U and V are type
NumericVector<T>
and you want to specify WHERE to add the NumericVector<T>
V
Implements Feel::Vector< T >.
References Feel::VectorPetsc< T >::add(), and Feel::Vector< T >::size().
void Feel::VectorPetsc< T >::addVector | ( | const Vector< value_type > & | V_in, |
const MatrixSparse< value_type > & | A_in | ||
) | [inline, virtual] |
, add the product of a
MatrixSparse
A
and a Vector
V
to this
, where this=U
.
Implements Feel::Vector< T >.
References Feel::VectorPetsc< T >::close().
void Feel::VectorPetsc< T >::addVector | ( | const ublas::vector< value_type > & | V, |
const std::vector< size_type > & | dof_indices | ||
) | [inline] |
where U and V are type uvlas::vector<T> and you want to specify WHERE to add the DenseVector<T> V
References Feel::VectorPetsc< T >::add().
void Feel::VectorPetsc< T >::clear | ( | ) | [virtual] |
VectorPetsc<T>
to a pristine state. Reimplemented from Feel::Vector< T >.
Referenced by Feel::VectorPetsc< T >::~VectorPetsc().
clone_ptrtype Feel::VectorPetsc< T >::clone | ( | ) | const [inline, virtual] |
Creates a copy of this vector and returns it in an shared_ptr<>
. This must be overloaded in the derived classes.
Implements Feel::Vector< T >.
void Feel::VectorPetsc< T >::close | ( | ) | [inline, virtual] |
Call the assemble functions
Implements Feel::Vector< T >.
References Feel::Vector< T >::isInitialized(), and Feel::Vector< T >::M_is_closed.
Referenced by Feel::VectorPetsc< T >::addVector(), Feel::VectorPetsc< T >::localize(), and Feel::SolverLinearPetsc< T >::solve().
size_type Feel::VectorPetsc< T >::firstLocalIndex | ( | ) | const [inline, virtual] |
Reimplemented from Feel::Vector< T >.
References Feel::Vector< T >::isInitialized().
Referenced by Feel::VectorPetsc< T >::operator()().
void Feel::VectorPetsc< T >::init | ( | const size_type | N, |
const size_type | n_local, | ||
const bool | fast = false |
||
) | [inline, virtual] |
Change the dimension of the vector to N
. The reserved memory for this vector remains unchanged if possible, to make things faster, but this may waste some memory, so take this in the back of your head. However, if N==0
all memory is freed, i.e. if you want to resize the vector and release the memory not needed, you have to first call init(0)
and then init(N)
. This cited behaviour is analogous to that of the STL containers.
On fast==false
, the vector is filled by zeros.
Reimplemented from Feel::Vector< T >.
Referenced by Feel::VectorPetsc< T >::init(), Feel::VectorPetsc< T >::localize(), and Feel::VectorPetsc< T >::VectorPetsc().
void Feel::VectorPetsc< T >::init | ( | const size_type | N, |
const bool | fast = false |
||
) | [inline, virtual] |
call init with n_local = N,
Reimplemented from Feel::Vector< T >.
References Feel::VectorPetsc< T >::init().
void Feel::VectorPetsc< T >::insert | ( | const std::vector< T > & | , |
const std::vector< size_type > & | |||
) | [inline, virtual] |
where v is a DenseVector<T> and you want to specify WHERE to insert it
Implements Feel::Vector< T >.
void Feel::VectorPetsc< T >::insert | ( | const ublas::vector< T > & | V, |
const std::vector< size_type > & | dof_indices | ||
) | [virtual] |
where U and V are type DenseVector<T> and you want to specify WHERE to insert the DenseVector<T> V
Implements Feel::Vector< T >.
void Feel::VectorPetsc< T >::insert | ( | const Vector< T > & | V, |
const std::vector< size_type > & | dof_indices | ||
) | [virtual] |
, where U and V are type Vector<T> and you want to specify WHERE to insert the Vector<T> V
Implements Feel::Vector< T >.
VectorPetsc< T >::real_type Feel::VectorPetsc< T >::l1Norm | ( | ) | const [virtual] |
Implements Feel::Vector< T >.
VectorPetsc< T >::real_type Feel::VectorPetsc< T >::l2Norm | ( | ) | const [virtual] |
Implements Feel::Vector< T >.
size_type Feel::VectorPetsc< T >::lastLocalIndex | ( | ) | const [inline, virtual] |
Reimplemented from Feel::Vector< T >.
References Feel::Vector< T >::isInitialized().
Referenced by Feel::VectorPetsc< T >::operator()().
VectorPetsc< T >::real_type Feel::VectorPetsc< T >::linftyNorm | ( | ) | const [virtual] |
Implements Feel::Vector< T >.
void Feel::VectorPetsc< T >::localize | ( | std::vector< T > & | v_local | ) | const [virtual] |
Creates a copy of the global vector in the local vector v_local
.
Implements Feel::Vector< T >.
Referenced by Feel::VectorPetsc< T >::localize().
void Feel::VectorPetsc< T >::localize | ( | Vector< T > & | v_local | ) | const [virtual] |
Same, but fills a Vector<T>
instead of a std::vector
.
Implements Feel::Vector< T >.
References Feel::iota(), and Feel::VectorPetsc< T >::localSize().
void Feel::VectorPetsc< T >::localize | ( | Vector< T > & | v_local, |
const std::vector< size_type > & | send_list | ||
) | const [virtual] |
Creates a local vector v_local
containing only information relevant to this processor, as defined by the send_list
.
Implements Feel::Vector< T >.
References Feel::VectorPetsc< T >::localSize(), and Feel::VectorPetsc< T >::size().
void Feel::VectorPetsc< T >::localize | ( | const size_type | first_local_idx, |
const size_type | last_local_idx, | ||
const std::vector< size_type > & | send_list | ||
) | [virtual] |
Updates a local vector with selected values from neighboring processors, as defined by send_list
.
Implements Feel::Vector< T >.
References Feel::VectorPetsc< T >::close(), Feel::VectorPetsc< T >::init(), Feel::iota(), and Feel::VectorPetsc< T >::localize().
void Feel::VectorPetsc< T >::localizeToOneProcessor | ( | std::vector< T > & | v_local, |
const size_type | proc_id = 0 |
||
) | const [virtual] |
Creates a local copy of the global vector in v_local
only on processor proc_id
. By default the data is sent to processor 0. This method is useful for outputting data from one processor.
Implements Feel::Vector< T >.
size_type Feel::VectorPetsc< T >::localSize | ( | ) | const [inline, virtual] |
Reimplemented from Feel::Vector< T >.
References Feel::Vector< T >::isInitialized().
Referenced by Feel::MatrixPetsc< T >::energy(), and Feel::VectorPetsc< T >::localize().
VectorPetsc< T >::real_type Feel::VectorPetsc< T >::max | ( | ) | const [virtual] |
Implements Feel::Vector< T >.
VectorPetsc< T >::real_type Feel::VectorPetsc< T >::min | ( | ) | const [virtual] |
Implements Feel::Vector< T >.
value_type Feel::VectorPetsc< T >::operator() | ( | const size_type | i | ) | const [inline, virtual] |
Access components, returns U(i)
.
Implements Feel::Vector< T >.
References Feel::VectorPetsc< T >::firstLocalIndex(), Feel::Vector< T >::isInitialized(), and Feel::VectorPetsc< T >::lastLocalIndex().
Vector<T>& Feel::VectorPetsc< T >::operator+= | ( | const Vector< value_type > & | V | ) | [inline, virtual] |
Addition operator. Fast equivalent to U.add(1, V)
.
Implements Feel::Vector< T >.
References Feel::VectorPetsc< T >::add(), and Feel::Vector< T >::closed().
Vector<T>& Feel::VectorPetsc< T >::operator-= | ( | const Vector< value_type > & | V | ) | [inline, virtual] |
Subtraction operator. Fast equivalent to U.add
(-1, V).
Implements Feel::Vector< T >.
References Feel::VectorPetsc< T >::add(), and Feel::Vector< T >::closed().
void Feel::VectorPetsc< T >::printMatlab | ( | const std::string | name = "NULL" | ) | const [virtual] |
Print the contents of the vector in Matlab's format. Optionally prints the vector to the file named name
. If name
is not specified it is dumped to the screen.
Create an ASCII file containing the matrix if a filename was provided.
Otherwise the matrix will be dumped to the screen.
Destroy the viewer.
Reimplemented from Feel::Vector< T >.
void Feel::VectorPetsc< T >::scale | ( | const T | factor | ) | [virtual] |
Scale each element of the vector by the given factor.
Implements Feel::Vector< T >.
void Feel::VectorPetsc< T >::set | ( | size_type | i, |
const value_type & | value | ||
) | [virtual] |
v(i) = value
Implements Feel::Vector< T >.
void Feel::VectorPetsc< T >::set | ( | const value_type & | value | ) |
void Feel::VectorPetsc< T >::setConstant | ( | value_type | v | ) | [inline, virtual] |
set the entries to the constant v
Implements Feel::Vector< T >.
size_type Feel::VectorPetsc< T >::size | ( | ) | const [inline, virtual] |
n()
, but was renamed to get the PetscVector<T>
class closer to the C++ standard library's std::vector
container. Reimplemented from Feel::Vector< T >.
References Feel::Vector< T >::isInitialized().
Referenced by Feel::VectorPetsc< T >::add(), and Feel::VectorPetsc< T >::localize().
VectorPetsc< T >::value_type Feel::VectorPetsc< T >::sum | ( | ) | const [virtual] |
Implements Feel::Vector< T >.
Vec Feel::VectorPetsc< T >::vec | ( | ) | const [inline] |
Returns the raw PETSc vector context pointer. Note this is generally not required in user-level code. Just don't do anything crazy like calling VecDestroy()!
Referenced by Feel::MatrixPetsc< T >::energy(), Feel::BackendPetsc< T >::prod(), Feel::SolverNonLinearPetsc< T >::solve(), Feel::SolverLinearPetsc< T >::solve(), and Feel::MatrixPetsc< T >::zeroRows().
void Feel::VectorPetsc< T >::zero | ( | ) | [inline, virtual] |
Set all entries to zero. Equivalent to v
= 0, but more obvious and faster.
Implements Feel::Vector< T >.
References Feel::Vector< T >::isInitialized().
Referenced by Feel::VectorPetsc< T >::zero().
void Feel::VectorPetsc< T >::zero | ( | size_type | , |
size_type | |||
) | [inline, virtual] |
Set entries to zero between start
and stop
Implements Feel::Vector< T >.
References Feel::VectorPetsc< T >::zero().