From 7083229fc8a31f2714c16059cd9c6f28cc54f7ab Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Tue, 8 Dec 2009 16:21:48 +0000
Subject: [PATCH] Work on adaptivity in parallelization code.

---
 AMDiS/bin/Makefile.am            |  21 ++--
 AMDiS/bin/Makefile.in            |  58 +++++------
 AMDiS/libtool                    |  66 ++++++-------
 AMDiS/src/AMDiS.h                |   2 +-
 AMDiS/src/CoarseningManager.cc   |  27 ++---
 AMDiS/src/Mesh.cc                |  57 ++++++-----
 AMDiS/src/Mesh.h                 |  23 ++++-
 AMDiS/src/MeshStructure.cc       |  93 ++++++++---------
 AMDiS/src/MeshStructure.h        |  63 ++++++------
 AMDiS/src/MeshStructure_ED.h     |  43 ++++----
 AMDiS/src/ParallelDomainBase.cc  | 165 +++++++++++--------------------
 AMDiS/src/ParallelDomainBase.h   |  22 +++--
 AMDiS/src/ParallelDomainScal.cc  |  62 ------------
 AMDiS/src/ParallelDomainScal.h   |  63 ------------
 AMDiS/src/RefinementManager.cc   |  13 ++-
 AMDiS/src/RefinementManager2d.cc |   3 +-
 16 files changed, 312 insertions(+), 469 deletions(-)
 delete mode 100644 AMDiS/src/ParallelDomainScal.cc
 delete mode 100644 AMDiS/src/ParallelDomainScal.h

diff --git a/AMDiS/bin/Makefile.am b/AMDiS/bin/Makefile.am
index 62593ec7..2dd03c77 100644
--- a/AMDiS/bin/Makefile.am
+++ b/AMDiS/bin/Makefile.am
@@ -14,8 +14,6 @@ if USE_PARALLEL_AMDIS
   PARALLEL_AMDIS_SOURCES = \
   $(PARALLEL_DIR)/ConditionalEstimator.h $(PARALLEL_DIR)/ConditionalEstimator.cc \
   $(PARALLEL_DIR)/ConditionalMarker.h \
-  $(PARALLEL_DIR)/MeshStructure.h $(PARALLEL_DIR)/MeshStructure.cc \
-  $(PARALLEL_DIR)/MeshStructure_ED.h \
   $(PARALLEL_DIR)/ParallelError.h $(PARALLEL_DIR)/ParallelError.hh \
   $(PARALLEL_DIR)/ParallelProblem.h $(PARALLEL_DIR)/ParallelProblem.cc \
   $(PARALLEL_DIR)/ParMetisPartitioner.h $(PARALLEL_DIR)/ParMetisPartitioner.cc \
@@ -30,7 +28,6 @@ endif
 if USE_PARALLEL_DOMAIN_AMDIS
   PARALLEL_AMDIS_SOURCES += \
   $(PARALLEL_DIR)/ParallelDomainBase.h $(PARALLEL_DIR)/ParallelDomainBase.cc \
-  $(PARALLEL_DIR)/ParallelDomainScal.h $(PARALLEL_DIR)/ParallelDomainScal.cc \
   $(PARALLEL_DIR)/ParallelDomainVec.h $(PARALLEL_DIR)/ParallelDomainVec.cc
   libamdis_la_CXXFLAGS += -DHAVE_PARALLEL_DOMAIN_AMDIS=1
   AMDIS_INCLUDES += -I$(PETSC_DIR)/include -I$(PETSC_DIR)/$(PETSC_ARCH)/include
@@ -121,6 +118,8 @@ $(SOURCE_DIR)/ElInfo.cc \
 $(SOURCE_DIR)/ElInfoStack.h $(SOURCE_DIR)/ElInfoStack.cc \
 $(SOURCE_DIR)/Operator.h $(SOURCE_DIR)/Operator.cc \
 $(SOURCE_DIR)/Mesh.cc \
+$(SOURCE_DIR)/MeshStructure.h $(SOURCE_DIR)/MeshStructure.cc \
+$(SOURCE_DIR)/MeshStructure_ED.h \
 $(SOURCE_DIR)/AMDiS.h \
 $(SOURCE_DIR)/AdaptStationary.h $(SOURCE_DIR)/AdaptStationary.cc \
 $(SOURCE_DIR)/AdaptInstationary.h $(SOURCE_DIR)/AdaptInstationary.cc \
@@ -130,9 +129,19 @@ $(SOURCE_DIR)/Boundary.h \
 $(SOURCE_DIR)/ITL_Solver.h \
 $(SOURCE_DIR)/CoarseningManager.h \
 $(SOURCE_DIR)/CoarseningManager1d.h $(SOURCE_DIR)/CoarseningManager2d.h $(SOURCE_DIR)/CoarseningManager3d.h \
-$(SOURCE_DIR)/DOFAdmin.h $(SOURCE_DIR)/DOFIterator.h $(SOURCE_DIR)/DOFMatrix.h $(SOURCE_DIR)/DOFVector.h $(SOURCE_DIR)/DOFVector.hh $(SOURCE_DIR)/DOFVector.cc $(SOURCE_DIR)/Element.h $(SOURCE_DIR)/ElementConnection.h \
-$(SOURCE_DIR)/ElInfo.h $(SOURCE_DIR)/ElInfo1d.h $(SOURCE_DIR)/ElInfo2d.h $(SOURCE_DIR)/ElInfo3d.h $(SOURCE_DIR)/Error.h \
-$(SOURCE_DIR)/Error.hh $(SOURCE_DIR)/Estimator.h $(SOURCE_DIR)/Estimator.cc $(SOURCE_DIR)/FiniteElemSpace.h $(SOURCE_DIR)/FixVec.h $(SOURCE_DIR)/FixVec.hh $(SOURCE_DIR)/FixVecConvert.h $(SOURCE_DIR)/Flag.h $(SOURCE_DIR)/Global.h \
+$(SOURCE_DIR)/DOFAdmin.h \
+$(SOURCE_DIR)/DOFIterator.h \
+$(SOURCE_DIR)/DOFMatrix.h \
+$(SOURCE_DIR)/DOFVector.h $(SOURCE_DIR)/DOFVector.hh $(SOURCE_DIR)/DOFVector.cc \
+$(SOURCE_DIR)/Element.h $(SOURCE_DIR)/ElementConnection.h \
+$(SOURCE_DIR)/ElInfo.h $(SOURCE_DIR)/ElInfo1d.h $(SOURCE_DIR)/ElInfo2d.h $(SOURCE_DIR)/ElInfo3d.h \
+$(SOURCE_DIR)/Error.h $(SOURCE_DIR)/Error.hh \
+$(SOURCE_DIR)/Estimator.h $(SOURCE_DIR)/Estimator.cc \
+$(SOURCE_DIR)/FiniteElemSpace.h \
+$(SOURCE_DIR)/FixVec.h $(SOURCE_DIR)/FixVec.hh \
+$(SOURCE_DIR)/FixVecConvert.h \
+$(SOURCE_DIR)/Flag.h \
+$(SOURCE_DIR)/Global.h \
 $(SOURCE_DIR)/UmfPackSolver.h \ $(SOURCE_DIR)/UmfPackSolver.hh \
 $(SOURCE_DIR)/Lagrange.h $(SOURCE_DIR)/Line.h \
 $(SOURCE_DIR)/MacroElement.h $(SOURCE_DIR)/MacroWriter.h \
diff --git a/AMDiS/bin/Makefile.in b/AMDiS/bin/Makefile.in
index aeed7614..1ef135b2 100644
--- a/AMDiS/bin/Makefile.in
+++ b/AMDiS/bin/Makefile.in
@@ -39,7 +39,6 @@ host_triplet = @host@
 @USE_PARALLEL_AMDIS_TRUE@am__append_1 = -DHAVE_PARALLEL_AMDIS=1
 @USE_PARALLEL_DOMAIN_AMDIS_TRUE@am__append_2 = \
 @USE_PARALLEL_DOMAIN_AMDIS_TRUE@  $(PARALLEL_DIR)/ParallelDomainBase.h $(PARALLEL_DIR)/ParallelDomainBase.cc \
-@USE_PARALLEL_DOMAIN_AMDIS_TRUE@  $(PARALLEL_DIR)/ParallelDomainScal.h $(PARALLEL_DIR)/ParallelDomainScal.cc \
 @USE_PARALLEL_DOMAIN_AMDIS_TRUE@  $(PARALLEL_DIR)/ParallelDomainVec.h $(PARALLEL_DIR)/ParallelDomainVec.cc
 
 @USE_PARALLEL_DOMAIN_AMDIS_TRUE@am__append_3 = -DHAVE_PARALLEL_DOMAIN_AMDIS=1
@@ -75,16 +74,11 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
 libamdis_la_LIBADD =
 am__libamdis_la_SOURCES_DIST = $(PARALLEL_DIR)/ParallelDomainBase.h \
 	$(PARALLEL_DIR)/ParallelDomainBase.cc \
-	$(PARALLEL_DIR)/ParallelDomainScal.h \
-	$(PARALLEL_DIR)/ParallelDomainScal.cc \
 	$(PARALLEL_DIR)/ParallelDomainVec.h \
 	$(PARALLEL_DIR)/ParallelDomainVec.cc \
 	$(PARALLEL_DIR)/ConditionalEstimator.h \
 	$(PARALLEL_DIR)/ConditionalEstimator.cc \
 	$(PARALLEL_DIR)/ConditionalMarker.h \
-	$(PARALLEL_DIR)/MeshStructure.h \
-	$(PARALLEL_DIR)/MeshStructure.cc \
-	$(PARALLEL_DIR)/MeshStructure_ED.h \
 	$(PARALLEL_DIR)/ParallelError.h \
 	$(PARALLEL_DIR)/ParallelError.hh \
 	$(PARALLEL_DIR)/ParallelProblem.h \
@@ -151,7 +145,9 @@ am__libamdis_la_SOURCES_DIST = $(PARALLEL_DIR)/ParallelDomainBase.h \
 	$(SOURCE_DIR)/ElementFileWriter.cc $(SOURCE_DIR)/ElInfo.cc \
 	$(SOURCE_DIR)/ElInfoStack.h $(SOURCE_DIR)/ElInfoStack.cc \
 	$(SOURCE_DIR)/Operator.h $(SOURCE_DIR)/Operator.cc \
-	$(SOURCE_DIR)/Mesh.cc $(SOURCE_DIR)/AMDiS.h \
+	$(SOURCE_DIR)/Mesh.cc $(SOURCE_DIR)/MeshStructure.h \
+	$(SOURCE_DIR)/MeshStructure.cc \
+	$(SOURCE_DIR)/MeshStructure_ED.h $(SOURCE_DIR)/AMDiS.h \
 	$(SOURCE_DIR)/AdaptStationary.h \
 	$(SOURCE_DIR)/AdaptStationary.cc \
 	$(SOURCE_DIR)/AdaptInstationary.h \
@@ -232,12 +228,10 @@ am__libamdis_la_SOURCES_DIST = $(PARALLEL_DIR)/ParallelDomainBase.h \
 	$(SOURCE_DIR)/parareal/AdaptParaReal.h \
 	$(SOURCE_DIR)/parareal/AdaptParaReal.cc
 @USE_PARALLEL_DOMAIN_AMDIS_TRUE@am__objects_1 = libamdis_la-ParallelDomainBase.lo \
-@USE_PARALLEL_DOMAIN_AMDIS_TRUE@	libamdis_la-ParallelDomainScal.lo \
 @USE_PARALLEL_DOMAIN_AMDIS_TRUE@	libamdis_la-ParallelDomainVec.lo
 @USE_PARALLEL_AMDIS_FALSE@am__objects_2 = $(am__objects_1)
 @USE_PARALLEL_AMDIS_TRUE@am__objects_2 =  \
 @USE_PARALLEL_AMDIS_TRUE@	libamdis_la-ConditionalEstimator.lo \
-@USE_PARALLEL_AMDIS_TRUE@	libamdis_la-MeshStructure.lo \
 @USE_PARALLEL_AMDIS_TRUE@	libamdis_la-ParallelProblem.lo \
 @USE_PARALLEL_AMDIS_TRUE@	libamdis_la-ParMetisPartitioner.lo \
 @USE_PARALLEL_AMDIS_TRUE@	$(am__objects_1)
@@ -264,7 +258,8 @@ am_libamdis_la_OBJECTS = $(am__objects_2) libamdis_la-DOFIndexed.lo \
 	libamdis_la-RobinBC.lo libamdis_la-FileWriter.lo \
 	libamdis_la-ElementFileWriter.lo libamdis_la-ElInfo.lo \
 	libamdis_la-ElInfoStack.lo libamdis_la-Operator.lo \
-	libamdis_la-Mesh.lo libamdis_la-AdaptStationary.lo \
+	libamdis_la-Mesh.lo libamdis_la-MeshStructure.lo \
+	libamdis_la-AdaptStationary.lo \
 	libamdis_la-AdaptInstationary.lo libamdis_la-DOFVector.lo \
 	libamdis_la-Estimator.lo libamdis_la-ProblemInstat.lo \
 	libamdis_la-ProblemNonLin.lo libamdis_la-NonLinUpdater.lo \
@@ -465,9 +460,6 @@ libamdis_la_CXXFLAGS = $(am__append_1) $(am__append_3) $(am__append_5) \
 @USE_PARALLEL_AMDIS_TRUE@PARALLEL_AMDIS_SOURCES = $(PARALLEL_DIR)/ConditionalEstimator.h \
 @USE_PARALLEL_AMDIS_TRUE@	$(PARALLEL_DIR)/ConditionalEstimator.cc \
 @USE_PARALLEL_AMDIS_TRUE@	$(PARALLEL_DIR)/ConditionalMarker.h \
-@USE_PARALLEL_AMDIS_TRUE@	$(PARALLEL_DIR)/MeshStructure.h \
-@USE_PARALLEL_AMDIS_TRUE@	$(PARALLEL_DIR)/MeshStructure.cc \
-@USE_PARALLEL_AMDIS_TRUE@	$(PARALLEL_DIR)/MeshStructure_ED.h \
 @USE_PARALLEL_AMDIS_TRUE@	$(PARALLEL_DIR)/ParallelError.h \
 @USE_PARALLEL_AMDIS_TRUE@	$(PARALLEL_DIR)/ParallelError.hh \
 @USE_PARALLEL_AMDIS_TRUE@	$(PARALLEL_DIR)/ParallelProblem.h \
@@ -535,6 +527,8 @@ $(SOURCE_DIR)/ElInfo.cc \
 $(SOURCE_DIR)/ElInfoStack.h $(SOURCE_DIR)/ElInfoStack.cc \
 $(SOURCE_DIR)/Operator.h $(SOURCE_DIR)/Operator.cc \
 $(SOURCE_DIR)/Mesh.cc \
+$(SOURCE_DIR)/MeshStructure.h $(SOURCE_DIR)/MeshStructure.cc \
+$(SOURCE_DIR)/MeshStructure_ED.h \
 $(SOURCE_DIR)/AMDiS.h \
 $(SOURCE_DIR)/AdaptStationary.h $(SOURCE_DIR)/AdaptStationary.cc \
 $(SOURCE_DIR)/AdaptInstationary.h $(SOURCE_DIR)/AdaptInstationary.cc \
@@ -544,9 +538,19 @@ $(SOURCE_DIR)/Boundary.h \
 $(SOURCE_DIR)/ITL_Solver.h \
 $(SOURCE_DIR)/CoarseningManager.h \
 $(SOURCE_DIR)/CoarseningManager1d.h $(SOURCE_DIR)/CoarseningManager2d.h $(SOURCE_DIR)/CoarseningManager3d.h \
-$(SOURCE_DIR)/DOFAdmin.h $(SOURCE_DIR)/DOFIterator.h $(SOURCE_DIR)/DOFMatrix.h $(SOURCE_DIR)/DOFVector.h $(SOURCE_DIR)/DOFVector.hh $(SOURCE_DIR)/DOFVector.cc $(SOURCE_DIR)/Element.h $(SOURCE_DIR)/ElementConnection.h \
-$(SOURCE_DIR)/ElInfo.h $(SOURCE_DIR)/ElInfo1d.h $(SOURCE_DIR)/ElInfo2d.h $(SOURCE_DIR)/ElInfo3d.h $(SOURCE_DIR)/Error.h \
-$(SOURCE_DIR)/Error.hh $(SOURCE_DIR)/Estimator.h $(SOURCE_DIR)/Estimator.cc $(SOURCE_DIR)/FiniteElemSpace.h $(SOURCE_DIR)/FixVec.h $(SOURCE_DIR)/FixVec.hh $(SOURCE_DIR)/FixVecConvert.h $(SOURCE_DIR)/Flag.h $(SOURCE_DIR)/Global.h \
+$(SOURCE_DIR)/DOFAdmin.h \
+$(SOURCE_DIR)/DOFIterator.h \
+$(SOURCE_DIR)/DOFMatrix.h \
+$(SOURCE_DIR)/DOFVector.h $(SOURCE_DIR)/DOFVector.hh $(SOURCE_DIR)/DOFVector.cc \
+$(SOURCE_DIR)/Element.h $(SOURCE_DIR)/ElementConnection.h \
+$(SOURCE_DIR)/ElInfo.h $(SOURCE_DIR)/ElInfo1d.h $(SOURCE_DIR)/ElInfo2d.h $(SOURCE_DIR)/ElInfo3d.h \
+$(SOURCE_DIR)/Error.h $(SOURCE_DIR)/Error.hh \
+$(SOURCE_DIR)/Estimator.h $(SOURCE_DIR)/Estimator.cc \
+$(SOURCE_DIR)/FiniteElemSpace.h \
+$(SOURCE_DIR)/FixVec.h $(SOURCE_DIR)/FixVec.hh \
+$(SOURCE_DIR)/FixVecConvert.h \
+$(SOURCE_DIR)/Flag.h \
+$(SOURCE_DIR)/Global.h \
 $(SOURCE_DIR)/UmfPackSolver.h \ $(SOURCE_DIR)/UmfPackSolver.hh \
 $(SOURCE_DIR)/Lagrange.h $(SOURCE_DIR)/Line.h \
 $(SOURCE_DIR)/MacroElement.h $(SOURCE_DIR)/MacroWriter.h \
@@ -768,7 +772,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-Operator.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ParMetisPartitioner.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ParallelDomainBase.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ParallelDomainScal.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ParallelDomainVec.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ParallelProblem.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-Parameters.Plo@am__quote@
@@ -848,13 +851,6 @@ libamdis_la-ParallelDomainBase.lo: $(PARALLEL_DIR)/ParallelDomainBase.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-ParallelDomainBase.lo `test -f '$(PARALLEL_DIR)/ParallelDomainBase.cc' || echo '$(srcdir)/'`$(PARALLEL_DIR)/ParallelDomainBase.cc
 
-libamdis_la-ParallelDomainScal.lo: $(PARALLEL_DIR)/ParallelDomainScal.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-ParallelDomainScal.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-ParallelDomainScal.Tpo" -c -o libamdis_la-ParallelDomainScal.lo `test -f '$(PARALLEL_DIR)/ParallelDomainScal.cc' || echo '$(srcdir)/'`$(PARALLEL_DIR)/ParallelDomainScal.cc; \
-@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-ParallelDomainScal.Tpo" "$(DEPDIR)/libamdis_la-ParallelDomainScal.Plo"; else rm -f "$(DEPDIR)/libamdis_la-ParallelDomainScal.Tpo"; exit 1; fi
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(PARALLEL_DIR)/ParallelDomainScal.cc' object='libamdis_la-ParallelDomainScal.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-ParallelDomainScal.lo `test -f '$(PARALLEL_DIR)/ParallelDomainScal.cc' || echo '$(srcdir)/'`$(PARALLEL_DIR)/ParallelDomainScal.cc
-
 libamdis_la-ParallelDomainVec.lo: $(PARALLEL_DIR)/ParallelDomainVec.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-ParallelDomainVec.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-ParallelDomainVec.Tpo" -c -o libamdis_la-ParallelDomainVec.lo `test -f '$(PARALLEL_DIR)/ParallelDomainVec.cc' || echo '$(srcdir)/'`$(PARALLEL_DIR)/ParallelDomainVec.cc; \
 @am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-ParallelDomainVec.Tpo" "$(DEPDIR)/libamdis_la-ParallelDomainVec.Plo"; else rm -f "$(DEPDIR)/libamdis_la-ParallelDomainVec.Tpo"; exit 1; fi
@@ -869,13 +865,6 @@ libamdis_la-ConditionalEstimator.lo: $(PARALLEL_DIR)/ConditionalEstimator.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-ConditionalEstimator.lo `test -f '$(PARALLEL_DIR)/ConditionalEstimator.cc' || echo '$(srcdir)/'`$(PARALLEL_DIR)/ConditionalEstimator.cc
 
-libamdis_la-MeshStructure.lo: $(PARALLEL_DIR)/MeshStructure.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-MeshStructure.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-MeshStructure.Tpo" -c -o libamdis_la-MeshStructure.lo `test -f '$(PARALLEL_DIR)/MeshStructure.cc' || echo '$(srcdir)/'`$(PARALLEL_DIR)/MeshStructure.cc; \
-@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-MeshStructure.Tpo" "$(DEPDIR)/libamdis_la-MeshStructure.Plo"; else rm -f "$(DEPDIR)/libamdis_la-MeshStructure.Tpo"; exit 1; fi
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(PARALLEL_DIR)/MeshStructure.cc' object='libamdis_la-MeshStructure.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-MeshStructure.lo `test -f '$(PARALLEL_DIR)/MeshStructure.cc' || echo '$(srcdir)/'`$(PARALLEL_DIR)/MeshStructure.cc
-
 libamdis_la-ParallelProblem.lo: $(PARALLEL_DIR)/ParallelProblem.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-ParallelProblem.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-ParallelProblem.Tpo" -c -o libamdis_la-ParallelProblem.lo `test -f '$(PARALLEL_DIR)/ParallelProblem.cc' || echo '$(srcdir)/'`$(PARALLEL_DIR)/ParallelProblem.cc; \
 @am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-ParallelProblem.Tpo" "$(DEPDIR)/libamdis_la-ParallelProblem.Plo"; else rm -f "$(DEPDIR)/libamdis_la-ParallelProblem.Tpo"; exit 1; fi
@@ -1170,6 +1159,13 @@ libamdis_la-Mesh.lo: $(SOURCE_DIR)/Mesh.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-Mesh.lo `test -f '$(SOURCE_DIR)/Mesh.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/Mesh.cc
 
+libamdis_la-MeshStructure.lo: $(SOURCE_DIR)/MeshStructure.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-MeshStructure.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-MeshStructure.Tpo" -c -o libamdis_la-MeshStructure.lo `test -f '$(SOURCE_DIR)/MeshStructure.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/MeshStructure.cc; \
+@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-MeshStructure.Tpo" "$(DEPDIR)/libamdis_la-MeshStructure.Plo"; else rm -f "$(DEPDIR)/libamdis_la-MeshStructure.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(SOURCE_DIR)/MeshStructure.cc' object='libamdis_la-MeshStructure.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-MeshStructure.lo `test -f '$(SOURCE_DIR)/MeshStructure.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/MeshStructure.cc
+
 libamdis_la-AdaptStationary.lo: $(SOURCE_DIR)/AdaptStationary.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-AdaptStationary.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-AdaptStationary.Tpo" -c -o libamdis_la-AdaptStationary.lo `test -f '$(SOURCE_DIR)/AdaptStationary.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/AdaptStationary.cc; \
 @am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-AdaptStationary.Tpo" "$(DEPDIR)/libamdis_la-AdaptStationary.Plo"; else rm -f "$(DEPDIR)/libamdis_la-AdaptStationary.Tpo"; exit 1; fi
diff --git a/AMDiS/libtool b/AMDiS/libtool
index 702bb183..5a2f54ef 100755
--- a/AMDiS/libtool
+++ b/AMDiS/libtool
@@ -30,10 +30,10 @@
 # the same distribution terms that you use for the rest of that program.
 
 # A sed program that does not truncate output.
-SED="/usr/bin/sed"
+SED="/bin/sed"
 
 # Sed that helps us avoid accidentally triggering echo(1) options like -n.
-Xsed="/usr/bin/sed -e 1s/^X//"
+Xsed="/bin/sed -e 1s/^X//"
 
 # The HP-UX ksh and POSIX shell print the target directory to stdout
 # if CDPATH is set.
@@ -44,7 +44,7 @@ available_tags=" CXX F77"
 
 # ### BEGIN LIBTOOL CONFIG
 
-# Libtool was configured on host deimos102:
+# Libtool was configured on host NWRW15:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -66,12 +66,12 @@ fast_install=yes
 
 # The host system.
 host_alias=
-host=x86_64-unknown-linux-gnu
+host=i686-pc-linux-gnu
 host_os=linux-gnu
 
 # The build system.
 build_alias=
-build=x86_64-unknown-linux-gnu
+build=i686-pc-linux-gnu
 build_os=linux-gnu
 
 # An echo program that does not interpret backslashes.
@@ -82,25 +82,25 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
+LTCC="/usr/lib/openmpi/1.3.2-gcc//bin/mpicc"
 
 # LTCC compiler flags.
 LTCFLAGS="-g -O2"
 
 # A language-specific compiler.
-CC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
+CC="/usr/lib/openmpi/1.3.2-gcc//bin/mpicc"
 
 # Is the compiler the GNU C compiler?
 with_gcc=yes
 
-gcc_dir=`gcc -print-file-name=. | /usr/bin/sed 's,/\.$,,'`
+gcc_dir=`gcc -print-file-name=. | /bin/sed 's,/\.$,,'`
 gcc_ver=`gcc -dumpversion`
 
 # An ERE matcher.
 EGREP="grep -E"
 
 # The linker used to build libraries.
-LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
+LD="/usr/bin/ld"
 
 # Whether we need hard or soft links.
 LN_S="ln -s"
@@ -328,10 +328,10 @@ variables_saved_for_relink="PATH LD_LIBRARY_PATH LD_RUN_PATH GCC_EXEC_PREFIX COM
 link_all_deplibs=unknown
 
 # Compile-time system search path for libraries
-sys_lib_search_path_spec=`echo "/lib64 /usr/lib64 /usr/local/lib64" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+sys_lib_search_path_spec=`echo " /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../ /lib/i386-redhat-linux/4.1.2/ /lib/ /usr/lib/i386-redhat-linux/4.1.2/ /usr/lib/" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Run-time system search path for libraries
-sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /usr/X11R6/lib64/Xaw3d /usr/X11R6/lib64 /usr/X11R6/lib/Xaw3d /usr/X11R6/lib /usr/x86_64-suse-linux/lib /usr/local/lib64 /usr/local/lib /opt/kde3/lib64 /opt/kde3/lib /opt/gnome/lib64 /opt/gnome/lib /lib64 /lib /usr/lib64 /usr/lib /opt/cluster/intel/cce/9.1.042/lib /opt/cluster/intel/fce/9.1.036/lib /opt/cluster/Pathscale3.0/lib/2.9.99 /opt/cluster/Pathscale3.0/lib/2.9.99/32 /work/licsoft/compilers/pgi/linux86-64/6.2/lib /work/licsoft/compilers/pgi/linux86-64/6.2/libso "
+sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/octave-2.9.9 /usr/lib/qt-3.3/lib /usr/lib/qt4/lib "
 
 # Fix the shell variable $srcfile for the compiler.
 fix_srcfile_path=""
@@ -6763,7 +6763,7 @@ build_old_libs=`case $build_libtool_libs in yes) $echo no;; *) $echo yes;; esac`
 # End:
 # ### BEGIN LIBTOOL TAG CONFIG: CXX
 
-# Libtool was configured on host deimos102:
+# Libtool was configured on host NWRW15:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -6785,12 +6785,12 @@ fast_install=yes
 
 # The host system.
 host_alias=
-host=x86_64-unknown-linux-gnu
+host=i686-pc-linux-gnu
 host_os=linux-gnu
 
 # The build system.
 build_alias=
-build=x86_64-unknown-linux-gnu
+build=i686-pc-linux-gnu
 build_os=linux-gnu
 
 # An echo program that does not interpret backslashes.
@@ -6801,25 +6801,25 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
+LTCC="/usr/lib/openmpi/1.3.2-gcc//bin/mpicc"
 
 # LTCC compiler flags.
 LTCFLAGS="-g -O2"
 
 # A language-specific compiler.
-CC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpiCC"
+CC="/usr/lib/openmpi/1.3.2-gcc//bin/mpiCC"
 
 # Is the compiler the GNU C compiler?
 with_gcc=yes
 
-gcc_dir=`gcc -print-file-name=. | /usr/bin/sed 's,/\.$,,'`
+gcc_dir=`gcc -print-file-name=. | /bin/sed 's,/\.$,,'`
 gcc_ver=`gcc -dumpversion`
 
 # An ERE matcher.
 EGREP="grep -E"
 
 # The linker used to build libraries.
-LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
+LD="/usr/bin/ld"
 
 # Whether we need hard or soft links.
 LN_S="ln -s"
@@ -6948,11 +6948,11 @@ striplib="strip --strip-unneeded"
 
 # Dependencies to place before the objects being linked to create a
 # shared library.
-predep_objects=`echo "/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtbeginS.o" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+predep_objects=`echo "/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.2/crtbeginS.o" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Dependencies to place after the objects being linked to create a
 # shared library.
-postdep_objects=`echo "/usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtendS.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crtn.o" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+postdep_objects=`echo "/usr/lib/gcc/i386-redhat-linux/4.1.2/crtendS.o /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crtn.o" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Dependencies to place before the objects being linked to create a
 # shared library.
@@ -6960,11 +6960,11 @@ predeps=""
 
 # Dependencies to place after the objects being linked to create a
 # shared library.
-postdeps="-lmpi_cxx -lmpi -lopen-rte -lopen-pal -libverbs -lrt -lnuma -ldl -lnsl -lutil -ldl -lstdc++ -lm -lgcc_s -lpthread -lc -lgcc_s"
+postdeps="-lmpi_cxx -lmpi -lopen-rte -lopen-pal -ldl -lnsl -lutil -ldl -lstdc++ -lm -lgcc_s -lpthread -lc -lgcc_s"
 
 # The library search path used internally by the compiler when linking
 # a shared library.
-compiler_lib_search_path=`echo "-L/usr/lib64 -L/licsoft/libraries/openmpi/1.2.6/64bit/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../.." | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+compiler_lib_search_path=`echo "-L/usr/lib/openmpi/1.3.2-gcc/lib -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2/../../.." | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Method to check whether dependent libraries are shared objects.
 deplibs_check_method="pass_all"
@@ -7044,10 +7044,10 @@ variables_saved_for_relink="PATH LD_LIBRARY_PATH LD_RUN_PATH GCC_EXEC_PREFIX COM
 link_all_deplibs=unknown
 
 # Compile-time system search path for libraries
-sys_lib_search_path_spec=`echo "/lib64 /usr/lib64 /usr/local/lib64" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+sys_lib_search_path_spec=`echo " /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../ /lib/i386-redhat-linux/4.1.2/ /lib/ /usr/lib/i386-redhat-linux/4.1.2/ /usr/lib/" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Run-time system search path for libraries
-sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /usr/X11R6/lib64/Xaw3d /usr/X11R6/lib64 /usr/X11R6/lib/Xaw3d /usr/X11R6/lib /usr/x86_64-suse-linux/lib /usr/local/lib64 /usr/local/lib /opt/kde3/lib64 /opt/kde3/lib /opt/gnome/lib64 /opt/gnome/lib /lib64 /lib /usr/lib64 /usr/lib /opt/cluster/intel/cce/9.1.042/lib /opt/cluster/intel/fce/9.1.036/lib /opt/cluster/Pathscale3.0/lib/2.9.99 /opt/cluster/Pathscale3.0/lib/2.9.99/32 /work/licsoft/compilers/pgi/linux86-64/6.2/lib /work/licsoft/compilers/pgi/linux86-64/6.2/libso "
+sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/octave-2.9.9 /usr/lib/qt-3.3/lib /usr/lib/qt4/lib "
 
 # Fix the shell variable $srcfile for the compiler.
 fix_srcfile_path=""
@@ -7071,7 +7071,7 @@ include_expsyms=""
 
 # ### BEGIN LIBTOOL TAG CONFIG: F77
 
-# Libtool was configured on host deimos102:
+# Libtool was configured on host NWRW15:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -7093,12 +7093,12 @@ fast_install=yes
 
 # The host system.
 host_alias=
-host=x86_64-unknown-linux-gnu
+host=i686-pc-linux-gnu
 host_os=linux-gnu
 
 # The build system.
 build_alias=
-build=x86_64-unknown-linux-gnu
+build=i686-pc-linux-gnu
 build_os=linux-gnu
 
 # An echo program that does not interpret backslashes.
@@ -7109,7 +7109,7 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
+LTCC="/usr/lib/openmpi/1.3.2-gcc//bin/mpicc"
 
 # LTCC compiler flags.
 LTCFLAGS="-g -O2"
@@ -7118,16 +7118,16 @@ LTCFLAGS="-g -O2"
 CC="g77"
 
 # Is the compiler the GNU C compiler?
-with_gcc=
+with_gcc=yes
 
-gcc_dir=`gcc -print-file-name=. | /usr/bin/sed 's,/\.$,,'`
+gcc_dir=`gcc -print-file-name=. | /bin/sed 's,/\.$,,'`
 gcc_ver=`gcc -dumpversion`
 
 # An ERE matcher.
 EGREP="grep -E"
 
 # The linker used to build libraries.
-LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
+LD="/usr/bin/ld"
 
 # Whether we need hard or soft links.
 LN_S="ln -s"
@@ -7355,10 +7355,10 @@ variables_saved_for_relink="PATH LD_LIBRARY_PATH LD_RUN_PATH GCC_EXEC_PREFIX COM
 link_all_deplibs=unknown
 
 # Compile-time system search path for libraries
-sys_lib_search_path_spec=`echo "/lib64 /usr/lib64 /usr/local/lib64" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+sys_lib_search_path_spec=`echo " /usr/lib/gcc/i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../i386-redhat-linux/lib/i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../i386-redhat-linux/lib/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../ /lib/i386-redhat-linux/3.4.6/ /lib/ /usr/lib/i386-redhat-linux/3.4.6/ /usr/lib/" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Run-time system search path for libraries
-sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /usr/X11R6/lib64/Xaw3d /usr/X11R6/lib64 /usr/X11R6/lib/Xaw3d /usr/X11R6/lib /usr/x86_64-suse-linux/lib /usr/local/lib64 /usr/local/lib /opt/kde3/lib64 /opt/kde3/lib /opt/gnome/lib64 /opt/gnome/lib /lib64 /lib /usr/lib64 /usr/lib /opt/cluster/intel/cce/9.1.042/lib /opt/cluster/intel/fce/9.1.036/lib /opt/cluster/Pathscale3.0/lib/2.9.99 /opt/cluster/Pathscale3.0/lib/2.9.99/32 /work/licsoft/compilers/pgi/linux86-64/6.2/lib /work/licsoft/compilers/pgi/linux86-64/6.2/libso "
+sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/octave-2.9.9 /usr/lib/qt-3.3/lib /usr/lib/qt4/lib "
 
 # Fix the shell variable $srcfile for the compiler.
 fix_srcfile_path=""
diff --git a/AMDiS/src/AMDiS.h b/AMDiS/src/AMDiS.h
index f0d73e1a..f102b77c 100644
--- a/AMDiS/src/AMDiS.h
+++ b/AMDiS/src/AMDiS.h
@@ -49,6 +49,7 @@
 #include "Marker.h"
 #include "MatrixVector.h"
 #include "Mesh.h"
+#include "MeshStructure.h"
 #include "ComponentTraverseInfo.h"
 #include "Newton.h"
 #include "NewtonS.h"
@@ -94,7 +95,6 @@
 #include "parareal/AdaptParaReal.h"
 
 #if HAVE_PARALLEL_DOMAIN_AMDIS
-#include "ParallelDomainScal.h"
 #include "ParallelDomainVec.h"
 #endif
 
diff --git a/AMDiS/src/CoarseningManager.cc b/AMDiS/src/CoarseningManager.cc
index 51f34507..1b31a92a 100644
--- a/AMDiS/src/CoarseningManager.cc
+++ b/AMDiS/src/CoarseningManager.cc
@@ -6,14 +6,9 @@
 #include "MacroElement.h"
 #include "RCNeighbourList.h"
 #include "FixVec.h"
-//#include "PeriodicBC.h"
 
 namespace AMDiS {
 
-  /****************************************************************************/
-  /*  tries to coarsen every element of mesh at least mark times		    */
-  /****************************************************************************/
-
   Flag CoarseningManager::globalCoarsen(Mesh *aMesh, int mark)
   {
     if (mark >= 0) 
@@ -50,12 +45,6 @@ namespace AMDiS {
     }
   }
 
-
-  /****************************************************************************/
-  /*  cleanup_after_coarsen:                                   		    */
-  /*  resets the element marks                                                */
-  /****************************************************************************/
-
   void CoarseningManager::cleanUpAfterCoarsen()
   {
     TraverseStack stack;
@@ -67,15 +56,10 @@ namespace AMDiS {
     }
   }
 
-  /****************************************************************************/
-  /*  coarsenMesh:       							    */
-  /*  traversal routine for recursiv coarsening of a triangulation            */
-  /****************************************************************************/
-
   Flag CoarseningManager::coarsenMesh(Mesh *aMesh)
   {
     mesh = aMesh;
-    int n_elements = mesh->getNumberOfLeaves();
+    int nElements = mesh->getNumberOfLeaves();
 
     spreadCoarsenMark();
 
@@ -95,9 +79,14 @@ namespace AMDiS {
 
     cleanUpAfterCoarsen();
 
-    n_elements -= mesh->getNumberOfLeaves();
+    nElements -= mesh->getNumberOfLeaves();
 
-    return(n_elements ? MESH_COARSENED : Flag(0));
+    if (nElements != 0) {
+      aMesh->incChangeIndex();
+      return MESH_COARSENED;
+    } else {
+      return Flag(0);
+    }
   }
 
 }
diff --git a/AMDiS/src/Mesh.cc b/AMDiS/src/Mesh.cc
index 9d7fee4b..cb317eb5 100644
--- a/AMDiS/src/Mesh.cc
+++ b/AMDiS/src/Mesh.cc
@@ -92,6 +92,7 @@ namespace AMDiS {
       elementIndex(-1),
       initialized(false),
       macroFileInfo(NULL),
+      changeIndex(0),
       final_lambda(dimension, DEFAULT_VALUE, 0.0)
   {
 
@@ -122,27 +123,22 @@ namespace AMDiS {
     Element::deletedDOFs.clear();
 
     for (std::deque<MacroElement*>::const_iterator it = macroElements.begin();
-	 it != macroElements.end();
-	 ++it) {
+	 it != macroElements.end(); ++it) {
       (*it)->getElement()->deleteElementDOFs();
       delete *it;
     }    
 
     Element::deletedDOFs.clear();
 
-    if (macroFileInfo != NULL) {
-      delete macroFileInfo;
-    }
-    if (elementPrototype) {
-      delete elementPrototype;
-    }
-    if (elementDataPrototype) {
-      delete elementDataPrototype;
-    }
+    if (macroFileInfo != NULL)
+      delete macroFileInfo;    
+    if (elementPrototype)
+      delete elementPrototype;    
+    if (elementDataPrototype)
+      delete elementDataPrototype;    
     
-    for (int i = 0; i < static_cast<int>(admin.size()); i++) {
-      delete admin[i];
-    }
+    for (int i = 0; i < static_cast<int>(admin.size()); i++)
+      delete admin[i];    
   }
 
   Mesh& Mesh::operator=(const Mesh& m)
@@ -200,8 +196,7 @@ namespace AMDiS {
     // Go through all MacroElements of mesh m, and create for every a new
     // MacroElement in this mesh.
     for (std::deque<MacroElement*>::const_iterator it = m.macroElements.begin();
-	 it != m.macroElements.end();
-	 ++it, insertCounter++) {
+	 it != m.macroElements.end(); ++it, insertCounter++) {
 
       // Create new MacroElement.
       MacroElement *el = new MacroElement(dim);
@@ -287,8 +282,7 @@ namespace AMDiS {
     
     // Determine all dof owner macro elements.
     for (std::deque<MacroElement*>::iterator macroIt = macroElements.begin();
-	 macroIt != macroElements.end();
-	 ++macroIt) {
+	 macroIt != macroElements.end(); ++macroIt) {
       elDofIter.reset((*macroIt)->getElement());
       do {
 	dofsOwner[elDofIter.getDofPtr()].insert(*macroIt);
@@ -817,18 +811,22 @@ namespace AMDiS {
 	if (lambda[0] >= lambda[1]) {
 	  c_el_info->fillElInfo(0, el_info);
 	  c_lambda[0] = lambda[0] - lambda[1];
-	  c_lambda[1] = lambda[Tetrahedron::childVertex[(dynamic_cast<ElInfo3d*>(el_info))->
-							getType()][0][1]];
-	  c_lambda[2] = lambda[Tetrahedron::childVertex[(dynamic_cast<ElInfo3d*>(el_info))->
-							getType()][0][2]];
+	  c_lambda[1] = 
+	    lambda[Tetrahedron::childVertex[(dynamic_cast<ElInfo3d*>(el_info))->
+					    getType()][0][1]];
+	  c_lambda[2] = 
+	    lambda[Tetrahedron::childVertex[(dynamic_cast<ElInfo3d*>(el_info))->
+					    getType()][0][2]];
 	  c_lambda[3] = 2.0 * lambda[1];
 	} else {
 	  c_el_info->fillElInfo(1, el_info);
 	  c_lambda[0] = lambda[1] - lambda[0];
-	  c_lambda[1] = lambda[Tetrahedron::childVertex[(dynamic_cast<ElInfo3d*>(el_info))->
-							getType()][1][1]];
-	  c_lambda[2] = lambda[Tetrahedron::childVertex[(dynamic_cast<ElInfo3d*>(el_info))->
-							getType()][1][2]];
+	  c_lambda[1] = 
+	    lambda[Tetrahedron::childVertex[(dynamic_cast<ElInfo3d*>(el_info))->
+					    getType()][1][1]];
+	  c_lambda[2] = 
+	    lambda[Tetrahedron::childVertex[(dynamic_cast<ElInfo3d*>(el_info))->
+					    getType()][1][2]];
 	  c_lambda[3] = 2.0 * lambda[0];
 	}
       }
@@ -917,13 +915,14 @@ namespace AMDiS {
     diam[i] = w; 
   }
 
-
-  int Mesh::newDOFFct1(ElInfo* ei) {
+  int Mesh::newDOFFct1(ElInfo* ei) 
+  {
     ei->getElement()->newDOFFct1(compressAdmin);
     return 0;
   }
 
-  int Mesh::newDOFFct2(ElInfo* ei) {
+  int Mesh::newDOFFct2(ElInfo* ei) 
+  {
     ei->getElement()->newDOFFct2(compressAdmin);
     return 0;
   }
diff --git a/AMDiS/src/Mesh.h b/AMDiS/src/Mesh.h
index 3b7ad11d..2779915d 100644
--- a/AMDiS/src/Mesh.h
+++ b/AMDiS/src/Mesh.h
@@ -546,6 +546,18 @@ namespace AMDiS {
       return macroFileInfo;
     }
 
+    /// Increment the value of mesh change index, see \ref changeIndex.
+    inline void incChangeIndex()
+    {
+      changeIndex++;
+    }
+
+    /// Returns the mesh change index, see \ref changeIndex.
+    inline long getChangeIndex()
+    {
+      return changeIndex;
+    }
+
     ///
     void clearMacroFileInfo();
 
@@ -773,11 +785,18 @@ namespace AMDiS {
     std::map<BoundaryType, VertexVector*> periodicAssociations;
 
     /** \brief
-     * If the mesh has been created by reading a macro file, here 
-     * the information are stored about the content of the file.
+     * If the mesh has been created by reading a macro file, here the information are
+     * are stored about the content of the file.
      */
     MacroInfo *macroFileInfo;
 
+    /** \brief
+     * This index is incremented every time the mesh is changed, e.g. by the refinement
+     * or the coarsening manager. It can be used by other object if the mesh has been
+     * changed by first copying this variable elsewhere and comparing its values.
+     */
+    long changeIndex;
+
   protected:
     /// for findElement-Fcts
     DimVec<double> final_lambda;
diff --git a/AMDiS/src/MeshStructure.cc b/AMDiS/src/MeshStructure.cc
index 74d046b8..b79b10d1 100644
--- a/AMDiS/src/MeshStructure.cc
+++ b/AMDiS/src/MeshStructure.cc
@@ -10,38 +10,40 @@
 
 namespace AMDiS {
 
-  const int MeshStructure::unsignedLongSize_ = sizeof(unsigned long int) * 8;
+  const int MeshStructure::unsignedLongSize = sizeof(unsigned long int) * 8;
 
-  void MeshStructure::insertElement(bool isLeaf) {
+  void MeshStructure::insertElement(bool isLeaf) 
+  {
     // overflow? -> next index
-    if (pos_ >= unsignedLongSize_) {
-      code_.push_back(currentCode_);
-      pos_ = 0;
-      currentCode_ = 0;
+    if (pos >= unsignedLongSize) {
+      code.push_back(currentCode);
+      pos = 0;
+      currentCode = 0;
     }
 
     // insert element in binary code
     if (!isLeaf) {
       unsigned long int one = 1;
-      currentCode_ += (one << pos_);
+      currentCode += (one << pos);
     } 
 
-    pos_++;
-    numElements_++;
+    pos++;
+    nElements++;
   }
 
   void MeshStructure::clear()
   {
-    currentCode_ = 0;
-    code_.resize(0);
-    pos_ = 0;
-    numElements_ = 0;
-    currentElement_ = 0;
+    currentCode = 0;
+    code.resize(0);
+    pos = 0;
+    nElements = 0;
+    currentElement = 0;
   }
 
   void MeshStructure::init(Mesh *mesh) 
   {
     clear();
+
     TraverseStack stack;
     ElInfo *elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_EVERY_EL_PREORDER);
     while (elInfo) {
@@ -52,44 +54,50 @@ namespace AMDiS {
     commit();
   }
 
-  void MeshStructure::reset() {
-    currentIndex_ = 0;
-    currentCode_ = code_[0];
-    pos_ = 0;
-    currentElement_ = 0;
+  void MeshStructure::reset() 
+  {
+    currentIndex = 0;
+    currentCode = code[0];
+    pos = 0;
+    currentElement = 0;
   }
 
   bool MeshStructure::nextElement(MeshStructure *insert)
   {
-    if(insert) {
+    FUNCNAME("MeshStructure::nextElement()");
+
+    if (insert)
       insert->insertElement(isLeafElement());
-    }
 
-    pos_++;
-    currentElement_++;
+    pos++;
+    currentElement++;
 
-    if(currentElement_ >= numElements_) return false;
+    if (currentElement >= nElements) 
+      return false;
 
-    if(pos_ >= unsignedLongSize_) {
-      currentIndex_++;
-      TEST_EXIT_DBG(currentIndex_ < static_cast<int>(code_.size()))
-	("end of structure reached\n");
-      pos_ = 0;
-      currentCode_ = code_[currentIndex_];
+    if (pos >= unsignedLongSize) {
+      currentIndex++;
+      TEST_EXIT_DBG(currentIndex < static_cast<int>(code.size()))
+	("End of structure reached!\n");
+      pos = 0;
+      currentCode = code[currentIndex];
     } else {
-      currentCode_ >>= 1;
+      currentCode >>= 1;
     }
+
     return true;
   }
 
   bool MeshStructure::skipBranch(MeshStructure *insert)
   {
+    FUNCNAME("MeshStructure::skipBranch()");
+
     if (isLeafElement()) {
       return nextElement(insert);
     } else {
       bool cont = nextElement(insert);
       cont = skipBranch(insert); // left branch
-      TEST_EXIT_DBG(cont)("invalid structure\n");
+      TEST_EXIT_DBG(cont)("Invalid structure!\n");
       cont = skipBranch(insert); // righ branch
       return cont;
     }
@@ -99,6 +107,8 @@ namespace AMDiS {
 			    MeshStructure *structure2,
 			    MeshStructure *result)
   {
+    FUNCNAME("MeshStructure::merge()");
+
     result->clear();
     structure1->reset();
     structure2->reset();
@@ -118,7 +128,7 @@ namespace AMDiS {
 	  cont2 = structure2->nextElement();
 	}
       }
-      TEST_EXIT_DBG(cont1 == cont2)("structures don't match\n");
+      TEST_EXIT_DBG(cont1 == cont2)("Structures don't match!\n");
       cont = cont1;
     }
 
@@ -132,23 +142,19 @@ namespace AMDiS {
   {
     FUNCNAME("MeshStructure::fitMeshToStructure()");
 
-    TraverseStack stack;
-    ElInfo *elInfo;
-
-
     bool cont = true;
 
     // decorate leaf data
     reset();
-    elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_EVERY_EL_PREORDER);
+    TraverseStack stack;
+    ElInfo *elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_EVERY_EL_PREORDER);
     while (elInfo) {
       TEST_EXIT(cont)("unexpected structure code end!\n");
 
       Element *element = elInfo->getElement();
 
-      if (isLeafElement()) {
-	TEST_EXIT(element->isLeaf())("mesh finer than code\n");
-      };
+      if (isLeafElement())
+	TEST_EXIT_DBG(element->isLeaf())("mesh finer than code\n");
 
       if (element->isLeaf() && !isLeafElement()) {
 	MeshStructure *structure = new MeshStructure();
@@ -159,11 +165,10 @@ namespace AMDiS {
 	if (checkPartition) {
 	  PartitionElementData *partitionData = dynamic_cast<PartitionElementData*>
 	    (element->getElementData(PARTITION_ED));
-	  TEST_EXIT(partitionData)("no partition element data\n");
+	  TEST_EXIT_DBG(partitionData)("no partition element data\n");
 	  PartitionStatus status = partitionData->getPartitionStatus();
-	  if ((debugMode == false) && (status == OUT || status == UNDEFINED)) {
+	  if (debugMode == false && (status == OUT || status == UNDEFINED))
 	    decorate = false;
-	  }
 	}
 
 	if (decorate) {
diff --git a/AMDiS/src/MeshStructure.h b/AMDiS/src/MeshStructure.h
index 92ef5a5c..d5f312f8 100644
--- a/AMDiS/src/MeshStructure.h
+++ b/AMDiS/src/MeshStructure.h
@@ -1,6 +1,6 @@
 // ============================================================================
 // ==                                                                        ==
-// == AMDiS - Adaptive multidimensional simulations                          ==
+// == Amdis - Adaptive multidimensional simulations                          ==
 // ==                                                                        ==
 // ============================================================================
 // ==                                                                        ==
@@ -32,11 +32,11 @@ namespace AMDiS {
   {
   public:
     MeshStructure()
-      : currentIndex_(0),
-	currentCode_(0),
-	pos_(0),
-	currentElement_(0),
-	numElements_(0)
+      : currentIndex(0),
+	currentCode(0),
+	pos(0),
+	currentElement(0),
+	nElements(0)
     {}
   
     void clear();
@@ -44,10 +44,10 @@ namespace AMDiS {
     /// Creates a mesh structure code from a Mesh object by traversing it in preorder.
     void init(Mesh *mesh);
 
-    void init(const std::vector<unsigned long int>& code, int numElements) 
+    void init(const std::vector<unsigned long int>& initCode, int n) 
     {
-      code_ = code;
-      numElements_ = numElements;
+      code = initCode;
+      nElements = n;
       reset();
     }
 
@@ -55,8 +55,8 @@ namespace AMDiS {
 
     inline void commit() 
     {
-      if (pos_ > 0)
-	code_.push_back(currentCode_);
+      if (pos > 0)
+	code.push_back(currentCode);
       reset();
     }
 
@@ -68,25 +68,25 @@ namespace AMDiS {
 
     inline bool isLeafElement() 
     {
-      return (currentCode_ & 1) == 0;
+      return (currentCode & 1) == 0;
     }
 
     /** \brief
-     * Merges a mesh structure code with its own mesh structure code. The
-     * result overwrites the own mesh structure code.
+     * Merges a mesh structure code with its own mesh structure code. The result
+     * overwrites the own mesh structure code.
      */
-    void merge(MeshStructure *structure) 
+    void merge(MeshStructure *struc) 
     {
       MeshStructure temp(*this);
-      merge(&temp, structure, this);
+      merge(&temp, struc, this);
     }
 
     /** \brief
      * Fits a given mesh to the mesh structure code. 
      *
-     * \param debugMode     In debugMode, the whole mesh is fitted to the mesh
-     *      structure code. Otherwise, the mesh is fitted only on the partition
-     *      of the current process.
+     * \param debugMode   In debugMode, the whole mesh is fitted to the mesh structure
+     *                    code. Otherwise, the mesh is fitted only on the partition
+     *                    of the current process.
      */
     void fitMeshToStructure(Mesh *mesh,
 			    RefinementManager *manager,
@@ -114,24 +114,21 @@ namespace AMDiS {
     /// Returns the mesh structure code.
     inline const std::vector<unsigned long int>& getCode() 
     {
-      return code_;
+      return code;
     }
 
     inline int getNumElements() 
     { 
-      return numElements_; 
+      return nElements; 
     }
 
     inline int getCurrentElement() 
     {
-      return currentElement_;
+      return currentElement;
     }
 
   protected:
-    /** \brief
-     * Insert a new element to the structure code. Is used by the init 
-     * function.
-     */
+    /// Insert a new element to the structure code. Is used by the init function.
     void insertElement(bool isLeaf);
 
     /// Merges two mesh structure codes to one structure code.     
@@ -140,19 +137,19 @@ namespace AMDiS {
 	       MeshStructure *result);
 
   protected:
-    std::vector<unsigned long int> code_;
+    std::vector<unsigned long int> code;
 
-    int currentIndex_;
+    int currentIndex;
 
-    unsigned long int currentCode_;
+    unsigned long int currentCode;
 
-    int pos_;
+    int pos;
 
-    int currentElement_;
+    int currentElement;
 
-    int numElements_;
+    int nElements;
 
-    static const int unsignedLongSize_;
+    static const int unsignedLongSize;
   };
 
 }
diff --git a/AMDiS/src/MeshStructure_ED.h b/AMDiS/src/MeshStructure_ED.h
index 5a74ee05..f086228a 100644
--- a/AMDiS/src/MeshStructure_ED.h
+++ b/AMDiS/src/MeshStructure_ED.h
@@ -19,8 +19,8 @@
 
 /** \file MeshStructure.h */
 
-#ifndef AMDIS_MESHSTRUCTURE_ED_H
-#define AMDIS_MESHSTRUCTURE_ED_H
+#ifndef AMDIS_MESHSTRUCTUREED_H
+#define AMDIS_MESHSTRUCTUREED_H
 
 #include <vector>
 #include "MeshStructure.h"
@@ -36,12 +36,12 @@ namespace AMDiS {
   public:
     MeshStructure_ED(ElementData *decorated = NULL) 
       : ElementData(decorated),
-	structure_(NULL)
+	structure(NULL)
     {}
 
     virtual ~MeshStructure_ED() 
-      {
-      delete structure_;
+    {
+      delete structure;
     }
 
     virtual bool refineElementData(Element* parent, 
@@ -49,31 +49,31 @@ namespace AMDiS {
 				   Element* child2,
 				   int elType)
     {
-      ElementData::refineElementData(parent, child1, child2, elType);
+      FUNCNAME("MeshStructureED::refineElementData()");
 
-      structure_->reset();
+      ElementData::refineElementData(parent, child1, child2, elType);
 
-      TEST_EXIT(structure_)("no structure\n");
+      structure->reset();
 
-      TEST_EXIT(!structure_->isLeafElement())
-	("don't store leaf structures\n");
+      TEST_EXIT_DBG(structure)("No structure!\n");
+      TEST_EXIT_DBG(!structure->isLeafElement())("Don't store leaf structures!\n");
 
-      structure_->nextElement();
+      structure->nextElement();
 
-      if (!structure_->isLeafElement()) {
+      if (!structure->isLeafElement()) {
 	MeshStructure *structure1 = new MeshStructure();
-	structure_->skipBranch(structure1);
+	structure->skipBranch(structure1);
 	structure1->commit();
 	MeshStructure_ED *elData1 = new MeshStructure_ED(child1->getElementData());
 	elData1->setStructure(structure1);
 	child1->setElementData(elData1);
       } else {
-	structure_->nextElement();
+	structure->nextElement();
       }
 
-      if (!structure_->isLeafElement()) {
+      if (!structure->isLeafElement()) {
 	MeshStructure *structure2 = new MeshStructure();
-	structure_->skipBranch(structure2);
+	structure->skipBranch(structure2);
 	structure2->commit();
 	MeshStructure_ED *elData2 = new MeshStructure_ED(child2->getElementData());
 	elData2->setStructure(structure2);
@@ -81,7 +81,7 @@ namespace AMDiS {
       }
 
       return true;
-    };
+    }
 
     virtual const int getTypeID() const 
     {
@@ -92,21 +92,22 @@ namespace AMDiS {
     {
       if (typeID == MESH_STRUCTURE) 
 	return true;
+
       return false;
     }
 
-    inline void setStructure(MeshStructure *structure) 
+    inline void setStructure(MeshStructure *s) 
     {
-      structure_ = structure;
+      structure = s;
     }
 
     inline MeshStructure *getStructure() 
     {
-      return structure_;
+      return structure;
     }
 
   protected:
-    MeshStructure *structure_;
+    MeshStructure *structure;
   };
 
 }
diff --git a/AMDiS/src/ParallelDomainBase.cc b/AMDiS/src/ParallelDomainBase.cc
index e91e663d..2fdde4b5 100644
--- a/AMDiS/src/ParallelDomainBase.cc
+++ b/AMDiS/src/ParallelDomainBase.cc
@@ -50,7 +50,8 @@ namespace AMDiS {
       nRankDofs(0),
       rstart(0),
       nComponents(1),
-      deserialized(false)
+      deserialized(false),
+      lastMeshChangeIndex(0)
   {
     FUNCNAME("ParallelDomainBase::ParalleDomainBase()");
 
@@ -153,6 +154,8 @@ namespace AMDiS {
       createPeriodicMap();
     }
 
+    lastMeshChangeIndex = mesh->getChangeIndex();
+
 #if (DEBUG != 0)
     dbgTestCommonDofs(true);
 #endif
@@ -364,40 +367,6 @@ namespace AMDiS {
   }
 
 
-  void ParallelDomainBase::fillPetscMatrix(DOFMatrix *mat, DOFVector<double> *vec)
-  {
-    FUNCNAME("ParallelDomainBase::fillPetscMatrix()");
-
-    ERROR_EXIT("Not yet tested for scalar problem definition!\n");
-
-    MatCreate(PETSC_COMM_WORLD, &petscMatrix);
-    MatSetSizes(petscMatrix, nRankRows, nRankRows, nOverallRows, nOverallRows);
-    MatSetType(petscMatrix, MATAIJ);
-
-    VecCreate(PETSC_COMM_WORLD, &petscRhsVec);
-    VecSetSizes(petscRhsVec, nRankRows, nOverallRows);
-    VecSetType(petscRhsVec, VECMPI);
-
-    VecCreate(PETSC_COMM_WORLD, &petscSolVec);
-    VecSetSizes(petscSolVec, nRankRows, nOverallRows);
-    VecSetType(petscSolVec, VECMPI);
-
-    VecCreate(PETSC_COMM_WORLD, &petscTmpVec);
-    VecSetSizes(petscTmpVec, nRankRows, nOverallRows);
-    VecSetType(petscTmpVec, VECMPI);
-
-    setDofMatrix(mat);
-
-    MatAssemblyBegin(petscMatrix, MAT_FINAL_ASSEMBLY);
-    MatAssemblyEnd(petscMatrix, MAT_FINAL_ASSEMBLY);
-
-    setDofVector(petscRhsVec, vec);
-
-    VecAssemblyBegin(petscRhsVec);
-    VecAssemblyEnd(petscRhsVec);
-  }
-
-  
   void ParallelDomainBase::fillPetscMatrix(Matrix<DOFMatrix*> *mat, SystemVector *vec)
   {
     FUNCNAME("ParallelDomainBase::fillPetscMatrix()");
@@ -634,79 +603,6 @@ namespace AMDiS {
   }
 
 
-  void ParallelDomainBase::solvePetscMatrix(DOFVector<double> *vec)
-  {
-    FUNCNAME("ParallelDomainBase::solvePetscMatrix()");
-
-    ERROR_EXIT("Not yet tested for scalar problem definition!\n");
-
-    KSP ksp;
-    KSPCreate(PETSC_COMM_WORLD, &ksp);
-    KSPSetOperators(ksp, petscMatrix, petscMatrix, SAME_NONZERO_PATTERN);
-    KSPSetTolerances(ksp, 1.e-7, PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT);
-    KSPSetType(ksp, KSPBCGS);
-    KSPMonitorSet(ksp, myKSPMonitor, PETSC_NULL, 0);
-    KSPSolve(ksp, petscRhsVec, petscSolVec);
-
-    PetscScalar *vecPointer;
-    VecGetArray(petscSolVec, &vecPointer);
-
-    for (int i = 0; i < nRankDofs; i++)
-      (*vec)[mapLocalToDofIndex[i]] = vecPointer[i];
-
-    VecRestoreArray(petscSolVec, &vecPointer);
-
-    std::vector<double*> sendBuffers(sendDofs.size());
-    std::vector<double*> recvBuffers(recvDofs.size());
-
-    MPI::Request request[sendDofs.size() + recvDofs.size()];
-    int requestCounter = 0;
-    
-    int i = 0;
-    for (RankToDofContainer::iterator sendIt = sendDofs.begin();
-	 sendIt != sendDofs.end(); ++sendIt, i++) {
-      int nSendDOFs = sendIt->second.size();
-      sendBuffers[i] = new double[nSendDOFs];
-
-      for (int j = 0; j < nSendDOFs; j++)
-	sendBuffers[i][j] = (*vec)[*((sendIt->second)[j])];
-
-      request[requestCounter++] =
-	mpiComm.Isend(sendBuffers[i], nSendDOFs, MPI_DOUBLE, sendIt->first, 0);
-    }
-
-    i = 0;
-    for (RankToDofContainer::iterator recvIt = recvDofs.begin();
-	 recvIt != recvDofs.end(); ++recvIt, i++) {
-      int nRecvDOFs = recvIt->second.size();
-      recvBuffers[i] = new double[nRecvDOFs];
-
-      request[requestCounter++] =
-	mpiComm.Irecv(recvBuffers[i], nRecvDOFs, MPI_DOUBLE, recvIt->first, 0);
-    }
-
-
-    MPI::Request::Waitall(requestCounter, request);
-
-    i = 0;
-    for (RankToDofContainer::iterator recvIt = recvDofs.begin();
-	 recvIt != recvDofs.end(); ++recvIt, i++) {
-      for (int j = 0; j < static_cast<int>(recvIt->second.size()); j++)
-	(*vec)[*(recvIt->second)[j]] = recvBuffers[i][j];
-
-      delete [] recvBuffers[i];
-    }
-    
-    for (int i = 0; i < static_cast<int>(sendBuffers.size()); i++)
-      delete [] sendBuffers[i];
-
-    MatDestroy(petscMatrix);
-    VecDestroy(petscRhsVec);
-    VecDestroy(petscSolVec);
-    VecDestroy(petscTmpVec);
-  }
-
-
   void ParallelDomainBase::solvePetscMatrix(SystemVector &vec)
   {
     FUNCNAME("ParallelDomainBase::solvePetscMatrix()");
@@ -859,6 +755,18 @@ namespace AMDiS {
 #endif
   }
 
+
+  void ParallelDomainBase::checkMeshChange()
+  {
+    if (mesh->getChangeIndex() == lastMeshChangeIndex)
+      return;
+
+    std::cout << "MESH HAS BEEN CHANGED!" << std::endl;
+    exit(0);    
+
+    lastMeshChangeIndex = mesh->getChangeIndex();
+  }
+
   
   void ParallelDomainBase::serialize(std::ostream &out, DofContainer &data)
   {
@@ -1914,8 +1822,7 @@ namespace AMDiS {
   {
     FUNCNAME("ParallelDomainBase::oneIteration()");
 
-    Flag flag = dynamic_cast<StandardProblemIteration*>(iterationIF)->
-      buildAndAdapt(adaptInfo, toDo);
+    Flag flag = buildAndAdapt(adaptInfo, toDo);
 
     if (toDo.isSet(SOLVE))
       solve();
@@ -1930,6 +1837,44 @@ namespace AMDiS {
   }
 
 
+  Flag ParallelDomainBase::buildAndAdapt(AdaptInfo *adaptInfo, Flag toDo)
+  {
+        FUNCNAME("StandardProblemIteration::buildAndAdapt()");
+
+    Flag flag = 0, markFlag = 0;
+    ProblemStatBase *problem = iterationIF->getProblem();
+
+    if (toDo.isSet(MARK))
+      markFlag = problem->markElements(adaptInfo);
+    else
+      markFlag = 3;
+
+    if (toDo.isSet(BUILD))
+      problem->buildBeforeRefine(adaptInfo, markFlag);
+
+    // refine
+    if (toDo.isSet(ADAPT) && markFlag.isSet(MESH_REFINED))
+      flag = problem->refineMesh(adaptInfo);
+
+    if (toDo.isSet(BUILD))
+      problem->buildBeforeCoarsen(adaptInfo, markFlag);
+
+    // coarsen
+    if (toDo.isSet(ADAPT) && markFlag.isSet(MESH_COARSENED))
+      flag |= problem->coarsenMesh(adaptInfo);
+
+    checkMeshChange();
+
+    if (toDo.isSet(BUILD))
+      problem->buildAfterCoarsen(adaptInfo, markFlag, true, true);
+
+    if (toDo.isSet(BUILD_RHS))
+      problem->buildAfterCoarsen(adaptInfo, markFlag, false, true);
+
+    return flag;
+  }
+
+
   void ParallelDomainBase::serialize(std::ostream &out)
   {
     SerUtil::serialize(out, elemWeights);
diff --git a/AMDiS/src/ParallelDomainBase.h b/AMDiS/src/ParallelDomainBase.h
index 22255b38..ffbb576a 100644
--- a/AMDiS/src/ParallelDomainBase.h
+++ b/AMDiS/src/ParallelDomainBase.h
@@ -151,6 +151,8 @@ namespace AMDiS {
 
     virtual Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo = FULL_ITERATION);
 
+    virtual Flag buildAndAdapt(AdaptInfo *adaptInfo, Flag toDo);
+
     virtual void endIteration(AdaptInfo *adaptInfo) 
     {
       iterationIF->endIteration(adaptInfo);
@@ -174,12 +176,8 @@ namespace AMDiS {
       return nRankDofs;
     }
 
-    void fillPetscMatrix(DOFMatrix *mat, DOFVector<double> *vec);
-
     void fillPetscMatrix(Matrix<DOFMatrix*> *mat, SystemVector *vec);
 
-    void solvePetscMatrix(DOFVector<double> *vec);
-
     void solvePetscMatrix(SystemVector &vec);
 
     virtual ProblemStatBase *getProblem(int number = 0) 
@@ -260,18 +258,16 @@ namespace AMDiS {
 			     DofToRank& boundaryDofs,
 			     DofToBool& vertexDof);
 
-    /** \brief
-     * Takes a dof matrix and sends the values to the global petsc matrix.
-     */
+    /// Takes a dof matrix and sends the values to the global petsc matrix.
     void setDofMatrix(DOFMatrix* mat, int dispMult = 1, 
 		      int dispAddRow = 0, int dispAddCol = 0);
 
-    /** \brief
-     * Takes a dof vector and sends its values to a given petsc vector.
-     */
+    /// Takes a dof vector and sends its values to a given petsc vector.
     void setDofVector(Vec& petscVec, DOFVector<double>* vec, 
 		      int disMult = 1, int dispAdd = 0);
 
+    void checkMeshChange();
+
     void dbgCreateElementMap(ElementIdxToDofs &elMap);
     
     void dbgTestElementMap(ElementIdxToDofs &elMap);
@@ -576,6 +572,12 @@ namespace AMDiS {
      * a serialization file.
      */
     bool deserialized;
+
+    /** \brief
+     * Stores the mesh change index. This is used to recognize changes in the mesh 
+     * structure (e.g. through refinement or coarsening managers).
+     */
+    long lastMeshChangeIndex;
   };
 
 }
diff --git a/AMDiS/src/ParallelDomainScal.cc b/AMDiS/src/ParallelDomainScal.cc
deleted file mode 100644
index c837efed..00000000
--- a/AMDiS/src/ParallelDomainScal.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-#include "ParallelDomainScal.h"
-#include "ProblemScal.h"
-#include "ProblemInstat.h"
-#include "DOFVector.h"
-
-namespace AMDiS {
-
-  ParallelDomainScal::ParallelDomainScal(ProblemScal *problem,
-					 ProblemInstatScal *problemInstat)
-    : ParallelDomainBase(problem, 
-			 problemInstat, 
-			 problem->getFESpace(),
-			 problem->getRefinementManager()),
-      probScal(problem)
-  {
-    info = problem->getInfo();
-
-    // Create parallel serialization file writer, if needed.
-    int writeSerialization = 0;
-    GET_PARAMETER(0, name + "->output->write serialization", "%d", &writeSerialization);
-    if (writeSerialization)
-      problem->getFileWriterList().push_back(new Serializer<ParallelDomainScal>(this));
-  }
-
-  void ParallelDomainScal::initParallelization(AdaptInfo *adaptInfo)
-  {
-    FUNCNAME("ParallelDomainScal::initParallelization()");
-
-    ParallelDomainBase::initParallelization(adaptInfo);
-
-    DOFMatrix* m = probScal->getSystemMatrix();
-
-    TEST_EXIT(m)("No DOF Matrix!\n");
-    m->setRankDofs(isRankDof);
-
-    probScal->getRHS()->setRankDofs(isRankDof);
-    probScal->getSolution()->setRankDofs(isRankDof);
-  }
-
-  void ParallelDomainScal::solve()
-  {
-    FUNCNAME("ParallelDomainScal::solve()");
-
-#ifdef _OPENMP
-    double wtime = omp_get_wtime();
-#endif
-    clock_t first = clock();
-
-    fillPetscMatrix(probScal->getSystemMatrix(), probScal->getRHS());      
-    solvePetscMatrix(probScal->getSolution());
-
-#ifdef _OPENMP
-    INFO(info, 8)("solution of discrete system needed %.5f seconds system time / %.5f seconds wallclock time\n",
-		   TIME_USED(first, clock()),
-		   omp_get_wtime() - wtime);
-#else
-    INFO(info, 8)("solution of discrete system needed %.5f seconds\n",
-		   TIME_USED(first, clock()));
-#endif
-  }
-
-}
diff --git a/AMDiS/src/ParallelDomainScal.h b/AMDiS/src/ParallelDomainScal.h
deleted file mode 100644
index bb534f48..00000000
--- a/AMDiS/src/ParallelDomainScal.h
+++ /dev/null
@@ -1,63 +0,0 @@
-// ============================================================================
-// ==                                                                        ==
-// == AMDiS - Adaptive multidimensional simulations                          ==
-// ==                                                                        ==
-// ============================================================================
-// ==                                                                        ==
-// ==  TU Dresden                                                            ==
-// ==                                                                        ==
-// ==  Institut für Wissenschaftliches Rechnen                               ==
-// ==  Zellescher Weg 12-14                                                  ==
-// ==  01069 Dresden                                                         ==
-// ==  germany                                                               ==
-// ==                                                                        ==
-// ============================================================================
-// ==                                                                        ==
-// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
-// ==                                                                        ==
-// ============================================================================
-
-/** \file ParallelDomainScal.h */
-
-#ifndef AMDIS_PARALLELDOMAINSCAL_H
-#define AMDIS_PARALLELDOMAINSCAL_H
-
-#include "ParallelDomainBase.h"
-#include "ProblemScal.h"
-
-namespace AMDiS {
-
-  class ParallelDomainScal : public ParallelDomainBase
-  {
-  public:
-    ParallelDomainScal(ProblemScal *problem,
-		       ProblemInstatScal *problemInstat);
-
-    void initParallelization(AdaptInfo *adaptInfo);
-
-    // Writes all data of this object to an output stream.
-    virtual void serialize(std::ostream &out)
-    {
-      probScal->serialize(out);
-      ParallelDomainBase::serialize(out);
-    }
-
-    // Reads the object data from an input stream.
-    virtual void deserialize(std::istream &in)
-    {
-      probScal->deserialize(in);
-      ParallelDomainBase::deserialize(in);
-    }
-
-  protected:
-    /// Starts the solution of the linear system using Petsc.
-    void solve();
-
-  protected:
-    /// Pointer to the stationary problem.
-    ProblemScal *probScal;
-  };
-
-}
-
-#endif // AMDIS_PARALLELDOMAINSCAL_H
diff --git a/AMDiS/src/RefinementManager.cc b/AMDiS/src/RefinementManager.cc
index fa82560e..757c0dd3 100644
--- a/AMDiS/src/RefinementManager.cc
+++ b/AMDiS/src/RefinementManager.cc
@@ -41,7 +41,7 @@ namespace AMDiS {
     FUNCNAME("RefinementManager::refineMesh()");
 
     mesh = aMesh;
-    int n_elements = mesh->getNumberOfLeaves();
+    int nElements = mesh->getNumberOfLeaves();
     ElInfo *elInfo;
     newCoords = false;
     stack = new TraverseStack;
@@ -67,9 +67,14 @@ namespace AMDiS {
 
     delete stack;
 
-    n_elements = mesh->getNumberOfLeaves() - n_elements;
-
-    return(n_elements ? MESH_REFINED : Flag(0));
+    nElements -= mesh->getNumberOfLeaves();
+   
+    if (nElements != 0) {
+      aMesh->incChangeIndex();
+      return MESH_REFINED;
+    } else {
+      return Flag(0);
+    }
   }
 
 }
diff --git a/AMDiS/src/RefinementManager2d.cc b/AMDiS/src/RefinementManager2d.cc
index 47502a11..4db3aaa9 100644
--- a/AMDiS/src/RefinementManager2d.cc
+++ b/AMDiS/src/RefinementManager2d.cc
@@ -150,7 +150,8 @@ namespace AMDiS {
   {
     TraverseStack stack;
     ElInfo *elInfo = stack.traverseFirst(mesh, -1, 
-					 Mesh::CALL_EVERY_EL_PREORDER | Mesh::FILL_BOUND | Mesh::FILL_COORDS);
+					 Mesh::CALL_EVERY_EL_PREORDER | 
+					 Mesh::FILL_BOUND | Mesh::FILL_COORDS);
     while (elInfo) {
       newCoordsFct(elInfo);
       elInfo = stack.traverseNext(elInfo);
-- 
GitLab