dune-istl  2.9.0
transfer.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_AMGTRANSFER_HH
6 #define DUNE_AMGTRANSFER_HH
7 
8 #include <dune/istl/bvector.hh>
10 #include <dune/istl/paamg/pinfo.hh>
13 #include <dune/common/exceptions.hh>
14 
15 namespace Dune
16 {
17  namespace Amg
18  {
19 
30  template<class V1, class V2, class T>
31  class Transfer
32  {
33 
34  public:
35  typedef V1 Vertex;
36  typedef V2 Vector;
37 
38  template<typename T1, typename R>
39  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
40  Vector& fineRedist,T1 damp, R& redistributor=R());
41 
42  template<typename T1, typename R>
43  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
44  T1 damp);
45 
46  static void restrictVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, const Vector& fine,
47  T& comm);
48  };
49 
50  template<class V,class V1>
52  {
53  public:
54  typedef V Vertex;
55  typedef V1 Vector;
57  template<typename T1>
58  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
59  Vector& fineRedist, T1 damp,
61  const Redist& redist=Redist());
62  template<typename T1>
63  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
64  T1 damp,
66 
67 
68  static void restrictVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, const Vector& fine,
69  const SequentialInformation& comm);
70  };
71 
72 #if HAVE_MPI
73 
74  template<class V,class V1, class T1, class T2>
76  {
77  public:
78  typedef V Vertex;
79  typedef V1 Vector;
81  template<typename T3>
82  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
83  Vector& fineRedist, T3 damp, OwnerOverlapCopyCommunication<T1,T2>& comm,
84  const Redist& redist);
85  template<typename T3>
86  static void prolongateVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, Vector& fine,
88 
89  static void restrictVector(const AggregatesMap<Vertex>& aggregates, Vector& coarse, const Vector& fine,
91  };
92 
93 #endif
94 
95  template<class V, class V1>
96  template<typename T>
97  inline void
99  Vector& coarse, Vector& fine,
100  [[maybe_unused]] Vector& fineRedist,
101  T damp,
102  [[maybe_unused]] const SequentialInformation& comm,
103  [[maybe_unused]] const Redist& redist)
104  {
105  prolongateVector(aggregates, coarse, fine, damp);
106  }
107  template<class V, class V1>
108  template<typename T>
109  inline void
111  Vector& coarse, Vector& fine,
112  T damp,
113  [[maybe_unused]] const SequentialInformation& comm)
114  {
115  typedef typename Vector::iterator Iterator;
116 
117  Iterator end = coarse.end();
118  Iterator begin= coarse.begin();
119  for(; begin!=end; ++begin)
120  *begin*=damp;
121  end=fine.end();
122  begin=fine.begin();
123 
124  for(Iterator block=begin; block != end; ++block) {
125  std::ptrdiff_t index=block-begin;
126  const Vertex& vertex = aggregates[index];
127  if(vertex != AggregatesMap<Vertex>::ISOLATED)
128  *block += coarse[aggregates[index]];
129  }
130  }
131 
132  template<class V, class V1>
133  inline void
135  Vector& coarse,
136  const Vector& fine,
137  [[maybe_unused]] const SequentialInformation& comm)
138  {
139  // Set coarse vector to zero
140  coarse=0;
141 
142  typedef typename Vector::const_iterator Iterator;
143  Iterator end = fine.end();
144  Iterator begin=fine.begin();
145 
146  for(Iterator block=begin; block != end; ++block) {
147  const Vertex& vertex = aggregates[block-begin];
148  if(vertex != AggregatesMap<Vertex>::ISOLATED)
149  coarse[vertex] += *block;
150  }
151  }
152 
153 #if HAVE_MPI
154  template<class V, class V1, class T1, class T2>
155  template<typename T3>
156  inline void Transfer<V,V1,OwnerOverlapCopyCommunication<T1,T2> >::prolongateVector(const AggregatesMap<Vertex>& aggregates,
157  Vector& coarse, Vector& fine,
158  Vector& fineRedist, T3 damp,
160  const Redist& redist)
161  {
162  if(fineRedist.size()>0)
163  // we operated on the coarse level
164  Transfer<V,V1,SequentialInformation>::prolongateVector(aggregates, coarse, fineRedist, damp);
165 
166  // TODO This could be accomplished with one communication, too!
167  redist.redistributeBackward(fine, fineRedist);
168  comm.copyOwnerToAll(fine,fine);
169  }
170 
171  template<class V, class V1, class T1, class T2>
172  template<typename T3>
173  inline void Transfer<V,V1,OwnerOverlapCopyCommunication<T1,T2> >::prolongateVector(
174  const AggregatesMap<Vertex>& aggregates,
175  Vector& coarse, Vector& fine, T3 damp,
176  [[maybe_unused]] OwnerOverlapCopyCommunication<T1,T2>& comm)
177  {
178  Transfer<V,V1,SequentialInformation>::prolongateVector(aggregates, coarse, fine, damp);
179  }
180  template<class V, class V1, class T1, class T2>
181  inline void Transfer<V,V1,OwnerOverlapCopyCommunication<T1,T2> >::restrictVector(const AggregatesMap<Vertex>& aggregates,
182  Vector& coarse, const Vector& fine,
184  {
186  // We need this here to avoid it in the smoothers on the coarse level.
187  // There (in the preconditioner d is const.
188  comm.project(coarse);
189  }
190 #endif
192  } // namspace Amg
193 } // namspace Dune
194 #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:11
Definition: matrixredistribute.hh:22
void redistributeBackward([[maybe_unused]] D &from, [[maybe_unused]]const D &to) const
Definition: matrixredistribute.hh:32
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:174
void project(T1 &x) const
Set vector to zero at copy dofs.
Definition: owneroverlapcopy.hh:538
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition: owneroverlapcopy.hh:311
Definition: pinfo.hh:28
Definition: transfer.hh:32
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:35
V2 Vector
Definition: transfer.hh:36
RedistributeInformation< SequentialInformation > Redist
Definition: transfer.hh:56
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:80
static void prolongateVector(const AggregatesMap< Vertex > &aggregates, Vector &coarse, Vector &fine, T3 damp, OwnerOverlapCopyCommunication< T1, T2 > &comm)