FileWriter.h 7.36 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
41
42
43
44
45
46
47

namespace AMDiS {

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

Thomas Witkowski's avatar
Thomas Witkowski committed
51
    virtual ~FileWriterInterface() {}
52
53
54

    /** \brief
     * Interface. Must be overridden in subclasses.
55
     * \param time time index of solution std::vector.
56
57
58
59
60
     * \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,
61
			    bool (*writeElem)(ElInfo*) = NULL) = 0;
62
63
64
65
66
67
68
69

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

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

  protected:
83
    /// Used filename prefix.
84
    std::string filename;
85
86
87
88
89
90
91

    int traverseLevel;

    Flag traverseFlag;

    bool (*writeElement)(ElInfo*);  
  };
92
93
  
  namespace detail
94
  {
95
96
97
98
99
100
101
102
103
104

    /**  
    * \ingroup Output
    *
    * \brief
    * Base class of FileWriterScal and FileWriterVec. Manages the file
    * output of solution vectors.
    */
    template<typename T>
    class FileWriter : public ::AMDiS::FileWriterInterface
105
    {
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
    public:
      /// Constructor for a filewriter for one data component.
      FileWriter(std::string name, Mesh *mesh, DOFVector<T> *vec);

      /// Constructor for a filewriter with more than one data component.
      FileWriter(std::string name,
			  Mesh *mesh,
			  std::vector< DOFVector<T>* > vecs);

      /// Constructor for a filewriter with more than one data component.
      FileWriter(std::string name,
			  Mesh *mesh,
			  SystemVector *vecs);
      
      /// Destructor
      virtual ~FileWriter();

      /// Implementation of FileWriterInterface::writeFiles().
      virtual void writeFiles(AdaptInfo *adaptInfo, bool force,
			      int level = -1,
			      Flag traverseFlag = Mesh::CALL_LEAF_EL,
			      bool (*writeElem)(ElInfo*) = NULL);
    
      std::vector<std::pair<double, std::string> >& getParaviewAnimationFrames()
      {
	return paraviewAnimationFrames;
      }
133

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

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

141
142
      /// Name of the writer.
      std::string name;
143

144
145
      /// AMDiS mesh-file extension.
      std::string amdisMeshExt;
146

147
148
      /// AMDiS solution-file extension.
      std::string amdisDataExt;
149

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

153
154
      /// Parallel VTK file extension.
      std::string paraviewParallelFileExt;
155

156
157
      /// Periodic file extension.
      std::string periodicFileExt;
158

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

162
163
      /// 0: Don't write ParaView files; 1: Write ParaView files.
      int writeParaViewFormat;
164
165
166
167
168
169
      
      /// 0: ASCII mode; 1: Appended mode; 2:Appended_compressed mode.
      int paraViewMode;
      
      /// 0: FLOAT32 precision; 1: FLOAT64 precision. Only works in appended and appended_compressed mode.
      int paraViewPrecision;
170

171
172
      /// 0: Don't write ParaView std::vector files; 1: Write ParaView std::vector files.
      int writeParaViewVectorFormat;
173

174
175
      /// 1: extend number of component to 3, so that paraview can display the std::vector as worldstd::vector
      bool writeAs3dVector;
176

177
178
      /// 0: Don't write ParaView animation file; 1: Write ParaView animation file.
      int writeParaViewAnimation;
179

180
181
      /// 0: Don't write periodic files; 1: Write periodic files.
      int writePeriodicFormat;
182

183
184
      /// 0: Don't write png files; 1: Write png image files.
      int writePngFormat;
185

186
187
      /// 0: Gray color picture; 1: RGB picture.
      int pngType;
188

189
190
      /// 0: Don't write Povray scripts; 1: Write Povray scripts
      int writePovrayFormat;
Thomas Witkowski's avatar
Thomas Witkowski committed
191

192
193
      /// 0: Don't write DOF files; 1: Write DOF files
      int writeDofFormat;
Thomas Witkowski's avatar
Thomas Witkowski committed
194

195
196
      /// 0: Don't write ARH files; 1: Write ARH files
      int writeArhFormat;
197

198
199
      /// 0: Don't write ARH2 files; 1: Write ARH2 files
      int writeArh2Format;
Thomas Witkowski's avatar
Thomas Witkowski committed
200

201
202
      /// camera position for povray script files
      std::string povrayCameraLocation;
Thomas Witkowski's avatar
Thomas Witkowski committed
203

204
205
      /// orientation for camera in povray script files
      std::string povrayCameraLookAt;
Thomas Witkowski's avatar
Thomas Witkowski committed
206

207
208
      /// name of the template file that will be prepended to all created *.pov files 
      std::string povrayTemplate;
209

210
211
212
      /// 0: Don't append time index to filename prefix.
      /// 1: Append time index to filename prefix.
      int appendIndex;
213

214
215
      /// Total length of appended time index.
      int indexLength;
216

217
218
      /// Number of decimals in time index.
      int indexDecimals;
219

220
221
222
223
224
225
      /// Timestep modulo: write only every tsModulo-th timestep! 
      int tsModulo;
      
      /// Time modulo: write at first iteration after lastWriteTime + timeModulo
      double timeModulo;
      double lastWriteTime;
226

227
228
229
      /// Stores a set of std::pairs of timepoint and filename to write a ParaView 
      /// animation file.
      std::vector<std::pair<double, std::string> > paraviewAnimationFrames;
230

231
232
      ///
      int timestepNumber;
233

234
235
      /// Mesh used for output.
      Mesh *mesh;
236

237
238
      /// fespace used for output.
      const FiniteElemSpace *feSpace;
239

240
241
      /// Pointers to the std::vectors which store the solution.
      std::vector<DOFVector<T>*> solutionVecs;
Thomas Witkowski's avatar
Thomas Witkowski committed
242

243
244
245
246
247
248
249
250
251
252
253
254
255
      /** \brief
      * Stores the number of temporal solutions std::vectors, which have been created
      * in the constructor. If this number is greater than zero, the std::vectors
      * stored in solutionVecs_ must be deleted in the destructor.
      */
      int nTmpSolutions;

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

257
258
259
260
261
262
263
264
265
266
267
268
269
    template<>
    FileWriter<double>::FileWriter(std::string name_,
			  Mesh *mesh_,
			  SystemVector *vecs);

    template<>
    void FileWriter<double>::writeFiles(AdaptInfo *adaptInfo,
				bool force,
				int level,
				Flag flag,
				bool (*writeElem)(ElInfo*));
    
  } // end namespace detail
Praetorius, Simon's avatar
Praetorius, Simon committed
270
  
271
272
  typedef detail::FileWriter<double> FileWriter;
  typedef detail::FileWriter<WorldVector<double> > FileVectorWriter;
273
274
}

275
276
#include "FileWriter.hh"

277
#endif // AMDIS_FILEWRITER_H