16 #ifndef dealii_vector_h 17 #define dealii_vector_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/logstream.h> 22 #include <deal.II/base/exceptions.h> 23 #include <deal.II/base/subscriptor.h> 24 #include <deal.II/base/index_set.h> 25 #include <deal.II/lac/vector_operation.h> 26 #include <deal.II/lac/vector_type_traits.h> 30 #include <boost/version.hpp> 31 #if BOOST_VERSION >= 106400 32 # include <boost/serialization/array_wrapper.hpp> 34 # include <boost/serialization/array.hpp> 36 #include <boost/serialization/split_member.hpp> 43 DEAL_II_NAMESPACE_OPEN
46 #ifdef DEAL_II_WITH_PETSC 53 #ifdef DEAL_II_WITH_TRILINOS 102 template <
typename Number>
148 Vector (
const Vector<Number> &v);
154 Vector (Vector<Number> &&v) noexcept;
168 template <
typename OtherNumber>
170 Vector (
const Vector<OtherNumber> &v);
172 #ifdef DEAL_II_WITH_PETSC 187 #ifdef DEAL_II_WITH_TRILINOS 214 explicit Vector (
const size_type n);
220 template <
typename InputIterator>
221 Vector (
const InputIterator first,
222 const InputIterator last);
261 virtual void reinit (
const size_type N,
262 const bool omit_zeroing_entries=
false);
296 template <
typename Number2>
297 void reinit (
const Vector<Number2> &V,
298 const bool omit_zeroing_entries=
false);
315 virtual void swap (Vector<Number> &v);
330 Vector<Number> &
operator= (
const Number s);
337 Vector<Number> &
operator= (
const Vector<Number> &v);
344 Vector<Number> &
operator= (Vector<Number> &&v) noexcept;
351 template <
typename Number2>
352 Vector<Number> &
operator= (
const Vector<Number2> &v);
359 #ifdef DEAL_II_WITH_PETSC 376 #ifdef DEAL_II_WITH_TRILINOS 401 template <
typename Number2>
402 bool operator== (
const Vector<Number2> &v)
const;
409 template <
typename Number2>
433 template <
typename Number2>
434 Number
operator * (
const Vector<Number2> &V)
const;
513 const Vector<Number> &V,
514 const Vector<Number> &W);
534 const_iterator
begin ()
const;
545 const_iterator
end ()
const;
586 template <
typename OtherNumber>
588 std::vector<OtherNumber> &
values)
const;
617 template <
typename ForwardIterator,
typename OutputIterator>
619 const ForwardIterator indices_end,
620 OutputIterator values_begin)
const;
634 Vector<Number> &
operator += (
const Vector<Number> &V);
641 Vector<Number> &
operator -= (
const Vector<Number> &V);
647 template <
typename OtherNumber>
648 void add (
const std::vector<size_type> &indices,
649 const std::vector<OtherNumber> &
values);
655 template <
typename OtherNumber>
656 void add (
const std::vector<size_type> &indices,
657 const Vector<OtherNumber> &
values);
664 template <
typename OtherNumber>
665 void add (
const size_type n_elements,
666 const size_type *indices,
667 const OtherNumber *
values);
675 void add (
const Number s);
682 void add (
const Number a,
const Vector<Number> &V,
683 const Number b,
const Vector<Number> &W);
690 void add (
const Number a,
const Vector<Number> &V);
697 void sadd (
const Number s,
698 const Vector<Number> &V);
705 void sadd (
const Number s,
707 const Vector<Number> &V);
730 void scale (
const Vector<Number> &scaling_factors);
737 template <
typename Number2>
738 void scale (
const Vector<Number2> &scaling_factors);
745 void equ (
const Number a,
const Vector<Number> &u);
750 template <
typename Number2>
751 void equ (
const Number a,
const Vector<Number2> &u);
766 void ratio (
const Vector<Number> &a,
767 const Vector<Number> &b);
788 void print (
const char *format =
nullptr)
const;
796 void print (std::ostream &out,
797 const unsigned int precision = 3,
798 const bool scientific =
true,
799 const bool across =
true)
const;
811 const unsigned int width = 6,
812 const bool across =
true)
const;
838 template <
class Archive>
839 void save (Archive &ar,
const unsigned int version)
const;
845 template <
class Archive>
846 void load (Archive &ar,
const unsigned int version);
848 BOOST_SERIALIZATION_SPLIT_MEMBER()
886 size_type
size () const;
947 template <typename Number2> friend class
Vector;
966 void allocate(const size_type copy_n_el = 0);
984 template <
typename Number>
1000 template <
typename Number>
1001 template <
typename InputIterator>
1006 values (nullptr, &free)
1010 reinit (std::distance (first, last),
true);
1011 std::copy (first, last,
begin());
1016 template <
typename Number>
1022 values(nullptr, &
free)
1032 template <
typename Number>
1034 typename Vector<Number>::size_type
1041 template <
typename Number>
1044 (
const size_type)
const 1051 template <
typename Number>
1053 typename Vector<Number>::iterator
1056 return values.get();
1061 template <
typename Number>
1063 typename Vector<Number>::const_iterator
1066 return values.get();
1071 template <
typename Number>
1073 typename Vector<Number>::iterator
1076 return values.get() + vec_size;
1081 template <
typename Number>
1083 typename Vector<Number>::const_iterator
1086 return values.get() + vec_size;
1091 template <
typename Number>
1101 template <
typename Number>
1105 Assert (i<vec_size, ExcIndexRangeType<size_type>(i,0,vec_size));
1111 template <
typename Number>
1115 return operator()(i);
1120 template <
typename Number>
1124 return operator()(i);
1129 template <
typename Number>
1130 template <
typename OtherNumber>
1133 std::vector<OtherNumber> &values)
const 1135 for (size_type i = 0; i < indices.size(); ++i)
1136 values[i] =
operator()(indices[i]);
1141 template <
typename Number>
1142 template <
typename ForwardIterator,
typename OutputIterator>
1145 const ForwardIterator indices_end,
1146 OutputIterator values_begin)
const 1148 while (indices_begin != indices_end)
1150 *values_begin = operator()(*indices_begin);
1158 template <
typename Number>
1166 this->operator *= (Number(1.)/factor);
1172 template <
typename Number>
1173 template <
typename OtherNumber>
1177 const std::vector<OtherNumber> &values)
1179 Assert (indices.size() == values.size(),
1181 add (indices.size(), indices.data(), values.data());
1186 template <
typename Number>
1187 template <
typename OtherNumber>
1195 add (indices.size(), indices.data(), values.
values.get());
1200 template <
typename Number>
1201 template <
typename OtherNumber>
1205 const size_type *indices,
1206 const OtherNumber *values)
1208 for (size_type i=0; i<n_indices; ++i)
1212 ExcMessage(
"The given value is not finite but either infinite or Not A Number (NaN)"));
1214 this->values[indices[i]] += values[i];
1220 template <
typename Number>
1221 template <
typename Number2>
1226 return ! (*
this == v);
1231 template <
typename Number>
1239 template <
typename Number>
1250 template <
typename Number>
1262 template <
typename Number>
1263 template <
class Archive>
1271 ar &vec_size &max_vec_size ;
1272 ar &boost::serialization::make_array(values.get(), max_vec_size);
1277 template <
typename Number>
1278 template <
class Archive>
1288 ar &vec_size &max_vec_size ;
1291 ar &boost::serialization::make_array(values.get(), max_vec_size);
1310 template <
typename Number>
1321 template <
typename number>
1324 operator << (std::ostream &os, const Vector<number> &v)
1333 template <
typename number>
1336 operator << (LogStream &os, const Vector<number> &v)
1350 template <
typename Number>
1356 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 add_and_dot(const Number a, const Vector< Number > &V, const Vector< Number > &W)
Number operator[](const size_type i) const
void ratio(const Vector< Number > &a, const Vector< Number > &b)
bool operator!=(const Vector< Number2 > &v) const
virtual ~Vector()=default
void load(Archive &ar, const unsigned int version)
void sadd(const Number s, const Vector< Number > &V)
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
Number operator()(const size_type i) const
real_type linfty_norm() const
bool is_non_negative() const
void equ(const Number a, const Vector< Number > &u)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
Vector< Number > & operator=(const Number s)
bool is_finite(const double x)
void allocate(const size_type copy_n_el=0)
void add(const std::vector< size_type > &indices, const std::vector< OtherNumber > &values)
static ::ExceptionBase & ExcMessage(std::string arg1)
numbers::NumberTraits< Number >::real_type real_type
void swap(BlockIndices &u, BlockIndices &v)
bool in_local_range(const size_type global_index) const
void scale(const Vector< Number > &scaling_factors)
Vector< Number > & operator+=(const Vector< Number > &V)
unsigned int global_dof_index
#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)
std::unique_ptr< Number[], decltype(&free)> values
void print(const char *format=nullptr) const
Number operator*(const Vector< Number2 > &V) const
void swap(Vector< Number > &u, Vector< Number > &v)
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)
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