FileWriter.h 8.22 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file FileWriter.h */

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

#ifndef AMDIS_FILEWRITER_H
#define AMDIS_FILEWRITER_H

29
#include <vector>
30
31
32
33
#include <string>
#include "MemoryManager.h"
#include "MatrixVector.h"
#include "Mesh.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
34
#include "DataCollector.h"
35
36
37
38
39
40
41
42
43
44
45
46

namespace AMDiS {

  class ProblemScal;
  class ProblemInstat;
  class Mesh;
  class SystemVector;
  class FiniteElemSpace;
  class AdaptInfo;

  template<typename T> class DOFVector;

47
48
49
50
51
52
53

  typedef enum {
    NONE = 0,
    GZIP = 1,
    BZIP2 = 2
  } FileCompression;

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  // ============================================================================
  // ===== class FileWriterInterface ============================================
  // ============================================================================

  class FileWriterInterface
  {
  public:
    FileWriterInterface()
      : filename(""),
	traverseLevel(-1),
	traverseFlag(Mesh::CALL_LEAF_EL),
	writeElement(NULL)
    {};

    virtual ~FileWriterInterface() {};

    /** \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;

Thomas Witkowski's avatar
Thomas Witkowski committed
80
81
    virtual void writeDelayedFiles() = 0;

Thomas Witkowski's avatar
Thomas Witkowski committed
82
83
    virtual bool isWritingDelayed() = 0;

84
85
86
87
88
89
90
91
92
    void setTraverseProperties(int level, 
			       Flag flag,
			       bool (*writeElem)(ElInfo*))
    {
      traverseLevel = level;
      traverseFlag |= flag;
      writeElement = writeElem;
    };

93
    std::string getFilename() { 
94
95
96
      return filename; 
    };
    
97
    void setFilename(std::string n) { 
98
99
100
101
102
103
104
      filename = n; 
    };

  protected:
    /** \brief
     * Used filename prefix.
     */
105
    std::string filename;
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

    int traverseLevel;

    Flag traverseFlag;

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

  // ============================================================================
  // ===== class FileWriter =====================================================
  // ============================================================================

  /**  
   * \ingroup Output
   *
   * \brief
   * Base class of FileWriterScal and FileWriterVec. Manages the file output
   * of solution vectors.
   */
  class FileWriter : public FileWriterInterface
  {
  public:
    MEMORY_MANAGED(FileWriter);

    /** \brief
     * Constructor for a filewriter for one data component.
     */
133
    FileWriter(const std::string& name_, 
134
135
136
137
138
139
	       Mesh *mesh_,
	       DOFVector<double> *vec);

    /** \brief
     * Constructor for a filewriter with more than one data component.
     */
140
    FileWriter(const std::string& name_,
141
	       Mesh *mesh_,
142
	       std::vector< DOFVector<double>* > vecs);
143

144
145
146
147
    /** \brief
     * Constructor for a filewriter, when the solution vector is a vector
     * of WorldVectors.
     */
148
    FileWriter(const std::string &name_, 
149
150
151
	       Mesh *mesh_,
	       DOFVector< WorldVector<double> > *vec);

152
153
154
    /** \brief
     * Destructor.
     */
155
    virtual ~FileWriter();
156
157
158
159
160
161
162
163
164

    /** \brief
     * Implementation of FileWriterInterface::writeFiles().
     */
    virtual void writeFiles(AdaptInfo *adaptInfo, bool force,
			    int level = -1,
			    Flag traverseFlag = Mesh::CALL_LEAF_EL,
			    bool (*writeElem)(ElInfo*) = NULL);

Thomas Witkowski's avatar
Thomas Witkowski committed
165
166
167
    /** \brief
     * Starts the delayed writing.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
168
169
    virtual void writeDelayedFiles();

Thomas Witkowski's avatar
Thomas Witkowski committed
170
171
172
173
174
175
176
    /** \brief
     * Returns true, if the file writer is waiting to start writing.
     */
    bool isWritingDelayed() {
      return writingIsDelayed_;
    }

177
  protected:
178
179
180
181
182
    /** \brief
     * Initialization of the filewriter.
     */
    void initialize();

183
184
185
186
187
188
189
190
    /** \brief
     *  Reads all file writer dependend parameters from the init file.
     */
    void readParameters();

    /** \brief
     * Name of the writer.
     */
191
    std::string name;
192
193
194
195

    /** \brief
     * TecPlot file extension.
     */
196
    std::string tecplotExt;
197
198
199
200

    /** \brief
     * AMDiS mesh-file extension.
     */
201
    std::string amdisMeshExt;
202
203
204
205

    /** \brief
     * AMDiS solution-file extension.
     */
206
    std::string amdisDataExt;
207
208
209
210

    /** \brief
     * VTK file extension.
     */
211
    std::string paraViewFileExt;
212
213
214
215

    /** \brief
     * Periodic file extension.
     */
216
    std::string periodicFileExt;
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235

    /** \brief
     * 0: Don't write TecPlot files.
     * 1: Write TecPlot files. 
     */
    int writeTecPlotFormat;

    /** \brief
     * 0: Don't write AMDiS files.
     * 1: Write AMDiS files. 
     */
    int writeAMDiSFormat;

    /** \brief
     * 0: Don't write ParaView files.
     * 1: Write ParaView files.
     */
    int writeParaViewFormat;

236
237
238
239
240
241
    /** \brief
     * 0: Don't write ParaView animation file.
     * 1: Write ParaView animation file.
     */
    int writeParaViewAnimation;

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
    /** \brief
     * 0: Don't write periodic files.
     * 1: Write periodic files.
     */
    int writePeriodicFormat;

    /** \brief
     * 0: Don't append time index to filename prefix.
     * 1: Append time index to filename prefix.
     */
    int appendIndex;

    /** \brief
     * Total length of appended time index.
     */
    int indexLength;

    /** \brief
     * Number of decimals in time index.
     */
    int indexDecimals;

    /** \brief
     * Timestep modulo: write only every tsModulo-th timestep! 
     */
    int tsModulo;

269
270
271
    /** \brief
     * Stores all writen filename to a ParaView animation file.
     */
272
    std::vector< std::string > paraViewAnimationFrames_;
273

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
    /**
     */
    int timestepNumber;

    /** \brief
     * Mesh used for output.
     */
    Mesh *mesh;

    /** \brief
     * fespace used for output.
     */
    const FiniteElemSpace *feSpace;

    /** \brief
289
     * Pointers to the vectors which store the solution.
290
     */
291
    std::vector< DOFVector<double>* > solutionVecs_;
292
293
294
295
296
297
298

    /** \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.
     */
    int nTmpSolutions_;
Thomas Witkowski's avatar
Thomas Witkowski committed
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

    /** \brief
     * If set to 1, the FileWriter will delay the file writing to the future, where
     * it can be executed in parallel with some other independent calculations.
     */
    int delayWriting_;

    /** \brief
     * If set to true, the FileWriter was filled with data, but the Files are currently
     * not written to disk.
     */
    bool writingIsDelayed_;

    /** \brief
     * Here the filename for the file, which should be written to the next, is stored.
     */
315
    std::string delayedFilename_;
316
317
318
319
320
321

    /** \brief
     * Defines if, and with what kind of compression, the file should be compressed
     * during writing.
     */
    FileCompression compression;
322
323
324
325
326
  };

}

#endif // AMDIS_FILEWRITER_H