VtkWriter.h 4.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file VtkWriter.h */

#ifndef AMDIS_VTKWRITER_H
#define AMDIS_VTKWRITER_H

25
26
27
28
29
30
#ifdef HAVE_BOOST
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#endif
31

32
#include <fstream>
33
#include "BasisFunction.h"
34
#include "DataCollector.h"
35
#include "FileWriter.h"
36
37
38
39
40
41

namespace AMDiS {

  class VtkWriter
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
42
    VtkWriter(std::vector<DataCollector*> *dc)
43
44
      : dataCollector(dc),
	compress(NONE)
45
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
46
47
      degree = (*dataCollector)[0]->getFeSpace()->getBasisFcts()->getDegree();    
      dim = (*dataCollector)[0]->getMesh()->getDim();
48
    }  
49

Thomas Witkowski's avatar
Thomas Witkowski committed
50
    /// Writes a ParaView-VTK file.
51
    int writeFile(const std::string name);
52

53
    /// May be used to simply write ParaView files.
54
    static void writeFile(DOFVector<double> *values,
55
			  const char *filename);
56

57
    /// Set a compressing method for file output.
58
59
60
    void setCompression(FileCompression c) {
      compress = c;
    }
61

62
    /// Adds a new entry to a ParaView animation file.
Thomas Witkowski's avatar
Thomas Witkowski committed
63
64
    int updateAnimationFile(std::string valueFilename,
			    std::vector< std::string > *paraViewAnimationFrames,
65
			    std::string animationFilename);
66
  protected:
67
    /// Writes the VTK file to an arbitrary stream.
68
    template<typename T>
69
    void writeFileToStream(T &file);
70

71
    /// Writes all coordinates of vertices and interpolation points to an output file.
72
73
    template<typename T>
    void writeVertexCoords(T &file);
74

75
    /// Writes all values of vertices and interpolation point to an output file.
76
77
    template<typename T>
    void writeVertexValues(T &file, int componentNo);
78

79
    /// Writes the connectivity of all simplices to an output file.
80
81
    template<typename T>
    void writeConnectivity(T &file);
82

83
    /// Writes the connectivity for the case dim = 2 and degree = 2 to an output file.
84
85
    template<typename T>
    void writeConnectivity_dim2_degree2(T &file);
86

87
    /// Writes the connectivity for the case dim = 2 and degree = 3 to an output file.
88
89
    template<typename T>
    void writeConnectivity_dim2_degree3(T &file);
90

91
    /// Writes the connectivity for the case dim = 2 and degree = 4 to an output file.
92
93
    template<typename T>
    void writeConnectivity_dim2_degree4(T &file);
94

95
#ifdef HAVE_BOOST
96
97
98
    /// Writes a world coordinate to a given file.
    inline void writeCoord(boost::iostreams::filtering_ostream &file, 
			   WorldVector<double> coord) {
99
100
101
102
103
104
105
106
107
      for (int i = 0; i < Global::getGeo(WORLD); i++) {
	file << " " << std::scientific << coord[i];
      }
      for (int i = Global::getGeo(WORLD); i < 3; i++) {
	file << " 0.0";
      }
      file << "\n";
    }
#endif
108

109
    /// Writes a world coordinate to a given file.
Thomas Witkowski's avatar
Thomas Witkowski committed
110
    inline void writeCoord(std::ofstream &file, WorldVector<double> coord) {
111
      for (int i = 0; i < Global::getGeo(WORLD); i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
112
	file << " " << std::scientific << coord[i];
113
114
115
116
      }
      for (int i = Global::getGeo(WORLD); i < 3; i++) {
	file << " 0.0";
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
117
      file << "\n";
118
119
120
    }

  private:
121
    /// List of DataCollectors, for each component of the problem one.
Thomas Witkowski's avatar
Thomas Witkowski committed
122
    std::vector<DataCollector*> *dataCollector;
123

124
125
126
127
128
129
    /** \brief
     * Defines if the file has to be compressed for ouput, and with which
     * kind of compress method.
     */
    FileCompression compress;

130
    /// Degree of the basis function of the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
131
    int degree;
132
    
133
    /// Dimension of the geometry.
Thomas Witkowski's avatar
Thomas Witkowski committed
134
    int dim;
135
136
137
  };
}

138
139
#include "VtkWriter.hh"

140
#endif