dune-istl  2.8.0
transfer.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_AMGTRANSFER_HH
4 #define DUNE_AMGTRANSFER_HH
5 
6 #include <dune/istl/bvector.hh>
11 #include <dune/common/exceptions.hh>
12 
13 namespace Dune
14 {
15  namespace Amg
16  {
17 
28  template<class V1, class V2, class T>
29  class Transfer
30  {
31 
32  public:
33  typedef V1 Vertex;
34  typedef V2 Vector;
35 
36  template<typename T1, typename R>
37  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
38  Vector& fineRedist,T1 damp, R& redistributor=R());
39 
40  template<typename T1, typename R>
41  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
42  T1 damp);
43 
44  static void restrictVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, const Vector& fine,
45  T& comm);
46  };
47 
48  template<class V,class V1>
50  {
51  public:
52  typedef V Vertex;
53  typedef V1 Vector;
55  template<typename T1>
56  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
57  Vector& fineRedist, T1 damp,
59  const Redist& redist=Redist());
60  template<typename T1>
61  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
62  T1 damp,
64 
65 
66  static void restrictVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, const Vector& fine,
67  const SequentialInformation& comm);
68  };
69 
70 #if HAVE_MPI
71 
72  template<class V,class V1, class T1, class T2>
74  {
75  public:
76  typedef V Vertex;
77  typedef V1 Vector;
79  template<typename T3>
80  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
81  Vector& fineRedist, T3 damp, OwnerOverlapCopyCommunication<T1,T2>& comm,
82  const Redist& redist);
83  template<typename T3>
84  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
86 
87  static void restrictVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, const Vector& fine,
89  };
90 
91 #endif
92 
93  template<class V, class V1>
94  template<typename T>
95  inline void
97  Vector& coarse, Vector& fine,
98  [[maybe_unused]] Vector& fineRedist,
99  T damp,
100  [[maybe_unused]] const SequentialInformation& comm,
101  [[maybe_unused]] const Redist& redist)
102  {
103  prolongateVector(aggregates, coarse, fine, damp);
104  }
105  template<class V, class V1>
106  template<typename T>
107  inline void
109  Vector& coarse, Vector& fine,
110  T damp,
111  [[maybe_unused]] const SequentialInformation& comm)
112  {
113  typedef typename Vector::iterator Iterator;
114 
115  Iterator end = coarse.end();
116  Iterator begin= coarse.begin();
117  for(; begin!=end; ++begin)
118  *begin*=damp;
119  end=fine.end();
120  begin=fine.begin();
121 
122  for(Iterator block=begin; block != end; ++block) {
123  std::ptrdiff_t index=block-begin;
124  const Vertex& vertex = aggregates[index];
125  if(vertex != AggregatesMap<Vertex>::ISOLATED)
126  *block += coarse[aggregates[index]];
127  }
128  }
129 
130  template<class V, class V1>
131  inline void
133  Vector& coarse,
134  const Vector& fine,
135  [[maybe_unused]] const SequentialInformation& comm)
136  {
137  // Set coarse vector to zero
138  coarse=0;
139 
140  typedef typename Vector::const_iterator Iterator;
141  Iterator end = fine.end();
142  Iterator begin=fine.begin();
143 
144  for(Iterator block=begin; block != end; ++block) {
145  const Vertex& vertex = aggregates[block-begin];
146  if(vertex != AggregatesMap<Vertex>::ISOLATED)
147  coarse[vertex] += *block;
148  }
149  }
150 
151 #if HAVE_MPI
152  template<class V, class V1, class T1, class T2>
153  template<typename T3>
154  inline void Transfer<V,V1,OwnerOverlapCopyCommunication<T1,T2> >::prolongateVector(const AggregatesMap<Vertex>& aggregates,
155  Vector& coarse, Vector& fine,
156  Vector& fineRedist, T3 damp,
158  const Redist& redist)
159  {
160  if(fineRedist.size()>0)
161  // we operated on the coarse level
162  Transfer<V,V1,SequentialInformation>::prolongateVector(aggregates, coarse, fineRedist, damp);
163 
164  // TODO This could be accomplished with one communication, too!
165  redist.redistributeBackward(fine, fineRedist);
166  comm.copyOwnerToAll(fine,fine);
167  }
168 
169  template<class V, class V1, class T1, class T2>
170  template<typename T3>
171  inline void Transfer<V,V1,OwnerOverlapCopyCommunication<T1,T2> >::prolongateVector(
172  const AggregatesMap<Vertex>& aggregates,
173  Vector& coarse, Vector& fine, T3 damp,
174  [[maybe_unused]] OwnerOverlapCopyCommunication<T1,T2>& comm)
175  {
176  Transfer<V,V1,SequentialInformation>::prolongateVector(aggregates, coarse, fine, damp);
177  }
178  template<class V, class V1, class T1, class T2>
179  inline void Transfer<V,V1,OwnerOverlapCopyCommunication<T1,T2> >::restrictVector(const AggregatesMap<Vertex>& aggregates,
180  Vector& coarse, const Vector& fine,
182  {
184  // We need this here to avoid it in the smoothers on the coarse level.
185  // There (in the preconditioner d is const.
186  comm.project(coarse);
187  }
188 #endif
190  } // namspace Amg
191 } // namspace Dune
192 #endif
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Functionality for redistributing a sparse matrix.
Classes providing communication interfaces for overlapping Schwarz methods.
Provides classes for the Coloring process of AMG.
Definition: allocator.hh:9
Definition: matrixredistribute.hh:20
void redistributeBackward([[maybe_unused]] D &from, [[maybe_unused]]const D &to) const
Definition: matrixredistribute.hh:30
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:172
void project(T1 &x) const
Set vector to zero at copy dofs.
Definition: owneroverlapcopy.hh:536
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition: owneroverlapcopy.hh:309
Definition: pinfo.hh:26
Definition: transfer.hh:30
static void restrictVector(const AggregatesMap< Vertex > &aggregates, Vector &coarse, const Vector &fine, T &comm)
static void prolongateVector(const AggregatesMap< Vertex > &aggregates, Vector &coarse, Vector &fine, T1 damp)
static void prolongateVector(const AggregatesMap< Vertex > &aggregates, Vector &coarse, Vector &fine, Vector &fineRedist, T1 damp, R &redistributor=R())
V1 Vertex
Definition: transfer.hh:33
V2 Vector
Definition: transfer.hh:34
RedistributeInformation< SequentialInformation > Redist
Definition: transfer.hh:54
static void prolongateVector(const AggregatesMap< Vertex > &aggregates, Vector &coarse, Vector &fine, Vector &fineRedist, T1 damp, const SequentialInformation &comm=SequentialInformation(), const Redist &redist=Redist())
static void prolongateVector(const AggregatesMap< Vertex > &aggregates, Vector &coarse, Vector &fine, T1 damp, const SequentialInformation &comm=SequentialInformation())
RedistributeInformation< OwnerOverlapCopyCommunication< T1, T2 > > Redist
Definition: transfer.hh:78
static void prolongateVector(const AggregatesMap< Vertex > &aggregates, Vector &coarse, Vector &fine, T3 damp, OwnerOverlapCopyCommunication< T1, T2 > &comm)