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
85 , vector(new Epetra_FEVector(
86 Epetra_Map(0, 0, 0,
Utilities::Trilinos::comm_self())))
93 , vector(new Epetra_FEVector(V.trilinos_vector()))
101 , vector(new Epetra_FEVector(
102 parallel_partitioner.make_trilinos_map(communicator, false)))
110 const bool omit_zeroing_entries)
112 Epetra_Map input_map =
114 if (
vector->Map().SameAs(input_map) ==
false)
115 vector = std::make_unique<Epetra_FEVector>(input_map);
116 else if (omit_zeroing_entries ==
false)
118 const int ierr =
vector->PutScalar(0.);
131 omit_zeroing_entries);
143 const auto &map =
vector.Map();
145 for (
unsigned int i = 0; i < indices.
size(); ++i)
148 const auto trilinos_i =
150 elements[i] =
vector[0][trilinos_i];
169 Epetra_Import data_exchange(
vector->Map(),
191 const int ierr =
vector->PutScalar(s);
204 const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
205 &communication_pattern)
209 if (communication_pattern ==
nullptr)
220 dynamic_cast<const Epetra_MpiComm &
>(
vector->Comm()).Comm());
226 std::dynamic_pointer_cast<const CommunicationPattern>(
227 communication_pattern);
231 std::string(
"The communication pattern is not of type ") +
232 "LinearAlgebra::EpetraWrappers::CommunicationPattern."));
238 Epetra_FEVector source_vector(import_map.TargetMap());
239 double *values = source_vector.Values();
240 std::copy(V.
begin(), V.
end(), values);
243 vector->Export(source_vector, import_map, Insert);
245 vector->Export(source_vector, import_map, Add);
247 vector->Export(source_vector, import_map, Epetra_Max);
249 vector->Export(source_vector, import_map, Epetra_Min);
272 *
this *= 1. / factor;
294# if DEAL_II_TRILINOS_VERSION_GTE(11, 11, 0)
298 Epetra_AddLocalAlso);
305 Epetra_MultiVector dummy(
vector->Map(), 1,
false);
311 ierr =
vector->Update(1.0, dummy, 1.0);
354 const unsigned local_size(
vector->MyLength());
355 for (
unsigned int i = 0; i < local_size; ++i)
426 this->
sadd(0., a, V);
443 double *start_ptr = (*vector)[0];
444 const double *ptr = start_ptr, *eptr = start_ptr +
vector->MyLength();
445 unsigned int flag = 0;
457 const Epetra_MpiComm *mpi_comm =
458 dynamic_cast<const Epetra_MpiComm *
>(&
vector->Map().Comm());
462 return num_nonzero == 0;
485 int ierr =
vector->Norm1(&norm);
498 int ierr =
vector->Norm2(&norm);
511 int ierr =
vector->NormInf(&norm);
533# ifndef DEAL_II_WITH_64BIT_INDICES
534 return vector->GlobalLength();
536 return vector->GlobalLength64();
545 return vector->MyLength();
553 const Epetra_MpiComm *epetra_comm =
554 dynamic_cast<const Epetra_MpiComm *
>(&(
vector->Comm()));
556 return epetra_comm->GetMpiComm();
567 if (
vector->Map().LinearMap())
569# ifndef DEAL_II_WITH_64BIT_INDICES
573 vector->Map().MaxMyGID64() + 1);
576 else if (
vector->Map().NumMyElements() > 0)
579# ifndef DEAL_II_WITH_64BIT_INDICES
580 unsigned int *vector_indices =
581 reinterpret_cast<unsigned int *
>(
vector->Map().MyGlobalElements());
586 is.
add_indices(vector_indices, vector_indices + n_indices);
600 const Epetra_FEVector &
618 const unsigned int precision,
619 const bool scientific,
620 const bool across)
const
623 boost::io::ios_flags_saver restore_flags(out);
628 int leading_dimension;
629 int ierr =
vector->ExtractView(&val, &leading_dimension);
633 out.precision(precision);
635 out.setf(std::ios::scientific, std::ios::floatfield);
637 out.setf(std::ios::fixed, std::ios::floatfield);
640 for (
int i = 0; i <
vector->MyLength(); ++i)
641 out << val[i] <<
' ';
643 for (
int i = 0; i <
vector->MyLength(); ++i)
644 out << val[i] << std::endl;
657 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)
virtual void extract_subvector_to(const ArrayView< const types::global_dof_index > &indices, ArrayView< double > &elements) const override
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)
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)