deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
trilinos_epetra_vector.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2016 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_trilinos_epetra_vector_h
14#define dealii_trilinos_epetra_vector_h
15
16
17#include <deal.II/base/config.h>
18
19#ifdef DEAL_II_TRILINOS_WITH_EPETRA
20
23
28
30# include <Epetra_FEVector.h>
32
33# include <memory>
34
35#endif
36
38
39#ifdef DEAL_II_TRILINOS_WITH_EPETRA
40namespace LinearAlgebra
41{
42 // Forward declaration
43 template <typename Number>
44 class ReadWriteVector;
45
53 namespace EpetraWrappers
54 {
60 "Transition to functionality provided in TrilinosWrappers or TpetraWrappers!")
62 {
63 public:
64 using value_type = double;
66 };
67
78 namespace internal
79 {
89 class VectorReference
90 {
91 private:
93 using size_type = VectorTraits::size_type;
94
99 VectorReference(Vector &vector, const size_type index);
100
101 public:
105 VectorReference(const VectorReference &) = default;
106
118 const VectorReference &
119 operator=(const VectorReference &r) const;
120
124 VectorReference &
125 operator=(const VectorReference &r);
126
130 const VectorReference &
131 operator=(const value_type &s) const;
132
136 const VectorReference &
137 operator+=(const value_type &s) const;
138
142 const VectorReference &
143 operator-=(const value_type &s) const;
144
148 const VectorReference &
149 operator*=(const value_type &s) const;
150
154 const VectorReference &
155 operator/=(const value_type &s) const;
156
161 operator value_type() const;
162
166 DeclException1(ExcTrilinosError,
167 int,
168 << "An error with error number " << arg1
169 << " occurred while calling a Trilinos function");
170
171 /*
172 * Access to a an element that is not (locally-)owned.
173 *
174 * @ingroup Exceptions
175 */
177 ExcAccessToNonLocalElement,
178 size_type,
179 size_type,
180 size_type,
181 size_type,
182 << "You are trying to access element " << arg1
183 << " of a distributed vector, but this element is not stored "
184 << "on the current processor. Note: There are " << arg2
185 << " elements stored "
186 << "on the current processor from within the range [" << arg3 << ','
187 << arg4 << "] but Trilinos vectors need not store contiguous "
188 << "ranges on each processor, and not every element in "
189 << "this range may in fact be stored locally."
190 << "\n\n"
191 << "A common source for this kind of problem is that you "
192 << "are passing a 'fully distributed' vector into a function "
193 << "that needs read access to vector elements that correspond "
194 << "to degrees of freedom on ghost cells (or at least to "
195 << "'locally active' degrees of freedom that are not also "
196 << "'locally owned'). You need to pass a vector that has these "
197 << "elements as ghost entries.");
198
199 private:
203 Vector &vector;
204
208 const size_type index;
209
210 // Make the vector class a friend, so that it can create objects of the
211 // present type.
212 friend class ::LinearAlgebra::EpetraWrappers::Vector;
213 }; // class VectorReference
214
215 } // namespace internal
230 "Transition to functionality provided in TrilinosWrappers or TpetraWrappers!")
231 Vector : public ReadVector<VectorTraits::value_type>
232 {
233 public:
237 using reference = internal::VectorReference;
238 using const_reference = const internal::VectorReference;
239
248 Vector();
249
254 Vector(const Vector &V);
255
262 explicit Vector(const IndexSet &parallel_partitioner,
263 const MPI_Comm communicator);
264
271 void
272 reinit(const IndexSet &parallel_partitioner,
273 const MPI_Comm communicator,
274 const bool omit_zeroing_entries = false);
275
280 void
281 reinit(const Vector &V, const bool omit_zeroing_entries = false);
282
286 virtual void
287 extract_subvector_to(
289 const ArrayView<double> &elements) const override;
290
320 Vector &
321 operator=(const Vector &V);
322
336 Vector &
337 operator=(const double s);
338
347 void
348 import_elements(
350 VectorOperation::values operation,
351 const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
352 &communication_pattern = {});
353
370 operator()(const size_type index);
371
380 operator()(const size_type index) const;
381
388 operator[](const size_type index);
389
396 operator[](const size_type index) const;
397
408 Vector &
409 operator*=(const double factor);
410
414 Vector &
415 operator/=(const double factor);
416
420 Vector &
421 operator+=(const Vector &V);
422
426 Vector &
427 operator-=(const Vector &V);
428
433 double
434 operator*(const Vector &V) const;
435
439 void
440 add(const double a);
441
446 void
447 add(const double a, const Vector &V);
448
453 void
454 add(const double a, const Vector &V, const double b, const Vector &W);
455
460 void
461 sadd(const double s, const double a, const Vector &V);
462
469 void
470 scale(const Vector &scaling_factors);
471
475 void
476 equ(const double a, const Vector &V);
477
481 bool
482 all_zero() const;
483
495 double
496 mean_value() const;
497
502 double
503 l1_norm() const;
504
509 double
510 l2_norm() const;
511
516 double
517 linfty_norm() const;
518
541 double
542 add_and_dot(const double a, const Vector &V, const Vector &W);
543
555 bool
556 has_ghost_elements() const;
557
562 virtual size_type
563 size() const override;
564
570 locally_owned_size() const;
571
576 get_mpi_communicator() const;
577
590 locally_owned_elements() const;
591
610 void
611 compress(const VectorOperation::values operation);
612
617 const Epetra_FEVector &
618 trilinos_vector() const;
619
624 Epetra_FEVector &
625 trilinos_vector();
626
630 void
631 print(std::ostream &out,
632 const unsigned int precision = 3,
633 const bool scientific = true,
634 const bool across = true) const;
635
639 std::size_t
640 memory_consumption() const;
641
648 DeclException0(ExcDifferentParallelPartitioning);
649
655 DeclException0(ExcVectorTypeNotCompatible);
656
662 DeclException1(ExcTrilinosError,
663 int,
664 << "An error with error number " << arg1
665 << " occurred while calling a Trilinos function");
666
667 private:
673 void
674 create_epetra_comm_pattern(const IndexSet &source_index_set,
675 const MPI_Comm mpi_comm);
676
680 std::unique_ptr<Epetra_FEVector> vector;
681
686
691 std::shared_ptr<const CommunicationPattern> epetra_comm_pattern;
692
693 // Make the reference class a friend.
694 friend class internal::VectorReference;
695 };
696
697# ifndef DOXYGEN
698
699 // VectorReference
700 namespace internal
701 {
702 inline VectorReference::VectorReference(Vector &vector,
703 const size_type index)
704 : vector(vector)
705 , index(index)
706 {}
707
708
709
710 inline const VectorReference &
711 VectorReference::operator=(const VectorReference &r) const
712 {
713 // as explained in the class
714 // documentation, this is not the copy
715 // operator. so simply pass on to the
716 // "correct" assignment operator
717 *this = static_cast<value_type>(r);
718
719 return *this;
720 }
721
722
723
724 inline VectorReference &
725 VectorReference::operator=(const VectorReference &r)
726 {
727 // as above
728 *this = static_cast<value_type>(r);
729
730 return *this;
731 }
732
733
734
735 inline const VectorReference &
736 VectorReference::operator=(const value_type &value) const
737 {
738 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
739
740 (*vector.vector)[0][index] = value;
741
742 return *this;
743 }
744
745
746
747 inline const VectorReference &
748 VectorReference::operator+=(const value_type &value) const
749 {
750 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
751
752 const value_type new_value = static_cast<value_type>(*this) + value;
753 (*vector.vector)[0][index] = new_value;
754
755 return *this;
756 }
757
758
759
760 inline const VectorReference &
761 VectorReference::operator-=(const value_type &value) const
762 {
763 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
764
765 const value_type new_value = static_cast<value_type>(*this) - value;
766 (*vector.vector)[0][index] = new_value;
767
768 return *this;
769 }
770
771
772
773 inline const VectorReference &
774 VectorReference::operator*=(const value_type &value) const
775 {
776 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
777
778 const value_type new_value = static_cast<value_type>(*this) * value;
779 (*vector.vector)[0][index] = new_value;
780
781 return *this;
782 }
783
784
785
786 inline const VectorReference &
787 VectorReference::operator/=(const value_type &value) const
788 {
789 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
790
791 const value_type new_value = static_cast<value_type>(*this) / value;
792 (*vector.vector)[0][index] = new_value;
793
794 return *this;
795 }
796 } // namespace internal
797
798# endif /* DOXYGEN */
799
800
801 inline internal::VectorReference
803 {
804 return internal::VectorReference(*this, index);
805 }
806
807 inline internal::VectorReference
809 {
810 return operator()(index);
811 }
812
813 inline Vector::value_type
814 Vector::operator[](const size_type index) const
815 {
816 return operator()(index);
817 }
818
819
820 inline bool
822 {
823 return false;
824 }
825 } // namespace EpetraWrappers
826} // namespace LinearAlgebra
827
828
832template <>
833struct is_serial_vector<LinearAlgebra::EpetraWrappers::Vector> : std::false_type
834{};
835
836#endif
837
839
840#endif
*  *  reference operator*() const
*  *  Point< dim > operator()(const Point< dim > &p) const * 
std::unique_ptr< Epetra_FEVector > vector
value_type operator()(const size_type index) const
std::shared_ptr< const CommunicationPattern > epetra_comm_pattern
const internal::VectorReference const_reference
bool has_ghost_elements() const
Number operator[](const size_type i) const
Number operator()(const size_type i) const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Definition config.h:636
#define DEAL_II_DEPRECATED_WITH_COMMENT(comment)
Definition config.h:295
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
Definition config.h:680
#define DeclException0(Exception0)
static ::ExceptionBase & ExcGhostsPresent()
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
#define Assert(cond, exc)
#define DeclException1(Exception1, type1, outsequence)
std::size_t size
Definition mpi.cc:733
types::global_dof_index locally_owned_size
Definition mpi.cc:821
unsigned int global_dof_index
Definition types.h:92
Number linfty_norm(const Tensor< 2, dim, Number > &t)
Definition tensor.h:3033
Number l1_norm(const Tensor< 2, dim, Number > &t)
Definition tensor.h:3007