ValueWriter.cc 3.48 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
#include <list>
#include <vector>
#include <fstream>
25
#include <algorithm>
Thomas Witkowski's avatar
Thomas Witkowski committed
26
#include <cstring>
27 28 29 30 31 32

#include "ValueWriter.h"
#include "DOFVector.h"
#include "DOFAdmin.h"
#include "ElInfo.h"
#include "BasisFunction.h"
33
#include "DataCollector.h"
34

35
namespace AMDiS { namespace io {
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  namespace ValueWriter
  {
    using namespace std;

    void writeValues(DataCollector<> *dc, std::string filename,
		    double time, int level,
		    Flag traverseFlag,
		    bool (*writeElem)(ElInfo*))
    {
      FUNCNAME("writeValues()");

      TEST_EXIT(dc)("no data collector\n");

      ofstream file(filename.c_str(), ios_base::out);

      file << "mesh name: " << dc->getMesh()->getName() << endl << endl;
      file << "time: " << std::scientific << time << endl << endl;
      file << "number of values: 1" << endl << endl;
      file << "value description: " << dc->getValues()->getName() << endl;
      file << "number of interpolation points: " << dc->getNumberInterpPoints()
	  << endl;
      file << "type: scalar" << endl;
      file << "interpolation type: lagrange" << endl;
      file << "interpolation degree: " << dc->getFeSpace()->getBasisFcts()->getDegree()
	  << endl;
      file << "end of description: " << dc->getValues()->getName()
63
	  << endl << endl;
64 65 66 67

      /* ----- write vertex values -----*/
      DOFVector<int>::Iterator intPointIt(dc->getInterpPointInd(), USED_DOFS);
      DOFVector<double>::Iterator valueIt(dc->getValues(), USED_DOFS);
68
      DOFVector< list<WorldVector<double> > >::Iterator
69 70 71 72 73 74
	coordIt(dc->getDofCoords(), USED_DOFS);


      file << "vertex values: " << dc->getValues()->getName() << endl;

      for (intPointIt.reset(), valueIt.reset(), coordIt.reset();
75
	  !intPointIt.end();
76 77 78 79 80 81 82 83
	  ++intPointIt, ++valueIt, ++coordIt) {

	  if (*intPointIt == -2) {
	    for (int i = 0; i < (int) coordIt->size(); i++) {
	      file << std::scientific << *valueIt << endl;
	    }
	  }
	}
84

85
      file << endl << endl;
86

87 88
      /* ----- write interpolation values ----- */
      file << "interpolation values: " << dc->getValues()->getName() << endl;
89

90
      for (intPointIt.reset(), valueIt.reset();
91
	  !intPointIt.end();
92
	  ++intPointIt, ++valueIt) {
93

94 95
	  if (*intPointIt >= 0) {
	    file << std::scientific << *valueIt << endl;
96 97 98
	  }
	}

99
      file << endl << endl;
100

101 102
      /* ----- write interpolation points for each simplex */
      file << "element interpolation points: " << dc->getValues()->getName() << endl;
103

104 105 106
      vector< vector<int> >* interpPoints = dc->getInterpPoints();
      vector< vector<int> >::iterator it1;
      vector<int>::iterator it2;
107

108 109 110
      for (it1 = interpPoints->begin(); it1 != interpPoints->end(); ++it1) {
	for (it2 = it1->begin(); it2 != it1->end(); ++it2) {
	  file << (*it2) << " ";
111
	}
112
	file << endl;
113
      }
114

115
      file << endl;
116

117
      file.close();
118 119
    }

120 121
  } // end namespace ValueWriter
} } // end namespace io, AMDiS