20 #ifndef LIBMESH_DENSE_VECTOR_H 21 #define LIBMESH_DENSE_VECTOR_H 24 #include "libmesh/libmesh_common.h" 25 #include "libmesh/dense_vector_base.h" 26 #include "libmesh/compare_types.h" 27 #include "libmesh/int_range.h" 28 #include "libmesh/tensor_tools.h" 30 #ifdef LIBMESH_HAVE_EIGEN 31 #include "libmesh/ignore_warnings.h" 33 #include "libmesh/restore_warnings.h" 36 #ifdef LIBMESH_HAVE_METAPHYSICL 37 #include "metaphysicl/raw_type.h" 42 #include <initializer_list> 58 class DenseVector :
public DenseVectorBase<T>
79 template <
typename T2>
85 template <
typename T2>
91 template <
typename T2>
104 virtual unsigned int size() const override final
106 return cast_int<unsigned int>(
_val.size());
109 virtual bool empty() const override final
110 {
return _val.empty(); }
112 virtual void zero() override final;
117 const T & operator() (const
unsigned int i) const;
122 T & operator() (const
unsigned int i);
127 const T & operator[] (const
unsigned int i)
const {
return (*
this)(i); }
134 virtual T
el(
const unsigned int i)
const override final 135 {
return (*
this)(i); }
137 virtual T &
el(
const unsigned int i)
override final 138 {
return (*
this)(i); }
145 template <
typename T2>
156 void resize (
const unsigned int n);
162 template <
typename T2>
168 void scale (
const T factor);
184 template <
typename T2,
typename T3>
187 add (
const T2 factor,
195 template <
typename T2>
204 template <
typename T2>
210 template <
typename T2>
216 template <
typename T2>
224 template <
typename T2>
232 template <
typename T2>
288 typename std::vector<T>::const_iterator
begin()
const {
return _val.begin(); }
289 typename std::vector<T>::iterator
begin() {
return _val.begin(); }
294 typename std::vector<T>::const_iterator
end()
const {
return _val.end(); }
295 typename std::vector<T>::iterator
end() {
return _val.end(); }
328 template<
typename T2>
333 const std::vector<T2> & other_vals = other_vector.get_values();
337 const int N = cast_int<int>(other_vals.size());
340 for (
int i=0; i<N; i++)
341 _val.push_back(other_vals[i]);
347 template<
typename T2>
356 template <
typename T2>
359 _val(init_list.begin(), init_list.end())
366 template<
typename T2>
370 const std::vector<T2> & other_vals = other_vector.get_values();
374 const int N = cast_int<int>(other_vals.size());
377 for (
int i=0; i<N; i++)
378 _val.push_back(other_vals[i]);
389 _val.
swap(other_vector._val);
406 template<
typename T2>
410 const std::vector<T2> & other_vals = other_vector.get_values();
412 _val.reserve(this->size() + other_vals.size());
413 _val.insert(_val.end(), other_vals.begin(), other_vals.end());
422 std::fill (_val.begin(),
433 libmesh_assert_less (i, _val.size());
444 libmesh_assert_less (i, _val.size());
455 const int N = cast_int<int>(_val.size());
456 for (
int i=0; i<N; i++)
473 template<
typename T2,
typename T3>
480 libmesh_assert_equal_to (this->size(), vec.size());
482 const int N = cast_int<int>(_val.size());
483 for (
int i=0; i<N; i++)
484 (*
this)(i) += static_cast<T>(factor)*vec(i);
490 template<
typename T2>
497 libmesh_assert_equal_to (this->size(), vec.size());
499 #ifdef LIBMESH_HAVE_EIGEN 504 return Eigen::Map<const typename Eigen::Matrix<T2, Eigen::Dynamic, 1>>(vec.get_values().data(), vec.size())
505 .dot(Eigen::Map<
const typename Eigen::Matrix<T, Eigen::Dynamic, 1>>(_val.data(), _val.size()));
509 const int N = cast_int<int>(_val.size());
513 #pragma clang loop vectorize(enable) 515 for (
int i=0; i<N; i++)
523 template<
typename T2>
527 libmesh_assert_equal_to (this->size(), vec.size());
531 const int N = cast_int<int>(_val.size());
532 for (
int i=0; i<N; i++)
533 val += (*
this)(i)*(vec(i));
539 template<
typename T2>
543 libmesh_assert_equal_to (this->size(), vec.size());
545 const int N = cast_int<int>(_val.size());
546 for (
int i=0; i<N; i++)
547 if ((*
this)(i) != vec(i))
556 template<
typename T2>
560 libmesh_assert_equal_to (this->size(), vec.size());
562 const int N = cast_int<int>(_val.size());
563 for (
int i=0; i<N; i++)
564 if ((*
this)(i) != vec(i))
573 template<
typename T2>
577 libmesh_assert_equal_to (this->size(), vec.size());
579 const int N = cast_int<int>(_val.size());
580 for (
int i=0; i<N; i++)
581 (*
this)(i) += vec(i);
589 template<
typename T2>
593 libmesh_assert_equal_to (this->size(), vec.size());
595 const int N = cast_int<int>(_val.size());
596 for (
int i=0; i<N; i++)
597 (*
this)(i) -= vec(i);
611 const int N = cast_int<int>(_val.size());
612 for (
int i=1; i!=N; i++)
615 my_min = (my_min < current? my_min : current);
629 const int N = cast_int<int>(_val.size());
630 for (
int i=1; i!=N; i++)
633 my_max = (my_max > current? my_max : current);
647 #ifdef LIBMESH_HAVE_EIGEN 648 return Eigen::Map<const typename Eigen::Matrix<T, Eigen::Dynamic, 1>>(_val.data(), _val.size()).
template lpNorm<1>();
651 const int N = cast_int<int>(_val.size());
652 for (
int i=0; i!=N; i++)
653 my_norm += std::abs((*
this)(i));
668 #ifdef LIBMESH_HAVE_EIGEN 669 return Eigen::Map<const typename Eigen::Matrix<T, Eigen::Dynamic, 1>>(_val.data(), _val.size()).
norm();
672 const int N = cast_int<int>(_val.size());
676 #pragma clang loop vectorize(enable) 678 for (
int i=0; i!=N; i++)
681 return sqrt(my_norm);
694 #ifdef LIBMESH_HAVE_EIGEN 695 return Eigen::Map<const typename Eigen::Matrix<T, Eigen::Dynamic, 1>>(_val.data(), _val.size()).
template lpNorm<Eigen::Infinity>();
699 const int N = cast_int<int>(_val.size());
700 for (
int i=1; i!=N; i++)
703 my_norm = (my_norm > current? my_norm : current);
705 return sqrt(my_norm);
716 libmesh_assert_less_equal ( sub_n, this->size() );
719 const int N = cast_int<int>(sub_n);
720 for (
int i=0; i<N; i++)
726 #ifdef LIBMESH_HAVE_METAPHYSICL 729 template <
typename T>
736 const auto s = in.
size();
738 for (
unsigned int i = 0; i < s; ++i)
739 ret(i) = raw_value(in(i));
747 #endif // LIBMESH_DENSE_VECTOR_H
DenseVector< T > & operator*=(const T factor)
Multiplies every element in the vector by factor.
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseVector< T3 > &vec)
Adds factor times vec to this vector.
virtual void zero() override final
Set every element in the vector to 0.
void resize(const unsigned int n)
Resize the vector.
std::vector< T > & get_values()
bool operator==(const DenseVector< T2 > &vec) const
The libMesh namespace provides an interface to certain functionality in the library.
void scale(const T factor)
Multiplies every element in the vector by factor.
bool operator==(const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &x, const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &y)
void get_principal_subvector(unsigned int sub_n, DenseVector< T > &dest) const
Puts the principal subvector of size sub_n (i.e.
const std::vector< T > & get_values() const
void swap(DenseVector< T > &other_vector)
STL-like swap method.
Order & operator-=(Order &o, T p)
virtual T & el(const unsigned int i) override final
DenseVector & operator=(const DenseVector &)=default
std::vector< T >::const_iterator begin() const
std::vector< T >::const_iterator end() const
auto l1_norm(const NumericVector< T > &vec)
virtual ~DenseVector()=default
virtual bool empty() const override final
bool operator!=(const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &x, const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &y)
std::vector< T >::iterator begin()
std::vector< T > _val
The actual data values, stored as a 1D array.
bool operator!=(const DenseVector< T2 > &vec) const
CompareTypes< T, T2 >::supertype indefinite_dot(const DenseVector< T2 > &vec) const
CompareTypes< T, T2 >::supertype dot(const DenseVector< T2 > &vec) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
DenseVector(const unsigned int n=0)
Constructor.
void append(const DenseVector< T2 > &other_vector)
Append additional entries to (resizing, but unchanging) the vector.
virtual unsigned int size() const override final
virtual T el(const unsigned int i) const override final
Defines an abstract dense vector base class for use in Finite Element-type computations.
Defines a dense vector for use in Finite Element-type computations.
const T & operator[](const unsigned int i) const
DenseVector< T > & operator+=(const DenseVector< T2 > &vec)
Adds vec to this vector.
std::vector< T >::iterator end()
DenseVector< T > & operator-=(const DenseVector< T2 > &vec)
Subtracts vec from this vector.
Order & operator+=(Order &o, T p)