Arh3Writer.h 4.09 KB
Newer Older
Siqi Ling's avatar
Siqi Ling committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#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"
#include "boost/assign.hpp"

namespace AMDiS { namespace io {

  namespace Arh3Writer
  {
    typedef enum{
        NONE = 0,
	ZLIB = 1,
	BZIP2 = 2
    } Cpsformat;
    
    typedef enum{SI08, SI16, SI32, SI64, UI08, UI16, UI32, UI64, SF32, SF64} Valformat;
    
    using namespace boost::assign;
    
    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);
      
    namespace detail
    {
      //Maybe remove this later
      void write(std::string filename,                                                
                      DOFVector<double>* vec0 = NULL,                                                  
                      DOFVector<double>* vec1 = NULL,
                      DOFVector<double>* vec2 = NULL,
		      bool writeParallel = true,
		      Cpsformat cps = NONE,
		      std::string dataformat = "SF64",
46
		      bool writeMacro = false);
Siqi Ling's avatar
Siqi Ling committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    
      /**
       * \ingroup Output
       *
       * \brief
       * checks the arguments, eventually splits the list of DOFVectors, to write
       * these to different files.
       * 
       * The behavior is as follows:
       * 
       * If mesh is given, then all the DOFVectors in vecs must belong to the
       * same mesh as the given one.
       * 
       * Else vecs can contain DOFVector belong to different meshes and they
       * will be seperated to diff files. If multiple output files generated, 
       * they are named like "filename.meshname.arh". 
       * 
       * 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.
      */
       void write(std::string filename, 
		  Mesh* mesh, 
		  std::vector<DOFVector<double>*> vecs,
		  bool writeParallel = true,
		  Cpsformat cps = NONE,
		  std::string dataformat = "SF64",
74
		  bool writeMacro = false);
Siqi Ling's avatar
Siqi Ling committed
75
76
77
78

       void writeAux(std::string filename, Mesh *mesh,
		       std::vector<DOFVector<double>*> vecs,
		       bool writeParallel, Cpsformat cps,
79
80
		       std::string dataformat,
		       bool writeMacro = false);
Siqi Ling's avatar
Siqi Ling committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

       ///\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,
                                  std::map<const FiniteElemSpace*, 
				  std::vector<int> >& feSpaces, 
				  Cpsformat cps, std::string dataformat);
       
       int writeValues(std::stringstream& file,
		       std::string dataformat, 
		       std::vector<double>& values);
       
       template<typename T>
       int writeValues(std::stringstream& file, std::vector<double>& values);

       int writeHeader(std::ofstream& file,
                            Mesh* mesh,
                            std::vector<DOFVector<double>*> vecs,
                            std::map<const FiniteElemSpace*, 
			    std::vector<int> >& feSpaces, 
102
103
			    Cpsformat cps, 
			    std::string dataformat);    
Siqi Ling's avatar
Siqi Ling committed
104
105
106
       
       ///internal method, don't call
       void setMacrosPos(std::ofstream& file, int headerLen,
107
108
109
110
111
112
	                    std::vector<std::pair<int, int> >& macroSize);  
       
       ///internal method, don't call
       void setMacroFile(std::ofstream& file, int headerLen, Mesh* mesh);
       
       void readFileToString(std::string filename, std::string& data);
Siqi Ling's avatar
Siqi Ling committed
113
114
115
116
       
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS         
       void writeParallelFile(std::string filename,
			      Mesh* mesh,
117
118
			      bool createSubDir,
			      bool writeMacro = true);
Siqi Ling's avatar
Siqi Ling committed
119
120
121
122
123
124
#endif
    }//end namespace detail
  } // end namespace Arh3Writer
} } // end namespace io, AMDiS

#endif