GNUPlotWriter.cc 2.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// 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.


13
14
15
16
17
18
19
20
21
22
23
#include "GNUPlotWriter.h"
#include "FiniteElemSpace.h"
#include "DOFVector.h"
#include "Mesh.h"
#include "ElInfo.h"
#include "Traverse.h"
#include "Global.h"
#include "AdaptInfo.h"

namespace AMDiS {

24
  GNUPlotWriter::GNUPlotWriter(std::string fn,
25
			       FiniteElemSpace *feSpace,
26
			       std::vector<DOFVector<double>*> &dofVectors)
27
28
29
30
31
32
33
    : feSpace_(feSpace),
      dofVectors_(dofVectors),
      filename_(filename)
  {
    filename = fn;
  }

34
35
36

  void GNUPlotWriter::writeFiles(AdaptInfo *adaptInfo, bool force, 
				 int, Flag, bool (*)(ElInfo*))
37
38
39
40
41
  {
    DOFVector<WorldVector<double> > coords(feSpace_, "coords");
    Mesh *mesh = feSpace_->getMesh();
    int dow = Global::getGeo(WORLD);
    const BasisFunction *basFcts = feSpace_->getBasisFcts();
42
43
    int numFcts = basFcts->getNumber();
    DegreeOfFreedom *localDOFs = new DegreeOfFreedom[numFcts];
44
45
46
47
48

    TraverseStack stack;
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, 
					 Mesh::CALL_LEAF_EL | 
					 Mesh::FILL_COORDS);
49
    while (elInfo) {
50
51
52
      basFcts->getLocalIndices(elInfo->getElement(),
			       feSpace_->getAdmin(),
			       localDOFs);
53
      for (int i = 0; i < numFcts; i++)
54
	coords[localDOFs[i]] = elInfo->getCoord(i);
55

56
57
58
      elInfo = stack.traverseNext(elInfo);
    }

59
    delete [] localDOFs;
60
61
62

    FILE *file = NULL;
    if (!(file = fopen(filename_.c_str(), "w")))
63
      ERROR("could not open file %s for writing\n", filename_.c_str());
64
65
66
67
68
69

    fprintf(file, "# line format: time x y z val1[x,y,z] val2[x,y,z] ...\n");

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

    int index, numVecs = static_cast<int>(dofVectors_.size());
70
    for (coordsIt.reset(); !coordsIt.end(); ++coordsIt) {
71
72
      index = coordsIt.getDOFIndex();
      fprintf(file, "%e ", adaptInfo->getTime());
73
      for (int i = 0; i < dow; i++)
74
	fprintf(file, "%e ", (*coordsIt)[i]);
75
      for (int i = 0; i < numVecs; i++)
76
77
78
79
80
81
	fprintf(file, "%e ", (*(dofVectors_[i]))[index]);
      fprintf(file, "\n");
    }
  }

}