3 #ifndef DUNE_AMGHIERARCHY_HH
4 #define DUNE_AMGHIERARCHY_HH
9 #include <dune/common/stdstreams.hh>
10 #include <dune/common/timer.hh>
11 #include <dune/common/bigunsignedint.hh>
36 template<
typename T,
typename A=std::allocator<T> >
45 template<
typename T1,
typename T2>
58 std::weak_ptr<Element> coarser_;
61 std::shared_ptr<Element> finer_;
64 std::shared_ptr<MemberType> element_;
67 std::shared_ptr<MemberType> redistributed_;
74 using Allocator =
typename std::allocator_traits<A>::template rebind_alloc<Element>;
82 Hierarchy(
const std::shared_ptr<MemberType> & first);
115 template<
class C,
class T1>
117 :
public BidirectionalIteratorFacade<LevelIterator<C,T1>,T1,T1&>
119 friend class LevelIterator<typename std::remove_const<C>::type,
120 typename std::remove_const<T1>::type >;
121 friend class
LevelIterator<const typename std::remove_const<C>::type,
122 const typename std::remove_const<T1>::type >;
135 typename std::remove_const<T1>::type>& other)
136 : element_(other.element_)
141 const typename std::remove_const<T1>::type>& other)
142 : element_(other.element_)
149 typename std::remove_const<T1>::type>& other)
const
151 return element_ == other.element_;
158 const typename std::remove_const<T1>::type>& other)
const
160 return element_ == other.element_;
166 return *(element_->element_);
172 element_ = element_->coarser_.lock();
178 element_ = element_->finer_;
187 return (
bool)element_->redistributed_;
196 assert(element_->redistributed_);
197 return *element_->redistributed_;
201 element_->redistributed_ = t;
206 element_->redistributed_ =
nullptr;
210 std::shared_ptr<Element> element_;
256 std::shared_ptr<MemberType> originalFinest_;
258 std::shared_ptr<Element> finest_;
260 std::shared_ptr<Element> coarsest_;
267 template<
class T,
class A>
269 : originalFinest_(first)
271 finest_ = std::allocate_shared<Element>(allocator_);
272 finest_->element_ = originalFinest_;
279 template<
class T,
class A>
281 : allocator_(other.allocator_),
282 levels_(other.levels_)
286 finest_=coarsest_=
nullptr;
289 finest_ = std::allocate_shared<Element>(allocator_);
290 std::shared_ptr<Element> finer_;
291 std::shared_ptr<Element> current_ = finest_;
292 std::weak_ptr<Element> otherWeak_ = other.finest_;
294 while(! otherWeak_.expired())
297 std::shared_ptr<Element> otherCurrent_ = std::shared_ptr<Element>(otherWeak_);
301 std::make_shared<MemberType>(*(otherCurrent_->element_));
302 current_->finer_=finer_;
303 if(otherCurrent_->redistributed_)
304 current_->redistributed_ =
305 std::make_shared<MemberType>(*(otherCurrent_->redistributed_));
307 if(not otherCurrent_->coarser_.expired())
309 auto c = std::allocate_shared<Element>(allocator_);
310 current_->coarser_ = c;
314 otherWeak_ = otherCurrent_->coarser_;
319 template<
class T,
class A>
325 template<
class T,
class A>
331 template<
class T,
class A>
339 coarsest_ = std::allocate_shared<Element>(allocator_);
340 coarsest_->element_ = originalFinest_;
343 auto old_coarsest = coarsest_;
344 coarsest_ = std::allocate_shared<Element>(allocator_);
345 coarsest_->finer_ = old_coarsest;
347 old_coarsest->coarser_ = coarsest_;
353 template<
class T,
class A>
362 finest_ = std::allocate_shared<Element>(allocator_);
363 finest_->element = originalFinest_;
366 finest_->finer_ = std::allocate_shared<Element>(allocator_);
367 finest_->finer_->coarser_ = finest_;
368 finest_ = finest_->finer_;
374 template<
class T,
class A>
380 template<
class T,
class A>
386 template<
class T,
class A>
392 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:280
void addRedistributedOnCoarsest(Arguments &args)
Definition: hierarchy.hh:326
std::size_t levels() const
Get the number of levels in the hierarchy.
Definition: hierarchy.hh:320
ConstIterator coarsest() const
Get an iterator positioned at the coarsest level.
Definition: hierarchy.hh:393
void addCoarser(Arguments &args)
Add an element on a coarser level.
Definition: hierarchy.hh:332
void addFiner(Arguments &args)
Add an element on a finer level.
Definition: hierarchy.hh:354
Hierarchy(const std::shared_ptr< MemberType > &first)
Construct a new hierarchy.
Definition: hierarchy.hh:268
const void * Arguments
A type holding all the arguments needed to call the constructor.
Definition: construction.hh:42
static std::shared_ptr< T > construct(Arguments &args)
Construct an object with the specified arguments.
Definition: construction.hh:50
Iterator coarsest()
Get an iterator positioned at the coarsest level.
Definition: hierarchy.hh:381
ConstIterator finest() const
Get an iterator positioned at the finest level.
Definition: hierarchy.hh:387
Iterator finest()
Get an iterator positioned at the finest level.
Definition: hierarchy.hh:375
Definition: allocator.hh:9
A hierarchy of containers (e.g. matrices or vectors)
Definition: hierarchy.hh:38
T MemberType
The type of the container we store.
Definition: hierarchy.hh:43
LevelIterator< Hierarchy< T, A >, T > Iterator
Type of the mutable iterator.
Definition: hierarchy.hh:214
LevelIterator< const Hierarchy< T, A >, const T > ConstIterator
Type of the const iterator.
Definition: hierarchy.hh:217
ConstructionTraits< T >::Arguments Arguments
Definition: hierarchy.hh:76
Hierarchy()
Construct an empty hierarchy.
Definition: hierarchy.hh:87
typename std::allocator_traits< A >::template rebind_alloc< Element > Allocator
The allocator to use for the list elements.
Definition: hierarchy.hh:74
Iterator over the levels in the hierarchy.
Definition: hierarchy.hh:118
LevelIterator(const LevelIterator< typename std::remove_const< C >::type, typename std::remove_const< T1 >::type > &other)
Copy constructor.
Definition: hierarchy.hh:134
void addRedistributed(std::shared_ptr< T1 > t)
Definition: hierarchy.hh:199
bool equals(const LevelIterator< typename std::remove_const< C >::type, typename std::remove_const< T1 >::type > &other) const
Equality check.
Definition: hierarchy.hh:148
bool isRedistributed() const
Check whether there was a redistribution at the current level.
Definition: hierarchy.hh:185
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:157
void increment()
Move to the next coarser level.
Definition: hierarchy.hh:170
T1 & getRedistributed() const
Get the redistributed container.
Definition: hierarchy.hh:194
LevelIterator(const LevelIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T1 >::type > &other)
Copy constructor.
Definition: hierarchy.hh:140
void deleteRedistributed()
Definition: hierarchy.hh:204
void decrement()
Move to the next fine level.
Definition: hierarchy.hh:176
LevelIterator(std::shared_ptr< Element > element)
Definition: hierarchy.hh:129
T1 & dereference() const
Dereference the iterator.
Definition: hierarchy.hh:164