Commit bf3468a4 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* ElInfoStack added

* Traverse:recursive uses ElInfoStack and is much faster :)
parent 5804e778
......@@ -105,6 +105,7 @@ $(SOURCE_DIR)/DOFContainer.h \
$(SOURCE_DIR)/FileWriter.h $(SOURCE_DIR)/FileWriter.hh $(SOURCE_DIR)/FileWriter.cc \
$(SOURCE_DIR)/ElementFileWriter.h $(SOURCE_DIR)/ElementFileWriter.cc \
$(SOURCE_DIR)/ElInfo.cc \
$(SOURCE_DIR)/ElInfoStack.h $(SOURCE_DIR)/ElInfoStack.cc \
$(SOURCE_DIR)/MatVecMultiplier.h \
$(SOURCE_DIR)/Operator.h $(SOURCE_DIR)/Operator.cc \
$(SOURCE_DIR)/Mesh.cc \
......
......@@ -140,6 +140,7 @@ am__libamdis_la_SOURCES_DIST = $(PARALLEL_DIR)/ConditionalEstimator.h \
$(SOURCE_DIR)/FileWriter.h $(SOURCE_DIR)/FileWriter.hh \
$(SOURCE_DIR)/FileWriter.cc $(SOURCE_DIR)/ElementFileWriter.h \
$(SOURCE_DIR)/ElementFileWriter.cc $(SOURCE_DIR)/ElInfo.cc \
$(SOURCE_DIR)/ElInfoStack.h $(SOURCE_DIR)/ElInfoStack.cc \
$(SOURCE_DIR)/MatVecMultiplier.h $(SOURCE_DIR)/Operator.h \
$(SOURCE_DIR)/Operator.cc $(SOURCE_DIR)/Mesh.cc \
$(SOURCE_DIR)/AMDiS.h $(SOURCE_DIR)/AdaptStationary.h \
......@@ -265,8 +266,9 @@ am_libamdis_la_OBJECTS = $(am__objects_1) \
libamdis_la-BoundaryManager.lo libamdis_la-DirichletBC.lo \
libamdis_la-RobinBC.lo libamdis_la-MatVecMultiplier.lo \
libamdis_la-FileWriter.lo libamdis_la-ElementFileWriter.lo \
libamdis_la-ElInfo.lo libamdis_la-Operator.lo \
libamdis_la-Mesh.lo libamdis_la-AdaptStationary.lo \
libamdis_la-ElInfo.lo libamdis_la-ElInfoStack.lo \
libamdis_la-Operator.lo libamdis_la-Mesh.lo \
libamdis_la-AdaptStationary.lo \
libamdis_la-AdaptInstationary.lo \
libamdis_la-DiagonalPreconditioner.lo \
libamdis_la-ILUPreconditioner.lo \
......@@ -532,6 +534,7 @@ $(SOURCE_DIR)/DOFContainer.h \
$(SOURCE_DIR)/FileWriter.h $(SOURCE_DIR)/FileWriter.hh $(SOURCE_DIR)/FileWriter.cc \
$(SOURCE_DIR)/ElementFileWriter.h $(SOURCE_DIR)/ElementFileWriter.cc \
$(SOURCE_DIR)/ElInfo.cc \
$(SOURCE_DIR)/ElInfoStack.h $(SOURCE_DIR)/ElInfoStack.cc \
$(SOURCE_DIR)/MatVecMultiplier.h \
$(SOURCE_DIR)/Operator.h $(SOURCE_DIR)/Operator.cc \
$(SOURCE_DIR)/Mesh.cc \
......@@ -772,6 +775,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ElInfo1d.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ElInfo2d.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ElInfo3d.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ElInfoStack.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-Element.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ElementData.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ElementFileWriter.Plo@am__quote@
......@@ -1193,6 +1197,13 @@ libamdis_la-ElInfo.lo: $(SOURCE_DIR)/ElInfo.cc
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libamdis_la_CXXFLAGS) $(CXXFLAGS) -c -o libamdis_la-ElInfo.lo `test -f '$(SOURCE_DIR)/ElInfo.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/ElInfo.cc
libamdis_la-ElInfoStack.lo: $(SOURCE_DIR)/ElInfoStack.cc
@am__fastdepCXX_TRUE@ if $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libamdis_la_CXXFLAGS) $(CXXFLAGS) -MT libamdis_la-ElInfoStack.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-ElInfoStack.Tpo" -c -o libamdis_la-ElInfoStack.lo `test -f '$(SOURCE_DIR)/ElInfoStack.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/ElInfoStack.cc; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libamdis_la-ElInfoStack.Tpo" "$(DEPDIR)/libamdis_la-ElInfoStack.Plo"; else rm -f "$(DEPDIR)/libamdis_la-ElInfoStack.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$(SOURCE_DIR)/ElInfoStack.cc' object='libamdis_la-ElInfoStack.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libamdis_la_CXXFLAGS) $(CXXFLAGS) -c -o libamdis_la-ElInfoStack.lo `test -f '$(SOURCE_DIR)/ElInfoStack.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/ElInfoStack.cc
libamdis_la-Operator.lo: $(SOURCE_DIR)/Operator.cc
@am__fastdepCXX_TRUE@ if $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libamdis_la_CXXFLAGS) $(CXXFLAGS) -MT libamdis_la-Operator.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-Operator.Tpo" -c -o libamdis_la-Operator.lo `test -f '$(SOURCE_DIR)/Operator.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/Operator.cc; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libamdis_la-Operator.Tpo" "$(DEPDIR)/libamdis_la-Operator.Plo"; else rm -f "$(DEPDIR)/libamdis_la-Operator.Tpo"; exit 1; fi
......
#include "ElInfoStack.h"
#include "Mesh.h"
namespace AMDiS {
ElInfoStack::ElInfoStack(Mesh *mesh)
: mesh_(mesh),
stackPosition_(-1)
{
elInfoStack_.resize(20);
for (int i = 0; i < 20; i++) {
elInfoStack_[i] = mesh_->createNewElInfo();
}
}
ElInfoStack::~ElInfoStack()
{
for (int i = 0; i < static_cast<int>(elInfoStack_.size()); i++) {
DELETE elInfoStack_[i];
}
}
ElInfo* ElInfoStack::getNextElement()
{
// Check if the stack if large enough. If not, the stack is enlarged
// and new elements are created.
if (stackPosition_ + 1 >= static_cast<int>(elInfoStack_.size())) {
int oldSize = elInfoStack_.size();
elInfoStack_.resize(oldSize + oldSize / 2);
for (int i = oldSize; i < static_cast<int>(elInfoStack_.size()); i++) {
elInfoStack_[i] = mesh_->createNewElInfo();
}
}
stackPosition_++;
return elInfoStack_[stackPosition_];
}
void ElInfoStack::getBackElement()
{
TEST_EXIT_DBG(stackPosition_ >= 0)("Invalid stack position!\n");
stackPosition_--;
}
ElInfo* ElInfoStack::getCurrentElement()
{
TEST_EXIT_DBG(stackPosition_ >= 0)("Invalid stack position!\n");
return elInfoStack_[stackPosition_];
}
}
// ============================================================================
// == ==
// == AMDiS - Adaptive multidimensional simulations ==
// == ==
// ============================================================================
// == ==
// == crystal growth group ==
// == ==
// == Stiftung caesar ==
// == Ludwig-Erhard-Allee 2 ==
// == 53175 Bonn ==
// == germany ==
// == ==
// ============================================================================
// == ==
// == http://www.caesar.de/cg/AMDiS ==
// == ==
// ============================================================================
/** \file ElInfo.h */
#ifndef AMDIS_ELINFOSTACK_H
#define AMDIS_ELINFOSTACK_H
// ============================================================================
// ===== includes =============================================================
// ============================================================================
#include <vector>
#include "ElInfo.h"
namespace AMDiS {
// ============================================================================
// ===== forward declarations =================================================
// ============================================================================
class Mesh;
// ============================================================================
// ===== class ElInfoStack ====================================================
// ============================================================================
/** \ingroup Traverse
* \brief
* Stores a stack of ElInfo object. Is used by meshes for recursive mesh
* traverse. The use of a stack is cheaper than allocating the ElInfo objects
* at every recursive step.
*/
class ElInfoStack
{
public:
/** \brief
* Constructer, creates the stack.
*/
ElInfoStack(Mesh *mesh);
/** \brief
* Destructor, deletes all ElInfos on the stack.
*/
~ElInfoStack();
/** \brief
* Get a new element from the stack an increase the stack position.
*/
ElInfo* getNextElement();
/** \brief
* Decrease the stack position.
*/
void getBackElement();
/** \brief
* Returns a pointer to the currently used element of the stack.
*/
ElInfo* getCurrentElement();
protected:
/** \brief
* The mesh on which the traverse is done.
*/
Mesh *mesh_;
/** \brief
* The stack of pointers to ElInfo objects.
*/
::std::vector<ElInfo*> elInfoStack_;
/** \brief
* Current position (depth) of the recursive mesh traverse.
*/
int stackPosition_;
};
}
#endif // AMDIS_ELINFOSTACK_H
#include <algorithm>
#include <set>
#include <map>
#include "time.h"
#include "AdaptStationary.h"
#include "AdaptInstationary.h"
#include "FiniteElemSpace.h"
......@@ -15,11 +21,8 @@
#include "MacroWriter.h"
#include "PeriodicMap.h"
#include "Projection.h"
#include <algorithm>
#include <set>
#include <map>
#include "ElInfoStack.h"
#include "time.h"
namespace AMDiS {
......@@ -131,8 +134,10 @@ namespace AMDiS {
int (*el_fct)(ElInfo*))
{
FUNCNAME("Mesh::traverse()");
::std::deque<MacroElement*>::iterator mel;
ElInfo* elinfo = createNewElInfo();
ElInfoStack elInfoStack(this);
ElInfo* elinfo = elInfoStack.getNextElement();
Traverse tinfo(this, flag, level, el_fct);
int sum = 0;
......@@ -146,10 +151,10 @@ namespace AMDiS {
for (mel = macroElements.begin(); mel != macroElements.end(); mel++) {
elinfo->fillMacroInfo(*mel);
sum += tinfo.recursive(elinfo);
sum += tinfo.recursive(&elInfoStack);
}
DELETE elinfo;
elInfoStack.getBackElement();
return (flag.isSet(Mesh::FILL_ADD_ALL)) ? sum : 0;
}
......
......@@ -112,10 +112,13 @@ namespace AMDiS {
/* depending on the traverse_info->level variable */
/****************************************************************************/
int Traverse::recursive(ElInfo *elinfo)
// int Traverse::recursive(ElInfo *elinfo)
int Traverse::recursive(ElInfoStack *elInfoStack)
{
FUNCNAME("Traverse::recursive()");
ElInfo *elinfo = elInfoStack->getCurrentElement();
Element *el = elinfo->getElement();
int mg_level, sum = 0;
Parametric *parametric = mesh->getParametric();
......@@ -123,164 +126,174 @@ namespace AMDiS {
if (flag.isSet(Mesh::CALL_LEAF_EL)) {
if (el->getFirstChild()) {
ElInfo* elinfo_new = mesh->createNewElInfo();
ElInfo* elinfo_new = elInfoStack->getNextElement();
elinfo_new->fillElInfo(0, elinfo);
sum += recursive(elinfo_new);
sum += recursive(elInfoStack);
elinfo_new->fillElInfo(1, elinfo);
sum += recursive(elinfo_new);
DELETE elinfo_new;
sum += recursive(elInfoStack);
elInfoStack->getBackElement();
} else {
if (el_fct != NULL) {
if (parametric)
elinfo = parametric->addParametricInfo(elinfo);
elinfo->fillDetGrdLambda();
sum+=el_fct(elinfo);
sum += el_fct(elinfo);
if (parametric)
elinfo = parametric->removeParametricInfo(elinfo);
}
}
return (flag.isSet(Mesh::FILL_ADD_ALL))?sum:0;;
return (flag.isSet(Mesh::FILL_ADD_ALL)) ? sum : 0;
}
if (flag.isSet(Mesh::CALL_LEAF_EL_LEVEL)) {
if (el->getFirstChild()) {
if ((elinfo->getLevel() >= level)) {
return (flag.isSet(Mesh::FILL_ADD_ALL))?sum:0;
return (flag.isSet(Mesh::FILL_ADD_ALL)) ? sum : 0;
}
ElInfo* elinfo_new = mesh->createNewElInfo();
ElInfo* elinfo_new = elInfoStack->getNextElement();
elinfo_new->fillElInfo(0, elinfo);
sum += recursive(elinfo_new);
sum += recursive(elInfoStack);
elinfo->fillElInfo(1, elinfo);
sum += recursive(elinfo_new);
DELETE elinfo_new;
}
else {
sum += recursive(elInfoStack);
elInfoStack->getBackElement();
} else {
if ((elinfo->getLevel() == level) && (el_fct!=NULL)) {
if (parametric)
elinfo = parametric->addParametricInfo(elinfo);
elinfo->fillDetGrdLambda();
sum+=el_fct(elinfo);
sum += el_fct(elinfo);
if (parametric)
elinfo = parametric->removeParametricInfo(elinfo);
}
}
return (flag.isSet(Mesh::FILL_ADD_ALL))?sum:0;
return (flag.isSet(Mesh::FILL_ADD_ALL)) ? sum : 0;
}
if (flag.isSet(Mesh::CALL_EL_LEVEL)) {
if (elinfo->getLevel() == level) {
if (NULL!=el_fct) {
if(parametric) elinfo = parametric->addParametricInfo(elinfo);
if (NULL != el_fct) {
if (parametric)
elinfo = parametric->addParametricInfo(elinfo);
elinfo->fillDetGrdLambda();
sum+=el_fct(elinfo);
if(parametric) elinfo = parametric->removeParametricInfo(elinfo);
}
sum += el_fct(elinfo);
if (parametric)
elinfo = parametric->removeParametricInfo(elinfo);
}
else {
} else {
if (elinfo->getLevel() > level){
return(flag.isSet(Mesh::FILL_ADD_ALL))?sum:0;
}
else
if (el->getFirstChild()) {
ElInfo* elinfo_new = mesh->createNewElInfo();
return (flag.isSet(Mesh::FILL_ADD_ALL)) ? sum : 0;
} else if (el->getFirstChild()) {
ElInfo* elinfo_new = elInfoStack->getNextElement();
elinfo_new->fillElInfo(0, elinfo);
sum+=recursive(elinfo_new);
sum += recursive(elInfoStack);
elinfo_new->fillElInfo(1, elinfo);
sum+=recursive(elinfo_new);
DELETE elinfo_new;
sum += recursive(elInfoStack);
elInfoStack->getBackElement();
}
}
return (flag.isSet(Mesh::FILL_ADD_ALL))?sum:0;
return (flag.isSet(Mesh::FILL_ADD_ALL)) ? sum : 0;
}
if (flag.isSet(Mesh::CALL_MG_LEVEL)) {
mg_level = (static_cast<int>(elinfo->getLevel()) +
mesh->getDim()-1) / mesh->getDim();
mg_level = (static_cast<int>(elinfo->getLevel()) + mesh->getDim() - 1) /
mesh->getDim();
if (mg_level > static_cast<int>(level)) {
return 0;
}
if (!(el->getFirstChild())) {
if (el_fct!=NULL) {
if(parametric) elinfo = parametric->addParametricInfo(elinfo);
if (el_fct != NULL) {
if (parametric)
elinfo = parametric->addParametricInfo(elinfo);
elinfo->fillDetGrdLambda();
sum+=el_fct(elinfo);
if(parametric) elinfo = parametric->removeParametricInfo(elinfo);
sum += el_fct(elinfo);
if (parametric)
elinfo = parametric->removeParametricInfo(elinfo);
}
return (flag.isSet(Mesh::FILL_ADD_ALL))?sum:0;
return (flag.isSet(Mesh::FILL_ADD_ALL)) ? sum : 0;
}
if ((mg_level == level) && ((elinfo->getLevel() % mesh->getDim()) == 0))
{
if (el_fct!=NULL) {
if(parametric) elinfo = parametric->addParametricInfo(elinfo);
if ((mg_level == level) && ((elinfo->getLevel() % mesh->getDim()) == 0)) {
if (el_fct != NULL) {
if (parametric)
elinfo = parametric->addParametricInfo(elinfo);
elinfo->fillDetGrdLambda();
sum+=el_fct(elinfo);
if(parametric) elinfo = parametric->removeParametricInfo(elinfo);
sum += el_fct(elinfo);
if (parametric)
elinfo = parametric->removeParametricInfo(elinfo);
}
return(flag.isSet(Mesh::FILL_ADD_ALL))?sum:0;;
return (flag.isSet(Mesh::FILL_ADD_ALL)) ? sum : 0;
}
ElInfo* elinfo_new = mesh->createNewElInfo();
ElInfo* elinfo_new = elInfoStack->getNextElement();
elinfo_new->fillElInfo(0, elinfo);
sum+=recursive(elinfo_new);
sum += recursive(elInfoStack);
elinfo_new->fillElInfo(1, elinfo);
sum+=recursive(elinfo_new);
sum += recursive(elInfoStack);
DELETE elinfo_new;
return(flag.isSet(Mesh::FILL_ADD_ALL))?sum:0;
elInfoStack->getBackElement();
return (flag.isSet(Mesh::FILL_ADD_ALL)) ? sum : 0;
}
if (flag.isSet(Mesh::CALL_EVERY_EL_PREORDER))
if (flag.isSet(Mesh::CALL_EVERY_EL_PREORDER)) {
if (el_fct != NULL) {
if(parametric) elinfo = parametric->addParametricInfo(elinfo);
if (parametric)
elinfo = parametric->addParametricInfo(elinfo);
elinfo->fillDetGrdLambda();
sum+=el_fct(elinfo);
if(parametric) elinfo = parametric->removeParametricInfo(elinfo);
sum += el_fct(elinfo);
if (parametric)
elinfo = parametric->removeParametricInfo(elinfo);
}
}
if (el->getFirstChild()) {
ElInfo* elinfo_new = mesh->createNewElInfo();
ElInfo* elinfo_new = elInfoStack->getNextElement();
elinfo_new->fillElInfo(0, elinfo);
sum+= recursive(elinfo_new);
sum += recursive(elInfoStack);
if (flag.isSet(Mesh::CALL_EVERY_EL_INORDER))
if (el_fct!=NULL) {
if(parametric) elinfo = parametric->addParametricInfo(elinfo);
if (parametric)
elinfo = parametric->addParametricInfo(elinfo);
elinfo->fillDetGrdLambda();
sum+=el_fct(elinfo);
if(parametric) elinfo = parametric->removeParametricInfo(elinfo);
sum += el_fct(elinfo);
if (parametric)
elinfo = parametric->removeParametricInfo(elinfo);
}
elinfo_new->fillElInfo(1, elinfo);
sum+= recursive(elinfo_new);
sum += recursive(elInfoStack);
DELETE elinfo_new;
}
else {
elInfoStack->getBackElement();
} else {
if (flag.isSet(Mesh::CALL_EVERY_EL_INORDER))
if (el_fct!=NULL) {
if(parametric) elinfo = parametric->addParametricInfo(elinfo);
if (el_fct != NULL) {
if (parametric)
elinfo = parametric->addParametricInfo(elinfo);
elinfo->fillDetGrdLambda();
sum+=el_fct(elinfo);
if(parametric) elinfo = parametric->removeParametricInfo(elinfo);
sum += el_fct(elinfo);
if (parametric)
elinfo = parametric->removeParametricInfo(elinfo);
}
}
if (flag.isSet(Mesh::CALL_EVERY_EL_POSTORDER))
if (el_fct!=NULL) {
if(parametric) elinfo = parametric->addParametricInfo(elinfo);
if (el_fct != NULL) {
if (parametric)
elinfo = parametric->addParametricInfo(elinfo);
elinfo->fillDetGrdLambda();
sum+=el_fct(elinfo);
if(parametric) elinfo = parametric->removeParametricInfo(elinfo);
sum += el_fct(elinfo);
if (parametric)
elinfo = parametric->removeParametricInfo(elinfo);
}
return(flag.isSet(Mesh::FILL_ADD_ALL))?sum:0;
return (flag.isSet(Mesh::FILL_ADD_ALL)) ? sum : 0;
}
void TraverseStack::enlargeTraverseStack()
......
......@@ -32,6 +32,7 @@
#include "Flag.h"
#include "Global.h"
#include "ElInfo.h"
#include "ElInfoStack.h"
#include "MemoryManager.h"
#include <vector>
#include <deque>
......@@ -304,7 +305,10 @@ namespace AMDiS {
const Flag f,
const unsigned char l,
int (*ef)(ElInfo*))
:mesh(m),flag(f),level(l),el_fct(ef)
: mesh(m),
flag(f),
level(l),
el_fct(ef)
{
TEST_EXIT(m)("No traverse without mesh!\n");
id = ElInfo::traverseIdCounter++;
......@@ -313,7 +317,8 @@ namespace AMDiS {
/** \brief
* Performs the recursive traversal
*/
int recursive(ElInfo*);
// int recursive(ElInfo*);
int recursive(ElInfoStack*);
private:
Mesh *mesh;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment