VtkWriter.h 5.47 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20
21
22
23
24
25

/** \file VtkWriter.h */

#ifndef AMDIS_VTKWRITER_H
#define AMDIS_VTKWRITER_H

26
27
28
29
#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>
30

31
#include <fstream>
32
#include "BasisFunction.h"
33
#include "DataCollector.h"
34
#include "FileWriter.h"
35
#include "SystemVector.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
71
72
73
    /// 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);
74

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

178
179
#include "VtkWriter.hh"

180
#endif