dune-grid 2.9.0
persistentcontainervector.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_PERSISTENTCONTAINERVECTOR_HH
6#define DUNE_PERSISTENTCONTAINERVECTOR_HH
7
8#include <algorithm>
9#include <cassert>
10
11namespace Dune
12{
13
14 // PersistentContainerVector
15 // -------------------------
16
49 template< class G, class IndexSet, class Vector >
51 {
53
54 public:
55 typedef G Grid;
56
57 typedef typename Vector::value_type Value;
58 typedef typename Vector::size_type Size;
59 typedef typename Vector::const_iterator ConstIterator;
60 typedef typename Vector::iterator Iterator;
61
62 typedef typename Vector::allocator_type Allocator;
63
64 PersistentContainerVector ( const IndexSet &indexSet, int codim, const Value &value,
65 const Allocator &allocator = Allocator() )
66 : codim_( codim ),
68 data_( indexSet.size( codim ), value, allocator )
69 {}
70
71 template< class Entity >
72 const Value &operator[] ( const Entity &entity ) const
73 {
74 assert( Entity::codimension == codimension() );
75 const Size index = indexSet().index( entity );
76 assert( index < data_.size() );
77 return data_[ index ];
78 }
79
80 template< class Entity >
81 Value &operator[] ( const Entity &entity )
82 {
83 assert( Entity::codimension == codimension() );
84 const Size index = indexSet().index( entity );
85 assert( index < data_.size() );
86 return data_[ index ];
87 }
88
89 template< class Entity >
90 const Value &operator() ( const Entity &entity, int subEntity ) const
91 {
92 const Size index = indexSet().subIndex( entity, subEntity, codimension() );
93 assert( index < data_.size() );
94 return data_[ index ];
95 }
96
97 template< class Entity >
98 Value &operator() ( const Entity &entity, int subEntity )
99 {
100 const Size index = indexSet().subIndex( entity, subEntity, codimension() );
101 assert( index < data_.size() );
102 return data_[ index ];
103 }
104
105 Size size () const { return data_.size(); }
106
107 void resize ( const Value &value = Value() )
108 {
109 const Size indexSetSize = indexSet().size( codimension() );
110 data_.resize( indexSetSize, value );
111 }
112
113 void shrinkToFit () {}
114
115 void fill ( const Value &value ) { std::fill( begin(), end(), value ); }
116
117 void swap ( This &other )
118 {
119 std::swap( codim_, other.codim_ );
120 std::swap( indexSet_, other.indexSet_ );
121 std::swap( data_, other.data_ );
122 }
123
124 ConstIterator begin () const { return data_.begin(); }
125 Iterator begin () { return data_.begin(); }
126
127 ConstIterator end () const { return data_.end(); }
128 Iterator end () { return data_.end(); }
129
130 int codimension () const { return codim_; }
131
132 protected:
133 const IndexSet &indexSet () const { return *indexSet_; }
134
137 Vector data_;
138 };
139
140} // namespace Dune
141
142#endif // #ifndef DUNE_PERSISTENTCONTAINERVECTOR_HH
void swap(Dune::PersistentContainer< G, T > &a, Dune::PersistentContainer< G, T > &b)
Definition: utility/persistentcontainer.hh:83
Include standard header files.
Definition: agrid.hh:60
Wrapper class for entities.
Definition: common/entity.hh:66
static constexpr int codimension
Know your own codimension.
Definition: common/entity.hh:106
Index Set Interface base class.
Definition: indexidset.hh:78
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:223
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:153
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:113
vector-based implementation of the PersistentContainer
Definition: persistentcontainervector.hh:51
PersistentContainerVector(const IndexSet &indexSet, int codim, const Value &value, const Allocator &allocator=Allocator())
Definition: persistentcontainervector.hh:64
Iterator begin()
Definition: persistentcontainervector.hh:125
Vector::size_type Size
Definition: persistentcontainervector.hh:58
Vector::value_type Value
Definition: persistentcontainervector.hh:57
Vector::allocator_type Allocator
Definition: persistentcontainervector.hh:62
void fill(const Value &value)
Definition: persistentcontainervector.hh:115
G Grid
Definition: persistentcontainervector.hh:55
const Value & operator()(const Entity &entity, int subEntity) const
Definition: persistentcontainervector.hh:90
const IndexSet * indexSet_
Definition: persistentcontainervector.hh:136
Vector::iterator Iterator
Definition: persistentcontainervector.hh:60
ConstIterator begin() const
Definition: persistentcontainervector.hh:124
ConstIterator end() const
Definition: persistentcontainervector.hh:127
int codim_
Definition: persistentcontainervector.hh:135
void shrinkToFit()
Definition: persistentcontainervector.hh:113
Vector::const_iterator ConstIterator
Definition: persistentcontainervector.hh:59
Vector data_
Definition: persistentcontainervector.hh:137
Iterator end()
Definition: persistentcontainervector.hh:128
const IndexSet & indexSet() const
Definition: persistentcontainervector.hh:133
int codimension() const
Definition: persistentcontainervector.hh:130
Size size() const
Definition: persistentcontainervector.hh:105
void swap(This &other)
Definition: persistentcontainervector.hh:117
const Value & operator[](const Entity &entity) const
Definition: persistentcontainervector.hh:72
void resize(const Value &value=Value())
Definition: persistentcontainervector.hh:107