FileWriter.h 5.88 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 {

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

44
45
46
47
48
49
50
51
52

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

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

    /** \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
74
    }
75

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

  protected:
87
    /// Used filename prefix.
88
    std::string filename;
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

    int traverseLevel;

    Flag traverseFlag;

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

  /**  
   * \ingroup Output
   *
   * \brief
   * Base class of FileWriterScal and FileWriterVec. Manages the file output
   * of solution vectors.
   */
  class FileWriter : public FileWriterInterface
  {
  public:
107
    /// Constructor for a filewriter for one data component.
Thomas Witkowski's avatar
Thomas Witkowski committed
108
    FileWriter(std::string name, Mesh *mesh, DOFVector<double> *vec);
109

110
    /// Constructor for a filewriter with more than one data component.
Thomas Witkowski's avatar
Thomas Witkowski committed
111
    FileWriter(std::string name, 
112
	       Mesh *mesh,
113
	       std::vector< DOFVector<double>* > vecs);
114

115
116
117
118
    /** \brief
     * Constructor for a filewriter, when the solution vector is a vector
     * of WorldVectors.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
119
    FileWriter(std::string name,
120
	       Mesh *mesh,
121
122
	       DOFVector< WorldVector<double> > *vec);

123
    /// Destructor
124
    virtual ~FileWriter();
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.
140
    std::string name;
141

142
    /// AMDiS mesh-file extension.
143
    std::string amdisMeshExt;
144

145
    /// AMDiS solution-file extension.
146
    std::string amdisDataExt;
147

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

    /// Parallel VTK file extension.
    std::string paraviewParallelFileExt;
153

154
    /// Periodic file extension.
155
    std::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
    /// 0: Don't write ParaView animation file; 1: Write ParaView animation file.
164
165
    int writeParaViewAnimation;

166
    /// 0: Don't write periodic files; 1: Write periodic files.
167
168
    int writePeriodicFormat;

169
170
171
    /// 0: Don't write png files; 1: Write png image files.
    int writePngFormat;

172
173
174
    /// 0: Gray color picture; 1: RGB picture.
    int pngType;

Thomas Witkowski's avatar
Thomas Witkowski committed
175
176
177
178
179
180
181
182
183
184
185
186
    /// 0: Don't write Povray scripts; 1: Write Povray scripts
    int writePovrayFormat;

    /// camera position for povray script files
    std::string povrayCameraLocation;

    /// orientation for camera in povray script files
    std::string povrayCameraLookAt;

    /// name of the template file that will be prepended to all created *.pov files 
    std::string povrayTemplate;

187
188
189
190
191
192
    /** \brief
     * 0: Don't append time index to filename prefix.
     * 1: Append time index to filename prefix.
     */
    int appendIndex;

193
    /// Total length of appended time index.
194
195
    int indexLength;

196
    /// Number of decimals in time index.
197
198
    int indexDecimals;

199
    /// Timestep modulo: write only every tsModulo-th timestep! 
200
201
    int tsModulo;

202
    /// Stores all writen filename to a ParaView animation file.
Thomas Witkowski's avatar
Thomas Witkowski committed
203
    std::vector< std::string > paraviewAnimationFrames;
204

205
    ///
206
207
    int timestepNumber;

208
    /// Mesh used for output.
209
210
    Mesh *mesh;

211
    /// fespace used for output.
212
213
    const FiniteElemSpace *feSpace;

214
    /// Pointers to the vectors which store the solution.
Thomas Witkowski's avatar
Thomas Witkowski committed
215
    std::vector< DOFVector<double>* > solutionVecs;
216
217
218
219
220
221

    /** \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
222
    int nTmpSolutions;
Thomas Witkowski's avatar
Thomas Witkowski committed
223

224
225
226
227
228
    /** \brief
     * Defines if, and with what kind of compression, the file should be compressed
     * during writing.
     */
    FileCompression compression;
229
230
231
232
233
  };

}

#endif // AMDIS_FILEWRITER_H