VtkWriter.h 4.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \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.
Thomas Witkowski's avatar
Thomas Witkowski committed
58
    static void writeFile(DOFVector<double> *values, std::string filename);
59

60
    /// Set a compressing method for file output.
61
62
    void setCompression(FileCompression c) 
    {
63
64
      compress = c;
    }
65

66
    /// Adds a new entry to a ParaView animation file.
Thomas Witkowski's avatar
Thomas Witkowski committed
67
68
    int updateAnimationFile(std::string valueFilename,
			    std::vector< std::string > *paraViewAnimationFrames,
69
			    std::string animationFilename);
70
  protected:
71
    /// Writes the VTK file to an arbitrary stream.
72
    template<typename T>
73
    void writeFileToStream(T &file);
74

75
    /// Writes all coordinates of vertices and interpolation points to an output file.
76
77
    template<typename T>
    void writeVertexCoords(T &file);
78

79
    /// Writes all values of vertices and interpolation point to an output file.
80
81
    template<typename T>
    void writeVertexValues(T &file, int componentNo);
82

83
    /// Writes the connectivity of all simplices to an output file.
84
85
    template<typename T>
    void writeConnectivity(T &file);
86

87
    /// Writes the connectivity for the case dim = 2 and degree = 2 to an output file.
88
89
    template<typename T>
    void writeConnectivity_dim2_degree2(T &file);
90

91
    /// Writes the connectivity for the case dim = 2 and degree = 3 to an output file.
92
93
    template<typename T>
    void writeConnectivity_dim2_degree3(T &file);
94

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

99
#ifdef HAVE_BOOST
100
101
    /// Writes a world coordinate to a given file.
    inline void writeCoord(boost::iostreams::filtering_ostream &file, 
102
103
104
			   WorldVector<double> coord) 
    {
      for (int i = 0; i < Global::getGeo(WORLD); i++)
105
	file << " " << std::scientific << coord[i];
106
      for (int i = Global::getGeo(WORLD); i < 3; i++)
107
	file << " 0.0";
108

109
110
111
      file << "\n";
    }
#endif
112

113
    /// Writes a world coordinate to a given file.
114
115
116
    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
117
	file << " " << std::scientific << coord[i];
118
      for (int i = Global::getGeo(WORLD); i < 3; i++)
119
	file << " 0.0";
120

Thomas Witkowski's avatar
Thomas Witkowski committed
121
      file << "\n";
122
123
124
    }

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

128
129
130
131
132
133
    /** \brief
     * Defines if the file has to be compressed for ouput, and with which
     * kind of compress method.
     */
    FileCompression compress;

134
    /// Degree of the basis function of the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
135
    int degree;
136
    
137
    /// Dimension of the geometry.
Thomas Witkowski's avatar
Thomas Witkowski committed
138
    int dim;
139
140
141
  };
}

142
143
#include "VtkWriter.hh"

144
#endif