18 #ifndef __DOLFIN_VECTOR_H 19 #define __DOLFIN_VECTOR_H 24 #include <dolfin/common/types.h> 25 #include "DefaultFactory.h" 26 #include "GenericVector.h" 31 template<
typename T>
class Array;
67 virtual std::shared_ptr<GenericVector>
copy()
const 69 std::shared_ptr<Vector> x(
new Vector(*
this));
78 virtual void apply(std::string mode)
79 { vector->apply(mode); }
83 {
return vector->mpi_comm(); }
86 virtual std::string
str(
bool verbose)
const 87 {
return "<Vector wrapper of " + vector->str(verbose) +
">"; }
92 virtual void init(std::size_t N)
96 virtual void init(std::pair<std::size_t, std::size_t> range)
97 { vector->init(range); }
101 virtual void init(std::pair<std::size_t, std::size_t> range,
102 const std::vector<std::size_t>& local_to_global_map,
103 const std::vector<la_index>& ghost_indices)
104 { vector->init(range, local_to_global_map, ghost_indices); }
111 {
return vector->empty(); }
114 virtual std::size_t
size()
const 115 {
return vector->size(); }
119 {
return vector->local_size(); }
123 {
return vector->local_range(); }
127 {
return vector->owns_index(i); }
131 virtual void get(
double* block, std::size_t m,
133 { vector->get(block, m, rows); }
139 { vector->get_local(block, m, rows); }
142 virtual void set(
const double* block, std::size_t m,
144 { vector->set(block, m, rows); }
147 virtual void set_local(
const double* block, std::size_t m,
149 { vector->set_local(block, m, rows); }
152 virtual void add(
const double* block, std::size_t m,
154 { vector->add(block, m, rows); }
157 virtual void add_local(
const double* block, std::size_t m,
159 { vector->add_local(block, m, rows); }
162 virtual void get_local(std::vector<double>& values)
const 163 { vector->get_local(values); }
166 virtual void set_local(
const std::vector<double>& values)
167 { vector->set_local(values); }
171 { vector->add_local(values); }
176 const std::vector<dolfin::la_index>& indices)
const 177 { vector->gather(x, indices); }
180 virtual void gather(std::vector<double>& x,
181 const std::vector<dolfin::la_index>& indices)
const 182 { vector->gather(x, indices); }
186 { vector->gather_on_zero(x); }
190 { vector->axpy(a, x); }
198 {
return vector->inner(x); }
201 virtual double norm(std::string norm_type)
const 202 {
return vector->norm(norm_type); }
205 virtual double min()
const 206 {
return vector->min(); }
209 virtual double max()
const 210 {
return vector->max(); }
213 virtual double sum()
const 214 {
return vector->sum(); }
217 {
return vector->sum(rows); }
221 { *vector *= a;
return *
this; }
225 { *vector *= x;
return *
this; }
229 { *
this *= 1.0 / a;
return *
this; }
233 {
axpy(1.0, x);
return *
this; }
237 { *vector += a;
return *
this; }
241 {
axpy(-1.0, x);
return *
this; }
245 { *vector -= a;
return *
this; }
249 { *vector = x;
return *
this; }
253 { *vector = a;
return *
this; }
259 {
return vector->factory(); }
265 {
return vector.get(); }
269 {
return vector.get(); }
281 { *vector = *x.vector;
return *
this; }
286 std::shared_ptr<GenericVector> vector;
virtual const Vector & operator/=(double a)
Divide vector by given number.
Definition: Vector.h:228
virtual void init(const TensorLayout &tensor_layout)
Definition: GenericVector.h:58
virtual void gather_on_zero(std::vector< double > &x) const
Gather all entries into x on process 0.
Definition: Vector.h:185
virtual const GenericVector & operator=(const GenericVector &x)
Assignment operator.
Definition: Vector.h:248
virtual std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: Vector.h:86
virtual bool empty() const
Return true if vector is empty.
Definition: Vector.h:110
virtual double norm(std::string norm_type) const
Return norm of vector.
Definition: Vector.h:201
virtual void init(std::pair< std::size_t, std::size_t > range)
Initialize vector with given ownership range.
Definition: Vector.h:96
virtual double sum() const
Return sum of values of vector.
Definition: Vector.h:213
virtual std::size_t size() const
Return size of vector.
Definition: Vector.h:114
virtual void get_local(double *block, std::size_t m, const dolfin::la_index *rows) const
Definition: Vector.h:137
Vector()
Create empty vector.
Definition: Vector.h:41
virtual void gather(GenericVector &x, const std::vector< dolfin::la_index > &indices) const
Definition: Vector.h:175
virtual void add_local(const Array< double > &values)
Add values to each entry on local process.
Definition: Vector.h:170
virtual std::shared_ptr< GenericVector > create_vector(MPI_Comm comm) const
Create empty vector.
Definition: DefaultFactory.cpp:37
virtual std::pair< std::int64_t, std::int64_t > local_range() const
Return local ownership range of a vector.
Definition: Vector.h:122
virtual void axpy(double a, const GenericVector &x)
Add multiple of given vector (AXPY operation)
Definition: Vector.h:189
virtual void zero()
Set all entries to zero and keep any sparse structure.
Definition: Vector.h:74
virtual std::shared_ptr< const LinearAlgebraObject > shared_instance() const
Return concrete shared ptr instance / unwrap (const version)
Definition: Vector.h:271
virtual bool owns_index(std::size_t i) const
Determine whether global vector index is owned by this process.
Definition: Vector.h:126
virtual const Vector & operator+=(const GenericVector &x)
Add given vector.
Definition: Vector.h:232
virtual void abs()
Replace all entries in the vector by their absolute values.
Definition: Vector.h:193
virtual const Vector & operator*=(double a)
Multiply vector by given number.
Definition: Vector.h:220
virtual const GenericVector * instance() const
Return concrete instance / unwrap (const version)
Definition: Vector.h:264
Vector(const Vector &x)
Copy constructor.
Definition: Vector.h:59
Vector(MPI_Comm comm, std::size_t N)
Create vector of size N.
Definition: Vector.h:51
Base class for LinearAlgebra factories.
Definition: GenericLinearAlgebraFactory.h:46
virtual MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: Vector.h:82
virtual GenericLinearAlgebraFactory & factory() const
Return linear algebra backend factory.
Definition: Vector.h:258
virtual void add(const double *block, std::size_t m, const dolfin::la_index *rows)
Add block of values using global indices.
Definition: Vector.h:152
virtual double sum(const Array< std::size_t > &rows) const
Definition: Vector.h:216
virtual void add_local(const double *block, std::size_t m, const dolfin::la_index *rows)
Add block of values using local indices.
Definition: Vector.h:157
virtual GenericVector * instance()
Return concrete instance / unwrap (non-const version)
Definition: Vector.h:268
virtual std::size_t local_size() const
Return local size of vector.
Definition: Vector.h:118
virtual void apply(std::string mode)
Finalize assembly of tensor.
Definition: Vector.h:78
virtual std::shared_ptr< LinearAlgebraObject > shared_instance()
Return concrete shared ptr instance / unwrap (non-const version)
Definition: Vector.h:274
PetscInt la_index
Index type for compatibility with linear algebra backend(s)
Definition: types.h:32
virtual double max() const
Return maximum value of vector.
Definition: Vector.h:209
virtual const Vector & operator-=(const GenericVector &x)
Subtract given vector.
Definition: Vector.h:240
virtual std::shared_ptr< GenericVector > copy() const
Return copy of vector.
Definition: Vector.h:67
virtual void gather(std::vector< double > &x, const std::vector< dolfin::la_index > &indices) const
Gather entries (given by global indices) into x.
Definition: Vector.h:180
virtual void init(std::size_t N)
Initialize vector to size N.
Definition: Vector.h:92
Vector(const GenericVector &x)
Create a Vector from a GenericVector.
Definition: Vector.h:62
virtual void set_local(const double *block, std::size_t m, const dolfin::la_index *rows)
Set block of values using local indices.
Definition: Vector.h:147
Vector(MPI_Comm comm)
Create empty vector.
Definition: Vector.h:44
virtual double min() const
Return minimum value of vector.
Definition: Vector.h:205
virtual void set_local(const std::vector< double > &values)
Set all values on local process.
Definition: Vector.h:166
This class defines a common interface for vectors.
Definition: GenericVector.h:47
virtual double inner(const GenericVector &x) const
Return inner product with given vector.
Definition: Vector.h:197
virtual void get_local(std::vector< double > &values) const
Get all values on local process.
Definition: Vector.h:162
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)
Definition: Vector.h:101
Default linear algebra factory based on global parameter "linear_algebra_backend".
Definition: DefaultFactory.h:35