vertexborderlistfromgrid.hh
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 /*
4  Copyright (C) 2011-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
25 #ifndef EWOMS_VERTEX_BORDER_LIST_FROM_GRID_HH
26 #define EWOMS_VERTEX_BORDER_LIST_FROM_GRID_HH
27 
28 #include "overlaptypes.hh"
29 #include "blacklist.hh"
30 
31 #include <dune/grid/common/datahandleif.hh>
32 #include <dune/grid/common/gridenums.hh>
33 #include <dune/istl/bcrsmatrix.hh>
34 #include <dune/istl/scalarproducts.hh>
35 #include <dune/istl/operators.hh>
36 #include <dune/common/version.hh>
37 
38 #include <algorithm>
39 
40 namespace Ewoms {
41 namespace Linear {
51 template <class GridView, class VertexMapper>
53  : public Dune::CommDataHandleIF<VertexBorderListFromGrid<GridView, VertexMapper>,
54  int>
55 {
56  static const int dimWorld = GridView::dimensionworld;
57 
58 public:
59  VertexBorderListFromGrid(const GridView &gridView, const VertexMapper &map)
60  : gridView_(gridView), map_(map)
61  {
62  gridView.communicate(*this,
63  Dune::InteriorBorder_InteriorBorder_Interface,
64  Dune::ForwardCommunication);
65 
66  auto vIt = gridView.template begin<dimWorld>();
67  const auto& vEndIt = gridView.template end<dimWorld >();
68  for (; vIt != vEndIt; ++vIt) {
69  if (vIt->partitionType() != Dune::InteriorEntity
70  && vIt->partitionType() != Dune::BorderEntity)
71  {
72 #if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 4)
73  int vIdx = map_.index(*vIt);
74 #else
75  int vIdx = map_.map(*vIt);
76 #endif
77  blackList_.addIndex(vIdx);
78  }
79  }
80  }
81 
82  // data handle methods
83  bool contains(int dim, int codim) const
84  { return dim == codim; }
85 
86  bool fixedsize(int dim, int codim) const
87  { return true; }
88 
89  template <class EntityType>
90  size_t size(const EntityType &e) const
91  { return 2; }
92 
93  template <class MessageBufferImp, class EntityType>
94  void gather(MessageBufferImp &buff, const EntityType &e) const
95  {
96  buff.write(static_cast<int>(gridView_.comm().rank()));
97 #if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 4)
98  buff.write(static_cast<int>(map_.index(e)));
99 #else
100  buff.write(static_cast<int>(map_.map(e)));
101 #endif
102  }
103 
104  template <class MessageBufferImp, class EntityType>
105  void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
106  {
107  BorderIndex bIdx;
108 
109 #if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 4)
110  bIdx.localIdx = map_.index(e);
111 #else
112  bIdx.localIdx = map_.map(e);
113 #endif
114  {
115  int tmp;
116  buff.read(tmp);
117  bIdx.peerRank = tmp;
118  }
119  {
120  int tmp;
121  buff.read(tmp);
122  bIdx.peerIdx = tmp;
123  }
124  bIdx.borderDistance = 0;
125 
126  borderList_.push_back(bIdx);
127  }
128 
129  // Access to the border list.
130  const BorderList &borderList() const
131  { return borderList_; }
132 
133  // Access to the black-list indices.
134  const BlackList& blackList() const
135  { return blackList_; }
136 
137 private:
138  const GridView gridView_;
139  const VertexMapper &map_;
140  BorderList borderList_;
141  BlackList blackList_;
142 };
143 
144 } // namespace Linear
145 } // namespace Ewoms
146 
147 #endif
This files provides several data structures for storing tuples of indices of remote and/or local proc...
Expresses which degrees of freedom are blacklisted for the parallel linear solvers and which domestic...
Definition: blacklist.hh:45
VertexBorderListFromGrid(const GridView &gridView, const VertexMapper &map)
Definition: vertexborderlistfromgrid.hh:59
Uses communication on the grid to find the initial seed list of indices.
Definition: vertexborderlistfromgrid.hh:52
BorderDistance borderDistance
Distance to the process border for the peer (in hops)
Definition: overlaptypes.hh:112
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
Definition: vertexborderlistfromgrid.hh:105
std::list< BorderIndex > BorderList
This class managages a list of indices which are on the border of a process' partition of the grid...
Definition: overlaptypes.hh:119
const BlackList & blackList() const
Definition: vertexborderlistfromgrid.hh:134
size_t size(const EntityType &e) const
Definition: vertexborderlistfromgrid.hh:90
Index localIdx
Index of the entity for the local process.
Definition: overlaptypes.hh:103
bool contains(int dim, int codim) const
Definition: vertexborderlistfromgrid.hh:83
Index peerIdx
Index of the entity for the peer process.
Definition: overlaptypes.hh:106
A single index intersecting with the process boundary.
Definition: overlaptypes.hh:100
Definition: baseauxiliarymodule.hh:35
bool fixedsize(int dim, int codim) const
Definition: vertexborderlistfromgrid.hh:86
const BorderList & borderList() const
Definition: vertexborderlistfromgrid.hh:130
void gather(MessageBufferImp &buff, const EntityType &e) const
Definition: vertexborderlistfromgrid.hh:94
ProcessRank peerRank
Rank of the peer process.
Definition: overlaptypes.hh:109
void addIndex(Index nativeIdx)
Definition: blacklist.hh:63
Expresses which degrees of freedom are blacklisted for the parallel linear solvers and which domestic...