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;
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;
274 template <
typename T>
285 template <
typename T>
292 this->
init(n, n,
false, ptype);
297 template <
typename T>
305 this->
init(n, n_local,
false, ptype);
310 template <
typename T>
315 const std::vector<numeric_index_type> & ghost,
319 this->
init(N, n_local, ghost,
false, ptype);
324 template <
typename T>
333 libmesh_error_msg_if(n != n_local,
"Error: EigenSparseVectors can only be used in serial!");
344 this->_is_closed =
true;
355 template <
typename T>
361 this->
init(n,n,fast,ptype);
365 template <
typename T>
369 const std::vector<numeric_index_type> & libmesh_dbg_var(ghost),
374 this->
init(n,n_local,fast,ptype);
390 template <
typename T>
396 this->_is_closed =
true;
401 template <
typename T>
408 this->_is_closed =
false;
413 template <
typename T>
inline 424 template <
typename T>
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;
436 template <
typename T>
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;
449 template <
typename T>
460 template <
typename T>
471 template <
typename T>
482 template <
typename T>
493 template <
typename T>
498 libmesh_assert_less (i, this->size());
500 std::scoped_lock lock(this->_numeric_vector_mutex);
503 this->_is_closed =
false;
508 template <
typename T>
513 libmesh_assert_less (i, this->size());
515 std::scoped_lock lock(this->_numeric_vector_mutex);
518 this->_is_closed =
false;
523 template <
typename T>
529 (i < this->last_local_index())) );
536 template <
typename T>
544 std::swap (this->_is_closed, v._is_closed);
546 std::swap (this->_type, v._type);
551 template <
typename T>
557 return std::numeric_limits<int>::max();
563 #endif // #ifdef LIBMESH_HAVE_EIGEN 564 #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 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 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.
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.
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 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 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.