16 #include <deal.II/base/std_cxx14/memory.h> 17 #include <deal.II/lac/trilinos_epetra_vector.h> 19 #ifdef DEAL_II_WITH_TRILINOS 21 #ifdef DEAL_II_WITH_MPI 23 #include <deal.II/base/index_set.h> 25 #include <boost/io/ios_state.hpp> 28 #include <deal.II/lac/read_write_vector.h> 30 # include <Epetra_Import.h> 31 # include <Epetra_Map.h> 32 # include <Epetra_MpiComm.h> 35 DEAL_II_NAMESPACE_OPEN
39 namespace EpetraWrappers
43 vector(new Epetra_FEVector(Epetra_Map(0,0,0,
Utilities::Trilinos::comm_self())))
51 vector(new Epetra_FEVector(V.trilinos_vector()))
57 const MPI_Comm &communicator)
59 vector(new Epetra_FEVector(parallel_partitioner.make_trilinos_map(communicator,false)))
65 const MPI_Comm &communicator,
66 const bool omit_zeroing_entries)
68 Epetra_Map input_map = parallel_partitioner.
make_trilinos_map(communicator,
false);
69 if (
vector->Map().SameAs(input_map)==
false)
70 vector = std_cxx14::make_unique<Epetra_FEVector>(input_map);
71 else if (omit_zeroing_entries==
false)
73 const int ierr =
vector->PutScalar(0.);
82 const bool omit_zeroing_entries)
91 omit_zeroing_entries);
127 const int ierr =
vector->PutScalar(s);
138 std::shared_ptr<const CommunicationPatternBase> communication_pattern)
142 if (communication_pattern ==
nullptr)
151 dynamic_cast<const Epetra_MpiComm &
>(
vector->Comm()).Comm());
159 ExcMessage(std::string(
"The communication pattern is not of type ") +
160 "LinearAlgebra::EpetraWrappers::CommunicationPattern."));
166 Epetra_FEVector source_vector(
import.TargetMap());
167 double *values = source_vector.Values();
168 std::copy(V.
begin(), V.
end(), values);
171 vector->Export(source_vector,
import, Insert);
173 vector->Export(source_vector,
import, Add);
218 #if DEAL_II_TRILINOS_VERSION_GTE(11,11,0) 221 data_exchange, Epetra_AddLocalAlso);
228 Epetra_MultiVector dummy(
vector->Map(), 1,
false);
229 Epetra_Import data_exchange(dummy.Map(), down_V.
trilinos_vector().Map());
231 int ierr = dummy.Import(down_V.
trilinos_vector(), data_exchange, Insert);
234 ierr =
vector->Update(1.0, dummy, 1.0);
257 Assert(dynamic_cast<const Vector *>(&V)!=
nullptr,
280 const unsigned local_size(
vector->MyLength());
281 for (
unsigned int i=0; i<local_size; ++i)
290 Assert(dynamic_cast<const Vector *>(&V)!=
nullptr,
310 Assert(dynamic_cast<const Vector *>(&V)!=
nullptr,
313 Assert(dynamic_cast<const Vector *>(&W)!=
nullptr,
339 Assert(dynamic_cast<const Vector *>(&V)!=
nullptr,
355 Assert(dynamic_cast<const Vector *>(&scaling_factors)!=
nullptr,
359 const Vector &down_scaling_factors =
360 dynamic_cast<const Vector &
>(scaling_factors);
375 Assert(dynamic_cast<const Vector *>(&V)!=
nullptr,
382 this->
sadd(0., a, V);
398 double *start_ptr = (*vector)[0];
399 const double *ptr = start_ptr,
400 *eptr = start_ptr +
vector->MyLength();
401 unsigned int flag = 0;
413 const Epetra_MpiComm *mpi_comm
414 =
dynamic_cast<const Epetra_MpiComm *
>(&
vector->Map().Comm());
418 return num_nonzero == 0;
439 int ierr =
vector->Norm1(&norm);
451 int ierr =
vector->Norm2(&norm);
463 int ierr =
vector->NormInf(&norm);
485 #ifndef DEAL_II_WITH_64BIT_INDICES 486 return vector->GlobalLength();
488 return vector->GlobalLength64();
496 const Epetra_MpiComm *epetra_comm
497 =
dynamic_cast<const Epetra_MpiComm *
>(&(
vector->Comm()));
499 return epetra_comm->GetMpiComm();
509 if (
vector->Map().LinearMap())
511 #ifndef DEAL_II_WITH_64BIT_INDICES 517 else if (
vector->Map().NumMyElements() > 0)
519 const size_type n_indices =
vector->Map().NumMyElements();
520 #ifndef DEAL_II_WITH_64BIT_INDICES 521 unsigned int *vector_indices = (
unsigned int *)
vector->Map().MyGlobalElements();
523 size_type *vector_indices = (size_type *)
vector->Map().MyGlobalElements64();
525 is.
add_indices(vector_indices, vector_indices+n_indices);
549 const unsigned int precision,
550 const bool scientific,
551 const bool across)
const 554 boost::io::ios_flags_saver restore_flags(out);
559 int leading_dimension;
560 int ierr =
vector->ExtractView(&val, &leading_dimension);
564 out.precision (precision);
566 out.setf(std::ios::scientific, std::ios::floatfield);
568 out.setf(std::ios::fixed, std::ios::floatfield);
571 for (
int i=0; i<
vector->MyLength(); ++i)
572 out << val[i] <<
' ';
574 for (
int i=0; i<
vector->MyLength(); ++i)
575 out << val[i] << std::endl;
588 +
vector->MyLength()*(
sizeof(double)+
589 sizeof(TrilinosWrappers::types::int_type));
595 const MPI_Comm &mpi_comm)
604 DEAL_II_NAMESPACE_CLOSE
virtual double l1_norm() const override
static ::ExceptionBase & ExcDifferentParallelPartitioning()
virtual bool all_zero() const override
static ::ExceptionBase & ExcIO()
virtual ::IndexSet locally_owned_elements() const override
virtual double l2_norm() const override
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
virtual size_type size() const override
virtual void scale(const VectorSpaceVector< double > &scaling_factors) override
#define AssertThrow(cond, exc)
virtual std::size_t memory_consumption() const override
std::unique_ptr< Epetra_FEVector > vector
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
virtual void equ(const double a, const VectorSpaceVector< double > &V) override
static ::ExceptionBase & ExcMessage(std::string arg1)
T sum(const T &t, const MPI_Comm &mpi_communicator)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void create_epetra_comm_pattern(const IndexSet &source_index_set, const MPI_Comm &mpi_comm)
virtual Vector & operator*=(const double factor) override
virtual void import(const ReadWriteVector< double > &V, VectorOperation::values operation, std::shared_ptr< const CommunicationPatternBase > communication_pattern=std::shared_ptr< const CommunicationPatternBase >()) override
const Epetra_FEVector & trilinos_vector() const
Vector & operator=(const Vector &V)
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcVectorTypeNotCompatible()
void reinit(const IndexSet ¶llel_partitioner, const MPI_Comm &communicator, const bool omit_zeroing_entries=false)
std::shared_ptr< const CommunicationPattern > epetra_comm_pattern
virtual void sadd(const double s, const double a, const VectorSpaceVector< double > &V) override
void add_range(const size_type begin, const size_type end)
virtual Vector & operator+=(const VectorSpaceVector< double > &V) override
virtual Vector & operator/=(const double factor) override
virtual void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const override
virtual double mean_value() const override
virtual Vector & operator-=(const VectorSpaceVector< double > &V) override
MPI_Comm get_mpi_communicator() const
virtual double operator*(const VectorSpaceVector< double > &V) const override
virtual void add(const double a) override
static ::ExceptionBase & ExcZero()
#define AssertIsFinite(number)
virtual double linfty_norm() const override
const IndexSet & get_stored_elements() const
static ::ExceptionBase & ExcInternalError()
virtual double add_and_dot(const double a, const VectorSpaceVector< double > &V, const VectorSpaceVector< double > &W) override
::IndexSet source_stored_elements