VtkWriter.h 5.03 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
50
    };  


51
52
53
    /** \brief
     * Writes a ParaView-VTK file.
     */
54
55
    int writeFile(const char *name);

56

57
    /** \brief
58
     * Set a compressing method for file output.
59
     */
60
61
62
    void setCompression(FileCompression c) {
      compress = c;
    }
63
64
65
66

    /** \brief
     * Adds a new entry to a ParaView animation file.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
67
68
    int updateAnimationFile(std::string valueFilename,
			    std::vector< std::string > *paraViewAnimationFrames,
69
70
			    const char *animationFilename);
  protected:
71
72
73
74
75
76
    /** \brief
     * Writes the VTU file to an arbitrary stream.
     */
    template<typename T>
    void writeFile(T &file);

77
    /** \brief
78
79
     * Writes all coordinates of vertices and interpolation points to an
     * output file.
80
     */
81
82
    template<typename T>
    void writeVertexCoords(T &file);
83
84
85


    /** \brief
86
87
     * Writes all values of vertices and interpolation point to an output 
     * file.
88
     */
89
90
    template<typename T>
    void writeVertexValues(T &file, int componentNo);
91
92
93


    /** \brief
94
     * Writes the connectivity of all simplices to an output file.
95
     */
96
97
    template<typename T>
    void writeConnectivity(T &file);
98
99

    /** \brief
100
101
     * Writes the connectivity for the case dim = 2 and degree = 2 to
     * an output file.
102
     */
103
104
    template<typename T>
    void writeConnectivity_dim2_degree2(T &file);
105
106


107
    /** \brief
108
109
     * Writes the connectivity for the case dim = 2 and degree = 3 to
     * an output file.
110
     */
111
112
    template<typename T>
    void writeConnectivity_dim2_degree3(T &file);
113
114
115


    /** \brief
116
117
     * Writes the connectivity for the case dim = 2 and degree = 4 to
     * an output file.
118
     */
119
120
    template<typename T>
    void writeConnectivity_dim2_degree4(T &file);
121

122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifdef HAVE_BOOST
    /** \brief
     * Writes a world coordinate to a given file.
     */
    inline void writeCoord(boost::iostreams::filtering_ostream &file, WorldVector<double> coord) {
      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
136

137
    /** \brief
138
     * Writes a world coordinate to a given file.
139
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
140
    inline void writeCoord(std::ofstream &file, WorldVector<double> coord) {
141
      for (int i = 0; i < Global::getGeo(WORLD); i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
142
	file << " " << std::scientific << coord[i];
143
144
145
146
      }
      for (int i = Global::getGeo(WORLD); i < 3; i++) {
	file << " 0.0";
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
147
      file << "\n";
148
149
150
    }

  private:
151
    /** \brief
152
     * List of DataCollectors, for each component of the problem one.
153
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
154
    std::vector<DataCollector*> *dataCollector;
155
156


157
158
159
160
161
162
    /** \brief
     * Defines if the file has to be compressed for ouput, and with which
     * kind of compress method.
     */
    FileCompression compress;

163
    /** \brief
164
     * Degree of the basis function of the problem.
165
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
166
    int degree;
167
168
169
    

    /** \brief
170
     * Dimension of the geometry.
171
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
172
    int dim;
173
174
175
  };
}

176
177
#include "VtkWriter.hh"

178
#endif