16 #ifndef dealii_vector_h 17 #define dealii_vector_h 20 #include <deal.II/base/config.h> 22 #include <deal.II/base/aligned_vector.h> 23 #include <deal.II/base/exceptions.h> 24 #include <deal.II/base/index_set.h> 25 #include <deal.II/base/logstream.h> 26 #include <deal.II/base/subscriptor.h> 28 #include <deal.II/differentiation/ad/ad_number_traits.h> 30 #include <deal.II/lac/vector_operation.h> 31 #include <deal.II/lac/vector_type_traits.h> 33 #include <boost/serialization/split_member.hpp> 36 #include <initializer_list> 41 DEAL_II_NAMESPACE_OPEN
44 #ifdef DEAL_II_WITH_PETSC 51 #ifdef DEAL_II_WITH_TRILINOS 61 template <
typename number>
109 template <
typename Number>
117 "The Vector class does not support auto-differentiable numbers.");
161 Vector(
const Vector<Number> &v);
167 Vector(Vector<Number> &&v) noexcept =
default;
177 template <
typename OtherNumber>
178 explicit Vector(
const Vector<OtherNumber> &v);
195 template <
typename OtherNumber>
196 explicit Vector(
const std::initializer_list<OtherNumber> &v);
198 #ifdef DEAL_II_WITH_PETSC 213 #ifdef DEAL_II_WITH_TRILINOS 240 explicit Vector(
const size_type n);
246 template <
typename InputIterator>
247 Vector(
const InputIterator first,
const InputIterator last);
253 virtual ~Vector()
override =
default;
288 reinit(
const size_type N,
const bool omit_zeroing_entries =
false);
335 template <
typename Number2>
337 reinit(
const Vector<Number2> &V,
const bool omit_zeroing_entries =
false);
355 swap(Vector<Number> &v);
384 operator=(Vector<Number> &&v) noexcept =
default;
391 template <
typename Number2>
401 #ifdef DEAL_II_WITH_PETSC 418 #ifdef DEAL_II_WITH_TRILINOS 443 template <
typename Number2>
452 template <
typename Number2>
477 template <
typename Number2>
478 Number
operator*(
const Vector<Number2> &V)
const;
563 add_and_dot(
const Number a,
const Vector<Number> &V,
const Vector<Number> &W);
653 template <
typename OtherNumber>
656 std::vector<OtherNumber> &
values)
const;
685 template <
typename ForwardIterator,
typename OutputIterator>
688 const ForwardIterator indices_end,
689 OutputIterator values_begin)
const;
718 template <
typename OtherNumber>
720 add(
const std::vector<size_type> & indices,
721 const std::vector<OtherNumber> &
values);
727 template <
typename OtherNumber>
729 add(
const std::vector<size_type> &indices,
const Vector<OtherNumber> &
values);
736 template <
typename OtherNumber>
738 add(
const size_type n_elements,
739 const size_type * indices,
740 const OtherNumber *
values);
758 const Vector<Number> &V,
760 const Vector<Number> &W);
768 add(
const Number a,
const Vector<Number> &V);
776 sadd(
const Number s,
const Vector<Number> &V);
784 sadd(
const Number s,
const Number a,
const Vector<Number> &V);
810 scale(
const Vector<Number> &scaling_factors);
817 template <
typename Number2>
819 scale(
const Vector<Number2> &scaling_factors);
827 equ(
const Number a,
const Vector<Number> &u);
832 template <
typename Number2>
834 equ(
const Number a,
const Vector<Number2> &u);
850 ratio(
const Vector<Number> &a,
const Vector<Number> &b);
873 print(
const char *format =
nullptr)
const;
882 print(std::ostream & out,
883 const unsigned int precision = 3,
884 const bool scientific =
true,
885 const bool across =
true)
const;
898 const unsigned int width = 6,
899 const bool across =
true)
const;
927 template <
class Archive>
929 save(Archive &ar,
const unsigned int version)
const;
935 template <
class Archive>
937 load(Archive &ar,
const unsigned int version);
939 BOOST_SERIALIZATION_SPLIT_MEMBER()
1029 const
bool omit_zeroing_entries,
1030 const
bool reset_partitioner);
1042 template <typename Number2>
1061 template <
typename Number>
1072 template <
typename Number>
1073 template <
typename OtherNumber>
1080 template <
typename Number>
1081 template <
typename InputIterator>
1086 reinit(std::distance(first, last),
true);
1087 std::copy(first, last, begin());
1092 template <
typename Number>
1103 template <
typename Number>
1104 inline typename Vector<Number>::size_type
1107 return values.size();
1111 template <
typename Number>
1120 template <
typename Number>
1121 inline typename Vector<Number>::pointer
1124 return values.data();
1129 template <
typename Number>
1130 inline typename Vector<Number>::const_pointer
1133 return values.data();
1138 template <
typename Number>
1139 inline typename Vector<Number>::iterator
1142 return values.begin();
1147 template <
typename Number>
1148 inline typename Vector<Number>::const_iterator
1151 return values.begin();
1156 template <
typename Number>
1157 inline typename Vector<Number>::iterator
1160 return values.end();
1165 template <
typename Number>
1166 inline typename Vector<Number>::const_iterator
1169 return values.end();
1174 template <
typename Number>
1184 template <
typename Number>
1188 Assert(i < size(), ExcIndexRangeType<size_type>(i, 0, size()));
1194 template <
typename Number>
1197 return operator()(i);
1202 template <
typename Number>
1205 return operator()(i);
1210 template <
typename Number>
1211 template <
typename OtherNumber>
1214 std::vector<OtherNumber> & values)
const 1216 for (size_type i = 0; i < indices.size(); ++i)
1217 values[i] =
operator()(indices[i]);
1222 template <
typename Number>
1223 template <
typename ForwardIterator,
typename OutputIterator>
1226 const ForwardIterator indices_end,
1227 OutputIterator values_begin)
const 1229 while (indices_begin != indices_end)
1231 *values_begin = operator()(*indices_begin);
1239 template <
typename Number>
1240 inline Vector<Number> &
1246 this->operator*=(Number(1.) / factor);
1252 template <
typename Number>
1253 template <
typename OtherNumber>
1256 const std::vector<OtherNumber> &values)
1258 Assert(indices.size() == values.size(),
1260 add(indices.size(), indices.data(), values.data());
1265 template <
typename Number>
1266 template <
typename OtherNumber>
1269 const Vector<OtherNumber> & values)
1271 Assert(indices.size() == values.size(),
1273 add(indices.size(), indices.data(), values.values.begin());
1278 template <
typename Number>
1279 template <
typename OtherNumber>
1282 const size_type * indices,
1283 const OtherNumber *values)
1285 for (size_type i = 0; i < n_indices; ++i)
1291 "The given value is not finite but either infinite or Not A Number (NaN)"));
1293 this->values[indices[i]] += values[i];
1299 template <
typename Number>
1300 template <
typename Number2>
1304 return !(*
this == v);
1309 template <
typename Number>
1315 template <
typename Number>
1325 template <
typename Number>
1329 values.swap(v.values);
1330 std::swap(thread_loop_partitioner, v.thread_loop_partitioner);
1335 template <
typename Number>
1336 template <
class Archive>
1347 template <
typename Number>
1348 template <
class Archive>
1355 maybe_reset_thread_partitioner();
1374 template <
typename Number>
1376 swap(Vector<Number> &u, Vector<Number> &v)
1385 template <
typename number>
1386 inline std::ostream &
1387 operator<<(std::ostream &os, const Vector<number> &v)
1396 template <
typename number>
1398 operator<<(LogStream &os, const Vector<number> &v)
1412 template <
typename Number>
1417 DEAL_II_NAMESPACE_CLOSE
void block_read(std::istream &in)
void update_ghost_values() const
std::size_t memory_consumption() const
real_type l1_norm() const
Number operator[](const size_type i) const
void ratio(const Vector< Number > &a, const Vector< Number > &b)
bool operator!=(const Vector< Number2 > &v) const
void apply_givens_rotation(const std::array< Number, 3 > &csr, const size_type i, const size_type k)
void load(Archive &ar, const unsigned int version)
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
Number operator()(const size_type i) const
Subscriptor & operator=(const Subscriptor &)
real_type linfty_norm() const
typename numbers::NumberTraits< typename VectorType::value_type >::real_type real_type
void do_reinit(const size_type new_size, const bool omit_zeroing_entries, const bool reset_partitioner)
bool is_non_negative() const
__global__ void add_and_dot(Number *res, Number *v1, const Number *v2, const Number *v3, const Number a, const size_type N)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
LinearAlgebra::distributed::Vector< Number > Vector
bool is_finite(const double x)
__global__ void scale(Number *val, const Number *V_val, const size_type N)
void add(const std::vector< size_type > &indices, const std::vector< OtherNumber > &values)
static ::ExceptionBase & ExcMessage(std::string arg1)
void swap(BlockIndices &u, BlockIndices &v)
typename VectorType::value_type value_type
bool in_local_range(const size_type global_index) const
Vector< Number > & operator+=(const Vector< Number > &V)
void maybe_reset_thread_partitioner()
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
real_type lp_norm(const real_type p) const
void grow_or_shrink(const size_type N)
Vector< Number > & operator-=(const Vector< Number > &V)
Vector< Number > & operator*=(const Number factor)
__global__ void equ(Number *val, const Number a, const Number *V_val, const size_type N)
void print(const char *format=nullptr) const
__global__ void sadd(const Number s, Number *val, const Number a, const Number *V_val, const size_type N)
virtual ~Vector() override=default
void swap(Vector< Number > &u, Vector< Number > &v)
unsigned int global_dof_index
virtual void swap(Vector< Number > &v)
Vector< Number > & operator/=(const Number factor)
void block_write(std::ostream &out) const
IndexSet locally_owned_elements() const
void save(Archive &ar, const unsigned int version) const
bool operator==(const Vector< Number2 > &v) const
void compress(::VectorOperation::values operation=::VectorOperation::unknown) const
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
AlignedVector< Number > values
real_type norm_sqr() const
std::shared_ptr< parallel::internal::TBBPartitioner > thread_loop_partitioner
real_type l2_norm() const
static ::ExceptionBase & ExcZero()
#define AssertIsFinite(number)
Number mean_value() const