From 299ccf0d3c589762c531f3e078b0610e4678438a Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Wed, 9 Apr 2008 08:06:14 +0000
Subject: [PATCH] * writeResidualMesh() for ProblemScal and ProblemVec

---
 AMDiS/bin/Makefile.am          |   2 +-
 AMDiS/bin/Makefile.in          |  28 +-
 AMDiS/libtool                  |  10 +-
 AMDiS/src/ElementFileWriter.cc | 561 +++++++++++++++++++++------------
 AMDiS/src/ElementFileWriter.h  | 230 ++++++++------
 AMDiS/src/ProblemScal.cc       |  28 ++
 AMDiS/src/ProblemScal.h        |   2 +
 AMDiS/src/ProblemVec.cc        |  27 ++
 AMDiS/src/ProblemVec.h         |   3 +
 9 files changed, 560 insertions(+), 331 deletions(-)

diff --git a/AMDiS/bin/Makefile.am b/AMDiS/bin/Makefile.am
index 19b3265c..796639ee 100644
--- a/AMDiS/bin/Makefile.am
+++ b/AMDiS/bin/Makefile.am
@@ -12,7 +12,6 @@ if USE_PARALLEL_AMDIS
   PARALLEL_AMDIS_SOURCES = \
   $(PARALLEL_DIR)/ConditionalEstimator.h $(PARALLEL_DIR)/ConditionalEstimator.cc \
   $(PARALLEL_DIR)/ConditionalMarker.h \
-  $(PARALLEL_DIR)/ElementFileWriter.h $(PARALLEL_DIR)/ElementFileWriter.cc \
   $(PARALLEL_DIR)/MeshStructure.h $(PARALLEL_DIR)/MeshStructure.cc \
   $(PARALLEL_DIR)/MeshStructure_ED.h \
   $(PARALLEL_DIR)/ParallelError.h $(PARALLEL_DIR)/ParallelError.hh \
@@ -95,6 +94,7 @@ $(SOURCE_DIR)/ProblemStatBase.h \
 $(SOURCE_DIR)/MatVecMultiplier.cc \
 $(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)/MatVecMultiplier.h \
 $(SOURCE_DIR)/Operator.h $(SOURCE_DIR)/Operator.cc \
diff --git a/AMDiS/bin/Makefile.in b/AMDiS/bin/Makefile.in
index 657a40e3..939c3ef6 100644
--- a/AMDiS/bin/Makefile.in
+++ b/AMDiS/bin/Makefile.in
@@ -64,8 +64,6 @@ libamdis_la_LIBADD =
 am__libamdis_la_SOURCES_DIST = $(PARALLEL_DIR)/ConditionalEstimator.h \
 	$(PARALLEL_DIR)/ConditionalEstimator.cc \
 	$(PARALLEL_DIR)/ConditionalMarker.h \
-	$(PARALLEL_DIR)/ElementFileWriter.h \
-	$(PARALLEL_DIR)/ElementFileWriter.cc \
 	$(PARALLEL_DIR)/MeshStructure.h \
 	$(PARALLEL_DIR)/MeshStructure.cc \
 	$(PARALLEL_DIR)/MeshStructure_ED.h \
@@ -137,7 +135,8 @@ am__libamdis_la_SOURCES_DIST = $(PARALLEL_DIR)/ConditionalEstimator.h \
 	$(SOURCE_DIR)/ProblemStatBase.h \
 	$(SOURCE_DIR)/MatVecMultiplier.cc $(SOURCE_DIR)/DOFContainer.h \
 	$(SOURCE_DIR)/FileWriter.h $(SOURCE_DIR)/FileWriter.hh \
-	$(SOURCE_DIR)/FileWriter.cc $(SOURCE_DIR)/ElInfo.cc \
+	$(SOURCE_DIR)/FileWriter.cc $(SOURCE_DIR)/ElementFileWriter.h \
+	$(SOURCE_DIR)/ElementFileWriter.cc $(SOURCE_DIR)/ElInfo.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 \
@@ -228,7 +227,6 @@ am__libamdis_la_SOURCES_DIST = $(PARALLEL_DIR)/ConditionalEstimator.h \
 	$(SOURCE_DIR)/PeriodicInfo.h $(SOURCE_DIR)/OpenMP.h
 @USE_PARALLEL_AMDIS_TRUE@am__objects_1 =  \
 @USE_PARALLEL_AMDIS_TRUE@	libamdis_la-ConditionalEstimator.lo \
-@USE_PARALLEL_AMDIS_TRUE@	libamdis_la-ElementFileWriter.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
@@ -254,9 +252,9 @@ am_libamdis_la_OBJECTS = $(am__objects_1) \
 	libamdis_la-SurfaceQuadrature.lo libamdis_la-LeafData.lo \
 	libamdis_la-BoundaryManager.lo libamdis_la-DirichletBC.lo \
 	libamdis_la-RobinBC.lo libamdis_la-MatVecMultiplier.lo \
-	libamdis_la-FileWriter.lo libamdis_la-ElInfo.lo \
-	libamdis_la-Operator.lo libamdis_la-Mesh.lo \
-	libamdis_la-AdaptStationary.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-AdaptInstationary.lo \
 	libamdis_la-DiagonalPreconditioner.lo \
 	libamdis_la-ILUPreconditioner.lo \
@@ -447,7 +445,6 @@ AMDIS_INCLUDES = -I$(SOURCE_DIR) $(am__append_2)
 @USE_PARALLEL_AMDIS_TRUE@PARALLEL_AMDIS_SOURCES = \
 @USE_PARALLEL_AMDIS_TRUE@  $(PARALLEL_DIR)/ConditionalEstimator.h $(PARALLEL_DIR)/ConditionalEstimator.cc \
 @USE_PARALLEL_AMDIS_TRUE@  $(PARALLEL_DIR)/ConditionalMarker.h \
-@USE_PARALLEL_AMDIS_TRUE@  $(PARALLEL_DIR)/ElementFileWriter.h $(PARALLEL_DIR)/ElementFileWriter.cc \
 @USE_PARALLEL_AMDIS_TRUE@  $(PARALLEL_DIR)/MeshStructure.h $(PARALLEL_DIR)/MeshStructure.cc \
 @USE_PARALLEL_AMDIS_TRUE@  $(PARALLEL_DIR)/MeshStructure_ED.h \
 @USE_PARALLEL_AMDIS_TRUE@  $(PARALLEL_DIR)/ParallelError.h $(PARALLEL_DIR)/ParallelError.hh \
@@ -511,6 +508,7 @@ $(SOURCE_DIR)/ProblemStatBase.h \
 $(SOURCE_DIR)/MatVecMultiplier.cc \
 $(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)/MatVecMultiplier.h \
 $(SOURCE_DIR)/Operator.h $(SOURCE_DIR)/Operator.cc \
@@ -799,13 +797,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-ElementFileWriter.lo: $(PARALLEL_DIR)/ElementFileWriter.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-ElementFileWriter.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-ElementFileWriter.Tpo" -c -o libamdis_la-ElementFileWriter.lo `test -f '$(PARALLEL_DIR)/ElementFileWriter.cc' || echo '$(srcdir)/'`$(PARALLEL_DIR)/ElementFileWriter.cc; \
-@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-ElementFileWriter.Tpo" "$(DEPDIR)/libamdis_la-ElementFileWriter.Plo"; else rm -f "$(DEPDIR)/libamdis_la-ElementFileWriter.Tpo"; exit 1; fi
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(PARALLEL_DIR)/ElementFileWriter.cc' object='libamdis_la-ElementFileWriter.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-ElementFileWriter.lo `test -f '$(PARALLEL_DIR)/ElementFileWriter.cc' || echo '$(srcdir)/'`$(PARALLEL_DIR)/ElementFileWriter.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
@@ -1100,6 +1091,13 @@ libamdis_la-FileWriter.lo: $(SOURCE_DIR)/FileWriter.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-FileWriter.lo `test -f '$(SOURCE_DIR)/FileWriter.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/FileWriter.cc
 
+libamdis_la-ElementFileWriter.lo: $(SOURCE_DIR)/ElementFileWriter.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-ElementFileWriter.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-ElementFileWriter.Tpo" -c -o libamdis_la-ElementFileWriter.lo `test -f '$(SOURCE_DIR)/ElementFileWriter.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/ElementFileWriter.cc; \
+@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-ElementFileWriter.Tpo" "$(DEPDIR)/libamdis_la-ElementFileWriter.Plo"; else rm -f "$(DEPDIR)/libamdis_la-ElementFileWriter.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(SOURCE_DIR)/ElementFileWriter.cc' object='libamdis_la-ElementFileWriter.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-ElementFileWriter.lo `test -f '$(SOURCE_DIR)/ElementFileWriter.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/ElementFileWriter.cc
+
 libamdis_la-ElInfo.lo: $(SOURCE_DIR)/ElInfo.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-ElInfo.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-ElInfo.Tpo" -c -o libamdis_la-ElInfo.lo `test -f '$(SOURCE_DIR)/ElInfo.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/ElInfo.cc; \
 @am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-ElInfo.Tpo" "$(DEPDIR)/libamdis_la-ElInfo.Plo"; else rm -f "$(DEPDIR)/libamdis_la-ElInfo.Tpo"; exit 1; fi
diff --git a/AMDiS/libtool b/AMDiS/libtool
index 21b737c9..315f21f9 100755
--- a/AMDiS/libtool
+++ b/AMDiS/libtool
@@ -44,7 +44,7 @@ available_tags=" CXX F77"
 
 # ### BEGIN LIBTOOL CONFIG
 
-# Libtool was configured on host NWRW20:
+# Libtool was configured on host NWRW15:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -7266,7 +7266,7 @@ disable_libs=static
 # End:
 # ### BEGIN LIBTOOL TAG CONFIG: CXX
 
-# Libtool was configured on host NWRW20:
+# Libtool was configured on host NWRW15:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -7574,7 +7574,7 @@ include_expsyms=""
 
 # ### BEGIN LIBTOOL TAG CONFIG: F77
 
-# Libtool was configured on host NWRW20:
+# Libtool was configured on host NWRW15:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -7618,7 +7618,7 @@ LTCC="gcc"
 LTCFLAGS="-g -O2"
 
 # A language-specific compiler.
-CC="f95"
+CC="g77"
 
 # Is the compiler the GNU C compiler?
 with_gcc=yes
@@ -7858,7 +7858,7 @@ 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 " /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"`
+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="/lib /usr/lib /usr/lib/qt-3.3/lib "
diff --git a/AMDiS/src/ElementFileWriter.cc b/AMDiS/src/ElementFileWriter.cc
index 0dcf8b72..9d959bb8 100644
--- a/AMDiS/src/ElementFileWriter.cc
+++ b/AMDiS/src/ElementFileWriter.cc
@@ -1,275 +1,424 @@
 #include "ElementFileWriter.h"
-
 #include "BasisFunction.h"
 #include "Parameters.h"
 #include "Traverse.h"
 #include "AdaptInfo.h"
 
-using namespace std;
-
-ElementFileWriter::ElementFileWriter(const std::string& name_, 
-				     Mesh *mesh_,
-				     const FiniteElemSpace *feSpace_,
-				     std::map<int, int> &vec_)
-  : name(name_),
-    tecplotExt(".plt"),
-    amdisMeshDatExt(".elem.mesh"),
-    writeTecPlotFormat(0),
-    writeAMDiSFormat(0),
-    appendIndex(0),
-    indexLength(5),
-    indexDecimals(3),
-    tsModulo(1),
-    timestepNumber(-1),
-    mesh(mesh_),
-    feSpace(feSpace_),
-    vec(vec_)
-{
-  GET_PARAMETER(0, name + "->output->filename", &filename);
-  GET_PARAMETER(0, name + "->output->TecPlot format", "%d", 
-		&writeTecPlotFormat);
-  GET_PARAMETER(0, name + "->output->TecPlot ext", &tecplotExt);
-  GET_PARAMETER(0, name + "->output->AMDiS format", "%d", &writeAMDiSFormat);
-  GET_PARAMETER(0, name + "->output->AMDiS mesh-dat ext", &amdisMeshDatExt);
-  GET_PARAMETER(0, name + "->output->append index", "%d", &appendIndex);
-  GET_PARAMETER(0, name + "->output->index length", "%d", &indexLength);
-  GET_PARAMETER(0, name + "->output->index decimals", "%d", &indexDecimals);
-  GET_PARAMETER(0, name + "->output->write every i-th timestep", "%d", 
-		&tsModulo);
-
-  //   TEST_EXIT(vec.size() == mesh->getNumberOfLeaves())
-  //     ("illegal size !\n");
-}
+namespace AMDiS {
+
+  ElementFileWriter::ElementFileWriter(const std::string& name_, 
+				       Mesh *mesh_,
+				       const FiniteElemSpace *feSpace_,
+				       std::map<int, double> &vec_)
+    : name(name_),
+      tecplotExt(".plt"),
+      amdisMeshDatExt(".elem.mesh"),
+      vtkExt(".vtu"),
+      writeTecPlotFormat(0),
+      writeAMDiSFormat(0),
+      writeVtkFormat(0),
+      appendIndex(0),
+      indexLength(5),
+      indexDecimals(3),
+      tsModulo(1),
+      timestepNumber(-1),
+      mesh(mesh_),
+      feSpace(feSpace_),
+      vec(vec_)
+  {
+    GET_PARAMETER(0, name + "->output->filename", &filename);
+    GET_PARAMETER(0, name + "->output->TecPlot format", "%d", 
+		  &writeTecPlotFormat);
+    GET_PARAMETER(0, name + "->output->TecPlot ext", &tecplotExt);
+    GET_PARAMETER(0, name + "->output->AMDiS format", "%d", &writeAMDiSFormat);
+    GET_PARAMETER(0, name + "->output->AMDiS mesh-dat ext", &amdisMeshDatExt);
+    GET_PARAMETER(0, name + "->output->ParaView format", "%d", &writeVtkFormat);
+    GET_PARAMETER(0, name + "->output->append index", "%d", &appendIndex);
+    GET_PARAMETER(0, name + "->output->index length", "%d", &indexLength);
+    GET_PARAMETER(0, name + "->output->index decimals", "%d", &indexDecimals);
+    GET_PARAMETER(0, name + "->output->write every i-th timestep", "%d", 
+		  &tsModulo);
+
+    //   TEST_EXIT(vec.size() == mesh->getNumberOfLeaves())
+    //     ("illegal size !\n");
+  }
 
-void 
-ElementFileWriter::writeFiles(AdaptInfo *adaptInfo, bool force)
-{
-  FUNCNAME("ElementFileWriter::writeFiles()");
+  void ElementFileWriter::writeFiles(AdaptInfo *adaptInfo, bool force,
+				     int level, Flag traverseFlag, bool (*writeElem)(ElInfo*))
+  {
+    FUNCNAME("ElementFileWriter::writeFiles()");
 
-  timestepNumber++;
-  timestepNumber %= tsModulo;
+    timestepNumber++;
+    timestepNumber %= tsModulo;
 
-  if((timestepNumber != 0) && !force) return;
+    if ((timestepNumber != 0) && !force) 
+      return;
 
-  std::string fn = filename;
+    std::string fn = filename;
 
-  if(appendIndex) {
-    TEST_EXIT(indexLength <= 99)("index lenght > 99\n");
-    TEST_EXIT(indexDecimals <= 97)("index decimals > 97\n");
-    TEST_EXIT(indexDecimals < indexLength)
-      ("index length <= index decimals\n");
+    if (appendIndex) {
+      TEST_EXIT(indexLength <= 99)("index lenght > 99\n");
+      TEST_EXIT(indexDecimals <= 97)("index decimals > 97\n");
+      TEST_EXIT(indexDecimals < indexLength)("index length <= index decimals\n");
     
-    char formatStr[9];
+      char formatStr[9];
 
-    sprintf(formatStr, "%%0%d.%df", indexLength, indexDecimals);
+      sprintf(formatStr, "%%0%d.%df", indexLength, indexDecimals);
 
-    char timeStr[20];
+      char timeStr[20];
 
-    sprintf(timeStr, formatStr, adaptInfo ? adaptInfo->getTime() : 0.0);
+      sprintf(timeStr, formatStr, adaptInfo ? adaptInfo->getTime() : 0.0);
 
-    fn += timeStr;
-  }
+      fn += timeStr;
+    }
 
 
-  if(writeTecPlotFormat) {
-    writeTecPlotValues(const_cast<char*>((fn + tecplotExt).c_str()));
-    MSG("TecPlot file written to %s\n", (fn + tecplotExt).c_str());
-  }
+    if (writeTecPlotFormat) {
+      TEST_EXIT(mesh)("no mesh\n");
+
+      writeTecPlotValues(const_cast<char*>((fn + tecplotExt).c_str()));
+      MSG("TecPlot file written to %s\n", (fn + tecplotExt).c_str());
+    }
 
-  if(writeAMDiSFormat) {
-    TEST_EXIT(mesh)("no mesh\n");
+    if (writeAMDiSFormat) {
+      TEST_EXIT(mesh)("no mesh\n");
     
-    writeMeshDatValues(const_cast<char*>( (fn + amdisMeshDatExt).c_str()),
-		       adaptInfo ? adaptInfo->getTime() : 0.0);
+      writeMeshDatValues(const_cast<char*>( (fn + amdisMeshDatExt).c_str()),
+			 adaptInfo ? adaptInfo->getTime() : 0.0);
+      MSG("MeshDat file written to %s\n", (fn + amdisMeshDatExt).c_str());
+    }
 
-    MSG("MeshDat file written to %s\n", (fn + amdisMeshDatExt).c_str());
-  }
-}
+    if (writeVtkFormat) {
+      TEST_EXIT(mesh)("no mesh\n");
 
-void 
-ElementFileWriter::writeTecPlotValues(const char* filename)
-{
-  FUNCNAME("ElementFileWriter::writeTecPlotValues()");
-  ofstream fout(filename);
-
-  TEST_EXIT(fout)("Could not open file %s !\n", filename);
-  fout.setf(std::ios::scientific,std::ios::floatfield);
-
-  int dim = mesh->getDim();
-  double val;
-
-
-  // === Write header. ===
-  fout << "TITLE = \"" << name.c_str() << "\"\n";
-  fout << "VARIABLES = ";
-  switch(dim) {
-  case 2: fout << "\"x\",\"y\"";
-    break;
-  case 3: fout << "\"x\",\"y\",\"z\"";
-    break;
-  default: ERROR_EXIT("illegal dimension !\n");
-    break;
-  }
-  fout << ",\"" << name.c_str() << "\"\n";
-  fout << "ZONE T=\"" << name.c_str() << "\""
-       << ", N=" << 3*mesh->getNumberOfLeaves() 
-       << ", E=" << mesh->getNumberOfLeaves() 
-       << ", F=FEPOINT, ";
-  switch(dim) {
-  case 2: fout << "ET=TRIANGLE\n\n";
-    break;
-  case 3: fout << "ET=TETRAHEDRON\n\n";
-    break;
-  default: ERROR_EXIT("illegal dimension !\n");
-    break;
+      writeVtkValues(const_cast<char*>( (fn + vtkExt).c_str()));
+      MSG("VTK file written to %s\n", (fn + vtkExt).c_str());		     
+    }
   }
 
+  void ElementFileWriter::writeTecPlotValues(const char* filename)
+  {
+    FUNCNAME("ElementFileWriter::writeTecPlotValues()");
+    ::std::ofstream fout(filename);
+
+    TEST_EXIT(fout)("Could not open file %s !\n", filename);
+    fout.setf(std::ios::scientific,std::ios::floatfield);
 
-  // === Write vertex coordinates and values (for each element !). ===
-  TraverseStack stack;
+    int dim = mesh->getDim();
+    double val;
 
-  ElInfo *elInfo = stack.traverseFirst(mesh,
-				       -1, 
-				       Mesh::CALL_LEAF_EL | 
-				       Mesh::FILL_COORDS);
 
-  while(elInfo) {
+    // === Write header. ===
+    fout << "TITLE = \"" << name.c_str() << "\"\n";
+    fout << "VARIABLES = ";
+    switch (dim) {
+    case 2: fout << "\"x\",\"y\"";
+      break;
+    case 3: fout << "\"x\",\"y\",\"z\"";
+      break;
+    default: ERROR_EXIT("illegal dimension !\n");
+      break;
+    }
+    fout << ",\"" << name.c_str() << "\"\n";
+    fout << "ZONE T=\"" << name.c_str() << "\""
+	 << ", N=" << 3*mesh->getNumberOfLeaves() 
+	 << ", E=" << mesh->getNumberOfLeaves() 
+	 << ", F=FEPOINT, ";
+    switch (dim) {
+    case 2: fout << "ET=TRIANGLE\n\n";
+      break;
+    case 3: fout << "ET=TETRAHEDRON\n\n";
+      break;
+    default: ERROR_EXIT("illegal dimension !\n");
+      break;
+    }
+
+
+    // === Write vertex coordinates and values (for each element !). ===
+    TraverseStack stack;
 
-    // Get element value.
-    val = (double) vec[elInfo->getElement()->getIndex()];
+    ElInfo *elInfo = stack.traverseFirst(mesh,
+					 -1, 
+					 Mesh::CALL_LEAF_EL | 
+					 Mesh::FILL_COORDS);
+
+    while (elInfo) {
+      // Get element value.
+      val = vec[elInfo->getElement()->getIndex()];
     
-    // Write coordinates of all element vertices and element value.
-    for (int i=0; i<=dim; ++i) {
+      // Write coordinates of all element vertices and element value.
+      for (int i = 0; i <= dim; ++i) {
       
-      for (int j=0; j<dim; ++j) {
-	fout << elInfo->getCoord(i)[j] << " ";
+	for (int j = 0; j < dim; ++j) {
+	  fout << elInfo->getCoord(i)[j] << " ";
+	}
+	fout << val << "\n";
       }
-      fout << val << "\n";
-    }
     
-    elInfo = stack.traverseNext(elInfo);
-  }  // end of: mesh traverse
+      elInfo = stack.traverseNext(elInfo);
+    }  // end of: mesh traverse
 
   
-  // === Write elements. ===
-  int numLeaves = mesh->getNumberOfLeaves();
-  int vertCntr = 0;
-  fout << "\n";
-  for (int i=0; i<numLeaves; ++i) {
-
-    for (int j=0; j<=dim; ++j) {
+    // === Write elements. ===
+    int numLeaves = mesh->getNumberOfLeaves();
+    int vertCntr = 0;
+    fout << "\n";
 
-      ++vertCntr;
-      fout << vertCntr << " ";
+    for (int i = 0; i<numLeaves; ++i) {
+      for (int j = 0; j<=dim; ++j) {
+	++vertCntr;
+	fout << vertCntr << " ";
+      }
+      fout << "\n";
     }
-    fout << "\n";
+
+
+    fout.close();
   }
 
+  void ElementFileWriter::writeMeshDatValues(const char* filename, double time)
+  {
+    FUNCNAME("ElementFileWriter::writeMeshDatValues()");
+    ::std::ofstream fout(filename);
 
-  fout.close();
-}
+    TEST_EXIT(fout)("Could not open file %s !\n", filename);
 
-void 
-ElementFileWriter::writeMeshDatValues(const char* filename, double time)
-{
-  FUNCNAME("ElementFileWriter::writeMeshDatValues()");
-  ofstream fout(filename);
+    int dim = mesh->getDim();
+    double val;
 
-  TEST_EXIT(fout)("Could not open file %s !\n", filename);
+    // === Write header. ===
+    fout << "mesh name: " << mesh->getName().c_str() << "\n\n";
+    fout << "time: " << time << "\n\n"; 
+    fout << "DIM: " << dim << "\n";
+    fout << "DIM_OF_WORLD: " << Global::getGeo(WORLD) << "\n\n";
+    fout << "number of vertices: " << (dim+1)*mesh->getNumberOfLeaves() << "\n";
+    fout << "number of elements: " << mesh->getNumberOfLeaves() << "\n\n";
 
-  int dim = mesh->getDim();
-  double val;
 
-  // === Write header. ===
-  fout << "mesh name: " << mesh->getName().c_str() << "\n\n";
-  fout << "time: " << time << "\n\n"; 
-  fout << "DIM: " << dim << "\n";
-  fout << "DIM_OF_WORLD: " << Global::getGeo(WORLD) << "\n\n";
-  fout << "number of vertices: " << (dim+1)*mesh->getNumberOfLeaves() << "\n";
-  fout << "number of elements: " << mesh->getNumberOfLeaves() << "\n\n";
+    // === Write vertex coordinates (every vertex for every element). ===
+    fout << "vertex coordinates:\n";
+    TraverseStack stack;
 
+    ElInfo *elInfo = stack.traverseFirst(mesh,
+					 -1, 
+					 Mesh::CALL_LEAF_EL | 
+					 Mesh::FILL_COORDS);
 
-  // === Write vertex coordinates (every vertex for every element). ===
-  fout << "vertex coordinates:\n";
-  TraverseStack stack;
+    while (elInfo) {
 
-  ElInfo *elInfo = stack.traverseFirst(mesh,
-				       -1, 
-				       Mesh::CALL_LEAF_EL | 
-				       Mesh::FILL_COORDS);
+      // Write coordinates of all element vertices.
+      for (int i = 0; i <= dim; ++i) {     
+	for (int j = 0; j < dim; ++j) {
+	  fout << elInfo->getCoord(i)[j] << " ";
+	}
+	fout << "\n";
+      }
+    
+      elInfo = stack.traverseNext(elInfo);
+    }
 
-  while(elInfo) {
 
-    // Write coordinates of all element vertices.
-    for (int i=0; i<=dim; ++i) {
-      
-      for (int j=0; j<dim; ++j) {
-	fout << elInfo->getCoord(i)[j] << " ";
+    // === Write elements. ===
+    int numLeaves = mesh->getNumberOfLeaves();
+    int vertCntr = 0;
+    fout << "\n";
+    fout << "element vertices:\n";
+    for (int i = 0; i < numLeaves; ++i) {
+      for (int j = 0; j <= dim; ++j) {
+	fout << vertCntr << " ";
+	++vertCntr;
       }
       fout << "\n";
     }
-    
-    elInfo = stack.traverseNext(elInfo);
-  }  // end of: mesh traverse
-
 
-  // === Write elements. ===
-  int numLeaves = mesh->getNumberOfLeaves();
-  int vertCntr = 0;
-  fout << "\n";
-  fout << "element vertices:\n";
-  for (int i=0; i<numLeaves; ++i) {
 
-    for (int j=0; j<=dim; ++j) {
+    // === Write values. ===
 
-      fout << vertCntr << " ";
-      ++vertCntr;
-    }
+    // Write values header.
     fout << "\n";
-  }
-
+    fout << "number of values: 1\n\n";
+    fout << "value description: " << name.c_str() << "\n";
+    fout << "number of interpolation points: 0" << "\n";
+    fout << "type: scalar" << "\n";
+    fout << "interpolation type: lagrange" << "\n";
+    fout << "interpolation degree: 1" << "\n";
+    fout << "end of description: " << name.c_str() << "\n\n";
+
+    // Write values.
+    fout << "vertex values: " << name.c_str() << "\n";
+
+    fout.setf(std::ios::scientific,std::ios::floatfield);
+
+    elInfo = stack.traverseFirst(mesh,
+				 -1, 
+				 Mesh::CALL_LEAF_EL);
+
+    while (elInfo) {
+      // Get element value.
+      val = vec[elInfo->getElement()->getIndex()];
+    
+      // Write value for each vertex of each element.
+      for (int i = 0; i <= dim; ++i) {      
+	fout << val << "\n";
+      }
+    
+      elInfo = stack.traverseNext(elInfo);
+    }  // end of: mesh traverse
 
-  // === Write values. ===
 
-  // Write values header.
-  fout << "\n";
-  fout << "number of values: 1\n\n";
-  fout << "value description: " << name.c_str() << "\n";
-  fout << "number of interpolation points: 0" << "\n";
-  fout << "type: scalar" << "\n";
-  fout << "interpolation type: lagrange" << "\n";
-  fout << "interpolation degree: 1" << "\n";
-  fout << "end of description: " << name.c_str() << "\n\n";
+    // Write values trailor.
+    fout << "\n";
+    fout << "interpolation values: " << name.c_str() << "\n\n\n";
+    fout << "element interpolation points: " << name.c_str() << "\n";
 
-  // Write values.
-  fout << "vertex values: " << name.c_str() << "\n";
 
-  fout.setf(std::ios::scientific,std::ios::floatfield);
+    fout.close();
+  }
 
-  elInfo = stack.traverseFirst(mesh,
-			       -1, 
-			       Mesh::CALL_LEAF_EL);
+  void ElementFileWriter::writeVtkValues(const char* filename)
+  {
+    FUNCNAME("ElementFileWriter::writeVtkValues()");
+    ::std::ofstream fout(filename);
+
+    TEST_EXIT(fout)("Could not open file %s !\n", filename);
+
+    int dim = mesh->getDim();
+    int vertices = mesh->getGeo(VERTEX);
+    int nElements = mesh->getNumberOfLeaves();
+    double val;
+
+    fout << "<?xml version=\"1.0\"?>" << ::std::endl;
+    fout << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" << ::std::endl;
+    fout << "  <UnstructuredGrid>" << ::std::endl;
+    fout << "    <Piece NumberOfPoints=\"" << (dim + 1) * mesh->getNumberOfLeaves() 
+	 << "\" NumberOfCells=\"" <<  nElements << "\">" << ::std::endl;
+    fout << "      <Points>" << ::std::endl;
+    fout << "        <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">" << ::std::endl;
+
+
+    // === Write vertex coordinates (every vertex for every element). ===
+    TraverseStack stack;
+
+    ElInfo *elInfo = stack.traverseFirst(mesh,
+					 -1, 
+					 Mesh::CALL_LEAF_EL | 
+					 Mesh::FILL_COORDS);
+
+    while (elInfo) {
+      // Write coordinates of all element vertices.
+      for (int i = 0; i <= dim; i++) {     
+	for (int j = 0; j < dim; j++) {
+	  fout << elInfo->getCoord(i)[j] << " ";
+	}
+	for (int j = dim; j < 3; j++) {
+	  fout << "0.0";
+	}
+	fout << "\n";
+      }
+   
+      elInfo = stack.traverseNext(elInfo);
+    }
 
-  while(elInfo) {
+    fout << "        </DataArray>" << ::std::endl;
+    fout << "      </Points>" << ::std::endl;
+    fout << "      <Cells>" << ::std::endl;
 
-    // Get element value.
-    val = (double) vec[elInfo->getElement()->getIndex()];
+    fout << "        <DataArray type=\"Int32\" Name=\"offsets\">" << ::std::endl;
+    for (int i = 0; i < nElements; i++) {
+      fout << " " << (i + 1) * vertices << ::std::endl;
+    }
+    fout << "        </DataArray>" << ::std::endl;
+
+
+    fout << "        <DataArray type=\"UInt8\" Name=\"types\">" << ::std::endl;
+    for (int i = 0; i < nElements; i++) {
+      switch (vertices) {
+      case 2:
+	fout << " 3" << ::std::endl;
+	break;
+      case 3: 
+	fout << " 5" << ::std::endl;
+	break;
+      case 4:
+	fout << " 10" << ::std::endl;
+	break;		    
+      default:
+	break;
+      }	   
+    }
+    fout << "        </DataArray>" << ::std::endl;
+
+    fout << "        <DataArray type=\"Int32\" Name=\"connectivity\">" << ::std::endl;
+    int vertCntr = 0;
+    for (int i = 0; i < nElements; ++i) {
+      for (int j = 0; j <= dim; ++j) {
+	fout << vertCntr << " ";
+	++vertCntr;
+      }
+      fout << ::std::endl;
+    }
+    fout << "        </DataArray>" << ::std::endl;
     
-    // Write value for each vertex of each element.
-    for (int i=0; i<=dim; ++i) {
+    fout << "      </Cells>" << ::std::endl;
+    fout << "      <PointData>" << ::std::endl;
+    fout << "        <DataArray type=\"Float32\" Name=\"value\" format=\"ascii\">" << ::std::endl;
+
+    fout.setf(std::ios::scientific,std::ios::floatfield);
+
+    elInfo = stack.traverseFirst(mesh,
+				 -1, 
+				 Mesh::CALL_LEAF_EL |
+				 Mesh::FILL_COORDS);
+    int vc = 0;
+    while (elInfo) {
+      // Get element value.
+      val = vec[elInfo->getElement()->getIndex()];
+
+      /*      if ((elInfo->getCoord(0)[0] == 80.0) &&
+	  (elInfo->getCoord(0)[1] == 1.25) &&
+	  (elInfo->getCoord(1)[0] == 79.9609375) &&
+	  (elInfo->getCoord(1)[1] == 1.2109375) &&
+	  (elInfo->getCoord(2)[0] == 80.0) &&
+	  (elInfo->getCoord(2)[1] == 1.2109375))
+	{
+	  ::std::cout << "------" << ::std::endl;
+	  ::std::cout << "val = " << val << "  I = " << elInfo->getElement()->getIndex() << ::std::endl;
+	  ::std::cout << "PARENT-I = " << elInfo->getParent()->getIndex() << ::std::endl;
+	  ::std::cout << "vc = " << vc << ::std::endl;
+	  ::std::cout.precision(10);
+	  for (int i = 0; i < 3; i++) {
+	    ::std::cout << elInfo->getCoord(i)[0] << "/" << elInfo->getCoord(i)[1] << ::std::endl;
+	  }	  	  
+	}
+      */
+      
+      if (val > 0.3) {
+	::std::cout.precision(10);
+	::std::cout << "------" << ::std::endl;
+	::std::cout << "val = " << val << "  I = " << elInfo->getElement()->getIndex() << ::std::endl;
+	::std::cout << "vc = " << vc << ::std::endl;
+	for (int i = 0; i < 3; i++) {
+	  ::std::cout << elInfo->getCoord(i)[0] << "/" << elInfo->getCoord(i)[1] << ::std::endl;
+	}	  	  
+      }
       
-      fout << val << "\n";
-    }
     
-    elInfo = stack.traverseNext(elInfo);
-  }  // end of: mesh traverse
-
+      // Write value for each vertex of each element.
+      for (int i = 0; i <= dim; i++) {      
+	fout << (fabs(val) < 1e-40 ? 0.0 : val) << "\n";
+      }
+      vc++;
+      elInfo = stack.traverseNext(elInfo);
+    } 
 
-  // Write values trailor.
-  fout << "\n";
-  fout << "interpolation values: " << name.c_str() << "\n\n\n";
-  fout << "element interpolation points: " << name.c_str() << "\n";
+    fout << "        </DataArray>" << ::std::endl;
+    
 
+    fout << "      </PointData>" << ::std::endl;
+    fout << "    </Piece>" << ::std::endl;
+    fout << "  </UnstructuredGrid>" << ::std::endl;
+    fout << "</VTKFile>" << ::std::endl;
 
-  fout.close();
+    fout.close();
+  }
 }
diff --git a/AMDiS/src/ElementFileWriter.h b/AMDiS/src/ElementFileWriter.h
index d46b3f3a..3ba74474 100644
--- a/AMDiS/src/ElementFileWriter.h
+++ b/AMDiS/src/ElementFileWriter.h
@@ -7,109 +7,131 @@
 #include "MemoryManager.h"
 #include "Mesh.h"
 
-using namespace AMDiS;
-
-class ElementFileWriter : public FileWriterInterface
-{
- public:
-  MEMORY_MANAGED(ElementFileWriter);
-
-  /**
-   * Constructor.
-   */
-  ElementFileWriter(const std::string& name_, 
-		    Mesh *mesh_,
-		    const FiniteElemSpace *feSpace_,
-		    std::map<int, int> &vec_);
-
-  /**
-   * Implementation of FileWriterInterface::writeFiles().
-   */
-  void writeFiles(AdaptInfo *adaptInfo, bool force);
-
- protected:
-  /**
-   * Writes element data in tecplot format.
-   */
-  void writeTecPlotValues(const char* filename);
-
-  /**
-   * Writes element data in AMDiS format (1 file !).
-   */
-  void writeMeshDatValues(const char* filename, double time);
-
- protected:
-  /** \brief
-   * Name.
-   */
-  std::string name;
-
-  /** \brief
-   * Used filename prefix.
-   */
-  std::string filename;
-
-  /** \brief
-   * TecPlot file extension.
-   */
-  std::string tecplotExt;
-
-  /** \brief
-   * AMDiS mesh-data-file extension.
-   */
-  std::string amdisMeshDatExt;
-
-  /** \brief
-   * 0: Don't write TecPlot files.
-   * 1: Write TecPlot files. 
-   */
-  int writeTecPlotFormat;
-
-  /** \brief
-   * 0: Don't write AMDiS files.
-   * 1: Write AMDiS files. 
-   */
-  int writeAMDiSFormat;
-
-  /** \brief
-   * 0: Don't append time index to filename prefix.
-   * 1: Append time index to filename prefix.
-   */
-  int appendIndex;
-
-  /** \brief
-   * Total length of appended time index.
-   */
-  int indexLength;
-
-  /** \brief
-   * Number of decimals in time index.
-   */
-  int indexDecimals;
-
-  /** \brief
-   * Timestep modulo: write only every tsModulo-th timestep! 
-   */
-  int tsModulo;
-
-  /**
-   */
-  int timestepNumber;
-
-  /** \brief
-   * Mesh used for output.
-   */
-  Mesh *mesh;
-
-  /** \brief
-   * fespace used for output.
-   */
-  const FiniteElemSpace *feSpace;
-
-  /** \brief
-   * Vector that stores the solution.
-   */
-  std::map<int, int> vec;
-};
+namespace AMDiS {
+
+  class ElementFileWriter : public FileWriterInterface
+  {
+  public:
+    MEMORY_MANAGED(ElementFileWriter);
+
+    /**
+     * Constructor.
+     */
+    ElementFileWriter(const std::string& name_, 
+		      Mesh *mesh_,
+		      const FiniteElemSpace *feSpace_,
+		      std::map<int, double> &vec_);
+
+    /**
+     * Implementation of FileWriterInterface::writeFiles().
+     */
+    void writeFiles(AdaptInfo *adaptInfo, bool force,
+		    int level = -1,
+		    Flag traverseFlag = Mesh::CALL_LEAF_EL,
+		    bool (*writeElem)(ElInfo*) = NULL);
+
+  protected:
+    /**
+     * Writes element data in tecplot format.
+     */
+    void writeTecPlotValues(const char* filename);
+
+    /**
+     * Writes element data in AMDiS format (1 file !).
+     */
+    void writeMeshDatValues(const char* filename, double time);
+
+    /**
+     * Writes element data in VTK format.
+     */
+    void writeVtkValues(const char* filename);
+
+  protected:
+    /** \brief
+     * Name.
+     */
+    std::string name;
+
+    /** \brief
+     * Used filename prefix.
+     */
+    std::string filename;
+
+    /** \brief
+     * TecPlot file extension.
+     */
+    std::string tecplotExt;
+
+    /** \brief
+     * AMDiS mesh-data-file extension.
+     */
+    std::string amdisMeshDatExt;
+
+    /** \brief
+     * VTK file extension.
+     */
+    std::string vtkExt;
+
+    /** \brief
+     * 0: Don't write TecPlot files.
+     * 1: Write TecPlot files. 
+     */
+    int writeTecPlotFormat;
+
+    /** \brief
+     * 0: Don't write AMDiS files.
+     * 1: Write AMDiS files. 
+     */
+    int writeAMDiSFormat;
+
+    /** \brief
+     * 0: Don't write VTK files.
+     * 1: Write VTK files. 
+     */
+    int writeVtkFormat;
+
+    /** \brief
+     * 0: Don't append time index to filename prefix.
+     * 1: Append time index to filename prefix.
+     */
+    int appendIndex;
+
+    /** \brief
+     * Total length of appended time index.
+     */
+    int indexLength;
+
+    /** \brief
+     * Number of decimals in time index.
+     */
+    int indexDecimals;
+
+    /** \brief
+     * Timestep modulo: write only every tsModulo-th timestep! 
+     */
+    int tsModulo;
+
+    /**
+     */
+    int timestepNumber;
+
+    /** \brief
+     * Mesh used for output.
+     */
+    Mesh *mesh;
+
+    /** \brief
+     * fespace used for output.
+     */
+    const FiniteElemSpace *feSpace;
+
+    /** \brief
+     * Vector that stores the solution.
+     */
+    std::map<int, double> vec;
+  };
+
+}
+
 
 #endif  // ELEMENTFILEWRITER_H
diff --git a/AMDiS/src/ProblemScal.cc b/AMDiS/src/ProblemScal.cc
index 1ca8d3cf..50920aa5 100644
--- a/AMDiS/src/ProblemScal.cc
+++ b/AMDiS/src/ProblemScal.cc
@@ -23,6 +23,7 @@
 #include "Lagrange.h"
 #include "PeriodicBC.h"
 #include "ValueReader.h"
+#include "ElementFileWriter.h"
 
 namespace AMDiS {
 
@@ -636,6 +637,33 @@ namespace AMDiS {
     return 0;
   }
 
+  void ProblemScal::writeResidualMesh(AdaptInfo *adaptInfo, const ::std::string name)
+  {
+    FUNCNAME("ProblemVec::writeResidualMesh()");
+
+    Mesh *mesh = this->getMesh();
+    FiniteElemSpace *fe = this->getFESpace();
+    
+    std::map<int, double> vec;
+    
+    TraverseStack stack;
+    ElInfo *elInfo = stack.traverseFirst(mesh,
+					 -1, 
+					 Mesh::CALL_LEAF_EL | 
+					 Mesh::FILL_COORDS);
+    
+    while (elInfo) {		  
+      Element *el = elInfo->getElement();
+      double lError = el->getEstimation(0);
+      
+      vec[elInfo->getElement()->getIndex()] = lError;
+      elInfo = stack.traverseNext(elInfo);
+    }
+    
+    ElementFileWriter fw(name, mesh, fe, vec);
+    fw.writeFiles(adaptInfo, true);    
+  }
+
   void ProblemScal::serialize(::std::ostream &out) 
   {
     FUNCNAME("ProblemScal::serialize()");
diff --git a/AMDiS/src/ProblemScal.h b/AMDiS/src/ProblemScal.h
index 3906d2f9..029921a0 100644
--- a/AMDiS/src/ProblemScal.h
+++ b/AMDiS/src/ProblemScal.h
@@ -404,6 +404,8 @@ namespace AMDiS {
 
     /** \} */
 
+    void writeResidualMesh(AdaptInfo *adaptInfo, const ::std::string name);
+
     // ===== Serializable implementation =====
   
     /** \brief
diff --git a/AMDiS/src/ProblemVec.cc b/AMDiS/src/ProblemVec.cc
index d154f6b2..7b588164 100644
--- a/AMDiS/src/ProblemVec.cc
+++ b/AMDiS/src/ProblemVec.cc
@@ -903,6 +903,33 @@ namespace AMDiS {
 	addBoundaryCondition(periodic);
   }
 
+  void ProblemVec::writeResidualMesh(AdaptInfo *adaptInfo, const ::std::string name)
+  {
+    FUNCNAME("ProblemVec::writeResidualMesh()");
+
+    Mesh *mesh = this->getMesh(0);
+    FiniteElemSpace *fe = this->getFESpace(0);
+    
+    std::map<int, double> vec;
+    
+    TraverseStack stack;
+    ElInfo *elInfo = stack.traverseFirst(mesh,
+					 -1, 
+					 Mesh::CALL_LEAF_EL | 
+					 Mesh::FILL_COORDS);
+    
+    while (elInfo) {		  
+      Element *el = elInfo->getElement();
+      double lError = el->getEstimation(0);
+      
+      vec[elInfo->getElement()->getIndex()] = lError;
+      elInfo = stack.traverseNext(elInfo);
+    }
+    
+    ElementFileWriter fw(name, mesh, fe, vec);
+    fw.writeFiles(adaptInfo, true);    
+  }
+
   void ProblemVec::serialize(::std::ostream &out) 
   {
     FUNCNAME("ProblemVec::serialize()");
diff --git a/AMDiS/src/ProblemVec.h b/AMDiS/src/ProblemVec.h
index c27a8223..ad765bde 100644
--- a/AMDiS/src/ProblemVec.h
+++ b/AMDiS/src/ProblemVec.h
@@ -27,6 +27,7 @@
 #include "Boundary.h"
 #include "MatrixVector.h"
 #include "StandardProblemIteration.h"
+#include "ElementFileWriter.h"
 #include <vector>
 #include <list>
 
@@ -470,6 +471,8 @@ namespace AMDiS {
 
     /** \} */
 
+    void writeResidualMesh(AdaptInfo *adaptInfo, const ::std::string name);
+
     // ===== Serializable implementation =====
   
     /** \brief
-- 
GitLab