16 #include <deal.II/base/memory_consumption.h> 17 #include <deal.II/lac/trilinos_vector_base.h> 19 #ifdef DEAL_II_WITH_TRILINOS 21 # include <deal.II/base/mpi.h> 25 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
26 # include <Epetra_Import.h> 27 # include <Epetra_Export.h> 29 # include <boost/io/ios_state.hpp> 30 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
33 DEAL_II_NAMESPACE_OPEN
39 #ifndef DEAL_II_WITH_64BIT_INDICES 43 int global_length(
const Epetra_FEVector &vector)
45 return vector.GlobalLength();
51 long long int global_length(
const Epetra_FEVector &vector)
53 return vector.GlobalLength64();
60 VectorReference::operator TrilinosScalar ()
const 62 Assert (index < vector.size(),
69 const TrilinosWrappers::types::int_type local_index =
70 vector.vector->Map().LID(static_cast<TrilinosWrappers::types::int_type>(index));
73 vector.vector->Map().MinMyGID(),
74 vector.vector->Map().MaxMyGID()));
77 return (*(vector.vector))[0][local_index];
88 #ifdef DEAL_II_WITH_MPI
89 vector(new Epetra_FEVector(
90 Epetra_Map(0,0,Epetra_MpiComm(MPI_COMM_SELF))))
92 vector(new Epetra_FEVector(
93 Epetra_Map(0,0,Epetra_SerialComm())))
104 has_ghosts (v.has_ghosts),
105 vector(new Epetra_FEVector(*v.vector)),
106 owned_elements(complete_index_set(v.size()))
121 #ifdef DEAL_II_WITH_MPI 122 Epetra_Map map (0, 0, Epetra_MpiComm(MPI_COMM_SELF));
124 Epetra_Map map (0, 0, Epetra_SerialComm());
128 vector.reset (
new Epetra_FEVector(map));
138 ExcMessage(
"Vector is not constructed properly."));
150 ExcMessage (
"The Epetra maps in the assignment operator =" 151 " do not match, even though the local_range " 152 " seems to be the same. Check vector setup!"));
168 template <
typename number>
183 std::pair<size_type, size_type>
210 # ifdef DEAL_II_WITH_MPI 214 double double_mode = mode;
215 const Epetra_MpiComm *comm_ptr
220 Assert(result.max-result.min<1e-5,
221 ExcMessage (
"Not all processors agree whether the last operation on " 222 "this vector was an addition or a set operation. This will " 223 "prevent the compress() operation from succeeding."));
231 ierr =
vector->GlobalAssemble(mode);
251 TrilinosWrappers::types::int_type trilinos_i =
252 vector->Map().LID(static_cast<TrilinosWrappers::types::int_type>(index));
256 if (trilinos_i == -1)
259 return (*
vector)[0][trilinos_i];
268 TrilinosWrappers::types::int_type trilinos_i =
269 vector->Map().LID(static_cast<TrilinosWrappers::types::int_type>(index));
270 TrilinosScalar value = 0.;
274 if (trilinos_i == -1)
278 vector->Map().MaxMyGID()));
281 value = (*vector)[0][trilinos_i];
290 const bool allow_different_maps)
292 if (allow_different_maps ==
false)
300 #if DEAL_II_TRILINOS_VERSION_GTE(11,11,0) 301 Epetra_Import data_exchange (
vector->Map(), v.
vector->Map());
302 int ierr =
vector->Import(*v.
vector, data_exchange, Epetra_AddLocalAlso);
309 Epetra_MultiVector dummy(
vector->Map(), 1,
false);
310 Epetra_Import data_exchange (dummy.Map(), v.
vector->Map());
312 int ierr = dummy.Import(*v.
vector, data_exchange, Insert);
315 ierr =
vector->Update (1.0, dummy, 1.0);
333 if ((*(v.
vector))[0][i]!=(*vector)[0][i])
return false;
346 return (!(*
this==v));
356 TrilinosScalar *start_ptr = (*vector)[0];
357 const TrilinosScalar *ptr = start_ptr,
359 unsigned int flag = 0;
370 #ifdef DEAL_II_WITH_MPI 373 const Epetra_MpiComm *mpi_comm
374 =
dynamic_cast<const Epetra_MpiComm *
>(&
vector->Map().Comm());
377 return num_nonzero == 0;
389 #ifdef DEAL_II_WITH_MPI 399 TrilinosScalar *start_ptr;
400 int leading_dimension;
401 int ierr =
vector->ExtractView (&start_ptr, &leading_dimension);
408 const TrilinosScalar *ptr = start_ptr,
409 *eptr = start_ptr +
size();
429 const TrilinosScalar b,
444 sadd(0., a, v, b, w);
455 int ierr =
vector->Update(a, *v.
vector, b, *w.vector, 0.0);
474 for (size_type j=0; j<
size(); ++j)
476 double t = (*vector)[0][j];
479 std::printf (format, t);
481 std::printf (
" %5.2f",
double(t));
490 const unsigned int precision,
491 const bool scientific,
492 const bool across)
const 495 boost::io::ios_flags_saver restore_flags(out);
504 int leading_dimension;
505 int ierr =
vector->ExtractView (&val, &leading_dimension);
508 out.precision (precision);
510 out.setf (std::ios::scientific, std::ios::floatfield);
512 out.setf (std::ios::fixed, std::ios::floatfield);
515 for (size_type i=0; i<
size(); ++i)
516 out << static_cast<double>(val[i]) <<
' ';
518 for (size_type i=0; i<
size(); ++i)
519 out << static_cast<double>(val[i]) << std::endl;
549 sizeof(TrilinosWrappers::types::int_type) );
557 #include "trilinos_vector_base.inst" 560 DEAL_II_NAMESPACE_CLOSE
562 #endif // DEAL_II_WITH_TRILINOS
bool is_non_negative() const
reference operator()(const size_type index)
static ::ExceptionBase & ExcIO()
void sadd(const TrilinosScalar s, const VectorBase &V)
std_cxx11::shared_ptr< Epetra_MultiVector > nonlocal_vector
std::pair< size_type, size_type > local_range() const
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
void add(const std::vector< size_type > &indices, const std::vector< TrilinosScalar > &values)
static ::ExceptionBase & ExcMessage(std::string arg1)
T sum(const T &t, const MPI_Comm &mpi_communicator)
std_cxx11::shared_ptr< Epetra_FEVector > vector
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
const Epetra_Map & vector_partitioner() const
std::size_t memory_consumption() const
bool has_ghost_elements() const
static ::ExceptionBase & ExcTrilinosError(int arg1)
void compress(::VectorOperation::values operation)
static ::ExceptionBase & ExcGhostsPresent()
TrilinosScalar el(const size_type index) const 1
VectorBase & operator=(const TrilinosScalar s)
static ::ExceptionBase & ExcEmptyObject()
bool operator!=(const VectorBase &v) const
Epetra_CombineMode last_action
static ::ExceptionBase & ExcNotImplemented()
MinMaxAvg min_max_avg(const double my_value, const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcDifferentParallelPartitioning()
bool operator==(const VectorBase &v) const
#define AssertIsFinite(number)
size_type local_size() const
void print(const char *format=0) const 1
static ::ExceptionBase & ExcInternalError()
void equ(const TrilinosScalar a, const VectorBase &V)