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/lac/trilinos_sparse_matrix.h> 22 # include <deal.II/lac/trilinos_block_vector.h> 24 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
25 # include <Epetra_Import.h> 26 # include <Epetra_Vector.h> 27 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
32 DEAL_II_NAMESPACE_OPEN
38 #ifndef DEAL_II_WITH_64BIT_INDICES 43 int n_global_elements (
const Epetra_BlockMap &map)
45 return map.NumGlobalElements();
52 int *my_global_elements(
const Epetra_BlockMap &map)
54 return map.MyGlobalElements();
59 int global_length(
const Epetra_FEVector &vector)
61 return vector.GlobalLength();
68 long long int n_global_elements (
const Epetra_BlockMap &map)
70 return map.NumGlobalElements64();
77 long long int *my_global_elements(
const Epetra_BlockMap &map)
79 return map.MyGlobalElements64();
84 long long int global_length(
const Epetra_FEVector &vector)
86 return vector.GlobalLength64();
105 reinit (parallel_partitioning);
111 const MPI_Comm &communicator)
113 reinit (parallel_partitioning, communicator);
123 vector.reset (
new Epetra_FEVector(*v.vector));
130 #ifdef DEAL_II_WITH_CXX11 151 n_global_elements(v.
vector->Map())));
155 if (input_map.SameAs(v.
vector->Map()) ==
true)
159 vector.reset (
new Epetra_FEVector(input_map));
168 const MPI_Comm &communicator)
175 n_global_elements(v.
vector->Map())));
179 vector.reset (
new Epetra_FEVector
187 const MPI_Comm &communicator)
191 reinit(local, ghost, communicator,
false);
207 vector.reset (
new Epetra_FEVector(input_map));
223 if (
vector->Map().LinearMap())
225 const std::pair<size_type, size_type> x =
local_range();
228 else if (
vector->Map().NumMyElements() > 0)
231 #ifndef DEAL_II_WITH_64BIT_INDICES 232 unsigned int *vector_indices = (
unsigned int *)
vector->Map().MyGlobalElements();
240 #if defined(DEBUG) && defined(DEAL_II_WITH_MPI) 241 const Epetra_MpiComm *comm_ptr
242 =
dynamic_cast<const Epetra_MpiComm *
>(&(
vector->Comm()));
257 const MPI_Comm &communicator,
265 vector.reset (
new Epetra_FEVector(map));
295 const bool omit_zeroing_entries,
296 const bool allow_different_maps)
303 if (allow_different_maps ==
false)
309 #ifdef DEAL_II_WITH_MPI 310 const Epetra_MpiComm *my_comm =
dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
311 const Epetra_MpiComm *v_comm =
dynamic_cast<const Epetra_MpiComm *
>(&v.
vector->Comm());
312 const bool same_communicators = my_comm != NULL && v_comm != NULL &&
313 my_comm->DataPtr() == v_comm->DataPtr();
315 const bool same_communicators =
true;
317 if (!same_communicators ||
vector->Map().SameAs(v.
vector->Map()) ==
false)
324 else if (omit_zeroing_entries ==
false)
333 ierr =
vector->PutScalar(0.0);
346 Assert (omit_zeroing_entries ==
false,
347 ExcMessage (
"It is not possible to exchange data with the " 348 "option 'omit_zeroing_entries' set, which would not write " 354 Epetra_Import data_exchange (
vector->Map(), v.
vector->Map());
356 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
361 #if defined(DEBUG) && defined(DEAL_II_WITH_MPI) 362 const Epetra_MpiComm *comm_ptr
363 =
dynamic_cast<const Epetra_MpiComm *
>(&(v.
vector->Comm()));
376 const bool import_data)
390 size_type n_elements = 0, added_elements = 0, block_offset = 0;
392 n_elements += v.
block(block).local_size();
393 std::vector<TrilinosWrappers::types::int_type> global_ids (n_elements, -1);
396 TrilinosWrappers::types::int_type *glob_elements =
397 my_global_elements(v.
block(block).vector_partitioner());
399 global_ids[added_elements++] = glob_elements[i] + block_offset;
406 Epetra_Map new_map (v.
size(), n_elements, &global_ids[0], 0,
407 v.
block(0).vector_partitioner().Comm());
409 std_cxx11::shared_ptr<Epetra_FEVector> actual_vec;
410 if ( import_data ==
true )
411 actual_vec.reset (
new Epetra_FEVector (new_map));
414 vector.reset (
new Epetra_FEVector (new_map));
418 TrilinosScalar *entries = (*actual_vec)[0];
422 v.
block(block).trilinos_vector().ExtractCopy (entries, 0);
423 entries += v.
block(block).local_size();
426 if (import_data ==
true)
428 AssertThrow (static_cast<size_type>(global_length(*actual_vec))
433 Epetra_Import data_exchange (
vector->Map(), actual_vec->Map());
435 const int ierr =
vector->Import(*actual_vec, data_exchange, Insert);
440 #if defined(DEBUG) && defined(DEAL_II_WITH_MPI) 441 const Epetra_MpiComm *comm_ptr
442 =
dynamic_cast<const Epetra_MpiComm *
>(&(
vector->Comm()));
454 const MPI_Comm &communicator,
455 const bool vector_writable)
459 if (vector_writable ==
false)
461 IndexSet parallel_partitioner = locally_owned_entries;
465 vector.reset (
new Epetra_FEVector(map));
475 ExcMessage(
"A writable vector must not have ghost entries in " 476 "its parallel partitioning"));
479 IndexSet nonlocal_entries(ghost_entries);
483 Epetra_Map nonlocal_map =
503 #ifdef DEAL_II_WITH_MPI 504 const Epetra_MpiComm *my_comm =
dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
505 const Epetra_MpiComm *v_comm =
dynamic_cast<const Epetra_MpiComm *
>(&v.vector->Comm());
506 const bool same_communicators = my_comm != NULL && v_comm != NULL &&
507 my_comm->DataPtr() == v_comm->DataPtr();
528 const bool same_communicators =
true;
535 if (same_communicators && v.vector->Map().SameAs(
vector->Map()))
538 if (v.nonlocal_vector.get() != 0)
539 nonlocal_vector.reset(
new Epetra_MultiVector(v.nonlocal_vector->Map(), 1));
547 (v.vector->Map().UniqueGIDs() ||
vector->Map().UniqueGIDs()))
555 vector.reset (
new Epetra_FEVector(*v.vector));
561 if (v.nonlocal_vector.get() != 0)
562 nonlocal_vector.reset(
new Epetra_MultiVector(v.nonlocal_vector->Map(), 1));
569 #ifdef DEAL_II_WITH_CXX11 586 Epetra_Import data_exchange (
vector->Map(), v.vector->Map());
587 const int ierr =
vector->Import(*v.vector, data_exchange, Insert);
604 "Cannot find exchange information!"));
605 Assert (v.vector->Map().UniqueGIDs() ==
true,
606 ExcMessage (
"The input vector has overlapping data, " 607 "which is not allowed."));
611 vector.reset (
new Epetra_FEVector(
616 Epetra_Import data_exchange (
vector->Map(), v.vector->Map());
617 const int ierr =
vector->Import(*v.vector, data_exchange, Insert);
633 vector.reset (
new Epetra_FEVector(map));
653 const MPI_Comm &communicator)
655 reinit (partitioning, communicator);
663 Epetra_LocalMap map (n_global_elements(v.
vector->Map()),
664 v.
vector->Map().IndexBase(),
666 vector.reset (
new Epetra_FEVector(map));
684 Epetra_LocalMap map ((TrilinosWrappers::types::int_type)n, 0,
686 vector.reset (
new Epetra_FEVector (map));
697 Epetra_LocalMap map (n_global_elements(input_map),
698 input_map.IndexBase(),
700 vector.reset (
new Epetra_FEVector(map));
701 owned_elements = complete_index_set(n_global_elements(input_map));
710 const MPI_Comm &communicator,
713 Epetra_LocalMap map (static_cast<TrilinosWrappers::types::int_type>(partitioning.
size()),
715 #ifdef DEAL_II_WITH_MPI
716 Epetra_MpiComm(communicator));
718 Epetra_SerialComm());
721 vector.reset (
new Epetra_FEVector(map));
731 const bool omit_zeroing_entries,
732 const bool allow_different_maps)
741 if (allow_different_maps ==
false)
744 #ifdef DEAL_II_WITH_MPI 745 const Epetra_MpiComm *my_comm =
dynamic_cast<const Epetra_MpiComm *
>(&
vector->Comm());
746 const Epetra_MpiComm *v_comm =
dynamic_cast<const Epetra_MpiComm *
>(&v.
vector->Comm());
747 const bool same_communicators = my_comm != NULL && v_comm != NULL &&
748 my_comm->DataPtr() == v_comm->DataPtr();
750 const bool same_communicators =
true;
754 Epetra_LocalMap map (global_length(*(v.
vector)),
755 v.
vector->Map().IndexBase(),
757 vector.reset (
new Epetra_FEVector(map));
760 else if (omit_zeroing_entries)
764 ExcMessage (
"The Epetra maps in the assignment operator =" 765 " do not match, even though the local_range " 766 " seems to be the same. Check vector setup!"));
772 ierr =
vector->PutScalar(0.0);
786 Assert (omit_zeroing_entries ==
false,
787 ExcMessage (
"It is not possible to exchange data with the " 788 "option 'omit_zeroing_entries' set, which would not write " 794 Epetra_Import data_exchange (
vector->Map(), v.
vector->Map());
796 const int ierr =
vector->Import(*v.
vector, data_exchange, Insert);
811 Epetra_LocalMap map (n_global_elements(v.vector->Map()),
812 v.vector->Map().IndexBase(),
814 vector.reset (
new Epetra_FEVector(map));
828 Epetra_LocalMap map (n_global_elements(v.vector->Map()),
829 v.vector->Map().IndexBase(),
831 vector.reset (
new Epetra_FEVector(map));
835 const int ierr =
vector->Update(1.0, *v.vector, 0.0);
844 DEAL_II_NAMESPACE_CLOSE
846 #endif // DEAL_II_WITH_TRILINOS Vector & operator=(const TrilinosScalar s)
::types::global_dof_index size_type
Vector & operator=(const TrilinosScalar s)
std_cxx11::shared_ptr< Epetra_MultiVector > nonlocal_vector
std::pair< size_type, size_type > local_range() const
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
#define AssertThrow(cond, exc)
const Epetra_Comm & comm_self()
void reinit(const VectorBase &v, const bool omit_zeroing_entries=false, const bool allow_different_maps=false)
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
static ::ExceptionBase & ExcMessage(std::string arg1)
T sum(const T &t, const MPI_Comm &mpi_communicator)
std_cxx11::shared_ptr< Epetra_FEVector > vector
void subtract_set(const IndexSet &other)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void swap(Vector &u, Vector &v)
const Epetra_CrsMatrix & trilinos_matrix() const
void import_nonlocal_data_for_fe(const ::TrilinosWrappers::SparseMatrix &matrix, const Vector &vector)
static ::ExceptionBase & ExcTrilinosError(int arg1)
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
void add_range(const size_type begin, const size_type end)
void set_size(const size_type size)
unsigned int n_blocks() const
Epetra_CombineMode last_action
void reinit(const size_type n, const bool omit_zeroing_entries=false)
::types::global_dof_index size_type
BlockType & block(const unsigned int i)
size_type n_elements() const
static ::ExceptionBase & ExcInternalError()