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"
42template <
typename T>
class EigenSparseMatrix;
43template <
typename T>
class EigenSparseLinearSolver;
44template <
typename T>
class SparseMatrix;
91 const std::vector<numeric_index_type> & ghost,
115 virtual void close ()
override;
117 virtual void clear ()
override;
119 virtual void zero ()
override;
121 virtual std::unique_ptr<NumericVector<T>>
zero_clone ()
const override;
123 virtual std::unique_ptr<NumericVector<T>>
clone ()
const override;
127 const bool fast=
false,
131 const bool fast=
false,
136 const std::vector<numeric_index_type> & ghost,
137 const bool fast =
false,
141 const bool fast =
false)
override;
149 virtual Real min ()
const override;
151 virtual Real max ()
const override;
153 virtual T
sum ()
const override;
187 virtual void add (
const T s)
override;
205 virtual void scale (
const T factor)
override;
207 virtual void abs()
override;
211 virtual void localize (std::vector<T> & v_local)
const override;
216 const std::vector<numeric_index_type> & send_list)
const override;
218 virtual void localize (std::vector<T> & v_local,
219 const std::vector<numeric_index_type> & indices)
const override;
223 const std::vector<numeric_index_type> & send_list)
override;
235 const std::vector<numeric_index_type> & rows,
236 bool supplying_global_rows =
true)
const override;
242 virtual std::unique_ptr<NumericVector<T>>
243 get_subvector(
const std::vector<numeric_index_type> & rows)
override;
246 const std::vector<numeric_index_type> & rows)
override;
292 this->
init(n, n,
false, ptype);
305 this->
init(n, n_local,
false, ptype);
315 const std::vector<numeric_index_type> & ghost,
319 this->
init(N, n_local, ghost,
false, ptype);
333 libmesh_error_msg_if(n != n_local,
"Error: EigenSparseVectors can only be used in serial!");
343 this->_is_initialized =
true;
344 this->_is_closed =
true;
361 this->init(n,n,fast,ptype);
369 const std::vector<numeric_index_type> & libmesh_dbg_var(ghost),
374 this->init(n,n_local,fast,ptype);
396 this->_is_closed =
true;
407 this->_is_initialized =
false;
408 this->_is_closed =
false;
413template <
typename T>
inline
428 std::unique_ptr<NumericVector<T>> cloned_vector =
429 std::make_unique<EigenSparseVector<T>>(this->comm());
430 cloned_vector->init(*
this);
431 return cloned_vector;
440 std::unique_ptr<NumericVector<T>> cloned_vector =
441 std::make_unique<EigenSparseVector<T>>(this->comm());
442 cloned_vector->init(*
this,
true);
443 *cloned_vector = *
this;
444 return cloned_vector;
498 libmesh_assert_less (i, this->size());
500 std::scoped_lock lock(this->_numeric_vector_mutex);
503 this->_is_closed =
false;
513 libmesh_assert_less (i, this->size());
515 std::scoped_lock lock(this->_numeric_vector_mutex);
518 this->_is_closed =
false;
529 (i < this->last_local_index())) );
546 std::swap (this->_type, v.
_type);
557 return std::numeric_limits<int>::max();
This class provides an interface to Eigen iterative solvers that is compatible with the libMesh Linea...
The EigenSparseMatrix class wraps a sparse matrix object from the Eigen library.
This class provides a nice interface to the Eigen C++-based data structures for serial vectors.
virtual NumericVector< T > & operator+=(const NumericVector< T > &v) override
Adds v to *this, .
virtual void add_vector(const NumericVector< T > &v, const SparseMatrix< T > &A) override
Computes , i.e.
virtual std::size_t max_allowed_id() const override
virtual T sum() const override
virtual void close() override
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
virtual void restore_subvector(std::unique_ptr< NumericVector< T > > subvector, const std::vector< numeric_index_type > &rows) override
Restores a view into this vector using the indices in rows.
virtual void swap(NumericVector< T > &v) override
Swaps the contents of this with v.
virtual Real max() const override
virtual NumericVector< T > & operator-=(const NumericVector< T > &v) override
Subtracts v from *this, .
virtual void clear() override
Restores the NumericVector<T> to a pristine state.
virtual T operator()(const numeric_index_type i) const override
virtual T dot(const NumericVector< T > &v) const override
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.
EigenSparseVector(EigenSparseVector &&)=default
The 5 special functions can be defaulted for this class, as it does not manage any memory itself.
DataType _vec
Actual Eigen::SparseVector<> we are wrapping.
virtual Real l2_norm() const override
virtual std::unique_ptr< NumericVector< T > > zero_clone() const override
virtual void add(const numeric_index_type i, const T value) override
Adds value to the vector entry specified by i.
EigenSparseVector(const EigenSparseVector &)=default
virtual void zero() override
Set all entries to zero.
virtual void conjugate() override
Negates the imaginary component of each entry in the vector.
EigenSparseVector(const Parallel::Communicator &comm_in, const ParallelType=AUTOMATIC)
Dummy-Constructor.
virtual ~EigenSparseVector()=default
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const std::vector< numeric_index_type > &ghost, const bool fast=false, const ParallelType=AUTOMATIC) override
Create a vector that holds the local indices plus those specified in the ghost argument.
virtual numeric_index_type first_local_index() const override
virtual void add_vector_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A) override
Computes , i.e.
virtual Real min() const override
virtual void pointwise_divide(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
Computes (summation not implied) i.e.
virtual std::unique_ptr< NumericVector< T > > get_subvector(const std::vector< numeric_index_type > &rows) override
Creates a view into this vector using the indices in rows.
virtual numeric_index_type size() const override
virtual NumericVector< T > & operator/=(const NumericVector< T > &v_in) override
Computes the component-wise division of this vector's entries by another's, .
virtual Real linfty_norm() const override
virtual void localize(NumericVector< T > &v_local, const std::vector< numeric_index_type > &send_list) const override
Creates a local vector v_local containing only information relevant to this processor,...
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
Computes (summation not implied) i.e.
EigenSV DataType
Convenient typedefs.
virtual numeric_index_type local_size() const override
virtual std::unique_ptr< NumericVector< T > > clone() const override
const DataType & vec() const
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.
virtual void set(const numeric_index_type i, const T value) override
Sets v(i) = value.
virtual Real l1_norm() const override
virtual void localize(const numeric_index_type first_local_idx, const numeric_index_type last_local_idx, const std::vector< numeric_index_type > &send_list) override
Updates a local vector with selected values from neighboring processors, as defined by send_list.
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 reciprocal() override
Computes the component-wise reciprocal, .
DataType & vec()
References to the underlying Eigen data types.
virtual void scale(const T factor) override
Scale each element of the vector by the given factor.
virtual numeric_index_type last_local_index() const override
virtual void abs() override
Sets for each entry in the vector.
EigenSparseVector< T > & operator=(const EigenSparseVector< T > &v)
Copy assignment operator.
virtual void create_subvector(NumericVector< T > &subvector, const std::vector< numeric_index_type > &rows, bool supplying_global_rows=true) const override
Fills in subvector from this vector using the indices in rows.
virtual void localize(std::vector< T > &v_local) const override
Creates a copy of the global vector in the local vector v_local.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
ParallelType type() const
ParallelType _type
Type of vector.
bool _is_initialized
true once init() has been called.
virtual numeric_index_type size() const =0
bool _is_closed
Flag which tracks whether the vector's values are consistent on all processors after insertion or add...
virtual numeric_index_type local_size() const =0
The libMesh namespace provides an interface to certain functionality in the library.
ParallelType
Defines an enum for parallel data structure types.
bool closed()
Checks that the library has been closed.
dof_id_type numeric_index_type
Eigen::Matrix< Number, Eigen::Dynamic, 1 > EigenSV
bool initialized()
Checks that library initialization has been done.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type