VtkWriter.h 5.2 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.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
54
    int writeFile(const std::string &name);
55

56
57
58
59
    /** \brief
     * May be used to simply write ParaView files.
     */
    static void writeFile(DOFVector<double> *values,
Thomas Witkowski's avatar
Thomas Witkowski committed
60
			  const std::string &filename);
61

62
    /** \brief
63
     * Set a compressing method for file output.
64
     */
65
66
67
    void setCompression(FileCompression c) {
      compress = c;
    }
68
69
70
71

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

82
    /** \brief
83
84
     * Writes all coordinates of vertices and interpolation points to an
     * output file.
85
     */
86
87
    template<typename T>
    void writeVertexCoords(T &file);
88
89
90


    /** \brief
91
92
     * Writes all values of vertices and interpolation point to an output 
     * file.
93
     */
94
95
    template<typename T>
    void writeVertexValues(T &file, int componentNo);
96
97
98


    /** \brief
99
     * Writes the connectivity of all simplices to an output file.
100
     */
101
102
    template<typename T>
    void writeConnectivity(T &file);
103
104

    /** \brief
105
106
     * Writes the connectivity for the case dim = 2 and degree = 2 to
     * an output file.
107
     */
108
109
    template<typename T>
    void writeConnectivity_dim2_degree2(T &file);
110
111


112
    /** \brief
113
114
     * Writes the connectivity for the case dim = 2 and degree = 3 to
     * an output file.
115
     */
116
117
    template<typename T>
    void writeConnectivity_dim2_degree3(T &file);
118
119
120


    /** \brief
121
122
     * Writes the connectivity for the case dim = 2 and degree = 4 to
     * an output file.
123
     */
124
125
    template<typename T>
    void writeConnectivity_dim2_degree4(T &file);
126

127
128
129
130
131
132
133
134
135
136
137
138
139
140
#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
141

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

  private:
156
    /** \brief
157
     * List of DataCollectors, for each component of the problem one.
158
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
159
    std::vector<DataCollector*> *dataCollector;
160
161


162
163
164
165
166
167
    /** \brief
     * Defines if the file has to be compressed for ouput, and with which
     * kind of compress method.
     */
    FileCompression compress;

168
    /** \brief
169
     * Degree of the basis function of the problem.
170
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
171
    int degree;
172
173
174
    

    /** \brief
175
     * Dimension of the geometry.
176
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
177
    int dim;
178
179
180
  };
}

181
182
#include "VtkWriter.hh"

183
#endif