DUNE PDELab (2.8)

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
47 template< class G, class IndexSet, class Vector >
49 {
51
52 public:
53 typedef G Grid;
54
55 typedef typename Vector::value_type Value;
56 typedef typename Vector::size_type Size;
57 typedef typename Vector::const_iterator ConstIterator;
58 typedef typename Vector::iterator Iterator;
59
60 typedef typename Vector::allocator_type Allocator;
61
62 PersistentContainerVector ( const IndexSet &indexSet, int codim, const Value &value,
63 const Allocator &allocator = Allocator() )
64 : codim_( codim ),
65 indexSet_( &indexSet ),
66 data_( indexSet.size( codim ), value, allocator )
67 {}
68
69 template< class Entity >
70 const Value &operator[] ( const Entity &entity ) const
71 {
72 assert( Entity::codimension == codimension() );
73 const Size index = indexSet().index( entity );
74 assert( index < data_.size() );
75 return data_[ index ];
76 }
77
78 template< class Entity >
79 Value &operator[] ( const Entity &entity )
80 {
81 assert( Entity::codimension == codimension() );
82 const Size index = indexSet().index( entity );
83 assert( index < data_.size() );
84 return data_[ index ];
85 }
86
87 template< class Entity >
88 const Value &operator() ( const Entity &entity, int subEntity ) const
89 {
90 const Size index = indexSet().subIndex( entity, subEntity, codimension() );
91 assert( index < data_.size() );
92 return data_[ index ];
93 }
94
95 template< class Entity >
96 Value &operator() ( const Entity &entity, int subEntity )
97 {
98 const Size index = indexSet().subIndex( entity, subEntity, codimension() );
99 assert( index < data_.size() );
100 return data_[ index ];
101 }
102
103 Size size () const { return data_.size(); }
104
105 void resize ( const Value &value = Value() )
106 {
107 const Size indexSetSize = indexSet().size( codimension() );
108 data_.resize( indexSetSize, value );
109 }
110
111 void shrinkToFit () {}
112
113 void fill ( const Value &value ) { std::fill( begin(), end(), value ); }
114
115 void swap ( This &other )
116 {
117 std::swap( codim_, other.codim_ );
118 std::swap( indexSet_, other.indexSet_ );
119 std::swap( data_, other.data_ );
120 }
121
122 ConstIterator begin () const { return data_.begin(); }
123 Iterator begin () { return data_.begin(); }
124
125 ConstIterator end () const { return data_.end(); }
126 Iterator end () { return data_.end(); }
127
128 int codimension () const { return codim_; }
129
130 protected:
131 const IndexSet &indexSet () const { return *indexSet_; }
132
133 int codim_;
134 const IndexSet *indexSet_;
135 Vector data_;
136 };
137
138} // namespace Dune
139
140#endif // #ifndef DUNE_PERSISTENTCONTAINERVECTOR_HH
Wrapper class for entities.
Definition: entity.hh:64
@ codimension
Know your own codimension.
Definition: entity.hh:105
Index Set Interface base class.
Definition: indexidset.hh:76
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:221
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:151
IndexType index(const typename 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:111
vector-based implementation of the PersistentContainer
Definition: persistentcontainervector.hh:49
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)