FileWriter.h 6.59 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
125
126
    virtual void writeFiles(AdaptInfo *adaptInfo, bool force,
			    int level = -1,
			    Flag traverseFlag = Mesh::CALL_LEAF_EL,
			    bool (*writeElem)(ElInfo*) = NULL);

  protected:
127
    /// Initialization of the filewriter.
128
129
    void initialize();

130
    /// Reads all file writer dependend parameters from the init file.
131
132
    void readParameters();

133
    /// Name of the writer.
Thomas Witkowski's avatar
Thomas Witkowski committed
134
    string name;
135

136
    /// AMDiS mesh-file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
137
    string amdisMeshExt;
138

139
    /// AMDiS solution-file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
140
    string amdisDataExt;
141

142
    /// VTK file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
143
    string paraviewFileExt;
Thomas Witkowski's avatar
Thomas Witkowski committed
144
145

    /// Parallel VTK file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
146
    string paraviewParallelFileExt;
147

148
    /// Periodic file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
149
    string periodicFileExt;
150

151
    /// 0: Don't write AMDiS files; 1: Write AMDiS files. 
152
153
    int writeAMDiSFormat;

154
    /// 0: Don't write ParaView files; 1: Write ParaView files.
155
156
    int writeParaViewFormat;

157
158
159
    /// 0: Don't write ParaView vector files; 1: Write ParaView vector files.
    int writeParaViewVectorFormat;

160
161
162
    /// 1: extend number of component to 3, so that paraview can display the vector as worldvector
    bool writeAs3dVector;

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
    /// 0: Don't write Povray scripts; 1: Write Povray scripts
    int writePovrayFormat;

Thomas Witkowski's avatar
Thomas Witkowski committed
178
179
180
    /// 0: Don't write DOF files; 1: Write DOF files
    int writeDofFormat;

181
182
183
    /// 0: Don't write ARH files; 1: Write ARH files
    int writeArhFormat;

Thomas Witkowski's avatar
Thomas Witkowski committed
184
    /// camera position for povray script files
Thomas Witkowski's avatar
Thomas Witkowski committed
185
    string povrayCameraLocation;
Thomas Witkowski's avatar
Thomas Witkowski committed
186
187

    /// orientation for camera in povray script files
Thomas Witkowski's avatar
Thomas Witkowski committed
188
    string povrayCameraLookAt;
Thomas Witkowski's avatar
Thomas Witkowski committed
189
190

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

Thomas Witkowski's avatar
Thomas Witkowski committed
193
194
    /// 0: Don't append time index to filename prefix.
    /// 1: Append time index to filename prefix.
195
196
    int appendIndex;

197
    /// Total length of appended time index.
198
199
    int indexLength;

200
    /// Number of decimals in time index.
201
202
    int indexDecimals;

203
    /// Timestep modulo: write only every tsModulo-th timestep! 
204
205
    int tsModulo;

Thomas Witkowski's avatar
Thomas Witkowski committed
206
207
208
    /// Stores a set of pairs of timepoint and filename to write a ParaView 
    /// animation file.
    vector<pair<double, string> > paraviewAnimationFrames;
209

210
    ///
211
212
    int timestepNumber;

213
    /// Mesh used for output.
214
215
    Mesh *mesh;

216
    /// fespace used for output.
217
218
    const FiniteElemSpace *feSpace;

219
    /// Pointers to the vectors which store the solution.
Praetorius, Simon's avatar
Praetorius, Simon committed
220
    vector<DOFVector<T>*> solutionVecs;
221
222
223
224
225
226

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

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

Praetorius, Simon's avatar
Praetorius, Simon committed
236
237
238
239
240
241
242
243
244
245
246
247
248
249
  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;
250
251
}

252
253
#include "FileWriter.hh"

254
#endif // AMDIS_FILEWRITER_H