VtkWriter.h 6.11 KB
Newer Older
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut fr Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17
18
19
20
21
22
23
24
// ==                                                                        ==
// ============================================================================

/** \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
#include "SystemVector.h"
37
38
39
40
41
42

namespace AMDiS {

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
54
55
56
57
    /// Writes a pvtu file, which contains the links to all the rank files.
    void writeParallelFile(std::string name, int nRanks,
			   std::string fnPrefix, std::string fnPostfix);

58
    /// May be used to simply write ParaView files.
59
60
61
    static void writeFile(DOFVector<double> *values, 
			  std::string filename, 
			  bool writeParallel = true);
62

63
    /// May be used to simply write ParaView files.
64
65
66
    static void writeFile(DOFVector<double> &values, 
			  std::string filename,
			  bool writeParallel = true)
67
    {
68
      writeFile(&values, filename, writeParallel);
69
70
    }

71
72
73
74
    /// May be used to simply write ParaView files with a list of values.
    static void writeFile(std::vector<DOFVector<double>*> &values,
			  std::string filename, 
			  bool writeParallel = true);
75

76
77
78
    static void writeFile(WorldVector<DOFVector<double>*> &values,
			  std::string filename, 
			  bool writeParallel = true);
79

80
81
82
    static void writeFile(DOFVector<WorldVector<double> > *values,
			  std::string filename, 
			  bool writeParallel = true);
83

84
85
    static void writeFile(DOFVector<WorldVector<double> > &values,
			  std::string filename, 
86
87
			  bool writeParallel = true) 
    {
88
89
      writeFile(&values, filename, writeParallel);
    }
90

91
92
93
94
95
96
97
98
    static void writeFile(SystemVector *values,
			  std::string filename, 
			  bool writeParallel = true);

    static void writeFile(std::vector<DataCollector*> &dcList,
			  std::string filename,
			  bool writeParallel = true);

99
    /// Set a compressing method for file output.
100
101
    void setCompression(FileCompression c) 
    {
102
103
      compress = c;
    }
104

105
    /// Adds a new entry to a ParaView animation file.
Thomas Witkowski's avatar
Thomas Witkowski committed
106
107
    int updateAnimationFile(std::string valueFilename,
			    std::vector< std::string > *paraViewAnimationFrames,
108
			    std::string animationFilename);
109
  protected:
110
    /// Writes the VTK file to an arbitrary stream.
111
    template<typename T>
112
    void writeFileToStream(T &file);
113

114
    /// Writes all coordinates of vertices and interpolation points to an output file.
115
116
    template<typename T>
    void writeVertexCoords(T &file);
117

118
    /// Writes all values of vertices and interpolation point to an output file.
119
120
    template<typename T>
    void writeVertexValues(T &file, int componentNo);
121

122
    /// Writes the connectivity of all simplices to an output file.
123
124
    template<typename T>
    void writeConnectivity(T &file);
125

126
    /// Writes the connectivity for the case dim = 2 and degree = 2 to an output file.
127
128
    template<typename T>
    void writeConnectivity_dim2_degree2(T &file);
129

130
    /// Writes the connectivity for the case dim = 2 and degree = 3 to an output file.
131
132
    template<typename T>
    void writeConnectivity_dim2_degree3(T &file);
133

134
    /// Writes the connectivity for the case dim = 2 and degree = 4 to an output file.
135
136
    template<typename T>
    void writeConnectivity_dim2_degree4(T &file);
137

138
#ifdef HAVE_BOOST
139
140
    /// Writes a world coordinate to a given file.
    inline void writeCoord(boost::iostreams::filtering_ostream &file, 
141
142
143
			   WorldVector<double> coord) 
    {
      for (int i = 0; i < Global::getGeo(WORLD); i++)
144
	file << " " << std::scientific << coord[i];
145
      for (int i = Global::getGeo(WORLD); i < 3; i++)
146
	file << " 0.0";
147

148
149
150
      file << "\n";
    }
#endif
151

152
    /// Writes a world coordinate to a given file.
153
154
155
    inline void writeCoord(std::ofstream &file, WorldVector<double> coord) 
    {
      for (int i = 0; i < Global::getGeo(WORLD); i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
156
	file << " " << std::scientific << coord[i];
157
      for (int i = Global::getGeo(WORLD); i < 3; i++)
158
	file << " 0.0";
159

Thomas Witkowski's avatar
Thomas Witkowski committed
160
      file << "\n";
161
162
163
    }

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

167
168
169
170
171
172
    /** \brief
     * Defines if the file has to be compressed for ouput, and with which
     * kind of compress method.
     */
    FileCompression compress;

173
    /// Degree of the basis function of the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
174
    int degree;
175
    
176
    /// Dimension of the geometry.
Thomas Witkowski's avatar
Thomas Witkowski committed
177
    int dim;
178
179
180
  };
}

181
182
#include "VtkWriter.hh"

183
#endif