FileWriter.hh 8.11 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.
 * 
 ******************************************************************************/
Praetorius, Simon's avatar
Praetorius, Simon committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

/** \file FileWriter.hh */

#ifndef AMDIS_FILEWRITER_HH
#define AMDIS_FILEWRITER_HH

#include "boost/lexical_cast.hpp"
#include "FileWriter.h"
#include "Initfile.h"
#include "ValueWriter.h"
#include "MacroWriter.h"
#include "VtkWriter.h"
#include "VtkVectorWriter.h"
#include "PngWriter.h"
#include "PovrayWriter.h"
#include "DofWriter.h"
#include "ArhWriter.h"
37
#include "Arh2Writer.h"
Praetorius, Simon's avatar
Praetorius, Simon committed
38
39
40
41
42
43
#include "FiniteElemSpace.h"
#include "AdaptInfo.h"
#include "Flag.h"
#include "ElInfo.h"
#include "Mesh.h"
#include "SystemVector.h"
44
#include "DataCollector.h"
Praetorius, Simon's avatar
Praetorius, Simon committed
45
46
47
48
49

#if HAVE_PARALLEL_DOMAIN_AMDIS
#include <mpi.h>
#endif

50
51
52
namespace AMDiS
{
  namespace detail
Praetorius, Simon's avatar
Praetorius, Simon committed
53
  {
54
55
56
57
58
59
60
61
62
63
64
65
      
    template<typename T>
    FileWriter<T>::FileWriter(std::string str, Mesh *m, DOFVector<T> *vec)
      : name(str),
	mesh(m)
    {
      initialize();

      feSpace = vec->getFeSpace();

      solutionVecs.resize(1);
      solutionVecs[0] = vec;
Praetorius, Simon's avatar
Praetorius, Simon committed
66
67
      
      solutionNames.push_back(vec->getName());
68
    }
Praetorius, Simon's avatar
Praetorius, Simon committed
69
70


71
72
73
    template<typename T>
    FileWriter<T>::FileWriter(std::string name_,
			  Mesh *mesh_, 
Praetorius, Simon's avatar
Praetorius, Simon committed
74
75
			  std::vector<DOFVector<T>*> vecs,
			  std::vector< std::string > componentNames)
76
      : name(name_),
Praetorius, Simon's avatar
Praetorius, Simon committed
77
78
	mesh(mesh_),
	solutionNames(componentNames)
79
80
81
82
83
84
85
86
87
88
    {
      initialize();

  /** removed by Siqi. Not sure.
  *  for (int i = 0; i < static_cast<int>(vecs.size()); i++)
  *    TEST_EXIT(vecs[0]->getFeSpace() == vecs[i]->getFeSpace())
  *      ("All FeSpace have to be equal!\n");
  */
      feSpace = vecs[0]->getFeSpace();
      solutionVecs = vecs;
Praetorius, Simon's avatar
Praetorius, Simon committed
89
90
91
92
93
      
      if (solutionNames.size() < vecs.size()) {
	for (size_t i = solutionNames.size(); i < vecs.size(); i++)
	  solutionNames.push_back(vecs[i]->getName());
      }
94
    }
Praetorius, Simon's avatar
Praetorius, Simon committed
95
96


97
98
99
100
101
102
103
    template<typename T>
    FileWriter<T>::FileWriter(std::string name_,
			  Mesh *mesh_,
			  SystemVector *vecs)
      : name(name_),
	mesh(mesh_)
    {
104
      ERROR_EXIT("SystemVector contains DOFVectors of type double, so the FileWriter<not double> can not be used!\n");
Praetorius, Simon's avatar
Praetorius, Simon committed
105
106
107
    }


108
109
110
111
112
113
114
115
    template<typename T>
    FileWriter<T>::~FileWriter()
    {
      // Do not forget to delete temporal solution vector, if there have been
      // some created in the constructor.
      if (nTmpSolutions > 0)
	for (int i = 0; i < nTmpSolutions; i++)
	  delete solutionVecs[i]; 
116
    }
117
    
118
119
120
121

    template<typename T>
    void FileWriter<T>::initialize()
    {
122
      multiMesh = false;
123
124
125
126
      amdisMeshExt = ".mesh";
      amdisDataExt = ".dat";
      paraviewFileExt = ".vtu";
      paraviewParallelFileExt = ".pvtu";
127
128
      arhParallelFileExt = ".parh";
      arhTimeFileExt = ".tarh";
129
130
131
      periodicFileExt = ".per";
      writeAMDiSFormat = 0;
      writeParaViewFormat = 0;
132
133
      paraViewMode = 0;
      paraViewPrecision = 0;
134
135
136
137
138
139
140
141
      writeParaViewVectorFormat = 0;
      writeAs3dVector = false;
      writeParaViewAnimation = 0;
      writePeriodicFormat = 0;
      writePngFormat = 0;
      writePovrayFormat = 0;
      writeDofFormat = 0;
      writeArhFormat = 0;
Siqi Ling's avatar
Siqi Ling committed
142
143
144
      writeArh1 = 0;
      writeArh2 = 0;
      writeArh3 = 0;
Siqi Ling's avatar
Siqi Ling committed
145
      writeArhAnimation = 0;
146
147
      pngType = 0;
      nTmpSolutions = 0;
Siqi Ling's avatar
Siqi Ling committed
148
149
      paraviewAnimationFrames.resize(0);
      arhAnimationFrames.resize(0);
150
151
      compression = NONE;

152
      readParameters(name);
Praetorius, Simon's avatar
Praetorius, Simon committed
153
154
155
    }


156
    template<typename T>
157
    void FileWriter<T>::readParameters(std::string name)
158
    {
159
160
      super::readParameters(name);
      
161
162
163
164
      Parameters::get(name + "->AMDiS format", writeAMDiSFormat);
      Parameters::get(name + "->AMDiS mesh ext", amdisMeshExt);
      Parameters::get(name + "->AMDiS data ext", amdisDataExt);
      Parameters::get(name + "->ParaView format", writeParaViewFormat);
165
166
      Parameters::get(name + "->ParaView mode", paraViewMode);
      Parameters::get(name + "->ParaView precision", paraViewPrecision);
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
      Parameters::get(name + "->ParaView vector format", writeParaViewVectorFormat);
      Parameters::get(name + "->write vector as 3d vector", writeAs3dVector);
      Parameters::get(name + "->ParaView animation", writeParaViewAnimation);
      Parameters::get(name + "->ParaView ext", paraviewFileExt);    
      Parameters::get(name + "->Periodic format", writePeriodicFormat);
      Parameters::get(name + "->Periodic ext", periodicFileExt);
      Parameters::get(name + "->PNG format", writePngFormat);
      Parameters::get(name + "->PNG type", pngType);

      Parameters::get(name + "->Povray format", writePovrayFormat);
      Parameters::get(name + "->Povray template", povrayTemplate);
      Parameters::get(name + "->Povray camera location", povrayCameraLocation);
      Parameters::get(name + "->Povray camera look_at", povrayCameraLookAt);

      Parameters::get(name + "->DOF format", writeDofFormat);
      Parameters::get(name + "->ARH format", writeArhFormat);
Siqi Ling's avatar
Siqi Ling committed
183
184
185
      Parameters::get(name + "->ARH1 format", writeArh1);
      Parameters::get(name + "->ARH2 format", writeArh2);
      Parameters::get(name + "->ARH3 format", writeArh3);
Siqi Ling's avatar
Siqi Ling committed
186
      Parameters::get(name + "->Arh animation", writeArhAnimation);
187
188
189
190
191
192
193
194
195

      std::string compressionStr = "";
      Parameters::get(name + "->compression", compressionStr);
      if (compressionStr == "gzip" || compressionStr == "gz") {
	compression = GZIP;
      } else if (compressionStr == "bzip2" || compressionStr == "bz2") {
	compression = BZIP2;
      }
    }
Praetorius, Simon's avatar
Praetorius, Simon committed
196
197


198
199
200
201
202
203
204
205
206
    template<typename T>
    void FileWriter<T>::writeFiles(AdaptInfo *adaptInfo,
					    bool force,
					    int level,
					    Flag flag,
					    bool (*writeElem)(ElInfo*))
    {
      FUNCNAME("FileWriter<T>::writeFiles()");

207
208
      if (!super::doWriteTimestep(adaptInfo, force))
	return;
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
      
      // Containers, which store the data to be written;
      std::vector<DataCollector<T>*> dataCollectors(solutionVecs.size());
      
      if (writeElem) {
	for (int i = 0; i < static_cast<int>(dataCollectors.size()); i++)
	  dataCollectors[i] = new DataCollector<T>(feSpace, solutionVecs[i], 
						  level, flag, writeElem);
      } else {
	for (int i = 0; i < static_cast<int>(dataCollectors.size()); i++)
	  dataCollectors[i] = new DataCollector<T>(feSpace, solutionVecs[i], 
						  traverseLevel, 
						  flag | traverseFlag, 
						  writeElement);
      }
      
225
     std::string fn, fn2;
226
227
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
      std::string paraFilename, postfix;
228
      super::getFilename(adaptInfo, fn, fn2, paraFilename, postfix);
229
230
231
232
      postfix += paraviewFileExt;
#else
      super::getFilename(adaptInfo, fn);
#endif
Praetorius, Simon's avatar
Praetorius, Simon committed
233

234
235
236
237
      if (writeParaViewVectorFormat) {
	io::VtkVectorWriter::Aux<T> vtkVectorWriter(&dataCollectors, writeAs3dVector);
#ifdef HAVE_COMPRESSION
	vtkVectorWriter.setCompression(compression);
Praetorius, Simon's avatar
Praetorius, Simon committed
238
#endif
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
	vtkVectorWriter.writeFile(fn + paraviewFileExt);

  #if HAVE_PARALLEL_DOMAIN_AMDIS
	if (MPI::COMM_WORLD.Get_rank() == 0)
	  vtkVectorWriter.writeParallelFile(paraFilename + paraviewParallelFileExt,
					    MPI::COMM_WORLD.Get_size(),
					    filename, postfix);
  #endif
	  
	MSG("ParaView file written to %s\n", (fn + paraviewFileExt).c_str());
      }
      
      if (writeParaViewAnimation) {
  #if HAVE_PARALLEL_DOMAIN_AMDIS
	if (MPI::COMM_WORLD.Get_rank() == 0) {
	  io::VtkWriter::detail::updateAnimationFile(adaptInfo,
					paraFilename + paraviewParallelFileExt,
					&paraviewAnimationFrames,
					filename + ".pvd");

	}
  #else
	io::VtkWriter::detail::updateAnimationFile(adaptInfo,
				      fn + paraviewFileExt,
Praetorius, Simon's avatar
Praetorius, Simon committed
263
264
				      &paraviewAnimationFrames,
				      filename + ".pvd");
265
  #endif
Praetorius, Simon's avatar
Praetorius, Simon committed
266
      }
267
268
269
      
      for (int i = 0; i < static_cast<int>(dataCollectors.size()); i++)
	delete dataCollectors[i];
Praetorius, Simon's avatar
Praetorius, Simon committed
270
271
    }
    
272
273
  } // end namespace detail
} // end namespace AMDiS
Praetorius, Simon's avatar
Praetorius, Simon committed
274
275

#endif
276