15#ifndef dealii_trilinos_vector_h
16#define dealii_trilinos_vector_h
21#ifdef DEAL_II_WITH_TRILINOS
32# include <Epetra_ConfigDefs.h>
33# include <Epetra_FEVector.h>
34# include <Epetra_LocalMap.h>
35# include <Epetra_Map.h>
36# include <Epetra_MpiComm.h>
49 template <
typename Number>
50 class ReadWriteVector;
108 VectorReference(
MPI::Vector &vector,
const size_type index);
114 VectorReference(
const VectorReference &) =
default;
127 const VectorReference &
128 operator=(
const VectorReference &r)
const;
134 operator=(
const VectorReference &r);
139 const VectorReference &
145 const VectorReference &
151 const VectorReference &
157 const VectorReference &
163 const VectorReference &
177 <<
"An error with error number " << arg1
178 <<
" occurred while calling a Trilinos function");
189 const size_type index;
193 friend class ::TrilinosWrappers::MPI::Vector;
200# ifndef DEAL_II_WITH_64BIT_INDICES
205 gid(
const Epetra_BlockMap &map,
int i)
214 gid(
const Epetra_BlockMap &map,
int i)
454 const MPI_Comm communicator = MPI_COMM_WORLD);
469 const MPI_Comm communicator = MPI_COMM_WORLD);
487 const MPI_Comm communicator = MPI_COMM_WORLD);
501 template <
typename Number>
503 const ::Vector<Number> &v,
504 const MPI_Comm communicator = MPI_COMM_WORLD);
553 const bool omit_zeroing_entries =
false,
554 const bool allow_different_maps =
false);
580 const MPI_Comm communicator = MPI_COMM_WORLD,
581 const bool omit_zeroing_entries =
false);
619 const IndexSet &locally_relevant_or_ghost_entries,
620 const MPI_Comm communicator = MPI_COMM_WORLD,
621 const bool vector_writable =
false);
635 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
636 const bool make_ghosted =
true,
637 const bool vector_writable =
false);
725 template <
typename Number>
748 const ::TrilinosWrappers::SparseMatrix &matrix,
824 std::pair<size_type, size_type>
1027 std::vector<TrilinosScalar> &values)
const;
1064 template <
typename ForwardIterator,
typename OutputIterator>
1067 const ForwardIterator indices_end,
1068 OutputIterator values_begin)
const;
1117 set(
const std::vector<size_type> &indices,
1118 const std::vector<TrilinosScalar> &values);
1125 set(
const std::vector<size_type> &indices,
1126 const ::Vector<TrilinosScalar> &values);
1143 add(
const std::vector<size_type> &indices,
1144 const std::vector<TrilinosScalar> &values);
1151 add(
const std::vector<size_type> &indices,
1152 const ::Vector<TrilinosScalar> &values);
1208 add(
const Vector &V,
const bool allow_different_maps =
false);
1262 const Epetra_MultiVector &
1276 const Epetra_BlockMap &
1287 print(std::ostream &out,
1288 const unsigned int precision = 3,
1289 const bool scientific =
true,
1290 const bool across =
true)
const;
1331 <<
"An error with error number " << arg1
1332 <<
" occurred while calling a Trilinos function");
1343 <<
"You are trying to access element " << arg1
1344 <<
" of a distributed vector, but this element is not stored "
1345 <<
"on the current processor. Note: There are " << arg2
1346 <<
" elements stored "
1347 <<
"on the current processor from within the range [" << arg3 <<
','
1348 << arg4 <<
"] but Trilinos vectors need not store contiguous "
1349 <<
"ranges on each processor, and not every element in "
1350 <<
"this range may in fact be stored locally."
1352 <<
"A common source for this kind of problem is that you "
1353 <<
"are passing a 'fully distributed' vector into a function "
1354 <<
"that needs read access to vector elements that correspond "
1355 <<
"to degrees of freedom on ghost cells (or at least to "
1356 <<
"'locally active' degrees of freedom that are not also "
1357 <<
"'locally owned'). You need to pass a vector that has these "
1358 <<
"elements as ghost entries.");
1432 inline VectorReference::VectorReference(
MPI::Vector &vector,
1433 const size_type index)
1439 inline const VectorReference &
1440 VectorReference::operator=(
const VectorReference &r)
const
1453 inline VectorReference &
1454 VectorReference::operator=(
const VectorReference &r)
1463 inline const VectorReference &
1466 vector.set(1, &index, &value);
1472 inline const VectorReference &
1475 vector.add(1, &index, &value);
1481 inline const VectorReference &
1485 vector.add(1, &index, &new_value);
1491 inline const VectorReference &
1495 vector.set(1, &index, &new_value);
1501 inline const VectorReference &
1505 vector.set(1, &index, &new_value);
1515 std::pair<size_type, size_type> range =
local_range();
1517 return ((index >= range.first) && (index < range.second));
1527 "The locally owned elements have not been properly initialized!"
1528 " This happens for example if this object has been initialized"
1529 " with exactly one overlapping IndexSet."));
1549 inline internal::VectorReference
1557 inline internal::VectorReference
1575 std::vector<TrilinosScalar> &values)
const
1577 for (
size_type i = 0; i < indices.size(); ++i)
1578 values[i] =
operator()(indices[i]);
1589 for (
unsigned int i = 0; i < indices.
size(); ++i)
1592 elements[i] = (*this)[indices[i]];
1598 template <
typename ForwardIterator,
typename OutputIterator>
1601 const ForwardIterator indices_end,
1602 OutputIterator values_begin)
const
1604 while (indices_begin != indices_end)
1647 Vector::set(
const std::vector<size_type> &indices,
1648 const std::vector<TrilinosScalar> &values)
1656 set(indices.size(), indices.data(),
values.data());
1662 Vector::set(
const std::vector<size_type> &indices,
1663 const ::Vector<TrilinosScalar> &values)
1671 set(indices.size(), indices.data(),
values.begin());
1678 const size_type *indices,
1687 const int ierr =
vector->GlobalAssemble(Add);
1694 for (
size_type i = 0; i < n_elements; ++i)
1699 if (local_row != -1)
1700 (*vector)[0][local_row] =
values[i];
1703 const int ierr =
vector->ReplaceGlobalValues(1, &row, &values[i]);
1718 Vector::add(
const std::vector<size_type> &indices,
1719 const std::vector<TrilinosScalar> &values)
1726 add(indices.size(), indices.data(),
values.data());
1732 Vector::add(
const std::vector<size_type> &indices,
1733 const ::Vector<TrilinosScalar> &values)
1740 add(indices.size(), indices.data(),
values.begin());
1747 const size_type *indices,
1758 const int ierr =
vector->GlobalAssemble(Insert);
1764 for (
size_type i = 0; i < n_elements; ++i)
1769 if (local_row != -1)
1770 (*vector)[0][local_row] +=
values[i];
1773 const int ierr =
vector->SumIntoGlobalValues(
1790 "Attempted to write into off-processor vector entry "
1791 "that has not be specified as being writable upon "
1793 (*nonlocal_vector)[0][my_row] +=
values[i];
1804# ifndef DEAL_II_WITH_64BIT_INDICES
1805 return vector->Map().MaxAllGID() + 1 -
vector->Map().MinAllGID();
1807 return vector->Map().MaxAllGID64() + 1 -
vector->Map().MinAllGID64();
1821 inline std::pair<Vector::size_type, Vector::size_type>
1824# ifndef DEAL_II_WITH_64BIT_INDICES
1827 vector->Map().MaxMyGID() + 1;
1830 vector->Map().MinMyGID64();
1832 vector->Map().MaxMyGID64() + 1;
1838 "This function only makes sense if the elements that this "
1839 "vector stores on the current processor form a contiguous range. "
1840 "This does not appear to be the case for the current vector."));
1856 const int ierr =
vector->Dot(*(vec.vector), &result);
1879 const int ierr =
vector->MeanValue(&mean);
1891 const int ierr =
vector->MinValue(&min_value);
1903 const int ierr =
vector->MaxValue(&max_value);
1917 const int ierr =
vector->Norm1(&d);
1931 const int ierr =
vector->Norm2(&d);
1969 const int ierr =
vector->NormInf(&d);
1998 const int ierr =
vector->Scale(a);
2015 const int ierr =
vector->Scale(factor);
2030 const int ierr =
vector->Update(1.0, *(v.vector), 1.0);
2045 const int ierr =
vector->Update(-1.0, *(v.vector), 1.0);
2078 const int ierr =
vector->Update(a, *(v.vector), 1.);
2099 const int ierr =
vector->Update(a, *(v.vector), b, *(
w.vector), 1.);
2121 Assert(this->
vector->Map().SameAs(v.vector->Map()) ==
true,
2123 const int ierr =
vector->Update(1., *(v.vector), s);
2152 Assert(this->
vector->Map().SameAs(v.vector->Map()) ==
true,
2154 const int ierr =
vector->Update(a, *(v.vector), s);
2162 this->
add(tmp,
true);
2176 const int ierr =
vector->Multiply(1.0, *(factors.vector), *
vector, 0.0);
2191 if (
vector->Map().SameAs(v.vector->Map()) ==
false)
2193 this->
sadd(0., a, v);
2198 int ierr =
vector->Update(a, *v.vector, 0.0);
2207 inline const Epetra_MultiVector &
2210 return static_cast<const Epetra_MultiVector &
>(*vector);
2215 inline Epetra_FEVector &
2223 inline const Epetra_BlockMap &
2234 const Epetra_MpiComm *mpi_comm =
2235 dynamic_cast<const Epetra_MpiComm *
>(&
vector->Map().Comm());
2236 return mpi_comm->Comm();
2241 template <
typename number>
2243 const ::Vector<number> &v,
2258 int ierr =
vector->PutScalar(s);
2280 namespace LinearOperatorImplementation
2293 template <
typename Matrix>
2297 bool omit_zeroing_entries)
2299 v.
reinit(matrix.locally_owned_range_indices(),
2300 matrix.get_mpi_communicator(),
2301 omit_zeroing_entries);
2304 template <
typename Matrix>
2308 bool omit_zeroing_entries)
2310 v.
reinit(matrix.locally_owned_domain_indices(),
2311 matrix.get_mpi_communicator(),
2312 omit_zeroing_entries);
size_type n_elements() const
Epetra_Map make_trilinos_map(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) const
real_type l1_norm() const
Vector & operator/=(const TrilinosScalar factor)
void compress(VectorOperation::values operation)
Vector(const IndexSet ¶llel_partitioning, const ::Vector< Number > &v, const MPI_Comm communicator=MPI_COMM_WORLD)
void sadd(const TrilinosScalar s, const Vector &V)
TrilinosScalar mean_value() const
void add(const size_type n_elements, const size_type *indices, const TrilinosScalar *values)
VectorTraits::size_type size_type
void add(const std::vector< size_type > &indices, const std::vector< TrilinosScalar > &values)
std::unique_ptr< Epetra_MultiVector > nonlocal_vector
void add(const TrilinosScalar s)
void import_elements(const LinearAlgebra::ReadWriteVector< double > &rwv, const VectorOperation::values operation)
void update_ghost_values() const
MPI_Comm get_mpi_communicator() const
void swap(Vector &v) noexcept
const Epetra_BlockMap & trilinos_partitioner() const
reference operator()(const size_type index)
void import_nonlocal_data_for_fe(const ::TrilinosWrappers::SparseMatrix &matrix, const Vector &vector)
std::unique_ptr< Epetra_FEVector > vector
size_type size() const override
bool in_local_range(const size_type index) const
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
friend class internal::VectorReference
real_type lp_norm(const TrilinosScalar p) const
IndexSet locally_owned_elements() const
Vector & operator-=(const Vector &V)
real_type l2_norm() const
Vector & operator+=(const Vector &V)
const Epetra_MultiVector & trilinos_vector() const
const internal::VectorReference const_reference
void reinit(const Vector &v, const bool omit_zeroing_entries=false, const bool allow_different_maps=false)
bool has_ghost_elements() const
std::pair< size_type, size_type > local_range() const
real_type norm_sqr() const
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< TrilinosScalar > &values) const
bool operator!=(const Vector &v) const
~Vector() override=default
virtual void extract_subvector_to(const ArrayView< const size_type > &indices, const ArrayView< TrilinosScalar > &elements) const override
Epetra_FEVector & trilinos_vector()
const_iterator begin() const
real_type linfty_norm() const
internal::VectorReference reference
TrilinosScalar min() const
void set(const std::vector< size_type > &indices, const ::Vector< TrilinosScalar > &values)
void set(const size_type n_elements, const size_type *indices, const TrilinosScalar *values)
void scale(const Vector &scaling_factors)
void equ(const TrilinosScalar a, const Vector &V)
bool operator==(const Vector &v) const
void sadd(const TrilinosScalar s, const TrilinosScalar a, const Vector &V)
Epetra_CombineMode last_action
reference operator[](const size_type index)
const value_type * const_iterator
TrilinosScalar value_type
void swap(Vector &u, Vector &v) noexcept
size_type locally_owned_size() const
TrilinosScalar operator[](const size_type index) const
TrilinosScalar add_and_dot(const TrilinosScalar a, const Vector &V, const Vector &W)
Vector & operator=(const TrilinosScalar s)
Vector & operator*=(const TrilinosScalar factor)
bool is_non_negative() const
TrilinosScalar operator*(const Vector &vec) const
void add(const std::vector< size_type > &indices, const ::Vector< TrilinosScalar > &values)
void extract_subvector_to(ForwardIterator indices_begin, const ForwardIterator indices_end, OutputIterator values_begin) const
std::size_t memory_consumption() const
void add(const TrilinosScalar a, const Vector &V, const TrilinosScalar b, const Vector &W)
void add(const TrilinosScalar a, const Vector &V)
void set(const std::vector< size_type > &indices, const std::vector< TrilinosScalar > &values)
TrilinosScalar max() const
Vector & operator=(const ::Vector< Number > &v)
const_iterator end() const
::types::global_dof_index size_type
typename numbers::NumberTraits< Number >::real_type real_type
bool has_ghost_elements() const
const value_type * const_iterator
virtual size_type size() const override
size_type locally_owned_size() const
static void reinit_domain_vector(const Matrix &matrix, TrilinosWrappers::MPI::Vector &v, bool omit_zeroing_entries)
static void reinit_range_vector(const Matrix &matrix, TrilinosWrappers::MPI::Vector &v, bool omit_zeroing_entries)
#define DEAL_II_DEPRECATED
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define DeclException0(Exception0)
static ::ExceptionBase & ExcGhostsPresent()
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
static ::ExceptionBase & ExcDifferentParallelPartitioning()
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
#define Assert(cond, exc)
#define AssertIsFinite(number)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcTrilinosError(int arg1)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
double norm(const FEValuesBase< dim > &fe, const ArrayView< const std::vector< Tensor< 1, dim > > > &Du)
Tensor< 2, dim, Number > w(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
int gid(const Epetra_BlockMap &map, int i)
T sum(const T &t, const MPI_Comm mpi_communicator)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
unsigned int global_dof_index