VtkWriter.h 5.22 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
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

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

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

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

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

70
    /// Set a compressing method for file output.
71
72
    void setCompression(FileCompression c) 
    {
73
74
      compress = c;
    }
75

76
    /// Adds a new entry to a ParaView animation file.
Thomas Witkowski's avatar
Thomas Witkowski committed
77
78
    int updateAnimationFile(std::string valueFilename,
			    std::vector< std::string > *paraViewAnimationFrames,
79
			    std::string animationFilename);
80
  protected:
81
    /// Writes the VTK file to an arbitrary stream.
82
    template<typename T>
83
    void writeFileToStream(T &file);
84

85
    /// Writes all coordinates of vertices and interpolation points to an output file.
86
87
    template<typename T>
    void writeVertexCoords(T &file);
88

89
    /// Writes all values of vertices and interpolation point to an output file.
90
91
    template<typename T>
    void writeVertexValues(T &file, int componentNo);
92

93
    /// Writes the connectivity of all simplices to an output file.
94
95
    template<typename T>
    void writeConnectivity(T &file);
96

97
    /// Writes the connectivity for the case dim = 2 and degree = 2 to an output file.
98
99
    template<typename T>
    void writeConnectivity_dim2_degree2(T &file);
100

101
    /// Writes the connectivity for the case dim = 2 and degree = 3 to an output file.
102
103
    template<typename T>
    void writeConnectivity_dim2_degree3(T &file);
104

105
    /// Writes the connectivity for the case dim = 2 and degree = 4 to an output file.
106
107
    template<typename T>
    void writeConnectivity_dim2_degree4(T &file);
108

109
#ifdef HAVE_BOOST
110
111
    /// Writes a world coordinate to a given file.
    inline void writeCoord(boost::iostreams::filtering_ostream &file, 
112
113
114
			   WorldVector<double> coord) 
    {
      for (int i = 0; i < Global::getGeo(WORLD); i++)
115
	file << " " << std::scientific << coord[i];
116
      for (int i = Global::getGeo(WORLD); i < 3; i++)
117
	file << " 0.0";
118

119
120
121
      file << "\n";
    }
#endif
122

123
    /// Writes a world coordinate to a given file.
124
125
126
    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
127
	file << " " << std::scientific << coord[i];
128
      for (int i = Global::getGeo(WORLD); i < 3; i++)
129
	file << " 0.0";
130

Thomas Witkowski's avatar
Thomas Witkowski committed
131
      file << "\n";
132
133
134
    }

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

138
139
140
141
142
143
    /** \brief
     * Defines if the file has to be compressed for ouput, and with which
     * kind of compress method.
     */
    FileCompression compress;

144
    /// Degree of the basis function of the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
145
    int degree;
146
    
147
    /// Dimension of the geometry.
Thomas Witkowski's avatar
Thomas Witkowski committed
148
    int dim;
149
150
151
  };
}

152
153
#include "VtkWriter.hh"

154
#endif