FileWriter.h 6.64 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
26
27
28
29

/** \file FileWriter.h */

/** \defgroup Output Output module
 * @{ <img src="output.png"> @}
 */

#ifndef AMDIS_FILEWRITER_H
#define AMDIS_FILEWRITER_H

30
#include <vector>
31
#include <string>
Thomas Witkowski's avatar
Thomas Witkowski committed
32
#include "AMDiS_fwd.h"
33
#include "Mesh.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
34
#include "DataCollector.h"
35
36
37

namespace AMDiS {

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

40
41
42
43
44
45
  typedef enum {
    NONE = 0,
    GZIP = 1,
    BZIP2 = 2
  } FileCompression;

46
47
48
49
50
51
52
53
54

  class FileWriterInterface
  {
  public:
    FileWriterInterface()
      : filename(""),
	traverseLevel(-1),
	traverseFlag(Mesh::CALL_LEAF_EL),
	writeElement(NULL)
Thomas Witkowski's avatar
Thomas Witkowski committed
55
    {}
56

Thomas Witkowski's avatar
Thomas Witkowski committed
57
    virtual ~FileWriterInterface() {}
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

    /** \brief
     * Interface. Must be overridden in subclasses.
     * \param time time index of solution vector.
     * \param force enforces the output operation for the last timestep.
     */
    virtual void writeFiles(AdaptInfo *adaptInfo, bool force,
			    int level = -1,
			    Flag traverseFlag = Mesh::CALL_LEAF_EL,
			    bool (*writeElem)(ElInfo*) = NULL) = 0;

    void setTraverseProperties(int level, 
			       Flag flag,
			       bool (*writeElem)(ElInfo*))
    {
      traverseLevel = level;
      traverseFlag |= flag;
      writeElement = writeElem;
Thomas Witkowski's avatar
Thomas Witkowski committed
76
    }
77

Thomas Witkowski's avatar
Thomas Witkowski committed
78
    string getFilename() 
79
    { 
80
      return filename; 
Thomas Witkowski's avatar
Thomas Witkowski committed
81
    }
82
    
Thomas Witkowski's avatar
Thomas Witkowski committed
83
    void setFilename(string n) 
84
    { 
85
      filename = n; 
Thomas Witkowski's avatar
Thomas Witkowski committed
86
    }
87
88

  protected:
89
    /// Used filename prefix.
Thomas Witkowski's avatar
Thomas Witkowski committed
90
    string filename;
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

    int traverseLevel;

    Flag traverseFlag;

    bool (*writeElement)(ElInfo*);  
  };

  /**  
   * \ingroup Output
   *
   * \brief
   * Base class of FileWriterScal and FileWriterVec. Manages the file output
   * of solution vectors.
   */
Praetorius, Simon's avatar
Praetorius, Simon committed
106
107
  template<typename T>
  class FileWriterTemplated : public FileWriterInterface
108
109
  {
  public:
110
    /// Constructor for a filewriter for one data component.
Praetorius, Simon's avatar
Praetorius, Simon committed
111
    FileWriterTemplated(string name, Mesh *mesh, DOFVector<T> *vec);
112

113
    /// Constructor for a filewriter with more than one data component.
Praetorius, Simon's avatar
Praetorius, Simon committed
114
    FileWriterTemplated(string name,
115
	       Mesh *mesh,
Praetorius, Simon's avatar
Praetorius, Simon committed
116
	       vector< DOFVector<T>* > vecs);
117

118
    /// Constructor for a filewriter with more than one data component.
Praetorius, Simon's avatar
Praetorius, Simon committed
119
    FileWriterTemplated(std::string name,
120
121
	       Mesh *mesh,
	       SystemVector *vecs);
122

123
    /// Destructor
Praetorius, Simon's avatar
Praetorius, Simon committed
124
    virtual ~FileWriterTemplated();
125

126
    /// Implementation of FileWriterInterface::writeFiles().
127
128
129
130
131
132
    virtual void writeFiles(AdaptInfo *adaptInfo, bool force,
			    int level = -1,
			    Flag traverseFlag = Mesh::CALL_LEAF_EL,
			    bool (*writeElem)(ElInfo*) = NULL);

  protected:
133
    /// Initialization of the filewriter.
134
135
    void initialize();

136
    /// Reads all file writer dependend parameters from the init file.
137
138
    void readParameters();

139
    /// Name of the writer.
Thomas Witkowski's avatar
Thomas Witkowski committed
140
    string name;
141

142
    /// AMDiS mesh-file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
143
    string amdisMeshExt;
144

145
    /// AMDiS solution-file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
146
    string amdisDataExt;
147

148
    /// VTK file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
149
    string paraviewFileExt;
Thomas Witkowski's avatar
Thomas Witkowski committed
150
151

    /// Parallel VTK file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
152
    string paraviewParallelFileExt;
153

154
    /// Periodic file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
155
    string periodicFileExt;
156

157
    /// 0: Don't write AMDiS files; 1: Write AMDiS files. 
158
159
    int writeAMDiSFormat;

160
    /// 0: Don't write ParaView files; 1: Write ParaView files.
161
162
    int writeParaViewFormat;

163
164
165
    /// 0: Don't write ParaView vector files; 1: Write ParaView vector files.
    int writeParaViewVectorFormat;

166
167
168
    /// 1: extend number of component to 3, so that paraview can display the vector as worldvector
    bool writeAs3dVector;

169
    /// 0: Don't write ParaView animation file; 1: Write ParaView animation file.
170
171
    int writeParaViewAnimation;

172
    /// 0: Don't write periodic files; 1: Write periodic files.
173
174
    int writePeriodicFormat;

175
176
177
    /// 0: Don't write png files; 1: Write png image files.
    int writePngFormat;

178
179
180
    /// 0: Gray color picture; 1: RGB picture.
    int pngType;

Thomas Witkowski's avatar
Thomas Witkowski committed
181
182
183
    /// 0: Don't write Povray scripts; 1: Write Povray scripts
    int writePovrayFormat;

Thomas Witkowski's avatar
Thomas Witkowski committed
184
185
186
    /// 0: Don't write DOF files; 1: Write DOF files
    int writeDofFormat;

187
188
189
    /// 0: Don't write ARH files; 1: Write ARH files
    int writeArhFormat;

Thomas Witkowski's avatar
Thomas Witkowski committed
190
    /// camera position for povray script files
Thomas Witkowski's avatar
Thomas Witkowski committed
191
    string povrayCameraLocation;
Thomas Witkowski's avatar
Thomas Witkowski committed
192
193

    /// orientation for camera in povray script files
Thomas Witkowski's avatar
Thomas Witkowski committed
194
    string povrayCameraLookAt;
Thomas Witkowski's avatar
Thomas Witkowski committed
195
196

    /// name of the template file that will be prepended to all created *.pov files 
Thomas Witkowski's avatar
Thomas Witkowski committed
197
    string povrayTemplate;
Thomas Witkowski's avatar
Thomas Witkowski committed
198

Thomas Witkowski's avatar
Thomas Witkowski committed
199
200
    /// 0: Don't append time index to filename prefix.
    /// 1: Append time index to filename prefix.
201
202
    int appendIndex;

203
    /// Total length of appended time index.
204
205
    int indexLength;

206
    /// Number of decimals in time index.
207
208
    int indexDecimals;

209
    /// Timestep modulo: write only every tsModulo-th timestep! 
210
211
    int tsModulo;

Thomas Witkowski's avatar
Thomas Witkowski committed
212
213
214
    /// Stores a set of pairs of timepoint and filename to write a ParaView 
    /// animation file.
    vector<pair<double, string> > paraviewAnimationFrames;
215

216
    ///
217
218
    int timestepNumber;

219
    /// Mesh used for output.
220
221
    Mesh *mesh;

222
    /// fespace used for output.
223
224
    const FiniteElemSpace *feSpace;

225
    /// Pointers to the vectors which store the solution.
Praetorius, Simon's avatar
Praetorius, Simon committed
226
    vector<DOFVector<T>*> solutionVecs;
227
228
229
230
231
232

    /** \brief
     * Stores the number of temporal solutions vectors, which have been created
     * in the constructor. If this number is greater than zero, the vectors
     * stored in solutionVecs_ must be deleted in the destructor.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
233
    int nTmpSolutions;
Thomas Witkowski's avatar
Thomas Witkowski committed
234

235
236
237
238
239
    /** \brief
     * Defines if, and with what kind of compression, the file should be compressed
     * during writing.
     */
    FileCompression compression;
240
241
  };

Praetorius, Simon's avatar
Praetorius, Simon committed
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
  template<>
  FileWriterTemplated<double>::FileWriterTemplated(std::string name_,
			 Mesh *mesh_,
			 SystemVector *vecs);

  template<>
  void FileWriterTemplated<double>::writeFiles(AdaptInfo *adaptInfo,
			      bool force,
			      int level,
			      Flag flag,
			      bool (*writeElem)(ElInfo*));
  
  typedef FileWriterTemplated<double> FileWriter;
  typedef FileWriterTemplated<WorldVector<double> > FileVectorWriter;

257
258
259
}

#endif // AMDIS_FILEWRITER_H