FileWriter.h 6.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20
21


22
23
24
25
26
27
28
29
30
31

/** \file FileWriter.h */

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

#ifndef AMDIS_FILEWRITER_H
#define AMDIS_FILEWRITER_H

32
#include <vector>
33
#include <string>
Thomas Witkowski's avatar
Thomas Witkowski committed
34
#include "AMDiS_fwd.h"
35
#include "Mesh.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
36
#include "DataCollector.h"
37
#include "FileCompression.h"
38
39
40

namespace AMDiS {

Thomas Witkowski's avatar
Thomas Witkowski committed
41
42
  using namespace std;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
53
    virtual ~FileWriterInterface() {}
54
55
56
57
58
59
60
61
62

    /** \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,
63
			    bool (*writeElem)(ElInfo*) = nullptr) = 0;
64
65
66
67
68
69
70
71

    void setTraverseProperties(int level, 
			       Flag flag,
			       bool (*writeElem)(ElInfo*))
    {
      traverseLevel = level;
      traverseFlag |= flag;
      writeElement = writeElem;
Thomas Witkowski's avatar
Thomas Witkowski committed
72
    }
73

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

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

    int traverseLevel;

    Flag traverseFlag;

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

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

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

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

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

  protected:
134
    /// Initialization of the filewriter.
135
136
    void initialize();

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

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

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

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

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

    /// Parallel VTK file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
153
    string paraviewParallelFileExt;
154

155
    /// Periodic file extension.
Thomas Witkowski's avatar
Thomas Witkowski committed
156
    string periodicFileExt;
157

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

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

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

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

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

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

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

179
180
181
    /// 0: Gray color picture; 1: RGB picture.
    int pngType;

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

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

188
189
190
    /// 0: Don't write ARH files; 1: Write ARH files
    int writeArhFormat;

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

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

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

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

204
    /// Total length of appended time index.
205
206
    int indexLength;

207
    /// Number of decimals in time index.
208
209
    int indexDecimals;

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

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

221
    ///
222
223
    int timestepNumber;

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

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

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

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

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

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

263
264
#include "FileWriter.hh"

265
#endif // AMDIS_FILEWRITER_H