17#ifdef DEAL_II_WITH_TRILINOS
27# include <boost/io/ios_state.hpp>
30# include <Epetra_Export.h>
31# include <Epetra_Import.h>
32# include <Epetra_Vector.h>
55 vector.vector->Map().LID(
57# ifndef DEAL_II_WITH_64BIT_INDICES
61 vector.vector->Map().NumMyElements(),
62 vector.vector->Map().MinMyGID(),
63 vector.vector->Map().MaxMyGID()));
68 vector.vector->Map().NumMyElements(),
69 vector.vector->Map().MinMyGID64(),
70 vector.vector->Map().MaxMyGID64()));
74 return (*(vector.vector))[0][local_index];
85 ,
vector(new Epetra_FEVector(
86 Epetra_Map(0, 0, 0,
Utilities::Trilinos::comm_self())))
95 reinit(parallel_partitioning, communicator);
133 vector = std::make_unique<Epetra_FEVector>(
145 reinit(local, ghost, communicator,
false);
155 Epetra_Map map(0, 0, Epetra_MpiComm(MPI_COMM_SELF));
158 vector = std::make_unique<Epetra_FEVector>(map);
177 vector = std::make_unique<Epetra_FEVector>(map);
208 const bool omit_zeroing_entries,
209 const bool allow_different_maps)
216 if (allow_different_maps ==
false)
222 const Epetra_MpiComm *my_comm =
223 dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
224 const Epetra_MpiComm *v_comm =
225 dynamic_cast<const Epetra_MpiComm *
>(&v.
vector->Comm());
226 const bool same_communicators =
227 my_comm !=
nullptr && v_comm !=
nullptr &&
228 my_comm->DataPtr() == v_comm->DataPtr();
229 if (!same_communicators ||
232 vector = std::make_unique<Epetra_FEVector>(v.
vector->Map());
237 else if (omit_zeroing_entries ==
false)
244 ierr =
vector->PutScalar(0.0);
257 Assert(omit_zeroing_entries ==
false,
259 "It is not possible to exchange data with the "
260 "option 'omit_zeroing_entries' set, which would not write "
266 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
268 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
275 const Epetra_MpiComm *comm_ptr =
276 dynamic_cast<const Epetra_MpiComm *
>(&(v.
vector->Comm()));
301 size_type n_elements = 0, added_elements = 0, block_offset = 0;
303 n_elements += v.
block(block).vector->Map().NumMyElements();
304 std::vector<TrilinosWrappers::types::int_type> global_ids(n_elements, -1);
309 v.
block(block).trilinos_partitioner());
310 size_type vector_size = v.
block(block).vector->Map().NumMyElements();
311 for (
size_type i = 0; i < vector_size; ++i)
312 global_ids[added_elements++] = glob_elements[i] + block_offset;
315 block_offset += v.
block(block).size();
319 Epetra_Map new_map(v.
size(),
323 v.
block(0).trilinos_partitioner().Comm());
325 auto actual_vec = std::make_unique<Epetra_FEVector>(new_map);
330 v.
block(block).trilinos_vector().ExtractCopy(entries, 0);
331 entries += v.
block(block).vector->Map().NumMyElements();
334 if (import_data ==
true)
337 *actual_vec)) == v.
size(),
342 Epetra_Import data_exchange(
vector->Map(), actual_vec->Map());
344 const int ierr =
vector->Import(*actual_vec, data_exchange, Insert);
350 vector = std::move(actual_vec);
353 const Epetra_MpiComm *comm_ptr =
354 dynamic_cast<const Epetra_MpiComm *
>(&(
vector->Comm()));
369 const bool vector_writable)
373 if (vector_writable ==
false)
375 IndexSet parallel_partitioner = locally_owned_entries;
379 vector = std::make_unique<Epetra_FEVector>(map);
386 ExcMessage(
"A writable vector must not have ghost entries in "
387 "its parallel partitioning"));
389 if (
vector->Map().SameAs(map) ==
false)
390 vector = std::make_unique<Epetra_FEVector>(map);
393 const int ierr =
vector->PutScalar(0.);
397 IndexSet nonlocal_entries(ghost_entries);
401 Epetra_Map nonlocal_map =
404 std::make_unique<Epetra_MultiVector>(nonlocal_map, 1);
425 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
426 const bool make_ghosted,
427 const bool vector_writable)
431 Assert(partitioner->ghost_indices_initialized(),
432 ExcMessage(
"You asked to create a ghosted vector, but the "
433 "partitioner does not provide ghost indices."));
435 this->
reinit(partitioner->locally_owned_range(),
436 partitioner->ghost_indices(),
437 partitioner->get_mpi_communicator(),
442 this->
reinit(partitioner->locally_owned_range(),
443 partitioner->get_mpi_communicator());
453 ExcMessage(
"Vector is not constructed properly."));
457 const Epetra_MpiComm *my_comm =
458 dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
459 const Epetra_MpiComm *v_comm =
460 dynamic_cast<const Epetra_MpiComm *
>(&v.
vector->Comm());
461 const bool same_communicators = my_comm !=
nullptr && v_comm !=
nullptr &&
462 my_comm->DataPtr() == v_comm->DataPtr();
489 if (same_communicators && v.
vector->Map().SameAs(
vector->Map()))
502 (v.
vector->Map().UniqueGIDs() ||
vector->Map().UniqueGIDs()))
536 template <
typename number>
562 "Cannot find exchange information!"));
564 ExcMessage(
"The input vector has overlapping data, "
565 "which is not allowed."));
571 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
572 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
587 "Both vectors need to have the same size for import_elements() to work!"));
597 (*this)[idx] = rwv[idx];
602 (*this)[idx] += rwv[idx];
616 "Calling compress() is only useful if a vector "
617 "has been written into, but this is a vector with ghost "
618 "elements and consequently is read-only. It does "
619 "not make sense to call compress() for such "
638 "compress() can only be called with VectorOperation add, insert, or unknown"));
648 "The last operation on the Vector and the given last action in the compress() call do not agree!"));
657 const double double_mode = mode;
658 const Epetra_MpiComm *comm_ptr =
dynamic_cast<const Epetra_MpiComm *
>(
666 "Not all processors agree whether the last operation on "
667 "this vector was an addition or a set operation. This will "
668 "prevent the compress() operation from succeeding."));
674 const auto ierr =
vector->GlobalAssemble(mode);
704 if (trilinos_i == -1)
706# ifndef DEAL_II_WITH_64BIT_INDICES
709 vector->Map().NumMyElements(),
711 vector->Map().MaxMyGID()));
715 vector->Map().NumMyElements(),
716 vector->Map().MinMyGID64(),
717 vector->Map().MaxMyGID64()));
721 value = (*vector)[0][trilinos_i];
731 if (allow_different_maps ==
false)
739 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
741 vector->Import(*v.
vector, data_exchange, Epetra_AddLocalAlso);
753 if (
vector->Map().NumMyElements() != v.
vector->Map().NumMyElements())
757 for (
size_type i = 0; i < vector_size; ++i)
771 return (!(*
this == v));
783 *eptr = start_ptr +
vector->Map().NumMyElements();
784 unsigned int flag = 0;
797 const Epetra_MpiComm *mpi_comm =
798 dynamic_cast<const Epetra_MpiComm *
>(&
vector->Map().Comm());
801 return num_nonzero == 0;
813 *eptr = start_ptr +
vector->Map().NumMyElements();
814 unsigned int flag = 0;
827 const auto max_n_negative =
829 return max_n_negative == 0;
836 const unsigned int precision,
837 const bool scientific,
838 const bool across)
const
841 boost::io::ios_flags_saver restore_flags(out);
844 out.precision(precision);
846 out.setf(std::ios::scientific, std::ios::floatfield);
848 out.setf(std::ios::fixed, std::ios::floatfield);
851 if (
size() != vector_size)
853 auto global_id = [&](
const size_type index) {
856 out <<
"size:" <<
size()
857 <<
" locally_owned_size:" <<
vector->Map().NumMyElements() <<
" :"
859 for (
size_type i = 0; i < vector_size; ++i)
860 out <<
"[" << global_id(i) <<
"]: " << (*(
vector))[0][i]
866 int leading_dimension;
867 int ierr =
vector->ExtractView(&val, &leading_dimension);
872 out <<
static_cast<double>(val[i]) <<
' ';
875 out <<
static_cast<double>(val[i]) << std::endl;
890 std::swap(
vector, v.vector);
905 return sizeof(*this) +
906 this->
vector->Map().NumMyElements() *
912# 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
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
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
bool operator!=(const Vector &v) const
bool operator==(const Vector &v) const
Epetra_CombineMode last_action
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)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
T max(const T &t, const MPI_Comm mpi_communicator)
MinMaxAvg min_max_avg(const double my_value, const MPI_Comm mpi_communicator)