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

namespace AMDiS {

Thomas Witkowski's avatar
Thomas Witkowski committed
39
40
  using namespace std;

41
42
43
  class VtkWriter
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
44
    VtkWriter(vector<DataCollector*> *dc)
45
46
      : dataCollector(dc),
	compress(NONE)
47
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
48
49
      degree = (*dataCollector)[0]->getFeSpace()->getBasisFcts()->getDegree();    
      dim = (*dataCollector)[0]->getMesh()->getDim();
50
    }  
51

Thomas Witkowski's avatar
Thomas Witkowski committed
52
    /// Writes a ParaView-VTK file.
Thomas Witkowski's avatar
Thomas Witkowski committed
53
    int writeFile(string name);
54

Thomas Witkowski's avatar
Thomas Witkowski committed
55
    /// Writes a pvtu file, which contains the links to all the rank files.
Thomas Witkowski's avatar
Thomas Witkowski committed
56
57
    void writeParallelFile(string name, int nRanks,
			   string fnPrefix, string fnPostfix);
Thomas Witkowski's avatar
Thomas Witkowski committed
58

59
    /// May be used to simply write ParaView files.
60
    static void writeFile(DOFVector<double> *values, 
Thomas Witkowski's avatar
Thomas Witkowski committed
61
			  string filename, 
62
			  bool writeParallel = true);
63

64
    /// May be used to simply write ParaView files.
65
    static void writeFile(DOFVector<double> &values, 
Thomas Witkowski's avatar
Thomas Witkowski committed
66
			  string filename,
67
			  bool writeParallel = true)
68
    {
69
      writeFile(&values, filename, writeParallel);
70
71
    }

72
    /// May be used to simply write ParaView files with a list of values.
Thomas Witkowski's avatar
Thomas Witkowski committed
73
74
    static void writeFile(vector<DOFVector<double>*> &values,
			  string filename, 
75
			  bool writeParallel = true);
76

77
    static void writeFile(WorldVector<DOFVector<double>*> &values,
Thomas Witkowski's avatar
Thomas Witkowski committed
78
			  string filename, 
79
			  bool writeParallel = true);
80

81
    static void writeFile(DOFVector<WorldVector<double> > *values,
Thomas Witkowski's avatar
Thomas Witkowski committed
82
			  string filename, 
83
			  bool writeParallel = true);
84

85
    static void writeFile(DOFVector<WorldVector<double> > &values,
Thomas Witkowski's avatar
Thomas Witkowski committed
86
			  string filename, 
87
88
			  bool writeParallel = true) 
    {
89
90
      writeFile(&values, filename, writeParallel);
    }
91

92
    static void writeFile(SystemVector *values,
Thomas Witkowski's avatar
Thomas Witkowski committed
93
			  string filename, 
94
95
			  bool writeParallel = true);

Thomas Witkowski's avatar
Thomas Witkowski committed
96
97
    static void writeFile(vector<DataCollector*> &dcList,
			  string filename,
98
99
			  bool writeParallel = true);

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

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

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

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

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

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

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

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

140
141
    /// Writes a world coordinate to a given file.
    inline void writeCoord(boost::iostreams::filtering_ostream &file, 
142
143
144
			   WorldVector<double> coord) 
    {
      for (int i = 0; i < Global::getGeo(WORLD); i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
145
	file << " " << scientific << coord[i];
146
      for (int i = Global::getGeo(WORLD); i < 3; i++)
147
	file << " "<<0.0;
148

149
150
      file << "\n";
    }
151

152
    /// Writes a world coordinate to a given file.
Thomas Witkowski's avatar
Thomas Witkowski committed
153
    inline void writeCoord(ofstream &file, WorldVector<double> coord) 
154
155
    {
      for (int i = 0; i < Global::getGeo(WORLD); i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
156
	file << " " << scientific << coord[i];
157
      for (int i = Global::getGeo(WORLD); i < 3; i++)
158
	file << " "<<0.0;
159

Thomas Witkowski's avatar
Thomas Witkowski committed
160
      file << "\n";
161
162
163
    }

  private:
164
    /// List of DataCollectors, for each component of the problem one.
Thomas Witkowski's avatar
Thomas Witkowski committed
165
    vector<DataCollector*> *dataCollector;
166

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

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

181
182
#include "VtkWriter.hh"

183
#endif