3 #ifndef DUNE_AMGHIERARCHY_HH
4 #define DUNE_AMGHIERARCHY_HH
9 #include <dune/common/stdstreams.hh>
10 #include <dune/common/unused.hh>
11 #include <dune/common/timer.hh>
12 #include <dune/common/bigunsignedint.hh>
37 template<
typename T,
typename A=std::allocator<T> >
46 template<
typename T1,
typename T2>
55 friend class LevelIterator<
Hierarchy<T,A>, T>;
56 friend class LevelIterator<const
Hierarchy<T,A>, const T>;
59 std::weak_ptr<Element> coarser_;
62 std::shared_ptr<Element> finer_;
65 std::shared_ptr<MemberType> element_;
68 std::shared_ptr<MemberType> redistributed_;
75 using Allocator =
typename std::allocator_traits<A>::template rebind_alloc<Element>;
83 Hierarchy(
const std::shared_ptr<MemberType> & first);
116 template<
class C,
class T1>
118 :
public BidirectionalIteratorFacade<LevelIterator<C,T1>,T1,T1&>
120 friend class LevelIterator<typename std::remove_const<C>::type,
121 typename std::remove_const<T1>::type >;
122 friend class
LevelIterator<const typename std::remove_const<C>::type,
123 const typename std::remove_const<T1>::type >;
136 typename std::remove_const<T1>::type>& other)
137 : element_(other.element_)
142 const typename std::remove_const<T1>::type>& other)
143 : element_(other.element_)
150 typename std::remove_const<T1>::type>& other)
const
152 return element_ == other.element_;
159 const typename std::remove_const<T1>::type>& other)
const
161 return element_ == other.element_;
167 return *(element_->element_);
173 element_ = element_->coarser_.lock();
179 element_ = element_->finer_;
188 return (
bool)element_->redistributed_;
197 assert(element_->redistributed_);
198 return *element_->redistributed_;
202 element_->redistributed_ = t;
207 element_->redistributed_ =
nullptr;
211 std::shared_ptr<Element> element_;
257 std::shared_ptr<MemberType> originalFinest_;
259 std::shared_ptr<Element> finest_;
261 std::shared_ptr<Element> coarsest_;
268 template<
class T,
class A>
270 : originalFinest_(first)
272 finest_ = std::allocate_shared<Element>(allocator_);
273 finest_->element_ = originalFinest_;
280 template<
class T,
class A>
282 : allocator_(other.allocator_),
283 levels_(other.levels_)
287 finest_=coarsest_=
nullptr;
290 finest_ = std::allocate_shared<Element>(allocator_);
291 std::shared_ptr<Element> finer_;
292 std::shared_ptr<Element> current_ = finest_;
293 std::weak_ptr<Element> otherWeak_ = other.finest_;
295 while(! otherWeak_.expired())
298 std::shared_ptr<Element> otherCurrent_ = std::shared_ptr<Element>(otherWeak_);
302 std::make_shared<MemberType>(*(otherCurrent_->element_));
303 current_->finer_=finer_;
304 if(otherCurrent_->redistributed_)
305 current_->redistributed_ =
306 std::make_shared<MemberType>(*(otherCurrent_->redistributed_));
308 if(not otherCurrent_->coarser_.expired())
310 auto c = std::allocate_shared<Element>(allocator_);
311 current_->coarser_ = c;
315 otherWeak_ = otherCurrent_->coarser_;
320 template<
class T,
class A>
326 template<
class T,
class A>
332 template<
class T,
class A>
340 coarsest_ = std::allocate_shared<Element>(allocator_);
341 coarsest_->element_ = originalFinest_;
344 auto old_coarsest = coarsest_;
345 coarsest_ = std::allocate_shared<Element>(allocator_);
346 coarsest_->finer_ = old_coarsest;
348 old_coarsest->coarser_ = coarsest_;
354 template<
class T,
class A>
363 finest_ = std::allocate_shared<Element>(allocator_);
364 finest_->element = originalFinest_;
367 finest_->finer_ = std::allocate_shared<Element>(allocator_);
368 finest_->finer_->coarser_ = finest_;
369 finest_ = finest_->finer_;
375 template<
class T,
class A>
381 template<
class T,
class A>
387 template<
class T,
class A>
393 template<
class T,
class A>
Helper classes for the construction of classes without empty constructor.
Hierarchy(const Hierarchy &other)
Copy constructor (deep copy!).
Definition: hierarchy.hh:281
void addRedistributedOnCoarsest(Arguments &args)
Definition: hierarchy.hh:327
std::size_t levels() const
Get the number of levels in the hierarchy.
Definition: hierarchy.hh:321
ConstIterator coarsest() const
Get an iterator positioned at the coarsest level.
Definition: hierarchy.hh:394
void addCoarser(Arguments &args)
Add an element on a coarser level.
Definition: hierarchy.hh:333
void addFiner(Arguments &args)
Add an element on a finer level.
Definition: hierarchy.hh:355
Hierarchy(const std::shared_ptr< MemberType > &first)
Construct a new hierarchy.
Definition: hierarchy.hh:269
const void * Arguments
A type holding all the arguments needed to call the constructor.
Definition: construction.hh:44
static std::shared_ptr< T > construct(Arguments &args)
Construct an object with the specified arguments.
Definition: construction.hh:52
Iterator coarsest()
Get an iterator positioned at the coarsest level.
Definition: hierarchy.hh:382
ConstIterator finest() const
Get an iterator positioned at the finest level.
Definition: hierarchy.hh:388
Iterator finest()
Get an iterator positioned at the finest level.
Definition: hierarchy.hh:376
Definition: allocator.hh:7
A hierarchy of containers (e.g. matrices or vectors)
Definition: hierarchy.hh:39
T MemberType
The type of the container we store.
Definition: hierarchy.hh:44
LevelIterator< Hierarchy< T, A >, T > Iterator
Type of the mutable iterator.
Definition: hierarchy.hh:215
LevelIterator< const Hierarchy< T, A >, const T > ConstIterator
Type of the const iterator.
Definition: hierarchy.hh:218
ConstructionTraits< T >::Arguments Arguments
Definition: hierarchy.hh:77
Hierarchy()
Construct an empty hierarchy.
Definition: hierarchy.hh:88
typename std::allocator_traits< std::allocator< X > >::template rebind_alloc< Element > Allocator
The allocator to use for the list elements.
Definition: hierarchy.hh:75
Iterator over the levels in the hierarchy.
Definition: hierarchy.hh:119
LevelIterator(const LevelIterator< typename std::remove_const< C >::type, typename std::remove_const< T1 >::type > &other)
Copy constructor.
Definition: hierarchy.hh:135
void addRedistributed(std::shared_ptr< T1 > t)
Definition: hierarchy.hh:200
bool equals(const LevelIterator< typename std::remove_const< C >::type, typename std::remove_const< T1 >::type > &other) const
Equality check.
Definition: hierarchy.hh:149
bool isRedistributed() const
Check whether there was a redistribution at the current level.
Definition: hierarchy.hh:186
bool equals(const LevelIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T1 >::type > &other) const
Equality check.
Definition: hierarchy.hh:158
void increment()
Move to the next coarser level.
Definition: hierarchy.hh:171
T1 & getRedistributed() const
Get the redistributed container.
Definition: hierarchy.hh:195
LevelIterator(const LevelIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T1 >::type > &other)
Copy constructor.
Definition: hierarchy.hh:141
void deleteRedistributed()
Definition: hierarchy.hh:205
void decrement()
Move to the next fine level.
Definition: hierarchy.hh:177
LevelIterator(std::shared_ptr< Element > element)
Definition: hierarchy.hh:130
LevelIterator()
Constructor.
Definition: hierarchy.hh:127
T1 & dereference() const
Dereference the iterator.
Definition: hierarchy.hh:165