version 3.10-dev
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_ENTITY_INDEX_MAP_HH
13#define DUMUX_ENTITY_INDEX_MAP_HH
14
15#include <vector>
16#include <utility>
17#include <dune/geometry/dimension.hh>
18
19namespace Dumux {
20
25template <class GridView, int codim = 0>
27{
28public:
29 using Grid = typename GridView::Traits::Grid;
30 using Entity = typename Grid::template Codim<codim>::Entity;
31 using EntitySeed = typename Grid::template Codim<codim>::EntitySeed;
32
34 EntityMap(const Grid& grid, std::vector<EntitySeed>&& seeds)
35 : grid_(grid)
36 , seeds_(std::move(seeds))
37 {}
38
40 template<class Mapper>
41 EntityMap(const Grid& grid, const Mapper& mapper)
42 : grid_(grid)
43 {
44 update(mapper);
45 }
46
48 void update(std::vector<EntitySeed>&& seeds)
49 { seeds_.swap(std::move(seeds)); }
50
52 template<class Mapper>
53 void update(const Mapper& mapper)
54 {
55 const auto& gv = grid_.leafGridView();
56 seeds_.resize(gv.size(codim));
57 for (const auto& entity : entities(gv, Dune::Codim<codim>()))
58 seeds_[mapper.index(entity)] = entity.seed();
59 }
60
62 Entity operator[](std::size_t i) const
63 { return grid_.entity(seeds_[i]); }
64
66 std::size_t size() const
67 { return seeds_.size(); }
68
69private:
70 const Grid& grid_;
71 std::vector<EntitySeed> seeds_;
72};
73
74template<class GridView>
76
77} // end namespace Dumux
78
79#endif
A map from indices to entities using grid entity seeds.
Definition: entitymap.hh:27
typename Grid::template Codim< codim >::EntitySeed EntitySeed
Definition: entitymap.hh:31
typename GridView::Traits::Grid Grid
Definition: entitymap.hh:29
std::size_t size() const
get the size of the map
Definition: entitymap.hh:66
EntityMap(const Grid &grid, std::vector< EntitySeed > &&seeds)
constructor moving a ready seed list in here
Definition: entitymap.hh:34
Entity operator[](std::size_t i) const
get an element from an index i
Definition: entitymap.hh:62
void update(std::vector< EntitySeed > &&seeds)
update the map after the grid changed
Definition: entitymap.hh:48
EntityMap(const Grid &grid, const Mapper &mapper)
constructor with all entities of codim
Definition: entitymap.hh:41
void update(const Mapper &mapper)
update the map after the grid changed
Definition: entitymap.hh:53
typename Grid::template Codim< codim >::Entity Entity
Definition: entitymap.hh:30
Definition: adapt.hh:17