Skip to content
Snippets Groups Projects
Commit 76a2114d authored by Robert Klöfkorn's avatar Robert Klöfkorn
Browse files

HierarchicIterator endlich richtig und verbessert (speicherplatzsparender)

implemetiert. Funktioniert sonst wie bisher.

[[Imported from SVN: r67]]
parent a25c9b02
No related branches found
No related tags found
No related merge requests found
......@@ -241,7 +241,7 @@ namespace Albert
//***********************************************************************
// Methods that not belong to the Interface, but have to be public
//***********************************************************************
void builtGeom(ALBERT EL_INFO *elInfo, unsigned char face,
bool builtGeom(ALBERT EL_INFO *elInfo, unsigned char face,
unsigned char edge, unsigned char vertex);
void initGeom();
......@@ -419,6 +419,7 @@ namespace Albert
//! know your own dimension of world
enum { dimensionworld=dimworld };
//! Default Constructor, needed, but empty
AlbertGridEntity();
AlbertGridEntity(ALBERT TRAVERSE_STACK * travStack);
......@@ -596,9 +597,6 @@ namespace Albert
//! does count References when copied
ALBERT ManageTravStack manageStack_;
//! remember on which level we started
int startLevel_;
//! The nessesary things for Albert
ALBERT EL_INFO * recursiveTraverse(ALBERT TRAVERSE_STACK * stack);
......@@ -714,7 +712,10 @@ namespace Albert
Vec<dimworld,albertCtype> outerNormal_;
AlbertGridElement<dim-1,dim> fakeNeigh_;
bool fakeNeighBuilt_;
AlbertGridElement<dim-1,dimworld> neighGlob_;
bool neighGlobBuilt_;
ALBERT EL_INFO * elInfo_;
......
......@@ -19,6 +19,8 @@
extern void free_leaf_data(void *leaf_data, MESH *mesh);
extern void free_dof(DOF *dof, MESH *mesh, int position);
void enlargeTraverseStack(TRAVERSE_STACK *stack);
//! organize the TRAVERSE_STACK Management, so we can use the nice Albert
//! fucntions get_traverse_stack and free_traverse_stack
//! this count the copy made of this class and call free_traverse_stack
......@@ -102,7 +104,6 @@ public:
};
//! copy all memory entries from org to copy via memcpy
void hardCopyStack(TRAVERSE_STACK* copy, TRAVERSE_STACK* org)
{
......@@ -142,6 +143,47 @@ void hardCopyStack(TRAVERSE_STACK* copy, TRAVERSE_STACK* org)
return;
}
//! copy all memory entries from org to copy via memcpy
void cutHierarchicStack(TRAVERSE_STACK* copy, TRAVERSE_STACK* org)
{
copy->traverse_mesh = org->traverse_mesh;
copy->traverse_level = org->traverse_level;
copy->traverse_fill_flag = org->traverse_fill_flag;
copy->traverse_mel = org->traverse_mel;
if(copy->stack_size < 5)
enlargeTraverseStack(copy);
int used = org->stack_used;
copy->stack_used = 1;
// copy only the last 2 elements
int copyUse = used-1;
if(copyUse < 0) copyUse = 0;
memcpy(copy->elinfo_stack,org->elinfo_stack+copyUse,
2*sizeof(EL_INFO));
copy->info_stack[0] = org->info_stack[used];
// go to child 0
copy->info_stack[1] = 0;
memcpy(copy->save_elinfo_stack,org->save_elinfo_stack+copyUse,
2*sizeof(EL_INFO));
copy->save_info_stack[0] = org->save_info_stack[used];
copy->save_info_stack[1] = 0;
copy->save_stack_used = org->save_stack_used;
copy->el_count = 1;
copy->next = org->next;
org->next = copy;
return;
}
TRAVERSE_STACK & removeTraverseStack(TRAVERSE_STACK& copy)
{
FUNCNAME("removeStack");
......@@ -217,12 +259,17 @@ void printTraverseStack(TRAVERSE_STACK *stack)
{
FUNCNAME("printTraverseStack");
MSG("****************************************************\n");
MSG("current stack %8X | size %d \n", stack,stack->stack_size);
MSG("traverse_level %d \n",stack->traverse_level);
MSG("elinfo_stack = %8X\n",stack->elinfo_stack);
MSG("info_stack = %8X\n",stack->info_stack);
MSG("save_elinfo_stack = %8X\n",stack->save_elinfo_stack);
MSG("save_info_stack = %8X\n",stack->save_info_stack);
MSG("save_info_stack = %8X\n\n",stack->save_info_stack);
MSG("stack_used = %d\n",stack->stack_used);
MSG("save_stack_used = %d\n",stack->save_stack_used);
MSG("****************************************************\n");
}
......
......@@ -330,7 +330,7 @@ namespace Dune
}
template< int dim, int dimworld>
inline void AlbertGridElement<dim,dimworld>::
inline bool AlbertGridElement<dim,dimworld>::
builtGeom(ALBERT EL_INFO *elInfo, unsigned char face,
unsigned char edge, unsigned char vertex)
{
......@@ -346,7 +346,11 @@ namespace Dune
{
(coord_ (i))(j) = elInfo_->coord[mapVertices<dimworld-dim>(i)][j];
}
// geometry built
return true;
}
// geometry not built
return false;
}
......@@ -739,6 +743,7 @@ namespace Dune
//*************************************************************************
//
// --AlbertGridEntity
// --Entity
//
//*************************************************************************
//
......@@ -752,7 +757,8 @@ namespace Dune
makeDescription()
{
elInfo_ = NULL;
geo_.initGeom();
builtgeometry_ = false;
//geo_.initGeom();
}
template<int codim, int dim, int dimworld>
......@@ -795,7 +801,7 @@ namespace Dune
edge_ = edge;
vertex_ = vertex;
elInfo_ = elInfo;
geo_.builtGeom(elInfo_,face,edge,vertex);
builtgeometry_ = geo_.builtGeom(elInfo_,face,edge,vertex);
}
template<int codim, int dim, int dimworld>
......@@ -854,7 +860,10 @@ namespace Dune
makeDescription()
{
elInfo_ = NULL;
geo_.initGeom();
builtgeometry_ = false;
// not fast
//geo_.initGeom();
}
template<int dim, int dimworld>
......@@ -872,14 +881,14 @@ namespace Dune
travStack_ = travStack;
}
template< int dim, int dimworld>
inline AlbertGridEntity < 0, dim ,dimworld >::
AlbertGridEntity()
{
travStack_ = NULL;
makeDescription();
elInfo_ = NULL;
builtgeometry_ = false;
//makeDescription();
}
......@@ -913,13 +922,16 @@ namespace Dune
// in this case the face, edge and vertex information is not used,
// because we are in the element case
elInfo_ = elInfo;
geo_.builtGeom(elInfo_,face,edge,vertex);
builtgeometry_ = geo_.builtGeom(elInfo_,face,edge,vertex);
}
template< int dim, int dimworld>
inline AlbertGridElement<dim,dimworld>&
AlbertGridEntity < 0, dim ,dimworld >::geometry()
{
if(!builtgeometry_)
std::cout << "Warning: geometry has not been built \n";
return geo_;
}
......@@ -960,7 +972,6 @@ namespace Dune
inline void AlbertGridHierarchicIterator<dim,dimworld>::
makeIterator()
{
//initTraverseStack(&travStack_);
manageStack_.init();
virtualEntity_.setTraverseStack(NULL);
virtualEntity_.setElInfo(NULL,0,0,0);
......@@ -980,18 +991,25 @@ namespace Dune
{
if(travStack)
{
startLevel_ = (travStack->elinfo_stack[travStack->stack_used]).level;
// get new ALBERT TRAVERSE STACK
manageStack_.makeItNew(true);
ALBERT TRAVERSE_STACK *stack = manageStack_.getStack();
// make explicit memory copy of travStack
hardCopyStack(stack, travStack);
// cut old traverse stack, kepp only actual element
cutHierarchicStack(stack, travStack);
// set new traverse level
if(travLevel < 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
travLevel = 123456789;
}
// set new traverse level
stack->traverse_level = travLevel;
virtualEntity_.setTraverseStack(stack);
// Hier kann ein beliebiges Element uebergeben werden,
// da jedes AlbertElement einen Zeiger auf das Macroelement
// enthaelt.
......@@ -1009,7 +1027,6 @@ namespace Dune
AlbertGridHierarchicIterator< dim,dimworld >::operator ++()
{
// die 0 ist wichtig, weil Face 0, heist hier jetzt Element
//virtualEntity_.setElInfo(recursiveTraverse(&travStack_));
virtualEntity_.setElInfo(recursiveTraverse(manageStack_.getStack()));
return (*this);
}
......@@ -1059,67 +1076,43 @@ namespace Dune
AlbertGridHierarchicIterator<dim,dimworld>::
recursiveTraverse(ALBERT TRAVERSE_STACK * stack)
{
// siehe die Funktion
// see function
// static EL_INFO *traverse_leaf_el(TRAVERSE_STACK *stack)
// Common/traverse_nr_common.cc Zeile 392
// Common/traverse_nr_common.cc, line 392
ALBERT EL * el=NULL;
int i=0;
if(stack->stack_used == 0)
{ /* first call */
if(stack->traverse_mel == NULL)
return (NULL);
stack->stack_used = 1;
fill_macro_info(stack->traverse_mel,
stack->elinfo_stack + stack->stack_used);
stack->info_stack[stack->stack_used] = 0;
el = stack->elinfo_stack[stack->stack_used].el;
if((el == NULL) || (el->child[0] == nil))
{
return (stack->elinfo_stack + stack->stack_used);
}
if(!stack->elinfo_stack)
{
/* somethin' wrong */
return NULL;
}
else
{
el = stack->elinfo_stack[stack->stack_used].el;
/*
* go up in tree until we can go down again
*/
while((stack->stack_used > 0) &&
((stack->info_stack[stack->stack_used] >= 2) || (el->child[0]==nil)
((stack->info_stack[stack->stack_used] >= 2)
|| (el->child[0]==NULL)
|| ( stack->traverse_level <=
(stack->elinfo_stack+stack->stack_used)->level)) )
{
stack->stack_used--;
el = stack->elinfo_stack[stack->stack_used].el;
// dont go higher than the level we started
if( (stack->elinfo_stack[stack->stack_used]).level < startLevel_ )
return NULL;
}
/*
* goto next macro element is done by LevelIterator
*/
// 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) )
// 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);
i = stack->info_stack[stack->stack_used];
int i = stack->info_stack[stack->stack_used];
el = el->child[i];
stack->info_stack[stack->stack_used]++;
ALBERT fill_elinfo(i, stack->elinfo_stack + stack->stack_used,
......@@ -1493,6 +1486,7 @@ namespace Dune
intersection_self_local()
{
std::cout << "intersection_self_local not implemented yet! \n";
//fakeNeighBuilt_ = fakeNeigh_.builtGeom(neighElInfo_,neighborCount_,0,0);
return fakeNeigh_;
}
......@@ -1501,7 +1495,7 @@ namespace Dune
AlbertGridNeighborIterator<dim,dimworld>::
intersection_self_global()
{
neighGlob_.builtGeom(elInfo_,neighborCount_,0,0);
neighGlobBuilt_ = neighGlob_.builtGeom(elInfo_,neighborCount_,0,0);
return neighGlob_;
}
......@@ -1511,6 +1505,7 @@ namespace Dune
intersection_neighbor_local()
{
std::cout << "intersection_neighbor_local not implemented yet! \n";
//fakeNeighBuilt_ = fakeNeigh_.builtGeom(elInfo_,neighborCount_,0,0);
return fakeNeigh_;
}
......@@ -1519,7 +1514,7 @@ namespace Dune
AlbertGridNeighborIterator<dim,dimworld>::
intersection_neighbor_global()
{
neighGlob_.builtGeom(elInfo_,neighborCount_,0,0);
neighGlobBuilt_ = neighGlob_.builtGeom(elInfo_,neighborCount_,0,0);
return neighGlob_;
}
......@@ -1587,7 +1582,6 @@ namespace Dune
// diese Methode muss neu geschrieben werden, da man
// die ParentElement explizit speichern moechte.
virtualEntity_.setElInfo(elInfo,face_,edge_,vertex_);
}
else
......@@ -1626,8 +1620,6 @@ namespace Dune
ALBERT EL_INFO* elInfo =
goFirstElement(manageStack_.getStack(), mesh, travLevel,travFlags);
//std::cout << manageStack_.getStack()->stack_size << "LevelStack \n";
virtualEntity_.setElInfo(elInfo,face_,edge_,vertex_);
}
else
......
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