16 #ifndef dealii_trilinos_vector_h
17 #define dealii_trilinos_vector_h
22 #ifdef DEAL_II_WITH_TRILINOS
33 # include <Epetra_ConfigDefs.h>
38 # ifdef DEAL_II_WITH_MPI // only if MPI is installed
39 # include <Epetra_MpiComm.h>
42 # include <Epetra_SerialComm.h>
44 # include <Epetra_FEVector.h>
45 # include <Epetra_LocalMap.h>
46 # include <Epetra_Map.h>
55 template <
typename Number>
56 class ReadWriteVector;
100 class VectorReference
121 const VectorReference &
122 operator=(
const VectorReference &r)
const;
128 operator=(
const VectorReference &r);
133 const VectorReference &
139 const VectorReference &
145 const VectorReference &
151 const VectorReference &
157 const VectorReference &
171 <<
"An error with error number " << arg1
172 <<
" occurred while calling a Trilinos function");
194 # ifndef DEAL_II_WITH_64BIT_INDICES
199 gid(
const Epetra_BlockMap &map,
int i)
208 gid(
const Epetra_BlockMap &map,
int i)
451 const MPI_Comm &communicator = MPI_COMM_WORLD);
466 const MPI_Comm &communicator = MPI_COMM_WORLD);
484 const MPI_Comm &communicator = MPI_COMM_WORLD);
498 template <
typename Number>
500 const ::Vector<Number> &v,
501 const MPI_Comm & communicator = MPI_COMM_WORLD);
546 const bool omit_zeroing_entries =
false,
547 const bool allow_different_maps =
false);
573 const MPI_Comm &communicator = MPI_COMM_WORLD,
574 const bool omit_zeroing_entries =
false);
604 const MPI_Comm &communicator = MPI_COMM_WORLD,
605 const bool vector_writable =
false);
669 template <
typename Number>
763 std::pair<size_type, size_type>
963 std::vector<TrilinosScalar> & values)
const;
992 template <
typename ForwardIterator,
typename OutputIterator>
995 const ForwardIterator indices_end,
996 OutputIterator values_begin)
const;
1047 set(
const std::vector<size_type> & indices,
1048 const std::vector<TrilinosScalar> &values);
1055 set(
const std::vector<size_type> & indices,
1056 const ::Vector<TrilinosScalar> &values);
1073 add(
const std::vector<size_type> & indices,
1074 const std::vector<TrilinosScalar> &values);
1081 add(
const std::vector<size_type> & indices,
1082 const ::Vector<TrilinosScalar> &values);
1138 add(
const Vector &
V,
const bool allow_different_maps =
false);
1192 const Epetra_MultiVector &
1206 const Epetra_BlockMap &
1217 print(std::ostream & out,
1218 const unsigned int precision = 3,
1219 const bool scientific =
true,
1220 const bool across =
true)
const;
1262 <<
"An error with error number " << arg1
1263 <<
" occurred while calling a Trilinos function");
1274 <<
"You tried to access element " << arg1
1275 <<
" of a distributed vector, but this element is not stored "
1276 <<
"on the current processor. Note: There are " << arg2
1277 <<
" elements stored "
1278 <<
"on the current processor from within the range " << arg3
1279 <<
" through " << arg4
1280 <<
" but Trilinos vectors need not store contiguous "
1281 <<
"ranges on each processor, and not every element in "
1282 <<
"this range may in fact be stored locally.");
1357 inline VectorReference::VectorReference(
MPI::Vector & vector,
1364 inline const VectorReference &
1365 VectorReference::operator=(
const VectorReference &r)
const
1378 inline VectorReference &
1379 VectorReference::operator=(
const VectorReference &r)
1388 inline const VectorReference &
1391 vector.set(1, &index, &
value);
1397 inline const VectorReference &
1400 vector.add(1, &index, &
value);
1406 inline const VectorReference &
1410 vector.add(1, &index, &new_value);
1416 inline const VectorReference &
1420 vector.set(1, &index, &new_value);
1426 inline const VectorReference &
1430 vector.set(1, &index, &new_value);
1440 std::pair<size_type, size_type> range = local_range();
1442 return ((index >= range.first) && (index < range.second));
1450 Assert(owned_elements.size() == size(),
1452 "The locally owned elements have not been properly initialized!"
1453 " This happens for example if this object has been initialized"
1454 " with exactly one overlapping IndexSet."));
1455 return owned_elements;
1474 inline internal::VectorReference
1477 return internal::VectorReference(*
this, index);
1484 return operator()(index);
1491 return operator()(index);
1498 std::vector<TrilinosScalar> & values)
const
1500 for (
size_type i = 0; i < indices.size(); ++i)
1501 values[i] =
operator()(indices[i]);
1506 template <
typename ForwardIterator,
typename OutputIterator>
1509 const ForwardIterator indices_end,
1510 OutputIterator values_begin)
const
1512 while (indices_begin != indices_end)
1514 *values_begin = operator()(*indices_begin);
1525 return (*vector)[0];
1533 return (*vector)[0] + local_size();
1541 return (*vector)[0];
1549 return (*vector)[0] + local_size();
1555 Vector::set(
const std::vector<size_type> & indices,
1556 const std::vector<TrilinosScalar> &values)
1562 Assert(indices.size() == values.size(),
1565 set(indices.size(), indices.data(), values.data());
1571 Vector::set(
const std::vector<size_type> & indices,
1572 const ::Vector<TrilinosScalar> &values)
1578 Assert(indices.size() == values.size(),
1581 set(indices.size(), indices.data(), values.begin());
1595 if (last_action == Add)
1597 const int ierr = vector->GlobalAssemble(Add);
1601 if (last_action != Insert)
1602 last_action = Insert;
1604 for (
size_type i = 0; i < n_elements; ++i)
1608 vector->Map().LID(row);
1609 if (local_row != -1)
1610 (*vector)[0][local_row] = values[i];
1613 const int ierr = vector->ReplaceGlobalValues(1, &row, &values[i]);
1628 Vector::add(
const std::vector<size_type> & indices,
1629 const std::vector<TrilinosScalar> &values)
1634 Assert(indices.size() == values.size(),
1637 add(indices.size(), indices.data(), values.data());
1643 Vector::add(
const std::vector<size_type> & indices,
1644 const ::Vector<TrilinosScalar> &values)
1649 Assert(indices.size() == values.size(),
1652 add(indices.size(), indices.data(), values.begin());
1666 if (last_action != Add)
1668 if (last_action == Insert)
1670 const int ierr = vector->GlobalAssemble(Insert);
1676 for (
size_type i = 0; i < n_elements; ++i)
1681 if (local_row != -1)
1682 (*vector)[0][local_row] += values[i];
1683 else if (nonlocal_vector.get() ==
nullptr)
1685 const int ierr = vector->SumIntoGlobalValues(
1698 nonlocal_vector->Map().LID(
1702 "Attempted to write into off-processor vector entry "
1703 "that has not be specified as being writable upon "
1705 (*nonlocal_vector)[0][my_row] += values[i];
1716 # ifndef DEAL_II_WITH_64BIT_INDICES
1717 return vector->Map().MaxAllGID() + 1 - vector->Map().MinAllGID();
1719 return vector->Map().MaxAllGID64() + 1 - vector->Map().MinAllGID64();
1726 Vector::local_size()
const
1728 return vector->Map().NumMyElements();
1733 inline std::pair<Vector::size_type, Vector::size_type>
1734 Vector::local_range()
const
1736 # ifndef DEAL_II_WITH_64BIT_INDICES
1739 vector->Map().MaxMyGID() + 1;
1742 vector->Map().MinMyGID64();
1744 vector->Map().MaxMyGID64() + 1;
1748 end -
begin == vector->Map().NumMyElements(),
1750 "This function only makes sense if the elements that this "
1751 "vector stores on the current processor form a contiguous range. "
1752 "This does not appear to be the case for the current vector."));
1761 Assert(vector->Map().SameAs(vec.vector->Map()),
1762 ExcDifferentParallelPartitioning());
1767 const int ierr = vector->Dot(*(vec.vector), &result);
1790 const int ierr = vector->MeanValue(&
mean);
1802 const int ierr = vector->MinValue(&min_value);
1814 const int ierr = vector->MaxValue(&max_value);
1828 const int ierr = vector->Norm1(&
d);
1842 const int ierr = vector->Norm2(&
d);
1880 const int ierr = vector->NormInf(&
d);
1909 const int ierr = vector->Scale(a);
1926 const int ierr = vector->Scale(factor);
1938 Assert(vector->Map().SameAs(v.vector->Map()),
1939 ExcDifferentParallelPartitioning());
1941 const int ierr = vector->Update(1.0, *(v.vector), 1.0);
1953 Assert(vector->Map().SameAs(v.vector->Map()),
1954 ExcDifferentParallelPartitioning());
1956 const int ierr = vector->Update(-1.0, *(v.vector), 1.0);
1974 (*vector)[0][i] += s;
1985 Assert(local_size() == v.local_size(),
1990 const int ierr = vector->Update(a, *(v.vector), 1.);
2005 Assert(local_size() == v.local_size(),
2007 Assert(local_size() ==
w.local_size(),
2013 const int ierr = vector->Update(a, *(v.vector),
b, *(
w.vector), 1.);
2032 if (local_size() == v.local_size() && !v.has_ghost_elements())
2034 Assert(this->vector->Map().SameAs(v.vector->Map()) ==
true,
2035 ExcDifferentParallelPartitioning());
2036 const int ierr = vector->Update(1., *(v.vector), s);
2062 if (local_size() == v.local_size() && !v.has_ghost_elements())
2064 Assert(this->vector->Map().SameAs(v.vector->Map()) ==
true,
2065 ExcDifferentParallelPartitioning());
2066 const int ierr = vector->Update(a, *(v.vector), s);
2074 this->add(tmp,
true);
2086 Assert(local_size() == factors.local_size(),
2089 const int ierr = vector->Multiply(1.0, *(factors.vector), *vector, 0.0);
2104 if (vector->Map().SameAs(v.vector->Map()) ==
false)
2106 this->
sadd(0., a, v);
2111 int ierr = vector->Update(a, *v.vector, 0.0);
2120 inline const Epetra_MultiVector &
2121 Vector::trilinos_vector()
const
2123 return static_cast<const Epetra_MultiVector &
>(*vector);
2128 inline Epetra_FEVector &
2129 Vector::trilinos_vector()
2136 inline const Epetra_BlockMap &
2137 Vector::trilinos_partitioner()
const
2139 return vector->Map();
2145 Vector::get_mpi_communicator()
const
2149 # ifdef DEAL_II_WITH_MPI
2151 const Epetra_MpiComm *mpi_comm =
2152 dynamic_cast<const Epetra_MpiComm *
>(&vector->Map().Comm());
2153 comm = mpi_comm->Comm();
2157 comm = MPI_COMM_SELF;
2164 template <
typename number>
2166 const ::Vector<number> &v,
2171 owned_elements = parallel_partitioner;
2181 int ierr = vector->PutScalar(s);
2184 if (nonlocal_vector.get() !=
nullptr)
2186 ierr = nonlocal_vector->PutScalar(0.);
2203 namespace LinearOperatorImplementation
2216 template <
typename Matrix>
2220 bool omit_zeroing_entries)
2223 matrix.get_mpi_communicator(),
2224 omit_zeroing_entries);
2227 template <
typename Matrix>
2231 bool omit_zeroing_entries)
2234 matrix.get_mpi_communicator(),
2235 omit_zeroing_entries);
2256 #endif // DEAL_II_WITH_TRILINOS
2260 #endif // dealii_trilinos_vector_h