16 #include <deal.II/lac/trilinos_vector.h> 18 #ifdef DEAL_II_WITH_TRILINOS 20 # include <deal.II/base/mpi.h> 21 # include <deal.II/base/std_cxx14/memory.h> 22 # include <deal.II/lac/trilinos_sparse_matrix.h> 23 # include <deal.II/lac/trilinos_parallel_block_vector.h> 24 # include <deal.II/lac/trilinos_index_access.h> 26 # include <Epetra_Import.h> 27 # include <Epetra_Export.h> 28 # include <Epetra_Vector.h> 30 # include <boost/io/ios_state.hpp> 35 DEAL_II_NAMESPACE_OPEN
41 VectorReference::operator TrilinosScalar ()
const 43 Assert (index < vector.size(),
50 const TrilinosWrappers::types::int_type local_index =
51 vector.vector->Map().LID(static_cast<TrilinosWrappers::types::int_type>(index));
54 vector.vector->Map().MinMyGID(),
55 vector.vector->Map().MaxMyGID()));
58 return (*(vector.vector))[0][local_index];
70 vector(new Epetra_FEVector(Epetra_Map(0,0,0,
Utilities::Trilinos::comm_self())))
76 const MPI_Comm &communicator)
79 reinit (parallel_partitioning, communicator);
89 vector = std_cxx14::make_unique<Epetra_FEVector>(*v.
vector);
107 const MPI_Comm &communicator)
115 vector = std_cxx14::make_unique<Epetra_FEVector>
124 const MPI_Comm &communicator)
127 reinit(local, ghost, communicator,
false);
137 #ifdef DEAL_II_WITH_MPI 138 Epetra_Map map (0, 0, Epetra_MpiComm(MPI_COMM_SELF));
140 Epetra_Map map (0, 0, Epetra_SerialComm());
144 vector = std_cxx14::make_unique<Epetra_FEVector>(map);
152 const MPI_Comm &communicator,
160 vector = std_cxx14::make_unique<Epetra_FEVector>(map);
177 const size_type n_elements_global
190 const bool omit_zeroing_entries,
191 const bool allow_different_maps)
198 if (allow_different_maps ==
false)
204 #ifdef DEAL_II_WITH_MPI 205 const Epetra_MpiComm *my_comm =
dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
206 const Epetra_MpiComm *v_comm =
dynamic_cast<const Epetra_MpiComm *
>(&v.
vector->Comm());
207 const bool same_communicators = my_comm !=
nullptr && v_comm !=
nullptr &&
208 my_comm->DataPtr() == v_comm->DataPtr();
210 const bool same_communicators =
true;
212 if (!same_communicators ||
vector->Map().SameAs(v.
vector->Map()) ==
false)
214 vector = std_cxx14::make_unique<Epetra_FEVector>(v.
vector->Map());
219 else if (omit_zeroing_entries ==
false)
228 ierr =
vector->PutScalar(0.0);
241 Assert (omit_zeroing_entries ==
false,
242 ExcMessage (
"It is not possible to exchange data with the " 243 "option 'omit_zeroing_entries' set, which would not write " 249 Epetra_Import data_exchange (
vector->Map(), v.
vector->Map());
251 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
256 #if defined(DEBUG) && defined(DEAL_II_WITH_MPI) 257 const Epetra_MpiComm *comm_ptr
258 =
dynamic_cast<const Epetra_MpiComm *
>(&(v.
vector->Comm()));
260 const size_type n_elements_global
270 const bool import_data)
284 size_type n_elements = 0, added_elements = 0, block_offset = 0;
285 for (size_type block=0; block<v.
n_blocks(); ++block)
286 n_elements += v.
block(block).local_size();
287 std::vector<TrilinosWrappers::types::int_type> global_ids (n_elements, -1);
288 for (size_type block=0; block<v.
n_blocks(); ++block)
290 TrilinosWrappers::types::int_type *glob_elements =
292 for (size_type i=0; i<v.
block(block).local_size(); ++i)
293 global_ids[added_elements++] = glob_elements[i] + block_offset;
296 block_offset += v.
block(block).size();
300 Epetra_Map new_map (v.
size(), n_elements, global_ids.data(), 0,
301 v.
block(0).vector_partitioner().Comm());
303 auto actual_vec = std_cxx14::make_unique<Epetra_FEVector>(new_map);
305 TrilinosScalar *entries = (*actual_vec)[0];
306 for (size_type block=0; block<v.
n_blocks(); ++block)
308 v.
block(block).trilinos_vector().ExtractCopy (entries, 0);
309 entries += v.
block(block).local_size();
312 if (import_data ==
true)
319 Epetra_Import data_exchange (
vector->Map(), actual_vec->Map());
321 const int ierr =
vector->Import(*actual_vec, data_exchange, Insert);
327 vector = std::move(actual_vec);
328 #if defined(DEBUG) && defined(DEAL_II_WITH_MPI) 329 const Epetra_MpiComm *comm_ptr
330 =
dynamic_cast<const Epetra_MpiComm *
>(&(
vector->Comm()));
332 const size_type n_elements_global
343 const MPI_Comm &communicator,
344 const bool vector_writable)
348 if (vector_writable ==
false)
350 IndexSet parallel_partitioner = locally_owned_entries;
354 vector = std_cxx14::make_unique<Epetra_FEVector>(map);
361 ExcMessage(
"A writable vector must not have ghost entries in " 362 "its parallel partitioning"));
364 if (
vector->Map().SameAs(map)==
false)
365 vector = std_cxx14::make_unique<Epetra_FEVector>(map);
368 const int ierr =
vector->PutScalar(0.);
373 IndexSet nonlocal_entries(ghost_entries);
377 Epetra_Map nonlocal_map =
379 nonlocal_vector = std_cxx14::make_unique<Epetra_MultiVector>(nonlocal_map, 1);
388 const size_type n_elements_global
401 ExcMessage(
"Vector is not constructed properly."));
405 #ifdef DEAL_II_WITH_MPI 406 const Epetra_MpiComm *my_comm =
dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
407 const Epetra_MpiComm *v_comm =
dynamic_cast<const Epetra_MpiComm *
>(&v.
vector->Comm());
408 const bool same_communicators = my_comm !=
nullptr && v_comm !=
nullptr &&
409 my_comm->DataPtr() == v_comm->DataPtr();
430 const bool same_communicators =
true;
437 if (same_communicators && v.
vector->Map().SameAs(
vector->Map()))
449 (v.
vector->Map().UniqueGIDs() ||
vector->Map().UniqueGIDs()))
457 vector = std_cxx14::make_unique<Epetra_FEVector>(*v.
vector);
479 template <
typename number>
506 "Cannot find exchange information!"));
508 ExcMessage (
"The input vector has overlapping data, " 509 "which is not allowed."));
514 Epetra_Import data_exchange (
vector->Map(), v.
vector->Map());
515 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
545 ExcMessage(
"The last operation on the Vector and the given last action in the compress() call do not agree!"));
550 # ifdef DEAL_II_WITH_MPI 554 double double_mode = mode;
555 const Epetra_MpiComm *comm_ptr
561 ExcMessage (
"Not all processors agree whether the last operation on " 562 "this vector was an addition or a set operation. This will " 563 "prevent the compress() operation from succeeding."));
571 ierr =
vector->GlobalAssemble(mode);
591 TrilinosWrappers::types::int_type trilinos_i =
592 vector->Map().LID(static_cast<TrilinosWrappers::types::int_type>(index));
593 TrilinosScalar value = 0.;
597 if (trilinos_i == -1)
601 vector->Map().MaxMyGID()));
604 value = (*vector)[0][trilinos_i];
613 const bool allow_different_maps)
615 if (allow_different_maps ==
false)
623 #if DEAL_II_TRILINOS_VERSION_GTE(11,11,0) 624 Epetra_Import data_exchange (
vector->Map(), v.
vector->Map());
625 int ierr =
vector->Import(*v.
vector, data_exchange, Epetra_AddLocalAlso);
632 Epetra_MultiVector dummy(
vector->Map(), 1,
false);
633 Epetra_Import data_exchange (dummy.Map(), v.
vector->Map());
635 int ierr = dummy.Import(*v.
vector, data_exchange, Insert);
638 ierr =
vector->Update (1.0, dummy, 1.0);
656 if ((*(v.
vector))[0][i]!=(*vector)[0][i])
return false;
669 return (!(*
this==v));
679 TrilinosScalar *start_ptr = (*vector)[0];
680 const TrilinosScalar *ptr = start_ptr,
682 unsigned int flag = 0;
693 #ifdef DEAL_II_WITH_MPI 696 const Epetra_MpiComm *mpi_comm
697 =
dynamic_cast<const Epetra_MpiComm *
>(&
vector->Map().Comm());
700 return num_nonzero == 0;
712 #ifdef DEAL_II_WITH_MPI 722 TrilinosScalar *start_ptr;
723 int leading_dimension;
724 int ierr =
vector->ExtractView (&start_ptr, &leading_dimension);
731 const TrilinosScalar *ptr = start_ptr,
732 *eptr = start_ptr +
size();
751 const unsigned int precision,
752 const bool scientific,
753 const bool across)
const 756 boost::io::ios_flags_saver restore_flags(out);
759 out.precision (precision);
761 out.setf (std::ios::scientific, std::ios::floatfield);
763 out.setf (std::ios::fixed, std::ios::floatfield);
767 auto global_id = [&] (
const size_type index)
769 return gid(
vector->Map(),
static_cast<TrilinosWrappers::types::int_type
>(index));
771 out <<
"size:" <<
size() <<
" local_size:" <<
local_size() <<
" :" << std::endl;
773 out <<
"[" << global_id(i) <<
"]: " << (*(
vector))[0][i] << std::endl;
778 int leading_dimension;
779 int ierr =
vector->ExtractView (&val, &leading_dimension);
783 for (size_type i=0; i<
size(); ++i)
784 out << static_cast<double>(val[i]) <<
' ';
786 for (size_type i=0; i<
size(); ++i)
787 out << static_cast<double>(val[i]) << std::endl;
819 sizeof(TrilinosWrappers::types::int_type) );
828 # include "trilinos_vector.inst" 832 DEAL_II_NAMESPACE_CLOSE
834 #endif // DEAL_II_WITH_TRILINOS Vector & operator=(const TrilinosScalar s)
std::unique_ptr< Epetra_MultiVector > nonlocal_vector
static ::ExceptionBase & ExcIO()
TrilinosWrappers::types::int_type global_length(const Epetra_MultiVector &vector)
void reinit(const Vector &v, const bool omit_zeroing_entries=false, const bool allow_different_maps=false)
void add(const std::vector< size_type > &indices, const std::vector< TrilinosScalar > &values)
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
std::pair< size_type, size_type > local_range() const
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
bool operator==(const Vector &v) const
static ::ExceptionBase & ExcMessage(std::string arg1)
reference operator()(const size_type index)
void swap(BlockVector &u, BlockVector &v)
T sum(const T &t, const MPI_Comm &mpi_communicator)
TrilinosWrappers::types::int_type * my_global_elements(const Epetra_BlockMap &map)
void subtract_set(const IndexSet &other)
#define Assert(cond, exc)
bool is_non_negative() const
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
std::unique_ptr< Epetra_FEVector > vector
void compress(::VectorOperation::values operation)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
std::size_t memory_consumption() const
const Epetra_CrsMatrix & trilinos_matrix() const
void import_nonlocal_data_for_fe(const ::TrilinosWrappers::SparseMatrix &matrix, const Vector &vector)
bool has_ghost_elements() const
const Epetra_Map & vector_partitioner() const
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcGhostsPresent()
TrilinosWrappers::types::int_type n_global_elements(const Epetra_BlockMap &map)
void swap(Vector< Number > &u, Vector< Number > &v)
void set_size(const size_type size)
size_type local_size() const
unsigned int n_blocks() const
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
static ::ExceptionBase & ExcNotImplemented()
Epetra_CombineMode last_action
bool operator!=(const Vector &v) const
MinMaxAvg min_max_avg(const double my_value, const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcTrilinosError(int arg1)
BlockType & block(const unsigned int i)
size_type n_elements() const
static ::ExceptionBase & ExcInternalError()