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
59 vector.vector->Map().LID(
61# ifndef DEAL_II_WITH_64BIT_INDICES
65 vector.vector->Map().NumMyElements(),
66 vector.vector->Map().MinMyGID(),
67 vector.vector->Map().MaxMyGID()));
72 vector.vector->Map().NumMyElements(),
73 vector.vector->Map().MinMyGID64(),
74 vector.vector->Map().MaxMyGID64()));
78 return (*(vector.vector))[0][local_index];
89 , vector(new Epetra_FEVector(
90 Epetra_Map(0, 0, 0,
Utilities::Trilinos::comm_self())))
99 reinit(parallel_partitioning, communicator);
137 vector = std::make_unique<Epetra_FEVector>(
142 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
144 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
157 reinit(local, ghost, communicator,
false);
167 Epetra_Map map(0, 0, Epetra_MpiComm(MPI_COMM_SELF));
170 vector = std::make_unique<Epetra_FEVector>(map);
189 vector = std::make_unique<Epetra_FEVector>(map);
227 const Epetra_MpiComm *my_comm =
228 dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
229 const Epetra_MpiComm *v_comm =
230 dynamic_cast<const Epetra_MpiComm *
>(&v.
vector->Comm());
231 const bool same_communicators = my_comm !=
nullptr && v_comm !=
nullptr &&
232 my_comm->DataPtr() == v_comm->DataPtr();
233 if (!same_communicators ||
vector->Map().SameAs(v.
vector->Map()) ==
false)
235 vector = std::make_unique<Epetra_FEVector>(v.
vector->Map());
240 else if (omit_zeroing_entries ==
false)
247 ierr =
vector->PutScalar(0.0);
255 const Epetra_MpiComm *comm_ptr =
256 dynamic_cast<const Epetra_MpiComm *
>(&(v.
vector->Comm()));
281 size_type n_elements = 0, added_elements = 0, block_offset = 0;
283 n_elements += v.
block(block).vector->Map().NumMyElements();
284 std::vector<TrilinosWrappers::types::int_type> global_ids(n_elements, -1);
289 v.
block(block).trilinos_partitioner());
290 size_type vector_size = v.
block(block).vector->Map().NumMyElements();
291 for (
size_type i = 0; i < vector_size; ++i)
292 global_ids[added_elements++] = glob_elements[i] + block_offset;
295 block_offset += v.
block(block).size();
299 Epetra_Map new_map(v.
size(),
303 v.
block(0).trilinos_partitioner().Comm());
305 auto actual_vec = std::make_unique<Epetra_FEVector>(new_map);
310 v.
block(block).trilinos_vector().ExtractCopy(entries, 0);
311 entries += v.
block(block).vector->Map().NumMyElements();
314 if (import_data ==
true)
317 *actual_vec)) == v.
size(),
322 Epetra_Import data_exchange(
vector->Map(), actual_vec->Map());
324 const int ierr =
vector->Import(*actual_vec, data_exchange, Insert);
330 vector = std::move(actual_vec);
333 const Epetra_MpiComm *comm_ptr =
334 dynamic_cast<const Epetra_MpiComm *
>(&(
vector->Comm()));
349 const bool vector_writable)
353 if (vector_writable ==
false)
355 IndexSet parallel_partitioner = locally_owned_entries;
359 vector = std::make_unique<Epetra_FEVector>(map);
366 ExcMessage(
"A writable vector must not have ghost entries in "
367 "its parallel partitioning"));
369 if (
vector->Map().SameAs(map) ==
false)
370 vector = std::make_unique<Epetra_FEVector>(map);
373 const int ierr =
vector->PutScalar(0.);
377 IndexSet nonlocal_entries(ghost_entries);
381 Epetra_Map nonlocal_map =
384 std::make_unique<Epetra_MultiVector>(nonlocal_map, 1);
405 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
406 const bool make_ghosted,
407 const bool vector_writable)
411 Assert(partitioner->ghost_indices_initialized(),
412 ExcMessage(
"You asked to create a ghosted vector, but the "
413 "partitioner does not provide ghost indices."));
415 this->
reinit(partitioner->locally_owned_range(),
416 partitioner->ghost_indices(),
417 partitioner->get_mpi_communicator(),
422 this->
reinit(partitioner->locally_owned_range(),
423 partitioner->get_mpi_communicator());
433 ExcMessage(
"Vector is not constructed properly."));
437 const Epetra_MpiComm *my_comm =
438 dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
439 const Epetra_MpiComm *v_comm =
440 dynamic_cast<const Epetra_MpiComm *
>(&v.
vector->Comm());
441 const bool same_communicators = my_comm !=
nullptr && v_comm !=
nullptr &&
442 my_comm->DataPtr() == v_comm->DataPtr();
469 if (same_communicators && v.
vector->Map().SameAs(
vector->Map()))
482 (v.
vector->Map().UniqueGIDs() ||
vector->Map().UniqueGIDs()))
484 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
486 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
521 template <
typename number>
547 "Cannot find exchange information!"));
549 ExcMessage(
"The input vector has overlapping data, "
550 "which is not allowed."));
556 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
557 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
572 "Both vectors need to have the same size for import_elements() to work!"));
582 (*
this)[idx] = rwv[idx];
587 (*
this)[idx] += rwv[idx];
601 "Calling compress() is only useful if a vector "
602 "has been written into, but this is a vector with ghost "
603 "elements and consequently is read-only. It does "
604 "not make sense to call compress() for such "
623 "compress() can only be called with VectorOperation add, insert, or unknown"));
633 "The last operation on the Vector and the given last action in the compress() call do not agree!"));
642 const double double_mode = mode;
643 const Epetra_MpiComm *comm_ptr =
dynamic_cast<const Epetra_MpiComm *
>(
651 "Not all processors agree whether the last operation on "
652 "this vector was an addition or a set operation. This will "
653 "prevent the compress() operation from succeeding."));
659 const auto ierr =
vector->GlobalAssemble(mode);
689 if (trilinos_i == -1)
691# ifndef DEAL_II_WITH_64BIT_INDICES
694 vector->Map().NumMyElements(),
696 vector->Map().MaxMyGID()));
700 vector->Map().NumMyElements(),
701 vector->Map().MinMyGID64(),
702 vector->Map().MaxMyGID64()));
706 value = (*vector)[0][trilinos_i];
716 if (allow_different_maps ==
false)
724 Epetra_Import data_exchange(
vector->Map(), v.
vector->Map());
726 vector->Import(*v.
vector, data_exchange, Epetra_AddLocalAlso);
738 if (
vector->Map().NumMyElements() != v.
vector->Map().NumMyElements())
742 for (
size_type i = 0; i < vector_size; ++i)
756 return (!(*
this == v));
766 const bool local_all_zero =
767 std::all_of(start_ptr,
769 numbers::value_is_zero<TrilinosScalar>);
780 const bool has_negative = std::any_of((*
vector)[0],
793 const unsigned int precision,
794 const bool scientific,
795 const bool across)
const
798 boost::io::ios_flags_saver restore_flags(out);
801 out.precision(precision);
803 out.setf(std::ios::scientific, std::ios::floatfield);
805 out.setf(std::ios::fixed, std::ios::floatfield);
808 if (
size() != vector_size)
810 auto global_id = [&](
const size_type index) {
813 out <<
"size:" <<
size()
814 <<
" locally_stored_size:" <<
vector->Map().NumMyElements()
815 <<
" :" << std::endl;
816 for (
size_type i = 0; i < vector_size; ++i)
817 out <<
"[" << global_id(i) <<
"]: " << (*(
vector))[0][i]
823 int leading_dimension;
824 int ierr =
vector->ExtractView(&val, &leading_dimension);
829 out <<
static_cast<double>(val[i]) <<
' ';
832 out <<
static_cast<double>(val[i]) << std::endl;
844 std::swap(last_action, v.last_action);
845 std::swap(compressed, v.compressed);
846 std::swap(has_ghosts, v.has_ghosts);
847 std::swap(vector, v.vector);
848 std::swap(nonlocal_vector, v.nonlocal_vector);
849 std::swap(owned_elements, v.owned_elements);
862 return sizeof(*this) +
863 this->
vector->Map().NumMyElements() *
869# 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
size_type n_elements() const
void set_size(const size_type size)
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
void compress(VectorOperation::values operation)
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)
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)