FileWriter.h 8.1 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

namespace AMDiS {

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

  template<typename T> class DOFVector;

  // ============================================================================
  // ===== 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
73
74
    virtual void writeDelayedFiles() = 0;

Thomas Witkowski's avatar
Thomas Witkowski committed
75
76
    virtual bool isWritingDelayed() = 0;

77
78
79
80
81
82
83
84
85
    void setTraverseProperties(int level, 
			       Flag flag,
			       bool (*writeElem)(ElInfo*))
    {
      traverseLevel = level;
      traverseFlag |= flag;
      writeElement = writeElem;
    };

86
    std::string getFilename() { 
87
88
89
      return filename; 
    };
    
90
    void setFilename(std::string n) { 
91
92
93
94
95
96
97
      filename = n; 
    };

  protected:
    /** \brief
     * Used filename prefix.
     */
98
    std::string filename;
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

    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.
     */
126
    FileWriter(const std::string& name_, 
127
128
129
130
131
132
	       Mesh *mesh_,
	       DOFVector<double> *vec);

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

137
138
139
140
    /** \brief
     * Constructor for a filewriter, when the solution vector is a vector
     * of WorldVectors.
     */
141
    FileWriter(const std::string &name_, 
142
143
144
	       Mesh *mesh_,
	       DOFVector< WorldVector<double> > *vec);

145
146
147
    /** \brief
     * Destructor.
     */
148
    virtual ~FileWriter();
149
150
151
152
153
154
155
156
157

    /** \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
158
159
160
    /** \brief
     * Starts the delayed writing.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
161
162
    virtual void writeDelayedFiles();

Thomas Witkowski's avatar
Thomas Witkowski committed
163
164
165
166
167
168
169
    /** \brief
     * Returns true, if the file writer is waiting to start writing.
     */
    bool isWritingDelayed() {
      return writingIsDelayed_;
    }

170
  protected:
171
172
173
174
175
    /** \brief
     * Initialization of the filewriter.
     */
    void initialize();

176
177
178
179
180
181
182
183
    /** \brief
     *  Reads all file writer dependend parameters from the init file.
     */
    void readParameters();

    /** \brief
     * Name of the writer.
     */
184
    std::string name;
185
186
187
188

    /** \brief
     * TecPlot file extension.
     */
189
    std::string tecplotExt;
190
191
192
193

    /** \brief
     * AMDiS mesh-file extension.
     */
194
    std::string amdisMeshExt;
195
196
197
198

    /** \brief
     * AMDiS solution-file extension.
     */
199
    std::string amdisDataExt;
200
201
202
203

    /** \brief
     * VTK file extension.
     */
204
    std::string paraViewFileExt;
205
206
207
208

    /** \brief
     * Periodic file extension.
     */
209
    std::string periodicFileExt;
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228

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

229
230
231
232
233
234
    /** \brief
     * 0: Don't write ParaView animation file.
     * 1: Write ParaView animation file.
     */
    int writeParaViewAnimation;

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
    /** \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;

262
263
264
    /** \brief
     * Stores all writen filename to a ParaView animation file.
     */
265
    std::vector< std::string > paraViewAnimationFrames_;
266

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
    /**
     */
    int timestepNumber;

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

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

    /** \brief
282
     * Pointers to the vectors which store the solution.
283
     */
284
    std::vector< DOFVector<double>* > solutionVecs_;
285
286
287
288
289
290
291

    /** \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
292
293
294
295

    /** \brief
     * Containers, which store the data to be written;
     */
296
    std::vector< DataCollector* > dataCollectors_;
Thomas Witkowski's avatar
Thomas Witkowski committed
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312

    /** \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.
     */
313
    std::string delayedFilename_;
314
315
316
317
318
  };

}

#endif // AMDIS_FILEWRITER_H