3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
entitymap.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_ENTITY_INDEX_MAP_HH
25#define DUMUX_ENTITY_INDEX_MAP_HH
26
27#include <vector>
28#include <utility>
29#include <dune/geometry/dimension.hh>
30
31namespace Dumux {
32
37template <class GridView, int codim = 0>
39{
40public:
41 using Grid = typename GridView::Traits::Grid;
42 using Entity = typename Grid::template Codim<codim>::Entity;
43 using EntitySeed = typename Grid::template Codim<codim>::EntitySeed;
44
46 EntityMap(const Grid& grid, std::vector<EntitySeed>&& seeds)
47 : grid_(grid)
48 , seeds_(std::move(seeds))
49 {}
50
52 template<class Mapper>
53 EntityMap(const Grid& grid, const Mapper& mapper)
54 : grid_(grid)
55 {
56 update(mapper);
57 }
58
60 void update(std::vector<EntitySeed>&& seeds)
61 { seeds_.swap(std::move(seeds)); }
62
64 template<class Mapper>
65 void update(const Mapper& mapper)
66 {
67 const auto& gv = grid_.leafGridView();
68 seeds_.resize(gv.size(codim));
69 for (const auto& entity : entities(gv, Dune::Codim<codim>()))
70 seeds_[mapper.index(entity)] = entity.seed();
71 }
72
74 Entity operator[](std::size_t i) const
75 { return grid_.entity(seeds_[i]); }
76
78 std::size_t size() const
79 { return seeds_.size(); }
80
81private:
82 const Grid& grid_;
83 std::vector<EntitySeed> seeds_;
84};
85
86template<class GridView>
88
89} // end namespace Dumux
90
91#endif
Definition: adapt.hh:29
A map from indices to entities using grid entity seeds.
Definition: entitymap.hh:39
typename Grid::template Codim< codim >::EntitySeed EntitySeed
Definition: entitymap.hh:43
typename GridView::Traits::Grid Grid
Definition: entitymap.hh:41
std::size_t size() const
get the size of the map
Definition: entitymap.hh:78
EntityMap(const Grid &grid, std::vector< EntitySeed > &&seeds)
constructor moving a ready seed list in here
Definition: entitymap.hh:46
Entity operator[](std::size_t i) const
get an element from an index i
Definition: entitymap.hh:74
void update(std::vector< EntitySeed > &&seeds)
update the map after the grid changed
Definition: entitymap.hh:60
EntityMap(const Grid &grid, const Mapper &mapper)
constructor with all entites of codim
Definition: entitymap.hh:53
void update(const Mapper &mapper)
update the map after the grid changed
Definition: entitymap.hh:65
typename Grid::template Codim< codim >::Entity Entity
Definition: entitymap.hh:42