dune-grid 2.9.0
scsgmapper.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_GRID_COMMON_SCSGMAPPER_HH
6#define DUNE_GRID_COMMON_SCSGMAPPER_HH
7
8#include <iostream>
9#include "mapper.hh"
10
12
19namespace Dune
20{
37 template <typename GV, int c>
39 public Mapper<typename GV::Grid,SingleCodimSingleGeomTypeMapper<GV,c>, typename GV::IndexSet::IndexType >
40 {
41 public:
42
44 typedef typename GV::IndexSet::IndexType Index;
45
50 using size_type = decltype(std::declval<typename GV::IndexSet>().size(0));
51
57 : gridView_(gridView)
58 , indexSet_(&gridView_.indexSet())
59 {
60 // check that grid has only a single geometry type
61 if (indexSet_->types(c).size() != 1)
62 DUNE_THROW(GridError, "mapper treats only a single codim and a single geometry type");
63 }
64
70 template<class EntityType>
71 Index index (const EntityType& e) const
72 {
73 static_assert(EntityType::codimension == c, "Entity of wrong codim passed to SingleCodimSingleGeomTypeMapper");
74 return indexSet_->index(e);
75 }
76
84 Index subIndex (const typename GV::template Codim<0>::Entity& e,
85 int i, unsigned int codim) const
86 {
87 if (codim != c)
88 DUNE_THROW(GridError, "Id of wrong codim requested from SingleCodimSingleGeomTypeMapper");
89 return indexSet_->subIndex(e,i,codim);
90 }
91
101 {
102 return indexSet_->size(c);
103 }
104
111 template<class EntityType>
112 bool contains (const EntityType& e, Index& result) const
113 {
114 result = index(e);
115 return true;
116 }
117
126 bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, Index& result) const
127 {
128 result = subIndex(e,i,cc);
129 return true;
130 }
131
137 void update (const GV& gridView)
138 {
139 gridView_ = gridView;
140 indexSet_ = &gridView_.indexSet();
141 }
142
148 void update (GV&& gridView)
149 {
150 gridView_ = std::move(gridView);
151 indexSet_ = &gridView_.indexSet();
152 }
153
156 [[deprecated("Use update(gridView) instead! Will be removed after release 2.8.")]]
157 void update ()
158 { // nothing to do here
159 }
160
161 private:
162 GV gridView_;
163 const typename GV::IndexSet* indexSet_;
164 };
165
184 template <typename G, int c>
185 class [[deprecated("Use SingleCodimSingleGeomTypeMapper instead! Will be removed after release 2.8.")]]
186 LeafSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<typename G::LeafGridView,c> {
188 public:
193 : Base(grid.leafGridView())
194 , gridPtr_(&grid)
195 {}
196
202 void update ()
203 {
204 Base::update(gridPtr_->leafGridView());
205 }
206
207 private:
208 const G* gridPtr_;
209 };
210
222 template <typename G, int c>
223 class [[deprecated("Use SingleCodimSingleGeomTypeMapper instead! Will be removed after release 2.8.")]]
224 LevelSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<typename G::LevelGridView,c> {
226 public:
227 /* @brief The constructor
228 @param grid A reference to a grid.
229 @param level A valid level of the grid.
230 */
231 LevelSingleCodimSingleGeomTypeMapper (const G& grid, int level)
232 : Base(grid.levelGridView(level))
233 , gridPtr_(&grid)
234 , level_(level)
235 {}
236
242 void update ()
243 {
244 Base::update(gridPtr_->levelGridView(level_));
245 }
246
247 private:
248 const G* gridPtr_;
249 int level_;
250 };
251
253}
254#endif
Provides classes with basic mappers which are used to attach data to a grid.
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
leaf grid view for the given grid
Definition: common/grid.hh:819
Grid< dim, dimworld, ct, GridFamily >::LevelGridView levelGridView(const Grid< dim, dimworld, ct, GridFamily > &grid, int level)
level grid view for the given grid and level.
Definition: common/grid.hh:802
Include standard header files.
Definition: agrid.hh:60
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:20
Mapper interface.
Definition: mapper.hh:110
Implementation class for a single codim and single geometry type mapper.
Definition: scsgmapper.hh:40
bool contains(const EntityType &e, Index &result) const
Returns true if the entity is contained in the index set.
Definition: scsgmapper.hh:112
GV::IndexSet::IndexType Index
Number type used for indices.
Definition: scsgmapper.hh:44
bool contains(const typename GV::template Codim< 0 >::Entity &e, int i, int cc, Index &result) const
Returns true if the entity is contained in the index set.
Definition: scsgmapper.hh:126
decltype(std::declval< typename GV::IndexSet >().size(0)) size_type
Number type used for the overall size (the return value of the 'size' method)
Definition: scsgmapper.hh:50
Index index(const EntityType &e) const
Map entity to array index.
Definition: scsgmapper.hh:71
Index subIndex(const typename GV::template Codim< 0 >::Entity &e, int i, unsigned int codim) const
Map subentity of codim 0 entity to array index.
Definition: scsgmapper.hh:84
SingleCodimSingleGeomTypeMapper(const GV &gridView)
Construct mapper from grid and one of its index sets.
Definition: scsgmapper.hh:56
void update(GV &&gridView)
Recalculates indices after grid adaptation.
Definition: scsgmapper.hh:148
size_type size() const
Return total number of entities in the entity set managed by the mapper.
Definition: scsgmapper.hh:100
void update()
Recalculates indices after grid adaptation.
Definition: scsgmapper.hh:157
void update(const GV &gridView)
Recalculates indices after grid adaptation.
Definition: scsgmapper.hh:137
Single codim and single geometry type mapper for leaf entities.
Definition: scsgmapper.hh:186
LeafSingleCodimSingleGeomTypeMapper(const G &grid)
The constructor.
Definition: scsgmapper.hh:192
void update()
Recalculates indices after grid adaptation.
Definition: scsgmapper.hh:202
Single codim and single geometry type mapper for entities of one level.
Definition: scsgmapper.hh:224
LevelSingleCodimSingleGeomTypeMapper(const G &grid, int level)
Definition: scsgmapper.hh:231
void update()
Recalculates indices after grid adaptation.
Definition: scsgmapper.hh:242
Different resources needed by all grid implementations.