Arh3Writer.h 4.67 KB
Newer Older
Siqi Ling's avatar
Siqi Ling committed
1
2
3
4
5
6
7
8
#ifndef AMDIS_ARH_WRITER3_DETAIL_H
#define AMDIS_ARH_WRITER3_DETAIL_H

#include "Global.h"
#include "Mesh.h"
#include "MeshStructure.h"
#include "DOFVector.h"
#include "SystemVector.h"
Siqi Ling's avatar
Siqi Ling committed
9
#include "AdaptInfo.h"
Siqi Ling's avatar
Siqi Ling committed
10
11
12
13
14
15
#include "boost/assign.hpp"

namespace AMDiS { namespace io {

  namespace Arh3Writer
  {
16
17
18
19
20
21
22
    namespace Cpsformat
    {
      typedef enum{
	  NONE = 0, // no compression
	  ZLIB = 1, // zlib compression
	  BZIP2 = 2 // bzip2 compression
      } Value;
23
    }
24

25
26
27
28
29
    namespace Macroformat
    {
      typedef enum{
	  NONE = 0, 		// no macro
	  PT_MACROFILE = 1, 	// pointer to macro file
30
	  SELF = 2		// pointer to this file, at the end of this file
31
      } Value;
32
    }
33

Siqi Ling's avatar
Siqi Ling committed
34
    typedef enum{SI08, SI16, SI32, SI64, UI08, UI16, UI32, UI64, SF32, SF64} Valformat;
35

Siqi Ling's avatar
Siqi Ling committed
36
    using namespace boost::assign;
37

Siqi Ling's avatar
Siqi Ling committed
38
39
40
41
42
43
44
45
46
47
    static const std::map<std::string, Valformat> dataformatMap = map_list_of("SI08", SI08)
									  ("SI16", SI16)
									  ("SI32", SI32)
									  ("SI64", SI64)
									  ("UI08", UI08)
									  ("UI16", UI16)
									  ("UI32", UI32)
									  ("UI64", UI64)
									  ("SF32", SF32)
									  ("SF64", SF64);
48

Siqi Ling's avatar
Siqi Ling committed
49
50
51
    namespace detail
    {
      //Maybe remove this later
52
53
      void write(std::string filename,
                      DOFVector<double>* vec0 = NULL,
Siqi Ling's avatar
Siqi Ling committed
54
55
56
                      DOFVector<double>* vec1 = NULL,
                      DOFVector<double>* vec2 = NULL,
		      bool writeParallel = true,
57
		      Cpsformat::Value cps = Cpsformat::NONE,
Siqi Ling's avatar
Siqi Ling committed
58
		      std::string dataformat = "SF64",
59
		      Macroformat::Value writeMacro = Macroformat::NONE);
60

Siqi Ling's avatar
Siqi Ling committed
61
62
63
64
65
66
      /**
       * \ingroup Output
       *
       * \brief
       * checks the arguments, eventually splits the list of DOFVectors, to write
       * these to different files.
67
       *
Siqi Ling's avatar
Siqi Ling committed
68
       * The behavior is as follows:
69
       *
Siqi Ling's avatar
Siqi Ling committed
70
71
       * If mesh is given, then all the DOFVectors in vecs must belong to the
       * same mesh as the given one.
72
       *
Siqi Ling's avatar
Siqi Ling committed
73
       * Else vecs can contain DOFVector belong to different meshes and they
74
75
76
       * will be seperated to diff files. If multiple output files generated,
       * they are named like "filename.meshname.arh".
       *
Siqi Ling's avatar
Siqi Ling committed
77
78
79
80
       * Note: NULL pointer in vecs is not allowed for writeFile.
       *       If mesh is NULL and vecs is empty, a warning is showed and returned.
       *       Identical name in DOFVectors is not allowed.
      */
81
82
       void write(std::string filename,
		  Mesh* mesh,
Siqi Ling's avatar
Siqi Ling committed
83
84
		  std::vector<DOFVector<double>*> vecs,
		  bool writeParallel = true,
85
		  Cpsformat::Value cps = Cpsformat::NONE,
Siqi Ling's avatar
Siqi Ling committed
86
		  std::string dataformat = "SF64",
87
		  Macroformat::Value writeMacro = Macroformat::NONE);
Siqi Ling's avatar
Siqi Ling committed
88
89
90

       void writeAux(std::string filename, Mesh *mesh,
		       std::vector<DOFVector<double>*> vecs,
91
		       bool writeParallel, Cpsformat::Value cps,
92
		       std::string dataformat,
93
		       Macroformat::Value writeMacro = Macroformat::NONE);
Siqi Ling's avatar
Siqi Ling committed
94
95
96
97
98

       ///\return the size of the macro block in file
       std::pair<int, int> writeMacroElement(std::ofstream &file,
                                  MeshStructure &code,
                                  std::vector<std::vector<double> >& values,
99
100
                                  std::map<const FiniteElemSpace*,
				  std::vector<int> >& feSpaces,
101
				  Cpsformat::Value cps, std::string dataformat);
102

Siqi Ling's avatar
Siqi Ling committed
103
       int writeValues(std::stringstream& file,
104
		       std::string dataformat,
Siqi Ling's avatar
Siqi Ling committed
105
		       std::vector<double>& values);
106

Siqi Ling's avatar
Siqi Ling committed
107
108
109
110
111
112
       template<typename T>
       int writeValues(std::stringstream& file, std::vector<double>& values);

       int writeHeader(std::ofstream& file,
                            Mesh* mesh,
                            std::vector<DOFVector<double>*> vecs,
113
114
115
                            std::map<const FiniteElemSpace*,
			    std::vector<int> >& feSpaces,
			    Cpsformat::Value cps,
116
			    std::string dataformat,
117
118
			    Macroformat::Value writeMacro);

Siqi Ling's avatar
Siqi Ling committed
119
120
       ///internal method, don't call
       void setMacrosPos(std::ofstream& file, int headerLen,
121
122
	                    std::vector<std::pair<int, int> >& macroSize);

123
       ///internal method, don't call
124
125
       void setMacroFile(std::ofstream& file,
			 int headerLen,
126
			 Mesh* mesh,
127
128
			 Macroformat::Value writeMacro);

129
       void readFileToString(std::string filename, std::string& data);
130
131

       void updateAnimationFile(AdaptInfo *adaptInfo,
Siqi Ling's avatar
Siqi Ling committed
132
133
134
135
136
				std::vector<double>* arhAnimationFrames,
				bool createSubDir,
				int indexLength,
				int indexDecimals,
				std::string animationFilename);
137
138

#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
Siqi Ling's avatar
Siqi Ling committed
139
140
       void writeParallelFile(std::string filename,
			      Mesh* mesh,
141
			      bool createSubDir,
Siqi Ling's avatar
Siqi Ling committed
142
			      Macroformat::Value writeMacro = Macroformat::PT_MACROFILE);
Siqi Ling's avatar
Siqi Ling committed
143
144
145
146
147
148
#endif
    }//end namespace detail
  } // end namespace Arh3Writer
} } // end namespace io, AMDiS

#endif