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" 42 template <
typename T>
class EigenSparseMatrix;
43 template <
typename T>
class EigenSparseLinearSolver;
44 template <
typename T>
class SparseMatrix;
55 class EigenSparseVector final :
public NumericVector<T>
91 const std::vector<numeric_index_type> & ghost,
99 EigenSparseVector<T> &
operator= (
const EigenSparseVector<T> & v);
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;
264 template <
typename T>
275 template <
typename T>
282 this->
init(n, n,
false, ptype);
287 template <
typename T>
295 this->
init(n, n_local,
false, ptype);
300 template <
typename T>
305 const std::vector<numeric_index_type> & ghost,
309 this->
init(N, n_local, ghost,
false, ptype);
314 template <
typename T>
323 libmesh_error_msg_if(n != n_local,
"Error: EigenSparseVectors can only be used in serial!");
334 this->_is_closed =
true;
345 template <
typename T>
351 this->
init(n,n,fast,ptype);
355 template <
typename T>
359 const std::vector<numeric_index_type> & libmesh_dbg_var(ghost),
364 this->
init(n,n_local,fast,ptype);
380 template <
typename T>
386 this->_is_closed =
true;
391 template <
typename T>
398 this->_is_closed =
false;
403 template <
typename T>
inline 414 template <
typename T>
418 std::unique_ptr<NumericVector<T>> cloned_vector =
419 std::make_unique<EigenSparseVector<T>>(this->comm());
420 cloned_vector->init(*
this);
421 return cloned_vector;
426 template <
typename T>
430 std::unique_ptr<NumericVector<T>> cloned_vector =
431 std::make_unique<EigenSparseVector<T>>(this->comm());
432 cloned_vector->init(*
this,
true);
433 *cloned_vector = *
this;
434 return cloned_vector;
439 template <
typename T>
450 template <
typename T>
461 template <
typename T>
472 template <
typename T>
483 template <
typename T>
488 libmesh_assert_less (i, this->size());
490 std::scoped_lock lock(this->_numeric_vector_mutex);
493 this->_is_closed =
false;
498 template <
typename T>
503 libmesh_assert_less (i, this->size());
505 std::scoped_lock lock(this->_numeric_vector_mutex);
508 this->_is_closed =
false;
513 template <
typename T>
519 (i < this->last_local_index())) );
526 template <
typename T>
534 std::swap (this->_is_closed, v._is_closed);
536 std::swap (this->_type, v._type);
541 template <
typename T>
547 return std::numeric_limits<int>::max();
553 #endif // #ifdef LIBMESH_HAVE_EIGEN 554 #endif // LIBMESH_EIGEN_SPARSE_VECTOR_H virtual std::size_t max_allowed_id() const override
bool closed()
Checks that the library has been closed.
The EigenSparseMatrix class wraps a sparse matrix object from the Eigen library.
virtual Real linfty_norm() const override
virtual void localize(std::vector< T > &v_local) const override
Creates a copy of the global vector in the local vector v_local.
virtual void conjugate() override
Negates the imaginary component of each entry in the vector.
virtual void pointwise_divide(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
Computes (summation not implied) i.e.
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
Computes (summation not implied) i.e.
virtual T sum() const override
virtual void add_vector(const NumericVector< T > &v, const SparseMatrix< T > &A) override
Computes , i.e.
DataType _vec
Actual Eigen::SparseVector<> we are wrapping.
virtual void reciprocal() override
Computes the component-wise reciprocal, .
virtual numeric_index_type size() const =0
virtual NumericVector< T > & operator-=(const NumericVector< T > &v) override
Subtracts v from *this, .
virtual Real min() const override
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
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
virtual numeric_index_type last_local_index() const override
The libMesh namespace provides an interface to certain functionality in the library.
virtual void close() override
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
virtual void swap(NumericVector< T > &v) override
Swaps the contents of this with v.
virtual std::unique_ptr< NumericVector< T > > zero_clone() const override
uint8_t processor_id_type
EigenSV DataType
Convenient typedefs.
virtual Real l2_norm() const override
dof_id_type numeric_index_type
bool _is_initialized
Flag that tells if init() has been called.
virtual void clear() override
Restores the NumericVector<T> to a pristine state.
virtual Real max() 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, .
Eigen::Matrix< Number, Eigen::Dynamic, 1 > EigenSV
virtual numeric_index_type size() const override
const DataType & vec() const
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
virtual numeric_index_type local_size() const override
EigenSparseVector< T > & operator=(const EigenSparseVector< T > &v)
Copy assignment operator.
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 NumericVector< T > & operator*=(const NumericVector< T > &v_in) override
Computes the component-wise multiplication of this vector's entries by another's, ...
virtual void add_vector_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A) override
Computes , i.e.
virtual void abs() override
Sets for each entry in the vector.
DataType & vec()
References to the underlying Eigen data types.
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.
ParallelType _type
Type of vector.
virtual void set(const numeric_index_type i, const T value) override
Sets v(i) = value.
virtual void scale(const T factor) override
Scale each element of the vector by the given factor.
virtual numeric_index_type first_local_index() const override
ParallelType type() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real l1_norm() const override
virtual void add(const numeric_index_type i, const T value) override
Adds value to the vector entry specified by i.
virtual numeric_index_type local_size() const =0
virtual void zero() override
Set all entries to zero.
bool initialized()
Checks that library initialization has been done.
EigenSparseVector(const Parallel::Communicator &comm_in, const ParallelType=AUTOMATIC)
Dummy-Constructor.
virtual T operator()(const numeric_index_type i) const override
virtual ~EigenSparseVector()=default
virtual T dot(const NumericVector< T > &v) 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...
ParallelType
Defines an enum for parallel data structure types.