From d1af7d661ec2dc5583f05a2e2cbdf51555d4fad6 Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Wed, 26 Jan 2011 09:51:01 +0000
Subject: [PATCH] Add DofWriter.

---
 AMDiS/CMakeLists.txt       |  3 +-
 AMDiS/bin/Makefile.am      |  1 +
 AMDiS/bin/Makefile.in      | 20 +++++++++---
 AMDiS/src/io/DofWriter.cc  | 62 ++++++++++++++++++++++++++++++++++++++
 AMDiS/src/io/DofWriter.h   | 51 +++++++++++++++++++++++++++++++
 AMDiS/src/io/FileWriter.cc | 14 +++++++--
 AMDiS/src/io/FileWriter.h  |  5 ++-
 7 files changed, 147 insertions(+), 9 deletions(-)
 create mode 100644 AMDiS/src/io/DofWriter.cc
 create mode 100644 AMDiS/src/io/DofWriter.h

diff --git a/AMDiS/CMakeLists.txt b/AMDiS/CMakeLists.txt
index f7ac49d2..7f3fd02e 100644
--- a/AMDiS/CMakeLists.txt
+++ b/AMDiS/CMakeLists.txt
@@ -136,7 +136,8 @@ SET(AMDIS_SRC ${SOURCE_DIR}/DOFIndexed.cc
 	      ${SOURCE_DIR}/TraverseParallel.cc 
 	      ${SOURCE_DIR}/Triangle.cc 
 	      ${SOURCE_DIR}/io/ValueWriter.cc 
-	      ${SOURCE_DIR}/io/VtkWriter.cc 
+	      ${SOURCE_DIR}/io/VtkWriter.cc
+	      ${SOURCE_DIR}/io/DofWriter.cc
 	      ${SOURCE_DIR}/io/PngWriter.cc 
 	      ${SOURCE_DIR}/io/PovrayWriter.cc 
 	      ${SOURCE_DIR}/io/DataCollector.cc 
diff --git a/AMDiS/bin/Makefile.am b/AMDiS/bin/Makefile.am
index 7cf79d50..7f4612bd 100644
--- a/AMDiS/bin/Makefile.am
+++ b/AMDiS/bin/Makefile.am
@@ -206,6 +206,7 @@ $(SOURCE_DIR)/TraverseParallel.h $(SOURCE_DIR)/TraverseParallel.cc \
 $(SOURCE_DIR)/Triangle.cc \
 $(SOURCE_DIR)/io/ValueWriter.cc \
 $(SOURCE_DIR)/io/VtkWriter.h $(SOURCE_DIR)/io/VtkWriter.cc \
+$(SOURCE_DIR)/io/DofWriter.h $(SOURCE_DIR)/io/DofWriter.cc \
 $(SOURCE_DIR)/io/PngWriter.h $(SOURCE_DIR)/io/PngWriter.cc \
 $(SOURCE_DIR)/io/PovrayWriter.h $(SOURCE_DIR)/io/PovrayWriter.cc \
 $(SOURCE_DIR)/io/DataCollector.h $(SOURCE_DIR)/io/DataCollector.cc \
diff --git a/AMDiS/bin/Makefile.in b/AMDiS/bin/Makefile.in
index 2cb803e6..93c6c264 100644
--- a/AMDiS/bin/Makefile.in
+++ b/AMDiS/bin/Makefile.in
@@ -234,7 +234,8 @@ am__libamdis_la_SOURCES_DIST = $(SOURCE_DIR)/parallel/StdMpi.h \
 	$(SOURCE_DIR)/TraverseParallel.h \
 	$(SOURCE_DIR)/TraverseParallel.cc $(SOURCE_DIR)/Triangle.cc \
 	$(SOURCE_DIR)/io/ValueWriter.cc $(SOURCE_DIR)/io/VtkWriter.h \
-	$(SOURCE_DIR)/io/VtkWriter.cc $(SOURCE_DIR)/io/PngWriter.h \
+	$(SOURCE_DIR)/io/VtkWriter.cc $(SOURCE_DIR)/io/DofWriter.h \
+	$(SOURCE_DIR)/io/DofWriter.cc $(SOURCE_DIR)/io/PngWriter.h \
 	$(SOURCE_DIR)/io/PngWriter.cc $(SOURCE_DIR)/io/PovrayWriter.h \
 	$(SOURCE_DIR)/io/PovrayWriter.cc \
 	$(SOURCE_DIR)/io/DataCollector.h \
@@ -319,10 +320,10 @@ am_libamdis_la_OBJECTS = $(am__objects_2) libamdis_la-DOFIndexed.lo \
 	libamdis_la-RefinementManager3d.lo libamdis_la-Tetrahedron.lo \
 	libamdis_la-Traverse.lo libamdis_la-TraverseParallel.lo \
 	libamdis_la-Triangle.lo libamdis_la-ValueWriter.lo \
-	libamdis_la-VtkWriter.lo libamdis_la-PngWriter.lo \
-	libamdis_la-PovrayWriter.lo libamdis_la-DataCollector.lo \
-	libamdis_la-ScalableQuadrature.lo libamdis_la-SubElInfo.lo \
-	libamdis_la-ElementDofIterator.lo \
+	libamdis_la-VtkWriter.lo libamdis_la-DofWriter.lo \
+	libamdis_la-PngWriter.lo libamdis_la-PovrayWriter.lo \
+	libamdis_la-DataCollector.lo libamdis_la-ScalableQuadrature.lo \
+	libamdis_la-SubElInfo.lo libamdis_la-ElementDofIterator.lo \
 	libamdis_la-InteriorBoundary.lo libamdis_la-Debug.lo \
 	libamdis_la-ArhReader.lo libamdis_la-ArhWriter.lo \
 	libamdis_la-RosenbrockAdaptInstationary.lo \
@@ -645,6 +646,7 @@ $(SOURCE_DIR)/TraverseParallel.h $(SOURCE_DIR)/TraverseParallel.cc \
 $(SOURCE_DIR)/Triangle.cc \
 $(SOURCE_DIR)/io/ValueWriter.cc \
 $(SOURCE_DIR)/io/VtkWriter.h $(SOURCE_DIR)/io/VtkWriter.cc \
+$(SOURCE_DIR)/io/DofWriter.h $(SOURCE_DIR)/io/DofWriter.cc \
 $(SOURCE_DIR)/io/PngWriter.h $(SOURCE_DIR)/io/PngWriter.cc \
 $(SOURCE_DIR)/io/PovrayWriter.h $(SOURCE_DIR)/io/PovrayWriter.cc \
 $(SOURCE_DIR)/io/DataCollector.h $(SOURCE_DIR)/io/DataCollector.cc \
@@ -780,6 +782,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-DataCollector.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-Debug.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-DirichletBC.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-DofWriter.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-DualTraverse.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ElInfo.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libamdis_la-ElInfo1d.Plo@am__quote@
@@ -1592,6 +1595,13 @@ libamdis_la-VtkWriter.lo: $(SOURCE_DIR)/io/VtkWriter.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-VtkWriter.lo `test -f '$(SOURCE_DIR)/io/VtkWriter.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/io/VtkWriter.cc
 
+libamdis_la-DofWriter.lo: $(SOURCE_DIR)/io/DofWriter.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-DofWriter.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-DofWriter.Tpo" -c -o libamdis_la-DofWriter.lo `test -f '$(SOURCE_DIR)/io/DofWriter.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/io/DofWriter.cc; \
+@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-DofWriter.Tpo" "$(DEPDIR)/libamdis_la-DofWriter.Plo"; else rm -f "$(DEPDIR)/libamdis_la-DofWriter.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(SOURCE_DIR)/io/DofWriter.cc' object='libamdis_la-DofWriter.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-DofWriter.lo `test -f '$(SOURCE_DIR)/io/DofWriter.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/io/DofWriter.cc
+
 libamdis_la-PngWriter.lo: $(SOURCE_DIR)/io/PngWriter.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-PngWriter.lo -MD -MP -MF "$(DEPDIR)/libamdis_la-PngWriter.Tpo" -c -o libamdis_la-PngWriter.lo `test -f '$(SOURCE_DIR)/io/PngWriter.cc' || echo '$(srcdir)/'`$(SOURCE_DIR)/io/PngWriter.cc; \
 @am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/libamdis_la-PngWriter.Tpo" "$(DEPDIR)/libamdis_la-PngWriter.Plo"; else rm -f "$(DEPDIR)/libamdis_la-PngWriter.Tpo"; exit 1; fi
diff --git a/AMDiS/src/io/DofWriter.cc b/AMDiS/src/io/DofWriter.cc
new file mode 100644
index 00000000..788165cd
--- /dev/null
+++ b/AMDiS/src/io/DofWriter.cc
@@ -0,0 +1,62 @@
+//
+// Software License for AMDiS
+//
+// Copyright (c) 2010 Dresden University of Technology 
+// All rights reserved.
+// Authors: Simon Vey, Thomas Witkowski et al.
+//
+// This file is part of AMDiS
+//
+// See also license.opensource.txt in the distribution.
+
+
+#include "DofWriter.h"
+#include "DOFVector.h"
+#include "BasisFunction.h"
+
+namespace AMDiS {
+
+  void DofWriter::writeFile(std::string filename, std::vector<DOFVector<double>*> &vec)
+  {
+    FUNCNAME("DofWriter::writeFile()");
+
+    DOFVector<WorldVector<double> > coordDof(feSpace, "tmp");
+    
+    Mesh *mesh = feSpace->getMesh();
+    const BasisFunction* basFcts = feSpace->getBasisFcts();
+    int nBasFcts = basFcts->getNumber();
+    std::vector<DegreeOfFreedom> dofVec(nBasFcts);
+    
+    TraverseStack stack;
+    ElInfo *elInfo = 
+      stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS);
+    while (elInfo) {
+      basFcts->getLocalIndices(elInfo->getElement(), feSpace->getAdmin(), dofVec);
+      for (int i = 0; i < nBasFcts; i++) {
+	DimVec<double> *baryCoords = basFcts->getCoords(i);
+	elInfo->coordToWorld(*baryCoords, coordDof[dofVec[i]]);
+      }
+      
+      elInfo = stack.traverseNext(elInfo);
+    }   
+    
+    std::ofstream outfile;
+    outfile.open(filename.c_str());
+    outfile.precision(10);
+    
+    DOFIterator<WorldVector<double> > it(&coordDof, USED_DOFS);
+    for (it.reset(); !it.end(); ++it) {
+      outfile << it.getDOFIndex() << " ";
+      
+      for (int i = 0; i < Global::getGeo(WORLD); i++)
+	outfile << (*it)[i] << " ";
+      
+      for (unsigned int i = 0; i < vec.size(); i++) 
+	outfile << (*(vec[i]))[it.getDOFIndex()] << " ";
+      outfile << std::endl;
+    }   
+    
+    outfile.close();
+  }
+    
+}
diff --git a/AMDiS/src/io/DofWriter.h b/AMDiS/src/io/DofWriter.h
new file mode 100644
index 00000000..b3236c05
--- /dev/null
+++ b/AMDiS/src/io/DofWriter.h
@@ -0,0 +1,51 @@
+// ============================================================================
+// ==                                                                        ==
+// == AMDiS - Adaptive multidimensional simulations                          ==
+// ==                                                                        ==
+// ==  http://www.amdis-fem.org                                              ==
+// ==                                                                        ==
+// ============================================================================
+//
+// Software License for AMDiS
+//
+// Copyright (c) 2010 Dresden University of Technology 
+// All rights reserved.
+// Authors: Simon Vey, Thomas Witkowski et al.
+//
+// This file is part of AMDiS
+//
+// See also license.opensource.txt in the distribution.
+
+
+
+/** \file DofWriter.h */
+
+#ifndef AMDIS_DOF_WRITER_H
+#define AMDIS_DOF_WRITER_H
+
+#include <fstream>
+#include <vector>
+#include "AMDiS_fwd.h"
+#include "FiniteElemSpace.h"
+#include "Mesh.h"
+
+namespace AMDiS {
+
+  class DofWriter
+  {
+  public:
+    DofWriter(const FiniteElemSpace *feSpace)
+      : feSpace(feSpace),
+	mesh(feSpace->getMesh())
+      {}
+
+    void writeFile(std::string filename, std::vector<DOFVector<double>*> &vec);
+
+  protected:
+    const FiniteElemSpace *feSpace;
+
+    Mesh *mesh;
+  };
+}
+
+#endif
diff --git a/AMDiS/src/io/FileWriter.cc b/AMDiS/src/io/FileWriter.cc
index 7783b963..b7f1cdf7 100644
--- a/AMDiS/src/io/FileWriter.cc
+++ b/AMDiS/src/io/FileWriter.cc
@@ -19,6 +19,7 @@
 #include "VtkWriter.h"
 #include "PngWriter.h"
 #include "PovrayWriter.h"
+#include "DofWriter.h"
 #include "FiniteElemSpace.h"
 #include "AdaptInfo.h"
 #include "Flag.h"
@@ -51,7 +52,7 @@ namespace AMDiS {
 
   FileWriter::FileWriter(std::string name_, 
 			 Mesh *mesh_, 
-			 std::vector< DOFVector<double>* > vecs)
+			 std::vector<DOFVector<double>*> vecs)
     : name(name_),
       mesh(mesh_)
   {
@@ -70,7 +71,7 @@ namespace AMDiS {
 
   FileWriter::FileWriter(std::string name_, 
 			 Mesh *mesh_,
-			 DOFVector< WorldVector<double> > *vec)
+			 DOFVector<WorldVector<double> > *vec)
     : name(name_),
       mesh(mesh_)
   {
@@ -156,6 +157,8 @@ namespace AMDiS {
     GET_PARAMETER(0, name + "->Povray camera location", &povrayCameraLocation);
     GET_PARAMETER(0, name + "->Povray camera look_at", &povrayCameraLookAt);
 
+    GET_PARAMETER(0, name + "->DOF format", "%d", &writeDofFormat);
+
     std::string compressionStr = "";
     GET_PARAMETER(0, name + "->compression", &compressionStr);
     if (compressionStr == "gzip" || compressionStr == "gz") {
@@ -268,6 +271,13 @@ namespace AMDiS {
 #endif
     }
 
+
+    if (writeDofFormat) {
+      DofWriter dofWriter(feSpace);
+      dofWriter.writeFile(fn + ".dof", solutionVecs);
+    }
+
+
 #ifdef HAVE_PNG
     if (writePngFormat) {
       PngWriter pngWriter(dataCollectors[0]);
diff --git a/AMDiS/src/io/FileWriter.h b/AMDiS/src/io/FileWriter.h
index c4906cea..b000ae55 100644
--- a/AMDiS/src/io/FileWriter.h
+++ b/AMDiS/src/io/FileWriter.h
@@ -175,6 +175,9 @@ namespace AMDiS {
     /// 0: Don't write Povray scripts; 1: Write Povray scripts
     int writePovrayFormat;
 
+    /// 0: Don't write DOF files; 1: Write DOF files
+    int writeDofFormat;
+
     /// camera position for povray script files
     std::string povrayCameraLocation;
 
@@ -212,7 +215,7 @@ namespace AMDiS {
     const FiniteElemSpace *feSpace;
 
     /// Pointers to the vectors which store the solution.
-    std::vector< DOFVector<double>* > solutionVecs;
+    std::vector<DOFVector<double>*> solutionVecs;
 
     /** \brief
      * Stores the number of temporal solutions vectors, which have been created
-- 
GitLab