Skip to content
Snippets Groups Projects
Commit f2825813 authored by Oliver Sander's avatar Oliver Sander
Browse files

An alpha-version of the hierarchical iterators for UGGrid.

Don't expect this to be bugfree, though.  :-)

[[Imported from SVN: r719]]
parent 00b01776
No related branches found
No related tags found
No related merge requests found
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#if 0
//***************************************************************
//
// --AlbertGridHierarchicIterator
// --UGGridHierarchicIterator
// --HierarchicIterator
//
//***************************************************************
template< int dim, int dimworld>
inline void AlbertGridHierarchicIterator<dim,dimworld>::
makeIterator()
inline
UGGridHierarchicIterator< dim,dimworld >::UGGridHierarchicIterator(int actLevel,int maxLevel)
: virtualEntity_(0)
{
manageStack_.init();
virtualEntity_.setTraverseStack(NULL);
virtualEntity_.setElInfo(NULL,0,0,0,0);
}
//level_ = actLevel;
maxlevel_ = maxLevel;
template< int dim, int dimworld>
inline AlbertGridHierarchicIterator<dim,dimworld>::
AlbertGridHierarchicIterator(AlbertGrid<dim,dimworld> &grid,int actLevel,
int maxLevel) : grid_(grid), level_ (actLevel)
, maxlevel_ (maxLevel) , virtualEntity_(grid,level_)
{
makeIterator();
virtualEntity_.setToTarget(NULL);
}
template< int dim, int dimworld>
inline AlbertGridHierarchicIterator<dim,dimworld>::
AlbertGridHierarchicIterator(AlbertGrid<dim,dimworld> &grid,
ALBERT TRAVERSE_STACK *travStack,int actLevel, int maxLevel) :
grid_(grid), level_ (actLevel),
maxlevel_ ( maxLevel), virtualEntity_(grid,level_)
inline UGGridHierarchicIterator<dim,dimworld>&
UGGridHierarchicIterator< dim,dimworld >::operator ++()
{
if(travStack)
{
// get new ALBERT TRAVERSE STACK
manageStack_.makeItNew(true);
ALBERT TRAVERSE_STACK *stack = manageStack_.getStack();
if (elemStack.isempty())
return (*this);
// cut old traverse stack, kepp only actual element
cutHierarchicStack(stack, travStack);
StackEntry old_target = elemStack.pop_front();
// set new traverse level
if(maxlevel_ < 0)
{
// this means, we go until leaf level
stack->traverse_fill_flag = CALL_LEAF_EL | stack->traverse_fill_flag;
// exact here has to stand Grid->maxlevel, but is ok anyway
maxlevel_ = grid_.maxlevel(); //123456789;
}
// set new traverse level
stack->traverse_level = maxlevel_;
// Traverse the tree no deeper than maxlevel
if (old_target.level < maxlevel_) {
virtualEntity_.setTraverseStack(stack);
// Hier kann ein beliebiges Element uebergeben werden,
// da jedes AlbertElement einen Zeiger auf das Macroelement
// enthaelt.
virtualEntity_.setElInfo(recursiveTraverse(stack));
// The 30 is the macro MAX_SONS from ug/gm/gm.h
UGElementType* sonList[30];
UG2d::GetSons(old_target.element,sonList);
// set new level
virtualEntity_.setLevel(level_);
#define NSONS(p) UG2d::ReadCW(p, UG2d::NSONS_CE)
// Load sons of old target onto the iterator stack
for (unsigned int i=0; i<NSONS(old_target.element); i++) {
StackEntry se;
se.element = sonList[i];
se.level = old_target.level + 1;
elemStack.push_front(se);
}
#undef NSONS
}
if (elemStack.isempty())
virtualEntity_.setToTarget(0);
else
{
std::cout << "Warning: travStack == NULL in HierarchicIterator(travStack,travLevel) \n";
makeIterator();
}
}
virtualEntity_.setToTarget(elemStack.front().element, elemStack.front().level);
template< int dim, int dimworld>
inline AlbertGridHierarchicIterator<dim,dimworld>&
AlbertGridHierarchicIterator< dim,dimworld >::operator ++()
{
virtualEntity_.setElInfo(recursiveTraverse(manageStack_.getStack()));
// set new actual level
virtualEntity_.setLevel(level_);
return (*this);
}
template< int dim, int dimworld>
inline AlbertGridHierarchicIterator<dim,dimworld>&
AlbertGridHierarchicIterator<dim,dimworld>::
operator ++(int steps)
{
for(int i=0; i<steps; i++)
++(*this);
return (*this);
}
template< int dim, int dimworld>
inline bool AlbertGridHierarchicIterator<dim,dimworld>::
operator ==(const AlbertGridHierarchicIterator& I) const
inline bool UGGridHierarchicIterator<dim,dimworld>::
operator ==(const UGGridHierarchicIterator& I) const
{
return (virtualEntity_.getElInfo() == I.virtualEntity_.getElInfo());
return ( (elemStack.size()==0 && I.elemStack.size()==0) ||
((elemStack.size() == I.elemStack.size()) &&
(elemStack.front().element == I.elemStack.front().element)));
}
template< int dim, int dimworld>
inline bool AlbertGridHierarchicIterator<dim,dimworld>::
operator !=(const AlbertGridHierarchicIterator& I) const
inline bool UGGridHierarchicIterator<dim,dimworld>::
operator !=(const UGGridHierarchicIterator& I) const
{
return !((*this) == I);
}
template< int dim, int dimworld>
inline AlbertGridEntity < 0, dim ,dimworld >&
AlbertGridHierarchicIterator<dim,dimworld>::
inline UGGridEntity < 0, dim ,dimworld >&
UGGridHierarchicIterator<dim,dimworld>::
operator *()
{
return virtualEntity_;
}
template< int dim, int dimworld>
inline AlbertGridEntity < 0, dim ,dimworld >*
AlbertGridHierarchicIterator<dim,dimworld>::
inline UGGridEntity < 0, dim ,dimworld >*
UGGridHierarchicIterator<dim,dimworld>::
operator ->()
{
return &virtualEntity_;
}
template< int dim, int dimworld>
inline ALBERT EL_INFO *
AlbertGridHierarchicIterator<dim,dimworld>::
recursiveTraverse(ALBERT TRAVERSE_STACK * stack)
{
// see function
// static EL_INFO *traverse_leaf_el(TRAVERSE_STACK *stack)
// Common/traverse_nr_common.cc, line 392
ALBERT EL * el=NULL;
if(!stack->elinfo_stack)
{
/* somethin' wrong */
return NULL;
}
else
{
// go up until we can go down again
el = stack->elinfo_stack[stack->stack_used].el;
while((stack->stack_used > 0) &&
((stack->info_stack[stack->stack_used] >= 2)
|| ((el->child[0]==NULL) && level_ >= maxlevel_ )
|| ( stack->traverse_level <=
(stack->elinfo_stack+stack->stack_used)->level)) )
{
stack->stack_used--;
el = stack->elinfo_stack[stack->stack_used].el;
level_ = stack->elinfo_stack[stack->stack_used].level;
}
// goto next father is done by other iterator and not our problem
if(stack->stack_used < 1)
{
return NULL;
}
}
// go down next child
if(el->child[0] && (stack->traverse_level >
(stack->elinfo_stack+stack->stack_used)->level) )
{
if(stack->stack_used >= stack->stack_size - 1)
ALBERT enlargeTraverseStack(stack);
int i = stack->info_stack[stack->stack_used];
el = el->child[i];
stack->info_stack[stack->stack_used]++;
// new: go down maxlevel, but fake the elements
level_++;
grid_.fillElInfo(i, level_, stack->elinfo_stack+stack->stack_used,
stack->elinfo_stack+stack->stack_used+1 ,true);
//ALBERT fill_elinfo(i, stack->elinfo_stack + stack->stack_used,
// stack->elinfo_stack + (stack->stack_used + 1));
stack->stack_used++;
stack->info_stack[stack->stack_used] = 0;
}
// the case if we have no child but level_ < maxlevel_
// then we want to fake the next maxlevel_ - level_ elements
else if(level_ < maxlevel_)
{
// new: go down until maxlevel, but fake the not existant elements
if(stack->stack_used >= stack->stack_size - 1)
ALBERT enlargeTraverseStack(stack);
el = el;
// means all elements visited
stack->info_stack[stack->stack_used] = 2;
// new: go down maxlevel, but fake the elements
level_++;
grid_.fillElInfo(0, level_, stack->elinfo_stack+stack->stack_used,stack->elinfo_stack+stack->stack_used+1, true);
//ALBERT fill_elinfo(i, stack->elinfo_stack + stack->stack_used,
// stack->elinfo_stack + (stack->stack_used + 1));
stack->stack_used++;
stack->info_stack[stack->stack_used] = 0;
}
return (stack->elinfo_stack + stack->stack_used);
} // recursive traverse over all childs
// end AlbertGridHierarchicIterator
#endif
......@@ -3,89 +3,74 @@
#ifndef __DUNE_UGHIERITERATOR_HH__
#define __DUNE_UGHIERITERATOR_HH__
//**********************************************************************
//
// --UGGridHierarchicIterator
// --HierarchicIterator
/*!
Mesh entities of codimension 0 ("elements") allow to visit all entities of
codimension 0 obtained through nested, hierarchic refinement of the entity.
Iteration over this set of entities is provided by the HIerarchicIterator,
starting from a given entity.
This is redundant but important for memory efficient implementations of unstru
hierarchically refined meshes.
*/
template<int dim, int dimworld>
class UGGridHierarchicIterator :
public HierarchicIteratorDefault <dim,dimworld, UGCtype,
UGGridHierarchicIterator,UGGridEntity>
{
public:
#if 1
#if 0
//! the normal Constructor
UGGridHierarchicIterator(UGGrid<dim,dimworld> &grid,
ALBERT TRAVERSE_STACK *travStack, int actLevel, int maxLevel);
#endif
#include <dune/common/stack.hh>
//! the default Constructor
UGGridHierarchicIterator(UGGrid<dim,dimworld> &grid,
int actLevel,int maxLevel);
#else
//! the normal Constructor
UGGridHierarchicIterator(UGGrid<dim,dimworld> &grid,
ALBERT TRAVERSE_STACK *travStack, int travLevel);
namespace Dune {
//! the default Constructor
UGGridHierarchicIterator(UGGrid<dim,dimworld> &grid);
#endif
//**********************************************************************
//
// --UGGridHierarchicIterator
// --HierarchicIterator
/*!
Mesh entities of codimension 0 ("elements") allow to visit all entities of
codimension 0 obtained through nested, hierarchic refinement of the entity.
Iteration over this set of entities is provided by the HIerarchicIterator,
starting from a given entity.
This is redundant but important for memory efficient implementations of unstru
hierarchically refined meshes.
*/
//! prefix increment
UGGridHierarchicIterator& operator ++();
template<int dim, int dimworld>
class UGGridHierarchicIterator :
public HierarchicIteratorDefault <dim,dimworld, UGCtype,
UGGridHierarchicIterator,UGGridEntity>
{
//! postfix increment
UGGridHierarchicIterator& operator ++(int i);
// Either UG3d::ELEMENT or UG2d:ELEMENT
typedef typename TargetType<0,dim>::T UGElementType;
public:
// Stack entry
struct StackEntry {
UGElementType* element;
int level;
};
//! equality
bool operator== (const UGGridHierarchicIterator& i) const;
public:
//! inequality
bool operator!= (const UGGridHierarchicIterator& i) const;
//! the default Constructor
UGGridHierarchicIterator(int actLevel,int maxLevel);
//! dereferencing
UGGridEntity<0,dim,dimworld>& operator*();
//! prefix increment
UGGridHierarchicIterator& operator ++();
//! arrow
UGGridEntity<0,dim,dimworld>* operator->();
//! equality
bool operator== (const UGGridHierarchicIterator& i) const;
private:
//! implement with virtual element
UGGridEntity<0,dim,dimworld> virtualEntity_;
//! inequality
bool operator!= (const UGGridHierarchicIterator& i) const;
//! know the grid were im comming from
UGGrid<dim,dimworld> &grid_;
//! dereferencing
UGGridEntity<0,dim,dimworld>& operator*();
//! the actual Level of this Hierarichic Iterator
int level_;
//! arrow
UGGridEntity<0,dim,dimworld>* operator->();
//! max level to go down
//int maxlevel_;
//! implement with virtual element
UGGridEntity<0,dim,dimworld> virtualEntity_;
#if 0
//! we need this for Albert traversal, and we need ManageTravStack, which
//! does count References when copied
ALBERT ManageTravStack manageStack_;
private:
//! know the grid were im comming from
//UGGrid<dim,dimworld> &grid_;
//! The nessesary things for Albert
ALBERT EL_INFO * recursiveTraverse(ALBERT TRAVERSE_STACK * stack);
#endif
//! max level to go down
int maxlevel_;
public:
Stack<StackEntry> elemStack;
//! make empty HierarchicIterator
void makeIterator();
};
UGElementType* target_;
};
} // end namespace Dune
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment