1 #ifndef OUTPUT_MANAGER_H
2 #define OUTPUT_MANAGER_H
3 
4 #include "ATC_TypeDefs.h"
5 #include <map>
6 #include <vector>
7 #include <string>
8 #include <set>
9 
10 
11 // 1 -> scalar
12 // 3 -> vector  x,y,z
13 // NOT 6 -> tensor  xx,xy,xz,yy,yz,zz
14 // 6 -> tensor  xx,yy,zz,xy,zx,yz
15 // 9 -> tensor  xx,xy,xz,yx,yy,yz,zx,zy,zz
16 
17 namespace ATC {
18 
19   enum OutputType     { ENSIGHT=0, GNUPLOT, FULL_GNUPLOT, VTK };
20   enum OutputDataType { POINT=0, MESH };
21   enum OutputDataCardinality { SCALAR_OUTPUT=0, VECTOR_OUTPUT, TENSOR_OUTPUT,
22     SYM_TENSOR_OUTPUT, LIST_OUTPUT };
23   enum OutputOption   { OUTPUT_VECTOR_COMPONENTS=0, OUTPUT_TENSOR_COMPONENTS};
24 
25   /**
26    *  @class  OutputManager
27    *  @brief  Base class for handling output desired from an AtC computation
28    */
29 
30   class OutputManager{
31 
32   public:
33     OutputManager(void);
34     OutputManager(std::string outputPrefix, std::set<int> &otypes);
35     ~OutputManager(void);
36 
37     /** initialize output */
38     void initialize(std::string outputPrefix, std::set<int> &otypes);
39 
40     /** set output options */
41     void set_option(OutputOption option, bool value);
42 
43     // Dump text-based field info to disk for later restart
44     void write_restart_file(std::string fileName, RESTART_LIST *data);
45 
46     // Read text-based field file written from write_restart_file
47     void read_restart_file(std::string fileName, RESTART_LIST *data);
48 
49     /** write initial/reference geometry
50         default is to write point data,
51         if connectivities are given then mesh data will be output
52         coordinates : num _total_ points/nodes X num spatial dim
53         connectivities : num elements X num nodes per element*/
54     void write_geometry(const MATRIX *coordinates,
55                         const Array2D<int> *connectivity=NULL);
56 
57     /** write data from a time step
58         specify node_map to handle periodic soln & data */
59     void write_data(double time, OUTPUT_LIST *data, const int *node_map=NULL);
60     void write_data(double time, FIELDS *soln, OUTPUT_LIST *data,
61       const int *node_map=NULL);
62 
63     /** add custom names for any field */
add_field_names(const std::string & name,const std::vector<std::string> & list)64     void add_field_names(const std::string& name, const std::vector<std::string>& list) {
65       fieldNames_[name] = list; }
66     /** add a scalar to a text output file */
add_global(const std::string & name,const double & value)67     void add_global(const std::string& name, const double& value) {
68       globalData_[name] = value; }
69 
70     /** delete a scalar from the output */
delete_global(const std::string & name)71     void delete_global(const std::string& name) { globalData_.erase(name); }
72 
73     /** reset the stored output scalars */
reset_globals()74     void reset_globals() { globalData_.clear(); writeGlobalsHeader_=true; }
75 
76     /** return data type: scalar, vector, tensor, list */
data_type(const DENS_MAT & data)77     int data_type(const DENS_MAT & data) const {
78       return data_type(data.nCols());
79     }
data_type(int cols)80     int data_type(int cols) const {
81       if      (cols == 1) return SCALAR_OUTPUT;
82       else if (cols == 3) return VECTOR_OUTPUT;
83       else if (cols == 6) return SYM_TENSOR_OUTPUT;
84       else if (cols == 9) return TENSOR_OUTPUT;
85       else                return LIST_OUTPUT;
86     }
use_component_names(int type)87     bool use_component_names(int type) const {
88       if ( (type==LIST_OUTPUT) ||
89        ((type==SYM_TENSOR_OUTPUT || type==TENSOR_OUTPUT) && tensorToComponents_)
90       || (type==VECTOR_OUTPUT && vectorToComponents_) )
91         return true;
92       else
93         return false;
94     }
custom_name(const std::string field,const int index,std::string & name)95     bool custom_name(const std::string field, const int index, std::string & name) const {
96       std::map<std::string,std::vector<std::string> >::const_iterator itr = fieldNames_.find(field);
97       if (itr == fieldNames_.end()) return false;
98       std::vector<std::string>  names = itr->second;
99       name = names[index];
100       return true;
101     }
102     void print_custom_names();
103 
104   private:
105 
106     void write_geometry_ensight(void);
107     void write_geometry_text(void);
108     void write_data_ensight(std::string name, const MATRIX *data, const int *node_map);
109     void write_text_data_header(OUTPUT_LIST *data, std::ofstream & text, int k);
110     void write_data_text(OUTPUT_LIST *data);
111     void write_data_text(OUTPUT_LIST *data, const int *node_map);
112     void write_data_vtk(OUTPUT_LIST *data);
113     void write_dictionary(double time, OUTPUT_LIST *data);
114     void write_globals();
115 
116     /** status flags */
117     bool initialized_, firstStep_, firstGlobalsWrite_, writeGlobalsHeader_;
118 
119     /** custom field names */
120     std::map<std::string,std::vector<std::string> > fieldNames_;
121 
122     /**  pointers to mesh data */
123     const MATRIX * coordinates_;
124     const Array2D<int> * connectivities_;
125     /** number of columns of data */
126     int nDataCols_;
127     /** number of nodes */
128     int number_of_nodes_;
129     /** data type */
130     int dataType_;
131     /** base name for output files */
132     std::string outputPrefix_;
133     /** list of output timesteps */
134     std::vector<double> outputTimes_;
135     /** output type flags */
136     bool ensightOutput_,textOutput_,fullTextOutput_,vtkOutput_;
137     /** output tensor as its components */
138     bool tensorToComponents_;
139     /** output vector as its components */
140     bool vectorToComponents_;
141     /** global variables */
142     std::map<std::string,double> globalData_;
143   };
144 }
145 #endif
146