Reference documentation for deal.II version 9.0.0
vector_element_access.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_vector_element_access_h
17 #define dealii_vector_element_access_h
18 
19 
20 #include <deal.II/lac/trilinos_epetra_vector.h>
21 
22 DEAL_II_NAMESPACE_OPEN
23 
24 namespace internal
25 {
26  template <typename VectorType>
27  struct ElementAccess
28  {
29  public:
30  static void add(const typename VectorType::value_type value,
32  VectorType &V);
33 
34  static void set(typename VectorType::value_type value,
36  VectorType &V);
37 
38  static typename VectorType::value_type get(const VectorType &V,
39  const types::global_dof_index i);
40  };
41 
42 
43 
44  template <typename VectorType>
45  inline
46  void ElementAccess<VectorType>::add(const typename VectorType::value_type value,
48  VectorType &V)
49  {
50  V(i) += value;
51  }
52 
53 
54 
55  template <typename VectorType>
56  inline
57  void ElementAccess<VectorType>::set(const typename VectorType::value_type value,
59  VectorType &V)
60  {
61  V(i) = value;
62  }
63 
64 
65 
66  template <typename VectorType>
67  inline
68  typename VectorType::value_type
69  ElementAccess<VectorType>::get(const VectorType &V,
71  {
72  return V(i);
73  }
74 
75 
76 
77 #if defined(DEAL_II_WITH_TRILINOS) && defined(DEAL_II_WITH_MPI)
78  template <>
79  inline
80  void ElementAccess<LinearAlgebra::EpetraWrappers::Vector>::
81  add(const double value,
84  {
85  // Extract local indices in the vector.
86  Epetra_FEVector vector = V.trilinos_vector();
87  TrilinosWrappers::types::int_type trilinos_i =
88  vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
89 
90  vector[0][trilinos_i] += value;
91  }
92 
93 
94 
95  template <>
96  inline
97  void ElementAccess<LinearAlgebra::EpetraWrappers::Vector>::
98  set(const double value,
101  {
102  // Extract local indices in the vector.
103  Epetra_FEVector vector = V.trilinos_vector();
104  TrilinosWrappers::types::int_type trilinos_i =
105  vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
106 
107  vector[0][trilinos_i] = value;
108  }
109 
110 
111  template <>
112  inline
113  double
114  ElementAccess<LinearAlgebra::EpetraWrappers::Vector>::
116  const types::global_dof_index i)
117  {
118  // Extract local indices in the vector.
119  Epetra_FEVector vector = V.trilinos_vector();
120  TrilinosWrappers::types::int_type trilinos_i =
121  vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
122 
123  return vector[0][trilinos_i];
124  }
125 #endif
126 }
127 
128 DEAL_II_NAMESPACE_CLOSE
129 
130 #endif
unsigned int global_dof_index
Definition: types.h:88
const Epetra_FEVector & trilinos_vector() const