Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (1.4)

persistentcontainer.hh
1#ifndef DUNE_MMESH_MISC_PERSISTENTCONTAINER_HH
2#define DUNE_MMESH_MISC_PERSISTENTCONTAINER_HH
3
4#include <unordered_map>
5#include <dune/grid/utility/persistentcontainer.hh>
6#include <dune/grid/utility/persistentcontainermap.hh>
7
8namespace Dune
9{
10
11 template< class HostGrid, int dim, class T >
12 class PersistentContainer< MMesh< HostGrid, dim >, T >
13 : public Dune::PersistentContainerMap<
14 MMesh< HostGrid, dim >,
15 typename MMesh< HostGrid, dim >::LocalIdSet,
16 std::unordered_map< typename MMesh< HostGrid, dim >::LocalIdSet::IdType, T > >
17 {
18 typedef MMesh< HostGrid, dim > G;
19 typedef PersistentContainerMap< G, typename G::LocalIdSet, std::unordered_map< typename G::LocalIdSet::IdType, T > > Base;
20 typedef typename MMesh< HostGrid, dim >::LocalIdSet IdSet;
21 typedef std::unordered_map< typename MMesh< HostGrid, dim >::LocalIdSet::IdType, T > Map;
22
23 public:
24 typedef typename Base::Grid Grid;
25 typedef typename Base::Value Value;
26
27 PersistentContainer ( const Grid &grid, int codim, const Value &value = Value() )
28 : Base( grid, codim, grid.localIdSet(), value )
29 {}
30
31 using Base::codimension;
32 using Base::migrateLevel;
33
34 void resize ( const Value &value = Value() )
35 {
36 if( sequence_ != this->grid_->sequence() )
37 {
38 Hybrid::forEach( std::make_index_sequence< Grid::dimension+1 >{},
39 [ & ]( auto i ){ if( i == this->codimension() ) this->template resize< i >( value ); } );
40 sequence_ = this->grid_->sequence();
41 }
42 }
43
44 template< int codim >
45 void resize ( const Value &value )
46 {
47 std::integral_constant< bool, Capabilities::hasEntity< Grid, codim >::v > hasEntity;
48 assert( codim == codimension() );
49
50 // add one id for caching entity during adaptation
51 if constexpr (codim == 0)
52 {
53 MMeshImpl::MultiId id ( { std::size_t(-4), std::size_t(-3), std::size_t(-2) } );
54 this->data_.insert( std::make_pair( id, value ) );
55 }
56
57 // add one id for a every caching codim 1 entity during adaptation
58 if constexpr (codim == 1)
59 {
60 MMeshImpl::MultiId eid0 ( { std::size_t(-4), std::size_t(-3) } );
61 this->data_.insert( std::make_pair( eid0, value ) );
62 MMeshImpl::MultiId eid1 ( { std::size_t(-4), std::size_t(-2) } );
63 this->data_.insert( std::make_pair( eid1, value ) );
64 MMeshImpl::MultiId eid2 ( { std::size_t(-3), std::size_t(-2) } );
65 this->data_.insert( std::make_pair( eid2, value ) );
66 }
67
68 // add one id for every caching vertex during adaptation
69 if constexpr (codim == dim)
70 {
71 MMeshImpl::MultiId vid0 ( std::size_t(-4) );
72 this->data_.insert( std::make_pair( vid0, value ) );
73 MMeshImpl::MultiId vid1 ( std::size_t(-3) );
74 this->data_.insert( std::make_pair( vid1, value ) );
75 MMeshImpl::MultiId vid2 ( std::size_t(-2) );
76 this->data_.insert( std::make_pair( vid2, value ) );
77 }
78
79 // create empty map, but keep old data
80 Map data;
81
82 // add new entries
83 this->template migrateLevel< codim >( 0, value, data, hasEntity );
84 }
85
86 private:
87 int sequence_ = -1;
88
89 };
90
91 template< class MMesh, class T >
92 class PersistentContainer< MMeshInterfaceGrid< MMesh >, T >
93 : public Dune::PersistentContainerMap<
94 MMeshInterfaceGrid< MMesh >,
95 typename MMeshInterfaceGrid< MMesh >::LocalIdSet,
96 std::unordered_map< typename MMeshInterfaceGrid< MMesh >::LocalIdSet::IdType, T > >
97 {
98 typedef MMeshInterfaceGrid< MMesh > G;
99 typedef PersistentContainerMap< G, typename G::LocalIdSet, std::unordered_map< typename G::LocalIdSet::IdType, T > > Base;
100 typedef typename MMeshInterfaceGrid< MMesh >::LocalIdSet IdSet;
101 typedef std::unordered_map< typename MMeshInterfaceGrid< MMesh >::LocalIdSet::IdType, T > Map;
102 static constexpr int dim = MMesh::dimensionworld-1;
103
104 public:
105 typedef typename Base::Grid Grid;
106 typedef typename Base::Value Value;
107
108 PersistentContainer ( const Grid &grid, int codim, const Value &value = Value() )
109 : Base( grid, codim, grid.localIdSet(), value )
110 {}
111
112 using Base::codimension;
113 using Base::migrateLevel;
114
115 void resize ( const Value &value = Value() )
116 {
117 if( sequence_ != this->grid_->sequence() )
118 {
119 Hybrid::forEach( std::make_index_sequence< Grid::dimension+1 >{},
120 [ & ]( auto i ){ if( i == this->codimension() ) this->template resize< i >( value ); } );
121 sequence_ = this->grid_->sequence();
122 }
123 }
124
125 template< int codim >
126 void resize ( const Value &value )
127 {
128 std::integral_constant< bool, Capabilities::hasEntity< Grid, codim >::v > hasEntity;
129 assert( codim == codimension() );
130
131 // add one id for caching entity during adaptation
132 if constexpr (codim == 0)
133 {
134 MMeshImpl::MultiId id ( { std::size_t(-3), std::size_t(-2)} );
135 this->data_.insert( std::make_pair( id, value ) );
136 }
137
138 // add one id for every caching vertex during adaptation
139 if constexpr (codim == dim)
140 {
141 MMeshImpl::MultiId vid0 ( std::size_t(-3) );
142 this->data_.insert( std::make_pair( vid0, value ) );
143 MMeshImpl::MultiId vid1 ( std::size_t(-2) );
144 this->data_.insert( std::make_pair( vid1, value ) );
145 }
146
147 // create empty map, but keep old data
148 Map data;
149
150 // add new entries
151 this->template migrateLevel< codim >( 0, value, data, hasEntity );
152 }
153
154 private:
155 int sequence_ = -1;
156
157 };
158
159} // namespace Dune
160
161#endif // #ifndef DUNE_MMESH_MISC_PERSISTENTCONTAINER_HH
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 13, 22:42, 2025)