FileWriter.h 6.84 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
#include "FileCompression.h"
36
37
38

namespace AMDiS {

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

41
42
43
44
45
46
47
48
  class FileWriterInterface
  {
  public:
    FileWriterInterface()
      : filename(""),
	traverseLevel(-1),
	traverseFlag(Mesh::CALL_LEAF_EL),
	writeElement(NULL)
Thomas Witkowski's avatar
Thomas Witkowski committed
49
    {}
50

Thomas Witkowski's avatar
Thomas Witkowski committed
51
    virtual ~FileWriterInterface() {}
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

    /** \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
70
    }
71

Thomas Witkowski's avatar
Thomas Witkowski committed
72
    string getFilename() 
73
    { 
74
      return filename; 
Thomas Witkowski's avatar
Thomas Witkowski committed
75
    }
76
    
Thomas Witkowski's avatar
Thomas Witkowski committed
77
    void setFilename(string n) 
78
    { 
79
      filename = n; 
Thomas Witkowski's avatar
Thomas Witkowski committed
80
    }
81
82

  protected:
83
    /// Used filename prefix.
Thomas Witkowski's avatar
Thomas Witkowski committed
84
    string filename;
85
86
87
88
89
90
91
92
93
94
95
96

    int traverseLevel;

    Flag traverseFlag;

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

  /**  
   * \ingroup Output
   *
   * \brief
97
98
   * Base class of FileWriterScal and FileWriterVec. Manages the file
   * output of solution vectors.
99
   */
Praetorius, Simon's avatar
Praetorius, Simon committed
100
101
  template<typename T>
  class FileWriterTemplated : public FileWriterInterface
102
103
  {
  public:
104
    /// Constructor for a filewriter for one data component.
Praetorius, Simon's avatar
Praetorius, Simon committed
105
    FileWriterTemplated(string name, Mesh *mesh, DOFVector<T> *vec);
106

107
    /// Constructor for a filewriter with more than one data component.
Praetorius, Simon's avatar
Praetorius, Simon committed
108
    FileWriterTemplated(string name,
109
110
			Mesh *mesh,
			vector< DOFVector<T>* > vecs);
111

112
    /// Constructor for a filewriter with more than one data component.
Praetorius, Simon's avatar
Praetorius, Simon committed
113
    FileWriterTemplated(std::string name,
114
115
116
			Mesh *mesh,
			SystemVector *vecs);
    
117
    /// Destructor
Praetorius, Simon's avatar
Praetorius, Simon committed
118
    virtual ~FileWriterTemplated();
119

120
    /// Implementation of FileWriterInterface::writeFiles().
121
122
123
124
    virtual void writeFiles(AdaptInfo *adaptInfo, bool force,
			    int level = -1,
			    Flag traverseFlag = Mesh::CALL_LEAF_EL,
			    bool (*writeElem)(ElInfo*) = NULL);
125
126
127
128
129
   
    vector<pair<double, string> >& getParaviewAnimationFrames()
    {
      return paraviewAnimationFrames;
    }
130
131

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

208
    /// Timestep modulo: write only every tsModulo-th timestep! 
209
    int tsModulo;
210
211
212
213
    
    /// Time modulo: write at first iteration after lastWriteTime + timeModulo
    double timeModulo;
    double lastWriteTime;
214

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

219
    ///
220
221
    int timestepNumber;

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

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

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

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

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

Praetorius, Simon's avatar
Praetorius, Simon committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
  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;
259
260
}

261
262
#include "FileWriter.hh"

263
#endif // AMDIS_FILEWRITER_H