GNUPlotWriter.cc 2.56 KB
Newer Older
1 2 3 4 5 6 7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9 10 11 12 13 14 15 16 17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
 ******************************************************************************/
20 21


22 23 24 25 26 27 28 29 30
#include "GNUPlotWriter.h"
#include "FiniteElemSpace.h"
#include "DOFVector.h"
#include "Mesh.h"
#include "ElInfo.h"
#include "Traverse.h"
#include "Global.h"
#include "AdaptInfo.h"

31
using namespace std;
32

33
namespace AMDiS
34 35
{
  namespace io
36
  {
37

38 39 40 41 42 43 44 45 46
    GNUPlotWriter::GNUPlotWriter(std::string fn,
				const FiniteElemSpace *feSpace,
				std::vector<DOFVector<double>*> &dofVectors)
      : feSpace_(feSpace),
	dofVectors_(dofVectors),
	filename_(filename)
    {
      filename = fn;
    }
47

48

49
    void GNUPlotWriter::writeFiles(AdaptInfo *adaptInfo, bool force,
50 51 52 53
				  int, Flag, bool (*)(ElInfo*))
    {
      DOFVector<WorldVector<double> > coords(feSpace_, "coords");
      Mesh *mesh = feSpace_->getMesh();
54

55 56 57 58 59
      double time;
      if (!adaptInfo)
	time = 0.0;
      else
	time = adaptInfo->getTime();
60

61
      mesh->getDofIndexCoords(coords);
62

63 64
      std::ofstream file(filename.c_str(), ios_base::out);
      TEST_EXIT(file.is_open())("could not open file %s for writing\n", filename_.c_str());
65

66
      file.precision(10);
67
      file.setf(std::ios_base::scientific);
68

69
      file << "# line format: time x y z val1[x,y,z] val2[x,y,z] ...\n";
70

71
      DOFVector<WorldVector<double> >::Iterator coordsIt(&coords, USED_DOFS);
72

73 74 75 76 77 78 79 80 81 82 83
      int index, numVecs = static_cast<int>(dofVectors_.size());
      for (coordsIt.reset(); !coordsIt.end(); ++coordsIt) {
	index = coordsIt.getDOFIndex();
	file << time << " ";
	for (int i = 0; i < Global::getGeo(WORLD); i++)
	  file << (*coordsIt)[i] << " ";
	for (int i = 0; i < numVecs; i++)
	  file << (*(dofVectors_[i]))[index] << " ";
	file << "\n";
      }
    }
84

85 86 87

    void GNUPlotWriter::writeFile(std::vector<DOFVector<double>*> &dofVectors,
			  std::string filename,
88 89 90 91
			  AdaptInfo *adaptInfo)
    {
      GNUPlotWriter gnuplotWriter(filename, dofVectors[0]->getFeSpace(), dofVectors);
      gnuplotWriter.writeFiles(adaptInfo, true);
92 93
    }

94 95
  } // end namespace io
} // end namespace AMDiS