17#ifdef DEAL_II_WITH_TRILINOS
25# include <boost/io/ios_state.hpp>
27# include <Epetra_Import.h>
28# include <Epetra_Map.h>
29# include <Epetra_MpiComm.h>
38 namespace EpetraWrappers
43 VectorReference::operator value_type()
const
52 vector.vector->Map().LID(
55# ifndef DEAL_II_WITH_64BIT_INDICES
57 ExcAccessToNonLocalElement(index,
58 vector.vector->Map().NumMyElements(),
59 vector.vector->Map().MinMyGID(),
60 vector.vector->Map().MaxMyGID()));
63 ExcAccessToNonLocalElement(index,
64 vector.vector->Map().NumMyElements(),
65 vector.vector->Map().MinMyGID64(),
66 vector.vector->Map().MaxMyGID64()));
69 return (*(vector.vector))[0][local_index];
79# ifdef DEAL_II_HAVE_CXX20
84 : vector(new Epetra_FEVector(
85 Epetra_Map(0, 0, 0,
Utilities::Trilinos::comm_self())))
91 : vector(new Epetra_FEVector(V.trilinos_vector()))
98 : vector(new Epetra_FEVector(
99 parallel_partitioner.make_trilinos_map(communicator, false)))
107 const bool omit_zeroing_entries)
109 Epetra_Map input_map =
111 if (
vector->Map().SameAs(input_map) ==
false)
112 vector = std::make_unique<Epetra_FEVector>(input_map);
113 else if (omit_zeroing_entries ==
false)
115 const int ierr =
vector->PutScalar(0.);
128 omit_zeroing_entries);
140 const auto &map =
vector.Map();
142 for (
unsigned int i = 0; i < indices.
size(); ++i)
145 const auto trilinos_i =
147 elements[i] =
vector[0][trilinos_i];
166 Epetra_Import data_exchange(
vector->Map(),
188 const int ierr =
vector->PutScalar(s);
201 const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
202 &communication_pattern)
206 if (communication_pattern ==
nullptr)
217 dynamic_cast<const Epetra_MpiComm &
>(
vector->Comm()).Comm());
223 std::dynamic_pointer_cast<const CommunicationPattern>(
224 communication_pattern);
227 ExcMessage(
"The communication pattern is not of type "
228 "LinearAlgebra::EpetraWrappers::CommunicationPattern."));
234 Epetra_FEVector source_vector(import_map.TargetMap());
235 double *values = source_vector.Values();
236 std::copy(V.
begin(), V.
end(), values);
239 vector->Export(source_vector, import_map, Insert);
241 vector->Export(source_vector, import_map, Add);
243 vector->Export(source_vector, import_map, Epetra_Max);
245 vector->Export(source_vector, import_map, Epetra_Min);
268 *
this *= 1. / factor;
290# if DEAL_II_TRILINOS_VERSION_GTE(11, 11, 0)
294 Epetra_AddLocalAlso);
301 Epetra_MultiVector dummy(
vector->Map(), 1,
false);
307 ierr =
vector->Update(1.0, dummy, 1.0);
350 const unsigned local_size(
vector->MyLength());
351 for (
unsigned int i = 0; i < local_size; ++i)
422 this->
sadd(0., a, V);
439 double *start_ptr = (*vector)[0];
440 const double *ptr = start_ptr, *eptr = start_ptr +
vector->MyLength();
441 unsigned int flag = 0;
453 const Epetra_MpiComm *mpi_comm =
454 dynamic_cast<const Epetra_MpiComm *
>(&
vector->Map().Comm());
458 return num_nonzero == 0;
481 int ierr =
vector->Norm1(&norm);
494 int ierr =
vector->Norm2(&norm);
507 int ierr =
vector->NormInf(&norm);
529# ifndef DEAL_II_WITH_64BIT_INDICES
530 return vector->GlobalLength();
532 return vector->GlobalLength64();
541 return vector->MyLength();
549 const Epetra_MpiComm *epetra_comm =
550 dynamic_cast<const Epetra_MpiComm *
>(&(
vector->Comm()));
552 return epetra_comm->GetMpiComm();
563 if (
vector->Map().LinearMap())
565# ifndef DEAL_II_WITH_64BIT_INDICES
569 vector->Map().MaxMyGID64() + 1);
572 else if (
vector->Map().NumMyElements() > 0)
575# ifndef DEAL_II_WITH_64BIT_INDICES
576 unsigned int *vector_indices =
577 reinterpret_cast<unsigned int *
>(
vector->Map().MyGlobalElements());
582 is.
add_indices(vector_indices, vector_indices + n_indices);
596 const Epetra_FEVector &
614 const unsigned int precision,
615 const bool scientific,
616 const bool across)
const
619 boost::io::ios_flags_saver restore_flags(out);
624 int leading_dimension;
625 int ierr =
vector->ExtractView(&val, &leading_dimension);
629 out.precision(precision);
631 out.setf(std::ios::scientific, std::ios::floatfield);
633 out.setf(std::ios::fixed, std::ios::floatfield);
636 for (
int i = 0; i <
vector->MyLength(); ++i)
637 out << val[i] <<
' ';
639 for (
int i = 0; i <
vector->MyLength(); ++i)
640 out << val[i] << std::endl;
653 return sizeof(*this) +
Epetra_Map make_trilinos_map(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) const
void add_range(const size_type begin, const size_type end)
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
Vector & operator-=(const Vector &V)
void equ(const double a, const Vector &V)
Vector & operator=(const Vector &V)
MPI_Comm get_mpi_communicator() const
void compress(const VectorOperation::values operation)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
std::unique_ptr< Epetra_FEVector > vector
const Epetra_FEVector & trilinos_vector() const
void import_elements(const ReadWriteVector< double > &V, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
void sadd(const double s, const double a, const Vector &V)
Vector & operator/=(const double factor)
virtual size_type size() const override
size_type locally_owned_size() const
::IndexSet locally_owned_elements() const
Vector & operator+=(const Vector &V)
void scale(const Vector &scaling_factors)
void create_epetra_comm_pattern(const IndexSet &source_index_set, const MPI_Comm mpi_comm)
double mean_value() const
Vector & operator*=(const double factor)
::IndexSet source_stored_elements
double operator*(const Vector &V) const
std::shared_ptr< const CommunicationPattern > epetra_comm_pattern
std::size_t memory_consumption() const
void reinit(const IndexSet ¶llel_partitioner, const MPI_Comm communicator, const bool omit_zeroing_entries=false)
virtual void extract_subvector_to(const ArrayView< const types::global_dof_index > &indices, const ArrayView< double > &elements) const override
double linfty_norm() const
double add_and_dot(const double a, const Vector &V, const Vector &W)
const IndexSet & get_stored_elements() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcZero()
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertIsFinite(number)
static ::ExceptionBase & ExcDifferentParallelPartitioning()
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
T sum(const T &t, const MPI_Comm mpi_communicator)