18 #ifndef __EIGEN_VECTOR_H 19 #define __EIGEN_VECTOR_H 26 #include <dolfin/common/types.h> 27 #include <Eigen/Dense> 29 #include <dolfin/common/MPI.h> 30 #include "GenericVector.h" 35 template<
typename T>
class Array;
62 explicit EigenVector(std::shared_ptr<Eigen::VectorXd> x);
73 virtual void apply(std::string mode);
77 {
return _mpi_comm.
comm(); }
80 virtual std::string
str(
bool verbose)
const;
85 virtual std::shared_ptr<GenericVector>
copy()
const;
88 virtual void init(std::size_t N)
93 "calling EigenVector::init(...)",
94 "Cannot call init for a non-empty vector. Use EigenVector::resize instead");
100 virtual void init(std::pair<std::size_t, std::size_t> range)
105 "calling EigenVector::init(...)",
106 "Cannot call init for a non-empty vector. Use EigenVector::resize instead");
109 dolfin_assert(range.first == 0);
110 const std::size_t
size = range.second - range.first;
115 virtual void init(std::pair<std::size_t, std::size_t> range,
116 const std::vector<std::size_t>& local_to_global_map,
117 const std::vector<la_index>& ghost_indices)
122 "calling EigenVector::init(...)",
123 "Cannot call init for a non-empty vector. Use EigenVector::resize instead");
126 if (!ghost_indices.empty())
129 "calling EigenVector::init(...)",
130 "EigenVector does not support ghost values");
133 dolfin_assert(range.first == 0);
134 const std::size_t
size = range.second - range.first;
142 virtual bool empty()
const;
145 virtual std::size_t
size()
const;
152 virtual std::pair<std::int64_t, std::int64_t>
local_range()
const;
158 virtual void get(
double* block, std::size_t m,
163 virtual void get_local(
double* block, std::size_t m,
167 virtual void set(
const double* block, std::size_t m,
171 virtual void set_local(
const double* block, std::size_t m,
173 {
set(block, m, rows); }
176 virtual void add(
const double* block, std::size_t m,
180 virtual void add_local(
const double* block, std::size_t m,
182 {
add(block, m, rows); }
185 virtual void get_local(std::vector<double>& values)
const;
188 virtual void set_local(
const std::vector<double>& values);
195 const std::vector<dolfin::la_index>& indices)
const;
198 virtual void gather(std::vector<double>& x,
199 const std::vector<dolfin::la_index>& indices)
const;
214 virtual double norm(std::string norm_type)
const;
217 virtual double min()
const;
220 virtual double max()
const;
223 virtual double sum()
const;
264 virtual void resize(std::size_t N);
267 std::shared_ptr<const Eigen::VectorXd>
vec()
const 271 std::shared_ptr<Eigen::VectorXd>
vec()
289 const double*
data()
const;
293 static void check_mpi_size(
const MPI_Comm comm)
298 "creating EigenVector",
299 "EigenVector does not support parallel communicators");
304 std::shared_ptr<Eigen::VectorXd> _x;
virtual const EigenVector & operator/=(double a)
Divide vector by given number.
Definition: EigenVector.cpp:305
virtual void set_local(const double *block, std::size_t m, const dolfin::la_index *rows)
Set block of values using local indices.
Definition: EigenVector.h:171
virtual double sum() const
Return sum of values of vector.
Definition: EigenVector.cpp:209
virtual void resize(std::size_t N)
Resize vector to size N.
Definition: EigenVector.cpp:368
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)
Resize vector with given ownership range and with ghost values.
Definition: EigenVector.h:115
virtual void apply(std::string mode)
Finalize assembly of tensor.
Definition: EigenVector.cpp:167
virtual void get_local(double *block, std::size_t m, const dolfin::la_index *rows) const
Get block of values using local indices.
Definition: EigenVector.cpp:106
virtual void gather(GenericVector &x, const std::vector< dolfin::la_index > &indices) const
Gather entries into local vector x.
Definition: EigenVector.cpp:132
virtual void init(const TensorLayout &tensor_layout)
Definition: GenericVector.h:58
virtual double min() const
Return minimum value of vector.
Definition: EigenVector.cpp:197
virtual const EigenVector & operator+=(const GenericVector &x)
Add given vector.
Definition: EigenVector.cpp:311
virtual std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: EigenVector.cpp:339
virtual std::shared_ptr< GenericVector > copy() const
Create copy of tensor.
Definition: EigenVector.cpp:73
virtual double inner(const GenericVector &x) const
Return inner product with given vector.
Definition: EigenVector.cpp:252
std::shared_ptr< const Eigen::VectorXd > vec() const
Return reference to Eigen vector (const version)
Definition: EigenVector.h:267
virtual double norm(std::string norm_type) const
Compute norm of vector.
Definition: EigenVector.cpp:178
virtual void init(std::pair< std::size_t, std::size_t > range)
Resize vector with given ownership range.
Definition: EigenVector.h:100
static unsigned int size(MPI_Comm comm)
Definition: MPI.cpp:154
virtual void init(std::size_t N)
Initialize vector to size N.
Definition: EigenVector.h:88
virtual bool empty() const
Return true if vector is empty.
Definition: EigenVector.cpp:79
virtual const GenericVector & operator=(const GenericVector &x)
Assignment operator.
Definition: EigenVector.cpp:260
virtual bool owns_index(std::size_t i) const
Determine whether global vector index is owned by this process.
Definition: EigenVector.cpp:98
virtual void zero()
Set all entries to zero and keep any sparse structure.
Definition: EigenVector.cpp:172
virtual ~EigenVector()
Destructor.
Definition: EigenVector.cpp:68
Base class for LinearAlgebra factories.
Definition: GenericLinearAlgebraFactory.h:46
virtual const EigenVector & operator-=(const GenericVector &x)
Subtract given vector.
Definition: EigenVector.cpp:325
virtual void add(const double *block, std::size_t m, const dolfin::la_index *rows)
Add block of values using global indices.
Definition: EigenVector.cpp:160
MPI_Comm comm() const
Return the underlying MPI_Comm object.
Definition: MPI.cpp:117
double * data()
Return pointer to underlying data.
Definition: EigenVector.cpp:379
virtual void add_local(const double *block, std::size_t m, const dolfin::la_index *rows)
Add block of values using local indices.
Definition: EigenVector.h:180
virtual void abs()
Replace all entries in the vector by their absolute values.
Definition: EigenVector.cpp:246
std::shared_ptr< Eigen::VectorXd > vec()
Return reference to Eigen vector (non-const version)
Definition: EigenVector.h:271
virtual std::size_t local_size() const
Return local size of vector.
Definition: EigenVector.h:148
virtual std::pair< std::int64_t, std::int64_t > local_range() const
Return local ownership range of a vector.
Definition: EigenVector.cpp:93
PetscInt la_index
Index type for compatibility with linear algebra backend(s)
Definition: types.h:32
EigenVector()
Create empty vector (on MPI_COMM_SELF)
Definition: EigenVector.cpp:34
Definition: EigenVector.h:45
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129
virtual MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: EigenVector.h:76
virtual double operator[](dolfin::la_index i) const
Access value of given entry (const version)
Definition: EigenVector.h:275
virtual GenericLinearAlgebraFactory & factory() const
Return linear algebra backend factory.
Definition: EigenVector.cpp:363
virtual const EigenVector & operator*=(double a)
Multiply vector by given number.
Definition: EigenVector.cpp:289
virtual void axpy(double a, const GenericVector &x)
Add multiple of given vector (AXPY operation)
Definition: EigenVector.cpp:232
virtual void gather_on_zero(std::vector< double > &x) const
Gather all entries into x on process 0.
Definition: EigenVector.cpp:148
This class defines a common interface for vectors.
Definition: GenericVector.h:47
virtual double max() const
Return maximum value of vector.
Definition: EigenVector.cpp:203
virtual std::size_t size() const
Return true if vector is empty.
Definition: EigenVector.cpp:88