5#ifndef DUNE_AMGHIERARCHY_HH
6#define DUNE_AMGHIERARCHY_HH
11#include <dune/common/stdstreams.hh>
12#include <dune/common/timer.hh>
13#include <dune/common/bigunsignedint.hh>
38 template<
typename T,
typename A=std::allocator<T> >
47 template<
typename T1,
typename T2>
60 std::weak_ptr<Element> coarser_;
63 std::shared_ptr<Element> finer_;
66 std::shared_ptr<MemberType> element_;
69 std::shared_ptr<MemberType> redistributed_;
76 using Allocator =
typename std::allocator_traits<A>::template rebind_alloc<Element>;
84 Hierarchy(
const std::shared_ptr<MemberType> & first);
117 template<
class C,
class T1>
119 :
public BidirectionalIteratorFacade<LevelIterator<C,T1>,T1,T1&>
122 typename std::remove_const<T1>::type >;
123 friend class
LevelIterator<const typename std::remove_const<C>::type,
124 const typename std::remove_const<T1>::type >;
137 typename std::remove_const<T1>::type>& other)
138 : element_(other.element_)
143 const typename std::remove_const<T1>::type>& other)
144 : element_(other.element_)
151 typename std::remove_const<T1>::type>& other)
const
153 return element_ == other.element_;
160 const typename std::remove_const<T1>::type>& other)
const
162 return element_ == other.element_;
168 return *(element_->element_);
174 element_ = element_->coarser_.lock();
180 element_ = element_->finer_;
189 return (
bool)element_->redistributed_;
198 assert(element_->redistributed_);
199 return *element_->redistributed_;
203 element_->redistributed_ = t;
208 element_->redistributed_ =
nullptr;
212 std::shared_ptr<Element> element_;
258 std::shared_ptr<MemberType> originalFinest_;
260 std::shared_ptr<Element> finest_;
262 std::shared_ptr<Element> coarsest_;
269 template<
class T,
class A>
271 : originalFinest_(first)
273 finest_ = std::allocate_shared<Element>(allocator_);
274 finest_->element_ = originalFinest_;
281 template<
class T,
class A>
283 : allocator_(other.allocator_),
284 levels_(other.levels_)
288 finest_=coarsest_=nullptr;
291 finest_ = std::allocate_shared<Element>(allocator_);
292 std::shared_ptr<Element> finer_;
293 std::shared_ptr<Element> current_ = finest_;
294 std::weak_ptr<Element> otherWeak_ = other.finest_;
296 while(! otherWeak_.expired())
299 std::shared_ptr<Element> otherCurrent_ = std::shared_ptr<Element>(otherWeak_);
303 std::make_shared<MemberType>(*(otherCurrent_->element_));
304 current_->finer_=finer_;
305 if(otherCurrent_->redistributed_)
306 current_->redistributed_ =
307 std::make_shared<MemberType>(*(otherCurrent_->redistributed_));
309 if(not otherCurrent_->coarser_.expired())
311 auto c = std::allocate_shared<Element>(allocator_);
312 current_->coarser_ = c;
316 otherWeak_ = otherCurrent_->coarser_;
321 template<
class T,
class A>
327 template<
class T,
class A>
333 template<
class T,
class A>
341 coarsest_ = std::allocate_shared<Element>(allocator_);
342 coarsest_->element_ = originalFinest_;
345 auto old_coarsest = coarsest_;
346 coarsest_ = std::allocate_shared<Element>(allocator_);
347 coarsest_->finer_ = old_coarsest;
349 old_coarsest->coarser_ = coarsest_;
355 template<
class T,
class A>
364 finest_ = std::allocate_shared<Element>(allocator_);
365 finest_->element = originalFinest_;
368 finest_->finer_ = std::allocate_shared<Element>(allocator_);
369 finest_->finer_->coarser_ = finest_;
370 finest_ = finest_->finer_;
376 template<
class T,
class A>
382 template<
class T,
class A>
388 template<
class T,
class A>
394 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:282
void addRedistributedOnCoarsest(Arguments &args)
Definition hierarchy.hh:328
std::size_t levels() const
Get the number of levels in the hierarchy.
Definition hierarchy.hh:322
ConstIterator coarsest() const
Get an iterator positioned at the coarsest level.
Definition hierarchy.hh:395
void addCoarser(Arguments &args)
Add an element on a coarser level.
Definition hierarchy.hh:334
void addFiner(Arguments &args)
Add an element on a finer level.
Definition hierarchy.hh:356
Hierarchy(const std::shared_ptr< MemberType > &first)
Construct a new hierarchy.
Definition hierarchy.hh:270
const void * Arguments
A type holding all the arguments needed to call the constructor.
Definition construction.hh:44
Iterator coarsest()
Get an iterator positioned at the coarsest level.
Definition hierarchy.hh:383
ConstIterator finest() const
Get an iterator positioned at the finest level.
Definition hierarchy.hh:389
Iterator finest()
Get an iterator positioned at the finest level.
Definition hierarchy.hh:377
Definition allocator.hh:11
Traits class for generically constructing non default constructable types.
Definition schwarz.hh:251
A hierarchy of containers (e.g. matrices or vectors)
Definition hierarchy.hh:40
LevelIterator< Hierarchy< T, A >, T > Iterator
Type of the mutable iterator.
Definition hierarchy.hh:216
ConstructionTraits< T >::Arguments Arguments
Definition hierarchy.hh:78
T MemberType
The type of the container we store.
Definition hierarchy.hh:45
Hierarchy()
Construct an empty hierarchy.
Definition hierarchy.hh:89
typename std::allocator_traits< A >::template rebind_alloc< Element > Allocator
The allocator to use for the list elements.
Definition hierarchy.hh:76
LevelIterator< const Hierarchy< T, A >, const T > ConstIterator
Type of the const iterator.
Definition hierarchy.hh:219
Iterator over the levels in the hierarchy.
Definition hierarchy.hh:120
LevelIterator(const LevelIterator< typename std::remove_const< C >::type, typename std::remove_const< T1 >::type > &other)
Copy constructor.
Definition hierarchy.hh:136
void addRedistributed(std::shared_ptr< T1 > t)
Definition hierarchy.hh:201
T1 & dereference() const
Dereference the iterator.
Definition hierarchy.hh:166
bool equals(const LevelIterator< typename std::remove_const< C >::type, typename std::remove_const< T1 >::type > &other) const
Equality check.
Definition hierarchy.hh:150
bool isRedistributed() const
Check whether there was a redistribution at the current level.
Definition hierarchy.hh:187
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:159
void increment()
Move to the next coarser level.
Definition hierarchy.hh:172
LevelIterator(const LevelIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T1 >::type > &other)
Copy constructor.
Definition hierarchy.hh:142
void deleteRedistributed()
Definition hierarchy.hh:206
void decrement()
Move to the next fine level.
Definition hierarchy.hh:178
LevelIterator(std::shared_ptr< Element > element)
Definition hierarchy.hh:131
T1 & getRedistributed() const
Get the redistributed container.
Definition hierarchy.hh:196