FileWriter.h 6.26 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
106
107
108

    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:
109
    /// Constructor for a filewriter for one data component.
Thomas Witkowski's avatar
Thomas Witkowski committed
110
    FileWriter(string name, Mesh *mesh, DOFVector<double> *vec);
111

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

117
118
119
120
121
    /// Constructor for a filewriter with more than one data component.
    FileWriter(std::string name,
	       Mesh *mesh,
	       SystemVector *vecs);
    
122
123
124
125
    /** \brief
     * Constructor for a filewriter, when the solution vector is a vector
     * of WorldVectors.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
126
    FileWriter(string name,
127
	       Mesh *mesh,
128
129
	       DOFVector< WorldVector<double> > *vec);

130
    /// Destructor
131
    virtual ~FileWriter();
132

133
    /// Implementation of FileWriterInterface::writeFiles().
134
135
136
137
138
139
    virtual void writeFiles(AdaptInfo *adaptInfo, bool force,
			    int level = -1,
			    Flag traverseFlag = Mesh::CALL_LEAF_EL,
			    bool (*writeElem)(ElInfo*) = NULL);

  protected:
140
    /// Initialization of the filewriter.
141
142
    void initialize();

143
    /// Reads all file writer dependend parameters from the init file.
144
145
    void readParameters();

146
    /// Name of the writer.
Thomas Witkowski's avatar
Thomas Witkowski committed
147
    string name;
148

149
    /// AMDiS mesh-file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
150
    string amdisMeshExt;
151

152
    /// AMDiS solution-file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
153
    string amdisDataExt;
154

155
    /// VTK file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
156
    string paraviewFileExt;
Thomas Witkowski's avatar
Thomas Witkowski committed
157
158

    /// Parallel VTK file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
159
    string paraviewParallelFileExt;
160

161
    /// Periodic file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
162
    string periodicFileExt;
163

164
    /// 0: Don't write AMDiS files; 1: Write AMDiS files. 
165
166
    int writeAMDiSFormat;

167
    /// 0: Don't write ParaView files; 1: Write ParaView files.
168
169
    int writeParaViewFormat;

170
171
172
    /// 0: Don't write ParaView vector files; 1: Write ParaView vector files.
    int writeParaViewVectorFormat;

173
    /// 0: Don't write ParaView animation file; 1: Write ParaView animation file.
174
175
    int writeParaViewAnimation;

176
    /// 0: Don't write periodic files; 1: Write periodic files.
177
178
    int writePeriodicFormat;

179
180
181
    /// 0: Don't write png files; 1: Write png image files.
    int writePngFormat;

182
183
184
    /// 0: Gray color picture; 1: RGB picture.
    int pngType;

Thomas Witkowski's avatar
Thomas Witkowski committed
185
186
187
    /// 0: Don't write Povray scripts; 1: Write Povray scripts
    int writePovrayFormat;

Thomas Witkowski's avatar
Thomas Witkowski committed
188
189
190
    /// 0: Don't write DOF files; 1: Write DOF files
    int writeDofFormat;

191
192
193
    /// 0: Don't write ARH files; 1: Write ARH files
    int writeArhFormat;

Thomas Witkowski's avatar
Thomas Witkowski committed
194
    /// camera position for povray script files
Thomas Witkowski's avatar
Thomas Witkowski committed
195
    string povrayCameraLocation;
Thomas Witkowski's avatar
Thomas Witkowski committed
196
197

    /// orientation for camera in povray script files
Thomas Witkowski's avatar
Thomas Witkowski committed
198
    string povrayCameraLookAt;
Thomas Witkowski's avatar
Thomas Witkowski committed
199
200

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

Thomas Witkowski's avatar
Thomas Witkowski committed
203
204
    /// 0: Don't append time index to filename prefix.
    /// 1: Append time index to filename prefix.
205
206
    int appendIndex;

207
    /// Total length of appended time index.
208
209
    int indexLength;

210
    /// Number of decimals in time index.
211
212
    int indexDecimals;

213
    /// Timestep modulo: write only every tsModulo-th timestep! 
214
215
    int tsModulo;

Thomas Witkowski's avatar
Thomas Witkowski committed
216
217
218
    /// Stores a set of pairs of timepoint and filename to write a ParaView 
    /// animation file.
    vector<pair<double, string> > paraviewAnimationFrames;
219

220
    ///
221
222
    int timestepNumber;

223
    /// Mesh used for output.
224
225
    Mesh *mesh;

226
    /// fespace used for output.
227
228
    const FiniteElemSpace *feSpace;

229
    /// Pointers to the vectors which store the solution.
Thomas Witkowski's avatar
Thomas Witkowski committed
230
    vector<DOFVector<double>*> solutionVecs;
231
232
233
234
235
236

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

239
240
241
242
243
    /** \brief
     * Defines if, and with what kind of compression, the file should be compressed
     * during writing.
     */
    FileCompression compression;
244
245
246
247
248
  };

}

#endif // AMDIS_FILEWRITER_H