VtkWriter.h 5.67 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
75
76
77
78
79
80
81
82
    /// 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);
    static void writeFile(SystemVector *values,
			  std::string filename, 
			  bool writeParallel = true);

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

83
    /// Set a compressing method for file output.
84
85
    void setCompression(FileCompression c) 
    {
86
87
      compress = c;
    }
88

89
    /// Adds a new entry to a ParaView animation file.
Thomas Witkowski's avatar
Thomas Witkowski committed
90
91
    int updateAnimationFile(std::string valueFilename,
			    std::vector< std::string > *paraViewAnimationFrames,
92
			    std::string animationFilename);
93
  protected:
94
    /// Writes the VTK file to an arbitrary stream.
95
    template<typename T>
96
    void writeFileToStream(T &file);
97

98
    /// Writes all coordinates of vertices and interpolation points to an output file.
99
100
    template<typename T>
    void writeVertexCoords(T &file);
101

102
    /// Writes all values of vertices and interpolation point to an output file.
103
104
    template<typename T>
    void writeVertexValues(T &file, int componentNo);
105

106
    /// Writes the connectivity of all simplices to an output file.
107
108
    template<typename T>
    void writeConnectivity(T &file);
109

110
    /// Writes the connectivity for the case dim = 2 and degree = 2 to an output file.
111
112
    template<typename T>
    void writeConnectivity_dim2_degree2(T &file);
113

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

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

122
#ifdef HAVE_BOOST
123
124
    /// Writes a world coordinate to a given file.
    inline void writeCoord(boost::iostreams::filtering_ostream &file, 
125
126
127
			   WorldVector<double> coord) 
    {
      for (int i = 0; i < Global::getGeo(WORLD); i++)
128
	file << " " << std::scientific << coord[i];
129
      for (int i = Global::getGeo(WORLD); i < 3; i++)
130
	file << " 0.0";
131

132
133
134
      file << "\n";
    }
#endif
135

136
    /// Writes a world coordinate to a given file.
137
138
139
    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
140
	file << " " << std::scientific << coord[i];
141
      for (int i = Global::getGeo(WORLD); i < 3; i++)
142
	file << " 0.0";
143

Thomas Witkowski's avatar
Thomas Witkowski committed
144
      file << "\n";
145
146
147
    }

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

151
152
153
154
155
156
    /** \brief
     * Defines if the file has to be compressed for ouput, and with which
     * kind of compress method.
     */
    FileCompression compress;

157
    /// Degree of the basis function of the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
158
    int degree;
159
    
160
    /// Dimension of the geometry.
Thomas Witkowski's avatar
Thomas Witkowski committed
161
    int dim;
162
163
164
  };
}

165
166
#include "VtkWriter.hh"

167
#endif