VtkWriter.h 6.07 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
#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>
29

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

namespace AMDiS {

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
52
53
54
55
    /// 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);

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

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

69
70
71
72
    /// 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);
73

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

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

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

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

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

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

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

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

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

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

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

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

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

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

145
146
      file << "\n";
    }
147

148
    /// Writes a world coordinate to a given file.
149
150
151
    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
152
	file << " " << std::scientific << coord[i];
153
      for (int i = Global::getGeo(WORLD); i < 3; i++)
154
	file << " "<<0.0;
155

Thomas Witkowski's avatar
Thomas Witkowski committed
156
      file << "\n";
157
158
159
    }

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

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

169
    /// Degree of the basis function of the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
170
    int degree;
171
    
172
    /// Dimension of the geometry.
Thomas Witkowski's avatar
Thomas Witkowski committed
173
    int dim;
174
175
176
  };
}

177
178
#include "VtkWriter.hh"

179
#endif