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 >;
131 : element_(std::move(element))
135 template <
class C_,
class T1_,
136 std::enable_if_t<std::is_same_v<std::remove_const_t<C>, std::remove_const_t<C_>>,
int> = 0,
137 std::enable_if_t<std::is_same_v<std::remove_const_t<T1>, std::remove_const_t<T1_>>,
int> = 0>
139 : element_(other.element_)
142 template <
class C_,
class T1_,
143 std::enable_if_t<std::is_same_v<std::remove_const_t<C>, std::remove_const_t<C_>>,
int> = 0,
144 std::enable_if_t<std::is_same_v<std::remove_const_t<T1>, std::remove_const_t<T1_>>,
int> = 0>
147 element_ = other.element_;
155 typename std::remove_const<T1>::type>& other)
const 157 return element_ == other.element_;
164 const typename std::remove_const<T1>::type>& other)
const 166 return element_ == other.element_;
172 return *(element_->element_);
178 element_ = element_->coarser_.lock();
184 element_ = element_->finer_;
193 return (
bool)element_->redistributed_;
202 assert(element_->redistributed_);
203 return *element_->redistributed_;
207 element_->redistributed_ = t;
212 element_->redistributed_ =
nullptr;
216 std::shared_ptr<Element> element_ = {};
254 std::size_t
levels()
const;
262 std::shared_ptr<MemberType> originalFinest_;
264 std::shared_ptr<Element> finest_;
266 std::shared_ptr<Element> coarsest_;
273 template<
class T,
class A>
275 : originalFinest_(first)
277 finest_ = std::allocate_shared<Element>(allocator_);
278 finest_->element_ = originalFinest_;
285 template<
class T,
class A>
287 : allocator_(other.allocator_),
288 levels_(other.levels_)
292 finest_=coarsest_=
nullptr;
295 finest_ = std::allocate_shared<Element>(allocator_);
296 std::shared_ptr<Element> finer_;
297 std::shared_ptr<Element> current_ = finest_;
298 std::weak_ptr<Element> otherWeak_ = other.finest_;
300 while(! otherWeak_.expired())
303 std::shared_ptr<Element> otherCurrent_ = std::shared_ptr<Element>(otherWeak_);
307 std::make_shared<MemberType>(*(otherCurrent_->element_));
308 current_->finer_=finer_;
309 if(otherCurrent_->redistributed_)
310 current_->redistributed_ =
311 std::make_shared<MemberType>(*(otherCurrent_->redistributed_));
313 if(not otherCurrent_->coarser_.expired())
315 auto c = std::allocate_shared<Element>(allocator_);
316 current_->coarser_ = c;
320 otherWeak_ = otherCurrent_->coarser_;
325 template<
class T,
class A>
331 template<
class T,
class A>
337 template<
class T,
class A>
345 coarsest_ = std::allocate_shared<Element>(allocator_);
346 coarsest_->element_ = originalFinest_;
349 auto old_coarsest = coarsest_;
350 coarsest_ = std::allocate_shared<Element>(allocator_);
351 coarsest_->finer_ = old_coarsest;
353 old_coarsest->coarser_ = coarsest_;
359 template<
class T,
class A>
368 finest_ = std::allocate_shared<Element>(allocator_);
369 finest_->element = originalFinest_;
372 finest_->finer_ = std::allocate_shared<Element>(allocator_);
373 finest_->finer_->coarser_ = finest_;
374 finest_ = finest_->finer_;
380 template<
class T,
class A>
386 template<
class T,
class A>
392 template<
class T,
class A>
398 template<
class T,
class A>
const void * Arguments
A type holding all the arguments needed to call the constructor.
Definition: construction.hh:44
A hierarchy of containers (e.g. matrices or vectors)
Definition: hierarchy.hh:39
Helper classes for the construction of classes without empty constructor.
typename std::allocator_traits< A >::template rebind_alloc< Element > Allocator
The allocator to use for the list elements.
Definition: hierarchy.hh:76
void addRedistributed(std::shared_ptr< T1 > t)
Definition: hierarchy.hh:205
ConstructionTraits< T >::Arguments Arguments
Definition: hierarchy.hh:78
LevelIterator & operator=(const LevelIterator< C_, T1_ > &other)
Definition: hierarchy.hh:145
T1 & dereference() const
Dereference the iterator.
Definition: hierarchy.hh:170
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:163
LevelIterator(const LevelIterator< C_, T1_ > &other)
Copy constructor.
Definition: hierarchy.hh:138
Traits class for generically constructing non default constructable types.
Definition: novlpschwarz.hh:257
T MemberType
The type of the container we store.
Definition: hierarchy.hh:45
LevelIterator()=default
Constructor.
std::size_t levels() const
Get the number of levels in the hierarchy.
Definition: hierarchy.hh:326
LevelIterator< Hierarchy< T, A >, T > Iterator
Type of the mutable iterator.
Definition: hierarchy.hh:220
Iterator finest()
Get an iterator positioned at the finest level.
Definition: hierarchy.hh:381
void decrement()
Move to the next fine level.
Definition: hierarchy.hh:182
bool isRedistributed() const
Check whether there was a redistribution at the current level.
Definition: hierarchy.hh:191
Iterator coarsest()
Get an iterator positioned at the coarsest level.
Definition: hierarchy.hh:387
void deleteRedistributed()
Definition: hierarchy.hh:210
LevelIterator< const Hierarchy< T, A >, const T > ConstIterator
Type of the const iterator.
Definition: hierarchy.hh:223
void increment()
Move to the next coarser level.
Definition: hierarchy.hh:176
Hierarchy()
Construct an empty hierarchy.
Definition: hierarchy.hh:89
Iterator over the levels in the hierarchy.
Definition: hierarchy.hh:48
void addCoarser(Arguments &args)
Add an element on a coarser level.
Definition: hierarchy.hh:338
bool equals(const LevelIterator< typename std::remove_const< C >::type, typename std::remove_const< T1 >::type > &other) const
Equality check.
Definition: hierarchy.hh:154
T1 & getRedistributed() const
Get the redistributed container.
Definition: hierarchy.hh:200
void addRedistributedOnCoarsest(Arguments &args)
Definition: hierarchy.hh:332
Definition: allocator.hh:11
void addFiner(Arguments &args)
Add an element on a finer level.
Definition: hierarchy.hh:360