Go to the documentation of this file.
21 #ifndef LIBMESH_EIGEN_SPARSE_VECTOR_H
22 #define LIBMESH_EIGEN_SPARSE_VECTOR_H
26 #include "libmesh/libmesh_common.h"
28 #ifdef LIBMESH_HAVE_EIGEN
31 #include "libmesh/eigen_core_support.h"
32 #include "libmesh/numeric_vector.h"
38 template <
typename T>
class EigenSparseMatrix;
39 template <
typename T>
class EigenSparseLinearSolver;
40 template <
typename T>
class SparseMatrix;
51 class EigenSparseVector final :
public NumericVector<T>
87 const std::vector<numeric_index_type> & ghost,
95 EigenSparseVector<T> &
operator= (
const EigenSparseVector<T> & v);
111 virtual void close ()
override;
113 virtual void clear ()
override;
115 virtual void zero ()
override;
117 virtual std::unique_ptr<NumericVector<T>>
zero_clone ()
const override;
119 virtual std::unique_ptr<NumericVector<T>>
clone ()
const override;
123 const bool fast=
false,
127 const bool fast=
false,
132 const std::vector<numeric_index_type> & ghost,
133 const bool fast =
false,
137 const bool fast =
false)
override;
145 virtual Real min ()
const override;
147 virtual Real max ()
const override;
149 virtual T
sum ()
const override;
183 virtual void add (
const T s)
override;
201 virtual void scale (
const T factor)
override;
203 virtual void abs()
override;
207 virtual void localize (std::vector<T> & v_local)
const override;
212 const std::vector<numeric_index_type> & send_list)
const override;
214 virtual void localize (std::vector<T> & v_local,
215 const std::vector<numeric_index_type> & indices)
const override;
219 const std::vector<numeric_index_type> & send_list)
override;
255 template <
typename T>
266 template <
typename T>
273 this->
init(n, n,
false, ptype);
278 template <
typename T>
286 this->
init(n, n_local,
false, ptype);
291 template <
typename T>
296 const std::vector<numeric_index_type> & ghost,
300 this->
init(N, n_local, ghost,
false, ptype);
305 template <
typename T>
315 libmesh_error_msg(
"Error: EigenSparseVectors can only be used in serial!");
326 this->_is_closed =
true;
337 template <
typename T>
343 this->
init(n,n,fast,ptype);
347 template <
typename T>
351 const std::vector<numeric_index_type> & libmesh_dbg_var(ghost),
356 this->
init(n,n_local,fast,ptype);
372 template <
typename T>
378 this->_is_closed =
true;
383 template <
typename T>
390 this->_is_closed =
false;
395 template <
typename T>
inline
406 template <
typename T>
411 cloned_vector->
init(*
this);
412 return std::unique_ptr<NumericVector<T>>(cloned_vector);
417 template <
typename T>
422 cloned_vector->
init(*
this,
true);
423 *cloned_vector = *
this;
424 return std::unique_ptr<NumericVector<T>>(cloned_vector);
429 template <
typename T>
435 return static_cast<numeric_index_type>(_vec.size());
440 template <
typename T>
451 template <
typename T>
462 template <
typename T>
473 template <
typename T>
478 libmesh_assert_less (i, this->size());
480 _vec[static_cast<eigen_idx_type>(i)] =
value;
482 this->_is_closed =
false;
487 template <
typename T>
492 libmesh_assert_less (i, this->size());
494 _vec[static_cast<eigen_idx_type>(i)] +=
value;
496 this->_is_closed =
false;
501 template <
typename T>
507 (i < this->last_local_index())) );
509 return _vec[static_cast<eigen_idx_type>(i)];
514 template <
typename T>
522 std::swap (this->_is_closed, v._is_closed);
531 #endif // #ifdef LIBMESH_HAVE_EIGEN
532 #endif // LIBMESH_EIGEN_SPARSE_VECTOR_H
virtual Real max() const override
DataType & vec()
References to the underlying Eigen data types.
EigenSparseVector< T > & operator=(const EigenSparseVector< T > &v)
Copy assignment operator.
virtual NumericVector< T > & operator*=(const NumericVector< T > &v_in) override
Computes the component-wise multiplication of this vector's entries by another's, .
virtual void clear() override
Restores the NumericVector<T> to a pristine state.
virtual numeric_index_type size() const override
virtual numeric_index_type first_local_index() const override
The EigenSparseMatrix class wraps a sparse matrix object from the Eigen library.
virtual numeric_index_type local_size() const override
virtual void abs() override
Sets for each entry in the vector.
virtual void add_vector_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A) override
Computes , i.e.
virtual void scale(const T factor) override
Scale each element of the vector by the given factor.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void localize_to_one(std::vector< T > &v_local, const processor_id_type proc_id=0) const override
Creates a local copy of the global vector in v_local only on processor proc_id.
virtual void set(const numeric_index_type i, const T value) override
Sets v(i) = value.
virtual Real l1_norm() const override
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
virtual void zero() override
Set all entries to zero.
virtual void add(const numeric_index_type i, const T value) override
Adds value to each entry of the vector.
EigenSparseVector(const Parallel::Communicator &comm_in, const ParallelType=AUTOMATIC)
Dummy-Constructor.
virtual ~EigenSparseVector()=default
virtual numeric_index_type size() const =0
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
ParallelType _type
Type of vector.
virtual T dot(const NumericVector< T > &v) const override
virtual T operator()(const numeric_index_type i) const override
virtual NumericVector< T > & operator+=(const NumericVector< T > &v) override
Adds v to *this, .
This class provides a nice interface to the Eigen C++-based data structures for serial vectors.
Eigen::Matrix< Number, Eigen::Dynamic, 1 > EigenSV
uint8_t processor_id_type
virtual void localize(std::vector< T > &v_local) const override
Creates a copy of the global vector in the local vector v_local.
virtual Real linfty_norm() const override
virtual numeric_index_type local_size() const =0
virtual void conjugate() override
Negates the imaginary component of each entry in the vector.
static PetscErrorCode Mat * A
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
Computes (summation not implied) i.e.
DataType _vec
Actual Eigen::SparseVector<> we are wrapping.
virtual T sum() const override
dof_id_type numeric_index_type
bool initialized()
Checks that library initialization has been done.
virtual void add_vector(const NumericVector< T > &v, const SparseMatrix< T > &A) override
Computes , i.e.
virtual numeric_index_type last_local_index() const override
virtual void reciprocal() override
Computes the component-wise reciprocal, .
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
virtual Real min() const override
virtual NumericVector< T > & operator-=(const NumericVector< T > &v) override
Subtracts v from *this, .
bool _is_initialized
Flag that tells if init() has been called.
This class provides an interface to Eigen iterative solvers that is compatible with the libMesh Linea...
virtual std::unique_ptr< NumericVector< T > > clone() const override
ParallelType
Defines an enum for parallel data structure types.
virtual void swap(NumericVector< T > &v) override
Swaps the contents of this with v.
virtual void close() override
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
virtual std::unique_ptr< NumericVector< T > > zero_clone() const override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
EigenSV DataType
Convenient typedefs.
const DataType & vec() const
ParallelType type() const
virtual Real l2_norm() const override
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC) override
Change the dimension of the vector to n.
bool closed()
Checks that the library has been closed.
virtual NumericVector< T > & operator/=(const NumericVector< T > &v_in) override
Computes the component-wise division of this vector's entries by another's, .