15#ifdef DEAL_II_WITH_TRILINOS
25# include <boost/io/ios_state.hpp>
28# include <Epetra_Export.h>
29# include <Epetra_Import.h>
30# include <Epetra_Vector.h>
42#ifdef DEAL_II_WITH_TRILINOS
58 vector.vector->Map().LID(
60# ifndef DEAL_II_WITH_64BIT_INDICES
64 vector.vector->Map().NumMyElements(),
65 vector.vector->Map().MinMyGID(),
66 vector.vector->Map().MaxMyGID()));
71 vector.vector->Map().NumMyElements(),
72 vector.vector->Map().MinMyGID64(),
73 vector.vector->Map().MaxMyGID64()));
77 return (*(vector.vector))[0][local_index];
88 ,
vector(new Epetra_FEVector(
89 Epetra_Map(0, 0, 0,
Utilities::Trilinos::comm_self())))
98 reinit(parallel_partitioning, communicator);
136 vector = std::make_unique<Epetra_FEVector>(
141 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
143 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
156 reinit(local, ghost, communicator,
false);
166 Epetra_Map map(0, 0, Epetra_MpiComm(MPI_COMM_SELF));
169 vector = std::make_unique<Epetra_FEVector>(map);
188 vector = std::make_unique<Epetra_FEVector>(map);
226 const Epetra_MpiComm *my_comm =
227 dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
228 const Epetra_MpiComm *v_comm =
229 dynamic_cast<const Epetra_MpiComm *
>(&v.
vector->Comm());
230 const bool same_communicators = my_comm !=
nullptr && v_comm !=
nullptr &&
231 my_comm->DataPtr() == v_comm->DataPtr();
232 if (!same_communicators ||
vector->Map().SameAs(v.
vector->Map()) ==
false)
234 vector = std::make_unique<Epetra_FEVector>(v.
vector->Map());
239 else if (omit_zeroing_entries ==
false)
246 ierr =
vector->PutScalar(0.0);
254 const Epetra_MpiComm *comm_ptr =
255 dynamic_cast<const Epetra_MpiComm *
>(&(v.
vector->Comm()));
280 size_type n_elements = 0, added_elements = 0, block_offset = 0;
282 n_elements += v.
block(block).vector->Map().NumMyElements();
283 std::vector<TrilinosWrappers::types::int_type> global_ids(n_elements, -1);
288 v.
block(block).trilinos_partitioner());
289 size_type vector_size = v.
block(block).vector->Map().NumMyElements();
290 for (
size_type i = 0; i < vector_size; ++i)
291 global_ids[added_elements++] = glob_elements[i] + block_offset;
294 block_offset += v.
block(block).size();
298 Epetra_Map new_map(v.
size(),
302 v.
block(0).trilinos_partitioner().Comm());
304 auto actual_vec = std::make_unique<Epetra_FEVector>(new_map);
309 v.
block(block).trilinos_vector().ExtractCopy(entries, 0);
310 entries += v.
block(block).vector->Map().NumMyElements();
313 if (import_data ==
true)
316 *actual_vec)) == v.
size(),
321 Epetra_Import data_exchange(
vector->Map(), actual_vec->Map());
323 const int ierr =
vector->Import(*actual_vec, data_exchange, Insert);
329 vector = std::move(actual_vec);
332 const Epetra_MpiComm *comm_ptr =
333 dynamic_cast<const Epetra_MpiComm *
>(&(
vector->Comm()));
348 const bool vector_writable)
352 if (vector_writable ==
false)
354 IndexSet parallel_partitioner = locally_owned_entries;
358 vector = std::make_unique<Epetra_FEVector>(map);
365 ExcMessage(
"A writable vector must not have ghost entries in "
366 "its parallel partitioning"));
368 if (
vector->Map().SameAs(map) ==
false)
369 vector = std::make_unique<Epetra_FEVector>(map);
372 const int ierr =
vector->PutScalar(0.);
376 IndexSet nonlocal_entries(ghost_entries);
380 Epetra_Map nonlocal_map =
383 std::make_unique<Epetra_MultiVector>(nonlocal_map, 1);
404 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
405 const bool make_ghosted,
406 const bool vector_writable)
410 Assert(partitioner->ghost_indices_initialized(),
411 ExcMessage(
"You asked to create a ghosted vector, but the "
412 "partitioner does not provide ghost indices."));
414 this->
reinit(partitioner->locally_owned_range(),
415 partitioner->ghost_indices(),
416 partitioner->get_mpi_communicator(),
421 this->
reinit(partitioner->locally_owned_range(),
422 partitioner->get_mpi_communicator());
432 ExcMessage(
"Vector is not constructed properly."));
436 const Epetra_MpiComm *my_comm =
437 dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
438 const Epetra_MpiComm *v_comm =
439 dynamic_cast<const Epetra_MpiComm *
>(&v.
vector->Comm());
440 const bool same_communicators = my_comm !=
nullptr && v_comm !=
nullptr &&
441 my_comm->DataPtr() == v_comm->DataPtr();
468 if (same_communicators && v.
vector->Map().SameAs(
vector->Map()))
481 (v.
vector->Map().UniqueGIDs() ||
vector->Map().UniqueGIDs()))
483 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
485 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
520 template <
typename number>
546 "Cannot find exchange information!"));
548 ExcMessage(
"The input vector has overlapping data, "
549 "which is not allowed."));
555 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
556 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
571 "Both vectors need to have the same size for import_elements() to work!"));
581 (*this)[idx] = rwv[idx];
586 (*this)[idx] += rwv[idx];
600 "Calling compress() is only useful if a vector "
601 "has been written into, but this is a vector with ghost "
602 "elements and consequently is read-only. It does "
603 "not make sense to call compress() for such "
622 "compress() can only be called with VectorOperation add, insert, or unknown"));
632 "The last operation on the Vector and the given last action in the compress() call do not agree!"));
641 const double double_mode = mode;
642 const Epetra_MpiComm *comm_ptr =
dynamic_cast<const Epetra_MpiComm *
>(
650 "Not all processors agree whether the last operation on "
651 "this vector was an addition or a set operation. This will "
652 "prevent the compress() operation from succeeding."));
658 const auto ierr =
vector->GlobalAssemble(mode);
688 if (trilinos_i == -1)
690# ifndef DEAL_II_WITH_64BIT_INDICES
693 vector->Map().NumMyElements(),
695 vector->Map().MaxMyGID()));
699 vector->Map().NumMyElements(),
700 vector->Map().MinMyGID64(),
701 vector->Map().MaxMyGID64()));
705 value = (*vector)[0][trilinos_i];
715 if (allow_different_maps ==
false)
723 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
725 vector->Import(*v.
vector, data_exchange, Epetra_AddLocalAlso);
737 if (
vector->Map().NumMyElements() != v.
vector->Map().NumMyElements())
741 for (
size_type i = 0; i < vector_size; ++i)
755 return (!(*
this == v));
765 const bool local_all_zero =
766 std::all_of(start_ptr,
779 const bool has_negative = std::any_of((*
vector)[0],
792 const unsigned int precision,
793 const bool scientific,
794 const bool across)
const
797 boost::io::ios_flags_saver restore_flags(out);
800 out.precision(precision);
802 out.setf(std::ios::scientific, std::ios::floatfield);
804 out.setf(std::ios::fixed, std::ios::floatfield);
807 if (
size() != vector_size)
809 auto global_id = [&](
const size_type index) {
812 out <<
"size:" <<
size()
813 <<
" locally_stored_size:" <<
vector->Map().NumMyElements()
814 <<
" :" << std::endl;
815 for (
size_type i = 0; i < vector_size; ++i)
816 out <<
"[" << global_id(i) <<
"]: " << (*(
vector))[0][i]
822 int leading_dimension;
823 int ierr =
vector->ExtractView(&val, &leading_dimension);
828 out <<
static_cast<double>(val[i]) <<
' ';
831 out <<
static_cast<double>(val[i]) << std::endl;
846 std::swap(
vector, v.vector);
861 return sizeof(*this) +
862 this->
vector->Map().NumMyElements() *
868# include "lac/trilinos_vector.inst"
virtual size_type size() const override
unsigned int n_blocks() const
BlockType & block(const unsigned int i)
bool is_ascending_and_one_to_one(const MPI_Comm communicator) const
Epetra_Map make_trilinos_map(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) const
void subtract_set(const IndexSet &other)
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
size_type size() const override
const IndexSet & get_stored_elements() const
types::global_dof_index size_type
void compress(VectorOperation::values operation)
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 import_elements(const LinearAlgebra::ReadWriteVector< double > &rwv, const VectorOperation::values operation)
MPI_Comm get_mpi_communicator() const
void swap(Vector &v) noexcept
void reinit(const Vector &v, const bool omit_zeroing_entries=false)
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
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
IndexSet locally_owned_elements() const
bool has_ghost_elements() const
std::pair< size_type, size_type > local_range() const
bool operator!=(const Vector &v) const
bool operator==(const Vector &v) const
Epetra_CombineMode last_action
size_type locally_owned_size() const
Vector & operator=(const TrilinosScalar s)
bool is_non_negative() const
std::size_t memory_consumption() const
const Epetra_CrsMatrix & trilinos_matrix() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
constexpr bool running_in_debug_mode()
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcGhostsPresent()
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
const bool IsBlockVector< VectorType >::value
void swap(BlockVector &u, BlockVector &v) noexcept
TrilinosWrappers::types::int_type global_length(const Epetra_MultiVector &vector)
int gid(const Epetra_BlockMap &map, int i)
TrilinosWrappers::types::int_type * my_global_elements(const Epetra_BlockMap &map)
TrilinosWrappers::types::int64_type n_global_elements(const Epetra_BlockMap &map)
T sum(const T &t, const MPI_Comm mpi_communicator)
bool logical_and(const bool t, const MPI_Comm mpi_communicator)
T logical_or(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
MinMaxAvg min_max_avg(const double my_value, const MPI_Comm mpi_communicator)
constexpr bool value_is_zero(const Number &value)