Reference documentation for deal.II version 9.1.0-pre
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.md at
12 // the top level directory of deal.II.
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
31  add(const typename VectorType::value_type value,
33  VectorType & V);
34 
35  static void
36  set(typename VectorType::value_type value,
38  VectorType & V);
39 
40  static typename VectorType::value_type
41  get(const VectorType &V, const types::global_dof_index i);
42  };
43 
44 
45 
46  template <typename VectorType>
47  inline void
48  ElementAccess<VectorType>::add(const typename VectorType::value_type value,
50  VectorType & V)
51  {
52  V(i) += value;
53  }
54 
55 
56 
57  template <typename VectorType>
58  inline void
59  ElementAccess<VectorType>::set(const typename VectorType::value_type value,
61  VectorType & V)
62  {
63  V(i) = value;
64  }
65 
66 
67 
68  template <typename VectorType>
69  inline typename VectorType::value_type
70  ElementAccess<VectorType>::get(const VectorType & V,
72  {
73  return V(i);
74  }
75 
76 
77 
78 #if defined(DEAL_II_WITH_TRILINOS) && defined(DEAL_II_WITH_MPI)
79  template <>
80  inline void
81  ElementAccess<LinearAlgebra::EpetraWrappers::Vector>::add(
82  const double value,
85  {
86  // Extract local indices in the vector.
87  Epetra_FEVector vector = V.trilinos_vector();
88  TrilinosWrappers::types::int_type trilinos_i =
89  vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
90 
91  vector[0][trilinos_i] += value;
92  }
93 
94 
95 
96  template <>
97  inline void
98  ElementAccess<LinearAlgebra::EpetraWrappers::Vector>::set(
99  const double value,
100  const types::global_dof_index i,
102  {
103  // Extract local indices in the vector.
104  Epetra_FEVector vector = V.trilinos_vector();
105  TrilinosWrappers::types::int_type trilinos_i =
106  vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
107 
108  vector[0][trilinos_i] = value;
109  }
110 
111 
112  template <>
113  inline double
114  ElementAccess<LinearAlgebra::EpetraWrappers::Vector>::get(
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 } // namespace internal
127 
128 DEAL_II_NAMESPACE_CLOSE
129 
130 #endif
const Epetra_FEVector & trilinos_vector() const
unsigned long long int global_dof_index
Definition: types.h:72