Dune Core Modules (2.3.1)

persistentcontainervector.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_PERSISTENTCONTAINERVECTOR_HH
4#define DUNE_PERSISTENTCONTAINERVECTOR_HH
5
6#include <algorithm>
7#include <cassert>
8
9namespace Dune
10{
11
12 // PersistentContainerVector
13 // -------------------------
14
16 template< class G, class IndexSet, class Vector >
18 {
20
21 public:
22 typedef G Grid;
23
24 typedef typename Vector::value_type Value;
25 typedef typename Vector::size_type Size;
26 typedef typename Vector::const_iterator ConstIterator;
27 typedef typename Vector::iterator Iterator;
28
29 typedef typename Vector::allocator_type Allocator;
30
31 PersistentContainerVector ( const IndexSet &indexSet, int codim, const Value &value,
32 const Allocator &allocator = Allocator() )
33 : codim_( codim ),
34 indexSet_( &indexSet ),
35 data_( indexSet.size( codim ), value, allocator )
36 {}
37
38 template< class Entity >
39 const Value &operator[] ( const Entity &entity ) const
40 {
41 assert( Entity::codimension == codimension() );
42 const Size index = indexSet().index( entity );
43 assert( index < data_.size() );
44 return data_[ index ];
45 }
46
47 template< class Entity >
48 Value &operator[] ( const Entity &entity )
49 {
50 assert( Entity::codimension == codimension() );
51 const Size index = indexSet().index( entity );
52 assert( index < data_.size() );
53 return data_[ index ];
54 }
55
56 template< class Entity >
57 const Value &operator() ( const Entity &entity, int subEntity ) const
58 {
59 const Size index = indexSet().subIndex( entity, subEntity, codimension() );
60 assert( index < data_.size() );
61 return data_[ index ];
62 }
63
64 template< class Entity >
65 Value &operator() ( const Entity &entity, int subEntity )
66 {
67 const Size index = indexSet().subIndex( entity, subEntity, codimension() );
68 assert( index < data_.size() );
69 return data_[ index ];
70 }
71
72 Size size () const { return data_.size(); }
73
74 void resize ( const Value &value = Value() )
75 {
76 const Size indexSetSize = indexSet().size( codimension() );
77 data_.resize( indexSetSize, value );
78 }
79
80 void shrinkToFit () {}
81
82 void fill ( const Value &value ) { std::fill( begin(), end(), value ); }
83
84 void swap ( This &other )
85 {
86 std::swap( codim_, other.codim_ );
87 std::swap( indexSet_, other.indexSet_ );
88 std::swap( data_, other.data_ );
89 }
90
91 ConstIterator begin () const { return data_.begin(); }
92 Iterator begin () { return data_.begin(); }
93
94 ConstIterator end () const { return data_.end(); }
95 Iterator end () { return data_.end(); }
96
97 int codimension () const { return codim_; }
98
99
100 // deprecated stuff, will be removed after Dune 2.3
101
102 typedef Grid GridType DUNE_DEPRECATED_MSG("Use Grid instead.");
103 typedef Value Data DUNE_DEPRECATED_MSG("Use Value instead.");
104
105 void reserve () DUNE_DEPRECATED_MSG("Use resize() instead.")
106 { return resize(); }
107
108 void clear () DUNE_DEPRECATED_MSG("Use resize() instead.")
109 {
110 resize( Value() );
111 shrinkToFit();
112 fill( Value() );
113 }
114
115 void update () DUNE_DEPRECATED_MSG("Use resize() instead.")
116 {
117 resize( Value() );
118 shrinkToFit();
119 }
120
121 protected:
122 const IndexSet &indexSet () const { return *indexSet_; }
123
124 int codim_;
125 const IndexSet *indexSet_;
126 Vector data_;
127 };
128
129} // namespace Dune
130
131#endif // #ifndef DUNE_PERSISTENTCONTAINERVECTOR_HH
Wrapper class for entities.
Definition: entity.hh:57
@ codimension
Know your own codimension.
Definition: entity.hh:99
Index Set Interface base class.
Definition: indexidset.hh:78
IndexType index(const typename remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: indexidset.hh:107
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:204
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:146
vector-based implementation of the PersistentContainer
Definition: persistentcontainervector.hh:18
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
Dune namespace.
Definition: alignment.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)