VtkWriter.h 6.1 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
79
80
81
82
83
84
85
    static void writeFile(WorldVector<DOFVector<double>*> &values,
			  std::string filename, 
			  bool writeParallel = true);
    static void writeFile(DOFVector<WorldVector<double> > *values,
			  std::string filename, 
			  bool writeParallel = true);
    static void writeFile(DOFVector<WorldVector<double> > &values,
			  std::string filename, 
			  bool writeParallel = true) {
      writeFile(&values, filename, writeParallel);
    }
86
87
88
89
90
91
92
93
    static void writeFile(SystemVector *values,
			  std::string filename, 
			  bool writeParallel = true);

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

94
    /// Set a compressing method for file output.
95
96
    void setCompression(FileCompression c) 
    {
97
98
      compress = c;
    }
99

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

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

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

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

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

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

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

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

143
144
145
      file << "\n";
    }
#endif
146

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

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

  private:
159
    /// List of DataCollectors, for each component of the problem one.
Thomas Witkowski's avatar
Thomas Witkowski committed
160
    std::vector<DataCollector*> *dataCollector;
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
    /// Degree of the basis function of the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
169
    int degree;
170
    
171
    /// Dimension of the geometry.
Thomas Witkowski's avatar
Thomas Witkowski committed
172
    int dim;
173
174
175
  };
}

176
177
#include "VtkWriter.hh"

178
#endif